mirror of
https://github.com/taoneill/war.git
synced 2025-01-07 16:27:44 +01:00
Closes gh-272. Made flagreturn into an enum. Adding missing flag capture mode tidbits (setting wasn't being saved, made flag capture broadcast reflect the current mode).
This commit is contained in:
parent
c7af5843fb
commit
cb9a34f5bd
@ -75,7 +75,7 @@ public class War extends JavaPlugin {
|
||||
private boolean defaultAutoAssignOnly = false;
|
||||
private boolean defaultUnbreakableZoneBlocks = false;
|
||||
private boolean defaultNoCreatures = false;
|
||||
private String defaultFlagReturn = "both";
|
||||
private FlagReturn defaultFlagReturn = FlagReturn.BOTH;
|
||||
private boolean defaultResetOnEmpty = false, defaultResetOnLoad = false, defaultResetOnUnload = false;
|
||||
private TeamSpawnStyle defaultSpawnStyle = TeamSpawnStyle.BIG;
|
||||
private final HashMap<Integer, ItemStack> defaultReward = new HashMap<Integer, ItemStack>();
|
||||
@ -262,16 +262,16 @@ public class War extends JavaPlugin {
|
||||
}
|
||||
if (namedParams.containsKey("spawnstyle")) {
|
||||
String spawnStyle = namedParams.get("spawnstyle");
|
||||
warzone.setSpawnStyle(TeamSpawnStyle.getStyleByString(spawnStyle));
|
||||
warzone.setSpawnStyle(TeamSpawnStyle.getStyleFromString(spawnStyle));
|
||||
}
|
||||
if (namedParams.containsKey("flagreturn")) {
|
||||
String flagReturn = namedParams.get("flagreturn").toLowerCase();
|
||||
if (flagReturn.equals("flag")) {
|
||||
warzone.setFlagReturn("flag");
|
||||
warzone.setFlagReturn(FlagReturn.FLAG);
|
||||
} else if (flagReturn.equals("spawn")) {
|
||||
warzone.setFlagReturn("spawn");
|
||||
warzone.setFlagReturn(FlagReturn.SPAWN);
|
||||
} else {
|
||||
warzone.setFlagReturn("both");
|
||||
warzone.setFlagReturn(FlagReturn.BOTH);
|
||||
}
|
||||
}
|
||||
if (namedParams.containsKey("unbreakable")) {
|
||||
@ -358,16 +358,16 @@ public class War extends JavaPlugin {
|
||||
}
|
||||
if (namedParams.containsKey("spawnstyle")) {
|
||||
String spawnStyle = namedParams.get("spawnstyle");
|
||||
this.setDefaultSpawnStyle(TeamSpawnStyle.getStyleByString(spawnStyle));
|
||||
this.setDefaultSpawnStyle(TeamSpawnStyle.getStyleFromString(spawnStyle));
|
||||
}
|
||||
if (namedParams.containsKey("flagreturn")) {
|
||||
String flagreturn = namedParams.get("flagreturn").toLowerCase();
|
||||
if (flagreturn.equals("flag")) {
|
||||
this.setDefaultFlagReturn("flag");
|
||||
this.setDefaultFlagReturn(FlagReturn.FLAG);
|
||||
} else if (flagreturn.equals("spawn")) {
|
||||
this.setDefaultFlagReturn("spawn");
|
||||
this.setDefaultFlagReturn(FlagReturn.SPAWN);
|
||||
} else {
|
||||
this.setDefaultFlagReturn("both");
|
||||
this.setDefaultFlagReturn(FlagReturn.BOTH);
|
||||
}
|
||||
}
|
||||
if (namedParams.containsKey("buildinzonesonly")) {
|
||||
@ -423,6 +423,7 @@ public class War extends JavaPlugin {
|
||||
+ " autoassign:" + String.valueOf(zone.getAutoAssignOnly())
|
||||
+ " blockheads:" + String.valueOf(zone.isBlockHeads())
|
||||
+ " spawnstyle:" + zone.getSpawnStyle()
|
||||
+ " flagreturn:" + zone.getFlagReturn()
|
||||
+ " monumentheal:" + zone.getMonumentHeal()
|
||||
+ " unbreakable:" + String.valueOf(zone.isUnbreakableZoneBlocks())
|
||||
+ " disabled:" + String.valueOf(zone.isDisabled())
|
||||
@ -445,6 +446,7 @@ public class War extends JavaPlugin {
|
||||
+ " autoassign:" + String.valueOf(War.war.isDefaultAutoAssignOnly())
|
||||
+ " blockheads:" + String.valueOf(War.war.isDefaultBlockHeads())
|
||||
+ " spawnstyle:" + War.war.getDefaultSpawnStyle()
|
||||
+ " flagreturn:" + War.war.getDefaultFlagReturn()
|
||||
+ " monumentheal:" + War.war.getDefaultMonumentHeal()
|
||||
+ " unbreakable:" + String.valueOf(War.war.isDefaultUnbreakableZoneBlocks())
|
||||
+ " nocreatures:" + String.valueOf(War.war.isDefaultNoCreatures())
|
||||
@ -867,11 +869,11 @@ public class War extends JavaPlugin {
|
||||
this.defaultSpawnStyle = defaultSpawnStyle;
|
||||
}
|
||||
|
||||
public void setDefaultFlagReturn(String defaultFlagReturn) {
|
||||
public void setDefaultFlagReturn(FlagReturn defaultFlagReturn) {
|
||||
this.defaultFlagReturn = defaultFlagReturn;
|
||||
}
|
||||
|
||||
public String getDefaultFlagReturn() {
|
||||
public FlagReturn getDefaultFlagReturn() {
|
||||
return defaultFlagReturn;
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,7 @@ import org.bukkit.event.block.BlockListener;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.tommytony.war.FlagReturn;
|
||||
import com.tommytony.war.Monument;
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.Warzone;
|
||||
@ -182,14 +183,21 @@ public class WarBlockListener extends BlockListener {
|
||||
warzone.addFlagThief(lostFlagTeam, player.getName());
|
||||
block.setType(Material.AIR);
|
||||
|
||||
String spawnOrFlag = "spawn or flag";
|
||||
if (warzone.getFlagReturn() == FlagReturn.FLAG || warzone.getFlagReturn() == FlagReturn.SPAWN) {
|
||||
spawnOrFlag = warzone.getFlagReturn().toString();
|
||||
}
|
||||
|
||||
for (Team t : warzone.getTeams()) {
|
||||
t.teamcast(team.getKind().getColor() + player.getName() + ChatColor.WHITE + " stole team " + lostFlagTeam.getName() + "'s flag.");
|
||||
if (t.getName().equals(lostFlagTeam.getName())) {
|
||||
t.teamcast("Prevent " + team.getKind().getColor() + player.getName() + ChatColor.WHITE
|
||||
+ " from reaching team " + team.getName() + "'s spawn or flag.");
|
||||
+ " from reaching team " + team.getName() + "'s " + spawnOrFlag + ".");
|
||||
}
|
||||
}
|
||||
War.war.msg(player, "You have team " + lostFlagTeam.getName() + "'s flag. Reach your team spawn or flag to capture it!");
|
||||
|
||||
|
||||
War.war.msg(player, "You have team " + lostFlagTeam.getName() + "'s flag. Reach your team " + spawnOrFlag + " to capture it!");
|
||||
} else {
|
||||
War.war.msg(player, "You can't steal team " + lostFlagTeam.getName() + "'s flag since no players are on that team.");
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
|
||||
import com.tommytony.war.FlagReturn;
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.WarHub;
|
||||
import com.tommytony.war.Warzone;
|
||||
@ -375,18 +376,18 @@ public class WarPlayerListener extends PlayerListener {
|
||||
boolean inSpawn = playerTeam.getSpawnVolume().contains(player.getLocation());
|
||||
boolean inFlag = (playerTeam.getFlagVolume() != null && playerTeam.getFlagVolume().contains(player.getLocation()));
|
||||
|
||||
if (playerWarzone.equals("both")) {
|
||||
if (playerWarzone.getFlagReturn() == FlagReturn.BOTH) {
|
||||
if (!inSpawn && !inFlag) return;
|
||||
} else if (playerWarzone.equals("spawn")) {
|
||||
} else if (playerWarzone.getFlagReturn() == FlagReturn.SPAWN) {
|
||||
if (inFlag) {
|
||||
War.war.badMsg(player, "You have to unload the flag at your spawn.");
|
||||
War.war.badMsg(player, "You have to capture the enemy flag at your team's spawn.");
|
||||
return;
|
||||
} else if (!inSpawn) {
|
||||
return;
|
||||
}
|
||||
} else if (playerWarzone.equals("flag")) {
|
||||
} else if (playerWarzone.getFlagReturn() == FlagReturn.FLAG) {
|
||||
if (inSpawn) {
|
||||
War.war.badMsg(player, "You have to unload the flag at your flag.");
|
||||
War.war.badMsg(player, "You have to capture the enemy flag at your team's flag.");
|
||||
return;
|
||||
} else if (!inFlag) {
|
||||
return;
|
||||
|
22
war/src/main/java/com/tommytony/war/FlagReturn.java
Normal file
22
war/src/main/java/com/tommytony/war/FlagReturn.java
Normal file
@ -0,0 +1,22 @@
|
||||
package com.tommytony.war;
|
||||
|
||||
public enum FlagReturn {
|
||||
BOTH,
|
||||
FLAG,
|
||||
SPAWN;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString().toLowerCase();
|
||||
}
|
||||
|
||||
public static FlagReturn getFromString(String string) {
|
||||
for (FlagReturn flagMode : FlagReturn.values()) {
|
||||
if (string.toLowerCase().equals(flagMode.toString())) {
|
||||
return flagMode;
|
||||
}
|
||||
}
|
||||
|
||||
return FlagReturn.BOTH;
|
||||
}
|
||||
}
|
@ -16,7 +16,7 @@ public enum TeamSpawnStyle {
|
||||
return super.toString().toLowerCase();
|
||||
}
|
||||
|
||||
public static TeamSpawnStyle getStyleByString(String string) {
|
||||
public static TeamSpawnStyle getStyleFromString(String string) {
|
||||
for (TeamSpawnStyle style : TeamSpawnStyle.values()) {
|
||||
if (string.toLowerCase().equals(style.toString())) {
|
||||
return style;
|
||||
|
@ -46,7 +46,7 @@ public class Warzone {
|
||||
private int teamCap = 5;
|
||||
private int scoreCap = 5;
|
||||
private int monumentHeal = 5;
|
||||
private String flagReturn = "both";
|
||||
private FlagReturn flagReturn = FlagReturn.BOTH;
|
||||
private TeamSpawnStyle spawnStyle = TeamSpawnStyle.BIG;
|
||||
private HashMap<Integer, ItemStack> reward = new HashMap<Integer, ItemStack>();
|
||||
|
||||
@ -79,6 +79,8 @@ public class Warzone {
|
||||
this.teamCap = War.war.getDefaultTeamCap();
|
||||
this.scoreCap = War.war.getDefaultScoreCap();
|
||||
this.monumentHeal = War.war.getDefaultMonumentHeal();
|
||||
this.spawnStyle = War.war.getDefaultSpawnStyle(); // don't use side-effect-full setters instead of this
|
||||
this.flagReturn = War.war.getDefaultFlagReturn();
|
||||
this.setBlockHeads(War.war.isDefaultBlockHeads());
|
||||
this.setUnbreakableZoneBlocks(War.war.isDefaultUnbreakableZoneBlocks());
|
||||
this.setNoCreatures(War.war.isDefaultNoCreatures());
|
||||
@ -973,11 +975,11 @@ public class Warzone {
|
||||
}
|
||||
|
||||
|
||||
public void setFlagReturn(String flagReturn) {
|
||||
public void setFlagReturn(FlagReturn flagReturn) {
|
||||
this.flagReturn = flagReturn;
|
||||
}
|
||||
|
||||
public String getFlagReturn() {
|
||||
public FlagReturn getFlagReturn() {
|
||||
return this.flagReturn;
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
|
||||
import com.tommytony.war.FlagReturn;
|
||||
import com.tommytony.war.TeamSpawnStyle;
|
||||
import com.tommytony.war.WarHub;
|
||||
import com.tommytony.war.Warzone;
|
||||
@ -118,19 +119,13 @@ public class WarMapper {
|
||||
// defaultSpawnStyle
|
||||
String spawnStyle = warConfig.getString("defaultspawnStyle");
|
||||
if (spawnStyle != null && !spawnStyle.equals("")) {
|
||||
War.war.setDefaultSpawnStyle(TeamSpawnStyle.getStyleByString(spawnStyle));
|
||||
War.war.setDefaultSpawnStyle(TeamSpawnStyle.getStyleFromString(spawnStyle));
|
||||
}
|
||||
|
||||
// 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)
|
||||
War.war.setDefaultFlagReturn(FlagReturn.getFromString(flagReturn));
|
||||
}
|
||||
|
||||
// defaultReward
|
||||
@ -242,6 +237,9 @@ public class WarMapper {
|
||||
// spawnStyle
|
||||
warConfig.setString("spawnStyle", War.war.getDefaultSpawnStyle().toString());
|
||||
|
||||
// spawnStyle
|
||||
warConfig.setString("flagReturn", War.war.getDefaultFlagReturn().toString());
|
||||
|
||||
// defaultReward
|
||||
String defaultRewardStr = "";
|
||||
HashMap<Integer, ItemStack> rewardItems = War.war.getDefaultReward();
|
||||
|
@ -13,6 +13,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
|
||||
import com.tommytony.war.FlagReturn;
|
||||
import com.tommytony.war.Monument;
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.TeamKind;
|
||||
@ -161,19 +162,13 @@ public class WarzoneMapper {
|
||||
// spawnStyle
|
||||
String spawnStyle = warzoneConfig.getString("spawnStyle");
|
||||
if (spawnStyle != null && !spawnStyle.equals("")) {
|
||||
warzone.setSpawnStyle(TeamSpawnStyle.getStyleByString(spawnStyle));
|
||||
warzone.setSpawnStyle(TeamSpawnStyle.getStyleFromString(spawnStyle));
|
||||
}
|
||||
|
||||
// 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)
|
||||
warzone.setFlagReturn(FlagReturn.getFromString(flagReturn));
|
||||
}
|
||||
|
||||
// reward
|
||||
@ -375,6 +370,9 @@ public class WarzoneMapper {
|
||||
|
||||
// spawnStyle
|
||||
warzoneConfig.setString("spawnStyle", warzone.getSpawnStyle().toString());
|
||||
|
||||
// flagReturn
|
||||
warzoneConfig.setString("flagReturn", warzone.getFlagReturn().toString());
|
||||
|
||||
// reward
|
||||
String rewardStr = "";
|
||||
|
Loading…
Reference in New Issue
Block a user