diff --git a/pom.xml b/pom.xml index f735ef765..39032a96b 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ UTF-8 PlotSquared - 3.2.19 + 3.2.20 PlotSquared jar diff --git a/src/main/java/com/intellectualcrafters/plot/PS.java b/src/main/java/com/intellectualcrafters/plot/PS.java index 2d2777b22..a5d67f3b3 100644 --- a/src/main/java/com/intellectualcrafters/plot/PS.java +++ b/src/main/java/com/intellectualcrafters/plot/PS.java @@ -699,7 +699,7 @@ public class PS { try { final ArrayList overflow = new ArrayList<>(); if ((range > limit) && (size > 1024)) { - plots = new Plot[Math.min((int) range, limit)]; + plots = new Plot[limit]; final int factor = (int) ((range / limit)); for (int i = 0; i < size; i++) { Plot plot = list.get(i); diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Info.java b/src/main/java/com/intellectualcrafters/plot/commands/Info.java index 7616317af..3a34d193e 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Info.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Info.java @@ -134,12 +134,9 @@ public class Info extends SubCommand { full = false; } MainUtil.format(info, plot, player, full, new RunnableVal() { - @Override public void run() { - MainUtil.sendMessage(player, C.PLOT_INFO_HEADER); - MainUtil.sendMessage(player, value, false); - MainUtil.sendMessage(player, C.PLOT_INFO_FOOTER); + MainUtil.sendMessage(player, C.PLOT_INFO_HEADER.s() + '\n' + value + '\n' + C.PLOT_INFO_FOOTER.s(), false); } }); return true; diff --git a/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java b/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java index e32dd7310..6fd9611be 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java @@ -320,6 +320,9 @@ public class MainCommand extends CommandManager { @Override public int handle(final PlotPlayer plr, final String input) { + // Clear perm caching // + plr.deleteMeta("perm"); + //////////////////////// final String[] parts = input.split(" "); String[] args; String label; diff --git a/src/main/java/com/intellectualcrafters/plot/commands/list.java b/src/main/java/com/intellectualcrafters/plot/commands/list.java index 0afbf75fc..aea24b87a 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/list.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/list.java @@ -331,7 +331,7 @@ public class list extends SubCommand { } } if (sort) { - plots = PS.get().sortPlots(plots, SortType.CREATION_DATE_TIMESTAMP, world); + plots = PS.get().sortPlots(plots, SortType.CREATION_DATE, world); } if (page < 0) { page = 0; diff --git a/src/main/java/com/intellectualcrafters/plot/config/C.java b/src/main/java/com/intellectualcrafters/plot/config/C.java index 2f52a5dae..f4aa447d7 100644 --- a/src/main/java/com/intellectualcrafters/plot/config/C.java +++ b/src/main/java/com/intellectualcrafters/plot/config/C.java @@ -675,14 +675,18 @@ public enum C { final Map map = new LinkedHashMap(); if (args.length > 0) { for (int i = args.length - 1; i >= 0; i--) { - if (args[i] == null) { - args[i] = ""; + String arg = args[i].toString(); + if (arg == null || arg.length() == 0) { + map.put("%s" + i, ""); + } else { + arg = C.color(arg); + map.put("%s" + i, arg); + } + if (i == 0) { + map.put("%s", arg); } - map.put("%s" + i, args[i].toString()); } - map.put("%s", args[0].toString()); } - map.putAll(replacements); m = StringMan.replaceFromMap(m, map); return m; } diff --git a/src/main/java/com/intellectualcrafters/plot/config/Settings.java b/src/main/java/com/intellectualcrafters/plot/config/Settings.java index 889b27e75..7300e6d45 100644 --- a/src/main/java/com/intellectualcrafters/plot/config/Settings.java +++ b/src/main/java/com/intellectualcrafters/plot/config/Settings.java @@ -40,7 +40,7 @@ public class Settings { /** * Default UUID_FECTHING: false */ - public static boolean PERMISSION_CACHING = false; + public static boolean PERMISSION_CACHING = true; public static boolean CACHE_RATINGS = true; public static boolean UUID_FROM_DISK = false; diff --git a/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java b/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java index 675c09228..ac6d556a1 100644 --- a/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java +++ b/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java @@ -2819,7 +2819,7 @@ public class SQLManager implements AbstractDB { final ConcurrentHashMap map = entry.getValue(); if (map.size() > 0) { for (final Entry entry2 : map.entrySet()) { - PS.debug("$1Plot was deleted: " + entry.getValue() + "// TODO implement this when sure safe"); + PS.debug("$1Plot was deleted: " + entry2.getValue() + "// TODO implement this when sure safe"); } } } diff --git a/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java b/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java index 6fe60e347..3c59ccec2 100644 --- a/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java +++ b/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java @@ -157,8 +157,16 @@ public class FlagManager { return result == null ? null : (Flag) result.clone(); } + /** + * Returns the raw flag
+ * - Faster + * - You should not modify the flag + * @param plot + * @param flag + * @return + */ public static Flag getPlotFlagRaw(final Plot plot, final String flag) { - if (!plot.hasOwner()) { + if (plot.owner == null) { return null; } return getSettingFlag(plot.world, plot.getSettings(), flag); diff --git a/src/main/java/com/intellectualcrafters/plot/util/EventUtil.java b/src/main/java/com/intellectualcrafters/plot/util/EventUtil.java index 54d5e551a..f5c7e88f2 100644 --- a/src/main/java/com/intellectualcrafters/plot/util/EventUtil.java +++ b/src/main/java/com/intellectualcrafters/plot/util/EventUtil.java @@ -63,12 +63,11 @@ public abstract class EventUtil { public boolean checkPlayerBlockEvent(final PlotPlayer pp, final PlayerBlockEventType type, final Location loc, final LazyBlock block, boolean notifyPerms) { final Plot plot = MainUtil.getPlotAbs(loc); - final UUID uuid = pp.getUUID(); if (plot == null) { if (!MainUtil.isPlotAreaAbs(loc)) { return true; } - } else if (plot.isAdded(uuid)) { + } else if (plot.isAdded(pp.getUUID())) { return true; } switch (type) { @@ -83,7 +82,7 @@ public abstract class EventUtil { if (plot == null) { return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_ROAD.s(), notifyPerms); } - if (!plot.hasOwner()) { + if (plot.owner == null) { return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), notifyPerms); } final Flag use = FlagManager.getPlotFlagRaw(plot, "use"); @@ -151,7 +150,7 @@ public abstract class EventUtil { if (plot == null) { return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_ROAD.s(), notifyPerms); } - if (!plot.hasOwner()) { + if (plot.owner == null) { return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), notifyPerms); } final Flag flag = FlagManager.getPlotFlagRaw(plot, "use"); @@ -168,7 +167,7 @@ public abstract class EventUtil { if (plot == null) { return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_ROAD.s(), notifyPerms); } - if (!plot.hasOwner()) { + if (plot.owner == null) { return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_UNOWNED.s(), notifyPerms); } final Flag flag = FlagManager.getPlotFlagRaw(plot, "place"); @@ -185,7 +184,7 @@ public abstract class EventUtil { if (plot == null) { return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_ROAD.s(), false); } - if (!plot.hasOwner()) { + if (plot.owner == null) { return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), false); } if (FlagManager.isPlotFlagTrue(plot, "device-interact")) { @@ -194,12 +193,10 @@ public abstract class EventUtil { final Flag flag = FlagManager.getPlotFlagRaw(plot, "use"); final HashSet value = flag == null ? null : (HashSet) flag.getValue(); if ((value == null) || (!value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock()))) { - long time = System.currentTimeMillis(); - notifyPerms = notifyPerms && (31 * (time / 31) == time); - if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER.s(), notifyPerms)) { + if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER.s(), false)) { return true; } - return !(!notifyPerms || MainUtil.sendMessage(pp, C.FLAG_TUTORIAL_USAGE, C.FLAG_USE.s() + "/" + C.FLAG_DEVICE_INTERACT.s())); + return !(!false || MainUtil.sendMessage(pp, C.FLAG_TUTORIAL_USAGE, C.FLAG_USE.s() + "/" + C.FLAG_DEVICE_INTERACT.s())); } return true; } @@ -207,7 +204,7 @@ public abstract class EventUtil { if (plot == null) { return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_ROAD.s(), notifyPerms); } - if (!plot.hasOwner()) { + if (plot.owner == null) { return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), notifyPerms); } if (FlagManager.isPlotFlagTrue(plot, "hanging-interact")) { @@ -227,7 +224,7 @@ public abstract class EventUtil { if (plot == null) { return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_ROAD.s(), notifyPerms); } - if (!plot.hasOwner()) { + if (plot.owner == null) { return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), notifyPerms); } if (FlagManager.isPlotFlagTrue(plot, "misc-interact")) { @@ -247,7 +244,7 @@ public abstract class EventUtil { if (plot == null) { return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_ROAD.s(), notifyPerms); } - if (!plot.hasOwner()) { + if (plot.owner == null) { return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), notifyPerms); } if (FlagManager.isPlotFlagTrue(plot, "vehicle-use")) { @@ -267,7 +264,7 @@ public abstract class EventUtil { if (plot == null) { return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER.s(), notifyPerms); } - if (!plot.hasOwner()) { + if (plot.owner == null) { return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), notifyPerms); } @@ -288,7 +285,7 @@ public abstract class EventUtil { // if (plot == null) { // return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER.s(), notifyPerms); // } - // if (!plot.hasOwner()) { + // if (plot.owner == null) { // return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), notifyPerms); // } // @@ -306,7 +303,7 @@ public abstract class EventUtil { if (plot == null) { return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER.s(), notifyPerms); } - if (!plot.hasOwner()) { + if (plot.owner == null) { return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), notifyPerms); } @@ -327,7 +324,7 @@ public abstract class EventUtil { if (plot == null) { return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER.s(), notifyPerms); } - if (!plot.hasOwner()) { + if (plot.owner == null) { return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), notifyPerms); } diff --git a/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java b/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java index 28299effa..678e973f9 100644 --- a/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java +++ b/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java @@ -2177,18 +2177,7 @@ public class MainUtil { * @return boolean success */ public static boolean sendMessage(final PlotPlayer plr, final C c, final String... args) { - if (c.s().length() > 1) { - String msg = c.s(); - if ((args != null) && (args.length > 0)) { - msg = C.format(c, args); - } - if (plr == null) { - ConsolePlayer.getConsole().sendMessage(msg); - } else { - sendMessage(plr, msg, c.usePrefix()); - } - } - return true; + return sendMessage(plr, c, (Object[]) args); } /** @@ -2200,17 +2189,23 @@ public class MainUtil { * @return boolean success */ public static boolean sendMessage(final PlotPlayer plr, final C c, final Object... args) { - if (c.s().length() > 1) { - String msg = c.s(); - if ((args != null) && (args.length > 0)) { - msg = C.format(c, args); - } - if (plr == null) { - ConsolePlayer.getConsole().sendMessage(msg); - } else { - sendMessage(plr, msg, c.usePrefix()); - } + if (c.s().length() == 0) { + return true; } + TaskManager.runTaskAsync(new Runnable() { + @Override + public void run() { + String msg = c.s(); + if (args.length != 0) { + msg = c.format(c, args); + } + if (plr != null) { + plr.sendMessage((c.usePrefix() ? C.PREFIX.s() + msg : msg)); + } else { + ConsolePlayer.getConsole().sendMessage((c.usePrefix() ? C.PREFIX.s() : "") + msg); + } + } + }); return true; } diff --git a/src/main/java/com/intellectualcrafters/plot/util/Permissions.java b/src/main/java/com/intellectualcrafters/plot/util/Permissions.java index b2f82d302..cf93cb97d 100644 --- a/src/main/java/com/intellectualcrafters/plot/util/Permissions.java +++ b/src/main/java/com/intellectualcrafters/plot/util/Permissions.java @@ -1,6 +1,9 @@ package com.intellectualcrafters.plot.util; +import java.util.HashMap; + import com.intellectualcrafters.plot.config.C; +import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.object.PlotPlayer; import com.plotsquared.general.commands.CommandCaller; @@ -10,7 +13,22 @@ public class Permissions { } public static boolean hasPermission(final PlotPlayer player, final String perm) { - return hasPermission((CommandCaller) player, perm); + if (!Settings.PERMISSION_CACHING) { + return hasPermission((CommandCaller) player, perm); + } + HashMap map = (HashMap) player.getMeta("perm"); + if (map != null) { + Boolean result = map.get(perm); + if (result != null) { + return result; + } + } else { + map = new HashMap<>(); + player.setMeta("perm", map); + } + boolean result = hasPermission((CommandCaller) player, perm); + map.put(perm, result); + return result; } public static boolean hasPermission(final CommandCaller player, String perm) { diff --git a/src/main/java/com/intellectualcrafters/plot/util/UUIDHandlerImplementation.java b/src/main/java/com/intellectualcrafters/plot/util/UUIDHandlerImplementation.java index de1010f1f..3004c965e 100644 --- a/src/main/java/com/intellectualcrafters/plot/util/UUIDHandlerImplementation.java +++ b/src/main/java/com/intellectualcrafters/plot/util/UUIDHandlerImplementation.java @@ -116,11 +116,11 @@ public abstract class UUIDHandlerImplementation { offline = null; } } - if (offline != null) { + if (offline != null && !offline.equals(uuid)) { unknown.remove(offline); final Set plots = PS.get().getPlots(offline); if (plots.size() > 0) { - for (final Plot plot : PS.get().getPlots(offline)) { + for (final Plot plot : plots) { plot.owner = uuid; } DBFunc.replaceUUID(offline, uuid); @@ -136,7 +136,7 @@ public abstract class UUIDHandlerImplementation { if (!offline.equals(uuid)) { final Set plots = PS.get().getPlots(offline); if (plots.size() > 0) { - for (final Plot plot : PS.get().getPlots(offline)) { + for (final Plot plot : plots) { plot.owner = uuid; } DBFunc.replaceUUID(offline, uuid); diff --git a/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java b/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java index 92fec7310..53318f7c7 100644 --- a/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java +++ b/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java @@ -334,7 +334,7 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen } } final Player player = event.getPlayer(); - final PlotPlayer pp = BukkitUtil.getPlayer(player); + final BukkitPlayer pp = (BukkitPlayer) BukkitUtil.getPlayer(player); Plot plot = pp.getCurrentPlot(); if (plot == null) { return; @@ -1035,27 +1035,26 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onInteract(final PlayerInteractEvent event) { - final Action action = event.getAction(); - final Block block = event.getClickedBlock(); - if (block == null) { - return; - } final Player player = event.getPlayer(); - final String world = player.getWorld().getName(); - if (!PS.get().isPlotWorld(world)) { + final PlotPlayer pp = BukkitUtil.getPlayer(player); + if (pp.getPlotWorld() == null) { return; } - final Location loc = BukkitUtil.getLocation(block.getLocation()); - final PlotPlayer pp = BukkitUtil.getPlayer(player); PlayerBlockEventType eventType = null; BukkitLazyBlock lb; + Location loc; + final Action action = event.getAction(); switch (action) { case PHYSICAL: { eventType = PlayerBlockEventType.TRIGGER_PHYSICAL; + Block block = event.getClickedBlock(); lb = new BukkitLazyBlock(block); + loc = BukkitUtil.getLocation(block.getLocation()); break; } case RIGHT_CLICK_BLOCK: { + Block block = event.getClickedBlock(); + loc = BukkitUtil.getLocation(block.getLocation()); final Material blockType = block.getType(); final int blockId = blockType.getId(); switch (blockType) { @@ -1137,8 +1136,9 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen lb = new BukkitLazyBlock(id, block); break; } - lb = new BukkitLazyBlock(new PlotBlock((short) hand.getTypeId(), (byte) hand.getDurability())); - switch (hand.getType()) { + Material handType = hand.getType(); + lb = new BukkitLazyBlock(new PlotBlock((short) handType.getId(), (byte) 0)); + switch (handType) { case MONSTER_EGG: case MONSTER_EGGS: { eventType = PlayerBlockEventType.SPAWN_MOB; @@ -1181,7 +1181,6 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen eventType = PlayerBlockEventType.EAT; break; } - case MINECART: case STORAGE_MINECART: case POWERED_MINECART: @@ -1205,6 +1204,8 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen break; } case LEFT_CLICK_BLOCK: { + Block block = event.getClickedBlock(); + loc = BukkitUtil.getLocation(block.getLocation()); eventType = PlayerBlockEventType.BREAK_BLOCK; lb = new BukkitLazyBlock(block); break; diff --git a/src/main/java/com/plotsquared/bukkit/object/BukkitLazyBlock.java b/src/main/java/com/plotsquared/bukkit/object/BukkitLazyBlock.java index c5e387acc..d711f5a4a 100644 --- a/src/main/java/com/plotsquared/bukkit/object/BukkitLazyBlock.java +++ b/src/main/java/com/plotsquared/bukkit/object/BukkitLazyBlock.java @@ -7,7 +7,7 @@ import com.intellectualcrafters.plot.object.PlotBlock; public class BukkitLazyBlock extends LazyBlock { - private int id = -1; + private int id; private Block block; private PlotBlock pb; @@ -30,7 +30,7 @@ public class BukkitLazyBlock extends LazyBlock { if (pb != null) { return pb; } - if (id == -1) { + if (id == 0) { id = block.getTypeId(); } byte data; @@ -121,8 +121,10 @@ public class BukkitLazyBlock extends LazyBlock { case 191: case 192: data = 0; + break; default: data = block.getData(); + break; } pb = new PlotBlock((short) id, data); return pb; @@ -131,7 +133,7 @@ public class BukkitLazyBlock extends LazyBlock { @Override public int getId() { - if (id == -1) { + if (id == 0) { id = block.getTypeId(); } return id; diff --git a/src/main/java/com/plotsquared/bukkit/object/BukkitPlayer.java b/src/main/java/com/plotsquared/bukkit/object/BukkitPlayer.java index f8628e6d1..ad379eaf1 100644 --- a/src/main/java/com/plotsquared/bukkit/object/BukkitPlayer.java +++ b/src/main/java/com/plotsquared/bukkit/object/BukkitPlayer.java @@ -14,7 +14,6 @@ import org.bukkit.permissions.PermissionDefault; import org.bukkit.plugin.PluginManager; import com.intellectualcrafters.plot.config.C; -import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.EconHandler; @@ -71,26 +70,10 @@ public class BukkitPlayer extends PlotPlayer { @Override public boolean hasPermission(final String node) { - if (Settings.PERMISSION_CACHING) { - if (noPerm.contains(node)) { - return false; - } - if (hasPerm.contains(node)) { - return true; - } - } if (offline && (EconHandler.manager != null)) { return EconHandler.manager.hasPermission(getName(), node); } - final boolean value = player.hasPermission(node); - if (Settings.PERMISSION_CACHING) { - if (value) { - hasPerm.add(node); - } else { - noPerm.add(node); - } - } - return value; + return player.hasPermission(node); } public Permission getPermission(final String node) { diff --git a/target/PlotSquared-Bukkit.jar b/target/PlotSquared-Bukkit.jar index c1845f565..602d991e1 100644 Binary files a/target/PlotSquared-Bukkit.jar and b/target/PlotSquared-Bukkit.jar differ