[UNSTABLE] Working on plot protection system

This commit is contained in:
Jesse Boyd 2015-01-24 21:40:50 -07:00
parent 90856e4424
commit 030f2df21c
13 changed files with 377 additions and 226 deletions

View File

@ -80,6 +80,7 @@ import com.intellectualcrafters.plot.events.PlayerTeleportToPlotEvent;
import com.intellectualcrafters.plot.events.PlotDeleteEvent; import com.intellectualcrafters.plot.events.PlotDeleteEvent;
import com.intellectualcrafters.plot.flag.AbstractFlag; import com.intellectualcrafters.plot.flag.AbstractFlag;
import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.flag.FlagValue;
import com.intellectualcrafters.plot.generator.HybridGen; import com.intellectualcrafters.plot.generator.HybridGen;
import com.intellectualcrafters.plot.generator.HybridPlotManager; import com.intellectualcrafters.plot.generator.HybridPlotManager;
import com.intellectualcrafters.plot.generator.HybridPlotWorld; import com.intellectualcrafters.plot.generator.HybridPlotWorld;
@ -1030,134 +1031,27 @@ public class PlotMain extends JavaPlugin implements Listener {
final List<String> intervalFlags = Arrays.asList("feed", "heal"); final List<String> intervalFlags = Arrays.asList("feed", "heal");
final List<String> stringFlags = Arrays.asList("greeting", "farewell"); final List<String> stringFlags = Arrays.asList("greeting", "farewell");
for (final String flag : stringFlags) { for (final String flag : stringFlags) {
FlagManager.addFlag(new AbstractFlag(flag) { FlagManager.addFlag(new AbstractFlag(flag));
@Override
public String parseValue(final String value) {
return value;
}
@Override
public String getValueDesc() {
return "Value must be a string, supports color codes (&)";
}
});
} }
for (final String flag : intervalFlags) { for (final String flag : intervalFlags) {
FlagManager.addFlag(new AbstractFlag(flag) { FlagManager.addFlag(new AbstractFlag(flag, new FlagValue.IntervalValue()));
@Override
public String parseValue(final String value) {
int seconds;
int amount;
final String[] values = value.split(" ");
if (values.length < 2) {
seconds = 1;
try {
amount = Integer.parseInt(values[0]);
} catch (final Exception e) {
return null;
}
} else {
try {
amount = Integer.parseInt(values[0]);
seconds = Integer.parseInt(values[1]);
} catch (final Exception e) {
return null;
}
}
return amount + " " + seconds;
}
@Override
public String getValueDesc() {
return "Value(s) must be numeric. /plot set flag {flag} {amount} [seconds]";
}
});
} }
for (final String flag : booleanFlags) { for (final String flag : booleanFlags) {
FlagManager.addFlag(new AbstractFlag(flag) { FlagManager.addFlag(new AbstractFlag(flag, new FlagValue.BooleanValue()));
@Override
public String parseValue(final String value) {
switch (value) {
case "on":
case "1":
case "true":
case "enabled":
return "true";
case "off":
case "0":
case "false":
case "disabled":
return "false";
default:
return null;
}
}
@Override
public String getValueDesc() {
return "Value must be true/false, 1/0, on/off, enabled/disabled";
}
});
} }
} }
private static void defaultFlags() { private static void defaultFlags() {
addPlusFlags(); addPlusFlags();
FlagManager.addFlag(new AbstractFlag("fly") { FlagManager.addFlag(new AbstractFlag("fly", new FlagValue.BooleanValue()));
@Override
public String parseValue(final String value) {
switch (value) {
case "on":
case "enabled":
case "true":
case "1":
return "true";
case "off":
case "disabled":
case "false":
case "0":
return "false";
default:
return null;
}
}
@Override
public String getValueDesc() {
return "Flag value must be a boolean: true, false, enabled, disabled";
}
});
for (final String str : booleanFlags.values()) { for (final String str : booleanFlags.values()) {
FlagManager.addFlag(new AbstractFlag(str) { FlagManager.addFlag(new AbstractFlag(str, new FlagValue.BooleanValue()));
@Override
public String parseValue(final String value) {
switch (value) {
case "true":
case "1":
case "yes":
return "true";
case "false":
case "off":
case "0":
return "false";
default:
return null;
}
}
@Override
public String getValueDesc() {
return "Flag value must be a boolean: true, false";
}
});
} }
FlagManager.addFlag(new AbstractFlag("gamemode") { FlagManager.addFlag(new AbstractFlag("gamemode") {
@Override @Override
public String parseValue(final String value) { public String parseValueRaw(final String value) {
switch (value) { switch (value) {
case "creative": case "creative":
case "c": case "c":
@ -1182,48 +1076,13 @@ public class PlotMain extends JavaPlugin implements Listener {
} }
}); });
FlagManager.addFlag(new AbstractFlag("price") { FlagManager.addFlag(new AbstractFlag("price", new FlagValue.UnsignedDoubleValue()));
@Override
public String parseValue(final String value) {
try {
double price = Double.parseDouble(value);
if (price >= 0) {
return price + "";
}
else {
return null;
}
}
catch (Exception e) {
return null;
}
}
@Override FlagManager.addFlag(new AbstractFlag("time", new FlagValue.LongValue()));
public String getValueDesc() {
return "Flag value must be a positive number representing the price of the plot'";
}
});
FlagManager.addFlag(new AbstractFlag("time") {
@Override
public String parseValue(final String value) {
try {
return Long.parseLong(value) + "";
} catch (final Exception e) {
return null;
}
}
@Override
public String getValueDesc() {
return "Flag value must be a time in ticks: 0=sunrise 12000=noon 18000=sunset 24000=night";
}
});
FlagManager.addFlag(new AbstractFlag("weather") { FlagManager.addFlag(new AbstractFlag("weather") {
@Override @Override
public String parseValue(final String value) { public String parseValueRaw(final String value) {
switch (value) { switch (value) {
case "rain": case "rain":
case "storm": case "storm":

View File

@ -86,7 +86,7 @@ public class Buy extends SubCommand {
if (flag == null) { if (flag == null) {
return sendMessage(plr, C.NOT_FOR_SALE); return sendMessage(plr, C.NOT_FOR_SALE);
} }
double initPrice = Double.parseDouble(flag.getValue()); double initPrice = (double) flag.getValue();
double price = initPrice; double price = initPrice;
PlotId id = plot.id; PlotId id = plot.id;
PlotId id2 = PlayerFunctions.getTopPlot(world, plot).id; PlotId id2 = PlayerFunctions.getTopPlot(world, plot).id;

View File

@ -149,18 +149,18 @@ public class Set extends SubCommand {
} }
try { try {
String value = StringUtils.join(Arrays.copyOfRange(args, 2, args.length), " "); String value = StringUtils.join(Arrays.copyOfRange(args, 2, args.length), " ");
value = af.parseValue(value); Object parsed_value = af.parseValueRaw(value);
if (value == null) { if (parsed_value == null) {
PlayerFunctions.sendMessage(plr, af.getValueDesc()); PlayerFunctions.sendMessage(plr, af.getValueDesc());
return false; return false;
} }
if ((FlagManager.getFlag(args[1].toLowerCase()) == null) && (PlotMain.worldGuardListener != null)) { if ((FlagManager.getFlag(args[1].toLowerCase()) == null) && (PlotMain.worldGuardListener != null)) {
PlotMain.worldGuardListener.addFlag(plr, plr.getWorld(), plot, args[1], value); PlotMain.worldGuardListener.addFlag(plr, plr.getWorld(), plot, args[1], af.toString(parsed_value));
return false; return false;
} }
final Flag flag = new Flag(FlagManager.getFlag(args[1].toLowerCase(), true), value); final Flag flag = new Flag(FlagManager.getFlag(args[1].toLowerCase(), true), parsed_value);
boolean result = FlagManager.addPlotFlag(plot, flag); boolean result = FlagManager.addPlotFlag(plot, flag);
if (!result) { if (!result) {
PlayerFunctions.sendMessage(plr, C.FLAG_NOT_ADDED); PlayerFunctions.sendMessage(plr, C.FLAG_NOT_ADDED);

View File

@ -80,7 +80,7 @@ public class list extends SubCommand {
for (final Plot p : PlotMain.getPlots(plr.getWorld()).values()) { for (final Plot p : PlotMain.getPlots(plr.getWorld()).values()) {
Flag price = FlagManager.getPlotFlag(p, "price"); Flag price = FlagManager.getPlotFlag(p, "price");
if (price != null) { if (price != null) {
string.append(C.PLOT_LIST_ITEM_ORDERED.s().replaceAll("%in", idx + 1 + "").replaceAll("%id", p.id.toString()).replaceAll("%world", price.getValue()).replaceAll("%owner", getName(p.owner))).append("\n"); string.append(C.PLOT_LIST_ITEM_ORDERED.s().replaceAll("%in", idx + 1 + "").replaceAll("%id", p.id.toString()).replaceAll("%world", price.getValueString()).replaceAll("%owner", getName(p.owner))).append("\n");
idx++; idx++;
} }
} }

View File

@ -683,7 +683,9 @@ public class SQLManager implements AbstractDB {
if (element.contains(":")) { if (element.contains(":")) {
final String[] split = element.split(":"); final String[] split = element.split(":");
try { try {
flags.add(new Flag(FlagManager.getFlag(split[0], true), split[1].replaceAll("\u00AF", ":").replaceAll("<EFBFBD>", ","))); String flag_str = split[1].replaceAll("\u00AF", ":").replaceAll("<EFBFBD>", ",");
Flag flag = new Flag(FlagManager.getFlag(split[0], true), flag_str);
flags.add(flag);
} catch (final Exception e) { } catch (final Exception e) {
e.printStackTrace(); e.printStackTrace();
exception = true; exception = true;
@ -756,7 +758,7 @@ public class SQLManager implements AbstractDB {
if (i != 0) { if (i != 0) {
flag_string.append(","); flag_string.append(",");
} }
flag_string.append(flag.getKey() + ":" + flag.getValue().replaceAll(":", "\u00AF").replaceAll(",", "\u00B4")); flag_string.append(flag.getKey() + ":" + flag.getValueString().replaceAll(":", "\u00AF").replaceAll(",", "\u00B4"));
i++; i++;
} }
TaskManager.runTask(new Runnable() { TaskManager.runTask(new Runnable() {

View File

@ -37,11 +37,10 @@ public class AbstractFlag {
public AbstractFlag(final String key) { public AbstractFlag(final String key) {
this(key, new FlagValue.StringValue()); this(key, new FlagValue.StringValue());
} }
/** /**
* AbstractFlag is a parameter used in creating a new Flag * AbstractFlag is a parameter used in creating a new Flag<br>
* * The key must be alphabetical characters and <= 16 characters in length
* @param key The key must be alphabetical characters and <= 16 characters in length * @param key
*/ */
public AbstractFlag(final String key, final FlagValue<?> value) { public AbstractFlag(final String key, final FlagValue<?> value) {
if (!StringUtils.isAlpha(key.replaceAll("_", "").replaceAll("-", ""))) { if (!StringUtils.isAlpha(key.replaceAll("_", "").replaceAll("-", ""))) {
@ -58,10 +57,14 @@ public class AbstractFlag {
} }
} }
public String parseValue(final String value) { public Object parseValueRaw(final String value) {
return this.value.parse(value); return this.value.parse(value);
} }
public String toString(final Object t) {
return this.value.toString(t);
}
public String getValueDesc() { public String getValueDesc() {
return this.value.getDescription(); return this.value.getDescription();
} }

View File

@ -25,7 +25,7 @@ import org.apache.commons.lang.StringUtils;
public class Flag { public class Flag {
private final AbstractFlag key; private final AbstractFlag key;
private final String value; private final Object value;
/** /**
* Flag object used to store basic information for a Plot. Flags are a key/value pair. For a flag to be usable by a * Flag object used to store basic information for a Plot. Flags are a key/value pair. For a flag to be usable by a
@ -49,12 +49,20 @@ public class Flag {
throw new IllegalArgumentException("Value must be <= 48 characters"); throw new IllegalArgumentException("Value must be <= 48 characters");
} }
this.key = key; this.key = key;
this.value = key.parseValue(value); this.value = key.parseValueRaw(value);
if (this.value == null) { if (this.value == null) {
throw new IllegalArgumentException(key.getValueDesc()); throw new IllegalArgumentException(key.getValueDesc());
} }
} }
/**
* Warning: Unchecked
*/
public Flag(final AbstractFlag key, final Object value) {
this.key = key;
this.value = value;
}
/** /**
* Get the AbstractFlag used in creating the flag * Get the AbstractFlag used in creating the flag
* *
@ -78,16 +86,20 @@ public class Flag {
* *
* @return String * @return String
*/ */
public String getValue() { public Object getValue() {
return this.value; return this.value;
} }
public String getValueString() {
return this.key.toString(this.value);
}
@Override @Override
public String toString() { public String toString() {
if (this.value.equals("")) { if (this.value.equals("")) {
return this.key.getKey(); return this.key.getKey();
} }
return this.key + ":" + this.value; return this.key + ":" + getValueString();
} }
@Override @Override

View File

@ -1,5 +1,11 @@
package com.intellectualcrafters.plot.flag; package com.intellectualcrafters.plot.flag;
import java.util.HashSet;
import org.apache.commons.lang.StringUtils;
import com.intellectualcrafters.plot.object.PlotBlock;
/** /**
* Created 2014-11-17 for PlotSquared * Created 2014-11-17 for PlotSquared
* *
@ -9,6 +15,7 @@ public abstract class FlagValue<T> {
private final Class<T> clazz; private final Class<T> clazz;
@SuppressWarnings("unchecked")
public FlagValue() { public FlagValue() {
this.clazz = (Class<T>) getClass(); this.clazz = (Class<T>) getClass();
} }
@ -24,30 +31,301 @@ public abstract class FlagValue<T> {
return (value != null) && (value.getClass() == this.clazz); return (value != null) && (value.getClass() == this.clazz);
} }
public abstract T getValue(String t); public String toString(Object t) {
return t.toString();
}
public abstract String parse(String t); public abstract T getValue(Object t);
public abstract T parse(String t);
public abstract String getDescription(); public abstract String getDescription();
public static class BooleanValue extends FlagValue<Boolean> { public static class BooleanValue extends FlagValue<Boolean> {
@Override @Override
public Boolean getValue(final String t) { public Boolean getValue(final Object t) {
return null; return (Boolean) t;
} }
@Override @Override
public String parse(final String t) { public Boolean parse(final String t) {
try {
return Boolean.parseBoolean(t);
}
catch (IllegalArgumentException e) {
return null; return null;
} }
}
@Override @Override
public String getDescription() { public String getDescription() {
return "Flag value must be a boolean (true|false)";
}
}
public static class IntegerValue extends FlagValue<Integer> {
@Override
public Integer getValue(final Object t) {
return (Integer) t;
}
@Override
public Integer parse(final String t) {
try {
return Integer.parseInt(t);
}
catch (IllegalArgumentException e) {
return null; return null;
} }
} }
@Override
public String getDescription() {
return "Flag value must be a whole number";
}
}
public static class IntervalValue extends FlagValue<Integer[]> {
@Override
public String toString(Object t) {
Integer[] value = ((Integer[]) t);
return value[0] + " " + value[1];
}
@Override
public Integer[] getValue(final Object t) {
return (Integer[]) t;
}
@Override
public Integer[] parse(final String t) {
int seconds;
int amount;
final String[] values = t.split(" ");
if (values.length < 2) {
seconds = 1;
try {
amount = Integer.parseInt(values[0]);
} catch (final Exception e) {
return null;
}
} else {
try {
amount = Integer.parseInt(values[0]);
seconds = Integer.parseInt(values[1]);
} catch (final Exception e) {
return null;
}
}
return new Integer[]{amount, seconds};
}
@Override
public String getDescription() {
return "Value(s) must be numeric. /plot set flag {flag} {amount} [seconds]";
}
}
public static class UnsignedIntegerValue extends FlagValue<Integer> {
@Override
public Integer getValue(final Object t) {
return (Integer) t;
}
@Override
public Integer parse(final String t) {
try {
int value = Integer.parseInt(t);
if (value >= 0) {
return null;
}
return value;
}
catch (IllegalArgumentException e) {
return null;
}
}
@Override
public String getDescription() {
return "Flag value must be a positive whole number (includes 0)";
}
}
public static class DoubleValue extends FlagValue<Double> {
@Override
public Double getValue(final Object t) {
return (Double) t;
}
@Override
public Double parse(final String t) {
try {
return Double.parseDouble(t);
}
catch (IllegalArgumentException e) {
return null;
}
}
@Override
public String getDescription() {
return "Flag value must be a number (negative decimals are allowed)";
}
}
public static class LongValue extends FlagValue<Long> {
@Override
public Long getValue(final Object t) {
return (Long) t;
}
@Override
public Long parse(final String t) {
try {
return Long.parseLong(t);
}
catch (IllegalArgumentException e) {
return null;
}
}
@Override
public String getDescription() {
return "Flag value must be a whole number (large numbers allowed)";
}
}
public static class UnsignedLongValue extends FlagValue<Long> {
@Override
public Long getValue(final Object t) {
return (Long) t;
}
@Override
public Long parse(final String t) {
try {
long value = Long.parseLong(t);
if (value < 0) {
return null;
}
return value;
}
catch (IllegalArgumentException e) {
return null;
}
}
@Override
public String getDescription() {
return "Flag value must be a positive whole number (large numbers allowed)";
}
}
public static class UnsignedDoubleValue extends FlagValue<Double> {
@Override
public Double getValue(final Object t) {
return (Double) t;
}
@Override
public Double parse(final String t) {
try {
double value = Double.parseDouble(t);
if (value < 0) {
return null;
}
return value;
}
catch (IllegalArgumentException e) {
return null;
}
}
@Override
public String getDescription() {
return "Flag value must be a positive number (decimals allowed)";
}
}
public static class PlotBlockValue extends FlagValue<PlotBlock> {
@Override
public PlotBlock getValue(final Object t) {
return (PlotBlock) t;
}
@Override
public PlotBlock parse(final String t) {
try {
String[] split = t.split(":");
byte data;
if (split.length == 2) {
data = Byte.parseByte(split[1]);
}
else {
data = 0;
}
short id = Short.parseShort(split[0]);
return new PlotBlock(id, data);
}
catch (Exception e) {
return null;
}
}
@Override
public String getDescription() {
return "Flag value must be a number (negative decimals are allowed)";
}
}
public static class PlotBlockListValue extends FlagValue<HashSet<PlotBlock>> {
@Override
public String toString(Object t) {
return StringUtils.join((HashSet<PlotBlock>) t, ",");
}
@SuppressWarnings("unchecked")
@Override
public HashSet<PlotBlock> getValue(final Object t) {
return (HashSet<PlotBlock>)t;
}
@Override
public HashSet<PlotBlock> parse(final String t) {
HashSet<PlotBlock> list = new HashSet<PlotBlock>();
for (String item : t.split(",")) {
String[] split = item.split(":");
byte data;
if (split.length == 2) {
data = Byte.parseByte(split[1]);
}
else {
data = 0;
}
short id = Short.parseShort(split[0]);
PlotBlock block = new PlotBlock(id, data);
list.add(block);
}
return list;
}
@Override
public String getDescription() {
return "Flag value must be a block list";
}
}
public static class StringValue extends FlagValue<String> { public static class StringValue extends FlagValue<String> {
@Override @Override
@ -57,12 +335,12 @@ public abstract class FlagValue<T> {
@Override @Override
public String getDescription() { public String getDescription() {
return "Flag value must be alphanumeric"; return "Flag value must be alphanumeric. Some special characters are allowed.";
} }
@Override @Override
public String getValue(final String t) { public String getValue(final Object t) {
return t; return t.toString();
} }
} }
} }

View File

@ -104,7 +104,7 @@ public class ForceFieldListener implements Listener {
} }
final Plot plot = PlayerFunctions.getCurrentPlot(player); final Plot plot = PlayerFunctions.getCurrentPlot(player);
if ((FlagManager.getPlotFlag(plot, "forcefield") != null) && FlagManager.getPlotFlag(plot, "forcefield").getValue().equals("true")) { if ((FlagManager.getPlotFlag(plot, "forcefield") != null) && FlagManager.getPlotFlag(plot, "forcefield").getValue().equals("true")) {
if (!PlotListener.booleanFlag(plot, "forcefield")) { if (!PlotListener.booleanFlag(plot, "forcefield", false)) {
if (plot.hasRights(player)) { if (plot.hasRights(player)) {
final Set<Player> players = getNearbyPlayers(player, plot); final Set<Player> players = getNearbyPlayers(player, plot);
for (final Player oPlayer : players) { for (final Player oPlayer : players) {

View File

@ -468,7 +468,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
} }
if (PlotMain.booleanFlags.containsKey(event.getClickedBlock().getType())) { if (PlotMain.booleanFlags.containsKey(event.getClickedBlock().getType())) {
final String flag = PlotMain.booleanFlags.get(event.getClickedBlock().getType()); final String flag = PlotMain.booleanFlags.get(event.getClickedBlock().getType());
if ((FlagManager.getPlotFlag(plot, flag) != null) && getFlagValue(FlagManager.getPlotFlag(plot, flag).getValue())) { if (PlotListener.booleanFlag(plot, flag, false)) {
return; return;
} }
} }
@ -782,10 +782,10 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
e.setCancelled(true); e.setCancelled(true);
return; return;
} }
} else if (aPlr && !booleanFlag(plot, "pvp")) { } else if (aPlr && !booleanFlag(plot, "pvp", false)) {
return; return;
} }
if (!aPlr && !booleanFlag(plot, "pve")) { if (!aPlr && !booleanFlag(plot, "pve", false)) {
return; return;
} }
assert plot != null; assert plot != null;

View File

@ -41,6 +41,7 @@ import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.events.PlayerEnterPlotEvent; import com.intellectualcrafters.plot.events.PlayerEnterPlotEvent;
import com.intellectualcrafters.plot.events.PlayerLeavePlotEvent; import com.intellectualcrafters.plot.events.PlayerLeavePlotEvent;
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotId;
@ -49,6 +50,7 @@ import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.titles.AbstractTitle; import com.intellectualcrafters.plot.titles.AbstractTitle;
import com.intellectualcrafters.plot.util.PlayerFunctions; import com.intellectualcrafters.plot.util.PlayerFunctions;
import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualcrafters.plot.util.UUIDHandler;
import com.sk89q.worldguard.protection.flags.BooleanFlag;
/** /**
* @author Citymonstret * @author Citymonstret
@ -62,6 +64,18 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
} }
} }
public static boolean booleanFlag(Plot plot, String key, boolean defaultValue) {
Flag flag = FlagManager.getPlotFlag(plot, key);
if (flag == null) {
return defaultValue;
}
Object value = flag.getValue();
if (value instanceof Boolean) {
return (boolean) value;
}
return defaultValue;
}
public static boolean isInPlot(final Player player) { public static boolean isInPlot(final Player player) {
return PlayerFunctions.isInPlot(player); return PlayerFunctions.isInPlot(player);
} }
@ -149,27 +163,6 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
} }
} }
public static boolean booleanFlag(final Plot plot, final String flag) {
return (FlagManager.getPlotFlag(plot, flag) != null) && getBooleanFlag(FlagManager.getPlotFlag(plot, flag).getValue()).equals("true");
}
private static String getBooleanFlag(final String value) {
switch (value) {
case "on":
case "1":
case "true":
case "enabled":
return "true";
case "off":
case "0":
case "false":
case "disabled":
return "false";
default:
return null;
}
}
private static GameMode getGameMode(final String str) { private static GameMode getGameMode(final String str) {
switch (str) { switch (str) {
case "creative": case "creative":
@ -185,24 +178,28 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
public static void plotEntry(final Player player, final Plot plot) { public static void plotEntry(final Player player, final Plot plot) {
if (plot.hasOwner()) { if (plot.hasOwner()) {
if (FlagManager.getPlotFlag(plot, "gamemode") != null) { Flag gamemodeFlag = FlagManager.getPlotFlag(plot, "gamemode");
player.setGameMode(getGameMode(FlagManager.getPlotFlag(plot, "gamemode").getValue())); if (gamemodeFlag != null) {
player.setGameMode(getGameMode(gamemodeFlag.getValueString()));
} }
if (FlagManager.getPlotFlag(plot, "fly") != null) { Flag flyFlag = FlagManager.getPlotFlag(plot, "fly");
player.setAllowFlight(getFlagValue(FlagManager.getPlotFlag(plot, "fly").getValue())); if (flyFlag != null) {
player.setAllowFlight((boolean) flyFlag.getValue());
} }
if (FlagManager.getPlotFlag(plot, "time") != null) { Flag timeFlag = FlagManager.getPlotFlag(plot, "time");
if (timeFlag != null) {
try { try {
final Long time = Long.parseLong(FlagManager.getPlotFlag(plot, "time").getValue()); long time = (long) timeFlag.getValue();
player.setPlayerTime(time, true); player.setPlayerTime(time, true);
} catch (final Exception e) { } catch (final Exception e) {
FlagManager.removePlotFlag(plot, "time"); FlagManager.removePlotFlag(plot, "time");
} }
} }
if (FlagManager.getPlotFlag(plot, "weather") != null) { Flag weatherFlag = FlagManager.getPlotFlag(plot, "weather");
player.setPlayerWeather(getWeatherType(FlagManager.getPlotFlag(plot, "weather").getValue())); if (weatherFlag != null) {
player.setPlayerWeather(getWeatherType(weatherFlag.getValueString()));
} }
if ((booleanFlag(plot, "titles") || Settings.TITLES) && (C.TITLE_ENTERED_PLOT.s().length() > 2)) { if ((booleanFlag(plot, "titles", false) || Settings.TITLES) && (C.TITLE_ENTERED_PLOT.s().length() > 2)) {
final String sTitleMain = C.TITLE_ENTERED_PLOT.s().replaceAll("%x%", plot.id.x + "").replaceAll("%z%", plot.id.y + "").replaceAll("%world%", plot.world + ""); final String sTitleMain = C.TITLE_ENTERED_PLOT.s().replaceAll("%x%", plot.id.x + "").replaceAll("%z%", plot.id.y + "").replaceAll("%world%", plot.world + "");
final String sTitleSub = C.TITLE_ENTERED_PLOT_SUB.s().replaceFirst("%s", getName(plot.owner)); final String sTitleSub = C.TITLE_ENTERED_PLOT_SUB.s().replaceFirst("%s", getName(plot.owner));
final ChatColor sTitleMainColor = ChatColor.valueOf(C.TITLE_ENTERED_PLOT_COLOR.s()); final ChatColor sTitleMainColor = ChatColor.valueOf(C.TITLE_ENTERED_PLOT_COLOR.s());

View File

@ -145,7 +145,7 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
return; return;
} }
final Plot plot = getPlot(player); final Plot plot = getPlot(player);
if (booleanFlag(plot, "instabreak")) { if (booleanFlag(plot, "instabreak", false)) {
event.getBlock().breakNaturally(); event.getBlock().breakNaturally();
} }
} }
@ -159,21 +159,21 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
if (!isInPlot(player)) { if (!isInPlot(player)) {
return; return;
} }
if (booleanFlag(getPlot(player), "invincible")) { if (booleanFlag(getPlot(player), "invincible", false)) {
event.setCancelled(true); event.setCancelled(true);
} }
} }
@EventHandler @EventHandler
public void onItemPickup(final PlayerPickupItemEvent event) { public void onItemPickup(final PlayerPickupItemEvent event) {
if (isInPlot(event.getPlayer()) && !getPlot(event.getPlayer()).hasRights(event.getPlayer()) && booleanFlag(getPlot(event.getPlayer()), "drop-protection")) { if (isInPlot(event.getPlayer()) && !getPlot(event.getPlayer()).hasRights(event.getPlayer()) && booleanFlag(getPlot(event.getPlayer()), "drop-protection", false)) {
event.setCancelled(true); event.setCancelled(true);
} }
} }
@EventHandler @EventHandler
public void onItemDrop(final PlayerDropItemEvent event) { public void onItemDrop(final PlayerDropItemEvent event) {
if (isInPlot(event.getPlayer()) && !getPlot(event.getPlayer()).hasRights(event.getPlayer()) && booleanFlag(getPlot(event.getPlayer()), "item-drop")) { if (isInPlot(event.getPlayer()) && !getPlot(event.getPlayer()).hasRights(event.getPlayer()) && booleanFlag(getPlot(event.getPlayer()), "item-drop", false)) {
event.setCancelled(true); event.setCancelled(true);
} }
} }
@ -182,9 +182,9 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
public void onPlotEnter(final PlayerEnterPlotEvent event) { public void onPlotEnter(final PlayerEnterPlotEvent event) {
final Plot plot = event.getPlot(); final Plot plot = event.getPlot();
if (FlagManager.getPlotFlag(plot, "greeting") != null) { if (FlagManager.getPlotFlag(plot, "greeting") != null) {
event.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', FlagManager.getPlotFlag(plot, "greeting").getValue())); event.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', FlagManager.getPlotFlag(plot, "greeting").getValueString()));
} }
if (booleanFlag(plot, "notify-enter")) { if (booleanFlag(plot, "notify-enter", false)) {
if (plot.hasOwner()) { if (plot.hasOwner()) {
final Player player = UUIDHandler.uuidWrapper.getPlayer(plot.getOwner()); final Player player = UUIDHandler.uuidWrapper.getPlayer(plot.getOwner());
@ -216,7 +216,7 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
event.getPlayer().playEffect(event.getPlayer().getLocation(), Effect.RECORD_PLAY, 0); event.getPlayer().playEffect(event.getPlayer().getLocation(), Effect.RECORD_PLAY, 0);
final Plot plot = event.getPlot(); final Plot plot = event.getPlot();
if (FlagManager.getPlotFlag(plot, "farewell") != null) { if (FlagManager.getPlotFlag(plot, "farewell") != null) {
event.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', FlagManager.getPlotFlag(plot, "farewell").getValue())); event.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', FlagManager.getPlotFlag(plot, "farewell").getValueString()));
} }
if (feedRunnable.containsKey(event.getPlayer().getName())) { if (feedRunnable.containsKey(event.getPlayer().getName())) {
feedRunnable.remove(event.getPlayer().getName()); feedRunnable.remove(event.getPlayer().getName());
@ -224,7 +224,7 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
if (healRunnable.containsKey(event.getPlayer().getName())) { if (healRunnable.containsKey(event.getPlayer().getName())) {
healRunnable.remove(event.getPlayer().getName()); healRunnable.remove(event.getPlayer().getName());
} }
if (booleanFlag(plot, "notify-leave")) { if (booleanFlag(plot, "notify-leave", false)) {
if (plot.hasOwner()) { if (plot.hasOwner()) {
final Player player = UUIDHandler.uuidWrapper.getPlayer(plot.getOwner()); final Player player = UUIDHandler.uuidWrapper.getPlayer(plot.getOwner());
if (player == null) { if (player == null) {

View File

@ -136,7 +136,7 @@ import com.intellectualcrafters.plot.util.PlotHelper;
public String getJoinMessage() { public String getJoinMessage() {
final Flag greeting = FlagManager.getPlotFlag(plot, "greeting"); final Flag greeting = FlagManager.getPlotFlag(plot, "greeting");
if (greeting != null) { if (greeting != null) {
return greeting.getValue(); return greeting.getValueString();
} }
return ""; return "";
} }
@ -149,7 +149,7 @@ import com.intellectualcrafters.plot.util.PlotHelper;
public String getLeaveMessage() { public String getLeaveMessage() {
final Flag farewell = FlagManager.getPlotFlag(plot, "farewell"); final Flag farewell = FlagManager.getPlotFlag(plot, "farewell");
if (farewell != null) { if (farewell != null) {
return farewell.getValue(); return farewell.getValueString();
} }
return ""; return "";
} }