diff --git a/resources/plugin.yml b/resources/plugin.yml index 4743453..0b6367c 100644 --- a/resources/plugin.yml +++ b/resources/plugin.yml @@ -1,7 +1,7 @@ name: MobArena author: garbagemule main: com.garbagemule.MobArena.MobArena -version: 0.95.5.13 +version: 0.95.5.14 softdepend: [Spout,Towny,Heroes,MagicSpells,Vault] commands: ma: diff --git a/src/com/garbagemule/MobArena/ArenaClass.java b/src/com/garbagemule/MobArena/ArenaClass.java index a32d6b1..b1b7098 100644 --- a/src/com/garbagemule/MobArena/ArenaClass.java +++ b/src/com/garbagemule/MobArena/ArenaClass.java @@ -16,14 +16,13 @@ public class ArenaClass private List items, armor; private Map perms; private Map lobbyperms; - private boolean unbreakableWeapons; - private boolean mount; + private boolean unbreakableWeapons, unbreakableArmor; /** * Create a new, empty arena class with the given name. * @param name the class name as it appears in the config-file */ - public ArenaClass(String name, boolean unbreakableWeapons) { + public ArenaClass(String name, boolean unbreakableWeapons, boolean unbreakableArmor) { this.configName = name; this.lowercaseName = name.toLowerCase(); @@ -31,8 +30,9 @@ public class ArenaClass this.armor = new ArrayList(4); this.perms = new HashMap(); this.lobbyperms = new HashMap(); - + this.unbreakableWeapons = unbreakableWeapons; + this.unbreakableArmor = unbreakableArmor; } /** @@ -97,29 +97,17 @@ public class ArenaClass /** * Add an item to the items list. - * If the item is a weapon-type, its durability will be set to "infinite". - * If the item is a bone, the pets counter will be incremented. * @param stack an item */ public void addItem(ItemStack stack) { if (stack == null) return; - if (unbreakableWeapons && isWeapon(stack)) { - stack.setDurability(Short.MIN_VALUE); - } - - else if (stack.getTypeId() == 170 && stack.getAmount() == 1) { - if (mount) return; - mount = true; - } - - else if (stack.getAmount() > 64) { + if (stack.getAmount() > 64) { while (stack.getAmount() > 64) { items.add(new ItemStack(stack.getType(), 64)); stack.setAmount(stack.getAmount() - 64); } } - items.add(stack); } @@ -254,13 +242,13 @@ public class ArenaClass } } } - + public boolean hasUnbreakableWeapons() { return unbreakableWeapons; } - - public boolean hasMount() { - return mount; + + public boolean hasUnbreakableArmor() { + return unbreakableArmor; } /** diff --git a/src/com/garbagemule/MobArena/ArenaListener.java b/src/com/garbagemule/MobArena/ArenaListener.java index d348a81..a12ff63 100644 --- a/src/com/garbagemule/MobArena/ArenaListener.java +++ b/src/com/garbagemule/MobArena/ArenaListener.java @@ -56,6 +56,7 @@ import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; import org.bukkit.material.Attachable; import org.bukkit.material.Bed; import org.bukkit.material.Door; @@ -541,6 +542,11 @@ public class ArenaListener if (damager instanceof Projectile) { damager = ((Projectile) damager).getShooter(); + } + + // Repair weapons if necessary + if (damager instanceof Player) { + repairWeapon((Player) damager); } else if (damager instanceof TNTPrimed) { damager = getPlanter(damager); } @@ -579,9 +585,14 @@ public class ArenaListener event.setCancelled(true); return; } + // If PvP is disabled and damager is a player, cancel damage - else if (arena.inArena(player)) { - if (!pvpEnabled && ((damager instanceof Player && !damager.equals(player)) || damager instanceof Wolf)) { + if (arena.inArena(player)) { + // Repair armor if necessary + repairArmor(player); + + // Cancel PvP damage if disabled + if (!pvpEnabled && damager instanceof Player && !damager.equals(player)) { event.setCancelled(true); return; } @@ -606,12 +617,6 @@ public class ArenaListener event.setCancelled(true); return; } - - // Dirty hack for invincible weapons - ItemStack weapon = p.getInventory().getContents()[p.getInventory().getHeldItemSlot()]; - if (ArenaClass.isWeapon(weapon)) { - weapon.setDurability((short) 0); - } ArenaPlayerStatistics aps = arena.getArenaPlayer(p).getStats(); aps.add("dmgDone", event.getDamage()); @@ -645,6 +650,34 @@ public class ArenaListener } } + private void repairWeapon(Player p) { + ArenaPlayer ap = arena.getArenaPlayer(p); + if (ap != null) { + ArenaClass ac = ap.getArenaClass(); + if (ac != null && ac.hasUnbreakableWeapons()) { + ItemStack weapon = p.getItemInHand(); + if (ArenaClass.isWeapon(weapon)) { + weapon.setDurability((short) 0); + } + } + } + } + + private void repairArmor(Player p) { + ArenaClass ac = arena.getArenaPlayer(p).getArenaClass(); + if (ac != null && ac.hasUnbreakableArmor()) { + PlayerInventory inv = p.getInventory(); + ItemStack stack = inv.getHelmet(); + if (stack != null) stack.setDurability((short) 0); + stack = inv.getChestplate(); + if (stack != null) stack.setDurability((short) 0); + stack = inv.getLeggings(); + if (stack != null) stack.setDurability((short) 0); + stack = inv.getBoots(); + if (stack != null) stack.setDurability((short) 0); + } + } + public void onEntityCombust(EntityCombustEvent event) { if (monsters.getMonsters().contains(event.getEntity())) { if (event instanceof EntityCombustByBlockEvent || event instanceof EntityCombustByEntityEvent) { diff --git a/src/com/garbagemule/MobArena/ArenaMasterImpl.java b/src/com/garbagemule/MobArena/ArenaMasterImpl.java index 72e3fb0..0519b29 100644 --- a/src/com/garbagemule/MobArena/ArenaMasterImpl.java +++ b/src/com/garbagemule/MobArena/ArenaMasterImpl.java @@ -312,11 +312,12 @@ public class ArenaMasterImpl implements ArenaMaster return null; } - // Check if weapons for this class should be unbreakable - boolean unbreakableWeapons = section.getBoolean("unbreakable-weapons", true); + // Check if weapons and armor for this class should be unbreakable + boolean weps = section.getBoolean("unbreakable-weapons", true); + boolean arms = section.getBoolean("unbreakable-armor", true); // Create an ArenaClass with the config-file name. - ArenaClass arenaClass = new ArenaClass(classname, unbreakableWeapons); + ArenaClass arenaClass = new ArenaClass(classname, weps, arms); // Parse the items-node String items = section.getString("items", "");