Start implementing new Flag system.

This commit is contained in:
MattBDev 2016-04-19 16:59:10 -04:00
parent d3dd88eb8d
commit aaf9511673
65 changed files with 1679 additions and 1322 deletions

View File

@ -385,18 +385,6 @@ public class PlotAPI {
FlagManager.addFlag(flag); FlagManager.addFlag(flag);
} }
/**
* get all the currently registered flags.
*
* @return array of Flag[]
*
* @see FlagManager#getFlags()
* @see AbstractFlag
*/
public AbstractFlag[] getFlags() {
return FlagManager.getFlags().toArray(new AbstractFlag[FlagManager.getFlags().size()]);
}
/** /**
* Get a plot based on the ID. * Get a plot based on the ID.
* *
@ -663,7 +651,7 @@ public class PlotAPI {
if (world == null) { if (world == null) {
return new HashSet<>(); return new HashSet<>();
} }
return BukkitUtil.getPlayer(player).getPlots(world.getName()); return PlotPlayer.wrap(player).getPlots(world.getName());
} }
/** /**
@ -675,7 +663,7 @@ public class PlotAPI {
* *
*/ */
public int getAllowedPlots(Player player) { public int getAllowedPlots(Player player) {
PlotPlayer pp = BukkitUtil.getPlayer(player); PlotPlayer pp = PlotPlayer.wrap(player);
return pp.getAllowedPlots(); return pp.getAllowedPlots();
} }

View File

@ -6,7 +6,6 @@ import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.ConfigurationNode; import com.intellectualcrafters.plot.config.ConfigurationNode;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.generator.GeneratorWrapper; import com.intellectualcrafters.plot.generator.GeneratorWrapper;
import com.intellectualcrafters.plot.generator.HybridGen; import com.intellectualcrafters.plot.generator.HybridGen;
import com.intellectualcrafters.plot.generator.HybridUtils; import com.intellectualcrafters.plot.generator.HybridUtils;
@ -95,7 +94,7 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
public static WorldEditPlugin worldEdit; public static WorldEditPlugin worldEdit;
@ -195,14 +194,18 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
public void run() { public void run() {
PS.get().foreachPlotArea(new RunnableVal<PlotArea>() { PS.get().foreachPlotArea(new RunnableVal<PlotArea>() {
@Override @Override
public void run(PlotArea pw) { public void run(PlotArea plotArea) {
World world = Bukkit.getWorld(pw.worldname); World world = Bukkit.getWorld(plotArea.worldname);
try { try {
if (world == null) { if (world == null) {
return; return;
} }
List<Entity> entities = world.getEntities(); List<Entity> entities = world.getEntities();
Iterator<Entity> iterator = entities.iterator(); Iterator<Entity> iterator = entities.iterator();
for (Entity entity : entities) {
}
while (iterator.hasNext()) { while (iterator.hasNext()) {
Entity entity = iterator.next(); Entity entity = iterator.next();
switch (entity.getType()) { switch (entity.getType()) {
@ -211,6 +214,7 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
case COMPLEX_PART: case COMPLEX_PART:
case FISHING_HOOK: case FISHING_HOOK:
case ENDER_SIGNAL: case ENDER_SIGNAL:
case LINGERING_POTION:
case AREA_EFFECT_CLOUD: case AREA_EFFECT_CLOUD:
case EXPERIENCE_ORB: case EXPERIENCE_ORB:
case LEASH_HITCH: case LEASH_HITCH:
@ -507,7 +511,6 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
if (!checkVersion) { if (!checkVersion) {
log(C.PREFIX + " &c[WARN] Titles are disabled - please update your version of Bukkit to support this feature."); log(C.PREFIX + " &c[WARN] Titles are disabled - please update your version of Bukkit to support this feature.");
Settings.TITLES = false; Settings.TITLES = false;
FlagManager.removeFlag(FlagManager.getFlag("titles"));
} else { } else {
AbstractTitle.TITLE_CLASS = new DefaultTitle_19(); AbstractTitle.TITLE_CLASS = new DefaultTitle_19();
if (wrapper instanceof DefaultUUIDWrapper || wrapper.getClass() == OfflineUUIDWrapper.class && !Bukkit.getOnlineMode()) { if (wrapper instanceof DefaultUUIDWrapper || wrapper.getClass() == OfflineUUIDWrapper.class && !Bukkit.getOnlineMode()) {

View File

@ -5,8 +5,6 @@ import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotId;
import org.bukkit.Bukkit;
import org.bukkit.World;
import java.sql.Connection; import java.sql.Connection;
import java.sql.SQLException; import java.sql.SQLException;
@ -21,15 +19,6 @@ abstract class APlotMeConnector {
public abstract boolean accepts(String version); public abstract boolean accepts(String version);
public String getWorld(String world) {
for (World newWorld : Bukkit.getWorlds()) {
if (newWorld.getName().equalsIgnoreCase(world)) {
return newWorld.getName();
}
}
return world;
}
public boolean isValidConnection(Connection connection) { public boolean isValidConnection(Connection connection) {
return connection != null; return connection != null;
} }

View File

@ -1,6 +1,7 @@
package com.plotsquared.bukkit.listeners; package com.plotsquared.bukkit.listeners;
import com.intellectualcrafters.plot.flag.FlagManager; import com.google.common.base.Optional;
import com.intellectualcrafters.plot.flag.Flags;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
@ -36,7 +37,13 @@ public class ForceFieldListener implements Listener {
private PlotPlayer hasNearbyPermitted(Player player, Plot plot) { private PlotPlayer hasNearbyPermitted(Player player, Plot plot) {
for (Entity entity : player.getNearbyEntities(5d, 5d, 5d)) { for (Entity entity : player.getNearbyEntities(5d, 5d, 5d)) {
PlotPlayer pp; PlotPlayer pp;
if (!(entity instanceof Player) || ((pp = BukkitUtil.getPlayer((Player) entity)) == null) || !plot.equals(pp.getCurrentPlot())) { if (!(entity instanceof Player)) {
continue;
}
if ((pp = BukkitUtil.getPlayer((Player) entity)) == null) {
continue;
}
if (!plot.equals(pp.getCurrentPlot())) {
continue; continue;
} }
if (plot.isAdded(pp.getUUID())) { if (plot.isAdded(pp.getUUID())) {
@ -84,8 +91,9 @@ public class ForceFieldListener implements Listener {
if (plot == null) { if (plot == null) {
return; return;
} }
if ((FlagManager.getPlotFlagRaw(plot, "forcefield") != null) && FlagManager.getPlotFlagRaw(plot, "forcefield").getValue().equals("true")) { Optional<Boolean> forcefield = plot.getFlag(Flags.FORCEFIELD);
if (!FlagManager.isBooleanFlag(plot, "forcefield", false)) { if (forcefield.isPresent() && forcefield.get()) {
if (!plot.getFlag(Flags.FORCEFIELD).or(false)) {
UUID uuid = pp.getUUID(); UUID uuid = pp.getUUID();
if (plot.isAdded(uuid)) { if (plot.isAdded(uuid)) {
Set<PlotPlayer> players = getNearbyPlayers(player, plot); Set<PlotPlayer> players = getNearbyPlayers(player, plot);

View File

@ -1,7 +1,7 @@
package com.plotsquared.bukkit.listeners; package com.plotsquared.bukkit.listeners;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.flag.Flags;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotArea; import com.intellectualcrafters.plot.object.PlotArea;
@ -35,7 +35,7 @@ public class PlayerEvents183 implements Listener {
return; return;
} }
Plot plot = area.getOwnedPlot(loc); Plot plot = area.getOwnedPlot(loc);
if (plot == null || !FlagManager.isPlotFlagTrue(plot, "explosion")) { if (plot == null || !plot.getFlag(Flags.EXPLOSION).or(false)) {
event.setCancelled(true); event.setCancelled(true);
} }
Iterator<Block> iterator = event.blockList().iterator(); Iterator<Block> iterator = event.blockList().iterator();

View File

@ -1,7 +1,7 @@
package com.plotsquared.bukkit.listeners; package com.plotsquared.bukkit.listeners;
import com.intellectualcrafters.plot.flag.Flag; import com.google.common.base.Optional;
import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.flag.Flags;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.plotsquared.bukkit.events.PlayerEnterPlotEvent; import com.plotsquared.bukkit.events.PlayerEnterPlotEvent;
@ -88,7 +88,7 @@ public class PlotPlusListener extends PlotListener implements Listener {
if (plot == null) { if (plot == null) {
return; return;
} }
if (FlagManager.isBooleanFlag(plot, "instabreak", false)) { if (plot.getFlag(Flags.INSTABREAK).or(false)) {
event.getBlock().breakNaturally(); event.getBlock().breakNaturally();
} }
} }
@ -103,7 +103,7 @@ public class PlotPlusListener extends PlotListener implements Listener {
if (plot == null) { if (plot == null) {
return; return;
} }
if (FlagManager.isBooleanFlag(plot, "invincible", false)) { if (plot.getFlag(Flags.INVINCIBLE).or(false)) {
event.setCancelled(true); event.setCancelled(true);
} }
} }
@ -117,7 +117,7 @@ public class PlotPlusListener extends PlotListener implements Listener {
return; return;
} }
UUID uuid = pp.getUUID(); UUID uuid = pp.getUUID();
if (plot.isAdded(uuid) && FlagManager.isBooleanFlag(plot, "drop-protection", false)) { if (plot.isAdded(uuid) && plot.getFlag(Flags.DROP_PROTECTION).or(false)) {
event.setCancelled(true); event.setCancelled(true);
} }
} }
@ -131,7 +131,7 @@ public class PlotPlusListener extends PlotListener implements Listener {
return; return;
} }
UUID uuid = pp.getUUID(); UUID uuid = pp.getUUID();
if (plot.isAdded(uuid) && FlagManager.isBooleanFlag(plot, "item-drop", false)) { if (plot.isAdded(uuid) && plot.getFlag(Flags.ITEM_DROP).or(false)) {
event.setCancelled(true); event.setCancelled(true);
} }
} }
@ -140,14 +140,14 @@ public class PlotPlusListener extends PlotListener implements Listener {
public void onPlotEnter(PlayerEnterPlotEvent event) { public void onPlotEnter(PlayerEnterPlotEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
Plot plot = event.getPlot(); Plot plot = event.getPlot();
Flag feed = FlagManager.getPlotFlagRaw(plot, "feed"); Optional<Integer[]> feed = plot.getFlag(Flags.FEED);
if (feed != null) { if (feed.isPresent()) {
Integer[] value = (Integer[]) feed.getValue(); Integer[] value = feed.get();
feedRunnable.put(player.getName(), new Interval(value[0], value[1], 20)); feedRunnable.put(player.getName(), new Interval(value[0], value[1], 20));
} }
Flag heal = FlagManager.getPlotFlagRaw(plot, "heal"); Optional<Integer[]> heal = plot.getFlag(Flags.HEAL);
if (heal != null) { if (heal.isPresent()) {
Integer[] value = (Integer[]) heal.getValue(); Integer[] value = heal.get();
healRunnable.put(player.getName(), new Interval(value[0], value[1], 20)); healRunnable.put(player.getName(), new Interval(value[0], value[1], 20));
} }
} }

View File

@ -5,7 +5,6 @@ import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
public class DefaultTitleManager extends TitleManager { public class DefaultTitleManager extends TitleManager {
@ -23,18 +22,6 @@ public class DefaultTitleManager extends TitleManager {
super(title, subtitle, fadeInTime, stayTime, fadeOutTime); super(title, subtitle, fadeInTime, stayTime, fadeOutTime);
} }
private static boolean equalsTypeArray(Class<?>[] a, Class<?>[] o) {
if (a.length != o.length) {
return false;
}
for (int i = 0; i < a.length; i++) {
if (!a[i].equals(o[i]) && !a[i].isAssignableFrom(o[i])) {
return false;
}
}
return true;
}
/** /**
* Load spigot and NMS classes. * Load spigot and NMS classes.
*/ */
@ -90,7 +77,8 @@ public class DefaultTitleManager extends TitleManager {
* @param player Player * @param player Player
* @throws Exception * @throws Exception
*/ */
@Override public void clearTitle(Player player) throws Exception { @Override
public void clearTitle(Player player) throws Exception {
// Send timings first // Send timings first
Object handle = getHandle(player); Object handle = getHandle(player);
Object connection = getField(handle.getClass(), "playerConnection").get(handle); Object connection = getField(handle.getClass(), "playerConnection").get(handle);
@ -106,7 +94,8 @@ public class DefaultTitleManager extends TitleManager {
* @param player Player * @param player Player
* @throws Exception * @throws Exception
*/ */
@Override public void resetTitle(Player player) throws Exception { @Override
public void resetTitle(Player player) throws Exception {
// Send timings first // Send timings first
Object handle = getHandle(player); Object handle = getHandle(player);
Object connection = getField(handle.getClass(), "playerConnection").get(handle); Object connection = getField(handle.getClass(), "playerConnection").get(handle);
@ -116,27 +105,7 @@ public class DefaultTitleManager extends TitleManager {
sendPacket.invoke(connection, packet); sendPacket.invoke(connection, packet);
} }
private Object getHandle(Object obj) { Field getField(Class<?> clazz, String name) {
try {
return getMethod("getHandle", obj.getClass()).invoke(obj);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
e.printStackTrace();
return null;
}
}
private Method getMethod(String name, Class<?> clazz, Class<?>... paramTypes) {
Class<?>[] t = toPrimitiveTypeArray(paramTypes);
for (Method m : clazz.getMethods()) {
Class<?>[] types = toPrimitiveTypeArray(m.getParameterTypes());
if (m.getName().equals(name) && equalsTypeArray(types, t)) {
return m;
}
}
return null;
}
private Field getField(Class<?> clazz, String name) {
try { try {
Field field = clazz.getDeclaredField(name); Field field = clazz.getDeclaredField(name);
field.setAccessible(true); field.setAccessible(true);
@ -157,7 +126,7 @@ public class DefaultTitleManager extends TitleManager {
return null; return null;
} }
private boolean ClassListEqual(Class<?>[] l1, Class<?>[] l2) { boolean ClassListEqual(Class<?>[] l1, Class<?>[] l2) {
if (l1.length != l2.length) { if (l1.length != l2.length) {
return false; return false;
} }

View File

@ -4,10 +4,9 @@ import com.plotsquared.bukkit.chat.Reflection;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
public class DefaultTitleManager_183 extends TitleManager { public class DefaultTitleManager_183 extends DefaultTitleManager {
/** /**
* Create a new 1.8 title. * Create a new 1.8 title.
@ -22,18 +21,6 @@ public class DefaultTitleManager_183 extends TitleManager {
super(title, subtitle, fadeInTime, stayTime, fadeOutTime); super(title, subtitle, fadeInTime, stayTime, fadeOutTime);
} }
private static boolean equalsTypeArray(Class<?>[] a, Class<?>[] o) {
if (a.length != o.length) {
return false;
}
for (int i = 0; i < a.length; i++) {
if (!a[i].equals(o[i]) && !a[i].isAssignableFrom(o[i])) {
return false;
}
}
return true;
}
/** /**
* Load spigot and NMS classes. * Load spigot and NMS classes.
*/ */
@ -82,71 +69,6 @@ public class DefaultTitleManager_183 extends TitleManager {
} }
} }
/**
* Clear the title.
*
* @param player Player
* @throws Exception
*/
@Override
public void clearTitle(Player player) throws Exception {
// Send timings first
Object handle = getHandle(player);
Object connection = getField(handle.getClass(), "playerConnection").get(handle);
Object[] actions = this.packetActions.getEnumConstants();
Method sendPacket = getMethod(connection.getClass(), "sendPacket");
Object packet = this.packetTitle.getConstructor(this.packetActions, this.chatBaseComponent).newInstance(actions[3], null);
sendPacket.invoke(connection, packet);
}
/**
* Reset the title settings.
*
* @param player Player
* @throws Exception
*/
@Override
public void resetTitle(Player player) throws Exception {
// Send timings first
Object handle = getHandle(player);
Object connection = getField(handle.getClass(), "playerConnection").get(handle);
Object[] actions = this.packetActions.getEnumConstants();
Method sendPacket = getMethod(connection.getClass(), "sendPacket");
Object packet = this.packetTitle.getConstructor(this.packetActions, this.chatBaseComponent).newInstance(actions[4], null);
sendPacket.invoke(connection, packet);
}
private Object getHandle(Object obj) {
try {
return getMethod("getHandle", obj.getClass()).invoke(obj);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
private Method getMethod(String name, Class<?> clazz, Class<?>... paramTypes) {
Class<?>[] t = toPrimitiveTypeArray(paramTypes);
for (Method m : clazz.getMethods()) {
Class<?>[] types = toPrimitiveTypeArray(m.getParameterTypes());
if (m.getName().equals(name) && equalsTypeArray(types, t)) {
return m;
}
}
return null;
}
private Field getField(Class<?> clazz, String name) {
try {
Field field = clazz.getDeclaredField(name);
field.setAccessible(true);
return field;
} catch (NoSuchFieldException | SecurityException e) {
e.printStackTrace();
return null;
}
}
private Method getMethod(Class<?> clazz, String name, Class<?>... args) { private Method getMethod(Class<?> clazz, String name, Class<?>... args) {
for (Method m : clazz.getMethods()) { for (Method m : clazz.getMethods()) {
if (m.getName().equals(name) && ((args.length == 0) || ClassListEqual(args, m.getParameterTypes()))) { if (m.getName().equals(name) && ((args.length == 0) || ClassListEqual(args, m.getParameterTypes()))) {
@ -157,17 +79,4 @@ public class DefaultTitleManager_183 extends TitleManager {
return null; return null;
} }
private boolean ClassListEqual(Class<?>[] l1, Class<?>[] l2) {
if (l1.length != l2.length) {
return false;
}
boolean equal = true;
for (int i = 0; i < l1.length; i++) {
if (l1[i] != l2[i]) {
equal = false;
break;
}
}
return equal;
}
} }

View File

@ -6,7 +6,6 @@ import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
public class HackTitleManager extends TitleManager { public class HackTitleManager extends TitleManager {
@ -24,18 +23,6 @@ public class HackTitleManager extends TitleManager {
super(title, subtitle, fadeInTime, stayTime, fadeOutTime); super(title, subtitle, fadeInTime, stayTime, fadeOutTime);
} }
private static boolean equalsTypeArray(Class<?>[] a, Class<?>[] o) {
if (a.length != o.length) {
return false;
}
for (int i = 0; i < a.length; i++) {
if (!a[i].equals(o[i]) && !a[i].isAssignableFrom(o[i])) {
return false;
}
}
return true;
}
/** /**
* Load spigot and NMS classes. * Load spigot and NMS classes.
*/ */
@ -171,26 +158,6 @@ public class HackTitleManager extends TitleManager {
return f.get(obj); return f.get(obj);
} }
private Object getHandle(Object obj) {
try {
return getMethod("getHandle", obj.getClass()).invoke(obj);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
e.printStackTrace();
return null;
}
}
private Method getMethod(String name, Class<?> clazz, Class<?>... paramTypes) {
Class<?>[] t = toPrimitiveTypeArray(paramTypes);
for (Method m : clazz.getMethods()) {
Class<?>[] types = toPrimitiveTypeArray(m.getParameterTypes());
if (m.getName().equals(name) && equalsTypeArray(types, t)) {
return m;
}
}
return null;
}
private Field getField(Class<?> clazz, String name) { private Field getField(Class<?> clazz, String name) {
try { try {
Field field = clazz.getDeclaredField(name); Field field = clazz.getDeclaredField(name);
@ -225,4 +192,5 @@ public class HackTitleManager extends TitleManager {
} }
return equal; return equal;
} }
} }

View File

@ -4,6 +4,8 @@ import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -201,4 +203,36 @@ public abstract class TitleManager {
return types; return types;
} }
final Object getHandle(Object obj) {
try {
return getMethod("getHandle", obj.getClass()).invoke(obj);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
e.printStackTrace();
return null;
}
}
final Method getMethod(String name, Class<?> clazz, Class<?>... paramTypes) {
Class<?>[] t = toPrimitiveTypeArray(paramTypes);
for (Method m : clazz.getMethods()) {
Class<?>[] types = toPrimitiveTypeArray(m.getParameterTypes());
if (m.getName().equals(name) && equalsTypeArray(types, t)) {
return m;
}
}
return null;
}
final boolean equalsTypeArray(Class<?>[] a, Class<?>[] o) {
if (a.length != o.length) {
return false;
}
for (int i = 0; i < a.length; i++) {
if (!a[i].equals(o[i]) && !a[i].isAssignableFrom(o[i])) {
return false;
}
}
return true;
}
} }

View File

@ -20,41 +20,41 @@ public class BukkitChatManager extends ChatManager<FancyMessage> {
} }
@Override @Override
public void color(PlotMessage m, String color) { public void color(PlotMessage message, String color) {
m.$(this).color(ChatColor.getByChar(C.color(color).substring(1))); message.$(this).color(ChatColor.getByChar(C.color(color).substring(1)));
} }
@Override @Override
public void tooltip(PlotMessage m, PlotMessage... tooltips) { public void tooltip(PlotMessage message, PlotMessage... tooltips) {
List<FancyMessage> lines = new ArrayList<>(); List<FancyMessage> lines = new ArrayList<>();
for (PlotMessage tooltip : tooltips) { for (PlotMessage tooltip : tooltips) {
lines.add(tooltip.$(this)); lines.add(tooltip.$(this));
} }
m.$(this).formattedTooltip(lines); message.$(this).formattedTooltip(lines);
} }
@Override @Override
public void command(PlotMessage m, String command) { public void command(PlotMessage message, String command) {
m.$(this).command(command); message.$(this).command(command);
} }
@Override @Override
public void text(PlotMessage m, String text) { public void text(PlotMessage message, String text) {
m.$(this).then(ChatColor.stripColor(text)); message.$(this).then(ChatColor.stripColor(text));
} }
@Override @Override
public void send(PlotMessage m, PlotPlayer player) { public void send(PlotMessage plotMessage, PlotPlayer player) {
if (player instanceof ConsolePlayer) { if (player instanceof ConsolePlayer) {
player.sendMessage(m.$(this).toOldMessageFormat()); player.sendMessage(plotMessage.$(this).toOldMessageFormat());
} else { } else {
m.$(this).send(((BukkitPlayer) player).player); plotMessage.$(this).send(((BukkitPlayer) player).player);
} }
} }
@Override @Override
public void suggest(PlotMessage m, String command) { public void suggest(PlotMessage plotMessage, String command) {
m.$(this).suggest(command); plotMessage.$(this).suggest(command);
} }
} }

View File

@ -73,7 +73,7 @@ public class BukkitEventUtil extends EventUtil {
} }
@Override @Override
public boolean callFlagRemove(Flag flag, Plot plot) { public boolean callFlagRemove(Flag<?> flag, Plot plot, Object value) {
return callEvent(new PlotFlagRemoveEvent(flag, plot)); return callEvent(new PlotFlagRemoveEvent(flag, plot));
} }
@ -113,7 +113,7 @@ public class BukkitEventUtil extends EventUtil {
} }
@Override @Override
public boolean callFlagRemove(Flag flag, PlotCluster cluster) { public boolean callFlagRemove(Flag flag, Object object, PlotCluster cluster) {
return callEvent(new ClusterFlagRemoveEvent(flag, cluster)); return callEvent(new ClusterFlagRemoveEvent(flag, cluster));
} }

View File

@ -16,35 +16,35 @@ public class BukkitPlainChatManager extends ChatManager<List<StringBuilder>> {
} }
@Override @Override
public void color(PlotMessage m, String color) { public void color(PlotMessage message, String color) {
List<StringBuilder> parts = m.$(this); List<StringBuilder> parts = message.$(this);
parts.get(parts.size() - 1).insert(0, color); parts.get(parts.size() - 1).insert(0, color);
} }
@Override @Override
public void tooltip(PlotMessage m, PlotMessage... tooltips) { public void tooltip(PlotMessage message, PlotMessage... tooltips) {
} }
@Override @Override
public void command(PlotMessage m, String command) { public void command(PlotMessage message, String command) {
} }
@Override @Override
public void text(PlotMessage m, String text) { public void text(PlotMessage message, String text) {
m.$(this).add(new StringBuilder(ChatColor.stripColor(text))); message.$(this).add(new StringBuilder(ChatColor.stripColor(text)));
} }
@Override @Override
public void send(PlotMessage m, PlotPlayer player) { public void send(PlotMessage plotMessage, PlotPlayer player) {
StringBuilder built = new StringBuilder(); StringBuilder built = new StringBuilder();
for (StringBuilder sb : m.$(this)) { for (StringBuilder sb : plotMessage.$(this)) {
built.append(sb); built.append(sb);
} }
player.sendMessage(built.toString()); player.sendMessage(built.toString());
} }
@Override @Override
public void suggest(PlotMessage m, String command) { public void suggest(PlotMessage plotMessage, String command) {
} }
} }

View File

@ -7,5 +7,5 @@ dependencies {
sourceCompatibility = 1.7 sourceCompatibility = 1.7
targetCompatibility = 1.7 targetCompatibility = 1.7
jar.archiveName="PlotSquared-API-${parent.version}.jar" jar.archiveName = "PlotSquared-Core-${parent.version}.jar"
jar.destinationDir = file '../target' jar.destinationDir = file '../target'

View File

@ -1830,8 +1830,8 @@ public class PS {
for (String flag : intFlags) { for (String flag : intFlags) {
FlagManager.addFlag(new AbstractFlag(flag, new FlagValue.UnsignedIntegerValue())); FlagManager.addFlag(new AbstractFlag(flag, new FlagValue.UnsignedIntegerValue()));
} }
FlagManager.addFlag(new AbstractFlag("done", new FlagValue.StringValue()), true); FlagManager.addFlag(new AbstractFlag("done", new FlagValue.StringValue()));
FlagManager.addFlag(new AbstractFlag("analysis", new FlagValue.IntegerListValue()), true); FlagManager.addFlag(new AbstractFlag("analysis", new FlagValue.IntegerListValue()));
FlagManager.addFlag(new AbstractFlag("disable-physics", new FlagValue.BooleanValue())); FlagManager.addFlag(new AbstractFlag("disable-physics", new FlagValue.BooleanValue()));
FlagManager.addFlag(new AbstractFlag("fly", new FlagValue.BooleanValue())); FlagManager.addFlag(new AbstractFlag("fly", new FlagValue.BooleanValue()));
FlagManager.addFlag(new AbstractFlag("explosion", new FlagValue.BooleanValue())); FlagManager.addFlag(new AbstractFlag("explosion", new FlagValue.BooleanValue()));
@ -1858,6 +1858,10 @@ public class PS {
FlagManager.addFlag(new AbstractFlag("use", new FlagValue.PlotBlockListValue())); FlagManager.addFlag(new AbstractFlag("use", new FlagValue.PlotBlockListValue()));
FlagManager.addFlag(new AbstractFlag("blocked-cmds", new FlagValue.StringListValue())); FlagManager.addFlag(new AbstractFlag("blocked-cmds", new FlagValue.StringListValue()));
FlagManager.addFlag(new AbstractFlag("ice-melt", new FlagValue.BooleanValue())); FlagManager.addFlag(new AbstractFlag("ice-melt", new FlagValue.BooleanValue()));
FlagManager.addFlag(new AbstractFlag("soil-dry", new FlagValue.BooleanValue()));
FlagManager.addFlag(new AbstractFlag("grass-grow", new FlagValue.BooleanValue()));
FlagManager.addFlag(new AbstractFlag("mycel-grow", new FlagValue.BooleanValue()));
FlagManager.addFlag(new AbstractFlag("vine-grow", new FlagValue.BooleanValue()));
FlagManager.addFlag(new AbstractFlag("block-ignition", new FlagValue.BooleanValue())); FlagManager.addFlag(new AbstractFlag("block-ignition", new FlagValue.BooleanValue()));
FlagManager.addFlag(new AbstractFlag("block-burn", new FlagValue.BooleanValue())); FlagManager.addFlag(new AbstractFlag("block-burn", new FlagValue.BooleanValue()));
FlagManager.addFlag(new AbstractFlag("fire-spread", new FlagValue.BooleanValue())); FlagManager.addFlag(new AbstractFlag("fire-spread", new FlagValue.BooleanValue()));
@ -1878,10 +1882,6 @@ public class PS {
} }
} }
@Override
public String getValueDesc() {
return "Flag value must a timestamp or a boolean";
}
}); });
FlagManager.addFlag(new AbstractFlag("gamemode") { FlagManager.addFlag(new AbstractFlag("gamemode") {
@ -1908,10 +1908,6 @@ public class PS {
} }
} }
@Override
public String getValueDesc() {
return "Flag value must be a gamemode: 'creative' , 'survival', 'adventure' or 'spectator'";
}
}); });
FlagManager.addFlag(new AbstractFlag("price", new FlagValue.UnsignedDoubleValue())); FlagManager.addFlag(new AbstractFlag("price", new FlagValue.UnsignedDoubleValue()));
FlagManager.addFlag(new AbstractFlag("time", new FlagValue.LongValue())); FlagManager.addFlag(new AbstractFlag("time", new FlagValue.LongValue()));
@ -1935,12 +1931,8 @@ public class PS {
} }
} }
@Override
public String getValueDesc() {
return "Flag value must be weather type: 'clear' or 'rain'";
}
}); });
FlagManager.addFlag(new AbstractFlag("description", new FlagValue.StringValue()), true); FlagManager.addFlag(new AbstractFlag("description", new FlagValue.StringValue()));
} }
/** /**

View File

@ -1,9 +1,9 @@
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import com.google.common.base.Optional;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.Flags;
import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
@ -11,6 +11,7 @@ import com.intellectualcrafters.plot.util.EconHandler;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.CommandDeclaration; import com.plotsquared.general.commands.CommandDeclaration;
import java.util.Set; import java.util.Set;
@CommandDeclaration( @CommandDeclaration(
@ -59,14 +60,14 @@ public class Buy extends SubCommand {
if (currentPlots > plr.getAllowedPlots()) { if (currentPlots > plr.getAllowedPlots()) {
return sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS); return sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS);
} }
Flag flag = FlagManager.getPlotFlagRaw(plot, "price"); Optional<Double> flag = plot.getFlag(Flags.PRICE);
if (flag == null) { if (!flag.isPresent()) {
return sendMessage(plr, C.NOT_FOR_SALE); return sendMessage(plr, C.NOT_FOR_SALE);
} }
if (plot.isOwner(plr.getUUID())) { if (plot.isOwner(plr.getUUID())) {
return sendMessage(plr, C.CANNOT_BUY_OWN); return sendMessage(plr, C.CANNOT_BUY_OWN);
} }
double price = (double) flag.getValue(); double price = flag.get();
if ((EconHandler.manager != null) && (price > 0d)) { if ((EconHandler.manager != null) && (price > 0d)) {
if (EconHandler.manager.getMoney(plr) < price) { if (EconHandler.manager.getMoney(plr) < price) {
return sendMessage(plr, C.CANNOT_AFFORD_PLOT, "" + price); return sendMessage(plr, C.CANNOT_AFFORD_PLOT, "" + price);
@ -78,7 +79,7 @@ public class Buy extends SubCommand {
if (owner != null) { if (owner != null) {
sendMessage(plr, C.PLOT_SOLD, plot.getId() + "", plr.getName(), price + ""); sendMessage(plr, C.PLOT_SOLD, plot.getId() + "", plr.getName(), price + "");
} }
FlagManager.removePlotFlag(plot, "price"); plot.removeFlag(Flags.PRICE);
} }
plot.setOwner(plr.getUUID()); plot.setOwner(plr.getUUID());
MainUtil.sendMessage(plr, C.CLAIMED); MainUtil.sendMessage(plr, C.CLAIMED);

View File

@ -3,6 +3,7 @@ package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.flag.Flags;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
@ -62,7 +63,7 @@ public class Clear extends SubCommand {
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER); MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
return false; return false;
} }
if ((FlagManager.getPlotFlagRaw(plot, "done") != null) if (plot.getFlag(Flags.DONE).isPresent()
&& (!Permissions.hasPermission(plr, "plots.continue") || (Settings.DONE_COUNTS_TOWARDS_LIMIT && (plr.getAllowedPlots() >= plr && (!Permissions.hasPermission(plr, "plots.continue") || (Settings.DONE_COUNTS_TOWARDS_LIMIT && (plr.getAllowedPlots() >= plr
.getPlotCount())))) { .getPlotCount())))) {
MainUtil.sendMessage(plr, C.DONE_ALREADY_DONE); MainUtil.sendMessage(plr, C.DONE_ALREADY_DONE);
@ -81,11 +82,11 @@ public class Clear extends SubCommand {
public void run() { public void run() {
plot.removeRunning(); plot.removeRunning();
// If the state changes, then mark it as no longer done // If the state changes, then mark it as no longer done
if (FlagManager.getPlotFlagRaw(plot, "done") != null) { if (plot.getFlag(Flags.DONE).isPresent()) {
FlagManager.removePlotFlag(plot, "done"); FlagManager.removePlotFlag(plot, Flags.DONE);
} }
if (FlagManager.getPlotFlagRaw(plot, "analysis") != null) { if (plot.getFlag(Flags.ANALYSIS).isPresent()) {
FlagManager.removePlotFlag(plot, "analysis"); FlagManager.removePlotFlag(plot, Flags.ANALYSIS);
} }
MainUtil.sendMessage(plr, C.CLEARING_DONE, "" + (System.currentTimeMillis() - start)); MainUtil.sendMessage(plr, C.CLEARING_DONE, "" + (System.currentTimeMillis() - start));
} }

View File

@ -2,7 +2,7 @@ package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.flag.Flags;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
@ -40,7 +40,7 @@ public class Continue extends SubCommand {
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER); MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
return false; return false;
} }
FlagManager.removePlotFlag(plot, "done"); plot.removeFlag(Flags.DONE);
MainUtil.sendMessage(plr, C.DONE_REMOVED); MainUtil.sendMessage(plr, C.DONE_REMOVED);
return true; return true;
} }

View File

@ -5,6 +5,7 @@ import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.generator.HybridUtils; import com.intellectualcrafters.plot.generator.HybridUtils;
import com.intellectualcrafters.plot.object.ConsolePlayer; import com.intellectualcrafters.plot.object.ConsolePlayer;
@ -211,8 +212,9 @@ public class DebugExec extends SubCommand {
} }
String flag = args[1]; String flag = args[1];
for (Plot plot : PS.get().getBasePlots()) { for (Plot plot : PS.get().getBasePlots()) {
if (FlagManager.getPlotFlagRaw(plot, flag) != null) { Flag<?> flag1 = FlagManager.getFlag(flag);
FlagManager.removePlotFlag(plot, flag); if (plot.getFlag(flag1).isPresent()) {
FlagManager.removePlotFlag(plot, flag1);
} }
} }
return MainUtil.sendMessage(player, "Cleared flag: " + flag); return MainUtil.sendMessage(player, "Cleared flag: " + flag);

View File

@ -4,7 +4,6 @@ import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotArea; import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
@ -39,17 +38,19 @@ public class DebugFixFlags extends SubCommand {
} }
MainUtil.sendMessage(plr, "&8--- &6Starting task &8 ---"); MainUtil.sendMessage(plr, "&8--- &6Starting task &8 ---");
for (Plot plot : area.getPlots()) { for (Plot plot : area.getPlots()) {
HashMap<String, Flag> flags = plot.getFlags(); HashMap<Flag<?>, Object> flags = plot.getFlags();
Iterator<Entry<String, Flag>> i = flags.entrySet().iterator(); Iterator<Entry<Flag<?>, Object>> i = flags.entrySet().iterator();
boolean changed = false; boolean changed = false;
while (i.hasNext()) { while (i.hasNext()) {
/*
if (FlagManager.getFlag(i.next().getKey()) == null) { if (FlagManager.getFlag(i.next().getKey()) == null) {
changed = true; changed = true;
i.remove(); i.remove();
} }
*/
} }
if (changed) { if (changed) {
DBFunc.setFlags(plot, plot.getFlags().values()); DBFunc.setFlags(plot, plot.getFlags());
} }
} }
MainUtil.sendMessage(plr, "&aDone!"); MainUtil.sendMessage(plr, "&aDone!");

View File

@ -1,8 +1,8 @@
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.flag.Flags;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
@ -21,12 +21,11 @@ public class Desc extends SetCommand {
@Override @Override
public boolean set(PlotPlayer plr, Plot plot, String desc) { public boolean set(PlotPlayer plr, Plot plot, String desc) {
if (desc.isEmpty()) { if (desc.isEmpty()) {
plot.removeFlag("description"); plot.removeFlag(Flags.DESCRIPTION);
MainUtil.sendMessage(plr, C.DESC_UNSET); MainUtil.sendMessage(plr, C.DESC_UNSET);
return true; return true;
} }
Flag flag = new Flag(FlagManager.getFlag("description"), desc); boolean result = FlagManager.addPlotFlag(plot, Flags.DESCRIPTION, desc);
boolean result = FlagManager.addPlotFlag(plot, flag);
if (!result) { if (!result) {
MainUtil.sendMessage(plr, C.FLAG_NOT_ADDED); MainUtil.sendMessage(plr, C.FLAG_NOT_ADDED);
return false; return false;

View File

@ -4,6 +4,7 @@ import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.flag.Flags;
import com.intellectualcrafters.plot.generator.HybridUtils; import com.intellectualcrafters.plot.generator.HybridUtils;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
@ -48,8 +49,9 @@ public class Done extends SubCommand {
public void run(PlotAnalysis value) { public void run(PlotAnalysis value) {
plot.removeRunning(); plot.removeRunning();
if ((value == null) || (value.getComplexity() >= Settings.CLEAR_THRESHOLD)) { if ((value == null) || (value.getComplexity() >= Settings.CLEAR_THRESHOLD)) {
Flag flag = new Flag(FlagManager.getFlag("done"), System.currentTimeMillis() / 1000); long flagValue = System.currentTimeMillis() / 1000;
FlagManager.addPlotFlag(plot, flag); Flag flag = Flags.DONE;
FlagManager.addPlotFlag(plot, flag, flagValue);
MainUtil.sendMessage(plr, C.DONE_SUCCESS); MainUtil.sendMessage(plr, C.DONE_SUCCESS);
} else { } else {
MainUtil.sendMessage(plr, C.DONE_INSUFFICIENT_COMPLEXITY); MainUtil.sendMessage(plr, C.DONE_INSUFFICIENT_COMPLEXITY);

View File

@ -4,7 +4,7 @@ import com.intellectualcrafters.jnbt.CompoundTag;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.flag.Flags;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.object.RunnableVal;
@ -41,11 +41,8 @@ public class Download extends SubCommand {
MainUtil.sendMessage(plr, C.PLOT_UNOWNED); MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
return false; return false;
} }
if ((Settings.DOWNLOAD_REQUIRES_DONE && (FlagManager.getPlotFlagRaw(plot, "done") == null)) && !Permissions.hasPermission(plr, "plots.admin.command.download")) { if ((!plot.isOwner(plr.getUUID()) || (Settings.DOWNLOAD_REQUIRES_DONE && plot.getFlag(Flags.DONE).isPresent())) && !Permissions
MainUtil.sendMessage(plr, C.DONE_NOT_DONE); .hasPermission(plr, "plots.admin.command.download")) {
return false;
}
if ((!plot.isOwner(plr.getUUID()))) {
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS); MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
return false; return false;
} }

View File

@ -1,11 +1,12 @@
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import com.google.common.base.Optional;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.flag.AbstractFlag;
import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.flag.FlagValue; import com.intellectualcrafters.plot.flag.Flags;
import com.intellectualcrafters.plot.flag.ListFlag;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
@ -16,6 +17,7 @@ import com.plotsquared.general.commands.CommandDeclaration;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -31,7 +33,7 @@ public class FlagCmd extends SubCommand {
@Override @Override
public String getUsage() { public String getUsage() {
return super.getUsage().replaceAll("<flag>", StringMan.join(FlagManager.getFlags(), "|")); return super.getUsage().replaceAll("<flag>", StringMan.join(Flags.getFlags(), "|"));
} }
@Override @Override
@ -62,7 +64,7 @@ public class FlagCmd extends SubCommand {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag.other"); MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag.other");
return false; return false;
} }
if (args.length > 1 && FlagManager.isReserved(args[1])) { if (args.length > 1 && FlagManager.isReserved(FlagManager.getFlag(args[1]))) {
MainUtil.sendMessage(player, C.NOT_VALID_FLAG); MainUtil.sendMessage(player, C.NOT_VALID_FLAG);
return false; return false;
} }
@ -76,18 +78,18 @@ public class FlagCmd extends SubCommand {
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag info <flag>"); MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag info <flag>");
return false; return false;
} }
AbstractFlag flag = FlagManager.getFlag(args[1]); Flag<?> flag = FlagManager.getFlag(args[1]);
if (flag == null) { if (flag == null) {
MainUtil.sendMessage(player, C.NOT_VALID_FLAG); MainUtil.sendMessage(player, C.NOT_VALID_FLAG);
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag info <flag>"); MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag info <flag>");
return false; return false;
} }
// flag key // flag key
MainUtil.sendMessage(player, C.FLAG_KEY, flag.getKey()); MainUtil.sendMessage(player, C.FLAG_KEY, flag.getName());
// flag type // flag type
MainUtil.sendMessage(player, C.FLAG_TYPE, flag.value.getClass().getSimpleName()); MainUtil.sendMessage(player, C.FLAG_TYPE, flag.getClass().getSimpleName());
// Flag type description // Flag type description
MainUtil.sendMessage(player, C.FLAG_DESC, flag.getValueDesc()); MainUtil.sendMessage(player, C.FLAG_DESC, flag.getValueDescription());
return true; return true;
} }
case "set": { case "set": {
@ -99,7 +101,7 @@ public class FlagCmd extends SubCommand {
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag set <flag> <value>"); MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag set <flag> <value>");
return false; return false;
} }
AbstractFlag af = FlagManager.getFlag(args[1].toLowerCase()); Flag<?> af = FlagManager.getFlag(args[1].toLowerCase());
if (af == null) { if (af == null) {
MainUtil.sendMessage(player, C.NOT_VALID_FLAG); MainUtil.sendMessage(player, C.NOT_VALID_FLAG);
return false; return false;
@ -109,13 +111,12 @@ public class FlagCmd extends SubCommand {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag." + args[1].toLowerCase() + "." + value.toLowerCase()); MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag." + args[1].toLowerCase() + "." + value.toLowerCase());
return false; return false;
} }
Object parsed = af.parseValueRaw(value); Object parsed = af.parseValue(value);
if (parsed == null) { if (parsed == null) {
MainUtil.sendMessage(player, "&c" + af.getValueDesc()); MainUtil.sendMessage(player, "&c" + af.getValueDescription());
return false; return false;
} }
Flag flag = new Flag(FlagManager.getFlag(args[1].toLowerCase(), true), parsed); boolean result = plot.setFlag(af, parsed);
boolean result = FlagManager.addPlotFlag(plot, flag);
if (!result) { if (!result) {
MainUtil.sendMessage(player, C.FLAG_NOT_ADDED); MainUtil.sendMessage(player, C.FLAG_NOT_ADDED);
return false; return false;
@ -124,42 +125,42 @@ public class FlagCmd extends SubCommand {
return true; return true;
} }
case "remove": { case "remove": {
if (!Permissions.hasPermission(player, "plots.flag.remove")) { if (!Permissions.hasPermission(player, "plots.flagValue.remove")) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.flag.remove"); MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.flagValue.remove");
return false; return false;
} }
if (args.length != 2 && args.length != 3) { if (args.length != 2 && args.length != 3) {
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag remove <flag> [values]"); MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flagValue remove <flagValue> [values]");
return false; return false;
} }
AbstractFlag af = FlagManager.getFlag(args[1].toLowerCase()); Flag<?> flag1 = FlagManager.getFlag(args[1].toLowerCase());
if (af == null) { if (flag1 == null) {
MainUtil.sendMessage(player, C.NOT_VALID_FLAG); MainUtil.sendMessage(player, C.NOT_VALID_FLAG);
return false; return false;
} }
Flag flag = FlagManager.getPlotFlagAbs(plot, args[1].toLowerCase()); Optional<?> flagValue = plot.getFlag(flag1);
if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase())) { if (!Permissions.hasPermission(player, "plots.set.flagValue." + args[1].toLowerCase())) {
if (args.length != 2) { if (args.length != 2) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag." + args[1].toLowerCase()); MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flagValue." + args[1].toLowerCase());
return false; return false;
} }
for (String entry : args[2].split(",")) { for (String entry : args[2].split(",")) {
if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase() + "." + entry)) { if (!Permissions.hasPermission(player, "plots.set.flagValue." + args[1].toLowerCase() + "." + entry)) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag." + args[1].toLowerCase() + "." + entry); MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flagValue." + args[1].toLowerCase() + "." + entry);
return false; return false;
} }
} }
} }
if (flag == null) { if (flagValue.isPresent()) {
MainUtil.sendMessage(player, C.FLAG_NOT_IN_PLOT); MainUtil.sendMessage(player, C.FLAG_NOT_IN_PLOT);
return false; return false;
} }
if (args.length == 3 && flag.getAbstractFlag().isList()) { if (args.length == 3 && flag1 instanceof ListFlag) {
String value = StringMan.join(Arrays.copyOfRange(args, 2, args.length), " "); String value = StringMan.join(Arrays.copyOfRange(args, 2, args.length), " ");
((FlagValue.ListValue) flag.getAbstractFlag().value).remove(flag.getValue(), value); boolean listFlag = ((Collection) plot.getFlags().get(flag1)).remove(flag1.parseValue(value));
DBFunc.setFlags(plot, plot.getFlags().values()); DBFunc.setFlags(plot, plot.getFlags());
} else { } else {
boolean result = FlagManager.removePlotFlag(plot, flag.getKey()); boolean result = plot.removeFlag(flag1);
if (!result) { if (!result) {
MainUtil.sendMessage(player, C.FLAG_NOT_REMOVED); MainUtil.sendMessage(player, C.FLAG_NOT_REMOVED);
return false; return false;
@ -177,7 +178,7 @@ public class FlagCmd extends SubCommand {
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag add <flag> <values>"); MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag add <flag> <values>");
return false; return false;
} }
AbstractFlag af = FlagManager.getFlag(args[1].toLowerCase()); Flag af = FlagManager.getFlag(args[1].toLowerCase());
if (af == null) { if (af == null) {
MainUtil.sendMessage(player, C.NOT_VALID_FLAG); MainUtil.sendMessage(player, C.NOT_VALID_FLAG);
return false; return false;
@ -189,18 +190,18 @@ public class FlagCmd extends SubCommand {
} }
} }
String value = StringMan.join(Arrays.copyOfRange(args, 2, args.length), " "); String value = StringMan.join(Arrays.copyOfRange(args, 2, args.length), " ");
Object parsed = af.parseValueRaw(value); Object parsed = af.parseValue(value);
if (parsed == null) { if (parsed == null) {
MainUtil.sendMessage(player, "&c" + af.getValueDesc()); MainUtil.sendMessage(player, "&c" + af.getValueDescription());
return false; return false;
} }
Flag flag = FlagManager.getPlotFlag(plot, args[1].toLowerCase()); Optional<?> flag = plot.getFlag(af);
if (flag == null || !flag.getAbstractFlag().isList()) { if (flag.isPresent()) {
flag = new Flag(FlagManager.getFlag(args[1].toLowerCase(), true), parsed); if (af instanceof ListFlag) {
} else { ((Collection) flag.get()).addAll((Collection) parsed);
((FlagValue.ListValue) flag.getAbstractFlag().value).add(flag.getValue(), value);
} }
boolean result = FlagManager.addPlotFlag(plot, flag); }
boolean result = FlagManager.addPlotFlag(plot, af, parsed);
if (!result) { if (!result) {
MainUtil.sendMessage(player, C.FLAG_NOT_ADDED); MainUtil.sendMessage(player, C.FLAG_NOT_ADDED);
return false; return false;
@ -217,12 +218,12 @@ public class FlagCmd extends SubCommand {
return false; return false;
} }
HashMap<String, ArrayList<String>> flags = new HashMap<>(); HashMap<String, ArrayList<String>> flags = new HashMap<>();
for (AbstractFlag flag1 : FlagManager.getFlags()) { for (Flag flag1 : Flags.getFlags()) {
String type = flag1.value.getClass().getSimpleName().replaceAll("Value", ""); String type = flag1.getClass().getSimpleName().replaceAll("Value", "");
if (!flags.containsKey(type)) { if (!flags.containsKey(type)) {
flags.put(type, new ArrayList<String>()); flags.put(type, new ArrayList<String>());
} }
flags.get(type).add(flag1.getKey()); //todo flags.get(type).add(flag1.getKey());
} }
String message = ""; String message = "";
String prefix = ""; String prefix = "";

View File

@ -1,10 +1,10 @@
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import com.google.common.base.Optional;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.PS.SortType; import com.intellectualcrafters.plot.PS.SortType;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.Flags;
import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotArea; import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotMessage; import com.intellectualcrafters.plot.object.PlotMessage;
@ -176,8 +176,8 @@ public class ListCmd extends SubCommand {
} }
plots = new ArrayList<>(); plots = new ArrayList<>();
for (Plot plot : PS.get().getPlots()) { for (Plot plot : PS.get().getPlots()) {
Flag flag = plot.getFlags().get("done"); Optional<String> flag = plot.getFlag(Flags.DONE);
if (flag == null) { if (!flag.isPresent()) {
continue; continue;
} }
plots.add(plot); plots.add(plot);
@ -185,8 +185,8 @@ public class ListCmd extends SubCommand {
Collections.sort(plots, new Comparator<Plot>() { Collections.sort(plots, new Comparator<Plot>() {
@Override @Override
public int compare(Plot a, Plot b) { public int compare(Plot a, Plot b) {
String va = a.getFlags().get("done").getValueString(); String va = (String) a.getFlags().get(Flags.DONE);
String vb = b.getFlags().get("done").getValueString(); String vb = (String) b.getFlags().get(Flags.DONE);
if (MathMan.isInteger(va)) { if (MathMan.isInteger(va)) {
if (MathMan.isInteger(vb)) { if (MathMan.isInteger(vb)) {
return Integer.parseInt(vb) - Integer.parseInt(va); return Integer.parseInt(vb) - Integer.parseInt(va);
@ -245,10 +245,12 @@ public class ListCmd extends SubCommand {
} }
plots = new ArrayList<>(); plots = new ArrayList<>();
for (Plot plot : PS.get().getPlots()) { for (Plot plot : PS.get().getPlots()) {
/*
Flag price = FlagManager.getPlotFlagRaw(plot, "price"); Flag price = FlagManager.getPlotFlagRaw(plot, "price");
if (price != null) { if (price != null) {
plots.add(plot); plots.add(plot);
} }
*/
} }
break; break;
case "unowned": case "unowned":

View File

@ -1,8 +1,7 @@
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.Flags;
import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.object.PlotBlock;
@ -41,9 +40,9 @@ public class Music extends SubCommand {
} }
int id = item.id == 7 ? 0 : item.id; int id = item.id == 7 ? 0 : item.id;
if (id == 0) { if (id == 0) {
FlagManager.removePlotFlag(plot, "music"); plot.removeFlag(Flags.MUSIC);
} else { } else {
FlagManager.addPlotFlag(plot, new Flag(FlagManager.getFlag("music"), id)); plot.setFlag(Flags.MUSIC, id);
} }
return false; return false;
} }

View File

@ -3,7 +3,7 @@ package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Configuration; import com.intellectualcrafters.plot.config.Configuration;
import com.intellectualcrafters.plot.flag.AbstractFlag; import com.intellectualcrafters.plot.flag.AbstractFlag;
import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.flag.Flags;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotArea; import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.object.PlotBlock;
@ -166,7 +166,7 @@ public class Set extends SubCommand {
} catch (Exception e) { } catch (Exception e) {
af = new AbstractFlag(""); af = new AbstractFlag("");
} }
if (FlagManager.getFlags().contains(af)) { if (Flags.getFlags().contains(af)) {
StringBuilder a = new StringBuilder(); StringBuilder a = new StringBuilder();
if (args.length > 1) { if (args.length > 1) {
for (int x = 1; x < args.length; x++) { for (int x = 1; x < args.length; x++) {

View File

@ -9,7 +9,6 @@ import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.object.comment.PlotComment; import com.intellectualcrafters.plot.object.comment.PlotComment;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -142,7 +141,7 @@ public interface AbstractDB {
* @param plot Plot Object * @param plot Plot Object
* @param flags flags to set (flag[]) * @param flags flags to set (flag[])
*/ */
void setFlags(Plot plot, Collection<Flag> flags); void setFlags(Plot plot, HashMap<Flag<?>, Object> flags);
/** /**
* Set cluster flags. * Set cluster flags.
@ -150,7 +149,7 @@ public interface AbstractDB {
* @param cluster PlotCluster Object * @param cluster PlotCluster Object
* @param flags flags to set (flag[]) * @param flags flags to set (flag[])
*/ */
void setFlags(PlotCluster cluster, Collection<Flag> flags); void setFlags(PlotCluster cluster, HashMap<Flag<?>, Object> flags);
/** /**
* Rename a cluster. * Rename a cluster.

View File

@ -12,7 +12,6 @@ import java.sql.ResultSet;
import java.sql.ResultSetMetaData; import java.sql.ResultSetMetaData;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -244,14 +243,14 @@ public class DBFunc {
DBFunc.dbManager.setMerged(plot, merged); DBFunc.dbManager.setMerged(plot, merged);
} }
public static void setFlags(Plot plot, Collection<Flag> flags) { public static void setFlags(Plot plot, HashMap<Flag<?>, Object> flags) {
if (plot.temp == -1) { if (plot.temp == -1) {
return; return;
} }
DBFunc.dbManager.setFlags(plot, flags); DBFunc.dbManager.setFlags(plot, flags);
} }
public static void setFlags(PlotCluster cluster, Collection<Flag> flags) { public static void setFlags(PlotCluster cluster, HashMap<Flag<?>, Object> flags) {
DBFunc.dbManager.setFlags(cluster, flags); DBFunc.dbManager.setFlags(cluster, flags);
} }

View File

@ -25,7 +25,6 @@ import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
@ -790,31 +789,32 @@ public class SQLManager implements AbstractDB {
} }
@Override @Override
public void setMySQL(PreparedStatement stmt, int i, SettingsPair pair) throws SQLException { public void setMySQL(PreparedStatement statement, int i, SettingsPair pair) throws SQLException {
stmt.setInt(i * 10 + 1, pair.id); // id statement.setInt(i * 10 + 1, pair.id); // id
stmt.setNull(i * 10 + 2, 4); // biome statement.setNull(i * 10 + 2, 4); // biome
stmt.setNull(i * 10 + 3, 4); // rain statement.setNull(i * 10 + 3, 4); // rain
stmt.setNull(i * 10 + 4, 4); // custom_time statement.setNull(i * 10 + 4, 4); // custom_time
stmt.setNull(i * 10 + 5, 4); // time statement.setNull(i * 10 + 5, 4); // time
stmt.setNull(i * 10 + 6, 4); // deny_entry statement.setNull(i * 10 + 6, 4); // deny_entry
if (pair.settings.getAlias().isEmpty()) { if (pair.settings.getAlias().isEmpty()) {
stmt.setNull(i * 10 + 7, 4); statement.setNull(i * 10 + 7, 4);
} else { } else {
stmt.setString(i * 10 + 7, pair.settings.getAlias()); statement.setString(i * 10 + 7, pair.settings.getAlias());
} }
StringBuilder flag_string = new StringBuilder(); StringBuilder flag_string = new StringBuilder();
int k = 0; int k = 0;
for (Flag flag : pair.settings.flags.values()) { for (Entry<Flag<?>, ?> flag : pair.settings.flags.entrySet()) {
if (k != 0) { if (k != 0) {
flag_string.append(","); flag_string.append(",");
} }
flag_string.append(flag.getKey() + ":" + flag.getValueString().replaceAll(":", "\u00AF").replaceAll(",", "\u00B4")); flag_string.append(flag.getKey().getName() + ":" + flag.getKey().valueToString(flag.getValue()).replaceAll(":", "¯")
.replaceAll(",", "´"));
k++; k++;
} }
stmt.setString(i * 10 + 8, flag_string.toString()); statement.setString(i * 10 + 8, flag_string.toString());
boolean[] merged = pair.settings.getMerged(); boolean[] merged = pair.settings.getMerged();
int hash = MainUtil.hash(merged); int hash = MainUtil.hash(merged);
stmt.setInt(i * 10 + 9, hash); statement.setInt(i * 10 + 9, hash);
BlockLoc loc = pair.settings.getPosition(); BlockLoc loc = pair.settings.getPosition();
String position; String position;
if (loc.y == 0) { if (loc.y == 0) {
@ -822,7 +822,7 @@ public class SQLManager implements AbstractDB {
} else { } else {
position = loc.x + "," + loc.y + "," + loc.z; position = loc.x + "," + loc.y + "," + loc.z;
} }
stmt.setString(i * 10 + 10, position); statement.setString(i * 10 + 10, position);
} }
@Override @Override
@ -840,11 +840,12 @@ public class SQLManager implements AbstractDB {
} }
StringBuilder flag_string = new StringBuilder(); StringBuilder flag_string = new StringBuilder();
int k = 0; int k = 0;
for (Flag flag : pair.settings.flags.values()) { for (Entry<Flag<?>, ?> flag : pair.settings.flags.entrySet()) {
if (k != 0) { if (k != 0) {
flag_string.append(","); flag_string.append(",");
} }
flag_string.append(flag.getKey() + ":" + flag.getValueString().replaceAll(":", "\u00AF").replaceAll(",", "\u00B4")); flag_string.append(flag.getKey().getName() + ":" + flag.getKey().valueToString(flag.getValue()).replaceAll(":", "¯")
.replaceAll(",", "´"));
k++; k++;
} }
stmt.setString(i * 10 + 8, flag_string.toString()); stmt.setString(i * 10 + 8, flag_string.toString());
@ -1784,18 +1785,18 @@ public class SQLManager implements AbstractDB {
deleteRows(toDelete, this.prefix + "plot_denied", "plot_plot_id"); deleteRows(toDelete, this.prefix + "plot_denied", "plot_plot_id");
} }
try (ResultSet r = statement.executeQuery("SELECT * FROM `" + this.prefix + "plot_settings`")) { try (ResultSet resultSet = statement.executeQuery("SELECT * FROM `" + this.prefix + "plot_settings`")) {
ArrayList<Integer> toDelete = new ArrayList<>(); ArrayList<Integer> toDelete = new ArrayList<>();
while (r.next()) { while (resultSet.next()) {
id = r.getInt("plot_plot_id"); id = resultSet.getInt("plot_plot_id");
Plot plot = plots.get(id); Plot plot = plots.get(id);
if (plot != null) { if (plot != null) {
plots.remove(id); plots.remove(id);
String alias = r.getString("alias"); String alias = resultSet.getString("alias");
if (alias != null) { if (alias != null) {
plot.getSettings().setAlias(alias); plot.getSettings().setAlias(alias);
} }
String pos = r.getString("position"); String pos = resultSet.getString("position");
switch (pos.toLowerCase()) { switch (pos.toLowerCase()) {
case "": case "":
case "default": case "default":
@ -1808,14 +1809,14 @@ public class SQLManager implements AbstractDB {
} catch (Exception ignored) { } catch (Exception ignored) {
} }
} }
Integer m = r.getInt("merged"); Integer m = resultSet.getInt("merged");
boolean[] merged = new boolean[4]; boolean[] merged = new boolean[4];
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
merged[3 - i] = (m & 1 << i) != 0; merged[3 - i] = (m & 1 << i) != 0;
} }
plot.getSettings().setMerged(merged); plot.getSettings().setMerged(merged);
String[] flags_string; String[] flags_string;
String myflags = r.getString("flags"); String myflags = resultSet.getString("flags");
if (myflags == null) { if (myflags == null) {
flags_string = new String[] {}; flags_string = new String[] {};
} else { } else {
@ -1825,15 +1826,15 @@ public class SQLManager implements AbstractDB {
flags_string = new String[] {}; flags_string = new String[] {};
} }
} }
HashMap<String, Flag> flags = new HashMap<>(); HashMap<Flag<?>, Object> flags = new HashMap<>();
boolean exception = false; boolean exception = false;
for (String element : flags_string) { for (String element : flags_string) {
if (element.contains(":")) { if (element.contains(":")) {
String[] split = element.split(":"); String[] split = element.split(":");
try { try {
String flag_str = split[1].replaceAll("\u00AF", ":").replaceAll("\u00B4", ","); String flag_str = split[1].replaceAll("\u00AF", ":").replaceAll("\u00B4", ",");
Flag flag = new Flag(FlagManager.getFlag(split[0], true), flag_str); Flag<?> flag = FlagManager.getFlag(split[0]);
flags.put(flag.getKey(), flag); flags.put(flag, flag_str);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
exception = true; exception = true;
@ -1841,8 +1842,8 @@ public class SQLManager implements AbstractDB {
} else { } else {
element = element.replaceAll("\u00AF", ":").replaceAll("\u00B4", ","); element = element.replaceAll("\u00AF", ":").replaceAll("\u00B4", ",");
if (StringMan.isAlpha(element.replaceAll("_", "").replaceAll("-", ""))) { if (StringMan.isAlpha(element.replaceAll("_", "").replaceAll("-", ""))) {
Flag flag = new Flag(FlagManager.getFlag(element, true), ""); Flag flag = FlagManager.getFlag(element);
flags.put(flag.getKey(), flag); flags.put(flag, "");
} else { } else {
PS.debug("INVALID FLAG: " + element); PS.debug("INVALID FLAG: " + element);
} }
@ -1851,7 +1852,7 @@ public class SQLManager implements AbstractDB {
if (exception) { if (exception) {
PS.debug("&cPlot " + id + " | " + plot + " had an invalid flag. A fix has been attempted."); PS.debug("&cPlot " + id + " | " + plot + " had an invalid flag. A fix has been attempted.");
PS.debug("&c" + myflags); PS.debug("&c" + myflags);
this.setFlags(plot, flags.values()); this.setFlags(plot, flags);
} }
plot.getSettings().flags = flags; plot.getSettings().flags = flags;
} else if (Settings.AUTO_PURGE) { } else if (Settings.AUTO_PURGE) {
@ -1962,8 +1963,8 @@ public class SQLManager implements AbstractDB {
} }
@Override @Override
public void setFlags(final Plot plot, Collection<Flag> flags) { public void setFlags(final Plot plot, HashMap<Flag<?>, Object> flags) {
final String flag_string = FlagManager.toString(flags); final String flag_string = FlagManager.toString(flags); //todo MattBDev: Fix this for flags to work.
addPlotTask(plot, new UniqueStatement("setFlags") { addPlotTask(plot, new UniqueStatement("setFlags") {
@Override @Override
public void set(PreparedStatement stmt) throws SQLException { public void set(PreparedStatement stmt) throws SQLException {
@ -2641,22 +2642,22 @@ public class SQLManager implements AbstractDB {
flags_string = new String[] {}; flags_string = new String[] {};
} }
} }
HashMap<String, Flag> flags = new HashMap<>(); HashMap<Flag<?>, Object> flags = new HashMap<>();
boolean exception = false; boolean exception = false;
for (String element : flags_string) { for (String element : flags_string) {
if (element.contains(":")) { if (element.contains(":")) {
String[] split = element.split(":"); String[] split = element.split(":");
try { try {
String flag_str = 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); Flag flag = FlagManager.getFlag(split[0]);
flags.put(flag.getKey(), flag); flags.put(flag, flag_str);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
exception = true; exception = true;
} }
} else { } else {
Flag flag = new Flag(FlagManager.getFlag(element, true), ""); Flag flag = FlagManager.getFlag(element);
flags.put(flag.getKey(), flag); flags.put(flag, "");
} }
} }
if (exception) { if (exception) {
@ -2687,14 +2688,15 @@ public class SQLManager implements AbstractDB {
} }
@Override @Override
public void setFlags(final PlotCluster cluster, Collection<Flag> flags) { public void setFlags(final PlotCluster cluster, HashMap<Flag<?>, Object> flags) {
final StringBuilder flag_string = new StringBuilder(); final StringBuilder flag_string = new StringBuilder();
int i = 0; int i = 0;
for (Flag flag : flags) { for (Entry<Flag<?>, Object> flag : flags.entrySet()) {
if (i != 0) { if (i != 0) {
flag_string.append(","); flag_string.append(",");
} }
flag_string.append(flag.getKey() + ":" + flag.getValueString().replaceAll(":", "\u00AF").replaceAll(",", "\u00B4")); flag_string.append(flag.getKey().getName() + ":" + flag.getKey().valueToString(flag.getValue()).replaceAll(":", "¯").replaceAll(",",
"´"));
i++; i++;
} }
addClusterTask(cluster, new UniqueStatement("setFlags") { addClusterTask(cluster, new UniqueStatement("setFlags") {
@ -3019,12 +3021,12 @@ public class SQLManager implements AbstractDB {
PS.debug("&8 - &7Correcting merge for: " + plot); PS.debug("&8 - &7Correcting merge for: " + plot);
setMerged(dataPlot, plot.getMerged()); setMerged(dataPlot, plot.getMerged());
} }
HashMap<String, Flag> pf = plot.getFlags(); HashMap<Flag<?>, Object> pf = plot.getFlags();
HashMap<String, Flag> df = dataPlot.getFlags(); HashMap<Flag<?>, Object> df = dataPlot.getFlags();
if (!pf.isEmpty() && !df.isEmpty()) { if (!pf.isEmpty() && !df.isEmpty()) {
if (pf.size() != df.size() || !StringMan.isEqual(StringMan.joinOrdered(pf.values(), ","), StringMan.joinOrdered(df.values(), ","))) { if (pf.size() != df.size() || !StringMan.isEqual(StringMan.joinOrdered(pf.values(), ","), StringMan.joinOrdered(df.values(), ","))) {
PS.debug("&8 - &7Correcting flags for: " + plot); PS.debug("&8 - &7Correcting flags for: " + plot);
setFlags(plot, pf.values()); setFlags(plot, pf);
} }
} }
} }

View File

@ -1,16 +1,14 @@
package com.intellectualcrafters.plot.flag; package com.intellectualcrafters.plot.flag;
import com.intellectualcrafters.plot.util.StringMan;
/** /**
* Created 2014-09-23 for PlotSquared * Created 2014-09-23 for PlotSquared
* *
*/ */
public class AbstractFlag { public class AbstractFlag<T extends FlagValue> {
public final String key; public final String key;
public final FlagValue<?> value; public final T value = null;
public AbstractFlag(String key) { public AbstractFlag(String key) {
this(key, new FlagValue.StringValue()); this(key, new FlagValue.StringValue());
@ -22,18 +20,12 @@ public class AbstractFlag {
* @param key * @param key
*/ */
public AbstractFlag(String key, FlagValue<?> value) { public AbstractFlag(String key, FlagValue<?> value) {
if (!StringMan.isAlpha(key.replaceAll("_", "").replaceAll("-", ""))) {
throw new IllegalArgumentException("Flag must be alphabetic characters");
}
if (key.length() > 16) {
throw new IllegalArgumentException("Key must be <= 16 characters");
}
this.key = key.toLowerCase(); this.key = key.toLowerCase();
if (value == null) { //if (value == null) {
this.value = new FlagValue.StringValue(); // this.value = new FlagValue.StringValue();
} else { //} else {
this.value = value; // this.value = value;
} //}
} }
public boolean isList() { public boolean isList() {
@ -52,10 +44,6 @@ public class AbstractFlag {
return this.value.toString(t); return this.value.toString(t);
} }
public String getValueDesc() {
return this.value.getDescription();
}
/** /**
* AbstractFlag key * AbstractFlag key
* *

View File

@ -5,4 +5,33 @@ public class BooleanFlag extends Flag<Boolean> {
public BooleanFlag(String name) { public BooleanFlag(String name) {
super(name); super(name);
} }
@Override public String valueToString(Object value) {
if (((boolean) value)) {
return "true";
} else {
return "false";
}
}
@Override public Boolean parseValue(String value) {
switch (value.toLowerCase()) {
case "1":
case "yes":
case "allow":
case "true":
return true;
case "0":
case "no":
case "deny":
case "false":
return false;
default:
return null;
}
}
@Override public String getValueDescription() {
return "Flag value must be a boolean (true|false)";
}
} }

View File

@ -1,14 +1,8 @@
package com.intellectualcrafters.plot.flag; package com.intellectualcrafters.plot.flag;
import com.intellectualcrafters.plot.util.StringMan; public class Flag<V> {
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class Flag<T> implements Cloneable {
private AbstractFlag key; private AbstractFlag key;
private Object value;
private String name; private String name;
/** /**
@ -16,35 +10,8 @@ public class Flag<T> implements Cloneable {
* key/value pair. For a flag to be usable by a player, you need to * key/value pair. For a flag to be usable by a player, you need to
* register it with PlotSquared. * register it with PlotSquared.
* *
* @param key AbstractFlag * @param name Flag name
* @param value Value must be alphanumerical (can have spaces) and be &lt;= 48 characters
*
* @throws IllegalArgumentException if you provide inadequate inputs
*/ */
public Flag(AbstractFlag key, String value) {
if (!StringMan.isAsciiPrintable(value)) {
throw new IllegalArgumentException("Flag must be ascii");
}
if (value.length() > 128) {
throw new IllegalArgumentException("Value must be <= 128 characters");
}
this.key = key;
this.value = key.parseValueRaw(value);
if (this.value == null) {
throw new IllegalArgumentException(key.getValueDesc() + " (" + value + ")");
}
}
/**
* Warning: Unchecked
* @param key
* @param value
*/
public Flag(AbstractFlag key, Object value) {
this.key = key;
this.value = value;
}
public Flag(String name) { public Flag(String name) {
this.name = name; this.name = name;
} }
@ -58,82 +25,25 @@ public class Flag<T> implements Cloneable {
return this.key; return this.key;
} }
/**
* Get the key for the AbstractFlag.
*
* @return String
*/
public String getKey() {
return this.key.getKey();
}
public void setKey(AbstractFlag key) {
this.key = key;
if (this.value instanceof String) {
this.value = key.parseValueRaw((String) this.value);
}
}
/**
* Get the value.
*
* @return String
*/
public Object getValue() {
return this.value;
}
public String getValueString() { public String getValueString() {
return this.key.toString(this.value); return this.key.toString(this.name);
}
public String valueToString(Object value) {
return null;
} }
@Override @Override
public String toString() { public String toString() {
if ("".equals(this.value)) { return "Flag { name='" + getName() + "'}";
return this.key.getKey();
}
return this.key + ":" + getValueString();
} }
@Override public V parseValue(String value) {
public boolean equals(Object obj) { return null;
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
Flag other = (Flag) obj;
return this.key.getKey().equals(other.key.getKey()) && this.value.equals(other.value);
} }
@Override public String getValueDescription() {
public int hashCode() { return null;
return this.key.getKey().hashCode();
}
@Override
protected Object clone() {
try {
if (this.value == null) {
return super.clone();
}
if (this.value instanceof Cloneable) {
Method method = this.value.getClass().getDeclaredMethod("clone");
if (!method.isAccessible()) {
method.setAccessible(true);
}
return new Flag(this.key, method.invoke(this.value));
}
return new Flag(this.key, this.key.parseValueRaw(this.key.toString(this.value)));
} catch (CloneNotSupportedException | IllegalAccessException | IllegalArgumentException | NoSuchMethodException | SecurityException |
InvocationTargetException e) {
e.printStackTrace();
}
return this;
} }
public String getName() { public String getName() {

View File

@ -1,19 +1,16 @@
package com.intellectualcrafters.plot.flag; package com.intellectualcrafters.plot.flag;
import com.intellectualcrafters.plot.PS; import com.google.common.collect.Sets;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotArea; import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotCluster; import com.intellectualcrafters.plot.object.PlotCluster;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotSettings; import com.intellectualcrafters.plot.object.PlotSettings;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.EventUtil;
import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.Permissions;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
@ -26,20 +23,16 @@ import java.util.Set;
*/ */
public class FlagManager { public class FlagManager {
//TODO Default Flags
public static final IntegerFlag MUSIC = new IntegerFlag("music");
private static final HashSet<? extends Flag<?>>
private static final HashSet<String> reserved = new HashSet<>(); reserved = Sets.newHashSet();//todo MattBDev: Ask Empire what a reserved flag is
private static final HashSet<AbstractFlag> flags = new HashSet<>();
/** /**
* Reserve a flag so that it cannot be set by players * Reserve a flag so that it cannot be set by players
* @param flag * @param flag
*/ */
public static void reserveFlag(String flag) { public static void reserveFlag(String flag) {
reserved.add(flag); //reserved.add(flag);
} }
/** /**
@ -47,7 +40,7 @@ public class FlagManager {
* @param flag * @param flag
* @return * @return
*/ */
public static boolean isReserved(String flag) { public static boolean isReserved(Flag<?> flag) {
return reserved.contains(flag); return reserved.contains(flag);
} }
@ -55,8 +48,8 @@ public class FlagManager {
* Get the reserved flags * Get the reserved flags
* @return * @return
*/ */
public static HashSet<String> getReservedFlags() { public static HashSet<Flag<?>> getReservedFlags() {
return (HashSet<String>) reserved.clone(); return (HashSet<Flag<?>>) reserved.clone();
} }
/** /**
@ -75,87 +68,37 @@ public class FlagManager {
* @return boolean success * @return boolean success
*/ */
public static boolean addFlag(AbstractFlag af) { public static boolean addFlag(AbstractFlag af) {
return addFlag(af, false); //todo MattBDev: Remove this
return true;
//return addFlag(af, false);
} }
public static boolean addFlag(final AbstractFlag af, boolean reserved) { public static String toString(HashMap<Flag<?>, Object> flags) {
PS.debug(C.PREFIX + "&8 - Adding flag: &7" + af); //todo MattBDev: Fix this for flags to work.
PS.get().foreachPlotArea(new RunnableVal<PlotArea>() { //noinspection StringBufferReplaceableByString,MismatchedQueryAndUpdateOfStringBuilder
@Override
public void run(PlotArea value) {
Flag flag = value.DEFAULT_FLAGS.get(af.getKey());
if (flag != null) {
flag.setKey(af);
}
}
});
PS.get().foreachPlotRaw(new RunnableVal<Plot>() {
@Override
public void run(Plot value) {
Flag flag = value.getFlags().get(af.getKey());
if (flag != null) {
flag.setKey(af);
}
}
});
if (flags.remove(af)) {
PS.debug("(Replaced existing flag)");
}
flags.add(af);
if (reserved) {
reserveFlag(af.getKey());
}
return false;
}
public static String toString(Collection<Flag> flags) {
StringBuilder flag_string = new StringBuilder(); StringBuilder flag_string = new StringBuilder();
int i = 0; /* int i = 0;
for (Flag flag : flags) { Flag<?> flag;
for (Map.Entry<Flag<?>, Object> entry : flags.entrySet()) {
flag = entry.getKey();
if (i != 0) { if (i != 0) {
flag_string.append(","); flag_string.append(",");
} }
flag_string.append(flag.getKey() + ":" + flag.getValueString().replaceAll(":", "\u00AF").replaceAll(",", "\u00B4")); flag_string.append(flag.getName() + ":" + flag.valueToString(entry.getValue()).replaceAll(":", "¯").replaceAll(",", "´"));
i++; i++;
} }*/
return flag_string.toString(); return flag_string.toString();
} }
public static Flag getSettingFlag(PlotArea area, PlotSettings settings, String id) { public static <V> V getSettingFlag(PlotArea area, PlotSettings settings, Flag<V> id) {
Flag flag; Object value;
if (settings.flags.isEmpty() || (flag = settings.flags.get(id)) == null) { if (settings.flags.isEmpty() || ((value = settings.flags.get(id)) == null)) {
if (area == null) { if (area == null || area.DEFAULT_FLAGS.isEmpty()) {
return null; return null;
} }
if (area.DEFAULT_FLAGS.isEmpty()) { return (V) area.DEFAULT_FLAGS.get(id);
return null;
} }
return area.DEFAULT_FLAGS.get(id); return (V) value;
}
return flag;
}
public static boolean isBooleanFlag(Plot plot, String key, boolean defaultValue) {
Flag flag = FlagManager.getPlotFlagRaw(plot, key);
if (flag == null) {
return defaultValue;
}
Object value = flag.getValue();
if (value instanceof Boolean) {
return (boolean) value;
}
return defaultValue;
}
/**
* Get the value of a flag for a plot (respects flag defaults)
* @param plot
* @param flag
* @return Flag
*/
public static Flag getPlotFlag(Plot plot, String flag) {
Flag result = getPlotFlagRaw(plot, flag);
return result == null ? null : (Flag) result.clone();
} }
/** /**
@ -166,80 +109,36 @@ public class FlagManager {
* @param flag * @param flag
* @return * @return
*/ */
public static Flag getPlotFlagRaw(Plot plot, String flag) { public static <V> V getPlotFlagRaw(Plot plot, Flag<V> flag) {
if (plot.owner == null) { if (plot.owner == null) {
return null; return null;
} }
return getSettingFlag(plot.getArea(), plot.getSettings(), flag); return getSettingFlag(plot.getArea(), plot.getSettings(), flag);
} }
public static boolean isPlotFlagTrue(Plot plot, String strFlag) {
if (plot.owner == null) {
return false;
}
Flag flag = getPlotFlagRaw(plot, strFlag);
return !(flag == null || !((Boolean) flag.getValue()));
}
public static boolean isPlotFlagFalse(Plot plot, String strFlag) {
if (plot.owner == null) {
return false;
}
Flag flag = getPlotFlagRaw(plot, strFlag);
if (flag == null || (Boolean) flag.getValue()) {
return false;
}
return false;
}
/**
* Get the value of a flag for a plot (ignores flag defaults)
* @param plot
* @param flag
* @return Flag
*/
public static Flag getPlotFlagAbs(Plot plot, String flag) {
return getSettingFlagAbs(plot.getSettings(), flag);
}
public static Flag getSettingFlagAbs(PlotSettings settings, String flag) {
if (settings.flags.isEmpty()) {
return null;
}
return settings.flags.get(flag);
}
/** /**
* Add a flag to a plot * Add a flag to a plot
* @param origin * @param origin
* @param flag * @param flag
* @param value
*/ */
public static boolean addPlotFlag(Plot origin, Flag flag) { public static <V> boolean addPlotFlag(Plot origin, Flag<V> flag, V value) {
boolean result = EventUtil.manager.callFlagAdd(flag, origin); boolean result = EventUtil.manager.callFlagAdd(flag, origin);
if (!result) { if (!result) {
return false; return false;
} }
for (Plot plot : origin.getConnectedPlots()) { for (Plot plot : origin.getConnectedPlots()) {
plot.getFlags().put(flag.getKey(), flag); plot.getFlags().put(flag, value);
plot.reEnter(); plot.reEnter();
DBFunc.setFlags(plot, plot.getFlags().values()); DBFunc.setFlags(plot, plot.getFlags());
} }
return true; return true;
} }
public static boolean addPlotFlagAbs(Plot plot, Flag flag) { public static <V> boolean addClusterFlag(PlotCluster cluster, Flag<V> flag, V value) {
boolean result = EventUtil.manager.callFlagAdd(flag, plot); getSettingFlag(cluster.area, cluster.settings, flag);
if (!result) { cluster.settings.flags.put(flag, value);
return false; DBFunc.setFlags(cluster, cluster.settings.flags);
}
plot.getFlags().put(flag.getKey(), flag);
return true;
}
public static boolean addClusterFlag(PlotCluster cluster, Flag flag) {
getSettingFlag(cluster.area, cluster.settings, flag.getKey());
cluster.settings.flags.put(flag.getKey(), flag);
DBFunc.setFlags(cluster, cluster.settings.flags.values());
return true; return true;
} }
@ -248,21 +147,21 @@ public class FlagManager {
* @param plot * @param plot
* @return set of flags * @return set of flags
*/ */
public static HashMap<String, Flag> getPlotFlags(Plot plot) { public static HashMap<Flag<?>, Object> getPlotFlags(Plot plot) {
if (!plot.hasOwner()) { if (!plot.hasOwner()) {
return null; return null;
} }
return getSettingFlags(plot.getArea(), plot.getSettings()); return getSettingFlags(plot.getArea(), plot.getSettings());
} }
public static HashMap<String, Flag> getPlotFlags(PlotArea area, PlotSettings settings, boolean ignorePluginflags) { public static HashMap<Flag<?>, Object> getPlotFlags(PlotArea area, PlotSettings settings, boolean ignorePluginflags) {
HashMap<String, Flag> flags = new HashMap<>(); HashMap<Flag<?>, Object> flags = new HashMap<>();
if (area != null && !area.DEFAULT_FLAGS.isEmpty()) { if (area != null && !area.DEFAULT_FLAGS.isEmpty()) {
flags.putAll(area.DEFAULT_FLAGS); flags.putAll(area.DEFAULT_FLAGS);
} }
if (ignorePluginflags) { if (ignorePluginflags) {
for (Map.Entry<String, Flag> flag : settings.flags.entrySet()) { for (Map.Entry<Flag<?>, Object> flag : settings.flags.entrySet()) {
if (isReserved(flag.getValue().getAbstractFlag().getKey())) { if (isReserved(flag.getKey())) {
continue; continue;
} }
flags.put(flag.getKey(), flag.getValue()); flags.put(flag.getKey(), flag.getValue());
@ -274,45 +173,45 @@ public class FlagManager {
return flags; return flags;
} }
public static HashMap<String, Flag> getSettingFlags(PlotArea area, PlotSettings settings) { public static HashMap<Flag<?>, Object> getSettingFlags(PlotArea area, PlotSettings settings) {
return getPlotFlags(area, settings, false); return getPlotFlags(area, settings, false);
} }
public static boolean removePlotFlag(Plot plot, String id) { public static boolean removePlotFlag(Plot plot, Flag<?> id) {
Flag flag = plot.getFlags().remove(id); Object value = plot.getFlags().remove(id);
if (flag == null) { if (value == null) {
return false; return false;
} }
boolean result = EventUtil.manager.callFlagRemove(flag, plot); boolean result = EventUtil.manager.callFlagRemove(id, plot, value);
if (!result) { if (!result) {
plot.getFlags().put(id, flag); plot.getFlags().put(id, value);
return false; return false;
} }
plot.reEnter(); plot.reEnter();
DBFunc.setFlags(plot, plot.getFlags().values()); DBFunc.setFlags(plot, plot.getFlags());
return true; return true;
} }
public static boolean removeClusterFlag(PlotCluster cluster, String id) { public static boolean removeClusterFlag(PlotCluster cluster, Flag id) {
Flag flag = cluster.settings.flags.remove(id); Object object = cluster.settings.flags.remove(id);
if (flag == null) { if (object == null) {
return false; return false;
} }
boolean result = EventUtil.manager.callFlagRemove(flag, cluster); boolean result = EventUtil.manager.callFlagRemove(id, object, cluster);
if (!result) { if (!result) {
cluster.settings.flags.put(id, flag); cluster.settings.flags.put(id, object);
return false; return false;
} }
DBFunc.setFlags(cluster, cluster.settings.flags.values()); DBFunc.setFlags(cluster, cluster.settings.flags);
return true; return true;
} }
public static void setPlotFlags(Plot origin, Set<Flag> flags) { public static void setPlotFlags(Plot origin, HashMap<Flag<?>, Object> flags) {
for (Plot plot : origin.getConnectedPlots()) { for (Plot plot : origin.getConnectedPlots()) {
if (flags != null && !flags.isEmpty()) { if (flags != null && !flags.isEmpty()) {
plot.getFlags().clear(); plot.getFlags().clear();
for (Flag flag : flags) { for (Map.Entry<Flag<?>, Object> flag : flags.entrySet()) {
plot.getFlags().put(flag.getKey(), flag); plot.getFlags().put(flag.getKey(), flag.getValue());
} }
} else if (plot.getFlags().isEmpty()) { } else if (plot.getFlags().isEmpty()) {
return; return;
@ -320,7 +219,7 @@ public class FlagManager {
plot.getFlags().clear(); plot.getFlags().clear();
} }
plot.reEnter(); plot.reEnter();
DBFunc.setFlags(plot, plot.getFlags().values()); DBFunc.setFlags(plot, plot.getFlags());
} }
} }
@ -328,57 +227,27 @@ public class FlagManager {
if (flags != null && !flags.isEmpty()) { if (flags != null && !flags.isEmpty()) {
cluster.settings.flags.clear(); cluster.settings.flags.clear();
for (Flag flag : flags) { for (Flag flag : flags) {
cluster.settings.flags.put(flag.getKey(), flag); cluster.settings.flags.put(flag, flag);
} }
} else if (cluster.settings.flags.isEmpty()) { } else if (cluster.settings.flags.isEmpty()) {
return; return;
} else { } else {
cluster.settings.flags.clear(); cluster.settings.flags.clear();
} }
DBFunc.setFlags(cluster, cluster.settings.flags.values()); DBFunc.setFlags(cluster, cluster.settings.flags);
}
public static Flag[] removeFlag(Flag[] flags, String r) {
Flag[] f = new Flag[flags.length - 1];
int index = 0;
for (Flag flag : flags) {
if (!flag.getKey().equals(r)) {
f[index++] = flag;
}
}
return f;
}
public static Set<Flag> removeFlag(Set<Flag> flags, String r) {
HashSet<Flag> newflags = new HashSet<>();
for (Flag flag : flags) {
if (!flag.getKey().equalsIgnoreCase(r)) {
newflags.add(flag);
}
}
return newflags;
} }
/** /**
* Get a list of registered AbstractFlag objects * Get a list of registered {@link Flag} objects based on player permissions
*
* @return List (AbstractFlag)
*/
public static HashSet<AbstractFlag> getFlags() {
return flags;
}
/**
* Get a list of registered AbstractFlag objects based on player permissions
* *
* @param player with permissions * @param player with permissions
* *
* @return List (AbstractFlag) * @return List (AbstractFlag)
*/ */
public static List<AbstractFlag> getFlags(PlotPlayer player) { public static List<Flag> getFlags(PlotPlayer player) {
List<AbstractFlag> returnFlags = new ArrayList<>(); List<Flag> returnFlags = new ArrayList<>();
for (AbstractFlag flag : flags) { for (Flag flag : Flags.flags) {
if (Permissions.hasPermission(player, "plots.set.flag." + flag.getKey().toLowerCase())) { if (Permissions.hasPermission(player, "plots.set.flag." + flag.getName().toLowerCase())) {
returnFlags.add(flag); returnFlags.add(flag);
} }
} }
@ -392,9 +261,9 @@ public class FlagManager {
* *
* @return AbstractFlag * @return AbstractFlag
*/ */
public static AbstractFlag getFlag(String string) { public static Flag<?> getFlag(String string) {
for (AbstractFlag flag : flags) { for (Flag flag : Flags.flags) {
if (flag.getKey().equalsIgnoreCase(string)) { if (flag.getName().equalsIgnoreCase(string)) {
return flag; return flag;
} }
} }
@ -409,26 +278,23 @@ public class FlagManager {
* *
* @return AbstractFlag * @return AbstractFlag
*/ */
public static AbstractFlag getFlag(String string, boolean create) { public static Flag getFlag(String string, boolean create) {
for (Flag flag : Flags.getFlags()) {
if (flag.getName().equalsIgnoreCase(string)) {
return flag;
}
}
if (getFlag(string) == null && create) { if (getFlag(string) == null && create) {
return new AbstractFlag(string); //return new AbstractFlag(string);
} }
return getFlag(string); return getFlag(string);
} }
/** public static HashMap<Flag<?>, Object> parseFlags(List<String> flagstrings) {
* Remove a registered AbstractFlag HashMap<Flag<?>, Object> map = new HashMap<>();
* //todo MattBDev: Fix this
* @param flag Flag Key /*
*
* @return boolean Result of operation
*/
public static boolean removeFlag(AbstractFlag flag) {
return flags.remove(flag);
}
public static HashMap<String, Flag> parseFlags(List<String> flagstrings) {
HashMap<String, Flag> map = new HashMap<>();
for (String key : flagstrings) { for (String key : flagstrings) {
String[] split; String[] split;
if (key.contains(";")) { if (key.contains(";")) {
@ -438,12 +304,13 @@ public class FlagManager {
} }
Flag flag; Flag flag;
if (split.length == 1) { if (split.length == 1) {
flag = new Flag(getFlag(split[0], true), ""); flag = new Flag(getFlag(split[0]), "");
} else { } else {
flag = new Flag(getFlag(split[0], true), split[1]); flag = new Flag(getFlag(split[0], true), split[1]);
} }
map.put(flag.getKey(), flag); map.put(flag.getKey(), flag);
} }
*/
return map; return map;
} }
} }

View File

@ -12,25 +12,10 @@ import java.util.List;
public abstract class FlagValue<T> { public abstract class FlagValue<T> {
private final Class<T> clazz;
@SuppressWarnings("unchecked")
public FlagValue() { public FlagValue() {
this.clazz = (Class<T>) getClass();
} }
public FlagValue(Class<T> clazz) { public String toString(T t) {
if (clazz == null) {
throw new NullPointerException();
}
this.clazz = clazz;
}
public boolean validValue(Object value) {
return value != null && value.getClass() == this.clazz;
}
public String toString(Object t) {
return t.toString(); return t.toString();
} }
@ -40,7 +25,7 @@ public abstract class FlagValue<T> {
public abstract String getDescription(); public abstract String getDescription();
public interface ListValue extends Cloneable { interface ListValue extends Cloneable {
void add(Object t, String value); void add(Object t, String value);
@ -103,9 +88,8 @@ public abstract class FlagValue<T> {
public static class IntervalValue extends FlagValue<Integer[]> { public static class IntervalValue extends FlagValue<Integer[]> {
@Override @Override
public String toString(Object t) { public String toString(Integer[] t) {
Integer[] value = (Integer[]) t; return t[0] + " " + t[1];
return value[0] + " " + value[1];
} }
@Override @Override
@ -306,8 +290,8 @@ public abstract class FlagValue<T> {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public String toString(Object t) { public String toString(HashSet<PlotBlock> t) {
return StringMan.join((HashSet<PlotBlock>) t, ","); return StringMan.join(t, ",");
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@ -318,7 +302,7 @@ public abstract class FlagValue<T> {
@Override @Override
public HashSet<PlotBlock> parse(String t) { public HashSet<PlotBlock> parse(String t) {
HashSet<PlotBlock> list = new HashSet<PlotBlock>(); HashSet<PlotBlock> list = new HashSet<>();
for (String item : t.split(",")) { for (String item : t.split(",")) {
PlotBlock block; PlotBlock block;
try { try {
@ -377,8 +361,8 @@ public abstract class FlagValue<T> {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public String toString(Object t) { public String toString(List<Integer> t) {
return StringMan.join((List<Integer>) t, ","); return StringMan.join(t, ",");
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@ -390,7 +374,7 @@ public abstract class FlagValue<T> {
@Override @Override
public List<Integer> parse(String t) { public List<Integer> parse(String t) {
String[] split = t.split(","); String[] split = t.split(",");
ArrayList<Integer> numbers = new ArrayList<Integer>(); ArrayList<Integer> numbers = new ArrayList<>();
for (String element : split) { for (String element : split) {
numbers.add(Integer.parseInt(element)); numbers.add(Integer.parseInt(element));
} }
@ -423,12 +407,11 @@ public abstract class FlagValue<T> {
} }
} }
@SuppressWarnings("ALL")
public static class StringListValue extends FlagValue<List<String>> implements ListValue { public static class StringListValue extends FlagValue<List<String>> implements ListValue {
@Override @Override
public String toString(final Object t) { public String toString(final List<String> t) {
return StringMan.join((List<String>) t, ","); return StringMan.join(t, ",");
} }
@Override @Override
@ -467,54 +450,6 @@ public abstract class FlagValue<T> {
} }
} }
public static class DoubleListValue extends FlagValue<List<Double>> implements ListValue {
@SuppressWarnings("unchecked")
@Override
public String toString(Object t) {
return StringMan.join((List<Double>) t, ",");
}
@SuppressWarnings("unchecked")
@Override
public List<Double> getValue(Object t) {
return (List<Double>) t;
}
@Override
public List<Double> parse(String t) {
String[] split = t.split(",");
ArrayList<Double> numbers = new ArrayList<Double>();
for (String element : split) {
numbers.add(Double.parseDouble(element));
}
return numbers;
}
@Override
public String getDescription() {
return "Flag value must be a integer list";
}
@Override
public void add(Object t, String value) {
try {
((List<Double>) t).addAll(parse(value));
} catch (Exception e) {
}
}
@Override
public void remove(Object t, String value) {
try {
for (Double item : parse(value)) {
((List<Double>) t).remove(item);
}
} catch (Exception e) {
}
}
}
public static class StringValue extends FlagValue<String> { public static class StringValue extends FlagValue<String> {
@Override @Override

View File

@ -0,0 +1,84 @@
package com.intellectualcrafters.plot.flag;
import com.google.common.collect.Sets;
import java.util.HashSet;
public class Flags {
public static final NumericFlag<Integer> MUSIC = new NumericFlag<>("music");
public static final StringFlag DESCRIPTION = new StringFlag("description");
public static final IntegerListFlag ANALYSIS = new IntegerListFlag("analysis");
public static final StringFlag GREETING = new StringFlag("greeting");
public static final StringFlag FAREWELL = new StringFlag("farewell");
public static final IntervalFlag FEED = new IntervalFlag("feed");
public static final IntervalFlag HEAL = new IntervalFlag("heal");
public static final GameModeFlag GAMEMODE = new GameModeFlag("gamemode");
public static final StringFlag DONE = new StringFlag("done");
public static final BooleanFlag REDSTONE = new BooleanFlag("redstone");
public static final BooleanFlag FLY = new BooleanFlag("fly");
public static final BooleanFlag NOTIFY_LEAVE = new BooleanFlag("notify-leave");
public static final BooleanFlag TITLES = new BooleanFlag("titles");
public static final BooleanFlag NOTIFY_ENTER = new BooleanFlag("notify-enter");
public static final NumericFlag<Long> TIME = new NumericFlag<>("time");
public static final PlotWeatherFlag WEATHER = new PlotWeatherFlag("weather");
public static final Flag<Object> KEEP = new Flag<>("keep");
public static final NumericFlag<Double> PRICE = new NumericFlag<>("price");
public static final BooleanFlag EXPLOSION = new BooleanFlag("explosion");
public static final BooleanFlag GRASS_GROW = new BooleanFlag("grass-grow");
public static final BooleanFlag VINE_GROW = new BooleanFlag("vine-grow");
public static final BooleanFlag MYCEL_GROW = new BooleanFlag("mycel-grow");
public static final BooleanFlag DISABLE_PHYSICS = new BooleanFlag("disable-physics");
public static final BooleanFlag SNOW_MELT = new BooleanFlag("snow-melt");
public static final BooleanFlag ICE_MELT = new BooleanFlag("ice-melt");
public static final BooleanFlag FIRE_SPREAD = new BooleanFlag("fire-spread");
public static final BooleanFlag BLOCK_BURN = new BooleanFlag("block-burn");
public static final BooleanFlag BLOCK_IGNITION = new BooleanFlag("block-ignition");
public static final BooleanFlag SOIL_DRY = new BooleanFlag("soil-dry");
public static final StringListFlag BLOCKED_CMDS = new StringListFlag("blocked-cmds");
public static final PlotBlockListFlag USE = new PlotBlockListFlag("use");
public static final PlotBlockListFlag BREAK = new PlotBlockListFlag("break");
public static final PlotBlockListFlag PLACE = new PlotBlockListFlag("place");
public static final BooleanFlag DEVICE_INTERACT = new BooleanFlag("device-interact");
public static final BooleanFlag VEHICLE_BREAK = new BooleanFlag("vehicle-break");
public static final BooleanFlag VEHICLE_PLACE = new BooleanFlag("vehicle-place");
public static final BooleanFlag VEHICLE_USE = new BooleanFlag("vehicle-use");
public static final BooleanFlag HANGING_BREAK = new BooleanFlag("hanging-break");
public static final BooleanFlag HANGING_PLACE = new BooleanFlag("hanging-place");
public static final BooleanFlag HANGING_INTERACT = new BooleanFlag("hanging-interact");
public static final BooleanFlag MISC_PLACE = new BooleanFlag("misc-place");
public static final BooleanFlag MISC_BREAK = new BooleanFlag("misc-break");
public static final BooleanFlag MISC_INTERACT = new BooleanFlag("misc-interact");
public static final BooleanFlag PLAYER_INTERACT = new BooleanFlag("player-interact");
public static final BooleanFlag TAMED_ATTACK = new BooleanFlag("tamed-attack");
public static final BooleanFlag TAMED_INTERACT = new BooleanFlag("tamed-interact");
public static final BooleanFlag ANIMAL_ATTACK = new BooleanFlag("animal-attack");
public static final BooleanFlag ANIMAL_INTERACT = new BooleanFlag("animal-interact");
public static final BooleanFlag HOSTILE_ATTACK = new BooleanFlag("hostile-attack");
public static final BooleanFlag HOSTILE_INTERACT = new BooleanFlag("hostile-interact");
public static final BooleanFlag MOB_PLACE = new BooleanFlag("mob-place");
public static final BooleanFlag FORCEFIELD = new BooleanFlag("forcefield");
public static final BooleanFlag INVINCIBLE = new BooleanFlag("invincible");
public static final BooleanFlag ITEM_DROP = new BooleanFlag("item-drop");
public static final BooleanFlag INSTABREAK = new BooleanFlag("instabreak");
public static final BooleanFlag DROP_PROTECTION = new BooleanFlag("drop-protection");
public static final BooleanFlag PVP = new BooleanFlag("pvp");
public static final BooleanFlag PVE = new BooleanFlag("pve");
public static final BooleanFlag NO_WORLDEDIT = new BooleanFlag("no-worldedit");
public static final NumericFlag<Integer> MISC_CAP = new NumericFlag<>("misc-cap");
public static final NumericFlag<Integer> ENTITY_CAP = new NumericFlag<>("entity-cap");
public static final NumericFlag<Integer> MOB_CAP = new NumericFlag<>("mob-cap");
public static final NumericFlag<Integer> ANIMAL_CAP = new NumericFlag<>("animal-cap");
public static final NumericFlag<Integer> HOSTILE_CAP = new NumericFlag<>("hostile-cap");
public static final NumericFlag<Integer> VEHICLE_CAP = new NumericFlag<>("vehicle-cap");
static final HashSet<? extends Flag<?>> flags = Sets.newHashSet(MUSIC, ANIMAL_CAP, HOSTILE_CAP, PVP, PVE, NO_WORLDEDIT);
/**
* Get a list of registered AbstractFlag objects
*
* @return List (AbstractFlag)
*/
public static HashSet<? extends Flag<?>> getFlags() {
return flags;
}
}

View File

@ -0,0 +1,41 @@
package com.intellectualcrafters.plot.flag;
import com.intellectualcrafters.plot.util.PlotGameMode;
public class GameModeFlag extends Flag<PlotGameMode> {
public GameModeFlag(String name) {
super(name);
}
@Override public String valueToString(Object value) {
return ((PlotGameMode) value).getName();
}
@Override
public PlotGameMode parseValue(String value) {
switch (value.toLowerCase()) {
case "survival":
case "s":
case "0":
return PlotGameMode.SURVIVAL;
case "creative":
case "c":
case "1":
return PlotGameMode.CREATIVE;
case "adventure":
case "a":
case "2":
return PlotGameMode.ADVENTURE;
case "spectator":
case "3":
return PlotGameMode.SPECTATOR;
default:
return PlotGameMode.NOT_SET;
}
}
@Override public String getValueDescription() {
return "Flag value must be a gamemode: 'creative' , 'survival', 'adventure' or 'spectator'";
}
}

View File

@ -1,8 +0,0 @@
package com.intellectualcrafters.plot.flag;
public class IntegerFlag extends Flag<Integer> {
public IntegerFlag(String name) {
super(name);
}
}

View File

@ -0,0 +1,23 @@
package com.intellectualcrafters.plot.flag;
import java.util.List;
public class IntegerListFlag extends ListFlag<List<Integer>> {
public IntegerListFlag(String name) {
super(name);
}
@Override public String valueToString(Object value) {
return null;
}
@Override public List<Integer> parseValue(String value) {
return null;
}
@Override public String getValueDescription() {
return null;
}
}

View File

@ -0,0 +1,41 @@
package com.intellectualcrafters.plot.flag;
public class IntervalFlag extends Flag<Integer[]> {
public IntervalFlag(String name) {
super(name);
}
@Override
public String valueToString(Object value) {
return null;
}
@Override public Integer[] parseValue(String value) {
int seconds;
int amount;
String[] values = value.split(" ");
if (values.length < 2) {
seconds = 1;
try {
amount = Integer.parseInt(values[0]);
} catch (NumberFormatException e) {
return null;
}
} else if (values.length == 2) {
try {
amount = Integer.parseInt(values[0]);
seconds = Integer.parseInt(values[1]);
} catch (NumberFormatException e) {
return null;
}
} else {
return null;
}
return new Integer[]{amount, seconds};
}
@Override public String getValueDescription() {
return "Value(s) must be numeric. /plot set flag <flag> <interval> [amount]";
}
}

View File

@ -0,0 +1,18 @@
package com.intellectualcrafters.plot.flag;
import java.util.Collection;
public abstract class ListFlag<V extends Collection> extends Flag<V> {
/**
* Flag object used to store basic information for a Plot. Flags are a
* key/value pair. For a flag to be usable by a player, you need to
* register it with PlotSquared.
*
* @param name Flag name
*/
public ListFlag(String name) {
super(name);
}
}

View File

@ -0,0 +1,16 @@
package com.intellectualcrafters.plot.flag;
public class NumericFlag<V extends Number> extends Flag<V> {
public NumericFlag(String name) {
super(name);
}
@Override public String getValueDescription() {
return super.getValueDescription();
}
@Override public String valueToString(Object value) {
return null;
}
}

View File

@ -0,0 +1,53 @@
package com.intellectualcrafters.plot.flag;
import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.util.StringComparison;
import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.WorldUtil;
import java.util.HashSet;
public class PlotBlockListFlag extends ListFlag<HashSet<PlotBlock>> {
public PlotBlockListFlag(String name) {
super(name);
}
@Override public String valueToString(Object value) {
return StringMan.join((HashSet<PlotBlock>) value, ",");
}
@Override public HashSet<PlotBlock> parseValue(String value) {
HashSet<PlotBlock> list = new HashSet<>();
for (String item : value.split(",")) {
PlotBlock block;
try {
String[] split = item.split(":");
byte data;
if (split.length == 2) {
if ("*".equals(split[1])) {
data = -1;
} else {
data = Byte.parseByte(split[1]);
}
} else {
data = -1;
}
short id = Short.parseShort(split[0]);
block = new PlotBlock(id, data);
} catch (NumberFormatException e) {
StringComparison<PlotBlock>.ComparisonResult str = WorldUtil.IMP.getClosestBlock(value);
if (str == null || str.match > 1) {
continue;
}
block = str.best;
}
list.add(block);
}
return list;
}
@Override public String getValueDescription() {
return null;
}
}

View File

@ -0,0 +1,22 @@
package com.intellectualcrafters.plot.flag;
import com.intellectualcrafters.plot.util.PlotWeather;
public class PlotWeatherFlag extends Flag<PlotWeather> {
public PlotWeatherFlag(String name) {
super(name);
}
@Override public String valueToString(Object value) {
return null;
}
@Override public PlotWeather parseValue(String value) {
return null;
}
@Override public String getValueDescription() {
return null;
}
}

View File

@ -0,0 +1,21 @@
package com.intellectualcrafters.plot.flag;
public class StringFlag extends Flag<String> {
public StringFlag(String name) {
super(name);
}
@Override public String valueToString(Object value) {
return ((String) value);
}
@Override public String parseValue(String value) {
return null;
}
@Override public String getValueDescription() {
return null;
}
}

View File

@ -0,0 +1,18 @@
package com.intellectualcrafters.plot.flag;
import java.util.List;
public class StringListFlag extends ListFlag<List<String>> {
/**
* Flag object used to store basic information for a Plot. Flags are a
* key/value pair. For a flag to be usable by a player, you need to
* register it with PlotSquared.
*
* @param name Flag name
*/
public StringListFlag(String name) {
super(name);
}
}

View File

@ -3,8 +3,8 @@ package com.intellectualcrafters.plot.generator;
import com.intellectualcrafters.jnbt.CompoundTag; import com.intellectualcrafters.jnbt.CompoundTag;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.flag.Flags;
import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
@ -89,8 +89,7 @@ public abstract class HybridUtils {
result.add(whenDone.value.data_sd); result.add(whenDone.value.data_sd);
result.add(whenDone.value.air_sd); result.add(whenDone.value.air_sd);
result.add(whenDone.value.variety_sd); result.add(whenDone.value.variety_sd);
Flag flag = new Flag(FlagManager.getFlag("analysis"), result); FlagManager.addPlotFlag(origin, Flags.ANALYSIS, result);
FlagManager.addPlotFlag(origin, flag);
TaskManager.runTask(whenDone); TaskManager.runTask(whenDone);
return; return;
} }

View File

@ -1,5 +1,6 @@
package com.intellectualcrafters.plot.object; package com.intellectualcrafters.plot.object;
import com.google.common.base.Optional;
import com.google.common.collect.BiMap; import com.google.common.collect.BiMap;
import com.intellectualcrafters.jnbt.CompoundTag; import com.intellectualcrafters.jnbt.CompoundTag;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
@ -194,7 +195,7 @@ public class Plot {
this.settings.setMerged(merged); this.settings.setMerged(merged);
if (flags != null) { if (flags != null) {
for (Flag flag : flags) { for (Flag flag : flags) {
this.settings.flags.put(flag.getKey(), flag); this.settings.flags.put(flag, flag);
} }
} }
this.timestamp = timestamp; this.timestamp = timestamp;
@ -941,24 +942,38 @@ public class Plot {
* @param flag * @param flag
* @param value * @param value
*/ */
public void setFlag(String flag, Object value) { public <V> boolean setFlag(Flag<V> flag, Object value) {
FlagManager.addPlotFlag(this, new Flag(FlagManager.getFlag(flag), value)); return FlagManager.addPlotFlag(this, flag, (V) value);
} }
/** /**
* Remove a flag from this plot * Remove a flag from this plot
* @param flag * @param flag
*/ */
public void removeFlag(String flag) { public boolean removeFlag(Flag<?> flag) {
FlagManager.removePlotFlag(this, flag); FlagManager.removePlotFlag(this, flag);
return false;
} }
/** /**
* Get the flag for a given key * Get the flag for a given key
* @param key * @param key
*/ */
public Flag getFlag(String key) { public <V> Optional<V> getFlag(Flag<V> key) {
return FlagManager.getPlotFlagRaw(this, key); return Optional.fromNullable(FlagManager.getPlotFlagRaw(this, key));
}
/**
* Get the flag for a given key
* @param key
*/
public <V> V getFlag(Flag<V> key, V def) {
V value = FlagManager.getPlotFlagRaw(this, key);
if (value == null) {
return def;
} else {
return value;
}
} }
/** /**
@ -1824,18 +1839,15 @@ public class Plot {
* - Does not take default flags into account<br> * - Does not take default flags into account<br>
* @return * @return
*/ */
public HashMap<String, Flag> getFlags() { public HashMap<Flag<?>, Object> getFlags() {
if (this.settings == null) { return this.getSettings().flags;
return new HashMap<>(0);
}
return this.settings.flags;
} }
/** /**
* Set a flag for this plot. * Set a flag for this plot.
* @param flags * @param flags
*/ */
public void setFlags(Set<Flag> flags) { public void setFlags(HashMap<Flag<?>, Object> flags) {
FlagManager.setPlotFlags(this, flags); FlagManager.setPlotFlags(this, flags);
} }
@ -2142,8 +2154,8 @@ public class Plot {
* @param b * @param b
*/ */
public void mergeData(Plot b) { public void mergeData(Plot b) {
HashMap<String, Flag> flags1 = this.getFlags(); HashMap<Flag<?>, Object> flags1 = this.getFlags();
HashMap<String, Flag> flags2 = b.getFlags(); HashMap<Flag<?>, Object> flags2 = b.getFlags();
if ((!flags1.isEmpty() || !flags2.isEmpty()) && !flags1.equals(flags2)) { if ((!flags1.isEmpty() || !flags2.isEmpty()) && !flags1.equals(flags2)) {
boolean greater = flags1.size() > flags2.size(); boolean greater = flags1.size() > flags2.size();
if (greater) { if (greater) {
@ -2151,7 +2163,7 @@ public class Plot {
} else { } else {
flags2.putAll(flags1); flags2.putAll(flags1);
} }
HashSet<Flag> net = new HashSet<>((greater ? flags1 : flags2).values()); HashMap<Flag<?>, Object> net = (greater ? flags1 : flags2);
this.setFlags(net); this.setFlags(net);
b.setFlags(net); b.setFlags(net);
} }
@ -2814,7 +2826,7 @@ public class Plot {
other.create(plot.owner, false); other.create(plot.owner, false);
if (!plot.getFlags().isEmpty()) { if (!plot.getFlags().isEmpty()) {
other.getSettings().flags = plot.getFlags(); other.getSettings().flags = plot.getFlags();
DBFunc.setFlags(other, plot.getFlags().values()); DBFunc.setFlags(other, plot.getFlags());
} }
if (plot.isMerged()) { if (plot.isMerged()) {
other.setMerged(plot.getMerged()); other.setMerged(plot.getMerged());
@ -2863,4 +2875,8 @@ public class Plot {
run.run(); run.run();
return true; return true;
} }
public boolean hasFlag(Flag<?> flag) {
return false;
}
} }

View File

@ -1,9 +1,9 @@
package com.intellectualcrafters.plot.object; package com.intellectualcrafters.plot.object;
import com.google.common.base.Optional;
import com.intellectualcrafters.configuration.file.YamlConfiguration; import com.intellectualcrafters.configuration.file.YamlConfiguration;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.Flags;
import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.generator.HybridUtils; import com.intellectualcrafters.plot.generator.HybridUtils;
import com.intellectualcrafters.plot.util.MathMan; import com.intellectualcrafters.plot.util.MathMan;
import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.TaskManager;
@ -34,10 +34,10 @@ public class PlotAnalysis {
private int complexity; private int complexity;
public static PlotAnalysis getAnalysis(Plot plot) { public static PlotAnalysis getAnalysis(Plot plot) {
Flag flag = FlagManager.getPlotFlagRaw(plot, "analysis"); Optional<List<Integer>> flag = plot.getFlag(Flags.ANALYSIS);
if (flag != null) { if (flag.isPresent()) {
PlotAnalysis analysis = new PlotAnalysis(); PlotAnalysis analysis = new PlotAnalysis();
List<Integer> values = (List<Integer>) flag.getValue(); List<Integer> values = flag.get();
analysis.changes = values.get(0); // 2126 analysis.changes = values.get(0); // 2126
analysis.faces = values.get(1); // 90 analysis.faces = values.get(1); // 90
analysis.data = values.get(2); // 0 analysis.data = values.get(2); // 0

View File

@ -53,7 +53,7 @@ public abstract class PlotArea {
public boolean SCHEMATIC_ON_CLAIM = false; public boolean SCHEMATIC_ON_CLAIM = false;
public String SCHEMATIC_FILE = "null"; public String SCHEMATIC_FILE = "null";
public List<String> SCHEMATICS = null; public List<String> SCHEMATICS = null;
public HashMap<String, Flag> DEFAULT_FLAGS; public HashMap<Flag<?>, Object> DEFAULT_FLAGS;
public boolean USE_ECONOMY = false; public boolean USE_ECONOMY = false;
public HashMap<String, Double> PRICES = new HashMap<>(); public HashMap<String, Double> PRICES = new HashMap<>();
public boolean SPAWN_EGGS = false; public boolean SPAWN_EGGS = false;

View File

@ -2,7 +2,7 @@ package com.intellectualcrafters.plot.object;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.flag.Flags;
import com.intellectualcrafters.plot.object.comment.PlotComment; import com.intellectualcrafters.plot.object.comment.PlotComment;
import java.util.ArrayList; import java.util.ArrayList;
@ -49,7 +49,7 @@ public class PlotSettings {
* @deprecated Raw access * @deprecated Raw access
*/ */
@Deprecated @Deprecated
public HashMap<String, Flag> flags; public HashMap<Flag<?>, Object> flags = new HashMap<>();
/** /**
* Home Position. * Home Position.
* @deprecated Raw access * @deprecated Raw access
@ -57,14 +57,6 @@ public class PlotSettings {
@Deprecated @Deprecated
private BlockLoc position; private BlockLoc position;
/**
* Constructor
*
*/
public PlotSettings() {
this.flags = new HashMap<>();
}
/** /**
* <b>Check if the plot is merged in a direction</b><br> 0 = North<br> 1 = East<br> 2 = South<br> 3 = West<br> * <b>Check if the plot is merged in a direction</b><br> 0 = North<br> 1 = East<br> 2 = South<br> 3 = West<br>
* *
@ -131,7 +123,7 @@ public class PlotSettings {
} }
public String getJoinMessage(PlotArea area) { public String getJoinMessage(PlotArea area) {
Flag greeting = FlagManager.getSettingFlag(area, this, "greeting"); Flag greeting = Flags.GREETING;
if (greeting != null) { if (greeting != null) {
return greeting.getValueString(); return greeting.getValueString();
} }
@ -145,7 +137,7 @@ public class PlotSettings {
* @return Farewell flag * @return Farewell flag
*/ */
public String getLeaveMessage(PlotArea plotArea) { public String getLeaveMessage(PlotArea plotArea) {
Flag farewell = FlagManager.getSettingFlag(plotArea, this, "farewell"); Flag farewell = Flags.FAREWELL;
if (farewell != null) { if (farewell != null) {
return farewell.getValueString(); return farewell.getValueString();
} }

View File

@ -64,19 +64,13 @@ public class ConsoleColors {
} }
} }
static enum ConsoleColor { enum ConsoleColor {
RESET("\u001B[0m"), BLACK("\u001B[30m"), RED("\u001B[31m"), GREEN("\u001B[32m"), YELLOW("\u001B[33m"), BLUE("\u001B[34m"), PURPLE("\u001B[35m"), CYAN("\u001B[36m"), WHITE("\u001B[37m"), BOLD( RESET("\u001B[0m"), BLACK("\u001B[30m"), RED("\u001B[31m"), GREEN("\u001B[32m"), YELLOW("\u001B[33m"), BLUE("\u001B[34m"), PURPLE("\u001B[35m"), CYAN("\u001B[36m"), WHITE("\u001B[37m"), BOLD(
"\033[1m"), UNDERLINE("\033[0m"), ITALIC("\033[3m"); "\033[1m"), UNDERLINE("\033[0m"), ITALIC("\033[3m");
private final String win;
private final String lin; private final String lin;
ConsoleColor(final String lin) { ConsoleColor(final String lin) {
this.lin = lin; this.lin = lin;
win = lin;
}
public String getWin() {
return win;
} }
public String getLin() { public String getLin() {

View File

@ -1,10 +1,11 @@
package com.intellectualcrafters.plot.util; package com.intellectualcrafters.plot.util;
import com.google.common.base.Optional;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.flag.Flags;
import com.intellectualcrafters.plot.object.LazyBlock; import com.intellectualcrafters.plot.object.LazyBlock;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
@ -36,9 +37,9 @@ public abstract class EventUtil {
public abstract boolean callFlagAdd(Flag flag, Plot plot); public abstract boolean callFlagAdd(Flag flag, Plot plot);
public abstract boolean callFlagRemove(Flag flag, Plot plot); public abstract boolean callFlagRemove(Flag<?> flag, Plot plot, Object value);
public abstract boolean callFlagRemove(Flag flag, PlotCluster cluster); public abstract boolean callFlagRemove(Flag<?> flag, Object value, PlotCluster cluster);
public abstract boolean callMerge(Plot plot, ArrayList<PlotId> plots); public abstract boolean callMerge(Plot plot, ArrayList<PlotId> plots);
@ -119,16 +120,16 @@ public abstract class EventUtil {
if (!plot.hasOwner()) { if (!plot.hasOwner()) {
return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), notifyPerms); return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), notifyPerms);
} }
Flag use = FlagManager.getPlotFlagRaw(plot, "use"); Optional<HashSet<PlotBlock>> use = plot.getFlag(Flags.USE);
if (use != null) { if (use.isPresent()) {
HashSet<PlotBlock> value = (HashSet<PlotBlock>) use.getValue(); HashSet<PlotBlock> value = use.get();
if (value.contains(PlotBlock.EVERYTHING) || value.contains(block.getPlotBlock())) { if (value.contains(PlotBlock.EVERYTHING) || value.contains(block.getPlotBlock())) {
return true; return true;
} }
} }
Flag destroy = FlagManager.getPlotFlagRaw(plot, "break"); Optional<HashSet<PlotBlock>> destroy = plot.getFlag(Flags.BREAK);
if (destroy != null) { if (destroy.isPresent()) {
HashSet<PlotBlock> value = (HashSet<PlotBlock>) destroy.getValue(); HashSet<PlotBlock> value = destroy.get();
if (value.contains(PlotBlock.EVERYTHING) || value.contains(block.getPlotBlock())) { if (value.contains(PlotBlock.EVERYTHING) || value.contains(block.getPlotBlock())) {
return true; return true;
} }
@ -141,7 +142,7 @@ public abstract class EventUtil {
if (plot == null) { if (plot == null) {
return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_ROAD.s(), notifyPerms); return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_ROAD.s(), notifyPerms);
} }
if (FlagManager.isPlotFlagTrue(plot, "hanging-break")) { if (plot.getFlag(Flags.HANGING_BREAK).or(false)) {
return true; return true;
} }
if (plot.hasOwner()) { if (plot.hasOwner()) {
@ -153,7 +154,7 @@ public abstract class EventUtil {
if (plot == null) { if (plot == null) {
return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_ROAD.s(), notifyPerms); return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_ROAD.s(), notifyPerms);
} }
if (FlagManager.isPlotFlagTrue(plot, "misc-break")) { if (plot.getFlag(Flags.MISC_BREAK).or(false)) {
return true; return true;
} }
if (plot.hasOwner()) { if (plot.hasOwner()) {
@ -165,7 +166,7 @@ public abstract class EventUtil {
if (plot == null) { if (plot == null) {
return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_ROAD.s(), notifyPerms); return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_ROAD.s(), notifyPerms);
} }
if (FlagManager.isPlotFlagTrue(plot, "vehicle-break")) { if (plot.getFlag(Flags.VEHICLE_BREAK).or(false)) {
return true; return true;
} }
if (plot.hasOwner()) { if (plot.hasOwner()) {
@ -182,14 +183,14 @@ public abstract class EventUtil {
if (!plot.hasOwner()) { if (!plot.hasOwner()) {
return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), notifyPerms); return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), notifyPerms);
} }
Flag flag = FlagManager.getPlotFlagRaw(plot, "use"); Optional<HashSet<PlotBlock>> flagValue = plot.getFlag(Flags.USE);
HashSet<PlotBlock> value; HashSet<PlotBlock> value;
if (flag == null) { if (flagValue.isPresent()) {
value = null; value = flagValue.get();
} else { } else {
value = (HashSet<PlotBlock>) flag.getValue(); return true;
} }
if (value == null || !value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock())) { if (!value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock())) {
return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER.s(), notifyPerms) || !(!notifyPerms || MainUtil return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER.s(), notifyPerms) || !(!notifyPerms || MainUtil
.sendMessage(pp, C.FLAG_TUTORIAL_USAGE, C.FLAG_USE.s())); .sendMessage(pp, C.FLAG_TUTORIAL_USAGE, C.FLAG_USE.s()));
} }
@ -202,14 +203,14 @@ public abstract class EventUtil {
if (!plot.hasOwner()) { if (!plot.hasOwner()) {
return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_UNOWNED.s(), notifyPerms); return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_UNOWNED.s(), notifyPerms);
} }
Flag flag = FlagManager.getPlotFlagRaw(plot, "place"); Optional<HashSet<PlotBlock>> flagValue = plot.getFlag(Flags.PLACE);
HashSet<PlotBlock> value; HashSet<PlotBlock> value;
if (flag == null) { if (flagValue.isPresent()) {
value = null; value = flagValue.get();
} else { } else {
value = (HashSet<PlotBlock>) flag.getValue(); return true;
} }
if (value == null || !value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock())) { if (!value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock())) {
if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER.s(), notifyPerms)) { if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER.s(), notifyPerms)) {
return true; return true;
} }
@ -224,18 +225,19 @@ public abstract class EventUtil {
if (!plot.hasOwner()) { if (!plot.hasOwner()) {
return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), false); return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), false);
} }
if (FlagManager.isPlotFlagTrue(plot, "device-interact")) { if (plot.getFlag(Flags.DEVICE_INTERACT).or(false)) {
return true; return true;
} }
Flag flag = FlagManager.getPlotFlagRaw(plot, "use"); Optional<HashSet<PlotBlock>> flagValue = plot.getFlag(Flags.USE);
HashSet<PlotBlock> value; HashSet<PlotBlock> value;
if (flag == null) { if (flagValue.isPresent()) {
value = null; value = flagValue.get();
} else { } else {
value = (HashSet<PlotBlock>) flag.getValue(); return true;
} }
if (value == null || !value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock())) { if (!value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock())) {
return false; //!(!false || MainUtil.sendMessage(pp, C.FLAG_TUTORIAL_USAGE, C.FLAG_USE.s() + "/" + C.FLAG_DEVICE_INTERACT.s())); // TODO: fix the commented dead code
return true; //!(!false || MainUtil.sendMessage(pp, C.FLAG_TUTORIAL_USAGE, C.FLAG_USE.s() + "/" + C.FLAG_DEVICE_INTERACT.s()));
} }
return true; return true;
} }
@ -246,12 +248,17 @@ public abstract class EventUtil {
if (!plot.hasOwner()) { if (!plot.hasOwner()) {
return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), notifyPerms); return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), notifyPerms);
} }
if (FlagManager.isPlotFlagTrue(plot, "hanging-interact")) { if (plot.getFlag(Flags.HOSTILE_INTERACT).or(false)) {
return true; return true;
} }
Flag flag = FlagManager.getPlotFlagRaw(plot, "use"); Optional<HashSet<PlotBlock>> flagValue = plot.getFlag(Flags.USE);
HashSet<PlotBlock> value = flag == null ? null : (HashSet<PlotBlock>) flag.getValue(); HashSet<PlotBlock> value;
if (value == null || !value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock())) { if (flagValue.isPresent()) {
value = flagValue.get();
} else {
return true;
}
if (!value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock())) {
if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER.s(), notifyPerms)) { if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER.s(), notifyPerms)) {
return true; return true;
} }
@ -266,12 +273,18 @@ public abstract class EventUtil {
if (!plot.hasOwner()) { if (!plot.hasOwner()) {
return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), notifyPerms); return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), notifyPerms);
} }
if (FlagManager.isPlotFlagTrue(plot, "misc-interact")) { if (plot.getFlag(Flags.MISC_INTERACT).or(false)) {
return true; return true;
} }
Flag flag = FlagManager.getPlotFlagRaw(plot, "use");
HashSet<PlotBlock> value = flag == null ? null : (HashSet<PlotBlock>) flag.getValue(); Optional<HashSet<PlotBlock>> flag = plot.getFlag(Flags.USE);
if (value == null || !value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock())) { HashSet<PlotBlock> value;
if (flag.isPresent()) {
value = flag.get();
} else {
return true;
}
if (!value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock())) {
if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER.s(), notifyPerms)) { if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER.s(), notifyPerms)) {
return true; return true;
} }
@ -286,12 +299,17 @@ public abstract class EventUtil {
if (!plot.hasOwner()) { if (!plot.hasOwner()) {
return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), notifyPerms); return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), notifyPerms);
} }
if (FlagManager.isPlotFlagTrue(plot, "vehicle-use")) { if (plot.getFlag(Flags.VEHICLE_USE).or(false)) {
return true; return true;
} }
Flag flag = FlagManager.getPlotFlagRaw(plot, "use"); Optional<HashSet<PlotBlock>> flag = plot.getFlag(Flags.USE);
HashSet<PlotBlock> value = flag == null ? null : (HashSet<PlotBlock>) flag.getValue(); HashSet<PlotBlock> value;
if (value == null || !value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock())) { if (flag.isPresent()) {
value = flag.get();
} else {
return true;
}
if (!value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock())) {
if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER.s(), notifyPerms)) { if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER.s(), notifyPerms)) {
return true; return true;
} }
@ -307,12 +325,17 @@ public abstract class EventUtil {
return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), notifyPerms); return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), notifyPerms);
} }
if (FlagManager.isPlotFlagTrue(plot, "mob-place")) { if (plot.getFlag(Flags.MOB_PLACE).or(false)) {
return true; return true;
} }
Flag flag = FlagManager.getPlotFlagRaw(plot, "place"); Optional<HashSet<PlotBlock>> flagValue = plot.getFlag(Flags.PLACE);
HashSet<PlotBlock> value = flag == null ? null : (HashSet<PlotBlock>) flag.getValue(); HashSet<PlotBlock> value;
if (value == null || !value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock())) { if (flagValue.isPresent()) {
value = flagValue.get();
} else {
return true;
}
if (!value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock())) {
if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER.s(), notifyPerms)) { if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER.s(), notifyPerms)) {
return true; return true;
} }
@ -330,17 +353,24 @@ public abstract class EventUtil {
return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), notifyPerms); return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), notifyPerms);
} }
if (FlagManager.isPlotFlagTrue(plot, "misc-place")) { if (plot.getFlag(Flags.MISC_PLACE).or(false)) {
return true; return true;
} }
Flag flag = FlagManager.getPlotFlagRaw(plot, "place"); Optional<HashSet<PlotBlock>> flag = plot.getFlag(Flags.PLACE);
HashSet<PlotBlock> value = flag == null ? null : (HashSet<PlotBlock>) flag.getValue();
if (value == null || !value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock())) { HashSet<PlotBlock> value;
if (flag.isPresent()) {
value = flag.get();
} else {
return true;
}
if (!value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock())) {
if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER.s(), notifyPerms)) { if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER.s(), notifyPerms)) {
return true; return true;
} }
return !(!notifyPerms || MainUtil.sendMessage(pp, C.FLAG_TUTORIAL_USAGE, C.FLAG_MISC_PLACE.s() + "/" + C.FLAG_PLACE.s())); return !(!notifyPerms || MainUtil.sendMessage(pp, C.FLAG_TUTORIAL_USAGE, C.FLAG_MISC_PLACE.s() + "/" + C.FLAG_PLACE.s()));
} }
return true; return true;
} }
case PLACE_VEHICLE: case PLACE_VEHICLE:
@ -351,12 +381,17 @@ public abstract class EventUtil {
return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), notifyPerms); return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), notifyPerms);
} }
if (FlagManager.isPlotFlagTrue(plot, "vehicle-place")) { if (plot.getFlag(Flags.VEHICLE_PLACE).or(false)) {
return true; return true;
} }
Flag flag = FlagManager.getPlotFlagRaw(plot, "place"); Optional<HashSet<PlotBlock>> flag = plot.getFlag(Flags.PLACE);
HashSet<PlotBlock> value = flag == null ? null : (HashSet<PlotBlock>) flag.getValue(); HashSet<PlotBlock> value;
if (value == null || !value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock())) { if (flag.isPresent()) {
value = flag.get();
} else {
return true;
}
if (!value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock())) {
if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER.s(), notifyPerms)) { if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER.s(), notifyPerms)) {
return true; return true;
} }

View File

@ -1,11 +1,12 @@
package com.intellectualcrafters.plot.util; package com.intellectualcrafters.plot.util;
import com.google.common.base.Optional;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.flag.Flags;
import com.intellectualcrafters.plot.generator.HybridUtils; import com.intellectualcrafters.plot.generator.HybridUtils;
import com.intellectualcrafters.plot.object.OfflinePlotPlayer; import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
@ -155,7 +156,7 @@ public class ExpireManager {
if ((changed.changes != 0) && (changed.getComplexity() > Settings.CLEAR_THRESHOLD)) { if ((changed.changes != 0) && (changed.getComplexity() > Settings.CLEAR_THRESHOLD)) {
PS.debug("$2[&5Expire&dManager$2] &bIgnoring modified plot: " + plot + " : " + changed.getComplexity() + " - " PS.debug("$2[&5Expire&dManager$2] &bIgnoring modified plot: " + plot + " : " + changed.getComplexity() + " - "
+ changed.changes); + changed.changes);
FlagManager.addPlotFlag(plot, new Flag(FlagManager.getFlag("analysis"), changed.asList())); FlagManager.addPlotFlag(plot, Flags.ANALYSIS, changed.asList());
TaskManager.runTaskLaterAsync(task, Settings.CLEAR_INTERVAL * 20); TaskManager.runTaskLaterAsync(task, Settings.CLEAR_INTERVAL * 20);
} else { } else {
expiredTask.run(plot, new Runnable() { expiredTask.run(plot, new Runnable() {
@ -263,9 +264,9 @@ public class ExpireManager {
if (!plot.hasOwner() || Objects.equals(DBFunc.everyone, plot.owner) || UUIDHandler.getPlayer(plot.owner) != null || plot.getRunning() > 0) { if (!plot.hasOwner() || Objects.equals(DBFunc.everyone, plot.owner) || UUIDHandler.getPlayer(plot.owner) != null || plot.getRunning() > 0) {
return false; return false;
} }
Flag keep = plot.getFlag("keep"); Optional<Object> keep = plot.getFlag(Flags.KEEP);
if (keep != null) { if (keep.isPresent()) {
Object value = keep.getValue(); Object value = keep.get();
if (value instanceof Boolean) { if (value instanceof Boolean) {
if (Boolean.TRUE.equals(value)) { if (Boolean.TRUE.equals(value)) {
return false; return false;

View File

@ -1,11 +1,12 @@
package com.intellectualcrafters.plot.util; package com.intellectualcrafters.plot.util;
import com.google.common.base.Optional;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.flag.Flags;
import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.object.ConsolePlayer; import com.intellectualcrafters.plot.object.ConsolePlayer;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
@ -708,9 +709,9 @@ public class MainUtil {
String expires = C.UNKNOWN.s(); String expires = C.UNKNOWN.s();
if (Settings.AUTO_CLEAR) { if (Settings.AUTO_CLEAR) {
if (plot.hasOwner()) { if (plot.hasOwner()) {
Flag keep = plot.getFlag("keep"); Optional<Object> keep = plot.getFlag(Flags.KEEP);
if (keep != null) { if (keep.isPresent()) {
Object value = keep.getValue(); Object value = keep.get();
if (value instanceof Boolean) { if (value instanceof Boolean) {
if (Boolean.TRUE.equals(value)) { if (Boolean.TRUE.equals(value)) {
expires = C.NONE.s(); expires = C.NONE.s();
@ -731,8 +732,8 @@ public class MainUtil {
} else { } else {
expires = C.NEVER.s(); expires = C.NEVER.s();
} }
Flag descriptionFlag = FlagManager.getPlotFlagRaw(plot, "description"); Optional<String> descriptionFlag = plot.getFlag(Flags.DESCRIPTION);
String description = descriptionFlag == null ? C.NONE.s() : descriptionFlag.getValueString(); String description = !descriptionFlag.isPresent() ? C.NONE.s() : Flags.DESCRIPTION.valueToString(descriptionFlag.get());
String flags; String flags;
if (!StringMan.join(FlagManager.getPlotFlags(plot.getArea(), plot.getSettings(), true).values(), "").isEmpty()) { if (!StringMan.join(FlagManager.getPlotFlags(plot.getArea(), plot.getSettings(), true).values(), "").isEmpty()) {

View File

@ -155,7 +155,7 @@ public abstract class SchematicHandler {
Map<String, Tag> flags = schematic.getFlags(); Map<String, Tag> flags = schematic.getFlags();
if (!flags.isEmpty()) { if (!flags.isEmpty()) {
for (Map.Entry<String, Tag> entry : flags.entrySet()) { for (Map.Entry<String, Tag> entry : flags.entrySet()) {
plot.setFlag(entry.getKey(), StringTag.class.cast(entry.getValue()).getValue()); //plot.setFlag(entry.getKey(), StringTag.class.cast(entry.getValue()).getValue());
} }
} }
@ -619,9 +619,9 @@ public abstract class SchematicHandler {
public void run(CompoundTag value) { public void run(CompoundTag value) {
if (!plot.getFlags().isEmpty()) { if (!plot.getFlags().isEmpty()) {
HashMap<String, Tag> flagMap = new HashMap<>(); HashMap<String, Tag> flagMap = new HashMap<>();
for (Map.Entry<String, Flag> entry : plot.getFlags().entrySet()) { for (Map.Entry<Flag<?>, Object> entry : plot.getFlags().entrySet()) {
String key = entry.getKey(); String key = entry.getKey().getName();
flagMap.put(key, new StringTag(key, entry.getValue().getValueString())); flagMap.put(key, new StringTag(key, entry.getKey().valueToString(entry.getValue())));
} }
CompoundTag tag = new CompoundTag("Flags", flagMap); CompoundTag tag = new CompoundTag("Flags", flagMap);
HashMap<String, Tag> map = new HashMap<>(value.getValue()); HashMap<String, Tag> map = new HashMap<>(value.getValue());

View File

@ -1,9 +1,11 @@
package com.plotsquared.listener; package com.plotsquared.listener;
import com.google.common.base.Optional;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.flag.Flags;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotArea; import com.intellectualcrafters.plot.object.PlotArea;
@ -41,19 +43,19 @@ public class PlotListener {
pp.setMeta("lastplot", plot); pp.setMeta("lastplot", plot);
EventUtil.manager.callEntry(pp, plot); EventUtil.manager.callEntry(pp, plot);
if (plot.hasOwner()) { if (plot.hasOwner()) {
HashMap<String, Flag> flags = FlagManager.getPlotFlags(plot); HashMap<Flag<?>, Object> flags = FlagManager.getPlotFlags(plot);
int size = flags.size(); int size = flags.size();
boolean titles = Settings.TITLES; boolean titles = Settings.TITLES;
final String greeting; final String greeting;
if (size != 0) { if (size != 0) {
Flag titleFlag = flags.get("titles"); Optional<Boolean> titleFlag = plot.getFlag(Flags.TITLES);
if (titleFlag != null) { if (titleFlag.isPresent()) {
titles = (Boolean) titleFlag.getValue(); titles = titleFlag.get();
} }
Flag greetingFlag = flags.get("greeting"); Optional<String> greetingFlag = plot.getFlag(Flags.GREETING);
if (greetingFlag != null) { if (greetingFlag.isPresent()) {
greeting = (String) greetingFlag.getValue(); greeting = greetingFlag.get();
MainUtil.format(C.PREFIX_GREETING.s() + greeting, plot, pp, false, new RunnableVal<String>() { MainUtil.format(C.PREFIX_GREETING.s() + greeting, plot, pp, false, new RunnableVal<String>() {
@Override @Override
public void run(String value) { public void run(String value) {
@ -63,8 +65,8 @@ public class PlotListener {
} else { } else {
greeting = ""; greeting = "";
} }
Flag enter = flags.get("notify-enter"); Optional<Boolean> enter = plot.getFlag(Flags.NOTIFY_ENTER);
if (enter != null && (Boolean) enter.getValue()) { if (enter.isPresent() && enter.get()) {
if (!Permissions.hasPermission(pp, "plots.flag.notify-enter.bypass")) { if (!Permissions.hasPermission(pp, "plots.flag.notify-enter.bypass")) {
for (UUID uuid : plot.getOwners()) { for (UUID uuid : plot.getOwners()) {
PlotPlayer owner = UUIDHandler.getPlayer(uuid); PlotPlayer owner = UUIDHandler.getPlayer(uuid);
@ -75,38 +77,38 @@ public class PlotListener {
} }
} }
} }
Flag gamemodeFlag = flags.get("gamemode"); Optional<PlotGameMode> gamemodeFlag = plot.getFlag(Flags.GAMEMODE);
if (gamemodeFlag != null) { if (gamemodeFlag.isPresent()) {
if (pp.getGameMode() != gamemodeFlag.getValue()) { if (pp.getGameMode() != gamemodeFlag.get()) {
if (!Permissions.hasPermission(pp, "plots.gamemode.bypass")) { if (!Permissions.hasPermission(pp, "plots.gamemode.bypass")) {
pp.setGameMode((PlotGameMode) gamemodeFlag.getValue()); pp.setGameMode(gamemodeFlag.get());
} else { } else {
MainUtil.sendMessage(pp, MainUtil.sendMessage(pp,
StringMan.replaceAll(C.GAMEMODE_WAS_BYPASSED.s(), "{plot}", plot.getId(), "{gamemode}", gamemodeFlag.getValue())); StringMan.replaceAll(C.GAMEMODE_WAS_BYPASSED.s(), "{plot}", plot.getId(), "{gamemode}", gamemodeFlag.get()));
} }
} }
} }
Flag flyFlag = flags.get("fly"); Optional<Boolean> flyFlag = plot.getFlag(Flags.FLY);
if (flyFlag != null) { if (flyFlag.isPresent()) {
pp.setFlight((boolean) flyFlag.getValue()); pp.setFlight(flyFlag.get());
} }
Flag timeFlag = flags.get("time"); Optional<Long> timeFlag = plot.getFlag(Flags.TIME);
if (timeFlag != null) { if (timeFlag.isPresent()) {
try { try {
long time = (long) timeFlag.getValue(); long time = timeFlag.get();
pp.setTime(time); pp.setTime(time);
} catch (Exception e) { } catch (Exception e) {
FlagManager.removePlotFlag(plot, "time"); FlagManager.removePlotFlag(plot, Flags.TIME);
} }
} }
Flag weatherFlag = flags.get("weather"); Optional<PlotWeather> weatherFlag = plot.getFlag(Flags.WEATHER);
if (weatherFlag != null) { if (weatherFlag.isPresent()) {
pp.setWeather((PlotWeather) weatherFlag.getValue()); pp.setWeather(weatherFlag.get());
} }
Flag musicFlag = flags.get("music"); Optional<Integer> musicFlag = plot.getFlag(Flags.MUSIC);
if (musicFlag != null) { if (musicFlag.isPresent()) {
Integer id = (Integer) musicFlag.getValue(); Integer id = musicFlag.get();
if ((id >= 2256 && id <= 2267) || (id == 0)) { if ((id >= 2256 && id <= 2267) || (id == 0)) {
Location loc = pp.getLocation(); Location loc = pp.getLocation();
Location lastLoc = pp.getMeta("music"); Location lastLoc = pp.getMeta("music");
@ -172,7 +174,7 @@ public class PlotListener {
if (pw == null) { if (pw == null) {
return true; return true;
} }
if (FlagManager.getPlotFlagRaw(plot, "gamemode") != null) { if (plot.getFlag(Flags.GAMEMODE).isPresent()) {
if (pp.getGameMode() != pw.GAMEMODE) { if (pp.getGameMode() != pw.GAMEMODE) {
if (!Permissions.hasPermission(pp, "plots.gamemode.bypass")) { if (!Permissions.hasPermission(pp, "plots.gamemode.bypass")) {
pp.setGameMode(pw.GAMEMODE); pp.setGameMode(pw.GAMEMODE);
@ -182,17 +184,17 @@ public class PlotListener {
} }
} }
} }
Flag farewell = FlagManager.getPlotFlagRaw(plot, "farewell"); Optional<String> farewell = plot.getFlag(Flags.FAREWELL);
if (farewell != null) { if (farewell.isPresent()) {
MainUtil.format(C.PREFIX_FAREWELL.s() + farewell.getValueString(), plot, pp, false, new RunnableVal<String>() { MainUtil.format(C.PREFIX_FAREWELL.s() + farewell.get(), plot, pp, false, new RunnableVal<String>() {
@Override @Override
public void run(String value) { public void run(String value) {
MainUtil.sendMessage(pp, value); MainUtil.sendMessage(pp, value);
} }
}); });
} }
Flag leave = FlagManager.getPlotFlagRaw(plot, "notify-leave"); Optional<Boolean> leave = plot.getFlag(Flags.NOTIFY_LEAVE);
if ((leave != null) && (Boolean) leave.getValue()) { if (leave.isPresent() && leave.get()) {
if (!Permissions.hasPermission(pp, "plots.flag.notify-enter.bypass")) { if (!Permissions.hasPermission(pp, "plots.flag.notify-enter.bypass")) {
for (UUID uuid : plot.getOwners()) { for (UUID uuid : plot.getOwners()) {
PlotPlayer owner = UUIDHandler.getPlayer(uuid); PlotPlayer owner = UUIDHandler.getPlayer(uuid);
@ -202,16 +204,16 @@ public class PlotListener {
} }
} }
} }
if (FlagManager.getPlotFlagRaw(plot, "fly") != null) { if (plot.getFlag(Flags.FLY).isPresent()) {
PlotGameMode gamemode = pp.getGameMode(); PlotGameMode gamemode = pp.getGameMode();
if (gamemode == PlotGameMode.SURVIVAL || (gamemode == PlotGameMode.ADVENTURE)) { if (gamemode == PlotGameMode.SURVIVAL || (gamemode == PlotGameMode.ADVENTURE)) {
pp.setFlight(false); pp.setFlight(false);
} }
} }
if (FlagManager.getPlotFlagRaw(plot, "time") != null) { if (plot.getFlag(Flags.TIME).isPresent()) {
pp.setTime(Long.MAX_VALUE); pp.setTime(Long.MAX_VALUE);
} }
if (FlagManager.getPlotFlagRaw(plot, "weather") != null) { if (plot.getFlag(Flags.WEATHER).isPresent()) {
pp.setWeather(PlotWeather.RESET); pp.setWeather(PlotWeather.RESET);
} }
Location lastLoc = pp.getMeta("music"); Location lastLoc = pp.getMeta("music");

View File

@ -2,7 +2,7 @@ package com.plotsquared.listener;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.flag.Flags;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotArea; import com.intellectualcrafters.plot.object.PlotArea;
@ -46,7 +46,7 @@ public class WEManager {
return regions; return regions;
} }
for (Plot plot : area.getPlots()) { for (Plot plot : area.getPlots()) {
if (!plot.isBasePlot() || (Settings.DONE_RESTRICTS_BUILDING && (FlagManager.getPlotFlagRaw(plot, "done") != null))) { if (!plot.isBasePlot() || (Settings.DONE_RESTRICTS_BUILDING && (plot.getFlag(Flags.DONE).isPresent()))) {
continue; continue;
} }
if (Settings.WE_ALLOW_HELPER && plot.isAdded(uuid) || !Settings.WE_ALLOW_HELPER && (plot.isOwner(uuid) || plot.getTrusted() if (Settings.WE_ALLOW_HELPER && plot.isAdded(uuid) || !Settings.WE_ALLOW_HELPER && (plot.isOwner(uuid) || plot.getTrusted()

View File

@ -0,0 +1,55 @@
package com.intellectualcrafters.plot;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import com.google.common.base.Optional;
import com.intellectualcrafters.plot.database.AbstractDBTEst;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.flag.Flags;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.util.EventUtil;
import com.intellectualcrafters.plot.util.EventUtilTest;
import org.hamcrest.core.IsCollectionContaining;
import org.junit.Before;
import org.junit.Test;
import java.util.HashSet;
import java.util.UUID;
public class FlagTest {
private PlotBlock testBlock;
@Before
public void setUp() throws Exception {
EventUtil.manager = new EventUtilTest();
DBFunc.dbManager = new AbstractDBTEst();
}
@Test
public void flagTest() throws Exception {
Plot plot = new Plot(null, new PlotId(0, 0));
plot.owner = UUID.fromString("84499644-ad72-454b-a19d-f28c28df382b");
Flags.USE.parseValue("33,33:1,6:4");
plot.setFlag(Flags.USE, Flags.USE.parseValue("33,33:1,6:4"));
Optional<HashSet<PlotBlock>> flag = plot.getFlag(Flags.USE);
if (flag.isPresent()) {
System.out.println(Flags.USE.valueToString(flag.get()));
}
testBlock = new PlotBlock((short) 1, (byte) 0);
flag.get().add(testBlock);
if (flag.isPresent()) {
System.out.println(Flags.USE.valueToString(flag.get()));
}
Optional<HashSet<PlotBlock>> flag2 = plot.getFlag(Flags.USE);
if (flag2.isPresent()) {
assertThat(flag2.get(), IsCollectionContaining.hasItem(testBlock));
}
if (flag.isPresent() && flag2.isPresent()) {
assertEquals(flag.get(), flag2.get());
}
}
}

View File

@ -0,0 +1,243 @@
package com.intellectualcrafters.plot.database;
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotCluster;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.object.comment.PlotComment;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
public class AbstractDBTEst implements AbstractDB {
@Override public void setOwner(Plot plot, UUID uuid) {
}
@Override public void createPlotsAndData(ArrayList<Plot> plots, Runnable whenDone) {
}
@Override public void createPlot(Plot plot) {
}
@Override public void createTables() throws Exception {
}
@Override public void delete(Plot plot) {
}
@Override public void deleteSettings(Plot plot) {
}
@Override public void deleteHelpers(Plot plot) {
}
@Override public void deleteTrusted(Plot plot) {
}
@Override public void deleteDenied(Plot plot) {
}
@Override public void deleteComments(Plot plot) {
}
@Override public void deleteRatings(Plot plot) {
}
@Override public void delete(PlotCluster cluster) {
}
@Override public void addPersistentMeta(UUID uuid, String key, byte[] meta, boolean delete) {
}
@Override public void removePersistentMeta(UUID uuid, String key) {
}
@Override public void getPersistentMeta(UUID uuid, RunnableVal<Map<String, byte[]>> result) {
}
@Override public void createPlotSettings(int id, Plot plot) {
}
@Override public int getId(Plot plot) {
return 0;
}
@Override public int getClusterId(PlotCluster cluster) {
return 0;
}
@Override public HashMap<String, HashMap<PlotId, Plot>> getPlots() {
return null;
}
@Override public void validateAllPlots(Set<Plot> toValidate) {
}
@Override public HashMap<String, Set<PlotCluster>> getClusters() {
return null;
}
@Override public void setMerged(Plot plot, boolean[] merged) {
}
@Override public void swapPlots(Plot plot1, Plot plot2) {
}
@Override public void setFlags(Plot plot, HashMap<Flag<?>, Object> flags) {
}
@Override public void setFlags(PlotCluster cluster, HashMap<Flag<?>, Object> flags) {
}
@Override public void setClusterName(PlotCluster cluster, String name) {
}
@Override public void setAlias(Plot plot, String alias) {
}
@Override public void purgeIds(Set<Integer> uniqueIds) {
}
@Override public void purge(PlotArea area, Set<PlotId> plotIds) {
}
@Override public void setPosition(Plot plot, String position) {
}
@Override public void setPosition(PlotCluster cluster, String position) {
}
@Override public void removeTrusted(Plot plot, UUID uuid) {
}
@Override public void removeHelper(PlotCluster cluster, UUID uuid) {
}
@Override public void removeMember(Plot plot, UUID uuid) {
}
@Override public void removeInvited(PlotCluster cluster, UUID uuid) {
}
@Override public void setTrusted(Plot plot, UUID uuid) {
}
@Override public void setHelper(PlotCluster cluster, UUID uuid) {
}
@Override public void setMember(Plot plot, UUID uuid) {
}
@Override public void setInvited(PlotCluster cluster, UUID uuid) {
}
@Override public void removeDenied(Plot plot, UUID uuid) {
}
@Override public void setDenied(Plot plot, UUID uuid) {
}
@Override public HashMap<UUID, Integer> getRatings(Plot plot) {
return null;
}
@Override public void setRating(Plot plot, UUID rater, int value) {
}
@Override public void removeComment(Plot plot, PlotComment comment) {
}
@Override public void clearInbox(Plot plot, String inbox) {
}
@Override public void setComment(Plot plot, PlotComment comment) {
}
@Override public void getComments(Plot plot, String inbox, RunnableVal<List<PlotComment>> whenDone) {
}
@Override public void createPlotAndSettings(Plot plot, Runnable whenDone) {
}
@Override public void createCluster(PlotCluster cluster) {
}
@Override public void resizeCluster(PlotCluster current, PlotId min, PlotId max) {
}
@Override public void movePlot(Plot originalPlot, Plot newPlot) {
}
@Override public void replaceUUID(UUID old, UUID now) {
}
@Override public boolean deleteTables() {
return false;
}
@Override public void close() {
}
@Override public void replaceWorld(String oldWorld, String newWorld, PlotId min, PlotId max) {
}
@Override public void updateTables(int[] oldVersion) {
}
}

View File

@ -0,0 +1,76 @@
package com.intellectualcrafters.plot.util;
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotCluster;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.Rating;
import java.util.ArrayList;
import java.util.UUID;
public class EventUtilTest extends EventUtil {
@Override public Rating callRating(PlotPlayer player, Plot plot, Rating rating) {
return null;
}
@Override public boolean callClaim(PlotPlayer player, Plot plot, boolean auto) {
return false;
}
@Override public boolean callTeleport(PlotPlayer player, Location from, Plot plot) {
return false;
}
@Override public boolean callClear(Plot plot) {
return false;
}
@Override public void callDelete(Plot plot) {
}
@Override public boolean callFlagAdd(Flag flag, Plot plot) {
return true;
}
@Override public boolean callFlagRemove(Flag<?> flag, Plot plot, Object value) {
return true;
}
@Override public boolean callFlagRemove(Flag<?> flag, Object value, PlotCluster cluster) {
return true;
}
@Override public boolean callMerge(Plot plot, ArrayList<PlotId> plots) {
return false;
}
@Override public boolean callUnlink(PlotArea area, ArrayList<PlotId> plots) {
return false;
}
@Override public void callEntry(PlotPlayer player, Plot plot) {
}
@Override public void callLeave(PlotPlayer player, Plot plot) {
}
@Override public void callDenied(PlotPlayer initiator, Plot plot, UUID player, boolean added) {
}
@Override public void callTrusted(PlotPlayer initiator, Plot plot, UUID player, boolean added) {
}
@Override public void callMember(PlotPlayer initiator, Plot plot, UUID player, boolean added) {
}
}

View File

@ -4,8 +4,7 @@ import com.flowpowered.math.vector.Vector3d;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.Flags;
import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotArea; import com.intellectualcrafters.plot.object.PlotArea;
@ -27,7 +26,6 @@ import com.plotsquared.sponge.util.SpongeUtil;
import org.spongepowered.api.block.BlockSnapshot; import org.spongepowered.api.block.BlockSnapshot;
import org.spongepowered.api.block.BlockState; import org.spongepowered.api.block.BlockState;
import org.spongepowered.api.data.Transaction; import org.spongepowered.api.data.Transaction;
import org.spongepowered.api.entity.Entity;
import org.spongepowered.api.entity.EntityTypes; import org.spongepowered.api.entity.EntityTypes;
import org.spongepowered.api.entity.explosive.Explosive; import org.spongepowered.api.entity.explosive.Explosive;
import org.spongepowered.api.entity.living.Ambient; import org.spongepowered.api.entity.living.Ambient;
@ -61,6 +59,7 @@ import java.util.UUID;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Predicate; import java.util.function.Predicate;
@SuppressWarnings("Guava")
public class MainListener { public class MainListener {
/* /*
@ -203,16 +202,16 @@ public class MainListener {
// } // }
if (entity.getType() == EntityTypes.ITEM) { if (entity.getType() == EntityTypes.ITEM) {
return !FlagManager.isPlotFlagFalse(plot, "item-drop"); return plot.getFlag(Flags.ITEM_DROP).or(true);
} }
int[] mobs = null; int[] mobs = null;
if (entity instanceof Living) { if (entity instanceof Living) {
if (!loc.getPlotArea().MOB_SPAWNING) { if (!loc.getPlotArea().MOB_SPAWNING) {
return false; return false;
} }
Flag mobCap = FlagManager.getPlotFlagRaw(plot, "mob-cap"); com.google.common.base.Optional<Integer> mobCap = plot.getFlag(Flags.MOB_CAP);
if (mobCap != null) { if (mobCap.isPresent()) {
Integer cap = (Integer) mobCap.getValue(); Integer cap = mobCap.get();
if (cap == 0) { if (cap == 0) {
return false; return false;
} }
@ -222,9 +221,9 @@ public class MainListener {
} }
} }
if (entity instanceof Ambient || entity instanceof Animal) { if (entity instanceof Ambient || entity instanceof Animal) {
Flag animalFlag = FlagManager.getPlotFlagRaw(plot, "animal-cap"); com.google.common.base.Optional<Integer> animalFlag = plot.getFlag(Flags.ANIMAL_CAP);
if (animalFlag != null) { if (animalFlag.isPresent()) {
int cap = (Integer) animalFlag.getValue(); int cap = animalFlag.get();
if (cap == 0) { if (cap == 0) {
return false; return false;
} }
@ -236,9 +235,9 @@ public class MainListener {
} }
} }
} else if (entity instanceof Monster) { } else if (entity instanceof Monster) {
Flag monsterFlag = FlagManager.getPlotFlagRaw(plot, "hostile-cap"); com.google.common.base.Optional<Integer> monsterFlag = plot.getFlag(Flags.HOSTILE_CAP);
if (monsterFlag != null) { if (monsterFlag.isPresent()) {
int cap = (Integer) monsterFlag.getValue(); int cap = monsterFlag.get();
if (cap == 0) { if (cap == 0) {
return false; return false;
} }
@ -252,9 +251,9 @@ public class MainListener {
} }
return true; return true;
} else if (entity instanceof Minecart || entity instanceof Boat) { } else if (entity instanceof Minecart || entity instanceof Boat) {
Flag vehicleFlag = FlagManager.getPlotFlagRaw(plot, "vehicle-cap"); com.google.common.base.Optional<Integer> vehicleFlag = plot.getFlag(Flags.VEHICLE_CAP);
if (vehicleFlag != null) { if (vehicleFlag.isPresent()) {
int cap = (Integer) vehicleFlag.getValue(); int cap = vehicleFlag.get();
if (cap == 0) { if (cap == 0) {
return false; return false;
} }
@ -264,9 +263,9 @@ public class MainListener {
} }
} }
} }
Flag entityCap = FlagManager.getPlotFlagRaw(plot, "entity-cap"); com.google.common.base.Optional<Integer> entityCap = plot.getFlag(Flags.ENTITY_CAP);
if (entityCap != null) { if (entityCap.isPresent()) {
Integer cap = (Integer) entityCap.getValue(); Integer cap = entityCap.get();
if (cap == 0) { if (cap == 0) {
return false; return false;
} }
@ -356,8 +355,8 @@ public class MainListener {
if (plot.isAdded(pp.getUUID()) || Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER)) { if (plot.isAdded(pp.getUUID()) || Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER)) {
return; return;
} else { } else {
Flag flag = FlagManager.getPlotFlagRaw(plot, "use"); com.google.common.base.Optional<HashSet<PlotBlock>> flag = plot.getFlag(Flags.USE);
if (flag != null && ((HashSet<PlotBlock>) flag.getValue()).contains(SpongeUtil.getPlotBlock(l.getBlock()))) { if (flag.isPresent() && flag.get().contains(SpongeUtil.getPlotBlock(l.getBlock()))) {
return; return;
} }
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_INTERACT_OTHER); MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_INTERACT_OTHER);
@ -396,22 +395,12 @@ public class MainListener {
return; return;
} }
} }
if (!FlagManager.isPlotFlagTrue(currentPlot, "explosion")) { if (!currentPlot.getFlag(Flags.EXPLOSION).or(false)) {
event.filterAll(); event.filterAll();
return; return;
} }
event.filter(new Predicate<org.spongepowered.api.world.Location<World>>() { event.filter(loc -> currentPlot.equals(SpongeUtil.getLocation(loc.getExtent().getName(), loc).getPlot()));
@Override event.filterEntities(entity -> currentPlot.equals(SpongeUtil.getLocation(entity).getPlot()));
public boolean test(org.spongepowered.api.world.Location<World> loc) {
return currentPlot.equals(SpongeUtil.getLocation(loc.getExtent().getName(), loc).getPlot());
}
});
event.filterEntities(new Predicate<Entity>() {
@Override
public boolean test(Entity entity) {
return currentPlot.equals(SpongeUtil.getLocation(entity).getPlot());
}
});
} }
} }
@ -432,12 +421,7 @@ public class MainListener {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
event.filter(new Predicate<org.spongepowered.api.world.Location<World>>() { event.filter(loc1 -> !SpongeUtil.getLocation(worldName, loc1).isPlotRoad());
@Override
public boolean test(org.spongepowered.api.world.Location<World> loc) {
return !SpongeUtil.getLocation(worldName, loc).isPlotRoad();
}
});
} }
@Listener @Listener
@ -494,9 +478,9 @@ public class MainListener {
return; return;
} else { } else {
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_DESTROY_OTHER); MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_DESTROY_OTHER);
Flag destroy = FlagManager.getPlotFlagRaw(plot, "break"); com.google.common.base.Optional<HashSet<PlotBlock>> destroy = plot.getFlag(Flags.BREAK);
BlockState state = pos.getState(); BlockState state = pos.getState();
if (destroy == null || !((HashSet<PlotBlock>) destroy.getValue()).contains(SpongeUtil.getPlotBlock(state))) { if (!destroy.isPresent() || !destroy.get().contains(SpongeUtil.getPlotBlock(state))) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
@ -524,9 +508,9 @@ public class MainListener {
if (plot.isAdded(pp.getUUID()) || Permissions.hasPermission(pp, C.PERMISSION_ADMIN_DESTROY_OTHER)) { if (plot.isAdded(pp.getUUID()) || Permissions.hasPermission(pp, C.PERMISSION_ADMIN_DESTROY_OTHER)) {
return true; return true;
} else { } else {
Flag destroy = FlagManager.getPlotFlagRaw(plot, "break"); com.google.common.base.Optional<HashSet<PlotBlock>> destroy = plot.getFlag(Flags.BREAK);
BlockState state = l.getBlock(); BlockState state = l.getBlock();
if (destroy != null && ((HashSet<PlotBlock>) destroy.getValue()).contains(SpongeUtil.getPlotBlock(state))) { if (destroy.isPresent() && destroy.get().contains(SpongeUtil.getPlotBlock(state))) {
return true; return true;
} }
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_DESTROY_OTHER); MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_DESTROY_OTHER);
@ -563,7 +547,19 @@ public class MainListener {
return; return;
} }
} else if (transactions.size() == 1) { } else if (transactions.size() == 1) {
if (!plot.hasOwner()) { if (plot.hasOwner()) {
if (plot.isAdded(pp.getUUID()) || Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER)) {
return;
} else {
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_OTHER);
com.google.common.base.Optional<HashSet<PlotBlock>> BUILD = plot.getFlag(Flags.PLACE);
BlockState state = pos.getState();
if (!BUILD.isPresent() || !BUILD.get().contains(SpongeUtil.getPlotBlock(state))) {
event.setCancelled(true);
return;
}
}
} else {
if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_UNOWNED)) { if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_UNOWNED)) {
return; return;
} }
@ -571,17 +567,6 @@ public class MainListener {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
if (plot.isAdded(pp.getUUID()) || Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER)) {
return;
} else {
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_OTHER);
Flag BUILD = FlagManager.getPlotFlagRaw(plot, C.FLAG_PLACE.s());
BlockState state = pos.getState();
if (BUILD == null || !((HashSet<PlotBlock>) BUILD.getValue()).contains(SpongeUtil.getPlotBlock(state))) {
event.setCancelled(true);
return;
}
}
} }
event.filter(new Predicate<org.spongepowered.api.world.Location<World>>() { event.filter(new Predicate<org.spongepowered.api.world.Location<World>>() {
@ -605,9 +590,9 @@ public class MainListener {
if (plot.isAdded(pp.getUUID()) || Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER)) { if (plot.isAdded(pp.getUUID()) || Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER)) {
return true; return true;
} else { } else {
Flag build = FlagManager.getPlotFlagRaw(plot, C.FLAG_PLACE.s()); com.google.common.base.Optional<HashSet<PlotBlock>> build = plot.getFlag(Flags.PLACE);
BlockState state = l.getBlock(); BlockState state = l.getBlock();
if (build != null && ((HashSet<PlotBlock>) build.getValue()).contains(SpongeUtil.getPlotBlock(state))) { if (build.isPresent() && build.get().contains(SpongeUtil.getPlotBlock(state))) {
return true; return true;
} }
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_OTHER); MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_OTHER);

View File

@ -22,7 +22,7 @@ public class SpongeChatManager extends ChatManager<Text.Builder> {
} }
@Override @Override
public void color(PlotMessage m, String color) { public void color(PlotMessage message, String color) {
TextColor tc = null; TextColor tc = null;
TextStyle ts = null; TextStyle ts = null;
switch (color.charAt(1)) { switch (color.charAt(1)) {
@ -94,10 +94,10 @@ public class SpongeChatManager extends ChatManager<Text.Builder> {
break; break;
} }
if (tc != null) { if (tc != null) {
apply(m, getChild(m).color(tc)); apply(message, getChild(message).color(tc));
} }
if (ts != null) { if (ts != null) {
apply(m, getChild(m).style(ts)); apply(message, getChild(message).style(ts));
} }
} }
@ -114,7 +114,7 @@ public class SpongeChatManager extends ChatManager<Text.Builder> {
} }
@Override @Override
public void tooltip(PlotMessage m, PlotMessage... tooltips) { public void tooltip(PlotMessage message, PlotMessage... tooltips) {
Text.Builder builder = Text.builder(); Text.Builder builder = Text.builder();
boolean lb = false; boolean lb = false;
for (PlotMessage tooltip : tooltips) { for (PlotMessage tooltip : tooltips) {
@ -124,30 +124,30 @@ public class SpongeChatManager extends ChatManager<Text.Builder> {
builder.append(tooltip.$(this).build()); builder.append(tooltip.$(this).build());
lb = true; lb = true;
} }
apply(m, getChild(m).onHover(TextActions.showText(builder.toText()))); apply(message, getChild(message).onHover(TextActions.showText(builder.toText())));
} }
@Override @Override
public void command(PlotMessage m, String command) { public void command(PlotMessage message, String command) {
apply(m, getChild(m).onClick(TextActions.runCommand(command))); apply(message, getChild(message).onClick(TextActions.runCommand(command)));
} }
@Override @Override
public void text(PlotMessage m, String text) { public void text(PlotMessage message, String text) {
m.$(this).append(SpongeUtil.getText(text)); message.$(this).append(SpongeUtil.getText(text));
} }
@Override @Override
public void send(PlotMessage m, PlotPlayer player) { public void send(PlotMessage plotMessage, PlotPlayer player) {
if (player instanceof ConsolePlayer) { if (player instanceof ConsolePlayer) {
player.sendMessage(m.$(this).build().toPlain()); player.sendMessage(plotMessage.$(this).build().toPlain());
} else { } else {
((SpongePlayer) player).player.sendMessage(m.$(this).build()); ((SpongePlayer) player).player.sendMessage(plotMessage.$(this).build());
} }
} }
@Override @Override
public void suggest(PlotMessage m, String command) { public void suggest(PlotMessage plotMessage, String command) {
apply(m, getChild(m).onClick(TextActions.suggestCommand(command))); apply(plotMessage, getChild(plotMessage).onClick(TextActions.suggestCommand(command)));
} }
} }

View File

@ -69,7 +69,7 @@ public class SpongeEventUtil extends EventUtil {
} }
@Override @Override
public boolean callFlagRemove(Flag flag, Plot plot) { public boolean callFlagRemove(Flag<?> flag, Plot plot, Object value) {
return callEvent(new PlotFlagRemoveEvent(flag, plot)); return callEvent(new PlotFlagRemoveEvent(flag, plot));
} }
@ -109,7 +109,7 @@ public class SpongeEventUtil extends EventUtil {
} }
@Override @Override
public boolean callFlagRemove(Flag flag, PlotCluster cluster) { public boolean callFlagRemove(Flag flag, Object object, PlotCluster cluster) {
return callEvent(new ClusterFlagRemoveEvent(flag, cluster)); return callEvent(new ClusterFlagRemoveEvent(flag, cluster));
} }