Refactor weapon/armor checking, fix skulls resetting on damage.

This commit is contained in:
garbagemule 2014-05-01 01:55:33 +02:00
parent 0182132337
commit 021b43179f
2 changed files with 30 additions and 20 deletions

View File

@ -1,7 +1,7 @@
name: MobArena
author: garbagemule
main: com.garbagemule.MobArena.MobArena
version: 0.96.4.3
version: 0.96.4.4
softdepend: [Multiverse-Core,Towny,Heroes,MagicSpells,Vault]
commands:
ma:

View File

@ -1,10 +1,6 @@
package com.garbagemule.MobArena;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
import java.util.Set;
import java.util.*;
import com.garbagemule.MobArena.events.ArenaKillEvent;
import org.bukkit.ChatColor;
@ -621,7 +617,6 @@ public class ArenaListener
return;
}
// If PvP is disabled and damager is a player, cancel damage
if (arena.inArena(player)) {
// Repair armor if necessary
repairArmor(player);
@ -679,20 +674,33 @@ public class ArenaListener
if (!pvpEnabled) {
event.setCancelled(true);
return;
}
}
}
private static final EnumSet<Material> REPAIRABLE_TYPES = EnumSet.of(
// Tools and swords
Material.GOLD_AXE, Material.GOLD_HOE, Material.GOLD_PICKAXE, Material.GOLD_SPADE, Material.GOLD_SWORD,
Material.WOOD_AXE, Material.WOOD_HOE, Material.WOOD_PICKAXE, Material.WOOD_SPADE, Material.WOOD_SWORD,
Material.STONE_AXE, Material.STONE_HOE, Material.STONE_PICKAXE, Material.STONE_SPADE, Material.STONE_SWORD,
Material.IRON_AXE, Material.IRON_HOE, Material.IRON_PICKAXE, Material.IRON_SPADE, Material.IRON_SWORD,
Material.DIAMOND_AXE, Material.DIAMOND_HOE, Material.DIAMOND_PICKAXE, Material.DIAMOND_SPADE, Material.DIAMOND_SWORD,
// Armor
Material.LEATHER_HELMET, Material.LEATHER_CHESTPLATE, Material.LEATHER_LEGGINGS, Material.LEATHER_BOOTS,
Material.GOLD_HELMET, Material.GOLD_CHESTPLATE, Material.GOLD_LEGGINGS, Material.GOLD_BOOTS,
Material.CHAINMAIL_HELMET, Material.CHAINMAIL_CHESTPLATE, Material.CHAINMAIL_LEGGINGS, Material.CHAINMAIL_BOOTS,
Material.IRON_HELMET, Material.IRON_CHESTPLATE, Material.IRON_LEGGINGS, Material.IRON_BOOTS,
Material.DIAMOND_HELMET, Material.DIAMOND_CHESTPLATE, Material.DIAMOND_LEGGINGS, Material.DIAMOND_BOOTS,
// Misc
Material.BOW, Material.FLINT_AND_STEEL, Material.FISHING_ROD, Material.SHEARS, Material.CARROT_STICK
);
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);
}
repair(p.getItemInHand());
}
}
}
@ -701,14 +709,16 @@ public class ArenaListener
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);
repair(inv.getHelmet());
repair(inv.getChestplate());
repair(inv.getLeggings());
repair(inv.getBoots());
}
}
private void repair(ItemStack stack) {
if (stack != null && REPAIRABLE_TYPES.contains(stack.getType())) {
stack.setDurability((short) 0);
}
}