mirror of
https://github.com/garbagemule/MobArena.git
synced 2025-01-11 19:00:38 +01:00
Add unbreakable-weapons and unbreakable-armor.
This commit is contained in:
parent
345efc9136
commit
76330f06d3
@ -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:
|
||||
|
@ -16,14 +16,13 @@ public class ArenaClass
|
||||
private List<ItemStack> items, armor;
|
||||
private Map<String,Boolean> perms;
|
||||
private Map<String,Boolean> 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();
|
||||
|
||||
@ -33,6 +32,7 @@ public class ArenaClass
|
||||
this.lobbyperms = new HashMap<String,Boolean>();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@ -259,8 +247,8 @@ public class ArenaClass
|
||||
return unbreakableWeapons;
|
||||
}
|
||||
|
||||
public boolean hasMount() {
|
||||
return mount;
|
||||
public boolean hasUnbreakableArmor() {
|
||||
return unbreakableArmor;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
}
|
||||
@ -607,12 +618,6 @@ public class ArenaListener
|
||||
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());
|
||||
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) {
|
||||
if (monsters.getMonsters().contains(event.getEntity())) {
|
||||
if (event instanceof EntityCombustByBlockEvent || event instanceof EntityCombustByEntityEvent) {
|
||||
|
@ -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", "");
|
||||
|
Loading…
Reference in New Issue
Block a user