From 49216a3da3556d55fa7a81cffed5a28127ff9c99 Mon Sep 17 00:00:00 2001 From: StrangeOne101 Date: Sat, 6 Aug 2016 20:53:10 +1200 Subject: [PATCH] Fixes :D (#529) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • Fixed MetalClips keeping armor on logout/kick • Fixed MetalClips breaking when used on more than one target • Fixed MetalClips/EarthArmor/PlantArmor keeping armor on death when keepInventory is on • Fixed MetalClips/EarthArmor/PlantArmor removing all armor peices from the inventory when you die (instead of just the set you were given) • Fixed EarthBlast firing wrong block when EarthRevert is off • Fixed PhaseChange not melting blocks from a distance underwater • Fixed EarthTunnel revert not functioning with EarthRevert off --- .../projectkorra/projectkorra/PKListener.java | 118 ++++++++++-------- .../projectkorra/earthbending/EarthBlast.java | 10 +- .../earthbending/EarthTunnel.java | 19 ++- .../earthbending/EarthbendingManager.java | 1 + .../projectkorra/earthbending/MetalClips.java | 24 +++- .../waterbending/PhaseChangeMelt.java | 2 +- 6 files changed, 110 insertions(+), 64 deletions(-) diff --git a/src/com/projectkorra/projectkorra/PKListener.java b/src/com/projectkorra/projectkorra/PKListener.java index fb66553f..a8b18eec 100644 --- a/src/com/projectkorra/projectkorra/PKListener.java +++ b/src/com/projectkorra/projectkorra/PKListener.java @@ -871,74 +871,82 @@ public class PKListener implements Listener { if (!(event.getEntity() instanceof Player)) { return; } - + Player player = event.getEntity(); EarthArmor earthArmor = CoreAbility.getAbility(player, EarthArmor.class); PlantArmor plantArmor = CoreAbility.getAbility(player, PlantArmor.class); - - if (earthArmor != null) { - List drops = event.getDrops(); - List newDrops = new ArrayList(); - for (int i = 0; i < drops.size(); i++) { - Material type = drops.get(i).getType(); - if (!(type == Material.LEATHER_BOOTS || type == Material.LEATHER_CHESTPLATE || type == Material.LEATHER_HELMET || type == Material.LEATHER_LEGGINGS || type == Material.AIR)) { - newDrops.add(drops.get(i)); - } + + if (event.getKeepInventory()) { + if (earthArmor != null && earthArmor.getOldArmor() != null) { + player.getInventory().setArmorContents(earthArmor.getOldArmor()); + } else if (plantArmor != null && plantArmor.getOldArmor() != null) { + player.getInventory().setArmorContents(plantArmor.getOldArmor()); + } else if (event.getEntity() instanceof LivingEntity && MetalClips.isControlled(event.getEntity()) && MetalClips.getOriginalArmor(player) != null) { + player.getInventory().setArmorContents(MetalClips.getOriginalArmor(player)); } - if (earthArmor.getOldArmor() != null) { - for (ItemStack is : earthArmor.getOldArmor()) { - if (is.getType() != Material.AIR) { - newDrops.add(is); + } else { + if (earthArmor != null) { + List earthArmorItems = Arrays.asList(new Material[] {Material.LEATHER_BOOTS, Material.LEATHER_LEGGINGS, Material.LEATHER_CHESTPLATE, Material.LEATHER_HELMET}); + List newDrops = new ArrayList(); + if (earthArmor.getOldArmor() != null) { + int size = event.getDrops().size(); + for (int i = 0; i < 4; i++) { + //Armor always drops last (items, boots, leggings, chestplate, helmet) so we got to get the last drop items + ItemStack is = event.getDrops().get(size - i - 1); + if (earthArmorItems.contains(is.getType())) { + event.getDrops().remove(is); + newDrops.add(earthArmor.getOldArmor()[i]); + } } } + event.getDrops().addAll(newDrops); + earthArmor.remove(); } - event.getDrops().clear(); - event.getDrops().addAll(newDrops); - earthArmor.remove(); - } - if (plantArmor != null) { - List drops = event.getDrops(); - List newDrops = new ArrayList<>(); - - for (int i = 0; i < drops.size(); i++) { - Material type = drops.get(i).getType(); - if (!(type == Material.LEATHER_BOOTS || type == Material.LEATHER_CHESTPLATE || type == Material.LEAVES || type == Material.LEAVES_2 || type == Material.LEATHER_LEGGINGS || type == Material.AIR)) { - newDrops.add(drops.get(i)); - } - } - if (plantArmor.getOldArmor() != null) { - for (ItemStack is : plantArmor.getOldArmor()) { - if (!(is.getType() == Material.AIR)) { - newDrops.add(is); + if (plantArmor != null) { + List plantArmorItems = Arrays.asList(new Material[] {Material.LEATHER_BOOTS, Material.LEATHER_LEGGINGS, Material.LEATHER_CHESTPLATE, Material.LEAVES}); + List newDrops = new ArrayList(); + if (plantArmor.getOldArmor() != null) { + int size = event.getDrops().size(); + for (int i = 0; i < 4; i++) { + ItemStack is = event.getDrops().get(size - i - 1); + if (plantArmorItems.contains(is.getType())) { + event.getDrops().remove(is); + newDrops.add(plantArmor.getOldArmor()[i]); + } } } + + event.getDrops().addAll(newDrops); + plantArmor.remove(); } - event.getDrops().clear(); - event.getDrops().addAll(newDrops); - plantArmor.remove(); - } - - if (MetalClips.getEntityClipsCount().containsKey(event.getEntity())) { - List drops = event.getDrops(); - List newdrops = new ArrayList(); - for (int i = 0; i < drops.size(); i++) { - if (!(drops.get(i).getType() == Material.IRON_HELMET || drops.get(i).getType() == Material.IRON_CHESTPLATE || drops.get(i).getType() == Material.IRON_LEGGINGS || drops.get(i).getType() == Material.IRON_BOOTS || drops.get(i).getType() == Material.AIR)) { - newdrops.add(drops.get(i)); + if (event.getEntity() instanceof LivingEntity && MetalClips.isControlled(event.getEntity())) { + + List currentArmor = new ArrayList(); + for (ItemStack is : Arrays.asList(event.getEntity().getInventory().getArmorContents())) { + if (is.getType() != Material.AIR) { //Remove Air because it won't show in the drops + currentArmor.add(is); + } } + + List oldArmor = new ArrayList(); + for (ItemStack is : Arrays.asList(MetalClips.getOriginalArmor(player))) { + if (is.getType() != Material.AIR) { //Shouldn't add air itemstacks to drop list + oldArmor.add(is); + } + } + + for (int i = 0; i < currentArmor.size(); i++) { //Remove all armor drops completely, so we can then drop the correct armor. + event.getDrops().remove(event.getDrops().size() - 1); + } + + event.getDrops().addAll(oldArmor); + MetalClips.getEntityClipsCount().remove(event.getEntity()); } - - newdrops.add(MetalClips.getOriginalHelmet(event.getEntity())); - newdrops.add(MetalClips.getOriginalChestplate(event.getEntity())); - newdrops.add(MetalClips.getOriginalLeggings(event.getEntity())); - newdrops.add(MetalClips.getOriginalBoots(event.getEntity())); - - event.getDrops().clear(); - event.getDrops().addAll(newdrops); - MetalClips.getEntityClipsCount().remove(event.getEntity()); } + if (event.getEntity().getKiller() != null) { if (BENDING_PLAYER_DEATH.containsKey(event.getEntity())) { String message = ConfigManager.languageConfig.get().getString("DeathMessages.Default"); @@ -1047,6 +1055,7 @@ public class PKListener implements Listener { if (event.isCancelled()) { return; } + AirFlight.remove(event.getPlayer()); JUMPS.remove(event.getPlayer()); } @@ -1183,6 +1192,10 @@ public class PKListener implements Listener { if (metalClips != null) { metalClips.remove(); } + + if (MetalClips.isControlled(event.getPlayer())) { + MetalClips.removeControlledEnitity(event.getPlayer()); + } MultiAbilityManager.remove(player); AirFlight.remove(player); @@ -1691,5 +1704,4 @@ public class PKListener implements Listener { public static Map getJumpStatistics() { return JUMPS; } - } diff --git a/src/com/projectkorra/projectkorra/earthbending/EarthBlast.java b/src/com/projectkorra/projectkorra/earthbending/EarthBlast.java index fedcec76..7eb90e9b 100644 --- a/src/com/projectkorra/projectkorra/earthbending/EarthBlast.java +++ b/src/com/projectkorra/projectkorra/earthbending/EarthBlast.java @@ -214,11 +214,7 @@ public class EarthBlast extends EarthAbility { } location = location.clone().add(direction); - Block block = location.getBlock(); - - WaterAbility.removeWaterSpouts(location, player); - AirAbility.removeAirSpouts(location, player); - EarthAbility.removeSandSpouts(location, player); + Block block = location.getBlock(); if (block.getLocation().equals(sourceBlock.getLocation())) { location = location.clone().add(direction); @@ -234,7 +230,7 @@ public class EarthBlast extends EarthAbility { location = location.clone().subtract(direction); direction = GeneralMethods.getDirection(location, destination).normalize(); location = location.clone().add(direction); - + WaterAbility.removeWaterSpouts(location, player); AirAbility.removeAirSpouts(location, player); EarthAbility.removeSandSpouts(location, player); @@ -303,7 +299,7 @@ public class EarthBlast extends EarthAbility { block.setType(Material.STONE); } } else { - block.setType(sourceBlock.getType()); + block.setType(sourceType); sourceBlock.setType(Material.AIR); } diff --git a/src/com/projectkorra/projectkorra/earthbending/EarthTunnel.java b/src/com/projectkorra/projectkorra/earthbending/EarthTunnel.java index 6b547048..e15aae7b 100644 --- a/src/com/projectkorra/projectkorra/earthbending/EarthTunnel.java +++ b/src/com/projectkorra/projectkorra/earthbending/EarthTunnel.java @@ -2,6 +2,8 @@ package com.projectkorra.projectkorra.earthbending; import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ability.EarthAbility; +import com.projectkorra.projectkorra.configuration.ConfigManager; +import com.projectkorra.projectkorra.util.TempBlock; import org.bukkit.Location; import org.bukkit.Material; @@ -10,6 +12,8 @@ import org.bukkit.entity.Player; import org.bukkit.util.Vector; import java.util.HashSet; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; public class EarthTunnel extends EarthAbility { @@ -27,6 +31,8 @@ public class EarthTunnel extends EarthAbility { private Location location; private Vector direction; + public static Map airBlocks = new ConcurrentHashMap(); + public EarthTunnel(Player player) { super(player); @@ -93,7 +99,7 @@ public class EarthTunnel extends EarthAbility { } if (this.revert) { - addTempAirBlock(block); + airBlocks.put(new TempBlock(block, Material.AIR, (byte) 0), System.currentTimeMillis()); } else { block.breakNaturally(); } @@ -219,4 +225,15 @@ public class EarthTunnel extends EarthAbility { this.location = location; } + public static void revertAirBlocks() { + if (ConfigManager.defaultConfig.get().getBoolean("Abilities.Earth.EarthTunnel.Revert")) { + for (TempBlock tempBlock : EarthTunnel.airBlocks.keySet()) { + if (EarthTunnel.airBlocks.get(tempBlock) + ConfigManager.defaultConfig.get().getLong("Properties.Earth.RevertCheckTime") <= System.currentTimeMillis()) { + tempBlock.revertBlock(); + EarthTunnel.airBlocks.remove(tempBlock); + } + } + } + } + } diff --git a/src/com/projectkorra/projectkorra/earthbending/EarthbendingManager.java b/src/com/projectkorra/projectkorra/earthbending/EarthbendingManager.java index edabc7d1..74e9c224 100644 --- a/src/com/projectkorra/projectkorra/earthbending/EarthbendingManager.java +++ b/src/com/projectkorra/projectkorra/earthbending/EarthbendingManager.java @@ -19,5 +19,6 @@ public class EarthbendingManager implements Runnable { RevertChecker.revertEarthBlocks(); Shockwave.progressAll(); Tremorsense.manage(Bukkit.getServer()); + EarthTunnel.revertAirBlocks(); } } diff --git a/src/com/projectkorra/projectkorra/earthbending/MetalClips.java b/src/com/projectkorra/projectkorra/earthbending/MetalClips.java index 7d9eb528..ed3c4401 100644 --- a/src/com/projectkorra/projectkorra/earthbending/MetalClips.java +++ b/src/com/projectkorra/projectkorra/earthbending/MetalClips.java @@ -1,6 +1,7 @@ package com.projectkorra.projectkorra.earthbending; import com.projectkorra.projectkorra.GeneralMethods; +import com.projectkorra.projectkorra.ability.CoreAbility; import com.projectkorra.projectkorra.ability.MetalAbility; import com.projectkorra.projectkorra.avatar.AvatarState; import com.projectkorra.projectkorra.util.DamageHandler; @@ -125,6 +126,14 @@ public class MetalClips extends MetalAbility { } return null; } + + public static ItemStack[] getOriginalArmor(LivingEntity ent) { + MetalClips clips = TARGET_TO_ABILITY.get(ent); + if (clips != null) { + return clips.oldArmor; + } + return null; + } public void shootMetal() { ItemStack is = new ItemStack(Material.IRON_INGOT, 1); @@ -405,7 +414,7 @@ public class MetalClips extends MetalAbility { for (Entity e : GeneralMethods.getEntitiesAroundPoint(ii.getLocation(), 2)) { if (e instanceof LivingEntity && e.getEntityId() != player.getEntityId()) { - if (e instanceof Player || e instanceof Zombie || e instanceof Skeleton) { + if ((e instanceof Player || e instanceof Zombie || e instanceof Skeleton) && targetEntity == null) { targetEntity = (LivingEntity) e; TARGET_TO_ABILITY.put(targetEntity, this); formArmor(); @@ -450,7 +459,7 @@ public class MetalClips extends MetalAbility { } } - public static boolean isControlled(Player player) { + public static boolean isControlled(LivingEntity player) { return TARGET_TO_ABILITY.containsKey(player); } @@ -466,6 +475,17 @@ public class MetalClips extends MetalAbility { public static Map getTargetToAbility() { return TARGET_TO_ABILITY; } + + public static boolean removeControlledEnitity(LivingEntity entity) { + if (entity == null) return false; + for (MetalClips metalclips : CoreAbility.getAbilities(MetalClips.class)) { + if (metalclips.targetEntity == entity) { + metalclips.remove(); + return true; + } + } + return false; + } @Override public String getName() { diff --git a/src/com/projectkorra/projectkorra/waterbending/PhaseChangeMelt.java b/src/com/projectkorra/projectkorra/waterbending/PhaseChangeMelt.java index 6be6b23d..0d09b483 100644 --- a/src/com/projectkorra/projectkorra/waterbending/PhaseChangeMelt.java +++ b/src/com/projectkorra/projectkorra/waterbending/PhaseChangeMelt.java @@ -50,7 +50,7 @@ public class PhaseChangeMelt extends IceAbility { } boolean evaporate = false; - location = GeneralMethods.getTargetedLocation(player, range); + location = GeneralMethods.getTargetedLocation(player, range, 0, 8, 9); if (isWater(player.getTargetBlock((HashSet) null, (int) range)) && !(player.getEyeLocation().getBlockY() <= 62)) { evaporate = true; radius = (int) getNightFactor(evaporateRadius);