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 name: MobArena
author: garbagemule author: garbagemule
main: com.garbagemule.MobArena.MobArena main: com.garbagemule.MobArena.MobArena
version: 0.96.4.3 version: 0.96.4.4
softdepend: [Multiverse-Core,Towny,Heroes,MagicSpells,Vault] softdepend: [Multiverse-Core,Towny,Heroes,MagicSpells,Vault]
commands: commands:
ma: ma:

View File

@ -1,10 +1,6 @@
package com.garbagemule.MobArena; package com.garbagemule.MobArena;
import java.util.HashSet; import java.util.*;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
import java.util.Set;
import com.garbagemule.MobArena.events.ArenaKillEvent; import com.garbagemule.MobArena.events.ArenaKillEvent;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -621,7 +617,6 @@ public class ArenaListener
return; return;
} }
// If PvP is disabled and damager is a player, cancel damage
if (arena.inArena(player)) { if (arena.inArena(player)) {
// Repair armor if necessary // Repair armor if necessary
repairArmor(player); repairArmor(player);
@ -679,20 +674,33 @@ public class ArenaListener
if (!pvpEnabled) { if (!pvpEnabled) {
event.setCancelled(true); 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) { private void repairWeapon(Player p) {
ArenaPlayer ap = arena.getArenaPlayer(p); ArenaPlayer ap = arena.getArenaPlayer(p);
if (ap != null) { if (ap != null) {
ArenaClass ac = ap.getArenaClass(); ArenaClass ac = ap.getArenaClass();
if (ac != null && ac.hasUnbreakableWeapons()) { if (ac != null && ac.hasUnbreakableWeapons()) {
ItemStack weapon = p.getItemInHand(); repair(p.getItemInHand());
if (ArenaClass.isWeapon(weapon)) {
weapon.setDurability((short) 0);
}
} }
} }
} }
@ -701,14 +709,16 @@ public class ArenaListener
ArenaClass ac = arena.getArenaPlayer(p).getArenaClass(); ArenaClass ac = arena.getArenaPlayer(p).getArenaClass();
if (ac != null && ac.hasUnbreakableArmor()) { if (ac != null && ac.hasUnbreakableArmor()) {
PlayerInventory inv = p.getInventory(); PlayerInventory inv = p.getInventory();
ItemStack stack = inv.getHelmet(); repair(inv.getHelmet());
if (stack != null) stack.setDurability((short) 0); repair(inv.getChestplate());
stack = inv.getChestplate(); repair(inv.getLeggings());
if (stack != null) stack.setDurability((short) 0); repair(inv.getBoots());
stack = inv.getLeggings(); }
if (stack != null) stack.setDurability((short) 0); }
stack = inv.getBoots();
if (stack != null) stack.setDurability((short) 0); private void repair(ItemStack stack) {
if (stack != null && REPAIRABLE_TYPES.contains(stack.getType())) {
stack.setDurability((short) 0);
} }
} }