mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-25 22:56:45 +01:00
Start implementing new Flag system.
This commit is contained in:
parent
d3dd88eb8d
commit
aaf9511673
@ -385,18 +385,6 @@ public class PlotAPI {
|
||||
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.
|
||||
*
|
||||
@ -663,7 +651,7 @@ public class PlotAPI {
|
||||
if (world == null) {
|
||||
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) {
|
||||
PlotPlayer pp = BukkitUtil.getPlayer(player);
|
||||
PlotPlayer pp = PlotPlayer.wrap(player);
|
||||
return pp.getAllowedPlots();
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,6 @@ import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.ConfigurationNode;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
import com.intellectualcrafters.plot.generator.GeneratorWrapper;
|
||||
import com.intellectualcrafters.plot.generator.HybridGen;
|
||||
import com.intellectualcrafters.plot.generator.HybridUtils;
|
||||
@ -95,7 +94,7 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
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;
|
||||
|
||||
@ -195,14 +194,18 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
|
||||
public void run() {
|
||||
PS.get().foreachPlotArea(new RunnableVal<PlotArea>() {
|
||||
@Override
|
||||
public void run(PlotArea pw) {
|
||||
World world = Bukkit.getWorld(pw.worldname);
|
||||
public void run(PlotArea plotArea) {
|
||||
World world = Bukkit.getWorld(plotArea.worldname);
|
||||
try {
|
||||
if (world == null) {
|
||||
return;
|
||||
}
|
||||
List<Entity> entities = world.getEntities();
|
||||
Iterator<Entity> iterator = entities.iterator();
|
||||
for (Entity entity : entities) {
|
||||
|
||||
}
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
Entity entity = iterator.next();
|
||||
switch (entity.getType()) {
|
||||
@ -211,6 +214,7 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
|
||||
case COMPLEX_PART:
|
||||
case FISHING_HOOK:
|
||||
case ENDER_SIGNAL:
|
||||
case LINGERING_POTION:
|
||||
case AREA_EFFECT_CLOUD:
|
||||
case EXPERIENCE_ORB:
|
||||
case LEASH_HITCH:
|
||||
@ -507,7 +511,6 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
|
||||
if (!checkVersion) {
|
||||
log(C.PREFIX + " &c[WARN] Titles are disabled - please update your version of Bukkit to support this feature.");
|
||||
Settings.TITLES = false;
|
||||
FlagManager.removeFlag(FlagManager.getFlag("titles"));
|
||||
} else {
|
||||
AbstractTitle.TITLE_CLASS = new DefaultTitle_19();
|
||||
if (wrapper instanceof DefaultUUIDWrapper || wrapper.getClass() == OfflineUUIDWrapper.class && !Bukkit.getOnlineMode()) {
|
||||
|
@ -5,8 +5,6 @@ import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
@ -21,15 +19,6 @@ abstract class APlotMeConnector {
|
||||
|
||||
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) {
|
||||
return connection != null;
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
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.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
@ -36,7 +37,13 @@ public class ForceFieldListener implements Listener {
|
||||
private PlotPlayer hasNearbyPermitted(Player player, Plot plot) {
|
||||
for (Entity entity : player.getNearbyEntities(5d, 5d, 5d)) {
|
||||
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;
|
||||
}
|
||||
if (plot.isAdded(pp.getUUID())) {
|
||||
@ -84,8 +91,9 @@ public class ForceFieldListener implements Listener {
|
||||
if (plot == null) {
|
||||
return;
|
||||
}
|
||||
if ((FlagManager.getPlotFlagRaw(plot, "forcefield") != null) && FlagManager.getPlotFlagRaw(plot, "forcefield").getValue().equals("true")) {
|
||||
if (!FlagManager.isBooleanFlag(plot, "forcefield", false)) {
|
||||
Optional<Boolean> forcefield = plot.getFlag(Flags.FORCEFIELD);
|
||||
if (forcefield.isPresent() && forcefield.get()) {
|
||||
if (!plot.getFlag(Flags.FORCEFIELD).or(false)) {
|
||||
UUID uuid = pp.getUUID();
|
||||
if (plot.isAdded(uuid)) {
|
||||
Set<PlotPlayer> players = getNearbyPlayers(player, plot);
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,7 +1,7 @@
|
||||
package com.plotsquared.bukkit.listeners;
|
||||
|
||||
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.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotArea;
|
||||
@ -35,7 +35,7 @@ public class PlayerEvents183 implements Listener {
|
||||
return;
|
||||
}
|
||||
Plot plot = area.getOwnedPlot(loc);
|
||||
if (plot == null || !FlagManager.isPlotFlagTrue(plot, "explosion")) {
|
||||
if (plot == null || !plot.getFlag(Flags.EXPLOSION).or(false)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
Iterator<Block> iterator = event.blockList().iterator();
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.plotsquared.bukkit.listeners;
|
||||
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
import com.google.common.base.Optional;
|
||||
import com.intellectualcrafters.plot.flag.Flags;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.plotsquared.bukkit.events.PlayerEnterPlotEvent;
|
||||
@ -88,7 +88,7 @@ public class PlotPlusListener extends PlotListener implements Listener {
|
||||
if (plot == null) {
|
||||
return;
|
||||
}
|
||||
if (FlagManager.isBooleanFlag(plot, "instabreak", false)) {
|
||||
if (plot.getFlag(Flags.INSTABREAK).or(false)) {
|
||||
event.getBlock().breakNaturally();
|
||||
}
|
||||
}
|
||||
@ -103,7 +103,7 @@ public class PlotPlusListener extends PlotListener implements Listener {
|
||||
if (plot == null) {
|
||||
return;
|
||||
}
|
||||
if (FlagManager.isBooleanFlag(plot, "invincible", false)) {
|
||||
if (plot.getFlag(Flags.INVINCIBLE).or(false)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
@ -117,7 +117,7 @@ public class PlotPlusListener extends PlotListener implements Listener {
|
||||
return;
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
@ -131,7 +131,7 @@ public class PlotPlusListener extends PlotListener implements Listener {
|
||||
return;
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
@ -140,14 +140,14 @@ public class PlotPlusListener extends PlotListener implements Listener {
|
||||
public void onPlotEnter(PlayerEnterPlotEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
Plot plot = event.getPlot();
|
||||
Flag feed = FlagManager.getPlotFlagRaw(plot, "feed");
|
||||
if (feed != null) {
|
||||
Integer[] value = (Integer[]) feed.getValue();
|
||||
Optional<Integer[]> feed = plot.getFlag(Flags.FEED);
|
||||
if (feed.isPresent()) {
|
||||
Integer[] value = feed.get();
|
||||
feedRunnable.put(player.getName(), new Interval(value[0], value[1], 20));
|
||||
}
|
||||
Flag heal = FlagManager.getPlotFlagRaw(plot, "heal");
|
||||
if (heal != null) {
|
||||
Integer[] value = (Integer[]) heal.getValue();
|
||||
Optional<Integer[]> heal = plot.getFlag(Flags.HEAL);
|
||||
if (heal.isPresent()) {
|
||||
Integer[] value = heal.get();
|
||||
healRunnable.put(player.getName(), new Interval(value[0], value[1], 20));
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class DefaultTitleManager extends TitleManager {
|
||||
@ -23,18 +22,6 @@ public class DefaultTitleManager extends TitleManager {
|
||||
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.
|
||||
*/
|
||||
@ -90,7 +77,8 @@ public class DefaultTitleManager extends TitleManager {
|
||||
* @param player Player
|
||||
* @throws Exception
|
||||
*/
|
||||
@Override public void clearTitle(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);
|
||||
@ -106,7 +94,8 @@ public class DefaultTitleManager extends TitleManager {
|
||||
* @param player Player
|
||||
* @throws Exception
|
||||
*/
|
||||
@Override public void resetTitle(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);
|
||||
@ -116,27 +105,7 @@ public class DefaultTitleManager extends TitleManager {
|
||||
sendPacket.invoke(connection, packet);
|
||||
}
|
||||
|
||||
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) {
|
||||
Field getField(Class<?> clazz, String name) {
|
||||
try {
|
||||
Field field = clazz.getDeclaredField(name);
|
||||
field.setAccessible(true);
|
||||
@ -157,7 +126,7 @@ public class DefaultTitleManager extends TitleManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean ClassListEqual(Class<?>[] l1, Class<?>[] l2) {
|
||||
boolean ClassListEqual(Class<?>[] l1, Class<?>[] l2) {
|
||||
if (l1.length != l2.length) {
|
||||
return false;
|
||||
}
|
||||
|
@ -4,10 +4,9 @@ import com.plotsquared.bukkit.chat.Reflection;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class DefaultTitleManager_183 extends TitleManager {
|
||||
public class DefaultTitleManager_183 extends DefaultTitleManager {
|
||||
|
||||
/**
|
||||
* Create a new 1.8 title.
|
||||
@ -22,18 +21,6 @@ public class DefaultTitleManager_183 extends TitleManager {
|
||||
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.
|
||||
*/
|
||||
@ -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) {
|
||||
for (Method m : clazz.getMethods()) {
|
||||
if (m.getName().equals(name) && ((args.length == 0) || ClassListEqual(args, m.getParameterTypes()))) {
|
||||
@ -157,17 +79,4 @@ public class DefaultTitleManager_183 extends TitleManager {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class HackTitleManager extends TitleManager {
|
||||
@ -24,18 +23,6 @@ public class HackTitleManager extends TitleManager {
|
||||
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.
|
||||
*/
|
||||
@ -171,26 +158,6 @@ public class HackTitleManager extends TitleManager {
|
||||
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) {
|
||||
try {
|
||||
Field field = clazz.getDeclaredField(name);
|
||||
@ -225,4 +192,5 @@ public class HackTitleManager extends TitleManager {
|
||||
}
|
||||
return equal;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,6 +4,8 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@ -201,4 +203,36 @@ public abstract class TitleManager {
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -20,41 +20,41 @@ public class BukkitChatManager extends ChatManager<FancyMessage> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void color(PlotMessage m, String color) {
|
||||
m.$(this).color(ChatColor.getByChar(C.color(color).substring(1)));
|
||||
public void color(PlotMessage message, String color) {
|
||||
message.$(this).color(ChatColor.getByChar(C.color(color).substring(1)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tooltip(PlotMessage m, PlotMessage... tooltips) {
|
||||
public void tooltip(PlotMessage message, PlotMessage... tooltips) {
|
||||
List<FancyMessage> lines = new ArrayList<>();
|
||||
for (PlotMessage tooltip : tooltips) {
|
||||
lines.add(tooltip.$(this));
|
||||
}
|
||||
m.$(this).formattedTooltip(lines);
|
||||
message.$(this).formattedTooltip(lines);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void command(PlotMessage m, String command) {
|
||||
m.$(this).command(command);
|
||||
public void command(PlotMessage message, String command) {
|
||||
message.$(this).command(command);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void text(PlotMessage m, String text) {
|
||||
m.$(this).then(ChatColor.stripColor(text));
|
||||
public void text(PlotMessage message, String text) {
|
||||
message.$(this).then(ChatColor.stripColor(text));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(PlotMessage m, PlotPlayer player) {
|
||||
public void send(PlotMessage plotMessage, PlotPlayer player) {
|
||||
if (player instanceof ConsolePlayer) {
|
||||
player.sendMessage(m.$(this).toOldMessageFormat());
|
||||
player.sendMessage(plotMessage.$(this).toOldMessageFormat());
|
||||
} else {
|
||||
m.$(this).send(((BukkitPlayer) player).player);
|
||||
plotMessage.$(this).send(((BukkitPlayer) player).player);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void suggest(PlotMessage m, String command) {
|
||||
m.$(this).suggest(command);
|
||||
public void suggest(PlotMessage plotMessage, String command) {
|
||||
plotMessage.$(this).suggest(command);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ public class BukkitEventUtil extends EventUtil {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean callFlagRemove(Flag flag, Plot plot) {
|
||||
public boolean callFlagRemove(Flag<?> flag, Plot plot, Object value) {
|
||||
return callEvent(new PlotFlagRemoveEvent(flag, plot));
|
||||
}
|
||||
|
||||
@ -113,7 +113,7 @@ public class BukkitEventUtil extends EventUtil {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean callFlagRemove(Flag flag, PlotCluster cluster) {
|
||||
public boolean callFlagRemove(Flag flag, Object object, PlotCluster cluster) {
|
||||
return callEvent(new ClusterFlagRemoveEvent(flag, cluster));
|
||||
}
|
||||
|
||||
|
@ -16,35 +16,35 @@ public class BukkitPlainChatManager extends ChatManager<List<StringBuilder>> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void color(PlotMessage m, String color) {
|
||||
List<StringBuilder> parts = m.$(this);
|
||||
public void color(PlotMessage message, String color) {
|
||||
List<StringBuilder> parts = message.$(this);
|
||||
parts.get(parts.size() - 1).insert(0, color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tooltip(PlotMessage m, PlotMessage... tooltips) {
|
||||
public void tooltip(PlotMessage message, PlotMessage... tooltips) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void command(PlotMessage m, String command) {
|
||||
public void command(PlotMessage message, String command) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void text(PlotMessage m, String text) {
|
||||
m.$(this).add(new StringBuilder(ChatColor.stripColor(text)));
|
||||
public void text(PlotMessage message, String text) {
|
||||
message.$(this).add(new StringBuilder(ChatColor.stripColor(text)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(PlotMessage m, PlotPlayer player) {
|
||||
public void send(PlotMessage plotMessage, PlotPlayer player) {
|
||||
StringBuilder built = new StringBuilder();
|
||||
for (StringBuilder sb : m.$(this)) {
|
||||
for (StringBuilder sb : plotMessage.$(this)) {
|
||||
built.append(sb);
|
||||
}
|
||||
player.sendMessage(built.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void suggest(PlotMessage m, String command) {
|
||||
public void suggest(PlotMessage plotMessage, String command) {
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -7,5 +7,5 @@ dependencies {
|
||||
sourceCompatibility = 1.7
|
||||
targetCompatibility = 1.7
|
||||
|
||||
jar.archiveName="PlotSquared-API-${parent.version}.jar"
|
||||
jar.archiveName = "PlotSquared-Core-${parent.version}.jar"
|
||||
jar.destinationDir = file '../target'
|
@ -1830,8 +1830,8 @@ public class PS {
|
||||
for (String flag : intFlags) {
|
||||
FlagManager.addFlag(new AbstractFlag(flag, new FlagValue.UnsignedIntegerValue()));
|
||||
}
|
||||
FlagManager.addFlag(new AbstractFlag("done", new FlagValue.StringValue()), true);
|
||||
FlagManager.addFlag(new AbstractFlag("analysis", new FlagValue.IntegerListValue()), true);
|
||||
FlagManager.addFlag(new AbstractFlag("done", new FlagValue.StringValue()));
|
||||
FlagManager.addFlag(new AbstractFlag("analysis", new FlagValue.IntegerListValue()));
|
||||
FlagManager.addFlag(new AbstractFlag("disable-physics", new FlagValue.BooleanValue()));
|
||||
FlagManager.addFlag(new AbstractFlag("fly", new FlagValue.BooleanValue()));
|
||||
FlagManager.addFlag(new AbstractFlag("explosion", new FlagValue.BooleanValue()));
|
||||
@ -1858,6 +1858,10 @@ public class PS {
|
||||
FlagManager.addFlag(new AbstractFlag("use", new FlagValue.PlotBlockListValue()));
|
||||
FlagManager.addFlag(new AbstractFlag("blocked-cmds", new FlagValue.StringListValue()));
|
||||
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-burn", 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") {
|
||||
|
||||
@ -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("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()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,9 +1,9 @@
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
import com.intellectualcrafters.plot.flag.Flags;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
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.UUIDHandler;
|
||||
import com.plotsquared.general.commands.CommandDeclaration;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@CommandDeclaration(
|
||||
@ -59,14 +60,14 @@ public class Buy extends SubCommand {
|
||||
if (currentPlots > plr.getAllowedPlots()) {
|
||||
return sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS);
|
||||
}
|
||||
Flag flag = FlagManager.getPlotFlagRaw(plot, "price");
|
||||
if (flag == null) {
|
||||
Optional<Double> flag = plot.getFlag(Flags.PRICE);
|
||||
if (!flag.isPresent()) {
|
||||
return sendMessage(plr, C.NOT_FOR_SALE);
|
||||
}
|
||||
if (plot.isOwner(plr.getUUID())) {
|
||||
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.getMoney(plr) < price) {
|
||||
return sendMessage(plr, C.CANNOT_AFFORD_PLOT, "" + price);
|
||||
@ -78,7 +79,7 @@ public class Buy extends SubCommand {
|
||||
if (owner != null) {
|
||||
sendMessage(plr, C.PLOT_SOLD, plot.getId() + "", plr.getName(), price + "");
|
||||
}
|
||||
FlagManager.removePlotFlag(plot, "price");
|
||||
plot.removeFlag(Flags.PRICE);
|
||||
}
|
||||
plot.setOwner(plr.getUUID());
|
||||
MainUtil.sendMessage(plr, C.CLAIMED);
|
||||
|
@ -3,6 +3,7 @@ package com.intellectualcrafters.plot.commands;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
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.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
@ -62,7 +63,7 @@ public class Clear extends SubCommand {
|
||||
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
|
||||
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
|
||||
.getPlotCount())))) {
|
||||
MainUtil.sendMessage(plr, C.DONE_ALREADY_DONE);
|
||||
@ -81,11 +82,11 @@ public class Clear extends SubCommand {
|
||||
public void run() {
|
||||
plot.removeRunning();
|
||||
// If the state changes, then mark it as no longer done
|
||||
if (FlagManager.getPlotFlagRaw(plot, "done") != null) {
|
||||
FlagManager.removePlotFlag(plot, "done");
|
||||
if (plot.getFlag(Flags.DONE).isPresent()) {
|
||||
FlagManager.removePlotFlag(plot, Flags.DONE);
|
||||
}
|
||||
if (FlagManager.getPlotFlagRaw(plot, "analysis") != null) {
|
||||
FlagManager.removePlotFlag(plot, "analysis");
|
||||
if (plot.getFlag(Flags.ANALYSIS).isPresent()) {
|
||||
FlagManager.removePlotFlag(plot, Flags.ANALYSIS);
|
||||
}
|
||||
MainUtil.sendMessage(plr, C.CLEARING_DONE, "" + (System.currentTimeMillis() - start));
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
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.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
@ -40,7 +40,7 @@ public class Continue extends SubCommand {
|
||||
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
|
||||
return false;
|
||||
}
|
||||
FlagManager.removePlotFlag(plot, "done");
|
||||
plot.removeFlag(Flags.DONE);
|
||||
MainUtil.sendMessage(plr, C.DONE_REMOVED);
|
||||
return true;
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
import com.intellectualcrafters.plot.generator.HybridUtils;
|
||||
import com.intellectualcrafters.plot.object.ConsolePlayer;
|
||||
@ -211,8 +212,9 @@ public class DebugExec extends SubCommand {
|
||||
}
|
||||
String flag = args[1];
|
||||
for (Plot plot : PS.get().getBasePlots()) {
|
||||
if (FlagManager.getPlotFlagRaw(plot, flag) != null) {
|
||||
FlagManager.removePlotFlag(plot, flag);
|
||||
Flag<?> flag1 = FlagManager.getFlag(flag);
|
||||
if (plot.getFlag(flag1).isPresent()) {
|
||||
FlagManager.removePlotFlag(plot, flag1);
|
||||
}
|
||||
}
|
||||
return MainUtil.sendMessage(player, "Cleared flag: " + flag);
|
||||
|
@ -4,7 +4,6 @@ import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotArea;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
@ -39,17 +38,19 @@ public class DebugFixFlags extends SubCommand {
|
||||
}
|
||||
MainUtil.sendMessage(plr, "&8--- &6Starting task &8 ---");
|
||||
for (Plot plot : area.getPlots()) {
|
||||
HashMap<String, Flag> flags = plot.getFlags();
|
||||
Iterator<Entry<String, Flag>> i = flags.entrySet().iterator();
|
||||
HashMap<Flag<?>, Object> flags = plot.getFlags();
|
||||
Iterator<Entry<Flag<?>, Object>> i = flags.entrySet().iterator();
|
||||
boolean changed = false;
|
||||
while (i.hasNext()) {
|
||||
/*
|
||||
if (FlagManager.getFlag(i.next().getKey()) == null) {
|
||||
changed = true;
|
||||
i.remove();
|
||||
}
|
||||
*/
|
||||
}
|
||||
if (changed) {
|
||||
DBFunc.setFlags(plot, plot.getFlags().values());
|
||||
DBFunc.setFlags(plot, plot.getFlags());
|
||||
}
|
||||
}
|
||||
MainUtil.sendMessage(plr, "&aDone!");
|
||||
|
@ -1,8 +1,8 @@
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
import com.intellectualcrafters.plot.flag.Flags;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
@ -21,12 +21,11 @@ public class Desc extends SetCommand {
|
||||
@Override
|
||||
public boolean set(PlotPlayer plr, Plot plot, String desc) {
|
||||
if (desc.isEmpty()) {
|
||||
plot.removeFlag("description");
|
||||
plot.removeFlag(Flags.DESCRIPTION);
|
||||
MainUtil.sendMessage(plr, C.DESC_UNSET);
|
||||
return true;
|
||||
}
|
||||
Flag flag = new Flag(FlagManager.getFlag("description"), desc);
|
||||
boolean result = FlagManager.addPlotFlag(plot, flag);
|
||||
boolean result = FlagManager.addPlotFlag(plot, Flags.DESCRIPTION, desc);
|
||||
if (!result) {
|
||||
MainUtil.sendMessage(plr, C.FLAG_NOT_ADDED);
|
||||
return false;
|
||||
|
@ -4,6 +4,7 @@ import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
import com.intellectualcrafters.plot.flag.Flags;
|
||||
import com.intellectualcrafters.plot.generator.HybridUtils;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
@ -48,8 +49,9 @@ public class Done extends SubCommand {
|
||||
public void run(PlotAnalysis value) {
|
||||
plot.removeRunning();
|
||||
if ((value == null) || (value.getComplexity() >= Settings.CLEAR_THRESHOLD)) {
|
||||
Flag flag = new Flag(FlagManager.getFlag("done"), System.currentTimeMillis() / 1000);
|
||||
FlagManager.addPlotFlag(plot, flag);
|
||||
long flagValue = System.currentTimeMillis() / 1000;
|
||||
Flag flag = Flags.DONE;
|
||||
FlagManager.addPlotFlag(plot, flag, flagValue);
|
||||
MainUtil.sendMessage(plr, C.DONE_SUCCESS);
|
||||
} else {
|
||||
MainUtil.sendMessage(plr, C.DONE_INSUFFICIENT_COMPLEXITY);
|
||||
|
@ -4,7 +4,7 @@ import com.intellectualcrafters.jnbt.CompoundTag;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
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.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.RunnableVal;
|
||||
@ -41,11 +41,8 @@ public class Download extends SubCommand {
|
||||
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
|
||||
return false;
|
||||
}
|
||||
if ((Settings.DOWNLOAD_REQUIRES_DONE && (FlagManager.getPlotFlagRaw(plot, "done") == null)) && !Permissions.hasPermission(plr, "plots.admin.command.download")) {
|
||||
MainUtil.sendMessage(plr, C.DONE_NOT_DONE);
|
||||
return false;
|
||||
}
|
||||
if ((!plot.isOwner(plr.getUUID()))) {
|
||||
if ((!plot.isOwner(plr.getUUID()) || (Settings.DOWNLOAD_REQUIRES_DONE && plot.getFlag(Flags.DONE).isPresent())) && !Permissions
|
||||
.hasPermission(plr, "plots.admin.command.download")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
|
||||
return false;
|
||||
}
|
||||
|
@ -1,11 +1,12 @@
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.flag.AbstractFlag;
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
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.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
@ -16,6 +17,7 @@ import com.plotsquared.general.commands.CommandDeclaration;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@ -31,7 +33,7 @@ public class FlagCmd extends SubCommand {
|
||||
|
||||
@Override
|
||||
public String getUsage() {
|
||||
return super.getUsage().replaceAll("<flag>", StringMan.join(FlagManager.getFlags(), "|"));
|
||||
return super.getUsage().replaceAll("<flag>", StringMan.join(Flags.getFlags(), "|"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -62,7 +64,7 @@ public class FlagCmd extends SubCommand {
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag.other");
|
||||
return false;
|
||||
}
|
||||
if (args.length > 1 && FlagManager.isReserved(args[1])) {
|
||||
if (args.length > 1 && FlagManager.isReserved(FlagManager.getFlag(args[1]))) {
|
||||
MainUtil.sendMessage(player, C.NOT_VALID_FLAG);
|
||||
return false;
|
||||
}
|
||||
@ -76,18 +78,18 @@ public class FlagCmd extends SubCommand {
|
||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag info <flag>");
|
||||
return false;
|
||||
}
|
||||
AbstractFlag flag = FlagManager.getFlag(args[1]);
|
||||
Flag<?> flag = FlagManager.getFlag(args[1]);
|
||||
if (flag == null) {
|
||||
MainUtil.sendMessage(player, C.NOT_VALID_FLAG);
|
||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag info <flag>");
|
||||
return false;
|
||||
}
|
||||
// flag key
|
||||
MainUtil.sendMessage(player, C.FLAG_KEY, flag.getKey());
|
||||
MainUtil.sendMessage(player, C.FLAG_KEY, flag.getName());
|
||||
// flag type
|
||||
MainUtil.sendMessage(player, C.FLAG_TYPE, flag.value.getClass().getSimpleName());
|
||||
MainUtil.sendMessage(player, C.FLAG_TYPE, flag.getClass().getSimpleName());
|
||||
// Flag type description
|
||||
MainUtil.sendMessage(player, C.FLAG_DESC, flag.getValueDesc());
|
||||
MainUtil.sendMessage(player, C.FLAG_DESC, flag.getValueDescription());
|
||||
return true;
|
||||
}
|
||||
case "set": {
|
||||
@ -99,7 +101,7 @@ public class FlagCmd extends SubCommand {
|
||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag set <flag> <value>");
|
||||
return false;
|
||||
}
|
||||
AbstractFlag af = FlagManager.getFlag(args[1].toLowerCase());
|
||||
Flag<?> af = FlagManager.getFlag(args[1].toLowerCase());
|
||||
if (af == null) {
|
||||
MainUtil.sendMessage(player, C.NOT_VALID_FLAG);
|
||||
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());
|
||||
return false;
|
||||
}
|
||||
Object parsed = af.parseValueRaw(value);
|
||||
Object parsed = af.parseValue(value);
|
||||
if (parsed == null) {
|
||||
MainUtil.sendMessage(player, "&c" + af.getValueDesc());
|
||||
MainUtil.sendMessage(player, "&c" + af.getValueDescription());
|
||||
return false;
|
||||
}
|
||||
Flag flag = new Flag(FlagManager.getFlag(args[1].toLowerCase(), true), parsed);
|
||||
boolean result = FlagManager.addPlotFlag(plot, flag);
|
||||
boolean result = plot.setFlag(af, parsed);
|
||||
if (!result) {
|
||||
MainUtil.sendMessage(player, C.FLAG_NOT_ADDED);
|
||||
return false;
|
||||
@ -124,42 +125,42 @@ public class FlagCmd extends SubCommand {
|
||||
return true;
|
||||
}
|
||||
case "remove": {
|
||||
if (!Permissions.hasPermission(player, "plots.flag.remove")) {
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.flag.remove");
|
||||
if (!Permissions.hasPermission(player, "plots.flagValue.remove")) {
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.flagValue.remove");
|
||||
return false;
|
||||
}
|
||||
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;
|
||||
}
|
||||
AbstractFlag af = FlagManager.getFlag(args[1].toLowerCase());
|
||||
if (af == null) {
|
||||
Flag<?> flag1 = FlagManager.getFlag(args[1].toLowerCase());
|
||||
if (flag1 == null) {
|
||||
MainUtil.sendMessage(player, C.NOT_VALID_FLAG);
|
||||
return false;
|
||||
}
|
||||
Flag flag = FlagManager.getPlotFlagAbs(plot, args[1].toLowerCase());
|
||||
if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase())) {
|
||||
Optional<?> flagValue = plot.getFlag(flag1);
|
||||
if (!Permissions.hasPermission(player, "plots.set.flagValue." + args[1].toLowerCase())) {
|
||||
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;
|
||||
}
|
||||
for (String entry : args[2].split(",")) {
|
||||
if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase() + "." + entry)) {
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION, "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.flagValue." + args[1].toLowerCase() + "." + entry);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (flag == null) {
|
||||
if (flagValue.isPresent()) {
|
||||
MainUtil.sendMessage(player, C.FLAG_NOT_IN_PLOT);
|
||||
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), " ");
|
||||
((FlagValue.ListValue) flag.getAbstractFlag().value).remove(flag.getValue(), value);
|
||||
DBFunc.setFlags(plot, plot.getFlags().values());
|
||||
boolean listFlag = ((Collection) plot.getFlags().get(flag1)).remove(flag1.parseValue(value));
|
||||
DBFunc.setFlags(plot, plot.getFlags());
|
||||
} else {
|
||||
boolean result = FlagManager.removePlotFlag(plot, flag.getKey());
|
||||
boolean result = plot.removeFlag(flag1);
|
||||
if (!result) {
|
||||
MainUtil.sendMessage(player, C.FLAG_NOT_REMOVED);
|
||||
return false;
|
||||
@ -177,7 +178,7 @@ public class FlagCmd extends SubCommand {
|
||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag add <flag> <values>");
|
||||
return false;
|
||||
}
|
||||
AbstractFlag af = FlagManager.getFlag(args[1].toLowerCase());
|
||||
Flag af = FlagManager.getFlag(args[1].toLowerCase());
|
||||
if (af == null) {
|
||||
MainUtil.sendMessage(player, C.NOT_VALID_FLAG);
|
||||
return false;
|
||||
@ -189,18 +190,18 @@ public class FlagCmd extends SubCommand {
|
||||
}
|
||||
}
|
||||
String value = StringMan.join(Arrays.copyOfRange(args, 2, args.length), " ");
|
||||
Object parsed = af.parseValueRaw(value);
|
||||
Object parsed = af.parseValue(value);
|
||||
if (parsed == null) {
|
||||
MainUtil.sendMessage(player, "&c" + af.getValueDesc());
|
||||
MainUtil.sendMessage(player, "&c" + af.getValueDescription());
|
||||
return false;
|
||||
}
|
||||
Flag flag = FlagManager.getPlotFlag(plot, args[1].toLowerCase());
|
||||
if (flag == null || !flag.getAbstractFlag().isList()) {
|
||||
flag = new Flag(FlagManager.getFlag(args[1].toLowerCase(), true), parsed);
|
||||
} else {
|
||||
((FlagValue.ListValue) flag.getAbstractFlag().value).add(flag.getValue(), value);
|
||||
Optional<?> flag = plot.getFlag(af);
|
||||
if (flag.isPresent()) {
|
||||
if (af instanceof ListFlag) {
|
||||
((Collection) flag.get()).addAll((Collection) parsed);
|
||||
}
|
||||
}
|
||||
boolean result = FlagManager.addPlotFlag(plot, flag);
|
||||
boolean result = FlagManager.addPlotFlag(plot, af, parsed);
|
||||
if (!result) {
|
||||
MainUtil.sendMessage(player, C.FLAG_NOT_ADDED);
|
||||
return false;
|
||||
@ -217,12 +218,12 @@ public class FlagCmd extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
HashMap<String, ArrayList<String>> flags = new HashMap<>();
|
||||
for (AbstractFlag flag1 : FlagManager.getFlags()) {
|
||||
String type = flag1.value.getClass().getSimpleName().replaceAll("Value", "");
|
||||
for (Flag flag1 : Flags.getFlags()) {
|
||||
String type = flag1.getClass().getSimpleName().replaceAll("Value", "");
|
||||
if (!flags.containsKey(type)) {
|
||||
flags.put(type, new ArrayList<String>());
|
||||
}
|
||||
flags.get(type).add(flag1.getKey());
|
||||
//todo flags.get(type).add(flag1.getKey());
|
||||
}
|
||||
String message = "";
|
||||
String prefix = "";
|
||||
|
@ -1,10 +1,10 @@
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.PS.SortType;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
import com.intellectualcrafters.plot.flag.Flags;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotArea;
|
||||
import com.intellectualcrafters.plot.object.PlotMessage;
|
||||
@ -176,8 +176,8 @@ public class ListCmd extends SubCommand {
|
||||
}
|
||||
plots = new ArrayList<>();
|
||||
for (Plot plot : PS.get().getPlots()) {
|
||||
Flag flag = plot.getFlags().get("done");
|
||||
if (flag == null) {
|
||||
Optional<String> flag = plot.getFlag(Flags.DONE);
|
||||
if (!flag.isPresent()) {
|
||||
continue;
|
||||
}
|
||||
plots.add(plot);
|
||||
@ -185,8 +185,8 @@ public class ListCmd extends SubCommand {
|
||||
Collections.sort(plots, new Comparator<Plot>() {
|
||||
@Override
|
||||
public int compare(Plot a, Plot b) {
|
||||
String va = a.getFlags().get("done").getValueString();
|
||||
String vb = b.getFlags().get("done").getValueString();
|
||||
String va = (String) a.getFlags().get(Flags.DONE);
|
||||
String vb = (String) b.getFlags().get(Flags.DONE);
|
||||
if (MathMan.isInteger(va)) {
|
||||
if (MathMan.isInteger(vb)) {
|
||||
return Integer.parseInt(vb) - Integer.parseInt(va);
|
||||
@ -245,10 +245,12 @@ public class ListCmd extends SubCommand {
|
||||
}
|
||||
plots = new ArrayList<>();
|
||||
for (Plot plot : PS.get().getPlots()) {
|
||||
/*
|
||||
Flag price = FlagManager.getPlotFlagRaw(plot, "price");
|
||||
if (price != null) {
|
||||
plots.add(plot);
|
||||
}
|
||||
*/
|
||||
}
|
||||
break;
|
||||
case "unowned":
|
||||
|
@ -1,8 +1,7 @@
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
import com.intellectualcrafters.plot.flag.Flags;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotBlock;
|
||||
@ -41,9 +40,9 @@ public class Music extends SubCommand {
|
||||
}
|
||||
int id = item.id == 7 ? 0 : item.id;
|
||||
if (id == 0) {
|
||||
FlagManager.removePlotFlag(plot, "music");
|
||||
plot.removeFlag(Flags.MUSIC);
|
||||
} else {
|
||||
FlagManager.addPlotFlag(plot, new Flag(FlagManager.getFlag("music"), id));
|
||||
plot.setFlag(Flags.MUSIC, id);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package com.intellectualcrafters.plot.commands;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Configuration;
|
||||
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.PlotArea;
|
||||
import com.intellectualcrafters.plot.object.PlotBlock;
|
||||
@ -166,7 +166,7 @@ public class Set extends SubCommand {
|
||||
} catch (Exception e) {
|
||||
af = new AbstractFlag("");
|
||||
}
|
||||
if (FlagManager.getFlags().contains(af)) {
|
||||
if (Flags.getFlags().contains(af)) {
|
||||
StringBuilder a = new StringBuilder();
|
||||
if (args.length > 1) {
|
||||
for (int x = 1; x < args.length; x++) {
|
||||
|
@ -9,7 +9,6 @@ import com.intellectualcrafters.plot.object.RunnableVal;
|
||||
import com.intellectualcrafters.plot.object.comment.PlotComment;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -139,10 +138,10 @@ public interface AbstractDB {
|
||||
|
||||
/**
|
||||
* Set plot flags.
|
||||
* @param plot Plot Object
|
||||
* @param plot Plot Object
|
||||
* @param flags flags to set (flag[])
|
||||
*/
|
||||
void setFlags(Plot plot, Collection<Flag> flags);
|
||||
void setFlags(Plot plot, HashMap<Flag<?>, Object> flags);
|
||||
|
||||
/**
|
||||
* Set cluster flags.
|
||||
@ -150,7 +149,7 @@ public interface AbstractDB {
|
||||
* @param cluster PlotCluster Object
|
||||
* @param flags flags to set (flag[])
|
||||
*/
|
||||
void setFlags(PlotCluster cluster, Collection<Flag> flags);
|
||||
void setFlags(PlotCluster cluster, HashMap<Flag<?>, Object> flags);
|
||||
|
||||
/**
|
||||
* Rename a cluster.
|
||||
|
@ -12,7 +12,6 @@ import java.sql.ResultSet;
|
||||
import java.sql.ResultSetMetaData;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@ -244,14 +243,14 @@ public class DBFunc {
|
||||
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) {
|
||||
return;
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,6 @@ import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
@ -790,31 +789,32 @@ public class SQLManager implements AbstractDB {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMySQL(PreparedStatement stmt, int i, SettingsPair pair) throws SQLException {
|
||||
stmt.setInt(i * 10 + 1, pair.id); // id
|
||||
stmt.setNull(i * 10 + 2, 4); // biome
|
||||
stmt.setNull(i * 10 + 3, 4); // rain
|
||||
stmt.setNull(i * 10 + 4, 4); // custom_time
|
||||
stmt.setNull(i * 10 + 5, 4); // time
|
||||
stmt.setNull(i * 10 + 6, 4); // deny_entry
|
||||
public void setMySQL(PreparedStatement statement, int i, SettingsPair pair) throws SQLException {
|
||||
statement.setInt(i * 10 + 1, pair.id); // id
|
||||
statement.setNull(i * 10 + 2, 4); // biome
|
||||
statement.setNull(i * 10 + 3, 4); // rain
|
||||
statement.setNull(i * 10 + 4, 4); // custom_time
|
||||
statement.setNull(i * 10 + 5, 4); // time
|
||||
statement.setNull(i * 10 + 6, 4); // deny_entry
|
||||
if (pair.settings.getAlias().isEmpty()) {
|
||||
stmt.setNull(i * 10 + 7, 4);
|
||||
statement.setNull(i * 10 + 7, 4);
|
||||
} else {
|
||||
stmt.setString(i * 10 + 7, pair.settings.getAlias());
|
||||
statement.setString(i * 10 + 7, pair.settings.getAlias());
|
||||
}
|
||||
StringBuilder flag_string = new StringBuilder();
|
||||
int k = 0;
|
||||
for (Flag flag : pair.settings.flags.values()) {
|
||||
for (Entry<Flag<?>, ?> flag : pair.settings.flags.entrySet()) {
|
||||
if (k != 0) {
|
||||
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++;
|
||||
}
|
||||
stmt.setString(i * 10 + 8, flag_string.toString());
|
||||
statement.setString(i * 10 + 8, flag_string.toString());
|
||||
boolean[] merged = pair.settings.getMerged();
|
||||
int hash = MainUtil.hash(merged);
|
||||
stmt.setInt(i * 10 + 9, hash);
|
||||
statement.setInt(i * 10 + 9, hash);
|
||||
BlockLoc loc = pair.settings.getPosition();
|
||||
String position;
|
||||
if (loc.y == 0) {
|
||||
@ -822,7 +822,7 @@ public class SQLManager implements AbstractDB {
|
||||
} else {
|
||||
position = loc.x + "," + loc.y + "," + loc.z;
|
||||
}
|
||||
stmt.setString(i * 10 + 10, position);
|
||||
statement.setString(i * 10 + 10, position);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -840,11 +840,12 @@ public class SQLManager implements AbstractDB {
|
||||
}
|
||||
StringBuilder flag_string = new StringBuilder();
|
||||
int k = 0;
|
||||
for (Flag flag : pair.settings.flags.values()) {
|
||||
for (Entry<Flag<?>, ?> flag : pair.settings.flags.entrySet()) {
|
||||
if (k != 0) {
|
||||
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++;
|
||||
}
|
||||
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");
|
||||
}
|
||||
|
||||
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<>();
|
||||
while (r.next()) {
|
||||
id = r.getInt("plot_plot_id");
|
||||
while (resultSet.next()) {
|
||||
id = resultSet.getInt("plot_plot_id");
|
||||
Plot plot = plots.get(id);
|
||||
if (plot != null) {
|
||||
plots.remove(id);
|
||||
String alias = r.getString("alias");
|
||||
String alias = resultSet.getString("alias");
|
||||
if (alias != null) {
|
||||
plot.getSettings().setAlias(alias);
|
||||
}
|
||||
String pos = r.getString("position");
|
||||
String pos = resultSet.getString("position");
|
||||
switch (pos.toLowerCase()) {
|
||||
case "":
|
||||
case "default":
|
||||
@ -1808,14 +1809,14 @@ public class SQLManager implements AbstractDB {
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
Integer m = r.getInt("merged");
|
||||
Integer m = resultSet.getInt("merged");
|
||||
boolean[] merged = new boolean[4];
|
||||
for (int i = 0; i < 4; i++) {
|
||||
merged[3 - i] = (m & 1 << i) != 0;
|
||||
}
|
||||
plot.getSettings().setMerged(merged);
|
||||
String[] flags_string;
|
||||
String myflags = r.getString("flags");
|
||||
String myflags = resultSet.getString("flags");
|
||||
if (myflags == null) {
|
||||
flags_string = new String[] {};
|
||||
} else {
|
||||
@ -1825,15 +1826,15 @@ public class SQLManager implements AbstractDB {
|
||||
flags_string = new String[] {};
|
||||
}
|
||||
}
|
||||
HashMap<String, Flag> flags = new HashMap<>();
|
||||
HashMap<Flag<?>, Object> flags = new HashMap<>();
|
||||
boolean exception = false;
|
||||
for (String element : flags_string) {
|
||||
if (element.contains(":")) {
|
||||
String[] split = element.split(":");
|
||||
try {
|
||||
String flag_str = split[1].replaceAll("\u00AF", ":").replaceAll("\u00B4", ",");
|
||||
Flag flag = new Flag(FlagManager.getFlag(split[0], true), flag_str);
|
||||
flags.put(flag.getKey(), flag);
|
||||
Flag<?> flag = FlagManager.getFlag(split[0]);
|
||||
flags.put(flag, flag_str);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
exception = true;
|
||||
@ -1841,8 +1842,8 @@ public class SQLManager implements AbstractDB {
|
||||
} else {
|
||||
element = element.replaceAll("\u00AF", ":").replaceAll("\u00B4", ",");
|
||||
if (StringMan.isAlpha(element.replaceAll("_", "").replaceAll("-", ""))) {
|
||||
Flag flag = new Flag(FlagManager.getFlag(element, true), "");
|
||||
flags.put(flag.getKey(), flag);
|
||||
Flag flag = FlagManager.getFlag(element);
|
||||
flags.put(flag, "");
|
||||
} else {
|
||||
PS.debug("INVALID FLAG: " + element);
|
||||
}
|
||||
@ -1851,7 +1852,7 @@ public class SQLManager implements AbstractDB {
|
||||
if (exception) {
|
||||
PS.debug("&cPlot " + id + " | " + plot + " had an invalid flag. A fix has been attempted.");
|
||||
PS.debug("&c" + myflags);
|
||||
this.setFlags(plot, flags.values());
|
||||
this.setFlags(plot, flags);
|
||||
}
|
||||
plot.getSettings().flags = flags;
|
||||
} else if (Settings.AUTO_PURGE) {
|
||||
@ -1962,8 +1963,8 @@ public class SQLManager implements AbstractDB {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFlags(final Plot plot, Collection<Flag> flags) {
|
||||
final String flag_string = FlagManager.toString(flags);
|
||||
public void setFlags(final Plot plot, HashMap<Flag<?>, Object> flags) {
|
||||
final String flag_string = FlagManager.toString(flags); //todo MattBDev: Fix this for flags to work.
|
||||
addPlotTask(plot, new UniqueStatement("setFlags") {
|
||||
@Override
|
||||
public void set(PreparedStatement stmt) throws SQLException {
|
||||
@ -2641,22 +2642,22 @@ public class SQLManager implements AbstractDB {
|
||||
flags_string = new String[] {};
|
||||
}
|
||||
}
|
||||
HashMap<String, Flag> flags = new HashMap<>();
|
||||
HashMap<Flag<?>, Object> flags = new HashMap<>();
|
||||
boolean exception = false;
|
||||
for (String element : flags_string) {
|
||||
if (element.contains(":")) {
|
||||
String[] split = element.split(":");
|
||||
try {
|
||||
String flag_str = split[1].replaceAll("\u00AF", ":").replaceAll("<EFBFBD>", ",");
|
||||
Flag flag = new Flag(FlagManager.getFlag(split[0], true), flag_str);
|
||||
flags.put(flag.getKey(), flag);
|
||||
Flag flag = FlagManager.getFlag(split[0]);
|
||||
flags.put(flag, flag_str);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
exception = true;
|
||||
}
|
||||
} else {
|
||||
Flag flag = new Flag(FlagManager.getFlag(element, true), "");
|
||||
flags.put(flag.getKey(), flag);
|
||||
Flag flag = FlagManager.getFlag(element);
|
||||
flags.put(flag, "");
|
||||
}
|
||||
}
|
||||
if (exception) {
|
||||
@ -2687,14 +2688,15 @@ public class SQLManager implements AbstractDB {
|
||||
}
|
||||
|
||||
@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();
|
||||
int i = 0;
|
||||
for (Flag flag : flags) {
|
||||
for (Entry<Flag<?>, Object> flag : flags.entrySet()) {
|
||||
if (i != 0) {
|
||||
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++;
|
||||
}
|
||||
addClusterTask(cluster, new UniqueStatement("setFlags") {
|
||||
@ -3019,12 +3021,12 @@ public class SQLManager implements AbstractDB {
|
||||
PS.debug("&8 - &7Correcting merge for: " + plot);
|
||||
setMerged(dataPlot, plot.getMerged());
|
||||
}
|
||||
HashMap<String, Flag> pf = plot.getFlags();
|
||||
HashMap<String, Flag> df = dataPlot.getFlags();
|
||||
HashMap<Flag<?>, Object> pf = plot.getFlags();
|
||||
HashMap<Flag<?>, Object> df = dataPlot.getFlags();
|
||||
if (!pf.isEmpty() && !df.isEmpty()) {
|
||||
if (pf.size() != df.size() || !StringMan.isEqual(StringMan.joinOrdered(pf.values(), ","), StringMan.joinOrdered(df.values(), ","))) {
|
||||
PS.debug("&8 - &7Correcting flags for: " + plot);
|
||||
setFlags(plot, pf.values());
|
||||
setFlags(plot, pf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +1,14 @@
|
||||
package com.intellectualcrafters.plot.flag;
|
||||
|
||||
import com.intellectualcrafters.plot.util.StringMan;
|
||||
|
||||
/**
|
||||
* Created 2014-09-23 for PlotSquared
|
||||
*
|
||||
|
||||
|
||||
*/
|
||||
public class AbstractFlag {
|
||||
public class AbstractFlag<T extends FlagValue> {
|
||||
public final String key;
|
||||
public final FlagValue<?> value;
|
||||
public final T value = null;
|
||||
|
||||
public AbstractFlag(String key) {
|
||||
this(key, new FlagValue.StringValue());
|
||||
@ -22,18 +20,12 @@ public class AbstractFlag {
|
||||
* @param key
|
||||
*/
|
||||
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();
|
||||
if (value == null) {
|
||||
this.value = new FlagValue.StringValue();
|
||||
} else {
|
||||
this.value = value;
|
||||
}
|
||||
//if (value == null) {
|
||||
// this.value = new FlagValue.StringValue();
|
||||
//} else {
|
||||
// this.value = value;
|
||||
//}
|
||||
}
|
||||
|
||||
public boolean isList() {
|
||||
@ -51,11 +43,7 @@ public class AbstractFlag {
|
||||
public String toString(Object t) {
|
||||
return this.value.toString(t);
|
||||
}
|
||||
|
||||
public String getValueDesc() {
|
||||
return this.value.getDescription();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* AbstractFlag key
|
||||
*
|
||||
|
@ -5,4 +5,33 @@ public class BooleanFlag extends Flag<Boolean> {
|
||||
public BooleanFlag(String 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)";
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,8 @@
|
||||
package com.intellectualcrafters.plot.flag;
|
||||
|
||||
import com.intellectualcrafters.plot.util.StringMan;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class Flag<T> implements Cloneable {
|
||||
public class Flag<V> {
|
||||
|
||||
private AbstractFlag key;
|
||||
private Object value;
|
||||
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
|
||||
* register it with PlotSquared.
|
||||
*
|
||||
* @param key AbstractFlag
|
||||
* @param value Value must be alphanumerical (can have spaces) and be <= 48 characters
|
||||
*
|
||||
* @throws IllegalArgumentException if you provide inadequate inputs
|
||||
* @param name Flag name
|
||||
*/
|
||||
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) {
|
||||
this.name = name;
|
||||
}
|
||||
@ -58,82 +25,25 @@ public class Flag<T> implements Cloneable {
|
||||
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() {
|
||||
return this.key.toString(this.value);
|
||||
return this.key.toString(this.name);
|
||||
}
|
||||
|
||||
public String valueToString(Object value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if ("".equals(this.value)) {
|
||||
return this.key.getKey();
|
||||
}
|
||||
return this.key + ":" + getValueString();
|
||||
return "Flag { name='" + getName() + "'}";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
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);
|
||||
public V parseValue(String value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
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 getValueDescription() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
|
@ -1,19 +1,16 @@
|
||||
package com.intellectualcrafters.plot.flag;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotArea;
|
||||
import com.intellectualcrafters.plot.object.PlotCluster;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.PlotSettings;
|
||||
import com.intellectualcrafters.plot.object.RunnableVal;
|
||||
import com.intellectualcrafters.plot.util.EventUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
@ -26,20 +23,16 @@ import java.util.Set;
|
||||
*/
|
||||
public class FlagManager {
|
||||
|
||||
//TODO Default Flags
|
||||
public static final IntegerFlag MUSIC = new IntegerFlag("music");
|
||||
|
||||
|
||||
private static final HashSet<String> reserved = new HashSet<>();
|
||||
|
||||
private static final HashSet<AbstractFlag> flags = new HashSet<>();
|
||||
private static final HashSet<? extends Flag<?>>
|
||||
reserved = Sets.newHashSet();//todo MattBDev: Ask Empire what a reserved flag is
|
||||
|
||||
/**
|
||||
* Reserve a flag so that it cannot be set by players
|
||||
* @param flag
|
||||
*/
|
||||
public static void reserveFlag(String flag) {
|
||||
reserved.add(flag);
|
||||
//reserved.add(flag);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -47,7 +40,7 @@ public class FlagManager {
|
||||
* @param flag
|
||||
* @return
|
||||
*/
|
||||
public static boolean isReserved(String flag) {
|
||||
public static boolean isReserved(Flag<?> flag) {
|
||||
return reserved.contains(flag);
|
||||
}
|
||||
|
||||
@ -55,8 +48,8 @@ public class FlagManager {
|
||||
* Get the reserved flags
|
||||
* @return
|
||||
*/
|
||||
public static HashSet<String> getReservedFlags() {
|
||||
return (HashSet<String>) reserved.clone();
|
||||
public static HashSet<Flag<?>> getReservedFlags() {
|
||||
return (HashSet<Flag<?>>) reserved.clone();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -75,87 +68,37 @@ public class FlagManager {
|
||||
* @return boolean success
|
||||
*/
|
||||
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) {
|
||||
PS.debug(C.PREFIX + "&8 - Adding flag: &7" + af);
|
||||
PS.get().foreachPlotArea(new RunnableVal<PlotArea>() {
|
||||
@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) {
|
||||
public static String toString(HashMap<Flag<?>, Object> flags) {
|
||||
//todo MattBDev: Fix this for flags to work.
|
||||
//noinspection StringBufferReplaceableByString,MismatchedQueryAndUpdateOfStringBuilder
|
||||
StringBuilder flag_string = new StringBuilder();
|
||||
int i = 0;
|
||||
for (Flag flag : flags) {
|
||||
/* int i = 0;
|
||||
Flag<?> flag;
|
||||
for (Map.Entry<Flag<?>, Object> entry : flags.entrySet()) {
|
||||
flag = entry.getKey();
|
||||
if (i != 0) {
|
||||
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++;
|
||||
}
|
||||
}*/
|
||||
return flag_string.toString();
|
||||
}
|
||||
|
||||
public static Flag getSettingFlag(PlotArea area, PlotSettings settings, String id) {
|
||||
Flag flag;
|
||||
if (settings.flags.isEmpty() || (flag = settings.flags.get(id)) == null) {
|
||||
if (area == null) {
|
||||
public static <V> V getSettingFlag(PlotArea area, PlotSettings settings, Flag<V> id) {
|
||||
Object value;
|
||||
if (settings.flags.isEmpty() || ((value = settings.flags.get(id)) == null)) {
|
||||
if (area == null || area.DEFAULT_FLAGS.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
if (area.DEFAULT_FLAGS.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return area.DEFAULT_FLAGS.get(id);
|
||||
return (V) area.DEFAULT_FLAGS.get(id);
|
||||
}
|
||||
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();
|
||||
return (V) value;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -166,80 +109,36 @@ public class FlagManager {
|
||||
* @param flag
|
||||
* @return
|
||||
*/
|
||||
public static Flag getPlotFlagRaw(Plot plot, String flag) {
|
||||
public static <V> V getPlotFlagRaw(Plot plot, Flag<V> flag) {
|
||||
if (plot.owner == null) {
|
||||
return null;
|
||||
}
|
||||
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
|
||||
* @param origin
|
||||
* @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);
|
||||
if (!result) {
|
||||
return false;
|
||||
}
|
||||
for (Plot plot : origin.getConnectedPlots()) {
|
||||
plot.getFlags().put(flag.getKey(), flag);
|
||||
plot.getFlags().put(flag, value);
|
||||
plot.reEnter();
|
||||
DBFunc.setFlags(plot, plot.getFlags().values());
|
||||
DBFunc.setFlags(plot, plot.getFlags());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean addPlotFlagAbs(Plot plot, Flag flag) {
|
||||
boolean result = EventUtil.manager.callFlagAdd(flag, plot);
|
||||
if (!result) {
|
||||
return false;
|
||||
}
|
||||
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());
|
||||
public static <V> boolean addClusterFlag(PlotCluster cluster, Flag<V> flag, V value) {
|
||||
getSettingFlag(cluster.area, cluster.settings, flag);
|
||||
cluster.settings.flags.put(flag, value);
|
||||
DBFunc.setFlags(cluster, cluster.settings.flags);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -248,21 +147,21 @@ public class FlagManager {
|
||||
* @param plot
|
||||
* @return set of flags
|
||||
*/
|
||||
public static HashMap<String, Flag> getPlotFlags(Plot plot) {
|
||||
public static HashMap<Flag<?>, Object> getPlotFlags(Plot plot) {
|
||||
if (!plot.hasOwner()) {
|
||||
return null;
|
||||
}
|
||||
return getSettingFlags(plot.getArea(), plot.getSettings());
|
||||
}
|
||||
|
||||
public static HashMap<String, Flag> getPlotFlags(PlotArea area, PlotSettings settings, boolean ignorePluginflags) {
|
||||
HashMap<String, Flag> flags = new HashMap<>();
|
||||
public static HashMap<Flag<?>, Object> getPlotFlags(PlotArea area, PlotSettings settings, boolean ignorePluginflags) {
|
||||
HashMap<Flag<?>, Object> flags = new HashMap<>();
|
||||
if (area != null && !area.DEFAULT_FLAGS.isEmpty()) {
|
||||
flags.putAll(area.DEFAULT_FLAGS);
|
||||
}
|
||||
if (ignorePluginflags) {
|
||||
for (Map.Entry<String, Flag> flag : settings.flags.entrySet()) {
|
||||
if (isReserved(flag.getValue().getAbstractFlag().getKey())) {
|
||||
for (Map.Entry<Flag<?>, Object> flag : settings.flags.entrySet()) {
|
||||
if (isReserved(flag.getKey())) {
|
||||
continue;
|
||||
}
|
||||
flags.put(flag.getKey(), flag.getValue());
|
||||
@ -274,45 +173,45 @@ public class FlagManager {
|
||||
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);
|
||||
}
|
||||
|
||||
public static boolean removePlotFlag(Plot plot, String id) {
|
||||
Flag flag = plot.getFlags().remove(id);
|
||||
if (flag == null) {
|
||||
public static boolean removePlotFlag(Plot plot, Flag<?> id) {
|
||||
Object value = plot.getFlags().remove(id);
|
||||
if (value == null) {
|
||||
return false;
|
||||
}
|
||||
boolean result = EventUtil.manager.callFlagRemove(flag, plot);
|
||||
boolean result = EventUtil.manager.callFlagRemove(id, plot, value);
|
||||
if (!result) {
|
||||
plot.getFlags().put(id, flag);
|
||||
plot.getFlags().put(id, value);
|
||||
return false;
|
||||
}
|
||||
plot.reEnter();
|
||||
DBFunc.setFlags(plot, plot.getFlags().values());
|
||||
DBFunc.setFlags(plot, plot.getFlags());
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean removeClusterFlag(PlotCluster cluster, String id) {
|
||||
Flag flag = cluster.settings.flags.remove(id);
|
||||
if (flag == null) {
|
||||
public static boolean removeClusterFlag(PlotCluster cluster, Flag id) {
|
||||
Object object = cluster.settings.flags.remove(id);
|
||||
if (object == null) {
|
||||
return false;
|
||||
}
|
||||
boolean result = EventUtil.manager.callFlagRemove(flag, cluster);
|
||||
boolean result = EventUtil.manager.callFlagRemove(id, object, cluster);
|
||||
if (!result) {
|
||||
cluster.settings.flags.put(id, flag);
|
||||
cluster.settings.flags.put(id, object);
|
||||
return false;
|
||||
}
|
||||
DBFunc.setFlags(cluster, cluster.settings.flags.values());
|
||||
DBFunc.setFlags(cluster, cluster.settings.flags);
|
||||
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()) {
|
||||
if (flags != null && !flags.isEmpty()) {
|
||||
plot.getFlags().clear();
|
||||
for (Flag flag : flags) {
|
||||
plot.getFlags().put(flag.getKey(), flag);
|
||||
for (Map.Entry<Flag<?>, Object> flag : flags.entrySet()) {
|
||||
plot.getFlags().put(flag.getKey(), flag.getValue());
|
||||
}
|
||||
} else if (plot.getFlags().isEmpty()) {
|
||||
return;
|
||||
@ -320,7 +219,7 @@ public class FlagManager {
|
||||
plot.getFlags().clear();
|
||||
}
|
||||
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()) {
|
||||
cluster.settings.flags.clear();
|
||||
for (Flag flag : flags) {
|
||||
cluster.settings.flags.put(flag.getKey(), flag);
|
||||
cluster.settings.flags.put(flag, flag);
|
||||
}
|
||||
} else if (cluster.settings.flags.isEmpty()) {
|
||||
return;
|
||||
} else {
|
||||
cluster.settings.flags.clear();
|
||||
}
|
||||
DBFunc.setFlags(cluster, cluster.settings.flags.values());
|
||||
}
|
||||
|
||||
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;
|
||||
DBFunc.setFlags(cluster, cluster.settings.flags);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of registered AbstractFlag objects
|
||||
*
|
||||
* @return List (AbstractFlag)
|
||||
*/
|
||||
public static HashSet<AbstractFlag> getFlags() {
|
||||
return flags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of registered AbstractFlag objects based on player permissions
|
||||
* Get a list of registered {@link Flag} objects based on player permissions
|
||||
*
|
||||
* @param player with permissions
|
||||
*
|
||||
* @return List (AbstractFlag)
|
||||
*/
|
||||
public static List<AbstractFlag> getFlags(PlotPlayer player) {
|
||||
List<AbstractFlag> returnFlags = new ArrayList<>();
|
||||
for (AbstractFlag flag : flags) {
|
||||
if (Permissions.hasPermission(player, "plots.set.flag." + flag.getKey().toLowerCase())) {
|
||||
public static List<Flag> getFlags(PlotPlayer player) {
|
||||
List<Flag> returnFlags = new ArrayList<>();
|
||||
for (Flag flag : Flags.flags) {
|
||||
if (Permissions.hasPermission(player, "plots.set.flag." + flag.getName().toLowerCase())) {
|
||||
returnFlags.add(flag);
|
||||
}
|
||||
}
|
||||
@ -392,9 +261,9 @@ public class FlagManager {
|
||||
*
|
||||
* @return AbstractFlag
|
||||
*/
|
||||
public static AbstractFlag getFlag(String string) {
|
||||
for (AbstractFlag flag : flags) {
|
||||
if (flag.getKey().equalsIgnoreCase(string)) {
|
||||
public static Flag<?> getFlag(String string) {
|
||||
for (Flag flag : Flags.flags) {
|
||||
if (flag.getName().equalsIgnoreCase(string)) {
|
||||
return flag;
|
||||
}
|
||||
}
|
||||
@ -409,26 +278,23 @@ public class FlagManager {
|
||||
*
|
||||
* @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) {
|
||||
return new AbstractFlag(string);
|
||||
//return new AbstractFlag(string);
|
||||
}
|
||||
return getFlag(string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a registered AbstractFlag
|
||||
*
|
||||
* @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<>();
|
||||
public static HashMap<Flag<?>, Object> parseFlags(List<String> flagstrings) {
|
||||
HashMap<Flag<?>, Object> map = new HashMap<>();
|
||||
//todo MattBDev: Fix this
|
||||
/*
|
||||
for (String key : flagstrings) {
|
||||
String[] split;
|
||||
if (key.contains(";")) {
|
||||
@ -438,12 +304,13 @@ public class FlagManager {
|
||||
}
|
||||
Flag flag;
|
||||
if (split.length == 1) {
|
||||
flag = new Flag(getFlag(split[0], true), "");
|
||||
flag = new Flag(getFlag(split[0]), "");
|
||||
} else {
|
||||
flag = new Flag(getFlag(split[0], true), split[1]);
|
||||
}
|
||||
map.put(flag.getKey(), flag);
|
||||
}
|
||||
*/
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
@ -12,25 +12,10 @@ import java.util.List;
|
||||
|
||||
public abstract class FlagValue<T> {
|
||||
|
||||
private final Class<T> clazz;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public FlagValue() {
|
||||
this.clazz = (Class<T>) getClass();
|
||||
}
|
||||
|
||||
public FlagValue(Class<T> clazz) {
|
||||
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) {
|
||||
public String toString(T t) {
|
||||
return t.toString();
|
||||
}
|
||||
|
||||
@ -40,7 +25,7 @@ public abstract class FlagValue<T> {
|
||||
|
||||
public abstract String getDescription();
|
||||
|
||||
public interface ListValue extends Cloneable {
|
||||
interface ListValue extends Cloneable {
|
||||
|
||||
void add(Object t, String value);
|
||||
|
||||
@ -103,9 +88,8 @@ public abstract class FlagValue<T> {
|
||||
public static class IntervalValue extends FlagValue<Integer[]> {
|
||||
|
||||
@Override
|
||||
public String toString(Object t) {
|
||||
Integer[] value = (Integer[]) t;
|
||||
return value[0] + " " + value[1];
|
||||
public String toString(Integer[] t) {
|
||||
return t[0] + " " + t[1];
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -306,8 +290,8 @@ public abstract class FlagValue<T> {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public String toString(Object t) {
|
||||
return StringMan.join((HashSet<PlotBlock>) t, ",");
|
||||
public String toString(HashSet<PlotBlock> t) {
|
||||
return StringMan.join(t, ",");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@ -318,7 +302,7 @@ public abstract class FlagValue<T> {
|
||||
|
||||
@Override
|
||||
public HashSet<PlotBlock> parse(String t) {
|
||||
HashSet<PlotBlock> list = new HashSet<PlotBlock>();
|
||||
HashSet<PlotBlock> list = new HashSet<>();
|
||||
for (String item : t.split(",")) {
|
||||
PlotBlock block;
|
||||
try {
|
||||
@ -377,8 +361,8 @@ public abstract class FlagValue<T> {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public String toString(Object t) {
|
||||
return StringMan.join((List<Integer>) t, ",");
|
||||
public String toString(List<Integer> t) {
|
||||
return StringMan.join(t, ",");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@ -390,7 +374,7 @@ public abstract class FlagValue<T> {
|
||||
@Override
|
||||
public List<Integer> parse(String t) {
|
||||
String[] split = t.split(",");
|
||||
ArrayList<Integer> numbers = new ArrayList<Integer>();
|
||||
ArrayList<Integer> numbers = new ArrayList<>();
|
||||
for (String element : split) {
|
||||
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 {
|
||||
|
||||
@Override
|
||||
public String toString(final Object t) {
|
||||
return StringMan.join((List<String>) t, ",");
|
||||
public String toString(final List<String> t) {
|
||||
return StringMan.join(t, ",");
|
||||
}
|
||||
|
||||
@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> {
|
||||
|
||||
@Override
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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'";
|
||||
}
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
package com.intellectualcrafters.plot.flag;
|
||||
|
||||
public class IntegerFlag extends Flag<Integer> {
|
||||
|
||||
public IntegerFlag(String name) {
|
||||
super(name);
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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]";
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -3,8 +3,8 @@ package com.intellectualcrafters.plot.generator;
|
||||
import com.intellectualcrafters.jnbt.CompoundTag;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
import com.intellectualcrafters.plot.flag.Flags;
|
||||
import com.intellectualcrafters.plot.object.ChunkLoc;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
@ -89,8 +89,7 @@ public abstract class HybridUtils {
|
||||
result.add(whenDone.value.data_sd);
|
||||
result.add(whenDone.value.air_sd);
|
||||
result.add(whenDone.value.variety_sd);
|
||||
Flag flag = new Flag(FlagManager.getFlag("analysis"), result);
|
||||
FlagManager.addPlotFlag(origin, flag);
|
||||
FlagManager.addPlotFlag(origin, Flags.ANALYSIS, result);
|
||||
TaskManager.runTask(whenDone);
|
||||
return;
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.intellectualcrafters.plot.object;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.intellectualcrafters.jnbt.CompoundTag;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
@ -194,7 +195,7 @@ public class Plot {
|
||||
this.settings.setMerged(merged);
|
||||
if (flags != null) {
|
||||
for (Flag flag : flags) {
|
||||
this.settings.flags.put(flag.getKey(), flag);
|
||||
this.settings.flags.put(flag, flag);
|
||||
}
|
||||
}
|
||||
this.timestamp = timestamp;
|
||||
@ -941,24 +942,38 @@ public class Plot {
|
||||
* @param flag
|
||||
* @param value
|
||||
*/
|
||||
public void setFlag(String flag, Object value) {
|
||||
FlagManager.addPlotFlag(this, new Flag(FlagManager.getFlag(flag), value));
|
||||
public <V> boolean setFlag(Flag<V> flag, Object value) {
|
||||
return FlagManager.addPlotFlag(this, flag, (V) value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a flag from this plot
|
||||
* @param flag
|
||||
*/
|
||||
public void removeFlag(String flag) {
|
||||
public boolean removeFlag(Flag<?> flag) {
|
||||
FlagManager.removePlotFlag(this, flag);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the flag for a given key
|
||||
* @param key
|
||||
*/
|
||||
public Flag getFlag(String key) {
|
||||
return FlagManager.getPlotFlagRaw(this, key);
|
||||
public <V> Optional<V> getFlag(Flag<V> 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>
|
||||
* @return
|
||||
*/
|
||||
public HashMap<String, Flag> getFlags() {
|
||||
if (this.settings == null) {
|
||||
return new HashMap<>(0);
|
||||
}
|
||||
return this.settings.flags;
|
||||
public HashMap<Flag<?>, Object> getFlags() {
|
||||
return this.getSettings().flags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a flag for this plot.
|
||||
* @param flags
|
||||
*/
|
||||
public void setFlags(Set<Flag> flags) {
|
||||
public void setFlags(HashMap<Flag<?>, Object> flags) {
|
||||
FlagManager.setPlotFlags(this, flags);
|
||||
}
|
||||
|
||||
@ -2142,8 +2154,8 @@ public class Plot {
|
||||
* @param b
|
||||
*/
|
||||
public void mergeData(Plot b) {
|
||||
HashMap<String, Flag> flags1 = this.getFlags();
|
||||
HashMap<String, Flag> flags2 = b.getFlags();
|
||||
HashMap<Flag<?>, Object> flags1 = this.getFlags();
|
||||
HashMap<Flag<?>, Object> flags2 = b.getFlags();
|
||||
if ((!flags1.isEmpty() || !flags2.isEmpty()) && !flags1.equals(flags2)) {
|
||||
boolean greater = flags1.size() > flags2.size();
|
||||
if (greater) {
|
||||
@ -2151,7 +2163,7 @@ public class Plot {
|
||||
} else {
|
||||
flags2.putAll(flags1);
|
||||
}
|
||||
HashSet<Flag> net = new HashSet<>((greater ? flags1 : flags2).values());
|
||||
HashMap<Flag<?>, Object> net = (greater ? flags1 : flags2);
|
||||
this.setFlags(net);
|
||||
b.setFlags(net);
|
||||
}
|
||||
@ -2814,7 +2826,7 @@ public class Plot {
|
||||
other.create(plot.owner, false);
|
||||
if (!plot.getFlags().isEmpty()) {
|
||||
other.getSettings().flags = plot.getFlags();
|
||||
DBFunc.setFlags(other, plot.getFlags().values());
|
||||
DBFunc.setFlags(other, plot.getFlags());
|
||||
}
|
||||
if (plot.isMerged()) {
|
||||
other.setMerged(plot.getMerged());
|
||||
@ -2863,4 +2875,8 @@ public class Plot {
|
||||
run.run();
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean hasFlag(Flag<?> flag) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
package com.intellectualcrafters.plot.object;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.intellectualcrafters.configuration.file.YamlConfiguration;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
import com.intellectualcrafters.plot.flag.Flags;
|
||||
import com.intellectualcrafters.plot.generator.HybridUtils;
|
||||
import com.intellectualcrafters.plot.util.MathMan;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
@ -34,10 +34,10 @@ public class PlotAnalysis {
|
||||
private int complexity;
|
||||
|
||||
public static PlotAnalysis getAnalysis(Plot plot) {
|
||||
Flag flag = FlagManager.getPlotFlagRaw(plot, "analysis");
|
||||
if (flag != null) {
|
||||
Optional<List<Integer>> flag = plot.getFlag(Flags.ANALYSIS);
|
||||
if (flag.isPresent()) {
|
||||
PlotAnalysis analysis = new PlotAnalysis();
|
||||
List<Integer> values = (List<Integer>) flag.getValue();
|
||||
List<Integer> values = flag.get();
|
||||
analysis.changes = values.get(0); // 2126
|
||||
analysis.faces = values.get(1); // 90
|
||||
analysis.data = values.get(2); // 0
|
||||
|
@ -53,7 +53,7 @@ public abstract class PlotArea {
|
||||
public boolean SCHEMATIC_ON_CLAIM = false;
|
||||
public String SCHEMATIC_FILE = "null";
|
||||
public List<String> SCHEMATICS = null;
|
||||
public HashMap<String, Flag> DEFAULT_FLAGS;
|
||||
public HashMap<Flag<?>, Object> DEFAULT_FLAGS;
|
||||
public boolean USE_ECONOMY = false;
|
||||
public HashMap<String, Double> PRICES = new HashMap<>();
|
||||
public boolean SPAWN_EGGS = false;
|
||||
|
@ -2,7 +2,7 @@ package com.intellectualcrafters.plot.object;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
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 java.util.ArrayList;
|
||||
@ -49,7 +49,7 @@ public class PlotSettings {
|
||||
* @deprecated Raw access
|
||||
*/
|
||||
@Deprecated
|
||||
public HashMap<String, Flag> flags;
|
||||
public HashMap<Flag<?>, Object> flags = new HashMap<>();
|
||||
/**
|
||||
* Home Position.
|
||||
* @deprecated Raw access
|
||||
@ -57,14 +57,6 @@ public class PlotSettings {
|
||||
@Deprecated
|
||||
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>
|
||||
*
|
||||
@ -131,7 +123,7 @@ public class PlotSettings {
|
||||
}
|
||||
|
||||
public String getJoinMessage(PlotArea area) {
|
||||
Flag greeting = FlagManager.getSettingFlag(area, this, "greeting");
|
||||
Flag greeting = Flags.GREETING;
|
||||
if (greeting != null) {
|
||||
return greeting.getValueString();
|
||||
}
|
||||
@ -145,7 +137,7 @@ public class PlotSettings {
|
||||
* @return Farewell flag
|
||||
*/
|
||||
public String getLeaveMessage(PlotArea plotArea) {
|
||||
Flag farewell = FlagManager.getSettingFlag(plotArea, this, "farewell");
|
||||
Flag farewell = Flags.FAREWELL;
|
||||
if (farewell != null) {
|
||||
return farewell.getValueString();
|
||||
}
|
||||
|
@ -63,22 +63,16 @@ public class ConsoleColors {
|
||||
return ConsoleColor.RESET;
|
||||
}
|
||||
}
|
||||
|
||||
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(
|
||||
"\033[1m"), UNDERLINE("\033[0m"), ITALIC("\033[3m");
|
||||
private final String win;
|
||||
private final String lin;
|
||||
|
||||
ConsoleColor(final String lin) {
|
||||
this.lin = lin;
|
||||
win = lin;
|
||||
}
|
||||
|
||||
public String getWin() {
|
||||
return win;
|
||||
}
|
||||
|
||||
|
||||
public String getLin() {
|
||||
return lin;
|
||||
}
|
||||
|
@ -1,10 +1,11 @@
|
||||
package com.intellectualcrafters.plot.util;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
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.Location;
|
||||
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 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);
|
||||
|
||||
@ -119,16 +120,16 @@ public abstract class EventUtil {
|
||||
if (!plot.hasOwner()) {
|
||||
return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), notifyPerms);
|
||||
}
|
||||
Flag use = FlagManager.getPlotFlagRaw(plot, "use");
|
||||
if (use != null) {
|
||||
HashSet<PlotBlock> value = (HashSet<PlotBlock>) use.getValue();
|
||||
Optional<HashSet<PlotBlock>> use = plot.getFlag(Flags.USE);
|
||||
if (use.isPresent()) {
|
||||
HashSet<PlotBlock> value = use.get();
|
||||
if (value.contains(PlotBlock.EVERYTHING) || value.contains(block.getPlotBlock())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Flag destroy = FlagManager.getPlotFlagRaw(plot, "break");
|
||||
if (destroy != null) {
|
||||
HashSet<PlotBlock> value = (HashSet<PlotBlock>) destroy.getValue();
|
||||
Optional<HashSet<PlotBlock>> destroy = plot.getFlag(Flags.BREAK);
|
||||
if (destroy.isPresent()) {
|
||||
HashSet<PlotBlock> value = destroy.get();
|
||||
if (value.contains(PlotBlock.EVERYTHING) || value.contains(block.getPlotBlock())) {
|
||||
return true;
|
||||
}
|
||||
@ -141,7 +142,7 @@ public abstract class EventUtil {
|
||||
if (plot == null) {
|
||||
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;
|
||||
}
|
||||
if (plot.hasOwner()) {
|
||||
@ -153,7 +154,7 @@ public abstract class EventUtil {
|
||||
if (plot == null) {
|
||||
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;
|
||||
}
|
||||
if (plot.hasOwner()) {
|
||||
@ -165,7 +166,7 @@ public abstract class EventUtil {
|
||||
if (plot == null) {
|
||||
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;
|
||||
}
|
||||
if (plot.hasOwner()) {
|
||||
@ -182,14 +183,14 @@ public abstract class EventUtil {
|
||||
if (!plot.hasOwner()) {
|
||||
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;
|
||||
if (flag == null) {
|
||||
value = null;
|
||||
if (flagValue.isPresent()) {
|
||||
value = flagValue.get();
|
||||
} 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
|
||||
.sendMessage(pp, C.FLAG_TUTORIAL_USAGE, C.FLAG_USE.s()));
|
||||
}
|
||||
@ -202,14 +203,14 @@ public abstract class EventUtil {
|
||||
if (!plot.hasOwner()) {
|
||||
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;
|
||||
if (flag == null) {
|
||||
value = null;
|
||||
if (flagValue.isPresent()) {
|
||||
value = flagValue.get();
|
||||
} 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)) {
|
||||
return true;
|
||||
}
|
||||
@ -224,18 +225,19 @@ public abstract class EventUtil {
|
||||
if (!plot.hasOwner()) {
|
||||
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;
|
||||
}
|
||||
Flag flag = FlagManager.getPlotFlagRaw(plot, "use");
|
||||
Optional<HashSet<PlotBlock>> flagValue = plot.getFlag(Flags.USE);
|
||||
HashSet<PlotBlock> value;
|
||||
if (flag == null) {
|
||||
value = null;
|
||||
if (flagValue.isPresent()) {
|
||||
value = flagValue.get();
|
||||
} else {
|
||||
value = (HashSet<PlotBlock>) flag.getValue();
|
||||
return true;
|
||||
}
|
||||
if (value == null || !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()));
|
||||
if (!value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock())) {
|
||||
// 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;
|
||||
}
|
||||
@ -246,12 +248,17 @@ public abstract class EventUtil {
|
||||
if (!plot.hasOwner()) {
|
||||
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;
|
||||
}
|
||||
Flag flag = FlagManager.getPlotFlagRaw(plot, "use");
|
||||
HashSet<PlotBlock> value = flag == null ? null : (HashSet<PlotBlock>) flag.getValue();
|
||||
if (value == null || !value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock())) {
|
||||
Optional<HashSet<PlotBlock>> flagValue = plot.getFlag(Flags.USE);
|
||||
HashSet<PlotBlock> value;
|
||||
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)) {
|
||||
return true;
|
||||
}
|
||||
@ -266,12 +273,18 @@ public abstract class EventUtil {
|
||||
if (!plot.hasOwner()) {
|
||||
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;
|
||||
}
|
||||
Flag flag = FlagManager.getPlotFlagRaw(plot, "use");
|
||||
HashSet<PlotBlock> value = flag == null ? null : (HashSet<PlotBlock>) flag.getValue();
|
||||
if (value == null || !value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock())) {
|
||||
|
||||
Optional<HashSet<PlotBlock>> flag = plot.getFlag(Flags.USE);
|
||||
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)) {
|
||||
return true;
|
||||
}
|
||||
@ -286,12 +299,17 @@ public abstract class EventUtil {
|
||||
if (!plot.hasOwner()) {
|
||||
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;
|
||||
}
|
||||
Flag flag = FlagManager.getPlotFlagRaw(plot, "use");
|
||||
HashSet<PlotBlock> value = flag == null ? null : (HashSet<PlotBlock>) flag.getValue();
|
||||
if (value == null || !value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock())) {
|
||||
Optional<HashSet<PlotBlock>> flag = plot.getFlag(Flags.USE);
|
||||
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)) {
|
||||
return true;
|
||||
}
|
||||
@ -307,12 +325,17 @@ public abstract class EventUtil {
|
||||
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;
|
||||
}
|
||||
Flag flag = FlagManager.getPlotFlagRaw(plot, "place");
|
||||
HashSet<PlotBlock> value = flag == null ? null : (HashSet<PlotBlock>) flag.getValue();
|
||||
if (value == null || !value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock())) {
|
||||
Optional<HashSet<PlotBlock>> flagValue = plot.getFlag(Flags.PLACE);
|
||||
HashSet<PlotBlock> value;
|
||||
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)) {
|
||||
return true;
|
||||
}
|
||||
@ -330,17 +353,24 @@ public abstract class EventUtil {
|
||||
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;
|
||||
}
|
||||
Flag flag = FlagManager.getPlotFlagRaw(plot, "place");
|
||||
HashSet<PlotBlock> value = flag == null ? null : (HashSet<PlotBlock>) flag.getValue();
|
||||
if (value == null || !value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock())) {
|
||||
Optional<HashSet<PlotBlock>> flag = plot.getFlag(Flags.PLACE);
|
||||
|
||||
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)) {
|
||||
return true;
|
||||
}
|
||||
return !(!notifyPerms || MainUtil.sendMessage(pp, C.FLAG_TUTORIAL_USAGE, C.FLAG_MISC_PLACE.s() + "/" + C.FLAG_PLACE.s()));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
case PLACE_VEHICLE:
|
||||
@ -351,12 +381,17 @@ public abstract class EventUtil {
|
||||
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;
|
||||
}
|
||||
Flag flag = FlagManager.getPlotFlagRaw(plot, "place");
|
||||
HashSet<PlotBlock> value = flag == null ? null : (HashSet<PlotBlock>) flag.getValue();
|
||||
if (value == null || !value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock())) {
|
||||
Optional<HashSet<PlotBlock>> flag = plot.getFlag(Flags.PLACE);
|
||||
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)) {
|
||||
return true;
|
||||
}
|
||||
|
@ -1,11 +1,12 @@
|
||||
package com.intellectualcrafters.plot.util;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
import com.intellectualcrafters.plot.flag.Flags;
|
||||
import com.intellectualcrafters.plot.generator.HybridUtils;
|
||||
import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
@ -155,7 +156,7 @@ public class ExpireManager {
|
||||
if ((changed.changes != 0) && (changed.getComplexity() > Settings.CLEAR_THRESHOLD)) {
|
||||
PS.debug("$2[&5Expire&dManager$2] &bIgnoring modified plot: " + plot + " : " + changed.getComplexity() + " - "
|
||||
+ 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);
|
||||
} else {
|
||||
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) {
|
||||
return false;
|
||||
}
|
||||
Flag keep = plot.getFlag("keep");
|
||||
if (keep != null) {
|
||||
Object value = keep.getValue();
|
||||
Optional<Object> keep = plot.getFlag(Flags.KEEP);
|
||||
if (keep.isPresent()) {
|
||||
Object value = keep.get();
|
||||
if (value instanceof Boolean) {
|
||||
if (Boolean.TRUE.equals(value)) {
|
||||
return false;
|
||||
|
@ -1,11 +1,12 @@
|
||||
package com.intellectualcrafters.plot.util;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
import com.intellectualcrafters.plot.flag.Flags;
|
||||
import com.intellectualcrafters.plot.object.ChunkLoc;
|
||||
import com.intellectualcrafters.plot.object.ConsolePlayer;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
@ -708,9 +709,9 @@ public class MainUtil {
|
||||
String expires = C.UNKNOWN.s();
|
||||
if (Settings.AUTO_CLEAR) {
|
||||
if (plot.hasOwner()) {
|
||||
Flag keep = plot.getFlag("keep");
|
||||
if (keep != null) {
|
||||
Object value = keep.getValue();
|
||||
Optional<Object> keep = plot.getFlag(Flags.KEEP);
|
||||
if (keep.isPresent()) {
|
||||
Object value = keep.get();
|
||||
if (value instanceof Boolean) {
|
||||
if (Boolean.TRUE.equals(value)) {
|
||||
expires = C.NONE.s();
|
||||
@ -731,8 +732,8 @@ public class MainUtil {
|
||||
} else {
|
||||
expires = C.NEVER.s();
|
||||
}
|
||||
Flag descriptionFlag = FlagManager.getPlotFlagRaw(plot, "description");
|
||||
String description = descriptionFlag == null ? C.NONE.s() : descriptionFlag.getValueString();
|
||||
Optional<String> descriptionFlag = plot.getFlag(Flags.DESCRIPTION);
|
||||
String description = !descriptionFlag.isPresent() ? C.NONE.s() : Flags.DESCRIPTION.valueToString(descriptionFlag.get());
|
||||
|
||||
String flags;
|
||||
if (!StringMan.join(FlagManager.getPlotFlags(plot.getArea(), plot.getSettings(), true).values(), "").isEmpty()) {
|
||||
|
@ -155,7 +155,7 @@ public abstract class SchematicHandler {
|
||||
Map<String, Tag> flags = schematic.getFlags();
|
||||
if (!flags.isEmpty()) {
|
||||
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) {
|
||||
if (!plot.getFlags().isEmpty()) {
|
||||
HashMap<String, Tag> flagMap = new HashMap<>();
|
||||
for (Map.Entry<String, Flag> entry : plot.getFlags().entrySet()) {
|
||||
String key = entry.getKey();
|
||||
flagMap.put(key, new StringTag(key, entry.getValue().getValueString()));
|
||||
for (Map.Entry<Flag<?>, Object> entry : plot.getFlags().entrySet()) {
|
||||
String key = entry.getKey().getName();
|
||||
flagMap.put(key, new StringTag(key, entry.getKey().valueToString(entry.getValue())));
|
||||
}
|
||||
CompoundTag tag = new CompoundTag("Flags", flagMap);
|
||||
HashMap<String, Tag> map = new HashMap<>(value.getValue());
|
||||
|
@ -1,9 +1,11 @@
|
||||
package com.plotsquared.listener;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
import com.intellectualcrafters.plot.flag.Flags;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotArea;
|
||||
@ -41,19 +43,19 @@ public class PlotListener {
|
||||
pp.setMeta("lastplot", plot);
|
||||
EventUtil.manager.callEntry(pp, plot);
|
||||
if (plot.hasOwner()) {
|
||||
HashMap<String, Flag> flags = FlagManager.getPlotFlags(plot);
|
||||
HashMap<Flag<?>, Object> flags = FlagManager.getPlotFlags(plot);
|
||||
int size = flags.size();
|
||||
boolean titles = Settings.TITLES;
|
||||
final String greeting;
|
||||
|
||||
if (size != 0) {
|
||||
Flag titleFlag = flags.get("titles");
|
||||
if (titleFlag != null) {
|
||||
titles = (Boolean) titleFlag.getValue();
|
||||
Optional<Boolean> titleFlag = plot.getFlag(Flags.TITLES);
|
||||
if (titleFlag.isPresent()) {
|
||||
titles = titleFlag.get();
|
||||
}
|
||||
Flag greetingFlag = flags.get("greeting");
|
||||
if (greetingFlag != null) {
|
||||
greeting = (String) greetingFlag.getValue();
|
||||
Optional<String> greetingFlag = plot.getFlag(Flags.GREETING);
|
||||
if (greetingFlag.isPresent()) {
|
||||
greeting = greetingFlag.get();
|
||||
MainUtil.format(C.PREFIX_GREETING.s() + greeting, plot, pp, false, new RunnableVal<String>() {
|
||||
@Override
|
||||
public void run(String value) {
|
||||
@ -63,8 +65,8 @@ public class PlotListener {
|
||||
} else {
|
||||
greeting = "";
|
||||
}
|
||||
Flag enter = flags.get("notify-enter");
|
||||
if (enter != null && (Boolean) enter.getValue()) {
|
||||
Optional<Boolean> enter = plot.getFlag(Flags.NOTIFY_ENTER);
|
||||
if (enter.isPresent() && enter.get()) {
|
||||
if (!Permissions.hasPermission(pp, "plots.flag.notify-enter.bypass")) {
|
||||
for (UUID uuid : plot.getOwners()) {
|
||||
PlotPlayer owner = UUIDHandler.getPlayer(uuid);
|
||||
@ -75,38 +77,38 @@ public class PlotListener {
|
||||
}
|
||||
}
|
||||
}
|
||||
Flag gamemodeFlag = flags.get("gamemode");
|
||||
if (gamemodeFlag != null) {
|
||||
if (pp.getGameMode() != gamemodeFlag.getValue()) {
|
||||
Optional<PlotGameMode> gamemodeFlag = plot.getFlag(Flags.GAMEMODE);
|
||||
if (gamemodeFlag.isPresent()) {
|
||||
if (pp.getGameMode() != gamemodeFlag.get()) {
|
||||
if (!Permissions.hasPermission(pp, "plots.gamemode.bypass")) {
|
||||
pp.setGameMode((PlotGameMode) gamemodeFlag.getValue());
|
||||
pp.setGameMode(gamemodeFlag.get());
|
||||
} else {
|
||||
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");
|
||||
if (flyFlag != null) {
|
||||
pp.setFlight((boolean) flyFlag.getValue());
|
||||
Optional<Boolean> flyFlag = plot.getFlag(Flags.FLY);
|
||||
if (flyFlag.isPresent()) {
|
||||
pp.setFlight(flyFlag.get());
|
||||
}
|
||||
Flag timeFlag = flags.get("time");
|
||||
if (timeFlag != null) {
|
||||
Optional<Long> timeFlag = plot.getFlag(Flags.TIME);
|
||||
if (timeFlag.isPresent()) {
|
||||
try {
|
||||
long time = (long) timeFlag.getValue();
|
||||
long time = timeFlag.get();
|
||||
pp.setTime(time);
|
||||
} catch (Exception e) {
|
||||
FlagManager.removePlotFlag(plot, "time");
|
||||
FlagManager.removePlotFlag(plot, Flags.TIME);
|
||||
}
|
||||
}
|
||||
Flag weatherFlag = flags.get("weather");
|
||||
if (weatherFlag != null) {
|
||||
pp.setWeather((PlotWeather) weatherFlag.getValue());
|
||||
Optional<PlotWeather> weatherFlag = plot.getFlag(Flags.WEATHER);
|
||||
if (weatherFlag.isPresent()) {
|
||||
pp.setWeather(weatherFlag.get());
|
||||
}
|
||||
|
||||
Flag musicFlag = flags.get("music");
|
||||
if (musicFlag != null) {
|
||||
Integer id = (Integer) musicFlag.getValue();
|
||||
Optional<Integer> musicFlag = plot.getFlag(Flags.MUSIC);
|
||||
if (musicFlag.isPresent()) {
|
||||
Integer id = musicFlag.get();
|
||||
if ((id >= 2256 && id <= 2267) || (id == 0)) {
|
||||
Location loc = pp.getLocation();
|
||||
Location lastLoc = pp.getMeta("music");
|
||||
@ -172,7 +174,7 @@ public class PlotListener {
|
||||
if (pw == null) {
|
||||
return true;
|
||||
}
|
||||
if (FlagManager.getPlotFlagRaw(plot, "gamemode") != null) {
|
||||
if (plot.getFlag(Flags.GAMEMODE).isPresent()) {
|
||||
if (pp.getGameMode() != pw.GAMEMODE) {
|
||||
if (!Permissions.hasPermission(pp, "plots.gamemode.bypass")) {
|
||||
pp.setGameMode(pw.GAMEMODE);
|
||||
@ -182,17 +184,17 @@ public class PlotListener {
|
||||
}
|
||||
}
|
||||
}
|
||||
Flag farewell = FlagManager.getPlotFlagRaw(plot, "farewell");
|
||||
if (farewell != null) {
|
||||
MainUtil.format(C.PREFIX_FAREWELL.s() + farewell.getValueString(), plot, pp, false, new RunnableVal<String>() {
|
||||
Optional<String> farewell = plot.getFlag(Flags.FAREWELL);
|
||||
if (farewell.isPresent()) {
|
||||
MainUtil.format(C.PREFIX_FAREWELL.s() + farewell.get(), plot, pp, false, new RunnableVal<String>() {
|
||||
@Override
|
||||
public void run(String value) {
|
||||
MainUtil.sendMessage(pp, value);
|
||||
}
|
||||
});
|
||||
}
|
||||
Flag leave = FlagManager.getPlotFlagRaw(plot, "notify-leave");
|
||||
if ((leave != null) && (Boolean) leave.getValue()) {
|
||||
Optional<Boolean> leave = plot.getFlag(Flags.NOTIFY_LEAVE);
|
||||
if (leave.isPresent() && leave.get()) {
|
||||
if (!Permissions.hasPermission(pp, "plots.flag.notify-enter.bypass")) {
|
||||
for (UUID uuid : plot.getOwners()) {
|
||||
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();
|
||||
if (gamemode == PlotGameMode.SURVIVAL || (gamemode == PlotGameMode.ADVENTURE)) {
|
||||
pp.setFlight(false);
|
||||
}
|
||||
}
|
||||
if (FlagManager.getPlotFlagRaw(plot, "time") != null) {
|
||||
if (plot.getFlag(Flags.TIME).isPresent()) {
|
||||
pp.setTime(Long.MAX_VALUE);
|
||||
}
|
||||
if (FlagManager.getPlotFlagRaw(plot, "weather") != null) {
|
||||
if (plot.getFlag(Flags.WEATHER).isPresent()) {
|
||||
pp.setWeather(PlotWeather.RESET);
|
||||
}
|
||||
Location lastLoc = pp.getMeta("music");
|
||||
|
@ -2,7 +2,7 @@ package com.plotsquared.listener;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
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.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotArea;
|
||||
@ -46,7 +46,7 @@ public class WEManager {
|
||||
return regions;
|
||||
}
|
||||
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;
|
||||
}
|
||||
if (Settings.WE_ALLOW_HELPER && plot.isAdded(uuid) || !Settings.WE_ALLOW_HELPER && (plot.isOwner(uuid) || plot.getTrusted()
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
@ -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) {
|
||||
|
||||
}
|
||||
}
|
@ -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) {
|
||||
|
||||
}
|
||||
}
|
@ -4,8 +4,7 @@ import com.flowpowered.math.vector.Vector3d;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
import com.intellectualcrafters.plot.flag.Flags;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
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.BlockState;
|
||||
import org.spongepowered.api.data.Transaction;
|
||||
import org.spongepowered.api.entity.Entity;
|
||||
import org.spongepowered.api.entity.EntityTypes;
|
||||
import org.spongepowered.api.entity.explosive.Explosive;
|
||||
import org.spongepowered.api.entity.living.Ambient;
|
||||
@ -61,6 +59,7 @@ import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
@SuppressWarnings("Guava")
|
||||
public class MainListener {
|
||||
|
||||
/*
|
||||
@ -203,16 +202,16 @@ public class MainListener {
|
||||
// }
|
||||
|
||||
if (entity.getType() == EntityTypes.ITEM) {
|
||||
return !FlagManager.isPlotFlagFalse(plot, "item-drop");
|
||||
return plot.getFlag(Flags.ITEM_DROP).or(true);
|
||||
}
|
||||
int[] mobs = null;
|
||||
if (entity instanceof Living) {
|
||||
if (!loc.getPlotArea().MOB_SPAWNING) {
|
||||
return false;
|
||||
}
|
||||
Flag mobCap = FlagManager.getPlotFlagRaw(plot, "mob-cap");
|
||||
if (mobCap != null) {
|
||||
Integer cap = (Integer) mobCap.getValue();
|
||||
com.google.common.base.Optional<Integer> mobCap = plot.getFlag(Flags.MOB_CAP);
|
||||
if (mobCap.isPresent()) {
|
||||
Integer cap = mobCap.get();
|
||||
if (cap == 0) {
|
||||
return false;
|
||||
}
|
||||
@ -222,9 +221,9 @@ public class MainListener {
|
||||
}
|
||||
}
|
||||
if (entity instanceof Ambient || entity instanceof Animal) {
|
||||
Flag animalFlag = FlagManager.getPlotFlagRaw(plot, "animal-cap");
|
||||
if (animalFlag != null) {
|
||||
int cap = (Integer) animalFlag.getValue();
|
||||
com.google.common.base.Optional<Integer> animalFlag = plot.getFlag(Flags.ANIMAL_CAP);
|
||||
if (animalFlag.isPresent()) {
|
||||
int cap = animalFlag.get();
|
||||
if (cap == 0) {
|
||||
return false;
|
||||
}
|
||||
@ -236,9 +235,9 @@ public class MainListener {
|
||||
}
|
||||
}
|
||||
} else if (entity instanceof Monster) {
|
||||
Flag monsterFlag = FlagManager.getPlotFlagRaw(plot, "hostile-cap");
|
||||
if (monsterFlag != null) {
|
||||
int cap = (Integer) monsterFlag.getValue();
|
||||
com.google.common.base.Optional<Integer> monsterFlag = plot.getFlag(Flags.HOSTILE_CAP);
|
||||
if (monsterFlag.isPresent()) {
|
||||
int cap = monsterFlag.get();
|
||||
if (cap == 0) {
|
||||
return false;
|
||||
}
|
||||
@ -252,9 +251,9 @@ public class MainListener {
|
||||
}
|
||||
return true;
|
||||
} else if (entity instanceof Minecart || entity instanceof Boat) {
|
||||
Flag vehicleFlag = FlagManager.getPlotFlagRaw(plot, "vehicle-cap");
|
||||
if (vehicleFlag != null) {
|
||||
int cap = (Integer) vehicleFlag.getValue();
|
||||
com.google.common.base.Optional<Integer> vehicleFlag = plot.getFlag(Flags.VEHICLE_CAP);
|
||||
if (vehicleFlag.isPresent()) {
|
||||
int cap = vehicleFlag.get();
|
||||
if (cap == 0) {
|
||||
return false;
|
||||
}
|
||||
@ -264,9 +263,9 @@ public class MainListener {
|
||||
}
|
||||
}
|
||||
}
|
||||
Flag entityCap = FlagManager.getPlotFlagRaw(plot, "entity-cap");
|
||||
if (entityCap != null) {
|
||||
Integer cap = (Integer) entityCap.getValue();
|
||||
com.google.common.base.Optional<Integer> entityCap = plot.getFlag(Flags.ENTITY_CAP);
|
||||
if (entityCap.isPresent()) {
|
||||
Integer cap = entityCap.get();
|
||||
if (cap == 0) {
|
||||
return false;
|
||||
}
|
||||
@ -356,8 +355,8 @@ public class MainListener {
|
||||
if (plot.isAdded(pp.getUUID()) || Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER)) {
|
||||
return;
|
||||
} else {
|
||||
Flag flag = FlagManager.getPlotFlagRaw(plot, "use");
|
||||
if (flag != null && ((HashSet<PlotBlock>) flag.getValue()).contains(SpongeUtil.getPlotBlock(l.getBlock()))) {
|
||||
com.google.common.base.Optional<HashSet<PlotBlock>> flag = plot.getFlag(Flags.USE);
|
||||
if (flag.isPresent() && flag.get().contains(SpongeUtil.getPlotBlock(l.getBlock()))) {
|
||||
return;
|
||||
}
|
||||
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_INTERACT_OTHER);
|
||||
@ -396,22 +395,12 @@ public class MainListener {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!FlagManager.isPlotFlagTrue(currentPlot, "explosion")) {
|
||||
if (!currentPlot.getFlag(Flags.EXPLOSION).or(false)) {
|
||||
event.filterAll();
|
||||
return;
|
||||
}
|
||||
event.filter(new Predicate<org.spongepowered.api.world.Location<World>>() {
|
||||
@Override
|
||||
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());
|
||||
}
|
||||
});
|
||||
event.filter(loc -> currentPlot.equals(SpongeUtil.getLocation(loc.getExtent().getName(), loc).getPlot()));
|
||||
event.filterEntities(entity -> currentPlot.equals(SpongeUtil.getLocation(entity).getPlot()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -432,12 +421,7 @@ public class MainListener {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
event.filter(new Predicate<org.spongepowered.api.world.Location<World>>() {
|
||||
@Override
|
||||
public boolean test(org.spongepowered.api.world.Location<World> loc) {
|
||||
return !SpongeUtil.getLocation(worldName, loc).isPlotRoad();
|
||||
}
|
||||
});
|
||||
event.filter(loc1 -> !SpongeUtil.getLocation(worldName, loc1).isPlotRoad());
|
||||
}
|
||||
|
||||
@Listener
|
||||
@ -494,9 +478,9 @@ public class MainListener {
|
||||
return;
|
||||
} else {
|
||||
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();
|
||||
if (destroy == null || !((HashSet<PlotBlock>) destroy.getValue()).contains(SpongeUtil.getPlotBlock(state))) {
|
||||
if (!destroy.isPresent() || !destroy.get().contains(SpongeUtil.getPlotBlock(state))) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@ -524,9 +508,9 @@ public class MainListener {
|
||||
if (plot.isAdded(pp.getUUID()) || Permissions.hasPermission(pp, C.PERMISSION_ADMIN_DESTROY_OTHER)) {
|
||||
return true;
|
||||
} else {
|
||||
Flag destroy = FlagManager.getPlotFlagRaw(plot, "break");
|
||||
com.google.common.base.Optional<HashSet<PlotBlock>> destroy = plot.getFlag(Flags.BREAK);
|
||||
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;
|
||||
}
|
||||
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_DESTROY_OTHER);
|
||||
@ -563,7 +547,19 @@ public class MainListener {
|
||||
return;
|
||||
}
|
||||
} 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)) {
|
||||
return;
|
||||
}
|
||||
@ -571,17 +567,6 @@ public class MainListener {
|
||||
event.setCancelled(true);
|
||||
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>>() {
|
||||
|
||||
@ -605,9 +590,9 @@ public class MainListener {
|
||||
if (plot.isAdded(pp.getUUID()) || Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER)) {
|
||||
return true;
|
||||
} 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();
|
||||
if (build != null && ((HashSet<PlotBlock>) build.getValue()).contains(SpongeUtil.getPlotBlock(state))) {
|
||||
if (build.isPresent() && build.get().contains(SpongeUtil.getPlotBlock(state))) {
|
||||
return true;
|
||||
}
|
||||
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_OTHER);
|
||||
|
@ -22,7 +22,7 @@ public class SpongeChatManager extends ChatManager<Text.Builder> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void color(PlotMessage m, String color) {
|
||||
public void color(PlotMessage message, String color) {
|
||||
TextColor tc = null;
|
||||
TextStyle ts = null;
|
||||
switch (color.charAt(1)) {
|
||||
@ -94,10 +94,10 @@ public class SpongeChatManager extends ChatManager<Text.Builder> {
|
||||
break;
|
||||
}
|
||||
if (tc != null) {
|
||||
apply(m, getChild(m).color(tc));
|
||||
apply(message, getChild(message).color(tc));
|
||||
}
|
||||
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
|
||||
public void tooltip(PlotMessage m, PlotMessage... tooltips) {
|
||||
public void tooltip(PlotMessage message, PlotMessage... tooltips) {
|
||||
Text.Builder builder = Text.builder();
|
||||
boolean lb = false;
|
||||
for (PlotMessage tooltip : tooltips) {
|
||||
@ -124,30 +124,30 @@ public class SpongeChatManager extends ChatManager<Text.Builder> {
|
||||
builder.append(tooltip.$(this).build());
|
||||
lb = true;
|
||||
}
|
||||
apply(m, getChild(m).onHover(TextActions.showText(builder.toText())));
|
||||
apply(message, getChild(message).onHover(TextActions.showText(builder.toText())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void command(PlotMessage m, String command) {
|
||||
apply(m, getChild(m).onClick(TextActions.runCommand(command)));
|
||||
public void command(PlotMessage message, String command) {
|
||||
apply(message, getChild(message).onClick(TextActions.runCommand(command)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void text(PlotMessage m, String text) {
|
||||
m.$(this).append(SpongeUtil.getText(text));
|
||||
public void text(PlotMessage message, String text) {
|
||||
message.$(this).append(SpongeUtil.getText(text));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(PlotMessage m, PlotPlayer player) {
|
||||
public void send(PlotMessage plotMessage, PlotPlayer player) {
|
||||
if (player instanceof ConsolePlayer) {
|
||||
player.sendMessage(m.$(this).build().toPlain());
|
||||
player.sendMessage(plotMessage.$(this).build().toPlain());
|
||||
} else {
|
||||
((SpongePlayer) player).player.sendMessage(m.$(this).build());
|
||||
((SpongePlayer) player).player.sendMessage(plotMessage.$(this).build());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void suggest(PlotMessage m, String command) {
|
||||
apply(m, getChild(m).onClick(TextActions.suggestCommand(command)));
|
||||
public void suggest(PlotMessage plotMessage, String command) {
|
||||
apply(plotMessage, getChild(plotMessage).onClick(TextActions.suggestCommand(command)));
|
||||
}
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ public class SpongeEventUtil extends EventUtil {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean callFlagRemove(Flag flag, Plot plot) {
|
||||
public boolean callFlagRemove(Flag<?> flag, Plot plot, Object value) {
|
||||
return callEvent(new PlotFlagRemoveEvent(flag, plot));
|
||||
}
|
||||
|
||||
@ -109,7 +109,7 @@ public class SpongeEventUtil extends EventUtil {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean callFlagRemove(Flag flag, PlotCluster cluster) {
|
||||
public boolean callFlagRemove(Flag flag, Object object, PlotCluster cluster) {
|
||||
return callEvent(new ClusterFlagRemoveEvent(flag, cluster));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user