Add support for new loadout system to base classes and configuration

subsystem.
This commit is contained in:
cmastudios 2013-03-22 22:09:29 -05:00
parent dd88a5ccbe
commit e6c1e64fef
5 changed files with 31 additions and 29 deletions

View File

@ -50,6 +50,7 @@ import com.tommytony.war.structure.HubLobbyMaterials;
import com.tommytony.war.structure.Monument;
import com.tommytony.war.structure.WarHub;
import com.tommytony.war.structure.ZoneLobby;
import com.tommytony.war.utility.Loadout;
import com.tommytony.war.utility.PlayerState;
import com.tommytony.war.utility.SizeCounter;
import com.tommytony.war.utility.WarLogFormatter;
@ -185,7 +186,7 @@ public class War extends JavaPlugin {
teamDefaultConfig.put(TeamConfig.SPAWNSTYLE, TeamSpawnStyle.SMALL);
teamDefaultConfig.put(TeamConfig.TEAMSIZE, 10);
this.getDefaultInventories().getLoadouts().clear();
this.getDefaultInventories().clearLoadouts();
HashMap<Integer, ItemStack> defaultLoadout = new HashMap<Integer, ItemStack>();
ItemStack stoneSword = new ItemStack(Material.STONE_SWORD, 1, (byte) 8);
@ -392,15 +393,15 @@ public class War extends JavaPlugin {
Player player = (Player) commandSender;
if (namedParams.containsKey("loadout")) {
String loadoutName = namedParams.get("loadout");
HashMap<Integer, ItemStack> loadout = team.getInventories().getLoadouts().get(loadoutName);
HashMap<Integer, ItemStack> loadout = team.getInventories().getLoadout(loadoutName);
if (loadout == null) {
// Check if any loadouts exist, if not gotta use the default inventories then add the newly created one
if(team.getInventories().getLoadouts().isEmpty()) {
if(!team.getInventories().hasLoadouts()) {
Warzone warzone = Warzone.getZoneByTeam(team);
for (String key : warzone.getDefaultInventories().resolveLoadouts().keySet()) {
HashMap<Integer, ItemStack> transferredLoadout = warzone.getDefaultInventories().resolveLoadouts().get(key);
if (transferredLoadout != null) {
team.getInventories().getLoadouts().put(key, transferredLoadout);
team.getInventories().setLoadout(key, transferredLoadout);
} else {
War.war.log("Failed to transfer loadout " + key + " down to team " + team.getName() + " in warzone " + warzone.getName(), Level.WARNING);
}
@ -408,7 +409,7 @@ public class War extends JavaPlugin {
}
loadout = new HashMap<Integer, ItemStack>();
team.getInventories().getLoadouts().put(loadoutName, loadout);
team.getInventories().setLoadout(loadoutName, loadout);
returnMessage.append(loadoutName + " respawn loadout added.");
} else {
returnMessage.append(loadoutName + " respawn loadout updated.");
@ -417,7 +418,7 @@ public class War extends JavaPlugin {
}
if (namedParams.containsKey("deleteloadout")) {
String loadoutName = namedParams.get("deleteloadout");
if (team.getInventories().getLoadouts().keySet().contains(loadoutName)) {
if (team.getInventories().containsLoadout(loadoutName)) {
team.getInventories().removeLoadout(loadoutName);
returnMessage.append(" " + loadoutName + " loadout removed.");
} else {
@ -473,23 +474,23 @@ public class War extends JavaPlugin {
Player player = (Player) commandSender;
if (namedParams.containsKey("loadout")) {
String loadoutName = namedParams.get("loadout");
HashMap<Integer, ItemStack> loadout = warzone.getDefaultInventories().getLoadouts().get(loadoutName);
HashMap<Integer, ItemStack> loadout = warzone.getDefaultInventories().getLoadout(loadoutName);
if (loadout == null) {
loadout = new HashMap<Integer, ItemStack>();
// Check if any loadouts exist, if not gotta use the default inventories then add the newly created one
if(warzone.getDefaultInventories().getLoadouts().isEmpty()) {
if(!warzone.getDefaultInventories().hasLoadouts()) {
for (String key : warzone.getDefaultInventories().resolveLoadouts().keySet()) {
HashMap<Integer, ItemStack> transferredLoadout = warzone.getDefaultInventories().resolveLoadouts().get(key);
if (transferredLoadout != null) {
warzone.getDefaultInventories().getLoadouts().put(key, transferredLoadout);
warzone.getDefaultInventories().setLoadout(key, transferredLoadout);
} else {
War.war.log("Failed to transfer loadout " + key + " down to warzone " + warzone.getName(), Level.WARNING);
}
}
}
warzone.getDefaultInventories().getLoadouts().put(loadoutName, loadout);
warzone.getDefaultInventories().setLoadout(loadoutName, loadout);
returnMessage.append(loadoutName + " respawn loadout added.");
} else {
returnMessage.append(loadoutName + " respawn loadout updated.");
@ -498,7 +499,7 @@ public class War extends JavaPlugin {
}
if (namedParams.containsKey("deleteloadout")) {
String loadoutName = namedParams.get("deleteloadout");
if (warzone.getDefaultInventories().getLoadouts().keySet().contains(loadoutName)) {
if (warzone.getDefaultInventories().containsLoadout(loadoutName)) {
warzone.getDefaultInventories().removeLoadout(loadoutName);
returnMessage.append(" " + loadoutName + " loadout removed.");
} else {
@ -637,7 +638,7 @@ public class War extends JavaPlugin {
Player player = (Player) commandSender;
if (namedParams.containsKey("loadout")) {
String loadoutName = namedParams.get("loadout");
HashMap<Integer, ItemStack> loadout = this.getDefaultInventories().getLoadouts().get(loadoutName);
HashMap<Integer, ItemStack> loadout = this.getDefaultInventories().getLoadout(loadoutName);
if (loadout == null) {
loadout = new HashMap<Integer, ItemStack>();
this.getDefaultInventories().addLoadout(loadoutName, loadout);
@ -649,8 +650,8 @@ public class War extends JavaPlugin {
}
if (namedParams.containsKey("deleteloadout")) {
String loadoutName = namedParams.get("deleteloadout");
if (this.getDefaultInventories().getLoadouts().keySet().contains(loadoutName)) {
if (this.getDefaultInventories().getLoadouts().keySet().size() > 1) {
if (this.getDefaultInventories().containsLoadout(loadoutName)) {
if (this.getDefaultInventories().getNewLoadouts().size() > 1) {
this.getDefaultInventories().removeLoadout(loadoutName);
returnMessage.append(" " + loadoutName + " loadout removed.");
} else {

View File

@ -80,12 +80,12 @@ public class WarTxtMapper {
}
// defaultLoadout
War.war.getDefaultInventories().getLoadouts().clear();
War.war.getDefaultInventories().clearLoadouts();
String loadoutStr = warConfig.getString("defaultLoadout");
if (loadoutStr != null && !loadoutStr.equals("")) {
War.war.getDefaultInventories().addLoadout("default", new HashMap<Integer, ItemStack>());
LoadoutTxtMapper.fromStringToLoadout(loadoutStr, War.war.getDefaultInventories().getLoadouts().get("default"));
LoadoutTxtMapper.fromStringToLoadout(loadoutStr, War.war.getDefaultInventories().getLoadout("default"));
}
// defaultExtraLoadouts
@ -101,7 +101,7 @@ public class WarTxtMapper {
for (String extraName : extraLoadoutsSplit) {
if (extraName != null && !extraName.equals("")) {
String loadoutString = warConfig.getString(extraName + "Loadout");
HashMap<Integer, ItemStack> loadout = War.war.getDefaultInventories().getLoadouts().get(extraName);
HashMap<Integer, ItemStack> loadout = War.war.getDefaultInventories().getLoadout(extraName);
LoadoutTxtMapper.fromStringToLoadout(loadoutString, loadout);
}
}

View File

@ -70,7 +70,7 @@ public class WarYmlMapper {
// defaultLoadouts
ConfigurationSection loadoutsSection = warRootSection.getConfigurationSection("team.default.loadout");
LoadoutYmlMapper.fromConfigToLoadouts(loadoutsSection, War.war.getDefaultInventories().getLoadouts());
War.war.getDefaultInventories().setLoadouts(LoadoutYmlMapper.fromConfigToLoadouts(loadoutsSection, new HashMap()));
// defaultReward
ConfigurationSection rewardsSection = warRootSection.getConfigurationSection("team.default.reward");
@ -121,7 +121,7 @@ public class WarYmlMapper {
// defaultLoadouts
ConfigurationSection loadoutSection = teamDefault.createSection("loadout");
LoadoutYmlMapper.fromLoadoutsToConfig(War.war.getDefaultInventories().getLoadouts(), loadoutSection);
LoadoutYmlMapper.fromLoadoutsToConfig(War.war.getDefaultInventories().getNewLoadouts(), loadoutSection);
// defaultReward
ConfigurationSection rewardsSection = teamDefault.createSection("reward");

View File

@ -86,12 +86,12 @@ public class WarzoneTxtMapper {
}
// loadout
warzone.getDefaultInventories().getLoadouts().clear();
warzone.getDefaultInventories().clearLoadouts();
String loadoutStr = warzoneConfig.getString("loadout");
if (loadoutStr != null && !loadoutStr.equals("")) {
warzone.getDefaultInventories().getLoadouts().put("default", new HashMap<Integer, ItemStack>());
LoadoutTxtMapper.fromStringToLoadout(loadoutStr, warzone.getDefaultInventories().getLoadouts().get("default"));
warzone.getDefaultInventories().setLoadout("default", new HashMap<Integer, ItemStack>());
LoadoutTxtMapper.fromStringToLoadout(loadoutStr, warzone.getDefaultInventories().getLoadout("default"));
}
// extraLoadouts
@ -100,14 +100,14 @@ public class WarzoneTxtMapper {
for (String nameStr : extraLoadoutsSplit) {
if (nameStr != null && !nameStr.equals("")) {
warzone.getDefaultInventories().getLoadouts().put(nameStr, new HashMap<Integer, ItemStack>());
warzone.getDefaultInventories().setLoadout(nameStr, new HashMap<Integer, ItemStack>());
}
}
for (String extraName : extraLoadoutsSplit) {
if (extraName != null && !extraName.equals("")) {
String loadoutString = warzoneConfig.getString(extraName + "Loadout");
HashMap<Integer, ItemStack> loadout = warzone.getDefaultInventories().getLoadouts().get(extraName);
HashMap<Integer, ItemStack> loadout = warzone.getDefaultInventories().getLoadout(extraName);
LoadoutTxtMapper.fromStringToLoadout(loadoutString, loadout);
}
}

View File

@ -27,6 +27,7 @@ import com.tommytony.war.structure.Monument;
import com.tommytony.war.structure.WarzoneMaterials;
import com.tommytony.war.structure.ZoneLobby;
import com.tommytony.war.utility.Direction;
import com.tommytony.war.utility.Loadout;
import com.tommytony.war.volume.Volume;
import com.tommytony.war.volume.ZoneVolume;
@ -79,7 +80,7 @@ public class WarzoneYmlMapper {
// defaultLoadouts
if (warzoneRootSection.contains("team.default.loadout")) {
ConfigurationSection loadoutsSection = warzoneRootSection.getConfigurationSection("team.default.loadout");
LoadoutYmlMapper.fromConfigToLoadouts(loadoutsSection, warzone.getDefaultInventories().getLoadouts());
warzone.getDefaultInventories().setLoadouts(LoadoutYmlMapper.fromConfigToLoadouts(loadoutsSection, new HashMap()));
}
// defaultReward
@ -231,11 +232,11 @@ public class WarzoneYmlMapper {
if (warzoneRootSection.contains(teamLoadoutPrefix)) {
// team specific loadouts
ConfigurationSection loadoutsSection = warzoneRootSection.getConfigurationSection(teamLoadoutPrefix);
LoadoutYmlMapper.fromConfigToLoadouts(loadoutsSection, team.getInventories().getLoadouts());
team.getInventories().setLoadouts(LoadoutYmlMapper.fromConfigToLoadouts(loadoutsSection, new HashMap()));
} else if (warzoneRootSection.contains(teamLoadoutPrefix.toLowerCase())) {
// try lowercase instead
ConfigurationSection loadoutsSection = warzoneRootSection.getConfigurationSection(teamLoadoutPrefix.toLowerCase());
LoadoutYmlMapper.fromConfigToLoadouts(loadoutsSection, team.getInventories().getLoadouts());
team.getInventories().setLoadouts(LoadoutYmlMapper.fromConfigToLoadouts(loadoutsSection, new HashMap()));
}
String teamRewardPrefix = "team." + teamName + ".reward";
@ -539,7 +540,7 @@ public class WarzoneYmlMapper {
// defaultLoadouts
if (warzone.getDefaultInventories().hasLoadouts()) {
ConfigurationSection loadoutsSection = teamsSection.createSection("default.loadout");
LoadoutYmlMapper.fromLoadoutsToConfig(warzone.getDefaultInventories().getLoadouts(), loadoutsSection);
LoadoutYmlMapper.fromLoadoutsToConfig(warzone.getDefaultInventories().getNewLoadouts(), loadoutsSection);
}
// defaultReward
@ -558,7 +559,7 @@ public class WarzoneYmlMapper {
if (team.getInventories().hasLoadouts()) {
// team specific loadouts
ConfigurationSection loadoutsSection = teamsSection.createSection(team.getName() + ".loadout");
LoadoutYmlMapper.fromLoadoutsToConfig(team.getInventories().getLoadouts(), loadoutsSection);
LoadoutYmlMapper.fromLoadoutsToConfig(team.getInventories().getNewLoadouts(), loadoutsSection);
}
if (team.getInventories().hasReward()) {