From b7a3458c3395664aadb060c73450d3e4544d7705 Mon Sep 17 00:00:00 2001 From: StrangeOne101 Date: Tue, 20 Dec 2016 17:53:20 +1300 Subject: [PATCH] Minor fixes (#662) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • Fixed Bottlebending breaking (needs testing) • Fixed CoreAbility not returning all abilities with CoreAbility.getAbilities() • Added new ability.setPlayer(...) method that is used for moves that change who created the ability (used for redirection) --- .../projectkorra/ability/CoreAbility.java | 17 +++++++++++++++-- .../waterbending/IceSpikeBlast.java | 2 +- .../waterbending/WaterManipulation.java | 2 +- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/com/projectkorra/projectkorra/ability/CoreAbility.java b/src/com/projectkorra/projectkorra/ability/CoreAbility.java index 77b3a395..e5020267 100644 --- a/src/com/projectkorra/projectkorra/ability/CoreAbility.java +++ b/src/com/projectkorra/projectkorra/ability/CoreAbility.java @@ -286,7 +286,7 @@ public abstract class CoreAbility implements Ability { * {@link #registerAbilities()} */ public static ArrayList getAbilities() { - return new ArrayList(ABILITIES_BY_NAME.values()); + return new ArrayList(ABILITIES_BY_CLASS.values()); } /** @@ -607,6 +607,19 @@ public abstract class CoreAbility implements Ability { public Player getPlayer() { return player; } + + /** + * Changes the player that owns this ability instance. Used for redirection + * and other abilities that change the player object. + * + * @param player The player who now controls the ability + */ + public void setPlayer(Player player) { + INSTANCES_BY_PLAYER.get(this.getClass()).get(this.player.getUniqueId()).remove(this.getId()); + INSTANCES_BY_PLAYER.get(this.getClass()).get(player.getUniqueId()).put(this.getId(), this); + + this.player = player; + } /** * Used by the CollisionManager to check if two instances can collide with @@ -731,4 +744,4 @@ public abstract class CoreAbility implements Ability { return DEFAULT_COLLISION_RADIUS; } -} +} \ No newline at end of file diff --git a/src/com/projectkorra/projectkorra/waterbending/IceSpikeBlast.java b/src/com/projectkorra/projectkorra/waterbending/IceSpikeBlast.java index 968650c0..ec342772 100644 --- a/src/com/projectkorra/projectkorra/waterbending/IceSpikeBlast.java +++ b/src/com/projectkorra/projectkorra/waterbending/IceSpikeBlast.java @@ -210,7 +210,7 @@ public class IceSpikeBlast extends IceAbility { private void redirect(Location destination, Player player) { this.destination = destination; - this.player = player; + this.setPlayer(player); } @Override diff --git a/src/com/projectkorra/projectkorra/waterbending/WaterManipulation.java b/src/com/projectkorra/projectkorra/waterbending/WaterManipulation.java index 47949bc9..f2a87053 100644 --- a/src/com/projectkorra/projectkorra/waterbending/WaterManipulation.java +++ b/src/com/projectkorra/projectkorra/waterbending/WaterManipulation.java @@ -317,7 +317,7 @@ public class WaterManipulation extends WaterAbility { targetDirection = GeneralMethods.getDirection(location, targetlocation).normalize(); } targetDestination = targetlocation; - this.player = player; + this.setPlayer(player); } }