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);