From 48311e4d95138cf7fc5119f2eaf207576df270da Mon Sep 17 00:00:00 2001 From: taoneill Date: Sat, 17 Sep 2011 00:21:26 -0400 Subject: [PATCH] Working extraLoadouts/classes system. Do /zonecfg loadout:warrior, etc. Simply sneak while in spawn to switch between the available loadouts/classes. --- .../main/java/bukkit/tommytony/war/War.java | 2 +- .../tommytony/war/WarPlayerListener.java | 36 +++++++++++++------ .../tommytony/war/mappers/WarzoneMapper.java | 2 +- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/war/src/main/java/bukkit/tommytony/war/War.java b/war/src/main/java/bukkit/tommytony/war/War.java index 3b93f9b..52199e3 100644 --- a/war/src/main/java/bukkit/tommytony/war/War.java +++ b/war/src/main/java/bukkit/tommytony/war/War.java @@ -368,7 +368,7 @@ public class War extends JavaPlugin { } this.inventoryToLoadout(player, extraLoadout); } - returnMessage.append(loadoutName + " respawn loadout updated."); + returnMessage.append(" " + loadoutName + " respawn loadout updated."); } if (namedParams.containsKey("reward")) { this.inventoryToLoadout(player, warzone.getReward()); diff --git a/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java b/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java index 588deda..af12278 100644 --- a/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java +++ b/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java @@ -2,6 +2,7 @@ package bukkit.tommytony.war; import java.util.HashMap; import java.util.Iterator; +import java.util.Map; import org.bukkit.ChatColor; import org.bukkit.Location; @@ -470,19 +471,32 @@ public class WarPlayerListener extends PlayerListener { public void onPlayerToggleSneak(PlayerToggleSneakEvent event) { if (War.war.isLoaded() && event.isSneaking()) { Warzone playerWarzone = Warzone.getZoneByLocation(event.getPlayer()); - if (playerWarzone != null && playerWarzone.getNewlyRespawned().keySet().contains(event.getPlayer().getName())) { - Integer currentIndex = playerWarzone.getNewlyRespawned().get(event.getPlayer().getName()); - currentIndex = (currentIndex + 1) % (playerWarzone.getExtraLoadouts().keySet().size() + 1); - playerWarzone.getNewlyRespawned().put(event.getPlayer().getName(), currentIndex); - - Team playerTeam = Team.getTeamByPlayerName(event.getPlayer().getName()); - - if (currentIndex == 0) { - playerWarzone.resetInventory(playerTeam, event.getPlayer(), playerWarzone.getLoadout()); + Team playerTeam = Team.getTeamByPlayerName(event.getPlayer().getName()); + if (playerWarzone != null && playerTeam.getSpawnVolume().contains(event.getPlayer().getLocation())) { + if (playerWarzone.getNewlyRespawned().keySet().contains(event.getPlayer().getName())) { + Integer currentIndex = playerWarzone.getNewlyRespawned().get(event.getPlayer().getName()); + currentIndex = (currentIndex + 1) % (playerWarzone.getExtraLoadouts().keySet().size() + 1); + playerWarzone.getNewlyRespawned().put(event.getPlayer().getName(), currentIndex); + + if (currentIndex == 0) { + playerWarzone.resetInventory(playerTeam, event.getPlayer(), playerWarzone.getLoadout()); + War.war.msg(event.getPlayer(), "Equiped default loadout."); + } else { + int i = 0; + Iterator it = playerWarzone.getExtraLoadouts().entrySet().iterator(); + while (it.hasNext()) { + Map.Entry pairs = (Map.Entry)it.next(); + if (i == currentIndex - 1) { + playerWarzone.resetInventory(playerTeam, event.getPlayer(), (HashMap)pairs.getValue()); + War.war.msg(event.getPlayer(), "Equiped " + pairs.getKey() + " loadout."); + } + i++; + } + } } else { - String[] array = (String[]) playerWarzone.getExtraLoadouts().keySet().toArray(); - playerWarzone.resetInventory(playerTeam, event.getPlayer(), playerWarzone.getExtraLoadouts().get(array[currentIndex-1])); + War.war.badMsg(event.getPlayer(), "Can't change loadout after exiting the spawn."); } + } } } diff --git a/war/src/main/java/com/tommytony/war/mappers/WarzoneMapper.java b/war/src/main/java/com/tommytony/war/mappers/WarzoneMapper.java index 1553d2a..e99866f 100644 --- a/war/src/main/java/com/tommytony/war/mappers/WarzoneMapper.java +++ b/war/src/main/java/com/tommytony/war/mappers/WarzoneMapper.java @@ -154,7 +154,7 @@ public class WarzoneMapper { for (String extraName : warzone.getExtraLoadouts().keySet()) { String loadoutString = warzoneConfig.getString(extraName + "Loadout"); String[] loadoutSplit = loadoutString.split(";"); - HashMap loadout = War.war.getDefaultExtraLoadouts().get(extraName); + HashMap loadout = warzone.getExtraLoadouts().get(extraName); loadout.clear(); for (String str : loadoutSplit) { if (str != null && !str.equals("")) {