diff --git a/src/com/projectkorra/projectkorra/ability/CoreAbility.java b/src/com/projectkorra/projectkorra/ability/CoreAbility.java index e5020267..fb6c6e72 100644 --- a/src/com/projectkorra/projectkorra/ability/CoreAbility.java +++ b/src/com/projectkorra/projectkorra/ability/CoreAbility.java @@ -615,7 +615,30 @@ public abstract class CoreAbility implements Ability { * @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()); + Map> classMap = INSTANCES_BY_PLAYER.get(getClass()); + if (classMap != null) { + Map playerMap = classMap.get(player.getUniqueId()); + if (playerMap != null) { + playerMap.remove(this.id); + if (playerMap.size() == 0) { + classMap.remove(player.getUniqueId()); + } + } + + if (classMap.size() == 0) { + INSTANCES_BY_PLAYER.remove(getClass()); + } + } + + + if (!INSTANCES_BY_PLAYER.containsKey(this.getClass())) { + INSTANCES_BY_PLAYER.put(this.getClass(), new ConcurrentHashMap>()); + } + + if (!INSTANCES_BY_PLAYER.get(this.getClass()).containsKey(player.getUniqueId())) { + INSTANCES_BY_PLAYER.get(this.getClass()).put(player.getUniqueId(), new ConcurrentHashMap()); + } + INSTANCES_BY_PLAYER.get(this.getClass()).get(player.getUniqueId()).put(this.getId(), this); this.player = player; diff --git a/src/com/projectkorra/projectkorra/command/DisplayCommand.java b/src/com/projectkorra/projectkorra/command/DisplayCommand.java index f173da1c..18a0e97f 100644 --- a/src/com/projectkorra/projectkorra/command/DisplayCommand.java +++ b/src/com/projectkorra/projectkorra/command/DisplayCommand.java @@ -15,6 +15,7 @@ import org.bukkit.entity.Player; import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.List; /** @@ -121,16 +122,19 @@ public class DisplayCommand extends PKCommand { sender.sendMessage(ChatColor.YELLOW + noAbilitiesAvailable.replace("{element}", Element.AVATAR.getColor() + "Avatar" + ChatColor.YELLOW)); return; } + HashSet abilitiesSent = new HashSet(); //Some abilities have the same name. This prevents this from showing anything. for (CoreAbility ability : abilities) { - if (ability.isHiddenAbility()) { + if (ability.isHiddenAbility() || abilitiesSent.contains(ability.getName())) { continue; } if (sender instanceof Player) { if (GeneralMethods.canView((Player) sender, ability.getName())) { sender.sendMessage(ability.getElement().getColor() + ability.getName()); + abilitiesSent.add(ability.getName()); } } else { sender.sendMessage(ability.getElement().getColor() + ability.getName()); + abilitiesSent.add(ability.getName()); } } } @@ -151,12 +155,14 @@ public class DisplayCommand extends PKCommand { sender.sendMessage(ChatColor.YELLOW + noAbilitiesAvailable.replace("{element}", element.getColor() + element.getName() + ChatColor.YELLOW)); } + HashSet abilitiesSent = new HashSet(); //Some abilities have the same name. This prevents this from showing anything. for (CoreAbility ability : abilities) { - if (ability instanceof SubAbility || ability.isHiddenAbility()) { + if (ability instanceof SubAbility || ability.isHiddenAbility() || abilitiesSent.contains(ability.getName())) { continue; } if (!(sender instanceof Player) || GeneralMethods.canView((Player) sender, ability.getName())) { sender.sendMessage(ability.getElement().getColor() + ability.getName()); + abilitiesSent.add(ability.getName()); } } @@ -185,11 +191,14 @@ public class DisplayCommand extends PKCommand { sender.sendMessage(ChatColor.YELLOW + noAbilitiesAvailable.replace("{element}", element.getColor() + element.getName() + ChatColor.YELLOW)); return; } + + HashSet abilitiesSent = new HashSet(); for (CoreAbility ability : abilities) { - if (ability.isHiddenAbility()) { + if (ability.isHiddenAbility() || abilitiesSent.contains(ability.getName())) { continue; } else if (!(sender instanceof Player) || GeneralMethods.canView((Player) sender, ability.getName())) { sender.sendMessage(element.getColor() + ability.getName()); + abilitiesSent.add(ability.getName()); } } } diff --git a/src/com/projectkorra/projectkorra/waterbending/WaterManipulation.java b/src/com/projectkorra/projectkorra/waterbending/WaterManipulation.java index f2a87053..6ec3d308 100644 --- a/src/com/projectkorra/projectkorra/waterbending/WaterManipulation.java +++ b/src/com/projectkorra/projectkorra/waterbending/WaterManipulation.java @@ -165,7 +165,7 @@ public class WaterManipulation extends WaterAbility { Block block = BlockSource.getWaterSourceBlock(player, selectRange, ClickType.SHIFT_DOWN, true, true, bPlayer.canPlantbend()); cancelPrevious(); - block(player); + //block(player); if (block != null) { sourceBlock = block; @@ -384,7 +384,7 @@ public class WaterManipulation extends WaterAbility { } /**Blocks other water manips*/ - private static void block(Player player) { + public static void block(Player player) { for (WaterManipulation manip : getAbilities(WaterManipulation.class)) { if (!manip.location.getWorld().equals(player.getWorld())) { continue; @@ -462,7 +462,6 @@ public class WaterManipulation extends WaterAbility { return location; } - @SuppressWarnings("deprecation") public static void moveWater(Player player) { BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player); if (bPlayer == null) { @@ -493,15 +492,16 @@ public class WaterManipulation extends WaterAbility { if (isTransparent(player, block) && isTransparent(player, eyeLoc.getBlock())) { if (getTargetLocation(player, range).distanceSquared(block.getLocation()) > 1) { - block.setType(Material.WATER); - block.setData((byte) 0); + TempBlock tb = new TempBlock(block, Material.WATER, (byte)0); WaterManipulation waterManip = new WaterManipulation(player); waterManip.moveWater(); if (!waterManip.progressing) { block.setType(Material.AIR); + tb.revertBlock(); } else { WaterReturn.emptyWaterBottle(player); + tb.revertBlock(); } } }