Fixed Yaml loader and another ton of bugs related to cascading configs and the /teamcfg command. Also tweaked /zonecfg so that you can change another warzone's config while standing in another warzone (the one you were in always took over). Made printing of configs more pretty and now printing loadouts.

This commit is contained in:
taoneill 2012-01-07 00:20:02 -05:00
parent 143afa4473
commit 1bae53670e
8 changed files with 118 additions and 55 deletions

View File

@ -543,9 +543,13 @@ public class War extends JavaPlugin {
public String printConfig(Team team) { public String printConfig(Team team) {
ChatColor teamColor = ChatColor.AQUA; ChatColor teamColor = ChatColor.AQUA;
ChatColor normalColor = ChatColor.WHITE; ChatColor normalColor = ChatColor.WHITE;
String teamConfigStr = ""; String teamConfigStr = "";
InventoryBag invs = team.getInventories();
teamConfigStr += getLoadoutsString(invs);
for (TeamConfig teamConfig : TeamConfig.values()) { for (TeamConfig teamConfig : TeamConfig.values()) {
Object value = team.getTeamConfig().getValue(teamConfig); Object value = team.getTeamConfig().getValue(teamConfig);
if (value != null) { if (value != null) {
@ -553,14 +557,33 @@ public class War extends JavaPlugin {
} }
} }
return teamColor + " ::" + normalColor + "Team " + team.getName() + " config" + teamColor + "::" + normalColor return " ::" + teamColor + "Team " + team.getName() + teamColor + " config" + normalColor + "::"
+ ifEmptyInheritedForTeam(teamConfigStr); + ifEmptyInheritedForTeam(teamConfigStr);
} }
private String getLoadoutsString(InventoryBag invs) {
String loadoutsString = "";
ChatColor loadoutColor = ChatColor.GREEN;
ChatColor normalColor = ChatColor.WHITE;
if (invs.hasLoadouts()) {
String loadouts = "";
for (String loadoutName : invs.getLoadouts().keySet()) {
loadouts += loadoutName + ",";
}
loadoutsString += " loadout:" + loadoutColor + loadouts + normalColor;
}
if (invs.hasReward()) {
loadoutsString += " reward:" + loadoutColor + "default" + normalColor;
}
return loadoutsString;
}
public String printConfig(Warzone zone) { public String printConfig(Warzone zone) {
ChatColor teamColor = ChatColor.AQUA; ChatColor teamColor = ChatColor.AQUA;
ChatColor zoneColor = ChatColor.RED; ChatColor zoneColor = ChatColor.DARK_AQUA;
ChatColor authorColor = ChatColor.GREEN; ChatColor authorColor = ChatColor.GREEN;
ChatColor normalColor = ChatColor.WHITE; ChatColor normalColor = ChatColor.WHITE;
@ -573,6 +596,7 @@ public class War extends JavaPlugin {
} }
String teamDefaultsStr = ""; String teamDefaultsStr = "";
teamDefaultsStr += getLoadoutsString( zone.getDefaultInventories());
for (TeamConfig teamConfig : TeamConfig.values()) { for (TeamConfig teamConfig : TeamConfig.values()) {
Object value = zone.getTeamDefaultConfig().getValue(teamConfig); Object value = zone.getTeamDefaultConfig().getValue(teamConfig);
if (value != null) { if (value != null) {
@ -580,10 +604,10 @@ public class War extends JavaPlugin {
} }
} }
return zoneColor + "::" + normalColor + "Warzone " + zone.getName() + " config" + zoneColor + "::" + normalColor return "::" + zoneColor + "Warzone " + authorColor + zone.getName() + zoneColor + " config" + normalColor + "::"
+ " author:" + authorColor + ifEmptyEveryone(zone.getAuthorsString()) + normalColor + " author:" + authorColor + ifEmptyEveryone(zone.getAuthorsString()) + normalColor
+ ifEmptyInheritedForWarzone(warzoneConfigStr) + ifEmptyInheritedForWarzone(warzoneConfigStr)
+ teamColor + " ::" + normalColor + "Team defaults" + teamColor + "::" + normalColor + " ::" + teamColor + "Team defaults" + normalColor + "::"
+ ifEmptyInheritedForWarzone(teamDefaultsStr); + ifEmptyInheritedForWarzone(teamDefaultsStr);
} }
@ -611,8 +635,8 @@ public class War extends JavaPlugin {
public String printConfig() { public String printConfig() {
ChatColor teamColor = ChatColor.AQUA; ChatColor teamColor = ChatColor.AQUA;
ChatColor zoneColor = ChatColor.RED; ChatColor zoneColor = ChatColor.DARK_AQUA;
ChatColor globalColor = ChatColor.GREEN; ChatColor globalColor = ChatColor.DARK_GREEN;
ChatColor normalColor = ChatColor.WHITE; ChatColor normalColor = ChatColor.WHITE;
String warConfigStr = ""; String warConfigStr = "";
@ -626,13 +650,14 @@ public class War extends JavaPlugin {
} }
String teamDefaultsStr = ""; String teamDefaultsStr = "";
teamDefaultsStr += getLoadoutsString(this.getDefaultInventories());
for (TeamConfig teamConfig : TeamConfig.values()) { for (TeamConfig teamConfig : TeamConfig.values()) {
teamDefaultsStr += " " + teamConfig.toStringWithValue(this.getTeamDefaultConfig().getValue(teamConfig)).replace(":", ":" + teamColor) + normalColor; teamDefaultsStr += " " + teamConfig.toStringWithValue(this.getTeamDefaultConfig().getValue(teamConfig)).replace(":", ":" + teamColor) + normalColor;
} }
return globalColor + "::" + normalColor + "War config" + globalColor + "::" + normalColor + warConfigStr return normalColor + "::" + globalColor + "War config" + normalColor + "::" + warConfigStr
+ zoneColor + " ::" + normalColor + "Warzone defaults" + zoneColor + "::" + normalColor + warzoneDefaultsStr + normalColor + " ::" + zoneColor + "Warzone defaults" + normalColor + "::" + warzoneDefaultsStr
+ teamColor + " ::" + normalColor + "Team defaults" + teamColor + "::" + normalColor + teamDefaultsStr; + normalColor + " ::" + teamColor + "Team defaults" + normalColor + "::" + teamDefaultsStr;
} }
private void setZoneRallyPoint(String warzoneName, Player player) { private void setZoneRallyPoint(String warzoneName, Player player) {

View File

@ -26,6 +26,8 @@ public class SetTeamConfigCommand extends AbstractZoneMakerCommand {
boolean isFirstParamWarzone = false; boolean isFirstParamWarzone = false;
boolean wantsToPrint = false; boolean wantsToPrint = false;
Team team = null;
if (this.args.length == 0) { if (this.args.length == 0) {
return false; return false;
} else { } else {
@ -43,6 +45,8 @@ public class SetTeamConfigCommand extends AbstractZoneMakerCommand {
if (this.getSender() instanceof Player) { if (this.getSender() instanceof Player) {
player = (Player) commandSender; player = (Player) commandSender;
if (zone == null) {
// zone not found, is he standing in it?
Warzone zoneByLoc = Warzone.getZoneByLocation(player); Warzone zoneByLoc = Warzone.getZoneByLocation(player);
ZoneLobby lobbyByLoc = ZoneLobby.getLobbyByLocation(player); ZoneLobby lobbyByLoc = ZoneLobby.getLobbyByLocation(player);
if (zoneByLoc == null && lobbyByLoc != null) { if (zoneByLoc == null && lobbyByLoc != null) {
@ -53,6 +57,9 @@ public class SetTeamConfigCommand extends AbstractZoneMakerCommand {
} }
} }
team = Team.getTeamByPlayerName(player.getName());
}
if (zone == null) { if (zone == null) {
// No warzone found, whatever the mean, escape // No warzone found, whatever the mean, escape
return false; return false;
@ -62,7 +69,7 @@ public class SetTeamConfigCommand extends AbstractZoneMakerCommand {
if (isFirstParamWarzone) { if (isFirstParamWarzone) {
if (this.args.length == 1) { if (this.args.length == 1) {
// Only one param: the warzone name - default to usage // Only one param: the warzone name - pritn usage
return false; return false;
} }
// More than one param: the arguments need to be shifted // More than one param: the arguments need to be shifted
@ -74,23 +81,33 @@ public class SetTeamConfigCommand extends AbstractZoneMakerCommand {
} }
// args have been shifted if needed // args have been shifted if needed
Team team = null;
if (this.args.length > 0) { if (this.args.length > 0) {
// only printing
TeamKind kind = TeamKind.teamKindFromString(this.args[0]); TeamKind kind = TeamKind.teamKindFromString(this.args[0]);
team = zone.getTeamByKind(kind); Team teamByName = zone.getTeamByKind(kind);
if (team == null) { if (team == null && teamByName == null) {
// Team not found // Team not found
return false; this.badMsg("No such team. Use /teams.");
return true;
} else if (this.args.length == 1 && teamByName != null) {
// only team name, print config
this.msg(War.war.printConfig(teamByName));
return true;
} }
if (teamByName != null) {
// first param was team, shift again // first param was team, shift again
String[] newargs = new String[this.args.length - 1]; String[] newargs = new String[this.args.length - 1];
for (int i = 1; i < this.args.length; i++) { for (int i = 1; i < this.args.length; i++) {
newargs[i - 1] = this.args[i]; newargs[i - 1] = this.args[i];
} }
this.args = newargs; this.args = newargs;
}
if (teamByName != null) {
// Named team > player's team
team = teamByName;
}
} else { } else {
// No team param, show usage // No team param, show usage
return false; return false;

View File

@ -40,7 +40,8 @@ public class SetZoneConfigCommand extends AbstractZoneMakerCommand {
if (this.getSender() instanceof Player) { if (this.getSender() instanceof Player) {
player = (Player) commandSender; player = (Player) commandSender;
if (zone == null) {
// zone not found, is he standing in it?
Warzone zoneByLoc = Warzone.getZoneByLocation(player); Warzone zoneByLoc = Warzone.getZoneByLocation(player);
ZoneLobby lobbyByLoc = ZoneLobby.getLobbyByLocation(player); ZoneLobby lobbyByLoc = ZoneLobby.getLobbyByLocation(player);
if (zoneByLoc == null && lobbyByLoc != null) { if (zoneByLoc == null && lobbyByLoc != null) {
@ -50,6 +51,7 @@ public class SetZoneConfigCommand extends AbstractZoneMakerCommand {
zone = zoneByLoc; zone = zoneByLoc;
} }
} }
}
if (zone == null) { if (zone == null) {
// No warzone found, whatever the mean, escape // No warzone found, whatever the mean, escape

View File

@ -36,12 +36,14 @@ public class Team {
private Volume flagVolume; private Volume flagVolume;
private final Warzone warzone; private final Warzone warzone;
private TeamKind kind; private TeamKind kind;
private InventoryBag inventories = new InventoryBag();
private TeamConfigBag teamConfig; private TeamConfigBag teamConfig;
private InventoryBag inventories;
public Team(String name, TeamKind kind, Location teamSpawn, Warzone warzone) { public Team(String name, TeamKind kind, Location teamSpawn, Warzone warzone) {
this.warzone = warzone; this.warzone = warzone;
this.teamConfig = new TeamConfigBag(warzone); this.teamConfig = new TeamConfigBag(warzone);
this.inventories = new InventoryBag(warzone); // important constructors for cascading configs
this.setName(name); this.setName(name);
this.teamSpawn = teamSpawn; this.teamSpawn = teamSpawn;
this.setSpawnVolume(new Volume(name, warzone.getWorld())); this.setSpawnVolume(new Volume(name, warzone.getWorld()));

View File

@ -34,6 +34,7 @@ import com.tommytony.war.config.WarzoneConfigBag;
import com.tommytony.war.jobs.InitZoneJob; import com.tommytony.war.jobs.InitZoneJob;
import com.tommytony.war.jobs.LoadoutResetJob; import com.tommytony.war.jobs.LoadoutResetJob;
import com.tommytony.war.jobs.ScoreCapReachedJob; import com.tommytony.war.jobs.ScoreCapReachedJob;
import com.tommytony.war.mappers.LoadoutYmlMapper;
import com.tommytony.war.utils.PlayerState; import com.tommytony.war.utils.PlayerState;
import com.tommytony.war.volumes.ZoneVolume; import com.tommytony.war.volumes.ZoneVolume;
@ -1024,17 +1025,20 @@ public class Warzone {
public void equipPlayerLoadoutSelection(Player player, Team playerTeam, boolean isFirstRespawn, boolean isToggle) { public void equipPlayerLoadoutSelection(Player player, Team playerTeam, boolean isFirstRespawn, boolean isToggle) {
LoadoutSelection selection = this.getLoadoutSelections().get(player.getName()); LoadoutSelection selection = this.getLoadoutSelections().get(player.getName());
if (selection != null && !this.isRespawning(player)) { if (selection != null && !this.isRespawning(player)) {
HashMap<String, HashMap<Integer, ItemStack>> loadouts = playerTeam.getInventories().resolveLoadouts();
List<String> sortedNames = LoadoutYmlMapper.sortNames(loadouts);
int currentIndex = selection.getSelectedIndex(); int currentIndex = selection.getSelectedIndex();
int i = 0; int i = 0;
Iterator it = playerTeam.getInventories().resolveLoadouts().entrySet().iterator(); Iterator<String> it = sortedNames.iterator();
while (it.hasNext()) { while (it.hasNext()) {
Map.Entry pairs = (Map.Entry)it.next(); String name = (String)it.next();
if (i == currentIndex) { if (i == currentIndex) {
this.resetInventory(playerTeam, player, (HashMap<Integer, ItemStack>)pairs.getValue()); this.resetInventory(playerTeam, player, loadouts.get(name));
if (isFirstRespawn && playerTeam.getInventories().resolveLoadouts().keySet().size() > 1) { if (isFirstRespawn && playerTeam.getInventories().resolveLoadouts().keySet().size() > 1) {
War.war.msg(player, "Equipped " + pairs.getKey() + " loadout (sneak to switch)."); War.war.msg(player, "Equipped " + name + " loadout (sneak to switch).");
} else if (isToggle) { } else if (isToggle) {
War.war.msg(player, "Equipped " + pairs.getKey() + " loadout."); War.war.msg(player, "Equipped " + name + " loadout.");
} }
} }
i++; i++;

View File

@ -80,7 +80,7 @@ public class WarzoneConfigBag {
String onOff = namedParams.get(namedParam); String onOff = namedParams.get(namedParam);
this.bag.put(warzoneConfig, onOff.equals("on") || onOff.equals("true")); this.bag.put(warzoneConfig, onOff.equals("on") || onOff.equals("true"));
} }
returnMessage += warzoneConfig.toString() + " set to " + namedParams.get(namedParam); returnMessage += " " + warzoneConfig.toString() + " set to " + namedParams.get(namedParam);
} else if (namedParam.equals("delete")) { } else if (namedParam.equals("delete")) {
String toDelete = namedParams.get(namedParam); String toDelete = namedParams.get(namedParam);
warzoneConfig = WarzoneConfig.warzoneConfigFromString(toDelete); warzoneConfig = WarzoneConfig.warzoneConfigFromString(toDelete);
@ -88,7 +88,7 @@ public class WarzoneConfigBag {
// param delete (to restore inheritance) // param delete (to restore inheritance)
if (warzoneConfig != null) { if (warzoneConfig != null) {
this.bag.remove(warzoneConfig); this.bag.remove(warzoneConfig);
returnMessage += warzoneConfig.toString() + " removed"; returnMessage += " " + warzoneConfig.toString() + " removed";
} }
} }
} }

View File

@ -16,8 +16,8 @@ public class LoadoutYmlMapper {
loadouts.clear(); loadouts.clear();
for (String name : loadoutNames) { for (String name : loadoutNames) {
HashMap<Integer, ItemStack> newLoadout = new HashMap<Integer, ItemStack>(); HashMap<Integer, ItemStack> newLoadout = new HashMap<Integer, ItemStack>();
loadouts.put(name, newLoadout);
fromConfigToLoadout(config, newLoadout, name); fromConfigToLoadout(config, newLoadout, name);
loadouts.put(name, newLoadout);
} }
} }
@ -45,22 +45,35 @@ public class LoadoutYmlMapper {
} }
} }
} }
loadout.put(slot, stack);
} }
} }
public static void fromLoadoutsToConfig(HashMap<String, HashMap<Integer, ItemStack>> loadouts, ConfigurationSection section) { public static void fromLoadoutsToConfig(HashMap<String, HashMap<Integer, ItemStack>> loadouts, ConfigurationSection section) {
section.set("names", toStringList(loadouts.keySet())); List<String> sortedNames = sortNames(loadouts);
for (String name : loadouts.keySet()) {
section.set("names", sortedNames);
for (String name : sortedNames) {
fromLoadoutToConfig(name, loadouts.get(name), section); fromLoadoutToConfig(name, loadouts.get(name), section);
} }
} }
private static List<String> toStringList(Set<String> keySet) { public static List<String> sortNames(HashMap<String, HashMap<Integer, ItemStack>> loadouts) {
List<String> list = new ArrayList<String>(); List<String> sortedNames = new ArrayList<String>();
for (String key : keySet) {
list.add(key); // default comes first
if (loadouts.containsKey("default")) {
sortedNames.add("default");
} }
return list;
for (String name : loadouts.keySet()) {
if (!name.equals("default")) {
sortedNames.add(name);
}
}
return sortedNames;
} }
private static List<Integer> toIntList(Set<Integer> keySet) { private static List<Integer> toIntList(Set<Integer> keySet) {

View File

@ -128,7 +128,7 @@ public class WarzoneYmlMapper {
List<String> teamsNames = warzoneRootSection.getStringList("team.names"); List<String> teamsNames = warzoneRootSection.getStringList("team.names");
for (String teamName : teamsNames) { for (String teamName : teamsNames) {
// team info // team info
String teamInfoPrefix = "team." + teamName + ".info"; String teamInfoPrefix = "team." + teamName + ".info.";
int teamX = warzoneRootSection.getInt(teamInfoPrefix + "spawn.x"); int teamX = warzoneRootSection.getInt(teamInfoPrefix + "spawn.x");
int teamY = warzoneRootSection.getInt(teamInfoPrefix + "spawn.y"); int teamY = warzoneRootSection.getInt(teamInfoPrefix + "spawn.y");
int teamZ = warzoneRootSection.getInt(teamInfoPrefix + "spawn.z"); int teamZ = warzoneRootSection.getInt(teamInfoPrefix + "spawn.z");