Add support for off-hand items.

This commit is contained in:
garbagemule
2016-12-29 17:56:32 +01:00
committed by Andreas Troelsen
parent 558681a2f2
commit 8705b5c9f7
4 changed files with 29 additions and 1 deletions
@@ -13,7 +13,7 @@ import org.bukkit.permissions.PermissionAttachment;
public class ArenaClass public class ArenaClass
{ {
private String configName, lowercaseName; private String configName, lowercaseName;
private ItemStack helmet, chestplate, leggings, boots; private ItemStack helmet, chestplate, leggings, boots, offhand;
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;
@@ -100,6 +100,14 @@ public class ArenaClass
this.boots = boots; this.boots = boots;
} }
/**
* Set the off-hand slot for the class.
* @param offHand
*/
public void setOffHand(ItemStack offHand) {
this.offhand = offHand;
}
/** /**
* Add an item to the items list. * Add an item to the items list.
* @param stack an item * @param stack an item
@@ -182,6 +190,7 @@ public class ArenaClass
if (chestplate != null) inv.setChestplate(chestplate); if (chestplate != null) inv.setChestplate(chestplate);
if (leggings != null) inv.setLeggings(leggings); if (leggings != null) inv.setLeggings(leggings);
if (boots != null) inv.setBoots(boots); if (boots != null) inv.setBoots(boots);
if (offhand != null) inv.setItemInOffHand(offhand);
} }
/** /**
@@ -1124,6 +1124,7 @@ public class ArenaImpl implements Arena
ItemStack chestplate = null; ItemStack chestplate = null;
ItemStack leggings = null; ItemStack leggings = null;
ItemStack boots = null; ItemStack boots = null;
ItemStack offhand = null;
// Check the very last slot to see if it'll work as a helmet // Check the very last slot to see if it'll work as a helmet
int last = contents.length-1; int last = contents.length-1;
@@ -1147,6 +1148,13 @@ public class ArenaImpl implements Arena
contents[i] = null; contents[i] = null;
} }
// Equip the fifth last slot as the off-hand
ItemStack fifth = contents[contents.length - 5];
if (fifth != null) {
offhand = fifth.clone();
contents[contents.length - 5] = null;
}
// Check the remaining slots for weapons // Check the remaining slots for weapons
if (arenaClass.hasUnbreakableWeapons()) { if (arenaClass.hasUnbreakableWeapons()) {
for (ItemStack stack : contents) { for (ItemStack stack : contents) {
@@ -1162,6 +1170,7 @@ public class ArenaImpl implements Arena
inv.setChestplate(chestplate); inv.setChestplate(chestplate);
inv.setLeggings(leggings); inv.setLeggings(leggings);
inv.setBoots(boots); inv.setBoots(boots);
inv.setItemInOffHand(offhand);
PermissionAttachment pa = arenaClass.grantLobbyPermissions(plugin, p); PermissionAttachment pa = arenaClass.grantLobbyPermissions(plugin, p);
replacePermissions(p, pa); replacePermissions(p, pa);
@@ -338,18 +338,21 @@ public class ArenaMasterImpl implements ArenaMaster
String chest = section.getString("chestplate", null); String chest = section.getString("chestplate", null);
String legs = section.getString("leggings", null); String legs = section.getString("leggings", null);
String feet = section.getString("boots", null); String feet = section.getString("boots", null);
String off = section.getString("offhand", null);
// Parse to ItemStacks // Parse to ItemStacks
ItemStack helmet = ItemParser.parseItem(head); ItemStack helmet = ItemParser.parseItem(head);
ItemStack chestplate = ItemParser.parseItem(chest); ItemStack chestplate = ItemParser.parseItem(chest);
ItemStack leggings = ItemParser.parseItem(legs); ItemStack leggings = ItemParser.parseItem(legs);
ItemStack boots = ItemParser.parseItem(feet); ItemStack boots = ItemParser.parseItem(feet);
ItemStack offhand = ItemParser.parseItem(off);
// Set in ArenaClass // Set in ArenaClass
arenaClass.setHelmet(helmet); arenaClass.setHelmet(helmet);
arenaClass.setChestplate(chestplate); arenaClass.setChestplate(chestplate);
arenaClass.setLeggings(leggings); arenaClass.setLeggings(leggings);
arenaClass.setBoots(boots); arenaClass.setBoots(boots);
arenaClass.setOffHand(offhand);
// Per-class permissions // Per-class permissions
loadClassPermissions(arenaClass, section); loadClassPermissions(arenaClass, section);
@@ -420,6 +423,12 @@ public class ArenaMasterImpl implements ArenaMaster
section.set("helmet", ItemParser.parseString(helmet)); section.set("helmet", ItemParser.parseString(helmet));
} }
// Include the off-hand
ItemStack offhand = inv.getItemInOffHand();
if (offhand != null) {
section.set("offhand", ItemParser.parseString(offhand));
}
// Save changes. // Save changes.
plugin.saveConfig(); plugin.saveConfig();
@@ -94,6 +94,7 @@ public class InventoryManager
inv.setChestplate(null); inv.setChestplate(null);
inv.setLeggings(null); inv.setLeggings(null);
inv.setBoots(null); inv.setBoots(null);
inv.setItemInOffHand(null);
InventoryView view = p.getOpenInventory(); InventoryView view = p.getOpenInventory();
if (view != null) { if (view != null) {
view.setCursor(null); view.setCursor(null);