Merge pull request #275 from taoneill/flagReturn

Closing gh-272 Implemented a way to specify how to return a flag
This commit is contained in:
taoneill 2011-08-31 16:55:11 -07:00
commit 3e452e9e21
5 changed files with 86 additions and 2 deletions

View File

@ -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<Integer, ItemStack> defaultReward = new HashMap<Integer, ItemStack>();
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<String, InventoryStash> getDisconnected() {
return this.disconnected;
}

View File

@ -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 {

View File

@ -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<Integer, ItemStack> reward = new HashMap<Integer, ItemStack>();
private HashMap<String, InventoryStash> inventories = new HashMap<String, InventoryStash>();
@ -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<Integer, ItemStack> reward) {
this.reward = reward;
}

View File

@ -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("")) {

View File

@ -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("")) {