From 8dac3f4ea9ffb321c271653e541640495de39088 Mon Sep 17 00:00:00 2001 From: cmastudios Date: Thu, 7 Mar 2013 18:13:39 -0600 Subject: [PATCH] Fixes gh-608 - loadout "first" will be given on join and each battle after When a player joins a warzone for the first time, they will be given a loadout called "first" instead of the default loadout. After they have died once, they will receive the default loadout. Players will also be assigned the "first" loadout every battle if they are on the default loadout when the battle ends. I do not know how servers will deal with players who might constantly leave and rejoin the zone in order to get the loadout back. This could be fixed with a war change if it becomes necessary (maybe remember the player until the battle ends). But, as always, if a server does not want to have a "first" loadout in a warzone, they do not have to create one. --- .../main/java/com/tommytony/war/Warzone.java | 35 ++++++++++++------- .../war/event/WarPlayerListener.java | 3 +- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/war/src/main/java/com/tommytony/war/Warzone.java b/war/src/main/java/com/tommytony/war/Warzone.java index 927d4e4..ead2bd2 100644 --- a/war/src/main/java/com/tommytony/war/Warzone.java +++ b/war/src/main/java/com/tommytony/war/Warzone.java @@ -387,6 +387,9 @@ public class Warzone { if (!this.getLoadoutSelections().keySet().contains(player.getName())) { isFirstRespawn = true; this.getLoadoutSelections().put(player.getName(), new LoadoutSelection(true, 0)); + } else if (this.isReinitializing) { + isFirstRespawn = true; + this.getLoadoutSelections().get(player.getName()).setStillInSpawn(true); } else { this.getLoadoutSelections().get(player.getName()).setStillInSpawn(true); } @@ -1328,28 +1331,34 @@ public class Warzone { // - repawn timer + this method is why inventories were getting wiped as players exited the warzone. HashMap> loadouts = playerTeam.getInventories().resolveLoadouts(); List sortedNames = LoadoutYmlMapper.sortNames(loadouts); + if (sortedNames.contains("first")) { + sortedNames.remove("first"); + } int currentIndex = selection.getSelectedIndex(); int i = 0; Iterator it = sortedNames.iterator(); - while (it.hasNext()) { - String name = (String)it.next(); - if (i == currentIndex) { - 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)); - } + while (it.hasNext()) { + String name = (String) it.next(); + if (i == currentIndex) { + if (playerTeam.getTeamConfig().resolveBoolean(TeamConfig.PLAYERLOADOUTASDEFAULT) && name.equals("default")) { + // Use player's own inventory as loadout + this.resetInventory(playerTeam, player, this.getPlayerInventoryFromSavedState(player)); + } else if (isFirstRespawn && loadouts.containsKey("first") && name.equals("default")) { + // Get the loadout for the first spawn + this.resetInventory(playerTeam, player, loadouts.get("first")); + } 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) { War.war.msg(player, "Equipped " + name + " loadout."); } - } - i++; - } + } + i++; + } } } diff --git a/war/src/main/java/com/tommytony/war/event/WarPlayerListener.java b/war/src/main/java/com/tommytony/war/event/WarPlayerListener.java index fd2663f..25eae22 100644 --- a/war/src/main/java/com/tommytony/war/event/WarPlayerListener.java +++ b/war/src/main/java/com/tommytony/war/event/WarPlayerListener.java @@ -820,7 +820,8 @@ public class WarPlayerListener implements Listener { if (playerWarzone.getLoadoutSelections().keySet().contains(event.getPlayer().getName()) && playerWarzone.getLoadoutSelections().get(event.getPlayer().getName()).isStillInSpawn()) { LoadoutSelection selection = playerWarzone.getLoadoutSelections().get(event.getPlayer().getName()); - int currentIndex = (selection.getSelectedIndex() + 1) % (playerTeam.getInventories().resolveLoadouts().keySet().size()); + boolean hasFirstLoadout = playerTeam.getInventories().resolveLoadouts().containsKey("first"); + int currentIndex = (selection.getSelectedIndex() + 1) % (playerTeam.getInventories().resolveLoadouts().keySet().size() - (hasFirstLoadout ? 1 : 0)); selection.setSelectedIndex(currentIndex); playerWarzone.equipPlayerLoadoutSelection(event.getPlayer(), playerTeam, false, true);