Added flag reservation

This commit is contained in:
boy0001 2015-06-25 05:06:47 +10:00
parent 7c55aa488c
commit c774e8b375
5 changed files with 52 additions and 3 deletions

View File

@ -8,7 +8,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<artifactId>PlotSquared</artifactId>
<version>2.11.23</version>
<version>2.11.24</version>
<name>PlotSquared</name>
<packaging>jar</packaging>
<build>

View File

@ -718,6 +718,7 @@ public class PlotSquared {
for (final String flag : intFlags) {
FlagManager.addFlag(new AbstractFlag(flag, new FlagValue.UnsignedIntegerValue()));
}
FlagManager.addFlag(new AbstractFlag("modified-blocks", new FlagValue.IntegerValue()), true);
FlagManager.addFlag(new AbstractFlag("disable-physics", new FlagValue.BooleanValue()));
FlagManager.addFlag(new AbstractFlag("fly", new FlagValue.BooleanValue()));
FlagManager.addFlag(new AbstractFlag("explosion", new FlagValue.BooleanValue()));

View File

@ -71,6 +71,10 @@ public class FlagCmd extends SubCommand {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag.other");
return false;
}
if (args.length > 1 && FlagManager.isReserved(args[1])) {
MainUtil.sendMessage(player, C.NOT_VALID_FLAG);
return false;
}
switch (args[0].toLowerCase()) {
case "info": {
if (!Permissions.hasPermission(player, "plots.set.flag")) {

View File

@ -106,7 +106,7 @@ public class Set extends SubCommand {
} catch (final Exception e) {
af = new AbstractFlag(args[1].toLowerCase());
}
if (!FlagManager.getFlags().contains(af)) {
if (!FlagManager.getFlags().contains(af) || FlagManager.isReserved(af.getKey())) {
MainUtil.sendMessage(plr, C.NOT_VALID_FLAG);
return false;
}

View File

@ -50,8 +50,44 @@ public class FlagManager {
// - Plot clear interval
// - Mob cap
// - customized plot composition
private final static HashSet<String> reserved = new HashSet<>();
private final static HashSet<AbstractFlag> flags = new HashSet<>();
/**
* Reserve a flag so that it cannot be set by players
* @param flag
*/
public static void reserveFlag(String flag) {
reserved.add(flag);
}
/**
* Get if a flag is reserved
* @param flag
* @return
*/
public static boolean isReserved(String flag) {
return reserved.contains(flag);
}
/**
* Get the reserved flags
* @return
*/
public static HashSet<String> getReservedFlags() {
return (HashSet<String>) reserved.clone();
}
/**
* Unreserve a flag
* @param flag
*/
public static void unreserveFlag(String flag) {
reserved.remove(flag);
}
/**
* Register an AbstractFlag with PlotSquared
*
@ -60,6 +96,10 @@ public class FlagManager {
* @return boolean success
*/
public static boolean addFlag(AbstractFlag af) {
return addFlag(af, false);
}
public static boolean addFlag(AbstractFlag af, boolean reserved) {
PlotSquared.log(C.PREFIX.s() + "&8 - Adding flag: &7" + af);
for (PlotWorld plotworld : PlotSquared.getPlotWorldObjects()) {
Flag flag = plotworld.DEFAULT_FLAGS.get(af.getKey());
@ -75,7 +115,11 @@ public class FlagManager {
}
}
}
return (getFlag(af.getKey()) == null) && flags.add(af);
if ((getFlag(af.getKey()) == null) && flags.add(af)) {
if (reserved) reserveFlag(af.getKey());
return true;
}
return false;
}
public static Flag getSettingFlag(final String world, final PlotSettings settings, final String id) {