New playerloadoutasdefault:true/false setting

Closes gh-491. Players can now safely bring their own inventories in the
warzone. They still get it back after leaving, but now thei own items
can be used to replace the default loadout. You *need* to have a loadout
named "default" available in your warzone.
This commit is contained in:
taoneill 2012-06-19 23:00:37 -04:00
parent 520bac05da
commit b504b5b014
3 changed files with 32 additions and 1 deletions

View File

@ -180,11 +180,13 @@ public class War extends JavaPlugin {
teamDefaultConfig.put(TeamConfig.LIFEPOOL, 7);
teamDefaultConfig.put(TeamConfig.MAXSCORE, 10);
teamDefaultConfig.put(TeamConfig.NOHUNGER, false);
teamDefaultConfig.put(TeamConfig.PLAYERLOADOUTASDEFAULT, false);
teamDefaultConfig.put(TeamConfig.RESPAWNTIMER, 0);
teamDefaultConfig.put(TeamConfig.SATURATION, 10);
teamDefaultConfig.put(TeamConfig.SPAWNSTYLE, TeamSpawnStyle.SMALL);
teamDefaultConfig.put(TeamConfig.TEAMSIZE, 10);
this.getDefaultInventories().getLoadouts().clear();
HashMap<Integer, ItemStack> defaultLoadout = new HashMap<Integer, ItemStack>();

View File

@ -1337,7 +1337,13 @@ public class Warzone {
while (it.hasNext()) {
String name = (String)it.next();
if (i == currentIndex) {
this.resetInventory(playerTeam, player, loadouts.get(name));
if (playerTeam.getTeamConfig().resolveBoolean(TeamConfig.PLAYERLOADOUTASDEFAULT) && name.equals("default")) {
// Use player's own inventory as loadout
this.resetInventory(playerTeam, player, this.getPlayerInventoryFromSavedState(player));
} else {
// Use the loadout from the list in the settings
this.resetInventory(playerTeam, player, loadouts.get(name));
}
if (isFirstRespawn && playerTeam.getInventories().resolveLoadouts().keySet().size() > 1) {
War.war.msg(player, "Equipped " + name + " loadout (sneak to switch).");
} else if (isToggle) {
@ -1349,6 +1355,28 @@ public class Warzone {
}
}
private HashMap<Integer, ItemStack> getPlayerInventoryFromSavedState(Player player) {
HashMap<Integer, ItemStack> playerItems = new HashMap<Integer, ItemStack>();
PlayerState originalState = this.playerStates.get(player.getName());
if (originalState != null) {
int invIndex = 0;
playerItems = new HashMap<Integer, ItemStack>();
for (ItemStack item : originalState.getContents()) {
if (item != null && item.getTypeId() != 0) {
playerItems.put(invIndex, item);
}
invIndex++;
}
if (War.war.isSpoutServer()) {
SpoutManager.getPlayer(player).setTitle(originalState.getPlayerTitle());
}
}
return playerItems;
}
public WarzoneConfigBag getWarzoneConfig() {
return this.warzoneConfig;
}

View File

@ -8,6 +8,7 @@ public enum TeamConfig {
LIFEPOOL (Integer.class),
MAXSCORE (Integer.class),
NOHUNGER (Boolean.class),
PLAYERLOADOUTASDEFAULT (Boolean.class),
RESPAWNTIMER (Integer.class),
SATURATION (Integer.class),
SPAWNSTYLE (TeamSpawnStyle.class),