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) {
ChatColor teamColor = ChatColor.AQUA;
ChatColor normalColor = ChatColor.WHITE;
String teamConfigStr = "";
InventoryBag invs = team.getInventories();
teamConfigStr += getLoadoutsString(invs);
for (TeamConfig teamConfig : TeamConfig.values()) {
Object value = team.getTeamConfig().getValue(teamConfig);
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);
}
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) {
ChatColor teamColor = ChatColor.AQUA;
ChatColor zoneColor = ChatColor.RED;
ChatColor zoneColor = ChatColor.DARK_AQUA;
ChatColor authorColor = ChatColor.GREEN;
ChatColor normalColor = ChatColor.WHITE;
@ -573,6 +596,7 @@ public class War extends JavaPlugin {
}
String teamDefaultsStr = "";
teamDefaultsStr += getLoadoutsString( zone.getDefaultInventories());
for (TeamConfig teamConfig : TeamConfig.values()) {
Object value = zone.getTeamDefaultConfig().getValue(teamConfig);
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
+ ifEmptyInheritedForWarzone(warzoneConfigStr)
+ teamColor + " ::" + normalColor + "Team defaults" + teamColor + "::" + normalColor
+ " ::" + teamColor + "Team defaults" + normalColor + "::"
+ ifEmptyInheritedForWarzone(teamDefaultsStr);
}
@ -611,8 +635,8 @@ public class War extends JavaPlugin {
public String printConfig() {
ChatColor teamColor = ChatColor.AQUA;
ChatColor zoneColor = ChatColor.RED;
ChatColor globalColor = ChatColor.GREEN;
ChatColor zoneColor = ChatColor.DARK_AQUA;
ChatColor globalColor = ChatColor.DARK_GREEN;
ChatColor normalColor = ChatColor.WHITE;
String warConfigStr = "";
@ -626,13 +650,14 @@ public class War extends JavaPlugin {
}
String teamDefaultsStr = "";
teamDefaultsStr += getLoadoutsString(this.getDefaultInventories());
for (TeamConfig teamConfig : TeamConfig.values()) {
teamDefaultsStr += " " + teamConfig.toStringWithValue(this.getTeamDefaultConfig().getValue(teamConfig)).replace(":", ":" + teamColor) + normalColor;
}
return globalColor + "::" + normalColor + "War config" + globalColor + "::" + normalColor + warConfigStr
+ zoneColor + " ::" + normalColor + "Warzone defaults" + zoneColor + "::" + normalColor + warzoneDefaultsStr
+ teamColor + " ::" + normalColor + "Team defaults" + teamColor + "::" + normalColor + teamDefaultsStr;
return normalColor + "::" + globalColor + "War config" + normalColor + "::" + warConfigStr
+ normalColor + " ::" + zoneColor + "Warzone defaults" + normalColor + "::" + warzoneDefaultsStr
+ normalColor + " ::" + teamColor + "Team defaults" + normalColor + "::" + teamDefaultsStr;
}
private void setZoneRallyPoint(String warzoneName, Player player) {

View File

@ -25,6 +25,8 @@ public class SetTeamConfigCommand extends AbstractZoneMakerCommand {
CommandSender commandSender = this.getSender();
boolean isFirstParamWarzone = false;
boolean wantsToPrint = false;
Team team = null;
if (this.args.length == 0) {
return false;
@ -43,14 +45,19 @@ public class SetTeamConfigCommand extends AbstractZoneMakerCommand {
if (this.getSender() instanceof Player) {
player = (Player) commandSender;
Warzone zoneByLoc = Warzone.getZoneByLocation(player);
ZoneLobby lobbyByLoc = ZoneLobby.getLobbyByLocation(player);
if (zoneByLoc == null && lobbyByLoc != null) {
zoneByLoc = lobbyByLoc.getZone();
}
if (zoneByLoc != null) {
zone = zoneByLoc;
if (zone == null) {
// zone not found, is he standing in it?
Warzone zoneByLoc = Warzone.getZoneByLocation(player);
ZoneLobby lobbyByLoc = ZoneLobby.getLobbyByLocation(player);
if (zoneByLoc == null && lobbyByLoc != null) {
zoneByLoc = lobbyByLoc.getZone();
}
if (zoneByLoc != null) {
zone = zoneByLoc;
}
}
team = Team.getTeamByPlayerName(player.getName());
}
if (zone == null) {
@ -62,7 +69,7 @@ public class SetTeamConfigCommand extends AbstractZoneMakerCommand {
if (isFirstParamWarzone) {
if (this.args.length == 1) {
// Only one param: the warzone name - default to usage
// Only one param: the warzone name - pritn usage
return false;
}
// 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
Team team = null;
if (this.args.length > 0) {
// only printing
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
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;
}
// first param was team, shift again
String[] newargs = new String[this.args.length - 1];
for (int i = 1; i < this.args.length; i++) {
newargs[i - 1] = this.args[i];
if (teamByName != null) {
// first param was team, shift again
String[] newargs = new String[this.args.length - 1];
for (int i = 1; i < this.args.length; i++) {
newargs[i - 1] = this.args[i];
}
this.args = newargs;
}
if (teamByName != null) {
// Named team > player's team
team = teamByName;
}
this.args = newargs;
} else {
// No team param, show usage
return false;

View File

@ -37,17 +37,19 @@ public class SetZoneConfigCommand extends AbstractZoneMakerCommand {
wantsToPrint = true;
}
}
if (this.getSender() instanceof Player) {
player = (Player) commandSender;
Warzone zoneByLoc = Warzone.getZoneByLocation(player);
ZoneLobby lobbyByLoc = ZoneLobby.getLobbyByLocation(player);
if (zoneByLoc == null && lobbyByLoc != null) {
zoneByLoc = lobbyByLoc.getZone();
}
if (zoneByLoc != null) {
zone = zoneByLoc;
if (zone == null) {
// zone not found, is he standing in it?
Warzone zoneByLoc = Warzone.getZoneByLocation(player);
ZoneLobby lobbyByLoc = ZoneLobby.getLobbyByLocation(player);
if (zoneByLoc == null && lobbyByLoc != null) {
zoneByLoc = lobbyByLoc.getZone();
}
if (zoneByLoc != null) {
zone = zoneByLoc;
}
}
}

View File

@ -36,12 +36,14 @@ public class Team {
private Volume flagVolume;
private final Warzone warzone;
private TeamKind kind;
private InventoryBag inventories = new InventoryBag();
private TeamConfigBag teamConfig;
private InventoryBag inventories;
public Team(String name, TeamKind kind, Location teamSpawn, Warzone warzone) {
this.warzone = warzone;
this.teamConfig = new TeamConfigBag(warzone);
this.inventories = new InventoryBag(warzone); // important constructors for cascading configs
this.setName(name);
this.teamSpawn = teamSpawn;
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.LoadoutResetJob;
import com.tommytony.war.jobs.ScoreCapReachedJob;
import com.tommytony.war.mappers.LoadoutYmlMapper;
import com.tommytony.war.utils.PlayerState;
import com.tommytony.war.volumes.ZoneVolume;
@ -1024,17 +1025,20 @@ public class Warzone {
public void equipPlayerLoadoutSelection(Player player, Team playerTeam, boolean isFirstRespawn, boolean isToggle) {
LoadoutSelection selection = this.getLoadoutSelections().get(player.getName());
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 i = 0;
Iterator it = playerTeam.getInventories().resolveLoadouts().entrySet().iterator();
Iterator<String> it = sortedNames.iterator();
while (it.hasNext()) {
Map.Entry pairs = (Map.Entry)it.next();
String name = (String)it.next();
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) {
War.war.msg(player, "Equipped " + pairs.getKey() + " loadout (sneak to switch).");
War.war.msg(player, "Equipped " + name + " loadout (sneak to switch).");
} else if (isToggle) {
War.war.msg(player, "Equipped " + pairs.getKey() + " loadout.");
War.war.msg(player, "Equipped " + name + " loadout.");
}
}
i++;

View File

@ -80,7 +80,7 @@ public class WarzoneConfigBag {
String onOff = namedParams.get(namedParam);
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")) {
String toDelete = namedParams.get(namedParam);
warzoneConfig = WarzoneConfig.warzoneConfigFromString(toDelete);
@ -88,7 +88,7 @@ public class WarzoneConfigBag {
// param delete (to restore inheritance)
if (warzoneConfig != null) {
this.bag.remove(warzoneConfig);
returnMessage += warzoneConfig.toString() + " removed";
returnMessage += " " + warzoneConfig.toString() + " removed";
}
}
}

View File

@ -16,8 +16,8 @@ public class LoadoutYmlMapper {
loadouts.clear();
for (String name : loadoutNames) {
HashMap<Integer, ItemStack> newLoadout = new HashMap<Integer, ItemStack>();
loadouts.put(name, newLoadout);
fromConfigToLoadout(config, newLoadout, name);
loadouts.put(name, newLoadout);
}
}
@ -45,24 +45,37 @@ public class LoadoutYmlMapper {
}
}
}
loadout.put(slot, stack);
}
}
public static void fromLoadoutsToConfig(HashMap<String, HashMap<Integer, ItemStack>> loadouts, ConfigurationSection section) {
section.set("names", toStringList(loadouts.keySet()));
for (String name : loadouts.keySet()) {
List<String> sortedNames = sortNames(loadouts);
section.set("names", sortedNames);
for (String name : sortedNames) {
fromLoadoutToConfig(name, loadouts.get(name), section);
}
}
private static List<String> toStringList(Set<String> keySet) {
List<String> list = new ArrayList<String>();
for (String key : keySet) {
list.add(key);
public static List<String> sortNames(HashMap<String, HashMap<Integer, ItemStack>> loadouts) {
List<String> sortedNames = new ArrayList<String>();
// 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) {
List<Integer> list = new ArrayList<Integer>();
for (Integer key : keySet) {

View File

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