From 63c7041a348d63f38e9c50abf43891d64130e7aa Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Fri, 13 May 2016 02:55:57 +1000 Subject: [PATCH 1/2] Flag tweaks --- .../bukkit/listeners/PlayerEvents.java | 120 ++++++++---------- .../bukkit/util/block/FastQueue_1_9.java | 29 ++--- .../plot/flag/BooleanFlag.java | 12 ++ .../intellectualcrafters/plot/flag/Flag.java | 6 + .../plot/flag/FlagManager.java | 33 ++++- .../plot/flag/ListFlag.java | 6 + .../plot/object/Plot.java | 2 +- 7 files changed, 123 insertions(+), 85 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java index ac1154369..94659ffba 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java @@ -196,13 +196,9 @@ public class PlayerEvents extends PlotListener implements Listener { if (plot == null) { return; } - if (plot.getFlag(Flags.REDSTONE).isPresent()) { - if (plot.getFlag(Flags.REDSTONE).get()) { - return; - } else { - event.setNewCurrent(0); - return; - } + if (Flags.REDSTONE.isFalse(plot)) { + event.setNewCurrent(0); + return; } if (Settings.REDSTONE_DISABLER) { if (UUIDHandler.getPlayer(plot.owner) == null) { @@ -245,7 +241,7 @@ public class PlayerEvents extends PlotListener implements Listener { if (plot == null) { return; } - if (plot.getFlag(Flags.REDSTONE).isPresent() && !plot.getFlag(Flags.REDSTONE).get()) { + if (Flags.REDSTONE.isFalse(plot)) { event.setCancelled(true); } return; @@ -261,10 +257,12 @@ public class PlayerEvents extends PlotListener implements Listener { return; } Plot plot = area.getOwnedPlotAbs(loc); - if (plot != null && plot.getFlag(Flags.DISABLE_PHYSICS).or(false)) { - event.setCancelled(true); + if (plot == null) { return; } + if (Flags.DISABLE_PHYSICS.isFalse(plot)) { + event.setCancelled(true); + } return; default: break; @@ -686,7 +684,7 @@ public class PlayerEvents extends PlotListener implements Listener { } Plot plot = area.getOwnedPlot(location); if (plot != null) { - if (plot.getFlag(Flags.EXPLOSION).isPresent() && plot.getFlag(Flags.EXPLOSION).get()) { + if (Flags.EXPLOSION.isTrue(plot)) { List meta = event.getEntity().getMetadata("plot"); Plot origin; if (meta.isEmpty()) { @@ -782,17 +780,17 @@ public class PlayerEvents extends PlotListener implements Listener { Plot plot = area.getOwnedPlot(location); switch (block.getType()) { case GRASS: - if (plot.getFlag(Flags.GRASS_GROW).isPresent() && plot.getFlag(Flags.GRASS_GROW).get()) { + if (Flags.GRASS_GROW.isFalse(plot)) { event.setCancelled(true); } break; case MYCEL: - if (plot.getFlag(Flags.MYCEL_GROW).isPresent() && plot.getFlag(Flags.MYCEL_GROW).get()) { + if (Flags.MYCEL_GROW.isFalse(plot)) { event.setCancelled(true); } break; case VINE: - if (plot.getFlag(Flags.VINE_GROW).isPresent() && plot.getFlag(Flags.VINE_GROW).get()) { + if (Flags.VINE_GROW.isFalse(plot)) { event.setCancelled(true); } break; @@ -864,27 +862,18 @@ public class PlayerEvents extends PlotListener implements Listener { } switch (b.getType()) { case ICE: - Optional ice_melt = plot.getFlag(Flags.ICE_MELT); - if (ice_melt.isPresent()) { - if (!ice_melt.get()) { - e.setCancelled(true); - } + if (Flags.ICE_MELT.isFalse(plot)) { + e.setCancelled(true); } break; case SNOW: - Optional snow_melt = plot.getFlag(Flags.SNOW_MELT); - if (snow_melt.isPresent()) { - if (!snow_melt.get()) { - e.setCancelled(true); - } + if (Flags.SNOW_MELT.isFalse(plot)) { + e.setCancelled(true); } break; case SOIL: - Optional soil_dry = plot.getFlag(Flags.SOIL_DRY); - if (soil_dry.isPresent()) { - if (!soil_dry.get()) { - e.setCancelled(true); - } + if (Flags.SOIL_DRY.isFalse(plot)) { + e.setCancelled(true); } break; } @@ -902,7 +891,7 @@ public class PlayerEvents extends PlotListener implements Listener { Plot plot = area.getOwnedPlot(tLocation); Location fLocation = BukkitUtil.getLocation(from.getLocation()); if (plot != null) { - if (plot.getFlag(Flags.DISABLE_PHYSICS).or(false)) { + if (plot.getFlag(Flags.DISABLE_PHYSICS, false)) { event.setCancelled(true); } else if (!area.contains(fLocation.getX(), fLocation.getZ()) || !Objects.equals(plot, area.getOwnedPlot(fLocation))) { event.setCancelled(true); @@ -1345,7 +1334,7 @@ public class PlayerEvents extends PlotListener implements Listener { event.setCancelled(true); return; } - if (plot.getFlag(Flags.DISABLE_PHYSICS).or(false)) { + if (plot.getFlag(Flags.DISABLE_PHYSICS, false)) { event.setCancelled(true); return; } @@ -1396,14 +1385,14 @@ public class PlayerEvents extends PlotListener implements Listener { default: i = 0; } - Optional plotFlag = plot.getFlag(flag); - if (!plotFlag.isPresent()) { + int cap = plot.getFlag(flag, Integer.MAX_VALUE); + if (cap != Integer.MAX_VALUE) { continue; } if (mobs == null) { mobs = plot.countEntities(); } - if (mobs[i] >= plotFlag.get()) { + if (mobs[i] >= cap) { return true; } } @@ -1529,7 +1518,7 @@ public class PlayerEvents extends PlotListener implements Listener { } Plot plot = location.getOwnedPlot(); - if (plot == null || !plot.getFlag(Flags.BLOCK_BURN).or(false)) { + if (plot == null || !plot.getFlag(Flags.BLOCK_BURN, false)) { e.setCancelled(true); return; } @@ -1579,11 +1568,11 @@ public class PlayerEvents extends PlotListener implements Listener { MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_OTHER); event.setCancelled(true); } - } else if (!plot.getFlag(Flags.BLOCK_IGNITION).or(false)) { + } else if (!plot.getFlag(Flags.BLOCK_IGNITION, false)) { event.setCancelled(true); } } else if (ignitingEntity != null) { - if (plot == null || !plot.getFlag(Flags.BLOCK_IGNITION).or(false)) { + if (plot == null || !plot.getFlag(Flags.BLOCK_IGNITION, false)) { event.setCancelled(true); return; } @@ -1607,7 +1596,7 @@ public class PlayerEvents extends PlotListener implements Listener { } else if (event.getIgnitingBlock() != null) { Block ignitingBlock = event.getIgnitingBlock(); if (igniteCause == BlockIgniteEvent.IgniteCause.FLINT_AND_STEEL) { - if (plot == null || !plot.getFlag(Flags.BLOCK_IGNITION).or(false)) { + if (plot == null || !plot.getFlag(Flags.BLOCK_IGNITION, false)) { event.setCancelled(true); return; } @@ -1621,7 +1610,7 @@ public class PlayerEvents extends PlotListener implements Listener { } } if (igniteCause == BlockIgniteEvent.IgniteCause.SPREAD || igniteCause == BlockIgniteEvent.IgniteCause.LAVA) { - if (plot == null || !plot.getFlag(Flags.BLOCK_IGNITION).or(false)) { + if (plot == null || !plot.getFlag(Flags.BLOCK_IGNITION, false)) { event.setCancelled(true); return; } @@ -1932,7 +1921,7 @@ public class PlayerEvents extends PlotListener implements Listener { } return; } else if (!plot.isAdded(pp.getUUID())) { - if (!plot.getFlag(Flags.HANGING_PLACE).or(false)) { + if (!plot.getFlag(Flags.HANGING_PLACE, false)) { if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER)) { MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_OTHER); event.setCancelled(true); @@ -1970,7 +1959,7 @@ public class PlayerEvents extends PlotListener implements Listener { event.setCancelled(true); } } else if (!plot.isAdded(pp.getUUID())) { - if (plot.getFlag(Flags.HANGING_BREAK).or(false)) { + if (plot.getFlag(Flags.HANGING_BREAK, false)) { return; } if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_DESTROY_OTHER)) { @@ -1996,7 +1985,7 @@ public class PlayerEvents extends PlotListener implements Listener { event.setCancelled(true); } } else if (!plot.isAdded(player.getUUID())) { - if (!plot.getFlag(Flags.HANGING_BREAK).or(false)) { + if (!plot.getFlag(Flags.HANGING_BREAK, false)) { if (!Permissions.hasPermission(player, C.PERMISSION_ADMIN_DESTROY_OTHER)) { MainUtil.sendMessage(player, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_DESTROY_OTHER); event.setCancelled(true); @@ -2032,19 +2021,19 @@ public class PlayerEvents extends PlotListener implements Listener { } } else if (!plot.isAdded(pp.getUUID())) { Entity entity = event.getRightClicked(); - if (entity instanceof Monster && plot.getFlag(Flags.HOSTILE_INTERACT).or(false)) { + if (entity instanceof Monster && plot.getFlag(Flags.HOSTILE_INTERACT, false)) { return; } - if (entity instanceof Animals && plot.getFlag(Flags.ANIMAL_INTERACT).or(false)) { + if (entity instanceof Animals && plot.getFlag(Flags.ANIMAL_INTERACT, false)) { return; } - if (entity instanceof Tameable && ((Tameable) entity).isTamed() && plot.getFlag(Flags.TAMED_INTERACT).or(false)) { + if (entity instanceof Tameable && ((Tameable) entity).isTamed() && plot.getFlag(Flags.TAMED_INTERACT, false)) { return; } - if (entity instanceof Vehicle && plot.getFlag(Flags.VEHICLE_USE).or(false)) { + if (entity instanceof Vehicle && plot.getFlag(Flags.VEHICLE_USE, false)) { return; } - if (entity instanceof Player && plot.getFlag(Flags.PLAYER_INTERACT).or(false)) { + if (entity instanceof Player && plot.getFlag(Flags.PLAYER_INTERACT, false)) { return; } if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER)) { @@ -2081,7 +2070,7 @@ public class PlayerEvents extends PlotListener implements Listener { return; } if (!plot.isAdded(pp.getUUID())) { - if (plot.getFlag(Flags.VEHICLE_BREAK).or(false)) { + if (plot.getFlag(Flags.VEHICLE_BREAK, false)) { return; } if (!Permissions.hasPermission(pp, "plots.admin.vehicle.break.other")) { @@ -2192,7 +2181,7 @@ public class PlayerEvents extends PlotListener implements Listener { if (player != null) { PlotPlayer pp = BukkitUtil.getPlayer(player); if (victim instanceof Hanging) { // hanging - if (plot != null && (plot.getFlag(Flags.HANGING_BREAK).or(false) || plot.isAdded(pp.getUUID()))) { + if (plot != null && (plot.getFlag(Flags.HANGING_BREAK, false) || plot.isAdded(pp.getUUID()))) { return true; } if (!Permissions.hasPermission(pp, "plots.admin.destroy." + stub)) { @@ -2200,7 +2189,7 @@ public class PlayerEvents extends PlotListener implements Listener { return false; } } else if (victim.getEntityId() == 30) { - if (plot != null && (plot.getFlag(Flags.MISC_BREAK).or(false) || plot.isAdded(pp.getUUID()))) { + if (plot != null && (plot.getFlag(Flags.MISC_BREAK, false) || plot.isAdded(pp.getUUID()))) { return true; } if (!Permissions.hasPermission(pp, "plots.admin.destroy." + stub)) { @@ -2208,7 +2197,7 @@ public class PlayerEvents extends PlotListener implements Listener { return false; } } else if (victim instanceof Monster || victim instanceof EnderDragon) { // victim is monster - if (plot != null && (plot.getFlag(Flags.HOSTILE_ATTACK).or(false) || plot.getFlag(Flags.PVE).or(false) || plot + if (plot != null && (plot.getFlag(Flags.HOSTILE_ATTACK, false) || plot.getFlag(Flags.PVE, false) || plot .isAdded(pp.getUUID()))) { return true; } @@ -2217,7 +2206,7 @@ public class PlayerEvents extends PlotListener implements Listener { return false; } } else if (victim instanceof Tameable) { // victim is tameable - if (plot != null && (plot.getFlag(Flags.TAMED_ATTACK).or(false) || plot.getFlag(Flags.PVE).or(false) || plot.isAdded(pp.getUUID()))) { + if (plot != null && (plot.getFlag(Flags.TAMED_ATTACK, false) || plot.getFlag(Flags.PVE, false) || plot.isAdded(pp.getUUID()))) { return true; } if (!Permissions.hasPermission(pp, "plots.admin.pve." + stub)) { @@ -2226,12 +2215,9 @@ public class PlayerEvents extends PlotListener implements Listener { } } else if (victim instanceof Player) { if (plot != null) { - Optional pvp = plot.getFlag(Flags.PVP); - if (pvp.isPresent() && !pvp.get()) { - if (!Permissions.hasPermission(pp, "plots.admin.pve." + stub)) { - MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.pve." + stub); - return false; - } + if (Flags.PVP.isFalse(plot) && !Permissions.hasPermission(pp, "plots.admin.pvp." + stub)) { + MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.pvp." + stub); + return false; } else { return true; } @@ -2241,7 +2227,7 @@ public class PlayerEvents extends PlotListener implements Listener { return false; } } else if (victim instanceof Creature) { // victim is animal - if (plot != null && (plot.getFlag(Flags.ANIMAL_ATTACK).or(false) || plot.getFlag(Flags.PVE).or(false) || plot + if (plot != null && (plot.getFlag(Flags.ANIMAL_ATTACK, false) || plot.getFlag(Flags.PVE, false) || plot .isAdded(pp.getUUID()))) { return true; } @@ -2252,7 +2238,7 @@ public class PlayerEvents extends PlotListener implements Listener { } else if (victim instanceof Vehicle) { // Vehicles are managed in vehicle destroy event return true; } else { // victim is something else - if (plot != null && (plot.getFlag(Flags.PVE).or(false) || plot.isAdded(pp.getUUID()))) { + if (plot != null && (plot.getFlag(Flags.PVE, false) || plot.isAdded(pp.getUUID()))) { return true; } if (!Permissions.hasPermission(pp, "plots.admin.pve." + stub)) { @@ -2312,10 +2298,14 @@ public class PlayerEvents extends PlotListener implements Listener { return; } } else if (!plot.isAdded(pp.getUUID())) { - Optional> place = plot.getFlag(Flags.PLACE); - Block block = event.getBlock(); - if ((place.isPresent() && !place.get().contains(new PlotBlock((short) block.getTypeId(), block.getData()))) && !Permissions - .hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER)) { + Set place = plot.getFlag(Flags.PLACE, null); + if (place != null) { + Block block = event.getBlock(); + if (place.contains(new PlotBlock((short) block.getTypeId(), block.getData()))) { + return; + } + } + if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER)) { MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_OTHER); event.setCancelled(true); return; @@ -2327,7 +2317,7 @@ public class PlayerEvents extends PlotListener implements Listener { return; } } - if (plot.getFlag(Flags.DISABLE_PHYSICS).or(false)) { + if (plot.getFlag(Flags.DISABLE_PHYSICS, false)) { Block block = event.getBlockPlaced(); if (block.getType().hasGravity()) { sendBlockChange(block.getLocation(), block.getType(), block.getData()); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_9.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_9.java index cb4c67f63..0e268a0ab 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_9.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_9.java @@ -1,7 +1,5 @@ package com.plotsquared.bukkit.util.block; -import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass; - import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.PseudoRandom; import com.intellectualcrafters.plot.util.ChunkManager; @@ -13,23 +11,23 @@ import com.intellectualcrafters.plot.util.ReflectionUtils.RefField; import com.intellectualcrafters.plot.util.ReflectionUtils.RefMethod; import com.intellectualcrafters.plot.util.ReflectionUtils.RefMethod.RefExecutor; import com.intellectualcrafters.plot.util.SetQueue.ChunkWrapper; -import com.intellectualcrafters.plot.util.TaskManager; import com.plotsquared.bukkit.util.BukkitUtil; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map.Entry; +import java.util.Set; import org.bukkit.Chunk; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.World.Environment; import org.bukkit.block.Biome; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map.Entry; -import java.util.Set; + +import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass; public class FastQueue_1_9 extends SlowQueue { @@ -220,12 +218,7 @@ public class FastQueue_1_9 extends SlowQueue { } } } - TaskManager.runTaskLater(new Runnable() { - @Override - public void run() { - sendChunk(fs.getChunkWrapper().world, Arrays.asList(new ChunkLoc(fs.getX(), fs.getZ()))); - } - }, 1); + world.refreshChunk(fs.getX(), fs.getZ()); } public Object newChunkSection(int i, boolean flag, char[] ids) { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/flag/BooleanFlag.java b/Core/src/main/java/com/intellectualcrafters/plot/flag/BooleanFlag.java index 0fb5c7919..0158e6175 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/flag/BooleanFlag.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/flag/BooleanFlag.java @@ -1,5 +1,7 @@ package com.intellectualcrafters.plot.flag; +import com.intellectualcrafters.plot.object.Plot; + public class BooleanFlag extends Flag { public BooleanFlag(String name) { @@ -34,4 +36,14 @@ public class BooleanFlag extends Flag { @Override public String getValueDescription() { return "Flag value must be a boolean (true|false)"; } + + public boolean isTrue(Plot plot) { + Boolean value = FlagManager.getPlotFlagRaw(plot, this); + return Boolean.TRUE == value; + } + + public boolean isFalse(Plot plot) { + Boolean value = FlagManager.getPlotFlagRaw(plot, this); + return Boolean.FALSE == value; + } } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/flag/Flag.java b/Core/src/main/java/com/intellectualcrafters/plot/flag/Flag.java index 02f7d3b21..517d297aa 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/flag/Flag.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/flag/Flag.java @@ -1,5 +1,7 @@ package com.intellectualcrafters.plot.flag; +import com.intellectualcrafters.plot.object.Plot; + public class Flag { private String name; @@ -35,4 +37,8 @@ public class Flag { public final String getName() { return this.name; } + + public boolean isSet(Plot plot) { + return FlagManager.getPlotFlagRaw(plot, this) != null; + } } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java b/Core/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java index 467fb99c8..72bf956f6 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java @@ -1,6 +1,8 @@ package com.intellectualcrafters.plot.flag; +import com.google.common.base.Optional; import com.google.common.collect.Sets; +import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotArea; @@ -9,7 +11,7 @@ import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotSettings; import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.Permissions; - +import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -27,6 +29,35 @@ public class FlagManager { private static final HashSet> reserved = Sets.newHashSet(Flags.ANALYSIS, Flags.DONE); + /** + * Some events can be called millions of times each second (e.g. physics) and reusing is a lot faster. + */ + private static Optional MUTABLE_OPTIONAL; + private static Field MUTABLE_OPTIONAL_FIELD; + static { + MUTABLE_OPTIONAL = Optional.of(new Object()); + try { + MUTABLE_OPTIONAL_FIELD = MUTABLE_OPTIONAL.getClass().getDeclaredField("reference"); + MUTABLE_OPTIONAL_FIELD.setAccessible(true); + } catch (NoSuchFieldException e) { + e.printStackTrace(); + } + } + + public static Optional getPlotFlag(Plot plot, Flag key) { + V value = FlagManager.getPlotFlagRaw(plot, key); + if (value != null) { + if (PS.get().isMainThread(Thread.currentThread())) { + try { + MUTABLE_OPTIONAL_FIELD.set(MUTABLE_OPTIONAL, value); + return MUTABLE_OPTIONAL; + } catch (IllegalAccessException e) {e.printStackTrace();} + } + return Optional.of(value); + } + return Optional.absent(); + } + /** * Reserve a flag so that it cannot be set by players * @param flag diff --git a/Core/src/main/java/com/intellectualcrafters/plot/flag/ListFlag.java b/Core/src/main/java/com/intellectualcrafters/plot/flag/ListFlag.java index 455683628..d696e2f0f 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/flag/ListFlag.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/flag/ListFlag.java @@ -1,5 +1,6 @@ package com.intellectualcrafters.plot.flag; +import com.intellectualcrafters.plot.object.Plot; import java.util.Collection; public abstract class ListFlag> extends Flag { @@ -7,4 +8,9 @@ public abstract class ListFlag> extends Flag { public ListFlag(String name) { super(name); } + + public boolean contains(Plot plot, Object value) { + V existing = plot.getFlag(this, null); + return existing != null && existing.contains(value); + } } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java b/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java index b427c7abe..e7d785d38 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java @@ -959,7 +959,7 @@ public class Plot { * @param key */ public Optional getFlag(Flag key) { - return Optional.fromNullable(FlagManager.getPlotFlagRaw(this, key)); + return FlagManager.getPlotFlag(this, key); } /** From 0095af0ce56381f609ce52741f4faedb225e4792 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Fri, 13 May 2016 03:38:32 +1000 Subject: [PATCH 2/2] Flag info --- .../intellectualcrafters/plot/config/C.java | 5 ++ .../plot/util/MainUtil.java | 51 ++++++++++--------- 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/Core/src/main/java/com/intellectualcrafters/plot/config/C.java b/Core/src/main/java/com/intellectualcrafters/plot/config/C.java index 18433c84e..4f7edfb5a 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/config/C.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/config/C.java @@ -483,6 +483,7 @@ public enum C { PLOT_INFO_SIZE("$1Size:$2 %size%", "Info"), PLOT_INFO_EXPIRES("$1Expires:$2 %expires%", "Info"), PLOT_USER_LIST(" $1%user%$2,", "Info"), + PLOT_FLAG_LIST("$1%s0:%s1$2", "Info"), INFO_SYNTAX_CONSOLE("$2/plot info X;Y", "Info"), /* * Generating @@ -686,6 +687,10 @@ public enum C { } } + public String f(final Object... args) { + return format(s(), args); + } + public static String color(String string) { return StringMan.replaceFromMap(string, replacements); } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java b/Core/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java index b0f8c53a7..4cdf40ebf 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java @@ -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.flag.Flags; import com.intellectualcrafters.plot.object.ChunkLoc; @@ -18,7 +19,6 @@ import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PseudoRandom; import com.intellectualcrafters.plot.object.RegionWrapper; import com.intellectualcrafters.plot.object.RunnableVal; - import java.io.File; import java.io.IOException; import java.io.OutputStream; @@ -39,7 +39,6 @@ import java.util.Map; import java.util.Map.Entry; import java.util.UUID; import java.util.concurrent.TimeUnit; -import java.util.regex.Matcher; /** * plot functions @@ -737,32 +736,38 @@ public class MainUtil { Optional 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()) { - flags = StringMan.replaceFromMap( - "$2" + StringMan.join(FlagManager.getPlotFlags(plot.getArea(), plot.getSettings(), true).values(), "$1, $2"), C.replacements); - } else { - flags = StringMan.replaceFromMap("$2" + C.NONE.s(), C.replacements); + StringBuilder flags = new StringBuilder(); + { + HashMap, Object> flagMap = FlagManager.getPlotFlags(plot.getArea(), plot.getSettings(), true); + if (flagMap.isEmpty()) { + flags.append(C.NONE.s()); + } else { + String prefix = ""; + for (Entry, Object> entry : flagMap.entrySet()) { + flags.append(prefix).append(C.PLOT_FLAG_LIST.f(entry.getKey().getName(), entry.getValue())); + prefix = ", "; + } + } } boolean build = plot.isAdded(player.getUUID()); String owner = plot.getOwners().isEmpty() ? "unowned" : getPlayerList(plot.getOwners()); - info = info.replaceAll("%id%", plot.getId().toString()); - info = info.replaceAll("%alias%", alias); - info = info.replaceAll("%num%", num + ""); - info = info.replaceAll("%desc%", description); - info = info.replaceAll("%biome%", biome); - info = info.replaceAll("%owner%", owner); - info = info.replaceAll("%members%", members); - info = info.replaceAll("%player%", player.getName()); - info = info.replaceAll("%trusted%", trusted); - info = info.replaceAll("%helpers%", members); - info = info.replaceAll("%denied%", denied); - info = info.replaceAll("%expires%", expires); - info = info.replaceAll("%flags%", Matcher.quoteReplacement(flags)); - info = info.replaceAll("%build%", build + ""); - info = info.replaceAll("%desc%", "No description set."); + info = info.replace("%id%", plot.getId().toString()); + info = info.replace("%alias%", alias); + info = info.replace("%num%", num + ""); + info = info.replace("%desc%", description); + info = info.replace("%biome%", biome); + info = info.replace("%owner%", owner); + info = info.replace("%members%", members); + info = info.replace("%player%", player.getName()); + info = info.replace("%trusted%", trusted); + info = info.replace("%helpers%", members); + info = info.replace("%denied%", denied); + info = info.replace("%expires%", expires); + info = info.replace("%flags%", flags); + info = info.replace("%build%", build + ""); + info = info.replace("%desc%", "No description set."); if (info.contains("%rating%")) { final String newInfo = info; TaskManager.runTaskAsync(new Runnable() {