Make all "damageable" items unbreakable.
This commit changes how the unbreakable setting works by just assuming that everything that is "damageable" (implements the Damageable interface) needs to be set as unbreakable. This means that the entire weapons/armor collection in ArenaClass is obsolete, and all of the checking is contained in ArenaImpl. Fixes #544
This commit is contained in:
@@ -11,6 +11,7 @@ These changes will (most likely) be included in the next version.
|
||||
|
||||
|
||||
## [Unreleased]
|
||||
- Tridents and crossbows are now considered weapons with regards to the `unbreakable-weapons` flag. All class items that have durability now have their unbreakable flag set to true unless the `unbreakable-weapons` and/or `unbreakable-armor` flags are set to `false`.
|
||||
- MobArena no longer crashes when players try to join with items that lower their max health below the default of 20. Players with lower max health will notice missing health in the lobby, but it will quickly regenerate to full.
|
||||
- Food levels no longer deplete for players in the lobby and spectator area.
|
||||
- Wither skeletons now correctly spawn with stone swords.
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.garbagemule.MobArena;
|
||||
|
||||
import static org.bukkit.Material.*;
|
||||
|
||||
import com.garbagemule.MobArena.framework.Arena;
|
||||
import com.garbagemule.MobArena.framework.ArenaMaster;
|
||||
import com.garbagemule.MobArena.things.Thing;
|
||||
@@ -12,7 +10,6 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
@@ -216,78 +213,6 @@ public class ArenaClass
|
||||
return price;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used by isWeapon() to determine if an ItemStack is a weapon type.
|
||||
*/
|
||||
private static EnumSet<Material> weaponTypes = EnumSet.of(
|
||||
WOODEN_SWORD, GOLDEN_SWORD, STONE_SWORD, IRON_SWORD, DIAMOND_SWORD,
|
||||
WOODEN_AXE, GOLDEN_AXE, STONE_AXE, IRON_AXE, DIAMOND_AXE,
|
||||
WOODEN_PICKAXE, GOLDEN_PICKAXE, STONE_PICKAXE, IRON_PICKAXE, DIAMOND_PICKAXE,
|
||||
WOODEN_SHOVEL, GOLDEN_SHOVEL, STONE_SHOVEL, IRON_SHOVEL, DIAMOND_SHOVEL,
|
||||
WOODEN_HOE, GOLDEN_HOE, STONE_HOE, IRON_HOE, DIAMOND_HOE,
|
||||
BOW, FISHING_ROD, FLINT_AND_STEEL, SHEARS, CARROT_ON_A_STICK, SHIELD
|
||||
);
|
||||
|
||||
/**
|
||||
* Returns true, if the ItemStack appears to be a weapon, in which case
|
||||
* the addItem() method will set the weapon durability to the absolute
|
||||
* maximum, as to give them "infinite" durability.
|
||||
* @param stack an ItemStack
|
||||
* @return true, if the item is a weapon
|
||||
*/
|
||||
public static boolean isWeapon(ItemStack stack) {
|
||||
if (stack == null) return false;
|
||||
return weaponTypes.contains(stack.getType());
|
||||
}
|
||||
|
||||
/**
|
||||
* Used by the grantItems() method to determine the armor type of a given
|
||||
* ItemStack. Armor pieces are auto-equipped.
|
||||
* Note: This enum is only necessary for backward-compatibility with the
|
||||
* 'armor'-node.
|
||||
*/
|
||||
public enum ArmorType {
|
||||
HELMET,
|
||||
CHESTPLATE,
|
||||
LEGGINGS,
|
||||
BOOTS;
|
||||
|
||||
public static ArmorType getType(ItemStack stack) {
|
||||
switch (stack.getType()) {
|
||||
case LEATHER_HELMET:
|
||||
case CHAINMAIL_HELMET:
|
||||
case IRON_HELMET:
|
||||
case DIAMOND_HELMET:
|
||||
case GOLDEN_HELMET:
|
||||
return HELMET;
|
||||
|
||||
case LEATHER_CHESTPLATE:
|
||||
case CHAINMAIL_CHESTPLATE:
|
||||
case IRON_CHESTPLATE:
|
||||
case DIAMOND_CHESTPLATE:
|
||||
case GOLDEN_CHESTPLATE:
|
||||
return CHESTPLATE;
|
||||
|
||||
case LEATHER_LEGGINGS:
|
||||
case CHAINMAIL_LEGGINGS:
|
||||
case IRON_LEGGINGS:
|
||||
case DIAMOND_LEGGINGS:
|
||||
case GOLDEN_LEGGINGS:
|
||||
return LEGGINGS;
|
||||
|
||||
case LEATHER_BOOTS:
|
||||
case CHAINMAIL_BOOTS:
|
||||
case IRON_BOOTS:
|
||||
case DIAMOND_BOOTS:
|
||||
case GOLDEN_BOOTS:
|
||||
return BOOTS;
|
||||
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == null) return false;
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.garbagemule.MobArena;
|
||||
|
||||
import static com.garbagemule.MobArena.util.config.ConfigUtils.makeSection;
|
||||
|
||||
import com.garbagemule.MobArena.ArenaClass.ArmorType;
|
||||
import com.garbagemule.MobArena.ScoreboardManager.NullScoreboardManager;
|
||||
import com.garbagemule.MobArena.steps.Step;
|
||||
import com.garbagemule.MobArena.steps.StepFactory;
|
||||
@@ -48,6 +47,7 @@ import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.inventory.meta.Damageable;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.permissions.PermissionAttachment;
|
||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||
@@ -1145,19 +1145,15 @@ public class ArenaImpl implements Arena
|
||||
if (arenaClass.hasUnbreakableWeapons()) {
|
||||
PlayerInventory inv = p.getInventory();
|
||||
for (ItemStack stack : inv.getContents()) {
|
||||
if (ArenaClass.isWeapon(stack)) {
|
||||
makeUnbreakable(stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (arenaClass.hasUnbreakableArmor()) {
|
||||
PlayerInventory inv = p.getInventory();
|
||||
for (ItemStack stack : inv.getArmorContents()) {
|
||||
if (stack != null && ArmorType.getType(stack) != null) {
|
||||
makeUnbreakable(stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
autoReady(p);
|
||||
}
|
||||
@@ -1198,17 +1194,19 @@ public class ArenaImpl implements Arena
|
||||
// Check the remaining three of the four last slots for armor
|
||||
for (int i = contents.length-1; i > contents.length-5; i--) {
|
||||
if (contents[i] == null) continue;
|
||||
ArmorType type = ArmorType.getType(contents[i]);
|
||||
if (type == null || type == ArmorType.HELMET) continue;
|
||||
|
||||
String[] parts = contents[i].getType().name().split("_");
|
||||
String type = parts[parts.length - 1];
|
||||
if (type.equals("HELMET")) continue;
|
||||
|
||||
ItemStack stack = contents[i].clone();
|
||||
if (arenaClass.hasUnbreakableArmor()) {
|
||||
makeUnbreakable(stack);
|
||||
}
|
||||
switch (type) {
|
||||
case CHESTPLATE: chestplate = stack; break;
|
||||
case LEGGINGS: leggings = stack; break;
|
||||
case BOOTS: boots = stack; break;
|
||||
case "CHESTPLATE": chestplate = stack; break;
|
||||
case "LEGGINGS": leggings = stack; break;
|
||||
case "BOOTS": boots = stack; break;
|
||||
default: break;
|
||||
}
|
||||
contents[i] = null;
|
||||
@@ -1218,10 +1216,10 @@ public class ArenaImpl implements Arena
|
||||
ItemStack fifth = contents[contents.length - 5];
|
||||
if (fifth != null) {
|
||||
offhand = fifth.clone();
|
||||
if (arenaClass.hasUnbreakableWeapons() && ArenaClass.isWeapon(fifth)) {
|
||||
if (arenaClass.hasUnbreakableWeapons()) {
|
||||
makeUnbreakable(offhand);
|
||||
}
|
||||
if (arenaClass.hasUnbreakableArmor() && ArmorType.getType(fifth) != null) {
|
||||
if (arenaClass.hasUnbreakableArmor()) {
|
||||
makeUnbreakable(offhand);
|
||||
}
|
||||
contents[contents.length - 5] = null;
|
||||
@@ -1230,11 +1228,9 @@ public class ArenaImpl implements Arena
|
||||
// Check the remaining slots for weapons
|
||||
if (arenaClass.hasUnbreakableWeapons()) {
|
||||
for (ItemStack stack : contents) {
|
||||
if (stack != null && arenaClass.isWeapon(stack)) {
|
||||
makeUnbreakable(stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Set contents, THEN set armor contents
|
||||
inv.setContents(contents);
|
||||
@@ -1251,7 +1247,13 @@ public class ArenaImpl implements Arena
|
||||
}
|
||||
|
||||
private void makeUnbreakable(ItemStack stack) {
|
||||
if (stack == null) {
|
||||
return;
|
||||
}
|
||||
ItemMeta meta = stack.getItemMeta();
|
||||
if (!(meta instanceof Damageable)) {
|
||||
return;
|
||||
}
|
||||
meta.setUnbreakable(true);
|
||||
stack.setItemMeta(meta);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user