11package com .nisovin .magicspells .spells .targeted ;
22
3- import org .bukkit .entity . LivingEntity ;
3+ import org .bukkit .util . Vector ;
44import org .bukkit .entity .Player ;
5+ import org .bukkit .entity .LivingEntity ;
6+ import com .nisovin .magicspells .util .Util ;
57import org .bukkit .event .entity .EntityDamageEvent .DamageCause ;
6- import org .bukkit .util .Vector ;
78
8- import com .nisovin .magicspells .events . MagicSpellsEntityDamageByEntityEvent ;
9- import com .nisovin .magicspells .spells . TargetedEntitySpell ;
9+ import com .nisovin .magicspells .util . TargetInfo ;
10+ import com .nisovin .magicspells .util . MagicConfig ;
1011import com .nisovin .magicspells .spells .TargetedSpell ;
1112import com .nisovin .magicspells .util .compat .EventUtil ;
12- import com .nisovin .magicspells .util . MagicConfig ;
13- import com .nisovin .magicspells .util . TargetInfo ;
13+ import com .nisovin .magicspells .spells . TargetedEntitySpell ;
14+ import com .nisovin .magicspells .events . MagicSpellsEntityDamageByEntityEvent ;
1415
1516public class ForcetossSpell extends TargetedSpell implements TargetedEntitySpell {
1617
1718 private int damage ;
1819 private float hForce ;
1920 private float vForce ;
21+ private float rotation ;
2022 private boolean checkPlugins ;
2123 private boolean powerAffectsForce ;
2224 private boolean avoidDamageModification ;
23-
25+
2426 public ForcetossSpell (MagicConfig config , String spellName ) {
2527 super (config , spellName );
26-
28+
2729 damage = getConfigInt ("damage" , 0 );
28- hForce = getConfigInt ("horizontal-force" , 20 ) / 10.0F ;
29- vForce = getConfigInt ("vertical-force" , 10 ) / 10.0F ;
30+ hForce = getConfigFloat ("horizontal-force" , 20 ) / 10.0F ;
31+ vForce = getConfigFloat ("vertical-force" , 10 ) / 10.0F ;
32+ rotation = getConfigFloat ("rotation" , 0 );
3033 checkPlugins = getConfigBoolean ("check-plugins" , true );
3134 powerAffectsForce = getConfigBoolean ("power-affects-force" , true );
3235 avoidDamageModification = getConfigBoolean ("avoid-damage-modification" , false );
@@ -38,37 +41,39 @@ public PostCastAction castSpell(Player player, SpellCastState state, float power
3841 // Get target
3942 TargetInfo <LivingEntity > targetInfo = getTargetedEntity (player , power );
4043 if (targetInfo == null ) return noTarget (player );
41- LivingEntity target = targetInfo .getTarget ();
42- power = targetInfo .getPower ();
43-
44- // Do damage
45- if (damage > 0 ) {
46- double damage = this .damage * power ;
47- if (target instanceof Player && checkPlugins ) {
48- MagicSpellsEntityDamageByEntityEvent event = new MagicSpellsEntityDamageByEntityEvent (player , target , DamageCause .ENTITY_ATTACK , damage );
49- EventUtil .call (event );
50- if (event .isCancelled ()) return noTarget (player );
51- if (!avoidDamageModification ) damage = event .getDamage ();
52- }
53- target .damage (damage );
54- }
55-
44+
5645 // Throw target
57- toss (player , target , power );
58-
59- sendMessages (player , target );
46+ toss (player , targetInfo . getTarget (), targetInfo . getPower () );
47+
48+ sendMessages (player , targetInfo . getTarget () );
6049 return PostCastAction .NO_MESSAGES ;
6150 }
6251 return PostCastAction .HANDLE_NORMALLY ;
6352 }
64-
53+
6554 private void toss (Player player , LivingEntity target , float power ) {
6655 if (!powerAffectsForce ) power = 1f ;
67- Vector v = target .getLocation ().toVector ().subtract (player .getLocation ().toVector ())
68- .setY (0 )
69- .normalize ()
70- .multiply (hForce * power )
71- .setY (vForce * power );
56+
57+ // Deal damage
58+ if (damage > 0 ) {
59+ double damage = this .damage * power ;
60+ if (target instanceof Player && checkPlugins ) {
61+ MagicSpellsEntityDamageByEntityEvent event = new MagicSpellsEntityDamageByEntityEvent (player , target , DamageCause .ENTITY_ATTACK , damage );
62+ EventUtil .call (event );
63+ if (!avoidDamageModification ) damage = event .getDamage ();
64+ }
65+ target .damage (damage );
66+ }
67+
68+ Vector v ;
69+ if (player .equals (target )) {
70+ v = player .getLocation ().getDirection ();
71+ } else {
72+ v = target .getLocation ().toVector ().subtract (player .getLocation ().toVector ());
73+ }
74+ if (v == null ) throw new NullPointerException ("v" );
75+ v .setY (0 ).normalize ().multiply (hForce * power ).setY (vForce * power );
76+ if (rotation != 0 ) Util .rotateVector (v , rotation );
7277 target .setVelocity (v );
7378 playSpellEffects (player , target );
7479 }
0 commit comments