diff --git a/war/src/main/java/bukkit/tommytony/war/War.java b/war/src/main/java/bukkit/tommytony/war/War.java index a88b955..c51b24f 100644 --- a/war/src/main/java/bukkit/tommytony/war/War.java +++ b/war/src/main/java/bukkit/tommytony/war/War.java @@ -77,6 +77,7 @@ public class War extends JavaPlugin { private boolean defaultNoCreatures = false; private boolean defaultResetOnEmpty = false, defaultResetOnLoad = false, defaultResetOnUnload = false; private String defaultSpawnStyle = TeamSpawnStyles.BIG; + private String defaultFlagReturn = "both"; private final HashMap defaultReward = new HashMap(); public War() { @@ -268,6 +269,16 @@ public class War extends JavaPlugin { warzone.setSpawnStyle(TeamSpawnStyles.BIG); } } + if (namedParams.containsKey("flagreturn")) { + String flagReturn = namedParams.get("flagreturn").toLowerCase(); + if (flagReturn.equals("flag")) { + warzone.setFlagReturn("flag"); + } else if (flagReturn.equals("spawn")) { + warzone.setFlagReturn("spawn"); + } else { + warzone.setFlagReturn("both"); + } + } if (namedParams.containsKey("unbreakable")) { String onOff = namedParams.get("unbreakable"); warzone.setUnbreakableZoneBlocks(onOff.equals("on") || onOff.equals("true")); @@ -362,6 +373,16 @@ public class War extends JavaPlugin { this.setDefaultSpawnStyle(TeamSpawnStyles.BIG); } } + if (namedParams.containsKey("flagreturn")) { + String flagreturn = namedParams.get("flagreturn").toLowerCase(); + if (flagreturn.equals("flag")) { + this.setDefaultFlagReturn("flag"); + } else if (flagreturn.equals("spawn")) { + this.setDefaultFlagReturn("spawn"); + } else { + this.setDefaultFlagReturn("both"); + } + } if (namedParams.containsKey("buildinzonesonly")) { String onOff = namedParams.get("buildinzonesonly"); this.setBuildInZonesOnly(onOff.equals("on") || onOff.equals("true")); @@ -885,6 +906,14 @@ public class War extends JavaPlugin { this.defaultSpawnStyle = defaultSpawnStyle; } + public void setDefaultFlagReturn(String defaultFlagReturn) { + this.defaultFlagReturn = defaultFlagReturn; + } + + public String getDefaultFlagReturn() { + return defaultFlagReturn; + } + public HashMap getDisconnected() { return this.disconnected; } diff --git a/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java b/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java index e882fe1..6a998db 100644 --- a/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java +++ b/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java @@ -369,7 +369,28 @@ public class WarPlayerListener extends PlayerListener { } // Flag capture - if (playerWarzone.isFlagThief(player.getName()) && (playerTeam.getSpawnVolume().contains(player.getLocation()) || (playerTeam.getFlagVolume() != null && playerTeam.getFlagVolume().contains(player.getLocation())))) { + if (playerWarzone.isFlagThief(player.getName())) { + boolean inSpawn = playerTeam.getSpawnVolume().contains(player.getLocation()); + boolean inFlag = (playerTeam.getFlagVolume() != null && playerTeam.getFlagVolume().contains(player.getLocation())); + + if (playerWarzone.equals("both")) { + if (!inSpawn && !inFlag) return; + } else if (playerWarzone.equals("spawn")) { + if (inFlag) { + War.war.badMsg(player, "You have to unload the flag at your spawn."); + return; + } else if (!inSpawn) { + return; + } + } else if (playerWarzone.equals("flag")) { + if (inSpawn) { + War.war.badMsg(player, "You have to unload the flag at your flag."); + return; + } else if (!inFlag) { + return; + } + } + if (playerWarzone.isTeamFlagStolen(playerTeam)) { War.war.badMsg(player, "You can't capture the enemy flag until your team's flag is returned."); } else { diff --git a/war/src/main/java/com/tommytony/war/Warzone.java b/war/src/main/java/com/tommytony/war/Warzone.java index ef53af0..f70922e 100644 --- a/war/src/main/java/com/tommytony/war/Warzone.java +++ b/war/src/main/java/com/tommytony/war/Warzone.java @@ -44,6 +44,7 @@ public class Warzone { private int scoreCap = 5; private int monumentHeal = 5; private String spawnStyle = TeamSpawnStyles.BIG; + private String flagReturn = "both"; private HashMap reward = new HashMap(); private HashMap inventories = new HashMap(); @@ -91,7 +92,7 @@ public class Warzone { // perfect match, return right away return warzone; } else if (warzone.getName().toLowerCase().startsWith(name.toLowerCase())) { - // prehaps there's a perfect match in the remaining zones, let's take this one aside + // prehaps there's a perfect match in the remaining zones, let's take this one aside bestGuess = warzone; } } @@ -959,6 +960,15 @@ public class Warzone { return this.spawnStyle; } + + public void setFlagReturn(String flagReturn) { + this.flagReturn = flagReturn; + } + + public String getFlagReturn() { + return this.flagReturn; + } + public void setReward(HashMap reward) { this.reward = reward; } diff --git a/war/src/main/java/com/tommytony/war/mappers/WarMapper.java b/war/src/main/java/com/tommytony/war/mappers/WarMapper.java index 2f4e8ce..e26039e 100644 --- a/war/src/main/java/com/tommytony/war/mappers/WarMapper.java +++ b/war/src/main/java/com/tommytony/war/mappers/WarMapper.java @@ -130,6 +130,18 @@ public class WarMapper { // default is already initialized to BIG (see Warzone) } + // defaultFlagReturn + String flagReturn = warConfig.getString("defaultFlagReturn"); + if (flagReturn != null && !flagReturn.equals("")) { + flagReturn = flagReturn.toLowerCase(); + if (flagReturn.equals("flag")) { + War.war.setDefaultFlagReturn("flag"); + } else if (flagReturn.equals("spawn")) { + War.war.setDefaultFlagReturn("spawn"); + } + // default is already initialized to both (see Warzone) + } + // defaultReward String defaultRewardStr = warConfig.getString("defaultReward"); if (defaultRewardStr != null && !defaultRewardStr.equals("")) { 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 47773e0..29528fd 100644 --- a/war/src/main/java/com/tommytony/war/mappers/WarzoneMapper.java +++ b/war/src/main/java/com/tommytony/war/mappers/WarzoneMapper.java @@ -172,6 +172,18 @@ public class WarzoneMapper { // default is already initialized to BIG (see Warzone) } + // flagReturn + String flagReturn = warzoneConfig.getString("flagReturn"); + if (flagReturn != null && !flagReturn.equals("")) { + flagReturn = flagReturn.toLowerCase(); + if (flagReturn.equals("flag")) { + warzone.setFlagReturn("flag"); + } else if (flagReturn.equals("spawn")) { + warzone.setFlagReturn("spawn"); + } + // default is already initialized to both (see Warzone) + } + // reward String rewardStr = warzoneConfig.getString("reward"); if (rewardStr != null && !rewardStr.equals("")) {