Add unbreakable-weapons and unbreakable-armor.

This commit is contained in:
garbagemule 2013-08-08 18:23:33 +02:00
parent 345efc9136
commit 76330f06d3
4 changed files with 55 additions and 33 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.95.5.13 version: 0.95.5.14
softdepend: [Spout,Towny,Heroes,MagicSpells,Vault] softdepend: [Spout,Towny,Heroes,MagicSpells,Vault]
commands: commands:
ma: ma:

View File

@ -16,14 +16,13 @@ public class ArenaClass
private List<ItemStack> items, armor; private List<ItemStack> items, armor;
private Map<String,Boolean> perms; private Map<String,Boolean> perms;
private Map<String,Boolean> lobbyperms; private Map<String,Boolean> lobbyperms;
private boolean unbreakableWeapons; private boolean unbreakableWeapons, unbreakableArmor;
private boolean mount;
/** /**
* Create a new, empty arena class with the given name. * Create a new, empty arena class with the given name.
* @param name the class name as it appears in the config-file * @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.configName = name;
this.lowercaseName = name.toLowerCase(); this.lowercaseName = name.toLowerCase();
@ -33,6 +32,7 @@ public class ArenaClass
this.lobbyperms = new HashMap<String,Boolean>(); this.lobbyperms = new HashMap<String,Boolean>();
this.unbreakableWeapons = unbreakableWeapons; this.unbreakableWeapons = unbreakableWeapons;
this.unbreakableArmor = unbreakableArmor;
} }
/** /**
@ -97,29 +97,17 @@ public class ArenaClass
/** /**
* Add an item to the items list. * 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 * @param stack an item
*/ */
public void addItem(ItemStack stack) { public void addItem(ItemStack stack) {
if (stack == null) return; if (stack == null) return;
if (unbreakableWeapons && isWeapon(stack)) { if (stack.getAmount() > 64) {
stack.setDurability(Short.MIN_VALUE);
}
else if (stack.getTypeId() == 170 && stack.getAmount() == 1) {
if (mount) return;
mount = true;
}
else if (stack.getAmount() > 64) {
while (stack.getAmount() > 64) { while (stack.getAmount() > 64) {
items.add(new ItemStack(stack.getType(), 64)); items.add(new ItemStack(stack.getType(), 64));
stack.setAmount(stack.getAmount() - 64); stack.setAmount(stack.getAmount() - 64);
} }
} }
items.add(stack); items.add(stack);
} }
@ -259,8 +247,8 @@ public class ArenaClass
return unbreakableWeapons; return unbreakableWeapons;
} }
public boolean hasMount() { public boolean hasUnbreakableArmor() {
return mount; return unbreakableArmor;
} }
/** /**

View File

@ -56,6 +56,7 @@ import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.material.Attachable; import org.bukkit.material.Attachable;
import org.bukkit.material.Bed; import org.bukkit.material.Bed;
import org.bukkit.material.Door; import org.bukkit.material.Door;
@ -541,6 +542,11 @@ public class ArenaListener
if (damager instanceof Projectile) { if (damager instanceof Projectile) {
damager = ((Projectile) damager).getShooter(); damager = ((Projectile) damager).getShooter();
}
// Repair weapons if necessary
if (damager instanceof Player) {
repairWeapon((Player) damager);
} else if (damager instanceof TNTPrimed) { } else if (damager instanceof TNTPrimed) {
damager = getPlanter(damager); damager = getPlanter(damager);
} }
@ -579,9 +585,14 @@ public class ArenaListener
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
// If PvP is disabled and damager is a player, cancel damage // If PvP is disabled and damager is a player, cancel damage
else if (arena.inArena(player)) { if (arena.inArena(player)) {
if (!pvpEnabled && ((damager instanceof Player && !damager.equals(player)) || damager instanceof Wolf)) { // Repair armor if necessary
repairArmor(player);
// Cancel PvP damage if disabled
if (!pvpEnabled && damager instanceof Player && !damager.equals(player)) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
@ -607,12 +618,6 @@ public class ArenaListener
return; 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(); ArenaPlayerStatistics aps = arena.getArenaPlayer(p).getStats();
aps.add("dmgDone", event.getDamage()); aps.add("dmgDone", event.getDamage());
aps.inc("hits"); aps.inc("hits");
@ -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) { public void onEntityCombust(EntityCombustEvent event) {
if (monsters.getMonsters().contains(event.getEntity())) { if (monsters.getMonsters().contains(event.getEntity())) {
if (event instanceof EntityCombustByBlockEvent || event instanceof EntityCombustByEntityEvent) { if (event instanceof EntityCombustByBlockEvent || event instanceof EntityCombustByEntityEvent) {

View File

@ -312,11 +312,12 @@ public class ArenaMasterImpl implements ArenaMaster
return null; return null;
} }
// Check if weapons for this class should be unbreakable // Check if weapons and armor for this class should be unbreakable
boolean unbreakableWeapons = section.getBoolean("unbreakable-weapons", true); boolean weps = section.getBoolean("unbreakable-weapons", true);
boolean arms = section.getBoolean("unbreakable-armor", true);
// Create an ArenaClass with the config-file name. // 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 // Parse the items-node
String items = section.getString("items", ""); String items = section.getString("items", "");