Fix #74, add blacklist for items brought into zone

/teamcfg loadout:banned will define a set of item types that will be prohibited from entering a warzone when using playerInvAsDefault or otherwise.
This commit is contained in:
Connor Monahan 2017-07-20 18:51:05 -04:00
parent ddfa24f626
commit 372576a396
1 changed files with 30 additions and 12 deletions

View File

@ -535,28 +535,41 @@ public class Warzone {
} }
} }
public void resetInventory(Team team, Player player, Map<Integer, ItemStack> loadout) { private void resetInventory(Team team, Player player, Map<Integer, ItemStack> loadout) {
// Reset inventory to loadout // Reset inventory to loadout
PlayerInventory playerInv = player.getInventory(); PlayerInventory playerInv = player.getInventory();
playerInv.clear(); playerInv.clear();
playerInv.clear(playerInv.getSize() + 0); playerInv.clear(playerInv.getSize());
playerInv.clear(playerInv.getSize() + 1); playerInv.clear(playerInv.getSize() + 1);
playerInv.clear(playerInv.getSize() + 2); playerInv.clear(playerInv.getSize() + 2);
playerInv.clear(playerInv.getSize() + 3); // helmet/blockHead playerInv.clear(playerInv.getSize() + 3); // helmet/blockHead
Loadout banned = Loadout.getLoadout(team.getInventories().resolveNewLoadouts(), "banned");
Set<Material> bannedMaterials = new HashSet<Material>();
if (banned != null) {
for (ItemStack bannedItem : banned.getContents().values()) {
bannedMaterials.add(bannedItem.getType());
}
}
for (Integer slot : loadout.keySet()) { for (Integer slot : loadout.keySet()) {
ItemStack item = loadout.get(slot);
if (item == null || item.getType() == Material.AIR) {
continue;
}
if (bannedMaterials.contains(item.getType())) {
continue;
}
if (slot == 100) { if (slot == 100) {
playerInv.setBoots(loadout.get(slot).clone()); playerInv.setBoots(item.clone());
} else if (slot == 101) { } else if (slot == 101) {
playerInv.setLeggings(loadout.get(slot).clone()); playerInv.setLeggings(item.clone());
} else if (slot == 102) { } else if (slot == 102) {
playerInv.setChestplate(loadout.get(slot).clone()); playerInv.setChestplate(item.clone());
} else if (slot == 103) { } else if (slot == 103) {
playerInv.setHelmet(loadout.get(slot).clone()); playerInv.setHelmet(item.clone());
} else { } else {
ItemStack item = loadout.get(slot); playerInv.addItem(item.clone());
if (item != null) {
playerInv.addItem(item.clone());
}
} }
} }
if (this.getWarzoneConfig().getBoolean(WarzoneConfig.BLOCKHEADS)) { if (this.getWarzoneConfig().getBoolean(WarzoneConfig.BLOCKHEADS)) {
@ -1531,9 +1544,14 @@ public class Warzone {
List<Loadout> loadouts = playerTeam.getInventories().resolveNewLoadouts(); List<Loadout> loadouts = playerTeam.getInventories().resolveNewLoadouts();
List<String> sortedNames = LoadoutYmlMapper.sortNames(Loadout.toLegacyFormat(loadouts)); List<String> sortedNames = LoadoutYmlMapper.sortNames(Loadout.toLegacyFormat(loadouts));
sortedNames.remove("first"); sortedNames.remove("first");
sortedNames.remove("banned");
for (Iterator<String> it = sortedNames.iterator(); it.hasNext();) { for (Iterator<String> it = sortedNames.iterator(); it.hasNext();) {
String loadoutName = it.next(); String loadoutName = it.next();
Loadout ldt = Loadout.getLoadout(loadouts, loadoutName); Loadout ldt = Loadout.getLoadout(loadouts, loadoutName);
if (ldt == null) {
War.war.getLogger().warning("Failed to resolve loadout " + loadoutName);
it.remove();
}
if (ldt.requiresPermission() && !player.hasPermission(ldt.getPermission())) { if (ldt.requiresPermission() && !player.hasPermission(ldt.getPermission())) {
it.remove(); it.remove();
} }
@ -1555,9 +1573,9 @@ public class Warzone {
// Use player's own inventory as loadout // Use player's own inventory as loadout
this.resetInventory(playerTeam, player, this.getPlayerInventoryFromSavedState(player)); this.resetInventory(playerTeam, player, this.getPlayerInventoryFromSavedState(player));
} else if (isFirstRespawn && firstLoadout != null && name.equals("default") } else if (isFirstRespawn && firstLoadout != null && name.equals("default")
&& (firstLoadout.requiresPermission() ? player.hasPermission(firstLoadout.getPermission()) : true)) { && (!firstLoadout.requiresPermission() || player.hasPermission(firstLoadout.getPermission()))) {
// Get the loadout for the first spawn // Get the loadout for the first spawn
this.resetInventory(playerTeam, player, Loadout.getLoadout(loadouts, "first").getContents()); this.resetInventory(playerTeam, player, firstLoadout.getContents());
} else { } else {
// Use the loadout from the list in the settings // Use the loadout from the list in the settings
this.resetInventory(playerTeam, player, Loadout.getLoadout(loadouts, name).getContents()); this.resetInventory(playerTeam, player, Loadout.getLoadout(loadouts, name).getContents());