From 761803f7773c08105e934420db00c73019826578 Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Tue, 19 May 2020 12:41:51 +0100 Subject: [PATCH 01/52] Add option for roads to respect a plot area's flags and implement to PlayerEvents --- .../bukkit/listener/PlayerEvents.java | 189 +++++++++++++----- .../com/plotsquared/core/plot/PlotArea.java | 3 + 2 files changed, 146 insertions(+), 46 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java index 069bae68b..55859d226 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java @@ -42,6 +42,7 @@ import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.plot.PlotHandler; import com.plotsquared.core.plot.PlotId; import com.plotsquared.core.plot.PlotInventory; +import com.plotsquared.core.plot.flag.FlagContainer; import com.plotsquared.core.plot.flag.implementations.AnimalAttackFlag; import com.plotsquared.core.plot.flag.implementations.AnimalCapFlag; import com.plotsquared.core.plot.flag.implementations.AnimalInteractFlag; @@ -227,8 +228,8 @@ import java.util.regex.Pattern; @SuppressWarnings("unused") public class PlayerEvents extends PlotListener implements Listener { - public static final com.sk89q.worldedit.world.entity.EntityType FAKE_ENTITY_TYPE - = new com.sk89q.worldedit.world.entity.EntityType("plotsquared:fake"); + public static final com.sk89q.worldedit.world.entity.EntityType FAKE_ENTITY_TYPE = + new com.sk89q.worldedit.world.entity.EntityType("plotsquared:fake"); private boolean pistonBlocks = true; private float lastRadius; @@ -343,6 +344,10 @@ public class PlayerEvents extends PlotListener implements Listener { } Plot plot = location.getOwnedPlot(); if (plot == null) { + if (area.isRoadRespectingGlobalFlags() && area.getFlagContainer() + .getFlag(RedstoneFlag.class).getValue()) { + event.setNewCurrent(0); + } return; } if (!plot.getFlag(RedstoneFlag.class)) { @@ -565,11 +570,13 @@ public class PlayerEvents extends PlotListener implements Listener { return; } } - if (plot == null) { + if (plot == null && !area.isRoadRespectingGlobalFlags()) { return; } - List blockedCommands = plot.getFlag(BlockedCmdsFlag.class); + List blockedCommands = plot != null ? + plot.getFlag(BlockedCmdsFlag.class) : + area.getFlagContainer().getFlag(BlockedCmdsFlag.class).getValue(); if (!blockedCommands.isEmpty() && !Permissions .hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_INTERACT_BLOCKED_CMDS)) { String part = parts[0]; @@ -614,10 +621,12 @@ public class PlayerEvents extends PlotListener implements Listener { } if (pattern.matcher(msg).matches()) { String perm; - if (plot.isAdded(plotPlayer.getUUID())) { + if (plot != null && plot.isAdded(plotPlayer.getUUID())) { perm = "plots.admin.command.blocked-cmds.shared"; - } else { + } else if (!area.isRoadRespectingGlobalFlags()) { perm = "plots.admin.command.blocked-cmds.other"; + } else { + perm = "plots.admin.command.blocked-cmds.road"; } if (!Permissions.hasPermission(plotPlayer, perm)) { MainUtil.sendMessage(plotPlayer, Captions.COMMAND_BLOCKED); @@ -1683,12 +1692,22 @@ public class PlayerEvents extends PlotListener implements Listener { if (event.getClick() == ClickType.CREATIVE) { final Plot plot = pp.getCurrentPlot(); - if (plot != null && - plot.getFlag(PreventCreativeCopyFlag.class) && - !plot.isAdded(player.getUniqueId()) && - !Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_INTERACT_OTHER)) { - final ItemStack newStack = new ItemStack(newItem.getType(), newItem.getAmount()); - event.setCursor(newStack); + if (plot != null) { + if (plot.getFlag(PreventCreativeCopyFlag.class) && !plot + .isAdded(player.getUniqueId()) && !Permissions + .hasPermission(pp, Captions.PERMISSION_ADMIN_INTERACT_OTHER)) { + final ItemStack newStack = + new ItemStack(newItem.getType(), newItem.getAmount()); + event.setCursor(newStack); + } + } else { + PlotArea area = pp.getPlotAreaAbs(); + if (area != null && area.isRoadRespectingGlobalFlags() && area.getFlagContainer() + .getFlag(PreventCreativeCopyFlag.class).getValue()) { + final ItemStack newStack = + new ItemStack(newItem.getType(), newItem.getAmount()); + event.setCursor(newStack); + } } return; } @@ -1805,7 +1824,9 @@ public class PlayerEvents extends PlotListener implements Listener { Plot plot = location.getPlotAbs(); PlotPlayer pp = BukkitUtil.getPlayer(e.getPlayer()); if (plot == null) { - if (!Permissions.hasPermission(pp, "plots.admin.interact.road")) { + if (!area.isRoadRespectingGlobalFlags() && !area.getFlagContainer() + .getFlag(MiscInteractFlag.class).getValue() && !Permissions + .hasPermission(pp, "plots.admin.interact.road")) { MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, "plots.admin.interact.road"); e.setCancelled(true); } @@ -1818,7 +1839,8 @@ public class PlayerEvents extends PlotListener implements Listener { return; } } - if (!plot.hasOwner()) { + if (!plot.hasOwner() && !area.isRoadRespectingGlobalFlags() && !area.getFlagContainer() + .getFlag(MiscInteractFlag.class).getValue()) { if (!Permissions.hasPermission(pp, "plots.admin.interact.unowned")) { MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, "plots.admin.interact.unowned"); @@ -2514,57 +2536,66 @@ public class PlayerEvents extends PlotListener implements Listener { Player p = event.getPlayer(); PlotPlayer pp = BukkitUtil.getPlayer(p); Plot plot = area.getPlot(location); - if (plot == null) { + if (plot == null && !area.isRoadRespectingGlobalFlags()) { if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_INTERACT_ROAD)) { MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_INTERACT_ROAD); event.setCancelled(true); } - } else if (!plot.hasOwner()) { + } else if (plot != null && !plot.hasOwner()) { if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_INTERACT_UNOWNED)) { MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_INTERACT_UNOWNED); event.setCancelled(true); } - } else if (!plot.isAdded(pp.getUUID())) { + } else if ((plot != null && !plot.isAdded(pp.getUUID())) || area + .isRoadRespectingGlobalFlags()) { final Entity entity = event.getRightClicked(); final com.sk89q.worldedit.world.entity.EntityType entityType = BukkitAdapter.adapt(entity.getType()); - if (EntityCategories.HOSTILE.contains(entityType) && plot - .getFlag(HostileInteractFlag.class)) { + FlagContainer flagContainer; + if (plot == null) { + flagContainer = area.getFlagContainer(); + } else { + flagContainer = plot.getFlagContainer(); + } + + if (EntityCategories.HOSTILE.contains(entityType) && flagContainer + .getFlag(HostileInteractFlag.class).getValue()) { return; } - if (EntityCategories.ANIMAL.contains(entityType) && plot - .getFlag(AnimalInteractFlag.class)) { + if (EntityCategories.ANIMAL.contains(entityType) && flagContainer + .getFlag(AnimalInteractFlag.class).getValue()) { return; } // This actually makes use of the interface, so we don't use the // category - if (entity instanceof Tameable && ((Tameable) entity).isTamed() && plot - .getFlag(TamedInteractFlag.class)) { + if (entity instanceof Tameable && ((Tameable) entity).isTamed() && flagContainer + .getFlag(TamedInteractFlag.class).getValue()) { return; } - if (EntityCategories.VEHICLE.contains(entityType) && plot - .getFlag(VehicleUseFlag.class)) { + if (EntityCategories.VEHICLE.contains(entityType) && flagContainer + .getFlag(VehicleUseFlag.class).getValue()) { return; } - if (EntityCategories.PLAYER.contains(entityType) && plot - .getFlag(PlayerInteractFlag.class)) { + if (EntityCategories.PLAYER.contains(entityType) && flagContainer + .getFlag(PlayerInteractFlag.class).getValue()) { return; } - if (EntityCategories.VILLAGER.contains(entityType) && plot - .getFlag(VillagerInteractFlag.class)) { + if (EntityCategories.VILLAGER.contains(entityType) && flagContainer + .getFlag(VillagerInteractFlag.class).getValue()) { return; } if ((EntityCategories.HANGING.contains(entityType) || EntityCategories.OTHER - .contains(entityType)) && plot.getFlag(MiscInteractFlag.class)) { + .contains(entityType)) && flagContainer.getFlag(MiscInteractFlag.class) + .getValue()) { return; } @@ -2713,12 +2744,14 @@ public class PlayerEvents extends PlotListener implements Listener { Plot plot; String stub; + boolean isPlot = true; if (dplot == null && vplot == null) { if (dArea == null) { return true; } plot = null; stub = "road"; + isPlot = false; } else { // Prioritize plots for close to seamless pvp zones if (victim.getTicksLived() > damager.getTicksLived()) { @@ -2748,6 +2781,8 @@ public class PlayerEvents extends PlotListener implements Listener { stub = "unowned"; } } + FlagContainer areaFlags = vArea.getFlagContainer(); + boolean roadFlags = vArea.isRoadRespectingGlobalFlags(); Player player; if (damager instanceof Player) { // attacker is player @@ -2781,8 +2816,7 @@ public class PlayerEvents extends PlotListener implements Listener { } if (EntityCategories.HANGING.contains(entityType)) { // hanging - if (plot != null && (plot.getFlag(HangingBreakFlag.class)) || plot - .isAdded(plotPlayer.getUUID())) { + if ((plot.getFlag(HangingBreakFlag.class)) || plot.isAdded(plotPlayer.getUUID())) { if (Settings.Done.RESTRICT_BUILDING && DoneFlag.isDone(plot)) { if (!Permissions .hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_BUILD_OTHER)) { @@ -2809,8 +2843,13 @@ public class PlayerEvents extends PlotListener implements Listener { return false; } } else if (EntityCategories.HOSTILE.contains(entityType)) { - if (plot != null && (plot.getFlag(HostileAttackFlag.class) || plot - .getFlag(PveFlag.class) || plot.isAdded(plotPlayer.getUUID()))) { + if (isPlot) { + if (plot.getFlag(HostileAttackFlag.class) || plot.getFlag(PveFlag.class) || plot + .isAdded(plotPlayer.getUUID())) { + return true; + } + } else if (roadFlags && (areaFlags.getFlag(HostileAttackFlag.class).getValue() + || areaFlags.getFlag(PveFlag.class).getValue())) { return true; } if (!Permissions.hasPermission(plotPlayer, "plots.admin.pve." + stub)) { @@ -2819,8 +2858,13 @@ public class PlayerEvents extends PlotListener implements Listener { return false; } } else if (EntityCategories.TAMEABLE.contains(entityType)) { // victim is tameable - if (plot != null && (plot.getFlag(TamedAttackFlag.class) || plot - .getFlag(PveFlag.class) || plot.isAdded(plotPlayer.getUUID()))) { + if (isPlot) { + if (plot.getFlag(TamedAttackFlag.class) || plot.getFlag(PveFlag.class) || plot + .isAdded(plotPlayer.getUUID())) { + return true; + } + } else if (roadFlags && (areaFlags.getFlag(TamedAttackFlag.class).getValue() + || areaFlags.getFlag(PveFlag.class).getValue())) { return true; } if (!Permissions.hasPermission(plotPlayer, "plots.admin.pve." + stub)) { @@ -2829,7 +2873,7 @@ public class PlayerEvents extends PlotListener implements Listener { return false; } } else if (EntityCategories.PLAYER.contains(entityType)) { - if (plot != null) { + if (isPlot) { if (!plot.getFlag(PvpFlag.class) && !Permissions .hasPermission(plotPlayer, "plots.admin.pvp." + stub)) { MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT, @@ -2838,6 +2882,8 @@ public class PlayerEvents extends PlotListener implements Listener { } else { return true; } + } else if (roadFlags && areaFlags.getFlag(PvpFlag.class).getValue()) { + return true; } if (!Permissions.hasPermission(plotPlayer, "plots.admin.pvp." + stub)) { MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT, @@ -2845,8 +2891,13 @@ public class PlayerEvents extends PlotListener implements Listener { return false; } } else if (EntityCategories.ANIMAL.contains(entityType)) { // victim is animal - if (plot != null && (plot.getFlag(AnimalAttackFlag.class) || plot - .getFlag(PveFlag.class) || plot.isAdded(plotPlayer.getUUID()))) { + if (isPlot) { + if (plot.getFlag(AnimalAttackFlag.class) || plot.getFlag(PveFlag.class) || plot + .isAdded(plotPlayer.getUUID())) { + return true; + } + } else if (roadFlags && (areaFlags.getFlag(AnimalAttackFlag.class).getValue() + || areaFlags.getFlag(PveFlag.class).getValue())) { return true; } if (!Permissions.hasPermission(plotPlayer, "plots.admin.pve." + stub)) { @@ -2858,8 +2909,12 @@ public class PlayerEvents extends PlotListener implements Listener { .contains(entityType)) { // Vehicles are managed in vehicle destroy event return true; } else { // victim is something else - if (plot != null && (plot.getFlag(PveFlag.class) || plot - .isAdded(plotPlayer.getUUID()))) { + if (isPlot) { + if (plot != null && (plot.getFlag(PveFlag.class) || plot + .isAdded(plotPlayer.getUUID()))) { + return true; + } + } else if (roadFlags && areaFlags.getFlag(PveFlag.class).getValue()) { return true; } if (!Permissions.hasPermission(plotPlayer, "plots.admin.pve." + stub)) { @@ -2880,6 +2935,9 @@ public class PlayerEvents extends PlotListener implements Listener { return false; } } + if (vplot == null && roadFlags && areaFlags.getFlag(PveFlag.class).getValue()) { + return true; + } return ((vplot != null && vplot.getFlag(PveFlag.class)) || !(damager instanceof Arrow && !(victim instanceof Creature))); } @@ -2980,8 +3038,17 @@ public class PlayerEvents extends PlotListener implements Listener { if (event.getEntityType() != EntityType.PLAYER) { return; } - Plot plot = BukkitUtil.getLocation(event.getEntity()).getOwnedPlot(); + Location location = BukkitUtil.getLocation(event.getEntity()); + PlotArea area = location.getPlotArea(); + if (area == null) { + return; + } + Plot plot = location.getOwnedPlot(); if (plot == null) { + if (area.isRoadRespectingGlobalFlags() && area.getFlagContainer() + .getFlag(InvincibleFlag.class).getValue()) { + event.setCancelled(true); + } return; } if (plot.getFlag(InvincibleFlag.class)) { @@ -2992,8 +3059,17 @@ public class PlayerEvents extends PlotListener implements Listener { @EventHandler public void onItemDrop(PlayerDropItemEvent event) { Player player = event.getPlayer(); PlotPlayer pp = BukkitUtil.getPlayer(player); - Plot plot = BukkitUtil.getLocation(player).getOwnedPlot(); + Location location = pp.getLocation(); + PlotArea area = location.getPlotArea(); + if (area == null) { + return; + } + Plot plot = location.getOwnedPlot(); if (plot == null) { + if (area.isRoadRespectingGlobalFlags() && area.getFlagContainer() + .getFlag(ItemDropFlag.class).getValue()) { + event.setCancelled(true); + } return; } UUID uuid = pp.getUUID(); @@ -3009,8 +3085,17 @@ public class PlayerEvents extends PlotListener implements Listener { if (ent instanceof Player) { Player player = (Player) ent; PlotPlayer pp = BukkitUtil.getPlayer(player); - Plot plot = BukkitUtil.getLocation(player).getOwnedPlot(); + Location location = pp.getLocation(); + PlotArea area = location.getPlotArea(); + if (area == null) { + return; + } + Plot plot = location.getOwnedPlot(); if (plot == null) { + if (area.isRoadRespectingGlobalFlags() && area.getFlagContainer() + .getFlag(DropProtectionFlag.class).getValue()) { + event.setCancelled(true); + } return; } UUID uuid = pp.getUUID(); @@ -3021,8 +3106,20 @@ public class PlayerEvents extends PlotListener implements Listener { } @EventHandler public void onDeath(final PlayerDeathEvent event) { - final Plot plot = BukkitUtil.getPlayer(event.getEntity()).getCurrentPlot(); - if (plot != null && plot.getFlag(KeepInventoryFlag.class)) { + Location location = BukkitUtil.getLocation(event.getEntity()); + PlotArea area = location.getPlotArea(); + if (area == null) { + return; + } + Plot plot = location.getOwnedPlot(); + if (plot == null) { + if (area.isRoadRespectingGlobalFlags() && area.getFlagContainer() + .getFlag(KeepInventoryFlag.class).getValue()) { + event.setCancelled(true); + } + return; + } + if (plot.getFlag(KeepInventoryFlag.class)) { event.setKeepInventory(true); } } diff --git a/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java b/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java index 45749d9e1..712339af6 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java +++ b/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java @@ -118,6 +118,7 @@ public abstract class PlotArea { @Getter private GameMode gameMode = GameModes.CREATIVE; @Getter private Map> prices = new HashMap<>(); @Getter(AccessLevel.PROTECTED) private List schematics = new ArrayList<>(); + @Getter private boolean roadRespectingGlobalFlags = false; private boolean worldBorder = false; private boolean useEconomy = false; private int hash; @@ -370,6 +371,7 @@ public abstract class PlotArea { this.spawnEggs = config.getBoolean("event.spawn.egg"); this.spawnCustom = config.getBoolean("event.spawn.custom"); this.spawnBreeding = config.getBoolean("event.spawn.breeding"); + this.roadRespectingGlobalFlags = config.getBoolean("road.respect-global-flags"); loadConfiguration(config); } @@ -413,6 +415,7 @@ public abstract class PlotArea { options.put("world.max_height", this.getMaxBuildHeight()); options.put("world.min_height", this.getMinBuildHeight()); options.put("world.gamemode", this.getGameMode().getName().toLowerCase()); + options.put("road.respect-global-flags", this.isRoadRespectingGlobalFlags()); if (this.getType() != PlotAreaType.NORMAL) { options.put("generator.terrain", this.getTerrain()); From 22c26fe9625c69231b54a8628757659cccdfc4c2 Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Tue, 19 May 2020 13:07:50 +0100 Subject: [PATCH 02/52] Add PlotArea#getFlag --- .../bukkit/listener/PlayerEvents.java | 61 +++++++++---------- .../com/plotsquared/core/plot/PlotArea.java | 24 ++++++++ 2 files changed, 53 insertions(+), 32 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java index 55859d226..421de869b 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java @@ -344,8 +344,8 @@ public class PlayerEvents extends PlotListener implements Listener { } Plot plot = location.getOwnedPlot(); if (plot == null) { - if (area.isRoadRespectingGlobalFlags() && area.getFlagContainer() - .getFlag(RedstoneFlag.class).getValue()) { + if (area.isRoadRespectingGlobalFlags() && area. + getFlag(RedstoneFlag.class)) { event.setNewCurrent(0); } return; @@ -576,7 +576,7 @@ public class PlayerEvents extends PlotListener implements Listener { List blockedCommands = plot != null ? plot.getFlag(BlockedCmdsFlag.class) : - area.getFlagContainer().getFlag(BlockedCmdsFlag.class).getValue(); + area.getFlag(BlockedCmdsFlag.class); if (!blockedCommands.isEmpty() && !Permissions .hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_INTERACT_BLOCKED_CMDS)) { String part = parts[0]; @@ -1702,8 +1702,8 @@ public class PlayerEvents extends PlotListener implements Listener { } } else { PlotArea area = pp.getPlotAreaAbs(); - if (area != null && area.isRoadRespectingGlobalFlags() && area.getFlagContainer() - .getFlag(PreventCreativeCopyFlag.class).getValue()) { + if (area != null && area.isRoadRespectingGlobalFlags() && area + .getFlag(PreventCreativeCopyFlag.class)) { final ItemStack newStack = new ItemStack(newItem.getType(), newItem.getAmount()); event.setCursor(newStack); @@ -1824,9 +1824,8 @@ public class PlayerEvents extends PlotListener implements Listener { Plot plot = location.getPlotAbs(); PlotPlayer pp = BukkitUtil.getPlayer(e.getPlayer()); if (plot == null) { - if (!area.isRoadRespectingGlobalFlags() && !area.getFlagContainer() - .getFlag(MiscInteractFlag.class).getValue() && !Permissions - .hasPermission(pp, "plots.admin.interact.road")) { + if (!area.isRoadRespectingGlobalFlags() && !area.getFlag(MiscInteractFlag.class) + && !Permissions.hasPermission(pp, "plots.admin.interact.road")) { MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, "plots.admin.interact.road"); e.setCancelled(true); } @@ -1839,8 +1838,8 @@ public class PlayerEvents extends PlotListener implements Listener { return; } } - if (!plot.hasOwner() && !area.isRoadRespectingGlobalFlags() && !area.getFlagContainer() - .getFlag(MiscInteractFlag.class).getValue()) { + if (!plot.hasOwner() && !area.isRoadRespectingGlobalFlags() && !area + .getFlag(MiscInteractFlag.class)) { if (!Permissions.hasPermission(pp, "plots.admin.interact.unowned")) { MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, "plots.admin.interact.unowned"); @@ -2781,8 +2780,10 @@ public class PlayerEvents extends PlotListener implements Listener { stub = "unowned"; } } - FlagContainer areaFlags = vArea.getFlagContainer(); - boolean roadFlags = vArea.isRoadRespectingGlobalFlags(); + boolean roadFlags = vArea != null ? + vArea.isRoadRespectingGlobalFlags() : + dArea.isRoadRespectingGlobalFlags(); + PlotArea area = vArea != null ? vArea : dArea; Player player; if (damager instanceof Player) { // attacker is player @@ -2816,7 +2817,8 @@ public class PlayerEvents extends PlotListener implements Listener { } if (EntityCategories.HANGING.contains(entityType)) { // hanging - if ((plot.getFlag(HangingBreakFlag.class)) || plot.isAdded(plotPlayer.getUUID())) { + if (plot != null && (plot.getFlag(HangingBreakFlag.class) || plot + .isAdded(plotPlayer.getUUID()))) { if (Settings.Done.RESTRICT_BUILDING && DoneFlag.isDone(plot)) { if (!Permissions .hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_BUILD_OTHER)) { @@ -2848,8 +2850,8 @@ public class PlayerEvents extends PlotListener implements Listener { .isAdded(plotPlayer.getUUID())) { return true; } - } else if (roadFlags && (areaFlags.getFlag(HostileAttackFlag.class).getValue() - || areaFlags.getFlag(PveFlag.class).getValue())) { + } else if (roadFlags && (area.getFlag(HostileAttackFlag.class) || area + .getFlag(PveFlag.class))) { return true; } if (!Permissions.hasPermission(plotPlayer, "plots.admin.pve." + stub)) { @@ -2863,8 +2865,8 @@ public class PlayerEvents extends PlotListener implements Listener { .isAdded(plotPlayer.getUUID())) { return true; } - } else if (roadFlags && (areaFlags.getFlag(TamedAttackFlag.class).getValue() - || areaFlags.getFlag(PveFlag.class).getValue())) { + } else if (roadFlags && (area.getFlag(TamedAttackFlag.class) || area + .getFlag(PveFlag.class))) { return true; } if (!Permissions.hasPermission(plotPlayer, "plots.admin.pve." + stub)) { @@ -2882,7 +2884,7 @@ public class PlayerEvents extends PlotListener implements Listener { } else { return true; } - } else if (roadFlags && areaFlags.getFlag(PvpFlag.class).getValue()) { + } else if (roadFlags && area.getFlag(PvpFlag.class)) { return true; } if (!Permissions.hasPermission(plotPlayer, "plots.admin.pvp." + stub)) { @@ -2896,8 +2898,8 @@ public class PlayerEvents extends PlotListener implements Listener { .isAdded(plotPlayer.getUUID())) { return true; } - } else if (roadFlags && (areaFlags.getFlag(AnimalAttackFlag.class).getValue() - || areaFlags.getFlag(PveFlag.class).getValue())) { + } else if (roadFlags && (area.getFlag(AnimalAttackFlag.class) || area + .getFlag(PveFlag.class))) { return true; } if (!Permissions.hasPermission(plotPlayer, "plots.admin.pve." + stub)) { @@ -2910,11 +2912,10 @@ public class PlayerEvents extends PlotListener implements Listener { return true; } else { // victim is something else if (isPlot) { - if (plot != null && (plot.getFlag(PveFlag.class) || plot - .isAdded(plotPlayer.getUUID()))) { + if (plot.getFlag(PveFlag.class) || plot.isAdded(plotPlayer.getUUID())) { return true; } - } else if (roadFlags && areaFlags.getFlag(PveFlag.class).getValue()) { + } else if (roadFlags && area.getFlag(PveFlag.class)) { return true; } if (!Permissions.hasPermission(plotPlayer, "plots.admin.pve." + stub)) { @@ -2935,7 +2936,7 @@ public class PlayerEvents extends PlotListener implements Listener { return false; } } - if (vplot == null && roadFlags && areaFlags.getFlag(PveFlag.class).getValue()) { + if (vplot == null && roadFlags && area.getFlag(PveFlag.class)) { return true; } return ((vplot != null && vplot.getFlag(PveFlag.class)) || !(damager instanceof Arrow @@ -3045,8 +3046,7 @@ public class PlayerEvents extends PlotListener implements Listener { } Plot plot = location.getOwnedPlot(); if (plot == null) { - if (area.isRoadRespectingGlobalFlags() && area.getFlagContainer() - .getFlag(InvincibleFlag.class).getValue()) { + if (area.isRoadRespectingGlobalFlags() && area.getFlag(InvincibleFlag.class)) { event.setCancelled(true); } return; @@ -3066,8 +3066,7 @@ public class PlayerEvents extends PlotListener implements Listener { } Plot plot = location.getOwnedPlot(); if (plot == null) { - if (area.isRoadRespectingGlobalFlags() && area.getFlagContainer() - .getFlag(ItemDropFlag.class).getValue()) { + if (area.isRoadRespectingGlobalFlags() && area.getFlag(ItemDropFlag.class)) { event.setCancelled(true); } return; @@ -3092,8 +3091,7 @@ public class PlayerEvents extends PlotListener implements Listener { } Plot plot = location.getOwnedPlot(); if (plot == null) { - if (area.isRoadRespectingGlobalFlags() && area.getFlagContainer() - .getFlag(DropProtectionFlag.class).getValue()) { + if (area.isRoadRespectingGlobalFlags() && area.getFlag(DropProtectionFlag.class)) { event.setCancelled(true); } return; @@ -3113,8 +3111,7 @@ public class PlayerEvents extends PlotListener implements Listener { } Plot plot = location.getOwnedPlot(); if (plot == null) { - if (area.isRoadRespectingGlobalFlags() && area.getFlagContainer() - .getFlag(KeepInventoryFlag.class).getValue()) { + if (area.isRoadRespectingGlobalFlags() && area.getFlag(KeepInventoryFlag.class)) { event.setCancelled(true); } return; diff --git a/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java b/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java index 712339af6..b6e630e40 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java +++ b/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java @@ -1072,4 +1072,28 @@ public abstract class PlotArea { } return flags; } + + /** + * Get the value associated with the specified flag. This will look at + * the default values stored in {@link GlobalFlagContainer}. + * + * @param flagClass The flag type (Class) + * @return The flag value + */ + public T getFlag(final Class> flagClass) { + return this.flagContainer.getFlag(flagClass).getValue(); + } + + /** + * Get the value associated with the specified flag. This will look at + * the default values stored in {@link GlobalFlagContainer}. + * + * @param flag The flag type (Any instance of the flag) + * @return The flag value + */ + public > T getFlag(final V flag) { + final Class flagClass = flag.getClass(); + final PlotFlag flagInstance = this.flagContainer.getFlagErased(flagClass); + return FlagContainer.castUnsafe(flagInstance).getValue(); + } } From 14baead342b999dd4bff75a24d93fee5bf23ac5b Mon Sep 17 00:00:00 2001 From: EpiCanard Date: Tue, 23 Jun 2020 01:20:17 +0200 Subject: [PATCH 03/52] Add placeholder to get the value of a plot flag --- .../bukkit/placeholder/Placeholders.java | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/Placeholders.java b/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/Placeholders.java index 0ae44fbcb..39de8a7fd 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/Placeholders.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/Placeholders.java @@ -29,6 +29,8 @@ import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; +import com.plotsquared.core.plot.flag.GlobalFlagContainer; +import com.plotsquared.core.plot.flag.PlotFlag; import me.clip.placeholderapi.PlaceholderAPIPlugin; import me.clip.placeholderapi.expansion.PlaceholderExpansion; import org.bukkit.Bukkit; @@ -36,9 +38,13 @@ import org.bukkit.entity.Player; import java.util.Set; import java.util.UUID; +import java.util.regex.Matcher; +import java.util.regex.Pattern; public class Placeholders extends PlaceholderExpansion { + private Pattern flagPattern = Pattern.compile("currentplot_flag_(.+)"); + public Placeholders() { } @@ -59,7 +65,7 @@ public class Placeholders extends PlaceholderExpansion { } @Override public String getVersion() { - return "2.4"; + return "2.5"; } @Override public String onPlaceholderRequest(Player p, String identifier) { @@ -124,7 +130,7 @@ public class Placeholders extends PlaceholderExpansion { return ""; } - String name = PlotSquared.get().getImpromptuUUIDPipeline() .getSingle(uid, + String name = PlotSquared.get().getImpromptuUUIDPipeline().getSingle(uid, Settings.UUID.BLOCKING_TIMEOUT); if (name != null) { @@ -181,6 +187,31 @@ public class Placeholders extends PlaceholderExpansion { default: break; } + final Matcher matcher = this.flagPattern.matcher(identifier); + if (matcher.find()) { + return getFlag(plot, matcher.group(1)); + } + return ""; + } + + /** + * Return the flag value from its name on the current plot. + * If the flag doesn't exist it return an empty string. + * If the flag exists but it is not set on current plot it return the default value. + * + * @param plot Current plot where the player is + * @param flagName Name of flag to get from current plot + * @return The value of flag serialized in string + */ + private String getFlag(final Plot plot, final String flagName) { + final PlotFlag flag = GlobalFlagContainer.getInstance().getFlagFromString(flagName); + if (flag != null) { + return plot.getFlags().stream() + .filter(pflag -> pflag.getName().equals(flagName)).findFirst() + .map(PlotFlag::getValue) + .map(Object::toString) + .orElseGet(() -> plot.getFlagContainer().getFlagErased(flag.getClass()).toString()); + } return ""; } } From 7fbac4f2868b331df7ab07414986ed5c099d8b01 Mon Sep 17 00:00:00 2001 From: EpiCanard Date: Wed, 24 Jun 2020 00:51:27 +0200 Subject: [PATCH 04/52] Add a second placeholder to support only local flag of current plot --- .../bukkit/placeholder/Placeholders.java | 43 +++++++++++-------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/Placeholders.java b/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/Placeholders.java index 39de8a7fd..ce2445052 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/Placeholders.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/Placeholders.java @@ -38,13 +38,9 @@ import org.bukkit.entity.Player; import java.util.Set; import java.util.UUID; -import java.util.regex.Matcher; -import java.util.regex.Pattern; public class Placeholders extends PlaceholderExpansion { - private Pattern flagPattern = Pattern.compile("currentplot_flag_(.+)"); - public Placeholders() { } @@ -130,8 +126,8 @@ public class Placeholders extends PlaceholderExpansion { return ""; } - String name = PlotSquared.get().getImpromptuUUIDPipeline().getSingle(uid, - Settings.UUID.BLOCKING_TIMEOUT); + String name = PlotSquared.get().getImpromptuUUIDPipeline() + .getSingle(uid, Settings.UUID.BLOCKING_TIMEOUT); if (name != null) { return name; @@ -187,31 +183,40 @@ public class Placeholders extends PlaceholderExpansion { default: break; } - final Matcher matcher = this.flagPattern.matcher(identifier); - if (matcher.find()) { - return getFlag(plot, matcher.group(1)); + if (identifier.startsWith("currentplot_localflag_")) { + final String[] splitValues = identifier.split("currentplot_localflag_"); + return (splitValues.length >= 2) ? getFlagValue(plot, splitValues[1], false) : ""; + } + if (identifier.startsWith("currentplot_flag_")) { + final String[] splitValues = identifier.split("currentplot_flag_"); + return (splitValues.length >= 2) ? getFlagValue(plot, splitValues[1], true) : ""; } return ""; } /** * Return the flag value from its name on the current plot. - * If the flag doesn't exist it return an empty string. - * If the flag exists but it is not set on current plot it return the default value. + * If the flag doesn't exist it returns an empty string. + * If the flag exists but it is not set on current plot and the parameter inherit is set to true, + * it returns the default value. * * @param plot Current plot where the player is * @param flagName Name of flag to get from current plot + * @param inherit Define if it returns only the flag set on currentplot or also inherited flag * @return The value of flag serialized in string */ - private String getFlag(final Plot plot, final String flagName) { + private String getFlagValue(final Plot plot, final String flagName, final boolean inherit) { final PlotFlag flag = GlobalFlagContainer.getInstance().getFlagFromString(flagName); - if (flag != null) { - return plot.getFlags().stream() - .filter(pflag -> pflag.getName().equals(flagName)).findFirst() - .map(PlotFlag::getValue) - .map(Object::toString) - .orElseGet(() -> plot.getFlagContainer().getFlagErased(flag.getClass()).toString()); + if (flag == null) { + return ""; } - return ""; + + if (inherit) { + return plot.getFlag(flag).toString(); + } else { + final PlotFlag plotFlag = plot.getFlagContainer().queryLocal(flag.getClass()); + return (plotFlag != null) ? plotFlag.getValue().toString() : ""; + } + } } From f64026af1ae80cfb262b3425c43bd69c1c265a74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Wed, 24 Jun 2020 15:26:06 +0200 Subject: [PATCH 05/52] Only initialise EconHandler when economy is enabled and stop accessing the static instance directly. --- .../bukkit/player/BukkitPlayer.java | 4 +- .../bukkit/util/BukkitEconHandler.java | 18 ++++----- .../com/plotsquared/core/PlotSquared.java | 3 +- .../com/plotsquared/core/command/Auto.java | 10 ++--- .../com/plotsquared/core/command/Buy.java | 4 +- .../com/plotsquared/core/command/Claim.java | 6 +-- .../plotsquared/core/command/DebugExec.java | 2 +- .../com/plotsquared/core/command/Delete.java | 4 +- .../com/plotsquared/core/command/ListCmd.java | 6 +-- .../plotsquared/core/command/MainCommand.java | 12 +++--- .../com/plotsquared/core/command/Merge.java | 18 ++++----- .../components/ComponentPresetManager.java | 8 ++-- .../plotsquared/core/player/PlotPlayer.java | 10 ++--- .../plotsquared/core/util/EconHandler.java | 38 +++++++++++++------ build.gradle | 2 + 15 files changed, 80 insertions(+), 65 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java b/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java index acbc31984..643039600 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java @@ -155,8 +155,8 @@ public class BukkitPlayer extends PlotPlayer { } @Override public boolean hasPermission(final String permission) { - if (this.offline && EconHandler.manager != null) { - return EconHandler.manager.hasPermission(getName(), permission); + if (this.offline && EconHandler.getEconHandler() != null) { + return EconHandler.getEconHandler().hasPermission(getName(), permission); } return this.player.hasPermission(permission); } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEconHandler.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEconHandler.java index 1efd7fea5..b8387efed 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEconHandler.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEconHandler.java @@ -48,28 +48,26 @@ public class BukkitEconHandler extends EconHandler { return this.econ != null && this.perms != null; } - private boolean setupPermissions() { + private void setupPermissions() { RegisteredServiceProvider permissionProvider = Bukkit.getServer().getServicesManager().getRegistration(Permission.class); if (permissionProvider != null) { this.perms = permissionProvider.getProvider(); } - return this.perms != null; } - private boolean setupEconomy() { + private void setupEconomy() { if (Bukkit.getServer().getPluginManager().getPlugin("Vault") == null) { - return false; + return; } RegisteredServiceProvider economyProvider = Bukkit.getServer().getServicesManager().getRegistration(Economy.class); if (economyProvider != null) { this.econ = economyProvider.getProvider(); } - return this.econ != null; } - @Override public double getMoney(PlotPlayer player) { + @Override public double getMoney(PlotPlayer player) { double bal = super.getMoney(player); if (Double.isNaN(bal)) { return this.econ.getBalance(((BukkitPlayer) player).player); @@ -77,11 +75,11 @@ public class BukkitEconHandler extends EconHandler { return bal; } - @Override public void withdrawMoney(PlotPlayer player, double amount) { + @Override public void withdrawMoney(PlotPlayer player, double amount) { this.econ.withdrawPlayer(((BukkitPlayer) player).player, amount); } - @Override public void depositMoney(PlotPlayer player, double amount) { + @Override public void depositMoney(PlotPlayer player, double amount) { this.econ.depositPlayer(((BukkitPlayer) player).player, amount); } @@ -93,11 +91,11 @@ public class BukkitEconHandler extends EconHandler { return this.perms.playerHas(world, Bukkit.getOfflinePlayer(player), perm); } - @Override public double getBalance(PlotPlayer player) { + @Override public double getBalance(PlotPlayer player) { return this.econ.getBalance(player.getName()); } - public void setPermission(String world, String player, String perm, boolean value) { + @Deprecated public void setPermission(String world, String player, String perm, boolean value) { if (value) { this.perms.playerAdd(world, player, perm); } else { diff --git a/Core/src/main/java/com/plotsquared/core/PlotSquared.java b/Core/src/main/java/com/plotsquared/core/PlotSquared.java index 3f7f35229..30d738afc 100644 --- a/Core/src/main/java/com/plotsquared/core/PlotSquared.java +++ b/Core/src/main/java/com/plotsquared/core/PlotSquared.java @@ -304,8 +304,7 @@ public class PlotSquared { } // Economy if (Settings.Enabled_Components.ECONOMY) { - TaskManager - .runTask(() -> EconHandler.manager = PlotSquared.this.IMP.getEconomyHandler()); + TaskManager.runTask(() -> EconHandler.initializeEconHandler()); } if (Settings.Enabled_Components.COMPONENT_PRESETS) { diff --git a/Core/src/main/java/com/plotsquared/core/command/Auto.java b/Core/src/main/java/com/plotsquared/core/command/Auto.java index 9658556d9..4c75de3f8 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Auto.java +++ b/Core/src/main/java/com/plotsquared/core/command/Auto.java @@ -157,9 +157,9 @@ public class Auto extends SubCommand { @Override public boolean onCommand(final PlotPlayer player, String[] args) { PlotArea plotarea = player.getApplicablePlotArea(); if (plotarea == null) { - if (EconHandler.manager != null) { + if (EconHandler.getEconHandler() != null) { for (PlotArea area : PlotSquared.get().getPlotAreaManager().getAllPlotAreas()) { - if (EconHandler.manager + if (EconHandler.getEconHandler() .hasPermission(area.getWorldName(), player.getName(), "plots.auto")) { if (plotarea != null) { plotarea = null; @@ -253,18 +253,18 @@ public class Auto extends SubCommand { return true; } } - if (EconHandler.manager != null && plotarea.useEconomy()) { + if (EconHandler.getEconHandler() != null && plotarea.useEconomy()) { Expression costExp = plotarea.getPrices().get("claim"); double cost = costExp.evaluate((double) (Settings.Limit.GLOBAL ? player.getPlotCount() : player.getPlotCount(plotarea.getWorldName()))); cost = (size_x * size_z) * cost; if (cost > 0d) { - if (!force && EconHandler.manager.getMoney(player) < cost) { + if (!force && EconHandler.getEconHandler().getMoney(player) < cost) { sendMessage(player, Captions.CANNOT_AFFORD_PLOT, "" + cost); return true; } - EconHandler.manager.withdrawMoney(player, cost); + EconHandler.getEconHandler().withdrawMoney(player, cost); sendMessage(player, Captions.REMOVED_BALANCE, cost + ""); } } diff --git a/Core/src/main/java/com/plotsquared/core/command/Buy.java b/Core/src/main/java/com/plotsquared/core/command/Buy.java index 036e2412f..337801385 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Buy.java +++ b/Core/src/main/java/com/plotsquared/core/command/Buy.java @@ -58,7 +58,7 @@ public class Buy extends Command { RunnableVal3 confirm, final RunnableVal2 whenDone) { - check(EconHandler.manager, Captions.ECON_DISABLED); + check(EconHandler.getEconHandler(), Captions.ECON_DISABLED); final Plot plot; if (args.length != 0) { checkTrue(args.length == 1, Captions.COMMAND_SYNTAX, getUsage()); @@ -82,7 +82,7 @@ public class Buy extends Command { confirm.run(this, () -> { Captions.REMOVED_BALANCE.send(player, price); - EconHandler.manager.depositMoney(PlotSquared.imp().getPlayerManager().getOfflinePlayer(plot.getOwnerAbs()), price); + EconHandler.getEconHandler().depositMoney(PlotSquared.imp().getPlayerManager().getOfflinePlayer(plot.getOwnerAbs()), price); PlotPlayer owner = PlotSquared.imp().getPlayerManager().getPlayerIfExists(plot.getOwnerAbs()); if (owner != null) { diff --git a/Core/src/main/java/com/plotsquared/core/command/Claim.java b/Core/src/main/java/com/plotsquared/core/command/Claim.java index 488b2dc84..481a25bf5 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Claim.java +++ b/Core/src/main/java/com/plotsquared/core/command/Claim.java @@ -105,14 +105,14 @@ public class Claim extends SubCommand { } } } - if ((EconHandler.manager != null) && area.useEconomy() && !force) { + if ((EconHandler.getEconHandler() != null) && area.useEconomy() && !force) { Expression costExr = area.getPrices().get("claim"); double cost = costExr.evaluate((double) currentPlots); if (cost > 0d) { - if (EconHandler.manager.getMoney(player) < cost) { + if (EconHandler.getEconHandler().getMoney(player) < cost) { return sendMessage(player, Captions.CANNOT_AFFORD_PLOT, "" + cost); } - EconHandler.manager.withdrawMoney(player, cost); + EconHandler.getEconHandler().withdrawMoney(player, cost); sendMessage(player, Captions.REMOVED_BALANCE, cost + ""); } } diff --git a/Core/src/main/java/com/plotsquared/core/command/DebugExec.java b/Core/src/main/java/com/plotsquared/core/command/DebugExec.java index 381582c57..3d6af68f1 100644 --- a/Core/src/main/java/com/plotsquared/core/command/DebugExec.java +++ b/Core/src/main/java/com/plotsquared/core/command/DebugExec.java @@ -166,7 +166,7 @@ public class DebugExec extends SubCommand { this.scope.put("BlockManager", WorldUtil.IMP); this.scope.put("SetupUtils", SetupUtils.manager); this.scope.put("EventUtil", PlotSquared.get().getEventDispatcher()); - this.scope.put("EconHandler", EconHandler.manager); + this.scope.put("EconHandler", EconHandler.getEconHandler()); this.scope.put("DBFunc", DBFunc.dbManager); this.scope.put("HybridUtils", HybridUtils.manager); this.scope.put("IMP", PlotSquared.get().IMP); diff --git a/Core/src/main/java/com/plotsquared/core/command/Delete.java b/Core/src/main/java/com/plotsquared/core/command/Delete.java index 6d8ea243e..5f8178e06 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Delete.java +++ b/Core/src/main/java/com/plotsquared/core/command/Delete.java @@ -86,11 +86,11 @@ public class Delete extends SubCommand { final long start = System.currentTimeMillis(); boolean result = plot.deletePlot(() -> { plot.removeRunning(); - if ((EconHandler.manager != null) && plotArea.useEconomy()) { + if ((EconHandler.getEconHandler() != null) && plotArea.useEconomy()) { Expression valueExr = plotArea.getPrices().get("sell"); double value = plots.size() * valueExr.evaluate((double) currentPlots); if (value > 0d) { - EconHandler.manager.depositMoney(player, value); + EconHandler.getEconHandler().depositMoney(player, value); sendMessage(player, Captions.ADDED_BALANCE, String.valueOf(value)); } } diff --git a/Core/src/main/java/com/plotsquared/core/command/ListCmd.java b/Core/src/main/java/com/plotsquared/core/command/ListCmd.java index 811eb88a7..a08de0cd0 100644 --- a/Core/src/main/java/com/plotsquared/core/command/ListCmd.java +++ b/Core/src/main/java/com/plotsquared/core/command/ListCmd.java @@ -71,7 +71,7 @@ public class ListCmd extends SubCommand { private String[] getArgumentList(PlotPlayer player) { List args = new ArrayList<>(); - if (EconHandler.manager != null && Permissions + if (EconHandler.getEconHandler() != null && Permissions .hasPermission(player, Captions.PERMISSION_LIST_FOR_SALE)) { args.add("forsale"); } @@ -264,7 +264,7 @@ public class ListCmd extends SubCommand { Captions.PERMISSION_LIST_FOR_SALE); return false; } - if (EconHandler.manager == null) { + if (EconHandler.getEconHandler() == null) { break; } plotConsumer.accept(PlotQuery.newQuery().allPlots().thatPasses(plot -> plot.getFlag(PriceFlag.class) > 0)); @@ -404,7 +404,7 @@ public class ListCmd extends SubCommand { @Override public Collection tab(PlotPlayer player, String[] args, boolean space) { final List completions = new LinkedList<>(); - if (EconHandler.manager != null && Permissions + if (EconHandler.getEconHandler() != null && Permissions .hasPermission(player, Captions.PERMISSION_LIST_FOR_SALE)) { completions.add("forsale"); } diff --git a/Core/src/main/java/com/plotsquared/core/command/MainCommand.java b/Core/src/main/java/com/plotsquared/core/command/MainCommand.java index 6e1151c4c..a5c42b117 100644 --- a/Core/src/main/java/com/plotsquared/core/command/MainCommand.java +++ b/Core/src/main/java/com/plotsquared/core/command/MainCommand.java @@ -164,14 +164,14 @@ public class MainCommand extends Command { public void run(final Command cmd, final Runnable success, final Runnable failure) { if (cmd.hasConfirmation(player)) { CmdConfirm.addPending(player, cmd.getUsage(), () -> { - if (EconHandler.manager != null) { + if (EconHandler.getEconHandler() != null) { PlotArea area = player.getApplicablePlotArea(); if (area != null) { Expression priceEval = area.getPrices().get(cmd.getFullId()); Double price = priceEval != null ? priceEval.evaluate(0d) : 0d; if (price != null - && EconHandler.manager.getMoney(player) < price) { + && EconHandler.getEconHandler().getMoney(player) < price) { if (failure != null) { failure.run(); } @@ -185,12 +185,12 @@ public class MainCommand extends Command { }); return; } - if (EconHandler.manager != null) { + if (EconHandler.getEconHandler() != null) { PlotArea area = player.getApplicablePlotArea(); if (area != null) { Expression priceEval = area.getPrices().get(cmd.getFullId()); Double price = priceEval != null ? priceEval.evaluate(0d) : 0d; - if (price != 0d && EconHandler.manager.getMoney(player) < price) { + if (price != 0d && EconHandler.getEconHandler().getMoney(player) < price) { if (failure != null) { failure.run(); } @@ -252,14 +252,14 @@ public class MainCommand extends Command { if ("f".equals(args[0].substring(1))) { confirm = new RunnableVal3() { @Override public void run(Command cmd, Runnable success, Runnable failure) { - if (EconHandler.manager != null) { + if (EconHandler.getEconHandler() != null) { PlotArea area = player.getApplicablePlotArea(); if (area != null) { Expression priceEval = area.getPrices().get(cmd.getFullId()); Double price = priceEval != null ? priceEval.evaluate(0d) : 0d; if (price != 0d - && EconHandler.manager.getMoney(player) < price) { + && EconHandler.getEconHandler().getMoney(player) < price) { if (failure != null) { failure.run(); } diff --git a/Core/src/main/java/com/plotsquared/core/command/Merge.java b/Core/src/main/java/com/plotsquared/core/command/Merge.java index 962b48163..33754c4b8 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Merge.java +++ b/Core/src/main/java/com/plotsquared/core/command/Merge.java @@ -156,8 +156,8 @@ public class Merge extends SubCommand { return true; } if (plot.autoMerge(Direction.ALL, maxSize, uuid, terrain)) { - if (EconHandler.manager != null && plotArea.useEconomy() && price > 0d) { - EconHandler.manager.withdrawMoney(player, price); + if (EconHandler.getEconHandler() != null && plotArea.useEconomy() && price > 0d) { + EconHandler.getEconHandler().withdrawMoney(player, price); sendMessage(player, Captions.REMOVED_BALANCE, String.valueOf(price)); } MainUtil.sendMessage(player, Captions.SUCCESS_MERGE); @@ -174,8 +174,8 @@ public class Merge extends SubCommand { uuid = plot.getOwnerAbs(); } } - if (!force && EconHandler.manager != null && plotArea.useEconomy() && price > 0d - && EconHandler.manager.getMoney(player) < price) { + if (!force && EconHandler.getEconHandler() != null && plotArea.useEconomy() && price > 0d + && EconHandler.getEconHandler().getMoney(player) < price) { sendMessage(player, Captions.CANNOT_AFFORD_MERGE, String.valueOf(price)); return false; } @@ -192,8 +192,8 @@ public class Merge extends SubCommand { return true; } if (plot.autoMerge(direction, maxSize - size, uuid, terrain)) { - if (EconHandler.manager != null && plotArea.useEconomy() && price > 0d) { - EconHandler.manager.withdrawMoney(player, price); + if (EconHandler.getEconHandler() != null && plotArea.useEconomy() && price > 0d) { + EconHandler.getEconHandler().withdrawMoney(player, price); sendMessage(player, Captions.REMOVED_BALANCE, String.valueOf(price)); } MainUtil.sendMessage(player, Captions.SUCCESS_MERGE); @@ -226,12 +226,12 @@ public class Merge extends SubCommand { sendMessage(accepter, Captions.MERGE_NOT_VALID); return; } - if (EconHandler.manager != null && plotArea.useEconomy() && price > 0d) { - if (!force && EconHandler.manager.getMoney(player) < price) { + if (EconHandler.getEconHandler() != null && plotArea.useEconomy() && price > 0d) { + if (!force && EconHandler.getEconHandler().getMoney(player) < price) { sendMessage(player, Captions.CANNOT_AFFORD_MERGE, String.valueOf(price)); return; } - EconHandler.manager.withdrawMoney(player, price); + EconHandler.getEconHandler().withdrawMoney(player, price); sendMessage(player, Captions.REMOVED_BALANCE, String.valueOf(price)); } MainUtil.sendMessage(player, Captions.SUCCESS_MERGE); diff --git a/Core/src/main/java/com/plotsquared/core/components/ComponentPresetManager.java b/Core/src/main/java/com/plotsquared/core/components/ComponentPresetManager.java index 80ae1deb4..fb10eff9b 100644 --- a/Core/src/main/java/com/plotsquared/core/components/ComponentPresetManager.java +++ b/Core/src/main/java/com/plotsquared/core/components/ComponentPresetManager.java @@ -170,12 +170,12 @@ public class ComponentPresetManager { return false; } - if (componentPreset.getCost() > 0.0D && EconHandler.manager != null && plot.getArea().useEconomy()) { - if (EconHandler.manager.getMoney(player) < componentPreset.getCost()) { + if (componentPreset.getCost() > 0.0D && EconHandler.getEconHandler() != null && plot.getArea().useEconomy()) { + if (EconHandler.getEconHandler().getMoney(player) < componentPreset.getCost()) { Captions.PRESET_CANNOT_AFFORD.send(player); return false; } else { - EconHandler.manager.withdrawMoney(player, componentPreset.getCost()); + EconHandler.getEconHandler().withdrawMoney(player, componentPreset.getCost()); Captions.REMOVED_BALANCE.send(player, componentPreset.getCost() + ""); } } @@ -196,7 +196,7 @@ public class ComponentPresetManager { for (int i = 0; i < allowedPresets.size(); i++) { final ComponentPreset preset = allowedPresets.get(i); final List lore = new ArrayList<>(); - if (preset.getCost() > 0 && EconHandler.manager != null && plot.getArea().useEconomy()){ + if (preset.getCost() > 0 && EconHandler.getEconHandler() != null && plot.getArea().useEconomy()){ lore.add(Captions.PRESET_LORE_COST.getTranslated().replace("%cost%", String.format("%.2f", preset.getCost()))); } diff --git a/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java b/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java index a9af02b65..13efa6bfb 100644 --- a/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java +++ b/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java @@ -756,18 +756,18 @@ public abstract class PlotPlayer

implements CommandCaller, OfflinePlotPlayer * The amount of money this Player has. */ public double getMoney() { - return EconHandler.manager == null ? 0 : EconHandler.manager.getMoney(this); + return EconHandler.getEconHandler() == null ? 0 : EconHandler.getEconHandler().getMoney(this); } public void withdraw(double amount) { - if (EconHandler.manager != null) { - EconHandler.manager.withdrawMoney(this, amount); + if (EconHandler.getEconHandler() != null) { + EconHandler.getEconHandler().withdrawMoney(this, amount); } } public void deposit(double amount) { - if (EconHandler.manager != null) { - EconHandler.manager.depositMoney(this, amount); + if (EconHandler.getEconHandler() != null) { + EconHandler.getEconHandler().depositMoney(this, amount); } } diff --git a/Core/src/main/java/com/plotsquared/core/util/EconHandler.java b/Core/src/main/java/com/plotsquared/core/util/EconHandler.java index 15180e68e..bedbda228 100644 --- a/Core/src/main/java/com/plotsquared/core/util/EconHandler.java +++ b/Core/src/main/java/com/plotsquared/core/util/EconHandler.java @@ -25,36 +25,52 @@ */ package com.plotsquared.core.util; +import com.plotsquared.core.IPlotMain; import com.plotsquared.core.PlotSquared; import com.plotsquared.core.player.ConsolePlayer; import com.plotsquared.core.player.OfflinePlotPlayer; import com.plotsquared.core.player.PlotPlayer; +import org.jetbrains.annotations.Nullable; public abstract class EconHandler { - public static EconHandler manager; - private static boolean initialized; + /** + * @deprecated This will be made private in the future + */ + @Deprecated public static EconHandler manager; - public static EconHandler getEconHandler() { - if (initialized) { - return manager; + /** + * Initialize the economy handler using + * {@link IPlotMain#getEconomyHandler()} + */ + public static void initializeEconHandler() { + if (manager != null) { + return; } - initialized = true; - return manager = PlotSquared.get().IMP.getEconomyHandler(); + manager = PlotSquared.get().IMP.getEconomyHandler(); } - public double getMoney(PlotPlayer player) { + /** + * Return the econ handler instance, if one exists + * + * @return Economy handler instance + */ + @Nullable public static EconHandler getEconHandler() { + return manager; + } + + public double getMoney(PlotPlayer player) { if (player instanceof ConsolePlayer) { return Double.MAX_VALUE; } return getBalance(player); } - public abstract double getBalance(PlotPlayer player); + public abstract double getBalance(PlotPlayer player); - public abstract void withdrawMoney(PlotPlayer player, double amount); + public abstract void withdrawMoney(PlotPlayer player, double amount); - public abstract void depositMoney(PlotPlayer player, double amount); + public abstract void depositMoney(PlotPlayer player, double amount); public abstract void depositMoney(OfflinePlotPlayer player, double amount); diff --git a/build.gradle b/build.gradle index 635cd7ea4..c55d34847 100644 --- a/build.gradle +++ b/build.gradle @@ -76,6 +76,8 @@ subprojects { delete("../target") } + javadoc.options.encoding = 'UTF-8' + dependencies { compile group: 'org.json', name: 'json', version: '20200518' From e833403e3c473542ec3fe52573de59c23d38aaf4 Mon Sep 17 00:00:00 2001 From: EpiCanard Date: Thu, 25 Jun 2020 14:08:44 +0200 Subject: [PATCH 06/52] Replace split with substring for placeholders --- .../bukkit/placeholder/Placeholders.java | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/Placeholders.java b/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/Placeholders.java index ce2445052..5457dbe0f 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/Placeholders.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/Placeholders.java @@ -72,20 +72,20 @@ public class Placeholders extends PlaceholderExpansion { } if (identifier.startsWith("has_plot_")) { - if (identifier.split("has_plot_").length != 2) + identifier = identifier.substring("has_plot_".length()); + if (identifier.isEmpty()) return ""; - identifier = identifier.split("has_plot_")[1]; return pl.getPlotCount(identifier) > 0 ? PlaceholderAPIPlugin.booleanTrue() : PlaceholderAPIPlugin.booleanFalse(); } if (identifier.startsWith("plot_count_")) { - if (identifier.split("plot_count_").length != 2) + identifier = identifier.substring("plot_count_".length()); + if (identifier.isEmpty()) return ""; - identifier = identifier.split("plot_count_")[1]; return String.valueOf(pl.getPlotCount(identifier)); } @@ -184,12 +184,11 @@ public class Placeholders extends PlaceholderExpansion { break; } if (identifier.startsWith("currentplot_localflag_")) { - final String[] splitValues = identifier.split("currentplot_localflag_"); - return (splitValues.length >= 2) ? getFlagValue(plot, splitValues[1], false) : ""; + return getFlagValue(plot, identifier.substring("currentplot_localflag_".length()), + false); } if (identifier.startsWith("currentplot_flag_")) { - final String[] splitValues = identifier.split("currentplot_flag_"); - return (splitValues.length >= 2) ? getFlagValue(plot, splitValues[1], true) : ""; + return getFlagValue(plot, identifier.substring("currentplot_flag_".length()), true); } return ""; } @@ -206,10 +205,11 @@ public class Placeholders extends PlaceholderExpansion { * @return The value of flag serialized in string */ private String getFlagValue(final Plot plot, final String flagName, final boolean inherit) { - final PlotFlag flag = GlobalFlagContainer.getInstance().getFlagFromString(flagName); - if (flag == null) { + if (flagName.isEmpty()) + return ""; + final PlotFlag flag = GlobalFlagContainer.getInstance().getFlagFromString(flagName); + if (flag == null) return ""; - } if (inherit) { return plot.getFlag(flag).toString(); @@ -217,6 +217,5 @@ public class Placeholders extends PlaceholderExpansion { final PlotFlag plotFlag = plot.getFlagContainer().queryLocal(flag.getClass()); return (plotFlag != null) ? plotFlag.getValue().toString() : ""; } - } } From 38425a1eaed2749bbe11982332a8bfcca48281e5 Mon Sep 17 00:00:00 2001 From: Hannes Greule Date: Fri, 26 Jun 2020 13:49:17 +0200 Subject: [PATCH 07/52] Update world border on Plot#claim (Fixes PS-13) --- Core/src/main/java/com/plotsquared/core/plot/Plot.java | 1 + 1 file changed, 1 insertion(+) diff --git a/Core/src/main/java/com/plotsquared/core/plot/Plot.java b/Core/src/main/java/com/plotsquared/core/plot/Plot.java index 0d756ac6c..46ce9f24c 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/Plot.java +++ b/Core/src/main/java/com/plotsquared/core/plot/Plot.java @@ -1751,6 +1751,7 @@ public class Plot { } } else { area.addPlot(this); + updateWorldBorder(); } setSign(player.getName()); MainUtil.sendMessage(player, Captions.CLAIMED); From cb04c183a823f0491c73a29483c979f14ffcaad2 Mon Sep 17 00:00:00 2001 From: MattBDev <4009945+MattBDev@users.noreply.github.com> Date: Fri, 26 Jun 2020 20:38:30 -0400 Subject: [PATCH 08/52] Update to 1.16.1 --- Bukkit/build.gradle | 4 ++-- Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java | 2 +- .../java/com/plotsquared/bukkit/listener/PlayerEvents.java | 5 +++++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Bukkit/build.gradle b/Bukkit/build.gradle index 6995d9034..6b011faf7 100644 --- a/Bukkit/build.gradle +++ b/Bukkit/build.gradle @@ -22,9 +22,9 @@ dependencies { implementation(project(":PlotSquared-Core")) compile("org.bstats:bstats-bukkit:1.7") compile(project(":PlotSquared-Core")) - compile("com.destroystokyo.paper:paper-api:1.15.2-R0.1-SNAPSHOT") + compile("com.destroystokyo.paper:paper-api:1.16.1-R0.1-SNAPSHOT") //implementation 'com.onarandombox.multiversecore:Multiverse-Core:3.0.0-SNAPSHOT' - implementation("org.spigotmc:spigot-api:1.15.2-R0.1-SNAPSHOT") + implementation("org.spigotmc:spigot-api:1.16.1-R0.1-SNAPSHOT") compile(group: "com.sk89q.worldedit", name: "worldedit-bukkit", version: "7.0.1") compile("io.papermc:paperlib:1.0.2") implementation("net.kyori:text-adapter-bukkit:3.0.3") diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java index 1a40c51d5..ca21d9a3d 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java @@ -123,6 +123,7 @@ import org.bukkit.World; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.command.PluginCommand; import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.Listener; @@ -790,7 +791,6 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< case MUSHROOM_COW: case OCELOT: case PIG: - case PIG_ZOMBIE: case RABBIT: case SHEEP: case SILVERFISH: diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java index 643f80611..c8c16a4c6 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java @@ -1389,6 +1389,11 @@ public class PlayerEvents extends PlotListener implements Listener { case BUBBLE_CORAL_FAN: case FIRE_CORAL_FAN: case HORN_CORAL_FAN: + case BRAIN_CORAL_WALL_FAN: + case BUBBLE_CORAL_WALL_FAN: + case FIRE_CORAL_WALL_FAN: + case HORN_CORAL_WALL_FAN: + case TUBE_CORAL_WALL_FAN: if (!plot.getFlag(CoralDryFlag.class)) { plot.debug("Coral could not dry because coral-dry = false"); event.setCancelled(true); From 9c3d2cfb0212dc5d3b463c0dc15642701df7603b Mon Sep 17 00:00:00 2001 From: MeFisto94 Date: Wed, 24 Jun 2020 17:33:49 +0200 Subject: [PATCH 09/52] Move the caching and static accessors from EconHandler to PlotMain --- .../com/plotsquared/bukkit/BukkitMain.java | 11 +++++++++- .../bukkit/util/BukkitEconHandler.java | 1 + .../java/com/plotsquared/core/IPlotMain.java | 4 ++-- .../plotsquared/core/util/EconHandler.java | 21 +++++++++++-------- 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java index 1a40c51d5..a0f19cb6e 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java @@ -178,6 +178,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< @Getter private BackupManager backupManager; @Getter private PlatformWorldManager worldManager; private final BukkitPlayerManager playerManager = new BukkitPlayerManager(); + private EconHandler econ; @Override public int[] getServerVersion() { if (this.version == null) { @@ -902,8 +903,16 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< } @Override public EconHandler getEconomyHandler() { + if (econ != null) { + if (econ.init() /* is inited*/) { + return econ; + } else { + return null; + } + } + try { - BukkitEconHandler econ = new BukkitEconHandler(); + econ = new BukkitEconHandler(); if (econ.init()) { return econ; } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEconHandler.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEconHandler.java index b8387efed..642ed3c63 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEconHandler.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEconHandler.java @@ -40,6 +40,7 @@ public class BukkitEconHandler extends EconHandler { private Economy econ; private Permission perms; + @Override public boolean init() { if (this.econ == null || this.perms == null) { setupPermissions(); diff --git a/Core/src/main/java/com/plotsquared/core/IPlotMain.java b/Core/src/main/java/com/plotsquared/core/IPlotMain.java index eb70402f6..4dc293c6d 100644 --- a/Core/src/main/java/com/plotsquared/core/IPlotMain.java +++ b/Core/src/main/java/com/plotsquared/core/IPlotMain.java @@ -174,11 +174,11 @@ public interface IPlotMain

extends ILogger { boolean initWorldEdit(); /** - * Gets the economy provider. + * Gets the economy provider, if there is one * * @return the PlotSquared economy manager */ - EconHandler getEconomyHandler(); + @Nullable EconHandler getEconomyHandler(); /** * Gets the {@link QueueProvider} class. diff --git a/Core/src/main/java/com/plotsquared/core/util/EconHandler.java b/Core/src/main/java/com/plotsquared/core/util/EconHandler.java index bedbda228..1064b0800 100644 --- a/Core/src/main/java/com/plotsquared/core/util/EconHandler.java +++ b/Core/src/main/java/com/plotsquared/core/util/EconHandler.java @@ -35,18 +35,17 @@ import org.jetbrains.annotations.Nullable; public abstract class EconHandler { /** - * @deprecated This will be made private in the future + * @deprecated This will be removed in the future, + * call {@link IPlotMain#getEconomyHandler()} instead. */ - @Deprecated public static EconHandler manager; + @Deprecated @Nullable public static EconHandler manager; /** - * Initialize the economy handler using - * {@link IPlotMain#getEconomyHandler()} + * Initialize the economy handler using {@link IPlotMain#getEconomyHandler()} + * @deprecated Call {@link #init} instead or use {@link IPlotMain#getEconomyHandler()} + * which does this already. */ - public static void initializeEconHandler() { - if (manager != null) { - return; - } + @Deprecated public static void initializeEconHandler() { manager = PlotSquared.get().IMP.getEconomyHandler(); } @@ -54,11 +53,15 @@ public abstract class EconHandler { * Return the econ handler instance, if one exists * * @return Economy handler instance + * @deprecated Call {@link IPlotMain#getEconomyHandler()} instead */ - @Nullable public static EconHandler getEconHandler() { + @Deprecated @Nullable public static EconHandler getEconHandler() { + manager = PlotSquared.get().IMP.getEconomyHandler(); return manager; } + public abstract boolean init(); + public double getMoney(PlotPlayer player) { if (player instanceof ConsolePlayer) { return Double.MAX_VALUE; From 02f3c3ef50684f254a86916c86ff8d75079cae08 Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Sat, 27 Jun 2020 20:38:55 +0100 Subject: [PATCH 10/52] Fix my stupid mistake of using lamdas not creating nested classes when creating schematics. "this" doesn't work like that. Cheers Java. --- .../core/util/SchematicHandler.java | 197 ++++++++++-------- 1 file changed, 105 insertions(+), 92 deletions(-) diff --git a/Core/src/main/java/com/plotsquared/core/util/SchematicHandler.java b/Core/src/main/java/com/plotsquared/core/util/SchematicHandler.java index 547741e6f..92b1b2ef4 100644 --- a/Core/src/main/java/com/plotsquared/core/util/SchematicHandler.java +++ b/Core/src/main/java/com/plotsquared/core/util/SchematicHandler.java @@ -130,8 +130,7 @@ public abstract class SchematicHandler { name = plot.getId().x + ";" + plot.getId().y + ',' + plot.getArea() + ',' + owner; } else { - name = namingScheme - .replaceAll("%id%", plot.getId().toString()) + name = namingScheme.replaceAll("%id%", plot.getId().toString()) .replaceAll("%idx%", plot.getId().x + "") .replaceAll("%idy%", plot.getId().y + "") .replaceAll("%world%", plot.getArea().toString()); @@ -566,100 +565,114 @@ public abstract class SchematicHandler { final int p2z = pos2.getZ(); final int ey = pos2.getY(); Iterator yiter = IntStream.range(sy, ey + 1).iterator(); - final Runnable yTask = () -> { - long ystart = System.currentTimeMillis(); - while (yiter.hasNext() && System.currentTimeMillis() - ystart < 20) { - final int y = yiter.next(); - Iterator ziter = IntStream.range(p1z, p2z + 1).iterator(); - final Runnable zTask = () -> { - long zstart = System.currentTimeMillis(); - while (ziter.hasNext() - && System.currentTimeMillis() - zstart < 20) { - final int z = ziter.next(); - Iterator xiter = - IntStream.range(p1x, p2x + 1).iterator(); - final Runnable xTask = () -> { - long xstart = System.currentTimeMillis(); - final int ry = y - sy; - final int rz = z - p1z; - while (xiter.hasNext() - && System.currentTimeMillis() - xstart < 20) { - final int x = xiter.next(); - final int rx = x - p1x; - BlockVector3 point = BlockVector3.at(x, y, z); - BaseBlock block = - cuboidRegion.getWorld().getFullBlock(point); - if (block.getNbtData() != null) { - Map values = new HashMap<>(); - for (Map.Entry entry : block - .getNbtData().getValue().entrySet()) { - values.put(entry.getKey(), entry.getValue()); + final Runnable yTask = new Runnable() { + @Override public void run() { + long ystart = System.currentTimeMillis(); + while (yiter.hasNext() && System.currentTimeMillis() - ystart < 20) { + final int y = yiter.next(); + Iterator ziter = IntStream.range(p1z, p2z + 1).iterator(); + final Runnable zTask = new Runnable() { + @Override public void run() { + long zstart = System.currentTimeMillis(); + while (ziter.hasNext() + && System.currentTimeMillis() - zstart < 20) { + final int z = ziter.next(); + Iterator xiter = + IntStream.range(p1x, p2x + 1).iterator(); + final Runnable xTask = new Runnable() { + @Override public void run() { + long xstart = System.currentTimeMillis(); + final int ry = y - sy; + final int rz = z - p1z; + while (xiter.hasNext() + && System.currentTimeMillis() - xstart + < 20) { + final int x = xiter.next(); + final int rx = x - p1x; + BlockVector3 point = + BlockVector3.at(x, y, z); + BaseBlock block = cuboidRegion.getWorld() + .getFullBlock(point); + if (block.getNbtData() != null) { + Map values = + new HashMap<>(); + for (Map.Entry entry : block + .getNbtData().getValue() + .entrySet()) { + values.put(entry.getKey(), + entry.getValue()); + } + // Remove 'id' if it exists. We want 'Id' + values.remove("id"); + + // Positions are kept in NBT, we don't want that. + values.remove("x"); + values.remove("y"); + values.remove("z"); + + values.put("Id", + new StringTag(block.getNbtId())); + values.put("Pos", new IntArrayTag( + new int[] {rx, ry, rz})); + + tileEntities + .add(new CompoundTag(values)); + } + String blockKey = + block.toImmutableState().getAsString(); + int blockId; + if (palette.containsKey(blockKey)) { + blockId = palette.get(blockKey); + } else { + blockId = palette.size(); + palette.put(blockKey, palette.size()); + } + + while ((blockId & -128) != 0) { + buffer.write(blockId & 127 | 128); + blockId >>>= 7; + } + buffer.write(blockId); + + if (ry > 0) { + continue; + } + BlockVector2 pt = BlockVector2.at(x, z); + BiomeType biome = + cuboidRegion.getWorld().getBiome(pt); + String biomeStr = biome.getId(); + int biomeId; + if (biomePalette.containsKey(biomeStr)) { + biomeId = biomePalette.get(biomeStr); + } else { + biomeId = biomePalette.size(); + biomePalette.put(biomeStr, biomeId); + } + while ((biomeId & -128) != 0) { + biomeBuffer.write(biomeId & 127 | 128); + biomeId >>>= 7; + } + biomeBuffer.write(biomeId); + } + if (xiter.hasNext()) { + this.run(); + } } - // Remove 'id' if it exists. We want 'Id' - values.remove("id"); - - // Positions are kept in NBT, we don't want that. - values.remove("x"); - values.remove("y"); - values.remove("z"); - - values.put("Id", new StringTag(block.getNbtId())); - values.put("Pos", - new IntArrayTag(new int[] {rx, ry, rz})); - - tileEntities.add(new CompoundTag(values)); - } - String blockKey = - block.toImmutableState().getAsString(); - int blockId; - if (palette.containsKey(blockKey)) { - blockId = palette.get(blockKey); - } else { - blockId = palette.size(); - palette.put(blockKey, palette.size()); - } - - while ((blockId & -128) != 0) { - buffer.write(blockId & 127 | 128); - blockId >>>= 7; - } - buffer.write(blockId); - - if (ry > 0) { - continue; - } - BlockVector2 pt = BlockVector2.at(x, z); - BiomeType biome = cuboidRegion.getWorld().getBiome(pt); - String biomeStr = biome.getId(); - int biomeId; - if (biomePalette.containsKey(biomeStr)) { - biomeId = biomePalette.get(biomeStr); - } else { - biomeId = biomePalette.size(); - biomePalette.put(biomeStr, biomeId); - } - while ((biomeId & -128) != 0) { - biomeBuffer.write(biomeId & 127 | 128); - biomeId >>>= 7; - } - biomeBuffer.write(biomeId); + }; + xTask.run(); } - if (xiter.hasNext()) { + if (ziter.hasNext()) { this.run(); } - }; - xTask.run(); - } - if (ziter.hasNext()) { - this.run(); - } - }; - zTask.run(); - } - if (yiter.hasNext()) { - TaskManager.runTaskLater(this, 1); - } else { - regionTask.run(); + } + }; + zTask.run(); + } + if (yiter.hasNext()) { + TaskManager.runTaskLater(this, 1); + } else { + regionTask.run(); + } } }; yTask.run(); From 74876f9e64191281deba2295f8ad3a0beb0dcdb8 Mon Sep 17 00:00:00 2001 From: Carter Date: Sat, 27 Jun 2020 15:40:20 -0400 Subject: [PATCH 11/52] Get biome data from correct schematic for intersections (Fixes PS-50) --- .../java/com/plotsquared/core/generator/HybridPlotWorld.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/src/main/java/com/plotsquared/core/generator/HybridPlotWorld.java b/Core/src/main/java/com/plotsquared/core/generator/HybridPlotWorld.java index 49a5c0da4..e322072df 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/HybridPlotWorld.java +++ b/Core/src/main/java/com/plotsquared/core/generator/HybridPlotWorld.java @@ -335,7 +335,7 @@ public class HybridPlotWorld extends ClassicPlotWorld { (short) (z - shift), id, false, h2); } } - BiomeType biome = blockArrayClipboard1 + BiomeType biome = blockArrayClipboard2 .getBiome(BlockVector2.at(x + min.getBlockX(), z + min.getBlockZ())); addOverlayBiome((short) (x - shift), (short) (z - shift), biome); } From 181c5b134f284d52d8dd8cad0b8290951a96420f Mon Sep 17 00:00:00 2001 From: NotMyFault Date: Sat, 27 Jun 2020 21:48:15 +0200 Subject: [PATCH 12/52] Update old links --- .github/PULL_REQUEST_TEMPLATE.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 60cba3066..f55841917 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -2,10 +2,10 @@ -**Fixes #{issue number}** +**Fixes {Link to issue}** ## Description From e139550949a52ebfabc6de4307f4ea4d1595d82b Mon Sep 17 00:00:00 2001 From: Hannes Greule Date: Sat, 27 Jun 2020 23:07:20 +0200 Subject: [PATCH 13/52] Make cache expiration configurable --- .../java/com/plotsquared/core/configuration/Settings.java | 7 +++++++ .../java/com/plotsquared/core/util/TabCompletions.java | 4 +++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Core/src/main/java/com/plotsquared/core/configuration/Settings.java b/Core/src/main/java/com/plotsquared/core/configuration/Settings.java index 7b0196412..80d103882 100644 --- a/Core/src/main/java/com/plotsquared/core/configuration/Settings.java +++ b/Core/src/main/java/com/plotsquared/core/configuration/Settings.java @@ -527,6 +527,13 @@ public class Settings extends Config { public static int TARGET_TIME = 65; } + @Comment("Settings related to tab completion") + public static final class Tab_Completions { + @Comment({"The time in seconds how long tab completions should remain in cache.", + "0 will disable caching. Lower values may be less performant."}) + public static int CACHE_EXPIRATION = 15; + } + @Comment({"Enable or disable parts of the plugin", "Note: A cache will use some memory if enabled"}) diff --git a/Core/src/main/java/com/plotsquared/core/util/TabCompletions.java b/Core/src/main/java/com/plotsquared/core/util/TabCompletions.java index dbf053c52..56a3ff8fa 100644 --- a/Core/src/main/java/com/plotsquared/core/util/TabCompletions.java +++ b/Core/src/main/java/com/plotsquared/core/util/TabCompletions.java @@ -56,7 +56,9 @@ import java.util.stream.Collectors; public class TabCompletions { private final Cache> cachedCompletionValues = - CacheBuilder.newBuilder().expireAfterWrite(15, TimeUnit.SECONDS).build(); + CacheBuilder.newBuilder() + .expireAfterWrite(Settings.Tab_Completions.CACHE_EXPIRATION, TimeUnit.SECONDS) + .build(); private final Command booleanTrueCompletion = new Command(null, false, "true", "", RequiredType.NONE, null) {}; From bd9bdc9e034ef5750d66efa0e799f50f2334cf65 Mon Sep 17 00:00:00 2001 From: MeFisto94 Date: Thu, 25 Jun 2020 00:19:58 +0200 Subject: [PATCH 14/52] Separate the Vault Permission Handling from the Economy Handling --- .../com/plotsquared/bukkit/BukkitMain.java | 25 +++++++- .../bukkit/util/BukkitEconHandler.java | 36 ++++------- .../bukkit/util/BukkitPermHandler.java | 59 +++++++++++++++++++ .../java/com/plotsquared/core/IPlotMain.java | 8 +++ .../plotsquared/core/util/EconHandler.java | 10 +++- .../plotsquared/core/util/PermHandler.java | 37 ++++++++++++ 6 files changed, 149 insertions(+), 26 deletions(-) create mode 100644 Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitPermHandler.java create mode 100644 Core/src/main/java/com/plotsquared/core/util/PermHandler.java diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java index a0f19cb6e..b313098a8 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java @@ -45,6 +45,7 @@ import com.plotsquared.bukkit.util.BukkitChatManager; import com.plotsquared.bukkit.util.BukkitChunkManager; import com.plotsquared.bukkit.util.BukkitEconHandler; import com.plotsquared.bukkit.util.BukkitInventoryUtil; +import com.plotsquared.bukkit.util.BukkitPermHandler; import com.plotsquared.bukkit.util.BukkitRegionManager; import com.plotsquared.bukkit.util.BukkitSetupUtils; import com.plotsquared.bukkit.util.BukkitTaskManager; @@ -94,6 +95,7 @@ import com.plotsquared.core.util.ConsoleColors; import com.plotsquared.core.util.EconHandler; import com.plotsquared.core.util.InventoryUtil; import com.plotsquared.core.util.MainUtil; +import com.plotsquared.core.util.PermHandler; import com.plotsquared.core.util.PlatformWorldManager; import com.plotsquared.core.util.PlayerManager; import com.plotsquared.core.util.PremiumVerification; @@ -179,6 +181,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< @Getter private PlatformWorldManager worldManager; private final BukkitPlayerManager playerManager = new BukkitPlayerManager(); private EconHandler econ; + private PermHandler perm; @Override public int[] getServerVersion() { if (this.version == null) { @@ -904,7 +907,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< @Override public EconHandler getEconomyHandler() { if (econ != null) { - if (econ.init() /* is inited*/) { + if (econ.init() /* is inited */) { return econ; } else { return null; @@ -922,6 +925,26 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< return null; } + @Override public PermHandler getPermissionHandler() { + if (perm != null) { + if (perm.init() /* is inited */) { + return perm; + } else { + return null; + } + } + + try { + perm = new BukkitPermHandler(); + if (perm.init()) { + return perm; + } + } catch (Throwable ignored) { + PlotSquared.debug("No permissions detected!"); + } + return null; + } + @Override public QueueProvider initBlockQueue() { //TODO Figure out why this code is still here yet isn't being called anywhere. // try { diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEconHandler.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEconHandler.java index 642ed3c63..e71c48158 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEconHandler.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEconHandler.java @@ -27,34 +27,25 @@ package com.plotsquared.bukkit.util; import com.plotsquared.bukkit.player.BukkitOfflinePlayer; import com.plotsquared.bukkit.player.BukkitPlayer; +import com.plotsquared.core.PlotSquared; import com.plotsquared.core.player.OfflinePlotPlayer; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.util.EconHandler; +import com.plotsquared.core.util.PermHandler; import net.milkbowl.vault.economy.Economy; -import net.milkbowl.vault.permission.Permission; import org.bukkit.Bukkit; import org.bukkit.plugin.RegisteredServiceProvider; public class BukkitEconHandler extends EconHandler { private Economy econ; - private Permission perms; @Override public boolean init() { - if (this.econ == null || this.perms == null) { - setupPermissions(); + if (this.econ == null) { setupEconomy(); } - return this.econ != null && this.perms != null; - } - - private void setupPermissions() { - RegisteredServiceProvider permissionProvider = - Bukkit.getServer().getServicesManager().getRegistration(Permission.class); - if (permissionProvider != null) { - this.perms = permissionProvider.getProvider(); - } + return this.econ != null; } private void setupEconomy() { @@ -88,20 +79,19 @@ public class BukkitEconHandler extends EconHandler { this.econ.depositPlayer(((BukkitOfflinePlayer) player).player, amount); } - @Override public boolean hasPermission(String world, String player, String perm) { - return this.perms.playerHas(world, Bukkit.getOfflinePlayer(player), perm); + /** + * @deprecated Use {@link PermHandler#hasPermission(String, String, String)} instead + */ + @Deprecated @Override public boolean hasPermission(String world, String player, String perm) { + if (PlotSquared.imp().getPermissionHandler() != null) { + return PlotSquared.imp().getPermissionHandler().hasPermission(world, player, perm); + } else { + return false; + } } @Override public double getBalance(PlotPlayer player) { return this.econ.getBalance(player.getName()); } - @Deprecated public void setPermission(String world, String player, String perm, boolean value) { - if (value) { - this.perms.playerAdd(world, player, perm); - } else { - this.perms.playerRemove(world, player, perm); - } - } - } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitPermHandler.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitPermHandler.java new file mode 100644 index 000000000..fee00a66d --- /dev/null +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitPermHandler.java @@ -0,0 +1,59 @@ +/* + * _____ _ _ _____ _ + * | __ \| | | | / ____| | | + * | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| | + * | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` | + * | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| | + * |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_| + * | | + * |_| + * PlotSquared plot management system for Minecraft + * Copyright (C) 2020 IntellectualSites + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.plotsquared.bukkit.util; + +import com.plotsquared.core.util.PermHandler; +import net.milkbowl.vault.permission.Permission; +import org.bukkit.Bukkit; +import org.bukkit.plugin.RegisteredServiceProvider; + +public class BukkitPermHandler extends PermHandler { + + private Permission perms; + + @Override + public boolean init() { + if (this.perms == null) { + setupPermissions(); + } + return this.perms != null; + } + + private void setupPermissions() { + if (Bukkit.getServer().getPluginManager().getPlugin("Vault") == null) { + return; + } + RegisteredServiceProvider permissionProvider = + Bukkit.getServer().getServicesManager().getRegistration(Permission.class); + if (permissionProvider != null) { + this.perms = permissionProvider.getProvider(); + } + } + + @Override public boolean hasPermission(String world, String player, String perm) { + return this.perms.playerHas(world, Bukkit.getOfflinePlayer(player), perm); + } +} diff --git a/Core/src/main/java/com/plotsquared/core/IPlotMain.java b/Core/src/main/java/com/plotsquared/core/IPlotMain.java index 4dc293c6d..a38045acb 100644 --- a/Core/src/main/java/com/plotsquared/core/IPlotMain.java +++ b/Core/src/main/java/com/plotsquared/core/IPlotMain.java @@ -35,6 +35,7 @@ import com.plotsquared.core.util.ChatManager; import com.plotsquared.core.util.ChunkManager; import com.plotsquared.core.util.EconHandler; import com.plotsquared.core.util.InventoryUtil; +import com.plotsquared.core.util.PermHandler; import com.plotsquared.core.util.PlatformWorldManager; import com.plotsquared.core.util.PlayerManager; import com.plotsquared.core.util.RegionManager; @@ -180,6 +181,13 @@ public interface IPlotMain

extends ILogger { */ @Nullable EconHandler getEconomyHandler(); + /** + * Gets the permission provider, if there is one + * + * @return the PlotSquared permission manager + */ + @Nullable PermHandler getPermissionHandler(); + /** * Gets the {@link QueueProvider} class. */ diff --git a/Core/src/main/java/com/plotsquared/core/util/EconHandler.java b/Core/src/main/java/com/plotsquared/core/util/EconHandler.java index 1064b0800..a593e0cb0 100644 --- a/Core/src/main/java/com/plotsquared/core/util/EconHandler.java +++ b/Core/src/main/java/com/plotsquared/core/util/EconHandler.java @@ -77,9 +77,15 @@ public abstract class EconHandler { public abstract void depositMoney(OfflinePlotPlayer player, double amount); - public abstract boolean hasPermission(String world, String player, String perm); + /** + * @deprecated Use {@link PermHandler#hasPermission(String, String, String)} instead + */ + @Deprecated public abstract boolean hasPermission(String world, String player, String perm); - public boolean hasPermission(String player, String perm) { + /** + * @deprecated Use {@link PermHandler#hasPermission(String, String)} instead + */ + @Deprecated public boolean hasPermission(String player, String perm) { return hasPermission(null, player, perm); } } diff --git a/Core/src/main/java/com/plotsquared/core/util/PermHandler.java b/Core/src/main/java/com/plotsquared/core/util/PermHandler.java new file mode 100644 index 000000000..1dec45fd4 --- /dev/null +++ b/Core/src/main/java/com/plotsquared/core/util/PermHandler.java @@ -0,0 +1,37 @@ +/* + * _____ _ _ _____ _ + * | __ \| | | | / ____| | | + * | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| | + * | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` | + * | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| | + * |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_| + * | | + * |_| + * PlotSquared plot management system for Minecraft + * Copyright (C) 2020 IntellectualSites + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.plotsquared.core.util; + +public abstract class PermHandler { + + public abstract boolean init(); + + public abstract boolean hasPermission(String world, String player, String perm); + + public boolean hasPermission(String player, String perm) { + return hasPermission(null, player, perm); + } +} From 3a2e932d171a51f23af96bd90a7020dd2211ffde Mon Sep 17 00:00:00 2001 From: MattBDev <4009945+MattBDev@users.noreply.github.com> Date: Sun, 28 Jun 2020 18:45:40 -0400 Subject: [PATCH 15/52] Add missing mobs from 1.13.2+ --- .../com/plotsquared/bukkit/BukkitMain.java | 214 +++++++++--------- 1 file changed, 110 insertions(+), 104 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java index ca21d9a3d..95ceed2de 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java @@ -627,46 +627,46 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< Iterator iterator = entities.iterator(); while (iterator.hasNext()) { Entity entity = iterator.next(); - switch (entity.getType()) { - case EGG: - case FISHING_HOOK: - case ENDER_SIGNAL: - case AREA_EFFECT_CLOUD: - case EXPERIENCE_ORB: - case LEASH_HITCH: - case FIREWORK: - case LIGHTNING: - case WITHER_SKULL: - case UNKNOWN: - case PLAYER: + switch (entity.getType().toString()) { + case "EGG": + case "FISHING_HOOK": + case "ENDER_SIGNAL": + case "AREA_EFFECT_CLOUD": + case "EXPERIENCE_ORB": + case "LEASH_HITCH": + case "FIREWORK": + case "LIGHTNING": + case "WITHER_SKULL": + case "UNKNOWN": + case "PLAYER": // non moving / unmovable continue; - case THROWN_EXP_BOTTLE: - case SPLASH_POTION: - case SNOWBALL: - case SHULKER_BULLET: - case SPECTRAL_ARROW: - case ENDER_PEARL: - case ARROW: - case LLAMA_SPIT: - case TRIDENT: + case "THROWN_EXP_BOTTLE": + case "SPLASH_POTION": + case "SNOWBALL": + case "SHULKER_BULLET": + case "SPECTRAL_ARROW": + case "ENDER_PEARL": + case "ARROW": + case "LLAMA_SPIT": + case "TRIDENT": // managed elsewhere | projectile continue; - case ITEM_FRAME: - case PAINTING: + case "ITEM_FRAME": + case "PAINTING": // Not vehicles continue; - case ARMOR_STAND: + case "ARMOR_STAND": // Temporarily classify as vehicle - case MINECART: - case MINECART_CHEST: - case MINECART_COMMAND: - case MINECART_FURNACE: - case MINECART_HOPPER: - case MINECART_MOB_SPAWNER: - case ENDER_CRYSTAL: - case MINECART_TNT: - case BOAT: + case "MINECART": + case "MINECART_CHEST": + case "MINECART_COMMAND": + case "MINECART_FURNACE": + case "MINECART_HOPPER": + case "MINECART_MOB_SPAWNER": + case "ENDER_CRYSTAL": + case "MINECART_TNT": + case "BOAT": if (Settings.Enabled_Components.KILL_ROAD_VEHICLES) { com.plotsquared.core.location.Location location = BukkitUtil.getLocation(entity.getLocation()); @@ -695,10 +695,10 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< } } continue; - case SMALL_FIREBALL: - case FIREBALL: - case DRAGON_FIREBALL: - case DROPPED_ITEM: + case "SMALL_FIREBALL": + case "FIREBALL": + case "DRAGON_FIREBALL": + case "DROPPED_ITEM": if (Settings.Enabled_Components.KILL_ROAD_ITEMS && plotArea .getOwnedPlotAbs(BukkitUtil.getLocation(entity.getLocation())) == null) { @@ -706,11 +706,11 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< } // dropped item continue; - case PRIMED_TNT: - case FALLING_BLOCK: + case "PRIMED_TNT": + case "FALLING_BLOCK": // managed elsewhere continue; - case SHULKER: + case "SHULKER": if (Settings.Enabled_Components.KILL_ROAD_MOBS) { LivingEntity livingEntity = (LivingEntity) entity; List meta = entity.getMetadata("shulkerPlot"); @@ -758,70 +758,76 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< } } continue; - case LLAMA: - case DONKEY: - case MULE: - case ZOMBIE_HORSE: - case SKELETON_HORSE: - case HUSK: - case ELDER_GUARDIAN: - case WITHER_SKELETON: - case STRAY: - case ZOMBIE_VILLAGER: - case EVOKER: - case EVOKER_FANGS: - case VEX: - case VINDICATOR: - case POLAR_BEAR: - case BAT: - case BLAZE: - case CAVE_SPIDER: - case CHICKEN: - case COW: - case CREEPER: - case ENDERMAN: - case ENDERMITE: - case ENDER_DRAGON: - case GHAST: - case GIANT: - case GUARDIAN: - case HORSE: - case IRON_GOLEM: - case MAGMA_CUBE: - case MUSHROOM_COW: - case OCELOT: - case PIG: - case RABBIT: - case SHEEP: - case SILVERFISH: - case SKELETON: - case SLIME: - case SNOWMAN: - case SPIDER: - case SQUID: - case VILLAGER: - case WITCH: - case WITHER: - case WOLF: - case ZOMBIE: - case PARROT: - case SALMON: - case DOLPHIN: - case TROPICAL_FISH: - case DROWNED: - case COD: - case TURTLE: - case PUFFERFISH: - case PHANTOM: - case ILLUSIONER: - case CAT: - case PANDA: - case FOX: - case PILLAGER: - case TRADER_LLAMA: - case WANDERING_TRADER: - case RAVAGER: - //case BEE: + case "ZOMBIFIED_PIGLIN": + case "LLAMA": + case "DONKEY": + case "MULE": + case "ZOMBIE_HORSE": + case "SKELETON_HORSE": + case "HUSK": + case "ELDER_GUARDIAN": + case "WITHER_SKELETON": + case "STRAY": + case "ZOMBIE_VILLAGER": + case "EVOKER": + case "EVOKER_FANGS": + case "VEX": + case "VINDICATOR": + case "POLAR_BEAR": + case "BAT": + case "BLAZE": + case "CAVE_SPIDER": + case "CHICKEN": + case "COW": + case "CREEPER": + case "ENDERMAN": + case "ENDERMITE": + case "ENDER_DRAGON": + case "GHAST": + case "GIANT": + case "GUARDIAN": + case "HORSE": + case "IRON_GOLEM": + case "MAGMA_CUBE": + case "MUSHROOM_COW": + case "OCELOT": + case "PIG": + case "PIG_ZOMBIE": + case "RABBIT": + case "SHEEP": + case "SILVERFISH": + case "SKELETON": + case "SLIME": + case "SNOWMAN": + case "SPIDER": + case "SQUID": + case "VILLAGER": + case "WITCH": + case "WITHER": + case "WOLF": + case "ZOMBIE": + case "PARROT": + case "SALMON": + case "DOLPHIN": + case "TROPICAL_FISH": + case "DROWNED": + case "COD": + case "TURTLE": + case "PUFFERFISH": + case "PHANTOM": + case "ILLUSIONER": + case "CAT": + case "PANDA": + case "FOX": + case "PILLAGER": + case "TRADER_LLAMA": + case "WANDERING_TRADER": + case "RAVAGER": + case "BEE": + case "HOGLIN": + case "PIGLIN": + case "ZOGLIN": + break; default: { if (Settings.Enabled_Components.KILL_ROAD_MOBS) { Location location = entity.getLocation(); From fa2ad8ab22a32b8d690cb66941f1a15dc9277ae4 Mon Sep 17 00:00:00 2001 From: Hannes Greule Date: Mon, 29 Jun 2020 13:48:18 +0200 Subject: [PATCH 16/52] Improve plot alias command (tab complete, admin permission) fixes PS-63 --- .../com/plotsquared/core/command/Alias.java | 79 +++++++++++++------ .../core/configuration/Captions.java | 2 + .../core/util/query/PlotQuery.java | 24 ++++++ 3 files changed, 80 insertions(+), 25 deletions(-) diff --git a/Core/src/main/java/com/plotsquared/core/command/Alias.java b/Core/src/main/java/com/plotsquared/core/command/Alias.java index a10bf8a6e..59c0da49c 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Alias.java +++ b/Core/src/main/java/com/plotsquared/core/command/Alias.java @@ -33,17 +33,24 @@ import com.plotsquared.core.plot.Plot; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.MathMan; import com.plotsquared.core.util.Permissions; +import com.plotsquared.core.util.query.PlotQuery; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; import java.util.concurrent.TimeoutException; -@CommandDeclaration(command = "setalias", +@CommandDeclaration(command = "alias", permission = "plots.alias", description = "Set the plot name", usage = "/plot alias ", - aliases = {"alias", "sa", "name", "rename", "setname", "seta", "nameplot"}, + aliases = {"setalias", "sa", "name", "rename", "setname", "seta", "nameplot"}, category = CommandCategory.SETTINGS, requiredType = RequiredType.PLAYER) public class Alias extends SubCommand { + private static final Command SET_COMMAND = new Command(null, false, "set", null, RequiredType.NONE, null) {}; + private static final Command REMOVE_COMMAND = new Command(null, false, "remove", null, RequiredType.NONE, null) {}; @Override public boolean onCommand(PlotPlayer player, String[] args) { @@ -63,13 +70,11 @@ public class Alias extends SubCommand { return false; } - if (!plot.isOwner(player.getUUID())) { - MainUtil.sendMessage(player, Captions.NO_PLOT_PERMS); - return false; - } - boolean result = false; + boolean owner = plot.isOwner(player.getUUID()); + boolean permission; + boolean admin; switch (args[0].toLowerCase()) { case "set": if (args.length != 2) { @@ -77,18 +82,34 @@ public class Alias extends SubCommand { return false; } - if (canExecuteCommand(player, Captions.PERMISSION_ALIAS_SET, false) - || canExecuteCommand(player, Captions.PERMISSION_ALIAS_SET_OBSOLETE, false)) { + permission = isPermitted(player, Captions.PERMISSION_ALIAS_SET) + || isPermitted(player, Captions.PERMISSION_ALIAS_SET_OBSOLETE); + admin = isPermitted(player, Captions.PERMISSION_ADMIN_ALIAS_SET); + if (!admin && !owner) { + MainUtil.sendMessage(player, Captions.NO_PLOT_PERMS); + return false; + } + if (permission) { // is either admin or owner setAlias(player, plot, args[1]); return true; } else { - MainUtil.sendMessage(player, Captions.NO_PERMISSION); + MainUtil.sendMessage(player, Captions.NO_PERMISSION, + Captions.PERMISSION_ALIAS_SET.getTranslated()); } break; case "remove": - if (canExecuteCommand(player, Captions.PERMISSION_ALIAS_REMOVE, true)) { + permission = isPermitted(player, Captions.PERMISSION_ALIAS_REMOVE); + admin = isPermitted(player, Captions.PERMISSION_ADMIN_ALIAS_REMOVE); + if (!admin && !owner) { + MainUtil.sendMessage(player, Captions.NO_PLOT_PERMS); + return false; + } + if (permission) { result = removeAlias(player, plot); + } else { + MainUtil.sendMessage(player, Captions.NO_PERMISSION, + Captions.PERMISSION_ALIAS_REMOVE.getTranslated()); } break; default: @@ -99,6 +120,20 @@ public class Alias extends SubCommand { return result; } + @Override + public Collection tab(PlotPlayer player, String[] args, boolean space) { + final List commands = new ArrayList<>(2); + if (args.length == 1) { + if ("set".startsWith(args[0])) { + commands.add(SET_COMMAND); + } + if ("remove".startsWith(args[0])) { + commands.add(REMOVE_COMMAND); + } + return commands; + } + return Collections.emptySet(); + } private void setAlias(PlotPlayer player, Plot plot, String alias) { if (alias.isEmpty()) { @@ -110,11 +145,11 @@ public class Alias extends SubCommand { } else if (MathMan.isInteger(alias)) { Captions.NOT_VALID_VALUE.send(player); } else { - for (Plot p : PlotSquared.get().getPlots(plot.getArea())) { - if (p.getAlias().equalsIgnoreCase(alias)) { - MainUtil.sendMessage(player, Captions.ALIAS_IS_TAKEN); - return; - } + if (PlotQuery.newQuery().inArea(plot.getArea()) + .withAlias(alias) + .anyMatch()) { + MainUtil.sendMessage(player, Captions.ALIAS_IS_TAKEN); + return; } PlotSquared.get().getImpromptuUUIDPipeline().getSingle(alias, ((uuid, throwable) -> { if (throwable instanceof TimeoutException) { @@ -130,19 +165,13 @@ public class Alias extends SubCommand { } } - private boolean removeAlias(PlotPlayer player, Plot plot) { + private boolean removeAlias(PlotPlayer player, Plot plot) { plot.setAlias(null); MainUtil.sendMessage(player, Captions.ALIAS_REMOVED.getTranslated()); return true; } - private boolean canExecuteCommand(PlotPlayer player, Captions caption, boolean sendMessage) { - if (!Permissions.hasPermission(player, caption)) { - if (sendMessage) { - MainUtil.sendMessage(player, Captions.NO_PERMISSION); - } - return false; - } - return true; + private boolean isPermitted(PlotPlayer player, Captions caption) { + return Permissions.hasPermission(player, caption); } } diff --git a/Core/src/main/java/com/plotsquared/core/configuration/Captions.java b/Core/src/main/java/com/plotsquared/core/configuration/Captions.java index 03874da48..dbcf463ac 100644 --- a/Core/src/main/java/com/plotsquared/core/configuration/Captions.java +++ b/Core/src/main/java/com/plotsquared/core/configuration/Captions.java @@ -182,7 +182,9 @@ public enum Captions implements Caption { PERMISSION_HOME("plots.home", "static.permissions"), PERMISSION_ALIAS_SET_OBSOLETE("plots.set.alias", "static.permissions"), // Note this is for backwards compatibility PERMISSION_ALIAS_SET("plots.alias.set", "static.permissions"), + PERMISSION_ADMIN_ALIAS_SET("plots.admin.alias.set", "static.permissions"), PERMISSION_ALIAS_REMOVE("plots.alias.remove", "static.permissions"), + PERMISSION_ADMIN_ALIAS_REMOVE("plots.admin.alias.remove", "static.permissions"), PERMISSION_ADMIN_CHAT_BYPASS("plots.admin.chat.bypass", "static.permissions"), PERMISSION_BACKUP("plots.backup", "static.permissions"), PERMISSION_BACKUP_SAVE("plots.backup.save", "static.permissions"), diff --git a/Core/src/main/java/com/plotsquared/core/util/query/PlotQuery.java b/Core/src/main/java/com/plotsquared/core/util/query/PlotQuery.java index 40d883062..27b4352eb 100644 --- a/Core/src/main/java/com/plotsquared/core/util/query/PlotQuery.java +++ b/Core/src/main/java/com/plotsquared/core/util/query/PlotQuery.java @@ -376,6 +376,30 @@ public final class PlotQuery { return this.asList(); } + /** + * Get whether any provided plot matches the given filters. + * If no plot was provided, false will be returned. + * + * @return true if any provided plot matches the filters. + */ + public boolean anyMatch() { + if (this.filters.isEmpty()) { + return !this.plotProvider.getPlots().isEmpty(); + } else { + final Collection plots = this.plotProvider.getPlots(); + outer: for (final Plot plot : plots) { + // a plot must pass all filters to match the criteria + for (final PlotFilter filter : this.filters) { + if (!filter.accepts(plot)) { + continue outer; + } + } + return true; // a plot passed all filters, so we have a match + } + return false; + } + } + @NotNull private PlotQuery addFilter(@NotNull final PlotFilter filter) { this.filters.add(filter); return this; From 49c35ec084f861ad1017d7b0e47aaaaa27fe3a1b Mon Sep 17 00:00:00 2001 From: MattBDev <4009945+MattBDev@users.noreply.github.com> Date: Mon, 29 Jun 2020 22:05:32 -0400 Subject: [PATCH 17/52] Resolve NMF's concerns --- Bukkit/build.gradle | 5 +- Bukkit/pom.xml | 12 +- .../entity/ReplicatingEntityWrapper.java | 338 +++++++++--------- 3 files changed, 185 insertions(+), 170 deletions(-) diff --git a/Bukkit/build.gradle b/Bukkit/build.gradle index 6b011faf7..61ae5e54f 100644 --- a/Bukkit/build.gradle +++ b/Bukkit/build.gradle @@ -25,7 +25,10 @@ dependencies { compile("com.destroystokyo.paper:paper-api:1.16.1-R0.1-SNAPSHOT") //implementation 'com.onarandombox.multiversecore:Multiverse-Core:3.0.0-SNAPSHOT' implementation("org.spigotmc:spigot-api:1.16.1-R0.1-SNAPSHOT") - compile(group: "com.sk89q.worldedit", name: "worldedit-bukkit", version: "7.0.1") + compile(group: "com.sk89q.worldedit", name: "worldedit-bukkit", version: "7.1.0") { + exclude(module: "bukkit") + + } compile("io.papermc:paperlib:1.0.2") implementation("net.kyori:text-adapter-bukkit:3.0.3") compile("com.github.MilkBowl:VaultAPI:1.7") { diff --git a/Bukkit/pom.xml b/Bukkit/pom.xml index d01f91307..d70af5d57 100644 --- a/Bukkit/pom.xml +++ b/Bukkit/pom.xml @@ -27,14 +27,20 @@ com.destroystokyo.paper paper-api - 1.15.2-R0.1-SNAPSHOT + 1.16.1-R0.1-SNAPSHOT compile com.sk89q.worldedit worldedit-bukkit - 7.0.1 + 7.1.0 compile + + + bukkit + * + + io.papermc @@ -131,7 +137,7 @@ org.spigotmc spigot-api - 1.15.2-R0.1-SNAPSHOT + 1.16.1-R0.1-SNAPSHOT runtime diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/entity/ReplicatingEntityWrapper.java b/Bukkit/src/main/java/com/plotsquared/bukkit/entity/ReplicatingEntityWrapper.java index f0ef20fba..83740e9db 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/entity/ReplicatingEntityWrapper.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/entity/ReplicatingEntityWrapper.java @@ -103,51 +103,51 @@ public final class ReplicatingEntityWrapper extends EntityWrapper { if (!entity.hasGravity()) { this.noGravity = true; } - switch (entity.getType()) { - case BOAT: + switch (entity.getType().toString()) { + case "BOAT": Boat boat = (Boat) entity; this.dataByte = getOrdinal(TreeSpecies.values(), boat.getWoodType()); return; - case ARROW: - case EGG: - case ENDER_CRYSTAL: - case ENDER_PEARL: - case ENDER_SIGNAL: - case EXPERIENCE_ORB: - case FALLING_BLOCK: - case FIREBALL: - case FIREWORK: - case FISHING_HOOK: - case LEASH_HITCH: - case LIGHTNING: - case MINECART: - case MINECART_COMMAND: - case MINECART_MOB_SPAWNER: - case MINECART_TNT: - case PLAYER: - case PRIMED_TNT: - case SLIME: - case SMALL_FIREBALL: - case SNOWBALL: - case MINECART_FURNACE: - case SPLASH_POTION: - case THROWN_EXP_BOTTLE: - case WITHER_SKULL: - case UNKNOWN: - case SPECTRAL_ARROW: - case SHULKER_BULLET: - case DRAGON_FIREBALL: - case AREA_EFFECT_CLOUD: - case TRIDENT: - case LLAMA_SPIT: + case "ARROW": + case "EGG": + case "ENDER_CRYSTAL": + case "ENDER_PEARL": + case "ENDER_SIGNAL": + case "EXPERIENCE_ORB": + case "FALLING_BLOCK": + case "FIREBALL": + case "FIREWORK": + case "FISHING_HOOK": + case "LEASH_HITCH": + case "LIGHTNING": + case "MINECART": + case "MINECART_COMMAND": + case "MINECART_MOB_SPAWNER": + case "MINECART_TNT": + case "PLAYER": + case "PRIMED_TNT": + case "SLIME": + case "SMALL_FIREBALL": + case "SNOWBALL": + case "MINECART_FURNACE": + case "SPLASH_POTION": + case "THROWN_EXP_BOTTLE": + case "WITHER_SKULL": + case "UNKNOWN": + case "SPECTRAL_ARROW": + case "SHULKER_BULLET": + case "DRAGON_FIREBALL": + case "AREA_EFFECT_CLOUD": + case "TRIDENT": + case "LLAMA_SPIT": // Do this stuff later return; // MISC // - case DROPPED_ITEM: + case "DROPPED_ITEM": Item item = (Item) entity; this.stack = item.getItemStack(); return; - case ITEM_FRAME: + case "ITEM_FRAME": this.x = Math.floor(this.x); this.y = Math.floor(this.y); this.z = Math.floor(this.z); @@ -155,7 +155,7 @@ public final class ReplicatingEntityWrapper extends EntityWrapper { this.dataByte = getOrdinal(Rotation.values(), itemFrame.getRotation()); this.stack = itemFrame.getItem().clone(); return; - case PAINTING: + case "PAINTING": this.x = Math.floor(this.x); this.y = Math.floor(this.y); this.z = Math.floor(this.z); @@ -170,18 +170,18 @@ public final class ReplicatingEntityWrapper extends EntityWrapper { return; // END MISC // // INVENTORY HOLDER // - case MINECART_CHEST: - case MINECART_HOPPER: + case "MINECART_CHEST": + case "MINECART_HOPPER": storeInventory((InventoryHolder) entity); return; // START LIVING ENTITY // // START AGEABLE // // START TAMEABLE // - case HORSE: - case DONKEY: - case LLAMA: - case MULE: - case SKELETON_HORSE: + case "HORSE": + case "DONKEY": + case "LLAMA": + case "MULE": + case "SKELETON_HORSE": AbstractHorse horse = (AbstractHorse) entity; this.horse = new HorseStats(); this.horse.jump = horse.getJumpStrength(); @@ -199,15 +199,15 @@ public final class ReplicatingEntityWrapper extends EntityWrapper { storeInventory(horse); return; // END INVENTORY HOLDER // - case WOLF: - case OCELOT: + case "WOLF": + case "OCELOT": storeTameable((Tameable) entity); storeAgeable((Ageable) entity); storeLiving((LivingEntity) entity); return; // END TAMEABLE // //todo fix sheep - case SHEEP: + case "SHEEP": Sheep sheep = (Sheep) entity; if (sheep.isSheared()) { this.dataByte = (byte) 1; @@ -218,23 +218,23 @@ public final class ReplicatingEntityWrapper extends EntityWrapper { storeAgeable(sheep); storeLiving(sheep); return; - case VILLAGER: - case CHICKEN: - case COW: - case MUSHROOM_COW: - case PIG: - case TURTLE: - case POLAR_BEAR: + case "VILLAGER": + case "CHICKEN": + case "COW": + case "MUSHROOM_COW": + case "PIG": + case "TURTLE": + case "POLAR_BEAR": storeAgeable((Ageable) entity); storeLiving((LivingEntity) entity); return; - case RABBIT: + case "RABBIT": this.dataByte = getOrdinal(Rabbit.Type.values(), ((Rabbit) entity).getRabbitType()); storeAgeable((Ageable) entity); storeLiving((LivingEntity) entity); return; // END AGEABLE // - case ARMOR_STAND: + case "ARMOR_STAND": ArmorStand stand = (ArmorStand) entity; this.inventory = new ItemStack[] {stand.getItemInHand().clone(), stand.getHelmet().clone(), @@ -286,42 +286,45 @@ public final class ReplicatingEntityWrapper extends EntityWrapper { this.stand.small = true; } return; - case ENDERMITE: + case "ENDERMITE": return; - case BAT: + case "BAT": if (((Bat) entity).isAwake()) { this.dataByte = (byte) 1; } else { this.dataByte = (byte) 0; } return; - case ENDER_DRAGON: + case "ENDER_DRAGON": EnderDragon entity1 = (EnderDragon) entity; this.dataByte = (byte) entity1.getPhase().ordinal(); return; - case SKELETON: - case WITHER_SKELETON: - case GUARDIAN: - case ELDER_GUARDIAN: - case GHAST: - case MAGMA_CUBE: - case SQUID: - case PIG_ZOMBIE: - case ZOMBIE: - case WITHER: - case WITCH: - case SPIDER: - case CAVE_SPIDER: - case SILVERFISH: - case GIANT: - case ENDERMAN: - case CREEPER: - case BLAZE: - case SHULKER: - case SNOWMAN: + case "SKELETON": + case "WITHER_SKELETON": + case "GUARDIAN": + case "ELDER_GUARDIAN": + case "GHAST": + case "MAGMA_CUBE": + case "SQUID": + case "PIG_ZOMBIE": + case "HOGLIN": + case "ZOMBIFIED_PIGLIN": + case "PIGLIN": + case "ZOMBIE": + case "WITHER": + case "WITCH": + case "SPIDER": + case "CAVE_SPIDER": + case "SILVERFISH": + case "GIANT": + case "ENDERMAN": + case "CREEPER": + case "BLAZE": + case "SHULKER": + case "SNOWMAN": storeLiving((LivingEntity) entity); return; - case IRON_GOLEM: + case "IRON_GOLEM": if (((IronGolem) entity).isPlayerCreated()) { this.dataByte = (byte) 1; } else { @@ -463,16 +466,16 @@ public final class ReplicatingEntityWrapper extends EntityWrapper { return null; } Entity entity; - switch (this.getType()) { - case DROPPED_ITEM: + switch (this.getType().toString()) { + case "DROPPED_ITEM": return world.dropItem(location, this.stack); - case PLAYER: - case LEASH_HITCH: + case "PLAYER": + case "LEASH_HITCH": return null; - case ITEM_FRAME: + case "ITEM_FRAME": entity = world.spawn(location, ItemFrame.class); break; - case PAINTING: + case "PAINTING": entity = world.spawn(location, Painting.class); break; default: @@ -504,73 +507,73 @@ public final class ReplicatingEntityWrapper extends EntityWrapper { if (this.noGravity) { entity.setGravity(false); } - switch (entity.getType()) { - case BOAT: + switch (entity.getType().toString()) { + case "BOAT": Boat boat = (Boat) entity; boat.setWoodType(TreeSpecies.values()[dataByte]); return entity; - case SLIME: + case "SLIME": ((Slime) entity).setSize(this.dataByte); return entity; - case ARROW: - case EGG: - case ENDER_CRYSTAL: - case ENDER_PEARL: - case ENDER_SIGNAL: - case DROPPED_ITEM: - case EXPERIENCE_ORB: - case FALLING_BLOCK: - case FIREBALL: - case FIREWORK: - case FISHING_HOOK: - case LEASH_HITCH: - case LIGHTNING: - case MINECART: - case MINECART_COMMAND: - case MINECART_MOB_SPAWNER: - case MINECART_TNT: - case PLAYER: - case PRIMED_TNT: - case SMALL_FIREBALL: - case SNOWBALL: - case SPLASH_POTION: - case THROWN_EXP_BOTTLE: - case SPECTRAL_ARROW: - case SHULKER_BULLET: - case AREA_EFFECT_CLOUD: - case DRAGON_FIREBALL: - case WITHER_SKULL: - case MINECART_FURNACE: - case LLAMA_SPIT: - case TRIDENT: - case UNKNOWN: + case "ARROW": + case "EGG": + case "ENDER_CRYSTAL": + case "ENDER_PEARL": + case "ENDER_SIGNAL": + case "DROPPED_ITEM": + case "EXPERIENCE_ORB": + case "FALLING_BLOCK": + case "FIREBALL": + case "FIREWORK": + case "FISHING_HOOK": + case "LEASH_HITCH": + case "LIGHTNING": + case "MINECART": + case "MINECART_COMMAND": + case "MINECART_MOB_SPAWNER": + case "MINECART_TNT": + case "PLAYER": + case "PRIMED_TNT": + case "SMALL_FIREBALL": + case "SNOWBALL": + case "SPLASH_POTION": + case "THROWN_EXP_BOTTLE": + case "SPECTRAL_ARROW": + case "SHULKER_BULLET": + case "AREA_EFFECT_CLOUD": + case "DRAGON_FIREBALL": + case "WITHER_SKULL": + case "MINECART_FURNACE": + case "LLAMA_SPIT": + case "TRIDENT": + case "UNKNOWN": // Do this stuff later return entity; // MISC // - case ITEM_FRAME: + case "ITEM_FRAME": ItemFrame itemframe = (ItemFrame) entity; itemframe.setRotation(Rotation.values()[this.dataByte]); itemframe.setItem(this.stack); return entity; - case PAINTING: + case "PAINTING": Painting painting = (Painting) entity; painting.setFacingDirection(BlockFace.values()[this.dataByte], true); painting.setArt(Art.getByName(this.dataString), true); return entity; // END MISC // // INVENTORY HOLDER // - case MINECART_CHEST: - case MINECART_HOPPER: + case "MINECART_CHEST": + case "MINECART_HOPPER": restoreInventory((InventoryHolder) entity); return entity; // START LIVING ENTITY // // START AGEABLE // // START TAMEABLE // - case HORSE: - case LLAMA: - case SKELETON_HORSE: - case DONKEY: - case MULE: + case "HORSE": + case "LLAMA": + case "SKELETON_HORSE": + case "DONKEY": + case "MULE": AbstractHorse horse = (AbstractHorse) entity; horse.setJumpStrength(this.horse.jump); if (horse instanceof ChestedHorse) { @@ -586,14 +589,14 @@ public final class ReplicatingEntityWrapper extends EntityWrapper { restoreInventory(horse); return entity; // END INVENTORY HOLDER // - case WOLF: - case OCELOT: + case "WOLF": + case "OCELOT": restoreTameable((Tameable) entity); restoreAgeable((Ageable) entity); restoreLiving((LivingEntity) entity); return entity; // END AGEABLE // - case SHEEP: + case "SHEEP": Sheep sheep = (Sheep) entity; if (this.dataByte == 1) { sheep.setSheared(true); @@ -604,25 +607,25 @@ public final class ReplicatingEntityWrapper extends EntityWrapper { restoreAgeable(sheep); restoreLiving(sheep); return sheep; - case VILLAGER: - case CHICKEN: - case COW: - case TURTLE: - case POLAR_BEAR: - case MUSHROOM_COW: - case PIG: + case "VILLAGER": + case "CHICKEN": + case "COW": + case "TURTLE": + case "POLAR_BEAR": + case "MUSHROOM_COW": + case "PIG": restoreAgeable((Ageable) entity); restoreLiving((LivingEntity) entity); return entity; // END AGEABLE // - case RABBIT: + case "RABBIT": if (this.dataByte != 0) { ((Rabbit) entity).setRabbitType(Rabbit.Type.values()[this.dataByte]); } restoreAgeable((Ageable) entity); restoreLiving((LivingEntity) entity); return entity; - case ARMOR_STAND: + case "ARMOR_STAND": // CHECK positions ArmorStand stand = (ArmorStand) entity; if (this.inventory[0] != null) { @@ -688,42 +691,45 @@ public final class ReplicatingEntityWrapper extends EntityWrapper { } restoreLiving(stand); return stand; - case BAT: + case "BAT": if (this.dataByte != 0) { ((Bat) entity).setAwake(true); } restoreLiving((LivingEntity) entity); return entity; - case ENDER_DRAGON: + case "ENDER_DRAGON": if (this.dataByte != 0) { ((EnderDragon) entity).setPhase(EnderDragon.Phase.values()[this.dataByte]); } restoreLiving((LivingEntity) entity); return entity; - case ENDERMITE: - case GHAST: - case MAGMA_CUBE: - case SQUID: - case PIG_ZOMBIE: - case ZOMBIE: - case WITHER: - case WITCH: - case SPIDER: - case CAVE_SPIDER: - case SILVERFISH: - case GIANT: - case ENDERMAN: - case CREEPER: - case BLAZE: - case SNOWMAN: - case SHULKER: - case GUARDIAN: - case ELDER_GUARDIAN: - case SKELETON: - case WITHER_SKELETON: + case "ENDERMITE": + case "GHAST": + case "MAGMA_CUBE": + case "SQUID": + case "PIG_ZOMBIE": + case "HOGLIN": + case "PIGLIN": + case "ZOMBIFIED_PIGLIN": + case "ZOMBIE": + case "WITHER": + case "WITCH": + case "SPIDER": + case "CAVE_SPIDER": + case "SILVERFISH": + case "GIANT": + case "ENDERMAN": + case "CREEPER": + case "BLAZE": + case "SNOWMAN": + case "SHULKER": + case "GUARDIAN": + case "ELDER_GUARDIAN": + case "SKELETON": + case "WITHER_SKELETON": restoreLiving((LivingEntity) entity); return entity; - case IRON_GOLEM: + case "IRON_GOLEM": if (this.dataByte != 0) { ((IronGolem) entity).setPlayerCreated(true); } From cbe8875b94c19e25159e3262e23ba998b4a26621 Mon Sep 17 00:00:00 2001 From: N0tMyFaultOG Date: Wed, 1 Jul 2020 11:59:28 +0200 Subject: [PATCH 18/52] Bump gradle version --- gradle/wrapper/gradle-wrapper.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 4c5803d13..bb8b2fc26 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.4-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists From c5ec8e1931953f7ad224fa4749d5919885a2b310 Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Wed, 1 Jul 2020 14:21:18 +0100 Subject: [PATCH 19/52] actually fix all conflicts --- .../bukkit/listener/PlayerEvents.java | 427 +++++++++--------- 1 file changed, 207 insertions(+), 220 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java index 530b7a8ec..f6e845bc6 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java @@ -2966,262 +2966,249 @@ public class PlayerEvents extends PlotListener implements Listener { return false; } } else if (EntityCategories.ANIMAL.contains(entityType)) { // victim is animal -<<<<<<>>>>>>v5 return true; - } if (!Permissions.hasPermission(plotPlayer, "plots.admin.pve." + stub)) { - MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT, - "plots.admin.pve." + stub); - return false; - } - } else if (EntityCategories.VEHICLE - .contains(entityType)) { // Vehicles are managed in vehicle destroy event - return true; - } else { // victim is something else - if (isPlot) { - if (plot.getFlag(PveFlag.class) || plot.isAdded(plotPlayer.getUUID())) { - return true; - } - } else if (roadFlags && area.getFlag(PveFlag.class)) { - return true; - } if (!Permissions.hasPermission(plotPlayer, "plots.admin.pve." + stub)) { MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT, "plots.admin.pve." + stub); - if (plot != null) { - plot.debug(player.getName() + " could not attack " + entityType - + " because pve = false"); - } return false; } - } return true; - } else if (dplot != null && (!dplot.equals(vplot) || Objects - .equals(dplot.getOwnerAbs(), vplot.getOwnerAbs()))) { - return vplot != null && vplot.getFlag(PveFlag.class); - } - //disable the firework damage. too much of a headache to support at the moment. - if (vplot != null) { - if (EntityDamageEvent.DamageCause.ENTITY_EXPLOSION == cause - && damager.getType() == EntityType.FIREWORK) { + } + } else if (EntityCategories.VEHICLE + .contains(entityType)) { // Vehicles are managed in vehicle destroy event + return true; + } else { // victim is something else + if (isPlot) { + if (plot.getFlag(PveFlag.class) || plot.isAdded(plotPlayer.getUUID())) { + return true; + } + } else if (roadFlags && area.getFlag(PveFlag.class)) { + return true; + } + if (!Permissions.hasPermission(plotPlayer, "plots.admin.pve." + stub)) { + MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT, + "plots.admin.pve." + stub); + if (plot != null) { + plot.debug(player.getName() + " could not attack " + entityType + + " because pve = false"); + } return false; } } - if (vplot == null && roadFlags && area.getFlag(PveFlag.class)) { - return true; - } - return ((vplot != null && vplot.getFlag(PveFlag.class)) || !(damager instanceof Arrow - && !(victim instanceof Creature))); + return true; + } else if (dplot != null && (!dplot.equals(vplot) || Objects + .equals(dplot.getOwnerAbs(), vplot.getOwnerAbs()))) { + return vplot != null && vplot.getFlag(PveFlag.class); } - - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onPlayerEggThrow (PlayerEggThrowEvent event){ - Location location = BukkitUtil.getLocation(event.getEgg().getLocation()); - PlotArea area = location.getPlotArea(); - if (area == null) { - return; - } - Player player = event.getPlayer(); - BukkitPlayer plotPlayer = BukkitUtil.getPlayer(player); - Plot plot = area.getPlot(location); - if (plot == null) { - if (!Permissions.hasPermission(plotPlayer, "plots.admin.projectile.road")) { - MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT, - "plots.admin.projectile.road"); - event.setHatching(false); - } - } else if (!plot.hasOwner()) { - if (!Permissions.hasPermission(plotPlayer, "plots.admin.projectile.unowned")) { - MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT, - "plots.admin.projectile.unowned"); - event.setHatching(false); - } - } else if (!plot.isAdded(plotPlayer.getUUID())) { - if (!Permissions.hasPermission(plotPlayer, "plots.admin.projectile.other")) { - MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT, - "plots.admin.projectile.other"); - event.setHatching(false); - } + //disable the firework damage. too much of a headache to support at the moment. + if (vplot != null) { + if (EntityDamageEvent.DamageCause.ENTITY_EXPLOSION == cause + && damager.getType() == EntityType.FIREWORK) { + return false; } } + if (vplot == null && roadFlags && area.getFlag(PveFlag.class)) { + return true; + } + return ((vplot != null && vplot.getFlag(PveFlag.class)) || !(damager instanceof Arrow + && !(victim instanceof Creature))); + } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void blockCreate (BlockPlaceEvent event){ - Location location = BukkitUtil.getLocation(event.getBlock().getLocation()); - PlotArea area = location.getPlotArea(); - if (area == null) { - return; + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onPlayerEggThrow(PlayerEggThrowEvent event) { + Location location = BukkitUtil.getLocation(event.getEgg().getLocation()); + PlotArea area = location.getPlotArea(); + if (area == null) { + return; + } + Player player = event.getPlayer(); + BukkitPlayer plotPlayer = BukkitUtil.getPlayer(player); + Plot plot = area.getPlot(location); + if (plot == null) { + if (!Permissions.hasPermission(plotPlayer, "plots.admin.projectile.road")) { + MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT, + "plots.admin.projectile.road"); + event.setHatching(false); } - Player player = event.getPlayer(); + } else if (!plot.hasOwner()) { + if (!Permissions.hasPermission(plotPlayer, "plots.admin.projectile.unowned")) { + MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT, + "plots.admin.projectile.unowned"); + event.setHatching(false); + } + } else if (!plot.isAdded(plotPlayer.getUUID())) { + if (!Permissions.hasPermission(plotPlayer, "plots.admin.projectile.other")) { + MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT, + "plots.admin.projectile.other"); + event.setHatching(false); + } + } + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void blockCreate(BlockPlaceEvent event) { + Location location = BukkitUtil.getLocation(event.getBlock().getLocation()); + PlotArea area = location.getPlotArea(); + if (area == null) { + return; + } + Player player = event.getPlayer(); + BukkitPlayer pp = BukkitUtil.getPlayer(player); + Plot plot = area.getPlot(location); + if (plot != null) { + if ((location.getY() > area.getMaxBuildHeight() || location.getY() < area + .getMinBuildHeight()) && !Permissions + .hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_HEIGHT_LIMIT)) { + event.setCancelled(true); + MainUtil.sendMessage(pp, Captions.HEIGHT_LIMIT.getTranslated() + .replace("{limit}", String.valueOf(area.getMaxBuildHeight()))); + } + if (!plot.hasOwner()) { + if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_UNOWNED)) { + MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, + Captions.PERMISSION_ADMIN_BUILD_UNOWNED); + event.setCancelled(true); + return; + } + } else if (!plot.isAdded(pp.getUUID())) { + List place = plot.getFlag(PlaceFlag.class); + if (place != null) { + Block block = event.getBlock(); + if (place.contains( + BlockTypeWrapper.get(BukkitAdapter.asBlockType(block.getType())))) { + return; + } + } + if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_OTHER)) { + MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, + Captions.PERMISSION_ADMIN_BUILD_OTHER); + event.setCancelled(true); + plot.debug(player.getName() + " could not place " + event.getBlock().getType() + + " because of the place flag"); + return; + } + } else if (Settings.Done.RESTRICT_BUILDING && DoneFlag.isDone(plot)) { + if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_OTHER)) { + MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, + Captions.PERMISSION_ADMIN_BUILD_OTHER); + event.setCancelled(true); + return; + } + } + if (plot.getFlag(DisablePhysicsFlag.class)) { + Block block = event.getBlockPlaced(); + if (block.getType().hasGravity()) { + sendBlockChange(block.getLocation(), block.getBlockData()); + plot.debug(event.getBlock().getType() + + " did not fall because of disable-physics = true"); + } + } + } else if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_ROAD)) { + MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, + Captions.PERMISSION_ADMIN_BUILD_ROAD); + event.setCancelled(true); + } + } + + @EventHandler(priority = EventPriority.HIGH) public void onDamage(EntityDamageEvent event) { + if (event.getEntityType() != EntityType.PLAYER) { + return; + } + Location location = BukkitUtil.getLocation(event.getEntity()); + PlotArea area = location.getPlotArea(); + if (area == null) { + return; + } + Plot plot = location.getOwnedPlot(); + if (plot == null) { + if (area.isRoadRespectingGlobalFlags() && area.getFlag(InvincibleFlag.class)) { + event.setCancelled(true); + } + return; + } + if (plot.getFlag(InvincibleFlag.class)) { + plot.debug( + event.getEntity().getName() + " could not take damage because invincible = true"); + event.setCancelled(true); + } + } + + @EventHandler public void onItemDrop(PlayerDropItemEvent event) { + Player player = event.getPlayer(); + BukkitPlayer pp = BukkitUtil.getPlayer(player); + Location location = pp.getLocation(); + PlotArea area = location.getPlotArea(); + if (area == null) { + return; + } + Plot plot = location.getOwnedPlot(); + if (plot == null) { + if (area.isRoadRespectingGlobalFlags() && area.getFlag(ItemDropFlag.class)) { + event.setCancelled(true); + } + return; + } + UUID uuid = pp.getUUID(); + if (!plot.isAdded(uuid)) { + if (!plot.getFlag(ItemDropFlag.class)) { + plot.debug(player.getName() + " could not drop item because of item-drop = false"); + event.setCancelled(true); + } + } + } + + @EventHandler public void onItemPickup(EntityPickupItemEvent event) { + LivingEntity ent = event.getEntity(); + if (ent instanceof Player) { + Player player = (Player) ent; BukkitPlayer pp = BukkitUtil.getPlayer(player); - Plot plot = area.getPlot(location); - if (plot != null) { - if ((location.getY() > area.getMaxBuildHeight() || location.getY() < area - .getMinBuildHeight()) && !Permissions - .hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_HEIGHT_LIMIT)) { - event.setCancelled(true); - MainUtil.sendMessage(pp, Captions.HEIGHT_LIMIT.getTranslated() - .replace("{limit}", String.valueOf(area.getMaxBuildHeight()))); - } - if (!plot.hasOwner()) { - if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_UNOWNED)) { - MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, - Captions.PERMISSION_ADMIN_BUILD_UNOWNED); - event.setCancelled(true); - return; - } - } else if (!plot.isAdded(pp.getUUID())) { - List place = plot.getFlag(PlaceFlag.class); - if (place != null) { - Block block = event.getBlock(); - if (place.contains( - BlockTypeWrapper.get(BukkitAdapter.asBlockType(block.getType())))) { - return; - } - } - if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_OTHER)) { - MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, - Captions.PERMISSION_ADMIN_BUILD_OTHER); - event.setCancelled(true); - plot.debug( - player.getName() + " could not place " + event.getBlock().getType() - + " because of the place flag"); - return; - } - } else if (Settings.Done.RESTRICT_BUILDING && DoneFlag.isDone(plot)) { - if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_OTHER)) { - MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, - Captions.PERMISSION_ADMIN_BUILD_OTHER); - event.setCancelled(true); - return; - } - } - if (plot.getFlag(DisablePhysicsFlag.class)) { - Block block = event.getBlockPlaced(); - if (block.getType().hasGravity()) { - sendBlockChange(block.getLocation(), block.getBlockData()); - plot.debug(event.getBlock().getType() - + " did not fall because of disable-physics = true"); - } - } - } else if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_ROAD)) { - MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, - Captions.PERMISSION_ADMIN_BUILD_ROAD); - event.setCancelled(true); - } - } - - @EventHandler(priority = EventPriority.HIGH) public void onDamage (EntityDamageEvent event){ - if (event.getEntityType() != EntityType.PLAYER) { - return; - } - Location location = BukkitUtil.getLocation(event.getEntity()); - PlotArea area = location.getPlotArea(); - if (area == null) { - return; - } - Plot plot = location.getOwnedPlot(); - if (plot == null) { - if (area.isRoadRespectingGlobalFlags() && area.getFlag(InvincibleFlag.class)) { - event.setCancelled(true); - } - return; - } - if (plot.getFlag(InvincibleFlag.class)) { - plot.debug(event.getEntity().getName() - + " could not take damage because invincible = true"); - event.setCancelled(true); - } - } - - @EventHandler public void onItemDrop (PlayerDropItemEvent event){ - Player player = event.getPlayer(); -<<<<<<>>>>>>v5 if (plot == null) { - if (area.isRoadRespectingGlobalFlags() && area.getFlag(ItemDropFlag.class)) { + if (plot == null) { + if (area.isRoadRespectingGlobalFlags() && area.getFlag(DropProtectionFlag.class)) { event.setCancelled(true); } return; } UUID uuid = pp.getUUID(); - if (!plot.isAdded(uuid)) { - if (!plot.getFlag(ItemDropFlag.class)) { - plot.debug( - player.getName() + " could not drop item because of item-drop = false"); - event.setCancelled(true); - } + if (!plot.isAdded(uuid) && plot.getFlag(DropProtectionFlag.class)) { + plot.debug( + player.getName() + " could not pick up item because of drop-protection = true"); + event.setCancelled(true); } } + } - @EventHandler public void onItemPickup (EntityPickupItemEvent event){ - LivingEntity ent = event.getEntity(); - if (ent instanceof Player) { - Player player = (Player) ent; -<<<<<<>>>>>>v5 if (plot == null) { - if (area.isRoadRespectingGlobalFlags() && area - .getFlag(DropProtectionFlag.class)) { - event.setCancelled(true); - } - return; - } - UUID uuid = pp.getUUID(); - if (!plot.isAdded(uuid) && plot.getFlag(DropProtectionFlag.class)) { - plot.debug(player.getName() - + " could not pick up item because of drop-protection = true"); - event.setCancelled(true); - } - } + @EventHandler public void onDeath(final PlayerDeathEvent event) { + Location location = BukkitUtil.getLocation(event.getEntity()); + PlotArea area = location.getPlotArea(); + if (area == null) { + return; } - - @EventHandler public void onDeath ( final PlayerDeathEvent event){ -<<<<<<>>>>>>v5 event.setKeepInventory(true); - } + plot.debug(event.getEntity().getName() + + " kept their inventory because of keep-inventory = true"); + event.setKeepInventory(true); } - } + } +} From 2910176b97f66a534545c99756dff56234b296f2 Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Wed, 1 Jul 2020 14:53:57 +0100 Subject: [PATCH 20/52] Add road flag container --- .../bukkit/listener/PlayerEvents.java | 53 +++++++------- .../com/plotsquared/core/plot/PlotArea.java | 70 +++++++++++++++++-- 2 files changed, 90 insertions(+), 33 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java index f6e845bc6..841470413 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java @@ -343,8 +343,7 @@ public class PlayerEvents extends PlotListener implements Listener { } Plot plot = location.getOwnedPlot(); if (plot == null) { - if (area.isRoadRespectingGlobalFlags() && area. - getFlag(RedstoneFlag.class)) { + if (area.isRoadFlags() && area.getRoadFlag(RedstoneFlag.class)) { event.setNewCurrent(0); } return; @@ -578,7 +577,7 @@ public class PlayerEvents extends PlotListener implements Listener { return; } } - if (plot == null && !area.isRoadRespectingGlobalFlags()) { + if (plot == null && !area.isRoadFlags()) { return; } @@ -631,8 +630,6 @@ public class PlayerEvents extends PlotListener implements Listener { String perm; if (plot != null && plot.isAdded(plotPlayer.getUUID())) { perm = "plots.admin.command.blocked-cmds.shared"; - } else if (!area.isRoadRespectingGlobalFlags()) { - perm = "plots.admin.command.blocked-cmds.other"; } else { perm = "plots.admin.command.blocked-cmds.road"; } @@ -1745,13 +1742,11 @@ public class PlayerEvents extends PlotListener implements Listener { } } else { PlotArea area = pp.getPlotAreaAbs(); - if (area != null && area.isRoadRespectingGlobalFlags() && area - .getFlag(PreventCreativeCopyFlag.class)) { + if (area != null && area.isRoadFlags() && area + .getRoadFlag(PreventCreativeCopyFlag.class)) { final ItemStack newStack = new ItemStack(newItem.getType(), newItem.getAmount()); event.setCursor(newStack); - plot.debug(player.getName() - + " could not creative-copy an item because prevent-creative-copy = true"); } } return; @@ -1869,7 +1864,7 @@ public class PlayerEvents extends PlotListener implements Listener { Plot plot = location.getPlotAbs(); BukkitPlayer pp = BukkitUtil.getPlayer(e.getPlayer()); if (plot == null) { - if (!area.isRoadRespectingGlobalFlags() && !area.getFlag(MiscInteractFlag.class) + if (!area.isRoadFlags() && !area.getRoadFlag(MiscInteractFlag.class) && !Permissions.hasPermission(pp, "plots.admin.interact.road")) { MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, "plots.admin.interact.road"); e.setCancelled(true); @@ -1883,8 +1878,8 @@ public class PlayerEvents extends PlotListener implements Listener { return; } } - if (!plot.hasOwner() && !area.isRoadRespectingGlobalFlags() && !area - .getFlag(MiscInteractFlag.class)) { + if (!plot.hasOwner() && !area.isRoadFlags() && !area + .getRoadFlag(MiscInteractFlag.class)) { if (!Permissions.hasPermission(pp, "plots.admin.interact.unowned")) { MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, "plots.admin.interact.unowned"); @@ -2235,7 +2230,9 @@ public class PlayerEvents extends PlotListener implements Listener { Plot plot = location.getOwnedPlot(); if (plot == null || !plot.getFlag(BlockBurnFlag.class)) { - plot.debug("Block burning was cancelled because block-burn = false"); + if (plot != null) { + plot.debug("Block burning was cancelled because block-burn = false"); + } event.setCancelled(true); } @@ -2592,7 +2589,7 @@ public class PlayerEvents extends PlotListener implements Listener { Player p = event.getPlayer(); BukkitPlayer pp = BukkitUtil.getPlayer(p); Plot plot = area.getPlot(location); - if (plot == null && !area.isRoadRespectingGlobalFlags()) { + if (plot == null && !area.isRoadFlags()) { if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_INTERACT_ROAD)) { MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_INTERACT_ROAD); @@ -2605,14 +2602,14 @@ public class PlayerEvents extends PlotListener implements Listener { event.setCancelled(true); } } else if ((plot != null && !plot.isAdded(pp.getUUID())) || area - .isRoadRespectingGlobalFlags()) { + .isRoadFlags()) { final Entity entity = event.getRightClicked(); final com.sk89q.worldedit.world.entity.EntityType entityType = BukkitAdapter.adapt(entity.getType()); FlagContainer flagContainer; if (plot == null) { - flagContainer = area.getFlagContainer(); + flagContainer = area.getRoadFlagContainer(); } else { flagContainer = plot.getFlagContainer(); } @@ -2839,9 +2836,7 @@ public class PlayerEvents extends PlotListener implements Listener { stub = "unowned"; } } - boolean roadFlags = vArea != null ? - vArea.isRoadRespectingGlobalFlags() : - dArea.isRoadRespectingGlobalFlags(); + boolean roadFlags = vArea != null ? vArea.isRoadFlags() : dArea.isRoadFlags(); PlotArea area = vArea != null ? vArea : dArea; Player player; @@ -2913,7 +2908,7 @@ public class PlayerEvents extends PlotListener implements Listener { .isAdded(plotPlayer.getUUID())) { return true; } - } else if (roadFlags && (area.getFlag(HostileAttackFlag.class) || area + } else if (roadFlags && (area.getRoadFlag(HostileAttackFlag.class) || area .getFlag(PveFlag.class))) { return true; } @@ -2932,7 +2927,7 @@ public class PlayerEvents extends PlotListener implements Listener { .isAdded(plotPlayer.getUUID())) { return true; } - } else if (roadFlags && (area.getFlag(TamedAttackFlag.class) || area + } else if (roadFlags && (area.getRoadFlag(TamedAttackFlag.class) || area .getFlag(PveFlag.class))) { return true; } @@ -2957,7 +2952,7 @@ public class PlayerEvents extends PlotListener implements Listener { } else { return true; } - } else if (roadFlags && area.getFlag(PvpFlag.class)) { + } else if (roadFlags && area.getRoadFlag(PvpFlag.class)) { return true; } if (!Permissions.hasPermission(plotPlayer, "plots.admin.pvp." + stub)) { @@ -2973,7 +2968,7 @@ public class PlayerEvents extends PlotListener implements Listener { + " because pve = false OR animal-attack = false"); return true; } - } else if (roadFlags && (area.getFlag(AnimalAttackFlag.class) || area + } else if (roadFlags && (area.getRoadFlag(AnimalAttackFlag.class) || area .getFlag(PveFlag.class))) { if (!Permissions.hasPermission(plotPlayer, "plots.admin.pve." + stub)) { MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT, @@ -2989,7 +2984,7 @@ public class PlayerEvents extends PlotListener implements Listener { if (plot.getFlag(PveFlag.class) || plot.isAdded(plotPlayer.getUUID())) { return true; } - } else if (roadFlags && area.getFlag(PveFlag.class)) { + } else if (roadFlags && area.getRoadFlag(PveFlag.class)) { return true; } if (!Permissions.hasPermission(plotPlayer, "plots.admin.pve." + stub)) { @@ -3014,7 +3009,7 @@ public class PlayerEvents extends PlotListener implements Listener { return false; } } - if (vplot == null && roadFlags && area.getFlag(PveFlag.class)) { + if (vplot == null && roadFlags && area.getRoadFlag(PveFlag.class)) { return true; } return ((vplot != null && vplot.getFlag(PveFlag.class)) || !(damager instanceof Arrow @@ -3128,7 +3123,7 @@ public class PlayerEvents extends PlotListener implements Listener { } Plot plot = location.getOwnedPlot(); if (plot == null) { - if (area.isRoadRespectingGlobalFlags() && area.getFlag(InvincibleFlag.class)) { + if (area.isRoadFlags() && area.getRoadFlag(InvincibleFlag.class)) { event.setCancelled(true); } return; @@ -3150,7 +3145,7 @@ public class PlayerEvents extends PlotListener implements Listener { } Plot plot = location.getOwnedPlot(); if (plot == null) { - if (area.isRoadRespectingGlobalFlags() && area.getFlag(ItemDropFlag.class)) { + if (area.isRoadFlags() && area.getRoadFlag(ItemDropFlag.class)) { event.setCancelled(true); } return; @@ -3176,7 +3171,7 @@ public class PlayerEvents extends PlotListener implements Listener { } Plot plot = location.getOwnedPlot(); if (plot == null) { - if (area.isRoadRespectingGlobalFlags() && area.getFlag(DropProtectionFlag.class)) { + if (area.isRoadFlags() && area.getRoadFlag(DropProtectionFlag.class)) { event.setCancelled(true); } return; @@ -3198,7 +3193,7 @@ public class PlayerEvents extends PlotListener implements Listener { } Plot plot = location.getOwnedPlot(); if (plot == null) { - if (area.isRoadRespectingGlobalFlags() && area.getFlag(KeepInventoryFlag.class)) { + if (area.isRoadFlags() && area.getRoadFlag(KeepInventoryFlag.class)) { event.setCancelled(true); } return; diff --git a/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java b/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java index 868b9f475..08ac2f962 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java +++ b/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java @@ -118,7 +118,7 @@ public abstract class PlotArea { @Getter private GameMode gameMode = GameModes.CREATIVE; @Getter private Map> prices = new HashMap<>(); @Getter(AccessLevel.PROTECTED) private List schematics = new ArrayList<>(); - @Getter private boolean roadRespectingGlobalFlags = false; + @Getter private boolean roadFlags = false; private boolean worldBorder = false; private boolean useEconomy = false; private int hash; @@ -128,7 +128,9 @@ public abstract class PlotArea { /** * Area flag container */ - @Getter private FlagContainer flagContainer = + @Getter private final FlagContainer flagContainer = + new FlagContainer(GlobalFlagContainer.getInstance()); + @Getter private final FlagContainer roadFlagContainer = new FlagContainer(GlobalFlagContainer.getInstance()); public PlotArea(@NotNull final String worldName, @Nullable final String id, @@ -371,7 +373,40 @@ public abstract class PlotArea { this.spawnEggs = config.getBoolean("event.spawn.egg"); this.spawnCustom = config.getBoolean("event.spawn.custom"); this.spawnBreeding = config.getBoolean("event.spawn.breeding"); - this.roadRespectingGlobalFlags = config.getBoolean("road.respect-global-flags"); + + List roadflags = config.getStringList("flags.default"); + if (roadflags.isEmpty()) { + roadflags = config.getStringList("road.flags"); + if (roadflags.isEmpty()) { + roadflags = new ArrayList<>(); + ConfigurationSection section = config.getConfigurationSection("road.flags"); + Set keys = section.getKeys(false); + for (String key : keys) { + if (!"default".equals(key)) { + roadflags.add(key + ';' + section.get(key)); + } + } + } + } + this.getRoadFlagContainer().addAll(parseFlags(roadflags)); + + StringBuilder roadFlagBuilder = new StringBuilder(); + Collection> roadFlagCollection = this.getFlagContainer().getFlagMap().values(); + if (roadFlagCollection.isEmpty()) { + roadFlagBuilder.append(Captions.NONE.getTranslated()); + } else { + roadFlags = true; + String prefix = " "; + for (final PlotFlag flag : roadFlagCollection) { + Object value = flag.toString(); + roadFlagBuilder.append(prefix).append(CaptionUtility + .format(null, Captions.PLOT_FLAG_LIST.getTranslated(), flag.getName(), + CaptionUtility.formatRaw(null, value.toString(), ""))); + prefix = ", "; + } + } + PlotSquared.log(Captions.PREFIX + "&3 - road flags: &7" + roadFlagBuilder.toString()); + loadConfiguration(config); } @@ -415,7 +450,7 @@ public abstract class PlotArea { options.put("world.max_height", this.getMaxBuildHeight()); options.put("world.min_height", this.getMinBuildHeight()); options.put("world.gamemode", this.getGameMode().getName().toLowerCase()); - options.put("road.respect-global-flags", this.isRoadRespectingGlobalFlags()); + options.put("road.flags.default", null); if (this.getType() != PlotAreaType.NORMAL) { options.put("generator.terrain", this.getTerrain()); @@ -437,6 +472,9 @@ public abstract class PlotArea { config.set("flags.use", "63,64,68,69,71,77,96,143,167,193,194,195,196,197,77,143,69,70,72,147,148,107,183,184,185,186,187,132"); } + if (!config.contains("road.flags")) { + config.set("road.flags.liquid-flow", false); + } } @NotNull @Override public String toString() { @@ -1096,4 +1134,28 @@ public abstract class PlotArea { final PlotFlag flagInstance = this.flagContainer.getFlagErased(flagClass); return FlagContainer.castUnsafe(flagInstance).getValue(); } + + /** + * Get the value associated with the specified road flag. This will look at + * the default values stored in {@link GlobalFlagContainer}. + * + * @param flagClass The flag type (Class) + * @return The flag value + */ + public T getRoadFlag(final Class> flagClass) { + return this.roadFlagContainer.getFlag(flagClass).getValue(); + } + + /** + * Get the value associated with the specified road flag. This will look at + * the default values stored in {@link GlobalFlagContainer}. + * + * @param flag The flag type (Any instance of the flag) + * @return The flag value + */ + public > T getRoadFlag(final V flag) { + final Class flagClass = flag.getClass(); + final PlotFlag flagInstance = this.roadFlagContainer.getFlagErased(flagClass); + return FlagContainer.castUnsafe(flagInstance).getValue(); + } } From b71de856a85fac2b7979199ba242c8cd17728ab5 Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Wed, 1 Jul 2020 20:04:37 +0100 Subject: [PATCH 21/52] allow plugins extending and replacing RegionManager to be notified of, and "accept" plot clear "requests". . . . . . FAWE --- .../com/plotsquared/core/util/RegionManager.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Core/src/main/java/com/plotsquared/core/util/RegionManager.java b/Core/src/main/java/com/plotsquared/core/util/RegionManager.java index ab3333a19..9f6c64696 100644 --- a/Core/src/main/java/com/plotsquared/core/util/RegionManager.java +++ b/Core/src/main/java/com/plotsquared/core/util/RegionManager.java @@ -29,6 +29,7 @@ import com.plotsquared.core.PlotSquared; import com.plotsquared.core.location.Location; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.PlotArea; +import com.plotsquared.core.plot.PlotManager; import com.plotsquared.core.queue.LocalBlockQueue; import com.plotsquared.core.util.task.RunnableVal; import com.plotsquared.core.util.task.TaskManager; @@ -163,6 +164,20 @@ public abstract class RegionManager { return queue.enqueue(); } + /** + * Notify any plugins that may want to modify clear behaviour that a clear is occuring + * + * @return true if the notified will accept the clear task + */ + public boolean notifyClear() { + return false; + } + + /** + * Only called when {@link RegionManager#notifyClear()} returns true in specific PlotManagers + */ + public abstract boolean handleClear(Plot plot, final Runnable whenDone, PlotManager manager); + /** * Copy a region to a new location (in the same world) */ From 580212d66d0f5fb12031ad6185445b0f8057a564 Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Wed, 1 Jul 2020 21:36:46 +0100 Subject: [PATCH 22/52] fix build --- .../com/plotsquared/bukkit/util/BukkitRegionManager.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitRegionManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitRegionManager.java index 158f90928..fc71c9d31 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitRegionManager.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitRegionManager.java @@ -32,6 +32,7 @@ import com.plotsquared.core.location.Location; import com.plotsquared.core.location.PlotLoc; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.PlotArea; +import com.plotsquared.core.plot.PlotManager; import com.plotsquared.core.queue.GlobalBlockQueue; import com.plotsquared.core.queue.LocalBlockQueue; import com.plotsquared.core.queue.ScopedLocalBlockQueue; @@ -109,6 +110,10 @@ public class BukkitRegionManager extends RegionManager { return chunks; } + @Override public boolean handleClear(Plot plot, Runnable whenDone, PlotManager manager) { + return false; + } + @Override public int[] countEntities(Plot plot) { int[] existing = (int[]) plot.getMeta("EntityCount"); if (existing != null && (System.currentTimeMillis() - (long) plot.getMeta("EntityCountTime") From ad1ec42b1284fd80783f805673a696b59dc7d435 Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Thu, 2 Jul 2020 14:33:22 +0100 Subject: [PATCH 23/52] Add new clear pipeline to hpw and make some stuff read access as required. --- .../plotsquared/core/generator/HybridPlotManager.java | 10 +++++++++- .../plotsquared/core/generator/HybridPlotWorld.java | 3 ++- .../java/com/plotsquared/core/util/RegionManager.java | 6 ++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Core/src/main/java/com/plotsquared/core/generator/HybridPlotManager.java b/Core/src/main/java/com/plotsquared/core/generator/HybridPlotManager.java index 3fd91eb3c..67ad6eb8b 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/HybridPlotManager.java +++ b/Core/src/main/java/com/plotsquared/core/generator/HybridPlotManager.java @@ -40,12 +40,14 @@ import com.plotsquared.core.util.ChunkManager; import com.plotsquared.core.util.FileBytes; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.MathMan; +import com.plotsquared.core.util.RegionManager; import com.plotsquared.core.util.task.RunnableVal; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockTypes; +import lombok.Getter; import java.io.File; import java.io.IOException; @@ -56,7 +58,7 @@ public class HybridPlotManager extends ClassicPlotManager { public static boolean REGENERATIVE_CLEAR = true; - private final HybridPlotWorld hybridPlotWorld; + @Getter private final HybridPlotWorld hybridPlotWorld; public HybridPlotManager(HybridPlotWorld hybridPlotWorld) { super(hybridPlotWorld); @@ -199,6 +201,12 @@ public class HybridPlotManager extends ClassicPlotManager { *

*/ @Override public boolean clearPlot(Plot plot, final Runnable whenDone) { + if (RegionManager.manager.notifyClear(this)) { + //If this returns false, the clear didn't work + if (RegionManager.manager.handleClear(plot, whenDone, this)) { + return true; + } + } final String world = hybridPlotWorld.getWorldName(); Location pos1 = plot.getBottomAbs(); Location pos2 = plot.getExtendedTopAbs(); diff --git a/Core/src/main/java/com/plotsquared/core/generator/HybridPlotWorld.java b/Core/src/main/java/com/plotsquared/core/generator/HybridPlotWorld.java index e322072df..a561a9ac3 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/HybridPlotWorld.java +++ b/Core/src/main/java/com/plotsquared/core/generator/HybridPlotWorld.java @@ -50,6 +50,7 @@ import com.sk89q.worldedit.math.transform.AffineTransform; import com.sk89q.worldedit.util.Direction; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BaseBlock; +import lombok.Getter; import org.jetbrains.annotations.NotNull; import java.io.File; @@ -69,6 +70,7 @@ public class HybridPlotWorld extends ClassicPlotWorld { public HashMap G_SCH_B; public int SCHEM_Y; private Location SIGN_LOCATION; + @Getter private File root = null; public HybridPlotWorld(String worldName, String id, @NotNull IndependentPlotGenerator generator, PlotId min, PlotId max) { @@ -198,7 +200,6 @@ public class HybridPlotWorld extends ClassicPlotWorld { // Try to determine root. This means that plot areas can have separate schematic // directories - File root; if (!(root = MainUtil.getFile(PlotSquared.get().IMP.getDirectory(), "schematics/GEN_ROAD_SCHEMATIC/" + this.getWorldName() + "/" + this.getId())).exists()) { root = MainUtil.getFile(PlotSquared.get().IMP.getDirectory(), diff --git a/Core/src/main/java/com/plotsquared/core/util/RegionManager.java b/Core/src/main/java/com/plotsquared/core/util/RegionManager.java index 9f6c64696..1349e6c9a 100644 --- a/Core/src/main/java/com/plotsquared/core/util/RegionManager.java +++ b/Core/src/main/java/com/plotsquared/core/util/RegionManager.java @@ -169,12 +169,14 @@ public abstract class RegionManager { * * @return true if the notified will accept the clear task */ - public boolean notifyClear() { + public boolean notifyClear(PlotManager manager) { return false; } /** - * Only called when {@link RegionManager#notifyClear()} returns true in specific PlotManagers + * Only called when {@link RegionManager#notifyClear(PlotManager)} returns true in specific PlotManagers + * + * @return true if the clear worked. False if someone went wrong so P2 can then handle the clear */ public abstract boolean handleClear(Plot plot, final Runnable whenDone, PlotManager manager); From 0e7a6d7a629ca42fca86b3619fafe2fb0d3723b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Fri, 3 Jul 2020 13:47:50 +0200 Subject: [PATCH 24/52] Fix typo --- Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java index 2132fefac..fa969ce10 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java @@ -125,7 +125,6 @@ import org.bukkit.World; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.command.PluginCommand; import org.bukkit.entity.Entity; -import org.bukkit.entity.EntityType; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.Listener; @@ -354,7 +353,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< } impromptuPipeline.storeImmediately("*", DBFunc.EVERYONE); - this.startUuidCatching(sqLiteUUIDService, cacheUUIDService); + this.startUuidCaching(sqLiteUUIDService, cacheUUIDService); if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) { new Placeholders().register(); @@ -491,7 +490,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< } } - private void startUuidCatching(@NotNull final SQLiteUUIDService sqLiteUUIDService, + private void startUuidCaching(@NotNull final SQLiteUUIDService sqLiteUUIDService, @NotNull final CacheUUIDService cacheUUIDService) { // Load all uuids into a big chunky boi queue final Queue uuidQueue = new LinkedBlockingQueue<>(); From 429f5e55c3e33e5bbfe101b11ed3c62744ab295d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Fri, 3 Jul 2020 13:50:12 +0200 Subject: [PATCH 25/52] Add option to disable background caching --- Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java | 5 ++++- .../java/com/plotsquared/core/configuration/Settings.java | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java index fa969ce10..39a763d24 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java @@ -353,7 +353,10 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< } impromptuPipeline.storeImmediately("*", DBFunc.EVERYONE); - this.startUuidCaching(sqLiteUUIDService, cacheUUIDService); + + if (Settings.UUID.BACKGROUND_CACHING_ENABLED) { + this.startUuidCaching(sqLiteUUIDService, cacheUUIDService); + } if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) { new Placeholders().register(); diff --git a/Core/src/main/java/com/plotsquared/core/configuration/Settings.java b/Core/src/main/java/com/plotsquared/core/configuration/Settings.java index 80d103882..db22c46be 100644 --- a/Core/src/main/java/com/plotsquared/core/configuration/Settings.java +++ b/Core/src/main/java/com/plotsquared/core/configuration/Settings.java @@ -257,6 +257,9 @@ public class Settings extends Config { public static boolean LEGACY_DATABASE_SUPPORT = true; @Comment("Whether or not PlotSquared should return Unknown if it fails to fulfill a request") public static boolean UNKNOWN_AS_DEFAULT = true; + @Comment("Whether or not automatic background caching should be enabled. It is HIGHLY recommended to keep this turned on." + + " This should only be disabled if the server has a very large number of plots (>100k)") + public static boolean BACKGROUND_CACHING_ENABLED = true; } From b5818bfefcb3c40bebb397f7a7e49607fcc1095b Mon Sep 17 00:00:00 2001 From: Hannes Greule Date: Sat, 4 Jul 2020 20:25:33 +0200 Subject: [PATCH 26/52] Lazy fix for FancyMessage 1.16 --- .../plotsquared/bukkit/chat/FancyMessage.java | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/chat/FancyMessage.java b/Bukkit/src/main/java/com/plotsquared/bukkit/chat/FancyMessage.java index 173d49e95..739d3bbd4 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/chat/FancyMessage.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/chat/FancyMessage.java @@ -56,6 +56,7 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.UUID; import java.util.logging.Level; /** @@ -74,6 +75,7 @@ public class FancyMessage private static Constructor nmsPacketPlayOutChatConstructor; // The ChatSerializer's instance of Gson private static Object nmsChatSerializerGsonInstance; + private static Object chatMessageType; private static Method fromJsonMethod; private static JsonParser _stringParser = new JsonParser(); @@ -101,8 +103,16 @@ public class FancyMessage dirty = false; if (nmsPacketPlayOutChatConstructor == null) { try { - nmsPacketPlayOutChatConstructor = Reflection.getNMSClass("PacketPlayOutChat") - .getDeclaredConstructor(Reflection.getNMSClass("IChatBaseComponent")); + Class componentClass = Reflection.getNMSClass("IChatBaseComponent"); + if (!Reflection.getVersion().startsWith("v1_16")) { // < 1.16 TODO needs to be fixed before 1.17 :P + nmsPacketPlayOutChatConstructor = Reflection.getNMSClass("PacketPlayOutChat") + .getDeclaredConstructor(componentClass); + } else { + Class chatMessageTypeClass = (Class) Reflection.getNMSClass("ChatMessageType"); + nmsPacketPlayOutChatConstructor = Reflection.getNMSClass("PacketPlayOutChat") + .getDeclaredConstructor(componentClass, chatMessageTypeClass, UUID.class); + chatMessageType = Enum.valueOf(chatMessageTypeClass, "SYSTEM"); + } nmsPacketPlayOutChatConstructor.setAccessible(true); } catch (NoSuchMethodException e) { Bukkit.getLogger() @@ -773,7 +783,7 @@ public class FancyMessage Reflection.getField(handle.getClass(), "playerConnection").get(handle); Reflection .getMethod(connection.getClass(), "sendPacket", Reflection.getNMSClass("Packet")) - .invoke(connection, createChatPacket(jsonString)); + .invoke(connection, createChatPacket(jsonString, ((Player) sender).getUniqueId())); } catch (IllegalArgumentException e) { Bukkit.getLogger().log(Level.WARNING, "Argument could not be passed.", e); } catch (IllegalAccessException e) { @@ -790,7 +800,7 @@ public class FancyMessage } } - private Object createChatPacket(String json) + private Object createChatPacket(String json, UUID receiver) throws IllegalArgumentException, IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException, ClassNotFoundException { if (nmsChatSerializerGsonInstance == null) { @@ -838,7 +848,11 @@ public class FancyMessage Object serializedChatComponent = fromJsonMethod.invoke(nmsChatSerializerGsonInstance, json, Reflection.getNMSClass("IChatBaseComponent")); - return nmsPacketPlayOutChatConstructor.newInstance(serializedChatComponent); + if (!Reflection.getVersion().startsWith("v1_16")) { + return nmsPacketPlayOutChatConstructor.newInstance(serializedChatComponent); + } else { + return nmsPacketPlayOutChatConstructor.newInstance(serializedChatComponent, chatMessageType, receiver); + } } /** From c058614fcc1b8e7835d6e837930fea63713d6179 Mon Sep 17 00:00:00 2001 From: Hannes Greule Date: Mon, 6 Jul 2020 18:13:23 +0200 Subject: [PATCH 27/52] Split visit command into home and visit --- .../plotsquared/core/command/HomeCommand.java | 169 ++++++++++++++++++ .../plotsquared/core/command/MainCommand.java | 1 + .../com/plotsquared/core/command/Visit.java | 71 ++------ 3 files changed, 185 insertions(+), 56 deletions(-) create mode 100644 Core/src/main/java/com/plotsquared/core/command/HomeCommand.java diff --git a/Core/src/main/java/com/plotsquared/core/command/HomeCommand.java b/Core/src/main/java/com/plotsquared/core/command/HomeCommand.java new file mode 100644 index 000000000..779d97ef2 --- /dev/null +++ b/Core/src/main/java/com/plotsquared/core/command/HomeCommand.java @@ -0,0 +1,169 @@ +/* + * _____ _ _ _____ _ + * | __ \| | | | / ____| | | + * | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| | + * | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` | + * | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| | + * |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_| + * | | + * |_| + * PlotSquared plot management system for Minecraft + * Copyright (C) 2020 IntellectualSites + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.plotsquared.core.command; + +import com.plotsquared.core.PlotSquared; +import com.plotsquared.core.configuration.Captions; +import com.plotsquared.core.events.TeleportCause; +import com.plotsquared.core.player.PlotPlayer; +import com.plotsquared.core.plot.Plot; +import com.plotsquared.core.plot.PlotArea; +import com.plotsquared.core.plot.PlotId; +import com.plotsquared.core.util.MainUtil; +import com.plotsquared.core.util.MathMan; +import com.plotsquared.core.util.query.PlotQuery; +import com.plotsquared.core.util.query.SortingStrategy; +import com.plotsquared.core.util.task.RunnableVal2; +import com.plotsquared.core.util.task.RunnableVal3; +import org.jetbrains.annotations.NotNull; + +import java.util.List; +import java.util.concurrent.CompletableFuture; + +@CommandDeclaration(command = "home", + description = "Teleport to your plot(s)", + permission = "plots.home", + usage = "/plot home [||| ]", + aliases = {"h"}, + requiredType = RequiredType.PLAYER, + category = CommandCategory.TELEPORT) +public class HomeCommand extends Command { + public HomeCommand() { + super(MainCommand.getInstance(), true); + } + + private void home(@NotNull final PlotPlayer player, + @NotNull final PlotQuery query, final int page, + final RunnableVal3 confirm, + final RunnableVal2 whenDone) { + List plots = query.asList(); + if (plots.isEmpty()) { + Captions.FOUND_NO_PLOTS.send(player); + return; + } else if (plots.size() < page) { + MainUtil.sendMessage(player, + String.format(Captions.NUMBER_NOT_IN_RANGE.getTranslated(), "1", plots.size())); + return; + } + Plot plot = plots.get(page - 1); + confirm.run(this, () -> plot.teleportPlayer(player, TeleportCause.COMMAND, result -> { + if (result) { + whenDone.run(this, CommandResult.SUCCESS); + } else { + whenDone.run(HomeCommand.this, CommandResult.FAILURE); + } + }), () -> whenDone.run(HomeCommand.this, CommandResult.FAILURE)); + } + + @NotNull private PlotQuery query(@NotNull final PlotPlayer player) { + // everything plots need to have in common here + return PlotQuery.newQuery().ownedBy(player).whereBasePlot(); + } + + @Override public CompletableFuture execute(PlotPlayer player, String[] args, + RunnableVal3 confirm, + RunnableVal2 whenDone) throws CommandException { + // /plot home (or page, whatever it's called) + // /plot home + // /plot home <[area;]x;y> + // /plot home + // /plot home + if (args.length > 2) { + Captions.COMMAND_SYNTAX.send(player, getUsage()); + return CompletableFuture.completedFuture(false); + } + PlotQuery query = query(player); + int page = 1; // page = index + 1 + String identifier; + switch (args.length) { + case 1: + identifier = args[0]; + if (MathMan.isInteger(identifier)) { + try { + page = Integer.parseInt(identifier); + } catch (NumberFormatException ignored) { + Captions.NOT_A_NUMBER.send(player, identifier); + return CompletableFuture.completedFuture(false); + } + query.withSortingStrategy(SortingStrategy.SORT_BY_CREATION); + break; + } + // either plot id or alias + Plot fromId = MainUtil.getPlotFromString(player, identifier, false); + if (fromId != null && fromId.isOwner(player.getUUID())) { + // it was a valid plot id + query.withPlot(fromId); + break; + } + // it wasn't a valid plot id, trying to find plot by alias + query.withAlias(identifier); + break; + case 2: + // we assume args[0] is a plot area and args[1] an identifier + PlotArea plotArea = PlotSquared.get().getPlotAreaByString(args[0]); + identifier = args[1]; + if (plotArea == null) { + // invalid command, therefore no plots + query.noPlots(); + break; + } + query.inArea(plotArea); + if (MathMan.isInteger(identifier)) { + // identifier is a page number + try { + page = Integer.parseInt(identifier); + } catch (NumberFormatException ignored) { + Captions.NOT_A_NUMBER.send(player, identifier); + return CompletableFuture.completedFuture(false); + } + query.withSortingStrategy(SortingStrategy.SORT_BY_CREATION); + break; + } + // identifier needs to be a plot id then + PlotId id = PlotId.fromStringOrNull(identifier); + if (id == null) { + // invalid command, therefore no plots + query.noPlots(); + break; + } + // we can try to get this plot + Plot plot = plotArea.getPlot(id); + if (plot == null) { + query.noPlots(); + break; + } + // as the query already filters by owner, this is fine + query.withPlot(plot); + break; + case 0: + query.withSortingStrategy(SortingStrategy.SORT_BY_CREATION); + break; + } + home(player, query, page, confirm, whenDone); + return CompletableFuture.completedFuture(true); + } + +} diff --git a/Core/src/main/java/com/plotsquared/core/command/MainCommand.java b/Core/src/main/java/com/plotsquared/core/command/MainCommand.java index a5c42b117..0df008815 100644 --- a/Core/src/main/java/com/plotsquared/core/command/MainCommand.java +++ b/Core/src/main/java/com/plotsquared/core/command/MainCommand.java @@ -77,6 +77,7 @@ public class MainCommand extends Command { new RegenAllRoads(); new Claim(); new Auto(); + new HomeCommand(); new Visit(); new Set(); new Clear(); diff --git a/Core/src/main/java/com/plotsquared/core/command/Visit.java b/Core/src/main/java/com/plotsquared/core/command/Visit.java index f5243b4ba..e2faaf19e 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Visit.java +++ b/Core/src/main/java/com/plotsquared/core/command/Visit.java @@ -54,8 +54,8 @@ import java.util.concurrent.TimeoutException; @CommandDeclaration(command = "visit", permission = "plots.visit", description = "Visit someones plot", - usage = "/plot visit [|||] [#]", - aliases = {"v", "tp", "teleport", "goto", "home", "h", "warp"}, + usage = "/plot visit <||> [#]", + aliases = {"v", "tp", "teleport", "goto", "warp"}, requiredType = RequiredType.PLAYER, category = CommandCategory.TELEPORT) public class Visit extends Command { @@ -155,7 +155,7 @@ public class Visit extends Command { switch (args.length) { // /p v [...] [...] case 3: - if (!MathMan.isInteger(args[1])) { + if (!MathMan.isInteger(args[2])) { Captions.NOT_VALID_NUMBER.send(player, "(1, ∞)"); Captions.COMMAND_SYNTAX.send(player, getUsage()); return CompletableFuture.completedFuture(false); @@ -188,24 +188,13 @@ public class Visit extends Command { } page = Integer.parseInt(args[1]); // /p v [page] - // /p v [page] // /p v [page] // /p v [page] case 1: final String[] finalArgs = args; int finalPage = page; - // Try to determine whether the given argument is a username - // or an ordinal - boolean isNumber = false; - if (args[0].length() < 2) { - isNumber = true; - } else if (args[0].length() <= 4 && MathMan.isInteger(args[0])) { - // Check if it's an all-digit username that is stored in cache - final UUIDMapping mapping = PlotSquared.get().getImpromptuUUIDPipeline().getImmediately(args[0]); - // If no UUID could be found, then we assume it's a number and not a username - isNumber = mapping == null; - } - if (!isNumber && args[0].length() >= 2 && !args[0].contains(";") && !args[0].contains(",")) { + + if (args[0].length() >= 2 && !args[0].contains(";") && !args[0].contains(",")) { PlotSquared.get().getImpromptuUUIDPipeline().getSingle(args[0], (uuid, throwable) -> { if (throwable instanceof TimeoutException) { // The request timed out @@ -214,61 +203,31 @@ public class Visit extends Command { // It was a valid UUID but the player has no plots MainUtil.sendMessage(player, Captions.PLAYER_NO_PLOTS); } else if (uuid == null) { - if (finalPage == Integer.MIN_VALUE && MathMan.isInteger(finalArgs[0])) { - // The argument was a number, so we assume it's the page number - int parsedPage; - try { - parsedPage = Integer.parseInt(finalArgs[0]); - } catch (final Throwable t) { - MainUtil.sendMessage(player, Captions.NOT_A_NUMBER, finalArgs[0]); - return; - } - this.visit(player, PlotQuery.newQuery().ownedBy(player).whereBasePlot(), null, - confirm, whenDone, parsedPage); - } else { - // Try to parse a plot - final Plot plot = MainUtil.getPlotFromString(player, finalArgs[0], true); - if (plot == null) { - MainUtil.sendMessage(player, Captions.NOT_VALID_PLOT_ID); - return; - } - this.visit(player, PlotQuery.newQuery().withPlot(plot), null, confirm, whenDone, 1); - } + // player not found + MainUtil.sendMessage(player, Captions.INVALID_PLAYER, finalArgs[0]); } else { this.visit(player, PlotQuery.newQuery().ownedBy(uuid).whereBasePlot(), null, confirm, whenDone, finalPage); } }); } else { - if (finalPage == Integer.MIN_VALUE && MathMan.isInteger(finalArgs[0])) { - // The argument was a number, so we assume it's the page number - int parsedPage; - try { - parsedPage = Integer.parseInt(finalArgs[0]); - this.visit(player, PlotQuery.newQuery().ownedBy(player).whereBasePlot(), null, confirm, - whenDone, parsedPage); - } catch (final Throwable throwable) { - MainUtil.sendMessage(player, Captions.NOT_A_NUMBER, finalArgs[0]); - } - } else { - // Try to parse a plot - final Plot plot = MainUtil.getPlotFromString(player, finalArgs[0], true); - if (plot != null) { - this.visit(player, PlotQuery.newQuery().withPlot(plot), null, confirm, whenDone, 1); - } + // Try to parse a plot + final Plot plot = MainUtil.getPlotFromString(player, finalArgs[0], true); + if (plot != null) { + this.visit(player, PlotQuery.newQuery().withPlot(plot), null, confirm, whenDone, 1); } } break; case 0: - // /p v - this.visit(player, PlotQuery.newQuery().ownedBy(player), null, confirm, whenDone); - break; + // /p v is invalid + Captions.COMMAND_SYNTAX.send(player, getUsage()); + return CompletableFuture.completedFuture(false); default: } return CompletableFuture.completedFuture(true); } - public Collection tab(PlotPlayer player, String[] args, boolean space) { + @Override public Collection tab(PlotPlayer player, String[] args, boolean space) { final List completions = new LinkedList<>(); switch (args.length - 1) { case 0: From 3d087b1bbe40a358951675c6968f2a6b73f02867 Mon Sep 17 00:00:00 2001 From: Hannes Greule Date: Tue, 7 Jul 2020 14:30:31 +0200 Subject: [PATCH 28/52] Fix tab completion and usage --- .../plotsquared/core/command/HomeCommand.java | 29 ++++++++- .../com/plotsquared/core/command/Visit.java | 31 ++++++---- .../plotsquared/core/util/TabCompletions.java | 60 +++++++++++++++++++ 3 files changed, 107 insertions(+), 13 deletions(-) diff --git a/Core/src/main/java/com/plotsquared/core/command/HomeCommand.java b/Core/src/main/java/com/plotsquared/core/command/HomeCommand.java index 779d97ef2..07c15147a 100644 --- a/Core/src/main/java/com/plotsquared/core/command/HomeCommand.java +++ b/Core/src/main/java/com/plotsquared/core/command/HomeCommand.java @@ -34,19 +34,22 @@ import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.plot.PlotId; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.MathMan; +import com.plotsquared.core.util.TabCompletions; import com.plotsquared.core.util.query.PlotQuery; import com.plotsquared.core.util.query.SortingStrategy; import com.plotsquared.core.util.task.RunnableVal2; import com.plotsquared.core.util.task.RunnableVal3; import org.jetbrains.annotations.NotNull; +import java.util.ArrayList; +import java.util.Collection; import java.util.List; import java.util.concurrent.CompletableFuture; @CommandDeclaration(command = "home", description = "Teleport to your plot(s)", permission = "plots.home", - usage = "/plot home [||| ]", + usage = "/plot home [||| | ]", aliases = {"h"}, requiredType = RequiredType.PLAYER, category = CommandCategory.TELEPORT) @@ -166,4 +169,28 @@ public class HomeCommand extends Command { return CompletableFuture.completedFuture(true); } + @Override + public Collection tab(PlotPlayer player, String[] args, boolean space) { + final List completions = new ArrayList<>(); + switch (args.length - 1) { + case 0: + completions.addAll( + TabCompletions.completeAreas(args[0])); + if (args[0].isEmpty()) { + // if no input is given, only suggest 1 - 3 + completions.addAll( + TabCompletions.asCompletions("1", "2", "3")); + break; + } + // complete more numbers from the already given input + completions.addAll( + TabCompletions.completeNumbers(args[0], 10, 999)); + break; + case 1: + completions.addAll( + TabCompletions.completeNumbers(args[1], 10, 999)); + break; + } + return completions; + } } diff --git a/Core/src/main/java/com/plotsquared/core/command/Visit.java b/Core/src/main/java/com/plotsquared/core/command/Visit.java index e2faaf19e..b984d7c58 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Visit.java +++ b/Core/src/main/java/com/plotsquared/core/command/Visit.java @@ -40,12 +40,11 @@ import com.plotsquared.core.util.query.PlotQuery; import com.plotsquared.core.util.query.SortingStrategy; import com.plotsquared.core.util.task.RunnableVal2; import com.plotsquared.core.util.task.RunnableVal3; -import com.plotsquared.core.uuid.UUIDMapping; import org.jetbrains.annotations.NotNull; +import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.LinkedList; import java.util.List; import java.util.UUID; import java.util.concurrent.CompletableFuture; @@ -54,7 +53,7 @@ import java.util.concurrent.TimeoutException; @CommandDeclaration(command = "visit", permission = "plots.visit", description = "Visit someones plot", - usage = "/plot visit <||> [#]", + usage = "/plot visit || [area]|[#] [#]", aliases = {"v", "tp", "teleport", "goto", "warp"}, requiredType = RequiredType.PLAYER, category = CommandCategory.TELEPORT) @@ -153,7 +152,7 @@ public class Visit extends Command { int page = Integer.MIN_VALUE; switch (args.length) { - // /p v [...] [...] + // /p v case 3: if (!MathMan.isInteger(args[2])) { Captions.NOT_VALID_NUMBER.send(player, "(1, ∞)"); @@ -228,24 +227,32 @@ public class Visit extends Command { } @Override public Collection tab(PlotPlayer player, String[] args, boolean space) { - final List completions = new LinkedList<>(); + final List completions = new ArrayList<>(); switch (args.length - 1) { case 0: - this.completeNumbers(completions, args[0], 0); completions.addAll(TabCompletions.completePlayers(args[0], Collections.emptyList())); - break; + break; case 1: - if (MathMan.isInteger(args[0])) { + completions.addAll( + TabCompletions.completeAreas(args[1])); + if (args[1].isEmpty()) { + // if no input is given, only suggest 1 - 3 + completions.addAll( + TabCompletions.asCompletions("1", "2", "3")); break; } - this.completeNumbers(completions, args[1], 0); - this.completeAreas(completions, args[1]); + completions.addAll( + TabCompletions.completeNumbers(args[1], 10, 999)); break; case 2: - if (MathMan.isInteger(args[1])) { + if (args[2].isEmpty()) { + // if no input is given, only suggest 1 - 3 + completions.addAll( + TabCompletions.asCompletions("1", "2", "3")); break; } - this.completeNumbers(completions, args[2], 0); + completions.addAll( + TabCompletions.completeNumbers(args[2], 10, 999)); break; } diff --git a/Core/src/main/java/com/plotsquared/core/util/TabCompletions.java b/Core/src/main/java/com/plotsquared/core/util/TabCompletions.java index 56a3ff8fa..077ac4563 100644 --- a/Core/src/main/java/com/plotsquared/core/util/TabCompletions.java +++ b/Core/src/main/java/com/plotsquared/core/util/TabCompletions.java @@ -34,6 +34,7 @@ import com.plotsquared.core.command.RequiredType; import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; +import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.uuid.UUIDMapping; import lombok.experimental.UtilityClass; import org.jetbrains.annotations.NotNull; @@ -136,6 +137,65 @@ public class TabCompletions { return Collections.emptyList(); } + /** + * Get a list of integer numbers matching the given input. If the input string + * is empty, nothing will be returned. The list is unmodifiable. + * + * @param input Input to filter with + * @param amountLimit Maximum amount of suggestions + * @param highestLimit Highest number to include + * @return Unmodifiable list of number completions + */ + @NotNull public List completeNumbers(@NotNull final String input, + final int amountLimit, final int highestLimit) { + if (input.isEmpty() || input.length() > highestLimit || !MathMan.isInteger(input)) { + return Collections.emptyList(); + } + int offset; + try { + offset = Integer.parseInt(input) * 10; + } catch (NumberFormatException ignored) { + return Collections.emptyList(); + } + final List commands = new ArrayList<>(); + for (int i = offset; i < highestLimit && (offset - i + amountLimit) > 0; i++) { + commands.add(String.valueOf(i)); + } + return asCompletions(commands.toArray(new String[0])); + } + + /** + * Get a list of plot areas matching the given input. + * The list is unmodifiable. + * + * @param input Input to filter with + * @return Unmodifiable list of area completions + */ + @NotNull public List completeAreas(@NotNull final String input) { + final List completions = new ArrayList<>(); + for (final PlotArea area : PlotSquared.get().getPlotAreas()) { + String areaName = area.getWorldName(); + if (area.getId() != null) { + areaName += ";" + area.getId(); + } + if (!areaName.toLowerCase().startsWith(input.toLowerCase())) { + continue; + } + completions.add(new Command(null, false, areaName, "", + RequiredType.NONE, null) {}); + } + return Collections.unmodifiableList(completions); + } + + @NotNull public List asCompletions(String... toFilter) { + final List completions = new ArrayList<>(); + for (String completion : toFilter) { + completions.add(new Command(null, false, completion, "", + RequiredType.NONE, null) {}); + } + return Collections.unmodifiableList(completions); + } + /** * @param cacheIdentifier Cache key * @param input Command input From 3476522c005b7c7e5d5dd39eb2bc5e7050cce20b Mon Sep 17 00:00:00 2001 From: Hannes Greule Date: Tue, 7 Jul 2020 15:03:26 +0200 Subject: [PATCH 29/52] Allow /p v --- .../main/java/com/plotsquared/core/command/Visit.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Core/src/main/java/com/plotsquared/core/command/Visit.java b/Core/src/main/java/com/plotsquared/core/command/Visit.java index b984d7c58..9d803f6e3 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Visit.java +++ b/Core/src/main/java/com/plotsquared/core/command/Visit.java @@ -189,10 +189,10 @@ public class Visit extends Command { // /p v [page] // /p v [page] // /p v [page] + // /p v case 1: final String[] finalArgs = args; int finalPage = page; - if (args[0].length() >= 2 && !args[0].contains(";") && !args[0].contains(",")) { PlotSquared.get().getImpromptuUUIDPipeline().getSingle(args[0], (uuid, throwable) -> { if (throwable instanceof TimeoutException) { @@ -202,8 +202,12 @@ public class Visit extends Command { // It was a valid UUID but the player has no plots MainUtil.sendMessage(player, Captions.PLAYER_NO_PLOTS); } else if (uuid == null) { - // player not found - MainUtil.sendMessage(player, Captions.INVALID_PLAYER, finalArgs[0]); + // player not found, so we assume it's an alias if no page was provided + if (finalPage == Integer.MIN_VALUE) { + this.visit(player, PlotQuery.newQuery().withAlias(finalArgs[0]), player.getApplicablePlotArea(), confirm, whenDone, 1); + } else { + MainUtil.sendMessage(player, Captions.INVALID_PLAYER, finalArgs[0]); + } } else { this.visit(player, PlotQuery.newQuery().ownedBy(uuid).whereBasePlot(), null, confirm, whenDone, finalPage); } From 57127537f7fe0410387890ff69a3c2fdc5557115 Mon Sep 17 00:00:00 2001 From: Hannes Greule Date: Tue, 7 Jul 2020 19:40:25 +0200 Subject: [PATCH 30/52] Add permission check for /plot home --- .../main/java/com/plotsquared/core/command/HomeCommand.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Core/src/main/java/com/plotsquared/core/command/HomeCommand.java b/Core/src/main/java/com/plotsquared/core/command/HomeCommand.java index 07c15147a..b72276026 100644 --- a/Core/src/main/java/com/plotsquared/core/command/HomeCommand.java +++ b/Core/src/main/java/com/plotsquared/core/command/HomeCommand.java @@ -34,6 +34,7 @@ import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.plot.PlotId; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.MathMan; +import com.plotsquared.core.util.Permissions; import com.plotsquared.core.util.TabCompletions; import com.plotsquared.core.util.query.PlotQuery; import com.plotsquared.core.util.query.SortingStrategy; @@ -94,6 +95,11 @@ public class HomeCommand extends Command { // /plot home <[area;]x;y> // /plot home // /plot home + if (!Permissions.hasPermission(player, Captions.PERMISSION_VISIT_OWNED) && !Permissions + .hasPermission(player, Captions.PERMISSION_HOME)) { + Captions.NO_PERMISSION.send(player, Captions.PERMISSION_VISIT_OWNED); + return CompletableFuture.completedFuture(false); + } if (args.length > 2) { Captions.COMMAND_SYNTAX.send(player, getUsage()); return CompletableFuture.completedFuture(false); From 67a49a2ca71c968a09439feb9bf436df9827b3f7 Mon Sep 17 00:00:00 2001 From: N0tMyFaultOG Date: Tue, 7 Jul 2020 21:03:30 +0200 Subject: [PATCH 31/52] 5.12.3 --- Bukkit/pom.xml | 2 +- build.gradle | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Bukkit/pom.xml b/Bukkit/pom.xml index d70af5d57..b83fa3070 100644 --- a/Bukkit/pom.xml +++ b/Bukkit/pom.xml @@ -21,7 +21,7 @@ com.plotsquared PlotSquared-Core - 5.12.2 + 5.12.3 compile diff --git a/build.gradle b/build.gradle index c55d34847..a841bb030 100644 --- a/build.gradle +++ b/build.gradle @@ -30,7 +30,7 @@ ext { git = Grgit.open(dir: new File(rootDir.toString() + "/.git")) } -def ver = "5.12.2" +def ver = "5.12.3" def versuffix = "" ext { if (project.hasProperty("versionsuffix")) { From 5004005c5af2af0eaa68467757d856d4d9471731 Mon Sep 17 00:00:00 2001 From: N0tMyFaultOG Date: Wed, 8 Jul 2020 12:21:31 +0200 Subject: [PATCH 32/52] Fixes PS-65 EssentialsX uses paperlib 1.0.4 where we compile explicitly against 1.0.2 --- Bukkit/build.gradle | 5 +++-- Bukkit/pom.xml | 6 ++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Bukkit/build.gradle b/Bukkit/build.gradle index 61ae5e54f..1036e1089 100644 --- a/Bukkit/build.gradle +++ b/Bukkit/build.gradle @@ -23,7 +23,6 @@ dependencies { compile("org.bstats:bstats-bukkit:1.7") compile(project(":PlotSquared-Core")) compile("com.destroystokyo.paper:paper-api:1.16.1-R0.1-SNAPSHOT") - //implementation 'com.onarandombox.multiversecore:Multiverse-Core:3.0.0-SNAPSHOT' implementation("org.spigotmc:spigot-api:1.16.1-R0.1-SNAPSHOT") compile(group: "com.sk89q.worldedit", name: "worldedit-bukkit", version: "7.1.0") { exclude(module: "bukkit") @@ -36,7 +35,9 @@ dependencies { } implementation("me.clip:placeholderapi:2.10.6") implementation("net.luckperms:api:5.1") - implementation("net.ess3:EssentialsX:2.17.2") + implementation("net.ess3:EssentialsX:2.17.2") { + exclude(group: "io.papermc", module: "paperlib") + } implementation("net.alpenblock:BungeePerms:4.0-dev-106") compile("se.hyperver.hyperverse:Core:0.6.0-SNAPSHOT"){ transitive = false } compile('com.sk89q:squirrelid:1.0.0-SNAPSHOT'){ transitive = false } diff --git a/Bukkit/pom.xml b/Bukkit/pom.xml index b83fa3070..13e2e6fcf 100644 --- a/Bukkit/pom.xml +++ b/Bukkit/pom.xml @@ -163,6 +163,12 @@ EssentialsX 2.17.2 runtime + + + paperlib + io.papermc + + net.alpenblock From 265c10ec1c4ad1d3be5f72c7a0cf5be138de8d8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Wed, 8 Jul 2020 13:40:55 +0200 Subject: [PATCH 33/52] Remove `commands.yml` --- .../com/plotsquared/core/PlotSquared.java | 19 ---------- .../com/plotsquared/core/command/Command.java | 35 ++++--------------- 2 files changed, 6 insertions(+), 48 deletions(-) diff --git a/Core/src/main/java/com/plotsquared/core/PlotSquared.java b/Core/src/main/java/com/plotsquared/core/PlotSquared.java index 30d738afc..0ebcc7b1c 100644 --- a/Core/src/main/java/com/plotsquared/core/PlotSquared.java +++ b/Core/src/main/java/com/plotsquared/core/PlotSquared.java @@ -154,12 +154,10 @@ public class PlotSquared { public File styleFile; public File configFile; public File worldsFile; - public File commandsFile; public File translationFile; public YamlConfiguration style; public YamlConfiguration worlds; public YamlConfiguration storage; - public YamlConfiguration commands; // Temporary hold the plots/clusters before the worlds load public HashMap> clusters_tmp; public HashMap> plots_tmp; @@ -1796,23 +1794,6 @@ public class PlotSquared { } catch (IOException ignored) { PlotSquared.log("Failed to save storage.yml"); } - try { - this.commandsFile = new File(folder, "commands.yml"); - if (!this.commandsFile.exists() && !this.commandsFile.createNewFile()) { - PlotSquared.log( - "Could not the storage settings file, please create \"commands.yml\" manually."); - } - this.commands = YamlConfiguration.loadConfiguration(this.commandsFile); - } catch (IOException ignored) { - PlotSquared.log("Failed to save commands.yml"); - } - try { - this.style.save(this.styleFile); - this.commands.save(this.commandsFile); - } catch (IOException e) { - PlotSquared.log("Configuration file saving failed"); - e.printStackTrace(); - } return true; } diff --git a/Core/src/main/java/com/plotsquared/core/command/Command.java b/Core/src/main/java/com/plotsquared/core/command/Command.java index 7238d4566..194fc48a4 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Command.java +++ b/Core/src/main/java/com/plotsquared/core/command/Command.java @@ -25,9 +25,7 @@ */ package com.plotsquared.core.command; -import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Captions; -import com.plotsquared.core.configuration.file.YamlConfiguration; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.message.PlotMessage; import com.plotsquared.core.util.MainUtil; @@ -40,7 +38,6 @@ import com.plotsquared.core.util.task.RunnableVal3; import lombok.SneakyThrows; import org.jetbrains.annotations.NotNull; -import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; @@ -190,36 +187,16 @@ public abstract class Command { this.permission = declaration.permission(); this.required = declaration.requiredType(); this.category = declaration.category(); + List aliasOptions = new ArrayList<>(); aliasOptions.add(this.id); aliasOptions.addAll(Arrays.asList(declaration.aliases())); - HashMap options = new HashMap<>(); - options.put("aliases", aliasOptions); - options.put("description", declaration.description()); - options.put("usage", declaration.usage()); - options.put("confirmation", declaration.confirmation()); - boolean set = false; - YamlConfiguration commands = - PlotSquared.get() == null ? new YamlConfiguration() : PlotSquared.get().commands; - for (Map.Entry entry : options.entrySet()) { - String key = this.getFullId() + "." + entry.getKey(); - if (!commands.contains(key)) { - commands.set(key, entry.getValue()); - set = true; - } - } - if (set && PlotSquared.get() != null) { - try { - commands.save(PlotSquared.get().commandsFile); - } catch (IOException e) { - e.printStackTrace(); - } - } - this.aliases = commands.getStringList(this.getFullId() + ".aliases"); - this.description = commands.getString(this.getFullId() + ".description"); - this.usage = commands.getString(this.getFullId() + ".usage"); - this.confirmation = commands.getBoolean(this.getFullId() + ".confirmation"); + this.aliases = aliasOptions; + this.description = declaration.description(); + this.usage = declaration.usage(); + this.confirmation = declaration.confirmation(); + if (this.parent != null) { this.parent.register(this); } From f2191cb731af85efcc26998038cc888e717a62b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Wed, 8 Jul 2020 13:43:16 +0200 Subject: [PATCH 34/52] Save style.yml again --- Core/src/main/java/com/plotsquared/core/PlotSquared.java | 1 + 1 file changed, 1 insertion(+) diff --git a/Core/src/main/java/com/plotsquared/core/PlotSquared.java b/Core/src/main/java/com/plotsquared/core/PlotSquared.java index 0ebcc7b1c..8df57ba4c 100644 --- a/Core/src/main/java/com/plotsquared/core/PlotSquared.java +++ b/Core/src/main/java/com/plotsquared/core/PlotSquared.java @@ -1779,6 +1779,7 @@ public class PlotSquared { } this.style = YamlConfiguration.loadConfiguration(this.styleFile); setupStyle(); + this.style.save(this.styleFile); } catch (IOException err) { err.printStackTrace(); PlotSquared.log("Failed to save style.yml"); From d267d1bb98f9981d236e764f44bad0183d57131d Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Wed, 8 Jul 2020 14:35:46 +0100 Subject: [PATCH 35/52] Start expiry tasks --- Core/src/main/java/com/plotsquared/core/PlotSquared.java | 1 + 1 file changed, 1 insertion(+) diff --git a/Core/src/main/java/com/plotsquared/core/PlotSquared.java b/Core/src/main/java/com/plotsquared/core/PlotSquared.java index 8df57ba4c..e9048f726 100644 --- a/Core/src/main/java/com/plotsquared/core/PlotSquared.java +++ b/Core/src/main/java/com/plotsquared/core/PlotSquared.java @@ -259,6 +259,7 @@ public class PlotSquared { if (Settings.Enabled_Components.CHUNK_PROCESSOR) { this.IMP.registerChunkProcessor(); } + startExpiryTasks(); // Create Event utility class eventDispatcher = new EventDispatcher(); // create Hybrid utility class From 2936b806f3d48b2e1b1c9f6b78a33aeb3b163e73 Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Wed, 8 Jul 2020 17:10:09 +0100 Subject: [PATCH 36/52] Allow players to interact on their own plot --- .../com/plotsquared/bukkit/listener/PlayerEvents.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java index 841470413..ed812d09f 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java @@ -1864,8 +1864,8 @@ public class PlayerEvents extends PlotListener implements Listener { Plot plot = location.getPlotAbs(); BukkitPlayer pp = BukkitUtil.getPlayer(e.getPlayer()); if (plot == null) { - if (!area.isRoadFlags() && !area.getRoadFlag(MiscInteractFlag.class) - && !Permissions.hasPermission(pp, "plots.admin.interact.road")) { + if (!area.isRoadFlags() && !area.getRoadFlag(MiscInteractFlag.class) && !Permissions + .hasPermission(pp, "plots.admin.interact.road")) { MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, "plots.admin.interact.road"); e.setCancelled(true); } @@ -2601,8 +2601,8 @@ public class PlayerEvents extends PlotListener implements Listener { Captions.PERMISSION_ADMIN_INTERACT_UNOWNED); event.setCancelled(true); } - } else if ((plot != null && !plot.isAdded(pp.getUUID())) || area - .isRoadFlags()) { + } else if ((plot != null && !plot.isAdded(pp.getUUID())) || (plot == null && area + .isRoadFlags())) { final Entity entity = event.getRightClicked(); final com.sk89q.worldedit.world.entity.EntityType entityType = BukkitAdapter.adapt(entity.getType()); From d652225f36063b661e215a5ad9fbdb34f4451edb Mon Sep 17 00:00:00 2001 From: Hannes Greule Date: Wed, 8 Jul 2020 19:33:58 +0200 Subject: [PATCH 37/52] Let players teleport to their merged plots --- .../java/com/plotsquared/core/command/HomeCommand.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Core/src/main/java/com/plotsquared/core/command/HomeCommand.java b/Core/src/main/java/com/plotsquared/core/command/HomeCommand.java index b72276026..38942ad11 100644 --- a/Core/src/main/java/com/plotsquared/core/command/HomeCommand.java +++ b/Core/src/main/java/com/plotsquared/core/command/HomeCommand.java @@ -84,7 +84,7 @@ public class HomeCommand extends Command { @NotNull private PlotQuery query(@NotNull final PlotPlayer player) { // everything plots need to have in common here - return PlotQuery.newQuery().ownedBy(player).whereBasePlot(); + return PlotQuery.newQuery().ownedBy(player); } @Override public CompletableFuture execute(PlotPlayer player, String[] args, @@ -107,6 +107,7 @@ public class HomeCommand extends Command { PlotQuery query = query(player); int page = 1; // page = index + 1 String identifier; + boolean basePlotOnly = true; switch (args.length) { case 1: identifier = args[0]; @@ -124,6 +125,7 @@ public class HomeCommand extends Command { Plot fromId = MainUtil.getPlotFromString(player, identifier, false); if (fromId != null && fromId.isOwner(player.getUUID())) { // it was a valid plot id + basePlotOnly = false; query.withPlot(fromId); break; } @@ -165,12 +167,16 @@ public class HomeCommand extends Command { break; } // as the query already filters by owner, this is fine + basePlotOnly = false; query.withPlot(plot); break; case 0: query.withSortingStrategy(SortingStrategy.SORT_BY_CREATION); break; } + if (basePlotOnly) { + query.whereBasePlot(); + } home(player, query, page, confirm, whenDone); return CompletableFuture.completedFuture(true); } From 1310f9470ed8ca53e5cb146b05b75049dd56de60 Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Wed, 8 Jul 2020 19:34:08 +0100 Subject: [PATCH 38/52] 5.12.4 --- Bukkit/pom.xml | 2 +- build.gradle | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Bukkit/pom.xml b/Bukkit/pom.xml index 13e2e6fcf..f70fa0eba 100644 --- a/Bukkit/pom.xml +++ b/Bukkit/pom.xml @@ -21,7 +21,7 @@ com.plotsquared PlotSquared-Core - 5.12.3 + 5.12.4 compile diff --git a/build.gradle b/build.gradle index a841bb030..fff3ba5eb 100644 --- a/build.gradle +++ b/build.gradle @@ -30,7 +30,7 @@ ext { git = Grgit.open(dir: new File(rootDir.toString() + "/.git")) } -def ver = "5.12.3" +def ver = "5.12.4" def versuffix = "" ext { if (project.hasProperty("versionsuffix")) { From 61de18190f084402a37fc67d8ca85c2ee86aec52 Mon Sep 17 00:00:00 2001 From: Traks Date: Thu, 9 Jul 2020 02:11:51 +0200 Subject: [PATCH 39/52] More dispense blocking on roads --- .../bukkit/listener/PlayerEvents.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java index ed812d09f..d81f24fa6 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java @@ -1618,6 +1618,35 @@ public class PlayerEvents extends PlotListener implements Listener { public void onBlockDispense(BlockDispenseEvent event) { Material type = event.getItem().getType(); switch (type) { + case SHULKER_BOX: + case WHITE_SHULKER_BOX: + case ORANGE_SHULKER_BOX: + case MAGENTA_SHULKER_BOX: + case LIGHT_BLUE_SHULKER_BOX: + case YELLOW_SHULKER_BOX: + case LIME_SHULKER_BOX: + case PINK_SHULKER_BOX: + case GRAY_SHULKER_BOX: + case LIGHT_GRAY_SHULKER_BOX: + case CYAN_SHULKER_BOX: + case PURPLE_SHULKER_BOX: + case BLUE_SHULKER_BOX: + case BROWN_SHULKER_BOX: + case GREEN_SHULKER_BOX: + case RED_SHULKER_BOX: + case BLACK_SHULKER_BOX: + case CARVED_PUMPKIN: + case WITHER_SKELETON_SKULL: + case FLINT_AND_STEEL: + case BONE_MEAL: + case SHEARS: + case GLASS_BOTTLE: + case GLOWSTONE: + case COD_BUCKET: + case PUFFERFISH_BUCKET: + case SALMON_BUCKET: + case TROPICAL_FISH_BUCKET: + case BUCKET: case WATER_BUCKET: case LAVA_BUCKET: { if (event.getBlock().getType() == Material.DROPPER) { From e05d81748229f71d4d6a0958cbf9487da482ca91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Thu, 9 Jul 2020 16:38:46 +0200 Subject: [PATCH 40/52] Fix plot owner placeholder. Fixes PS-62. --- .../bukkit/placeholder/Placeholders.java | 22 +++++---------- .../com/plotsquared/core/util/MainUtil.java | 27 ++++++++++++++++--- 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/Placeholders.java b/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/Placeholders.java index 5457dbe0f..c61b29f37 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/Placeholders.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/Placeholders.java @@ -26,17 +26,16 @@ package com.plotsquared.bukkit.placeholder; import com.plotsquared.core.PlotSquared; -import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.flag.GlobalFlagContainer; import com.plotsquared.core.plot.flag.PlotFlag; +import com.plotsquared.core.util.MainUtil; import me.clip.placeholderapi.PlaceholderAPIPlugin; import me.clip.placeholderapi.expansion.PlaceholderExpansion; import org.bukkit.Bukkit; import org.bukkit.entity.Player; -import java.util.Set; import java.util.UUID; public class Placeholders extends PlaceholderExpansion { @@ -117,23 +116,16 @@ public class Placeholders extends PlaceholderExpansion { return plot.getAlias(); } case "currentplot_owner": { - final Set o = plot.getOwners(); - if (o == null || o.isEmpty()) { - return ""; - } - final UUID uid = (UUID) o.toArray()[0]; - if (uid == null) { + final UUID plotOwner = plot.getOwnerAbs(); + if (plotOwner == null) { return ""; } - String name = PlotSquared.get().getImpromptuUUIDPipeline() - .getSingle(uid, Settings.UUID.BLOCKING_TIMEOUT); + try { + return MainUtil.getName(plotOwner, false); + } catch (final Exception ignored) {} - if (name != null) { - return name; - } - - name = Bukkit.getOfflinePlayer(uid).getName(); + final String name = Bukkit.getOfflinePlayer(plotOwner).getName(); return name != null ? name : "unknown"; } case "currentplot_members": { diff --git a/Core/src/main/java/com/plotsquared/core/util/MainUtil.java b/Core/src/main/java/com/plotsquared/core/util/MainUtil.java index 9e2a78853..9f79f3273 100644 --- a/Core/src/main/java/com/plotsquared/core/util/MainUtil.java +++ b/Core/src/main/java/com/plotsquared/core/util/MainUtil.java @@ -372,10 +372,21 @@ public class MainUtil { /** * Get the name from a UUID. * - * @param owner + * @param owner Owner UUID * @return The player's name, None, Everyone or Unknown */ - @NotNull public static String getName(UUID owner) { + @NotNull public static String getName(@Nullable UUID owner) { + return getName(owner, true); + } + + /** + * Get the name from a UUID. + * + * @param owner Owner UUID + * @param blocking Whether or not the operation can be blocking + * @return The player's name, None, Everyone or Unknown + */ + @NotNull public static String getName(@Nullable final UUID owner, final boolean blocking) { if (owner == null) { return Captions.NONE.getTranslated(); } @@ -385,7 +396,17 @@ public class MainUtil { if (owner.equals(DBFunc.SERVER)) { return Captions.SERVER.getTranslated(); } - String name = PlotSquared.get().getImpromptuUUIDPipeline().getSingle(owner, Settings.UUID.BLOCKING_TIMEOUT); + final String name; + if (blocking) { + name = PlotSquared.get().getImpromptuUUIDPipeline().getSingle(owner, Settings.UUID.BLOCKING_TIMEOUT); + } else { + final UUIDMapping uuidMapping = PlotSquared.get().getImpromptuUUIDPipeline().getImmediately(owner); + if (uuidMapping != null) { + name = uuidMapping.getUsername(); + } else { + name = null; + } + } if (name == null) { return Captions.UNKNOWN.getTranslated(); } From 6b07f38cff49aae77fdcab615eb43b6faff5fb46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Thu, 9 Jul 2020 16:45:25 +0200 Subject: [PATCH 41/52] Send teleportation cancellation message immediately on movement, rather than after the timer has finished. This fixes PS-33. --- .../com/plotsquared/bukkit/listener/PlayerEvents.java | 8 ++++++-- Core/src/main/java/com/plotsquared/core/plot/Plot.java | 4 +--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java index d81f24fa6..8cd72da47 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java @@ -822,7 +822,9 @@ public class PlayerEvents extends PlotListener implements Listener { Player player = event.getPlayer(); BukkitPlayer pp = BukkitUtil.getPlayer(player); // Cancel teleport - TaskManager.TELEPORT_QUEUE.remove(pp.getName()); + if (TaskManager.TELEPORT_QUEUE.remove(pp.getName())) { + MainUtil.sendMessage(pp, Captions.TELEPORT_FAILED); + } // Set last location Location location = BukkitUtil.getLocation(to); pp.setMeta(PlotPlayer.META_LOCATION, location); @@ -882,7 +884,9 @@ public class PlayerEvents extends PlotListener implements Listener { Player player = event.getPlayer(); BukkitPlayer pp = BukkitUtil.getPlayer(player); // Cancel teleport - TaskManager.TELEPORT_QUEUE.remove(pp.getName()); + if (TaskManager.TELEPORT_QUEUE.remove(pp.getName())) { + MainUtil.sendMessage(pp, Captions.TELEPORT_FAILED); + } // Set last location Location location = BukkitUtil.getLocation(to); pp.setMeta(PlotPlayer.META_LOCATION, location); diff --git a/Core/src/main/java/com/plotsquared/core/plot/Plot.java b/Core/src/main/java/com/plotsquared/core/plot/Plot.java index 46ce9f24c..2adca5334 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/Plot.java +++ b/Core/src/main/java/com/plotsquared/core/plot/Plot.java @@ -3010,11 +3010,9 @@ public class Plot { final String name = player.getName(); TaskManager.TELEPORT_QUEUE.add(name); TaskManager.runTaskLater(() -> { - if (!TaskManager.TELEPORT_QUEUE.contains(name)) { - MainUtil.sendMessage(player, Captions.TELEPORT_FAILED); + if (!TaskManager.TELEPORT_QUEUE.remove(name)) { return; } - TaskManager.TELEPORT_QUEUE.remove(name); if (player.isOnline()) { MainUtil.sendMessage(player, Captions.TELEPORTED_TO_PLOT); player.teleport(location, cause); From 699eb71e2a5bd4e99dbeba48a22a026698188895 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Thu, 9 Jul 2020 19:46:17 +0200 Subject: [PATCH 42/52] Fix kill-road-mobs. Fixes PS-73 --- Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java | 1 - 1 file changed, 1 deletion(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java index 39a763d24..39b2a3c9d 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java @@ -833,7 +833,6 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< case "HOGLIN": case "PIGLIN": case "ZOGLIN": - break; default: { if (Settings.Enabled_Components.KILL_ROAD_MOBS) { Location location = entity.getLocation(); From 89cb6450fb310c67f04e18562bfec98e39055acd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Thu, 9 Jul 2020 20:04:00 +0200 Subject: [PATCH 43/52] Fix issue where PlotPlayer#getLocation returns a mutable location --- .../java/com/plotsquared/core/location/Location.java | 11 +++++++++++ .../java/com/plotsquared/core/player/PlotPlayer.java | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Core/src/main/java/com/plotsquared/core/location/Location.java b/Core/src/main/java/com/plotsquared/core/location/Location.java index 0505137b1..fa9175892 100644 --- a/Core/src/main/java/com/plotsquared/core/location/Location.java +++ b/Core/src/main/java/com/plotsquared/core/location/Location.java @@ -34,6 +34,7 @@ import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.BlockVector3; import lombok.Getter; import lombok.Setter; +import org.jetbrains.annotations.NotNull; import org.khelekore.prtree.MBR; import org.khelekore.prtree.SimpleMBR; @@ -103,6 +104,16 @@ public class Location implements Cloneable, Comparable { } } + /** + * Return a copy of the location. This will pass {@link #equals(Object)} + * but will have a different identity. + * + * @return Copy of the location + */ + @NotNull public Location copy() { + return new Location(this.world, this.x, this.y, this.z, this.yaw, this.pitch); + } + public PlotArea getPlotArea() { return PlotSquared.get().getPlotAreaAbs(this); } diff --git a/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java b/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java index 13efa6bfb..b11a33ba6 100644 --- a/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java +++ b/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java @@ -367,7 +367,7 @@ public abstract class PlotPlayer

implements CommandCaller, OfflinePlotPlayer @NotNull public Location getLocation() { Location location = getMeta("location"); if (location != null) { - return location; + return location.copy(); // Always return a copy of the location } return getLocationFull(); } From 4576cfd961667a7695ed2dd02f6baec07ebb8eb2 Mon Sep 17 00:00:00 2001 From: Traks Date: Thu, 9 Jul 2020 15:43:16 +0200 Subject: [PATCH 44/52] Improve piston interaction with plot border Fixes retracting pistons being able to modify plot borders. Prevents piston heads from sticking outside plots. --- .../bukkit/listener/PlayerEvents.java | 74 ++++++------------- 1 file changed, 21 insertions(+), 53 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java index 8cd72da47..3949e0245 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java @@ -230,7 +230,6 @@ public class PlayerEvents extends PlotListener implements Listener { public static final com.sk89q.worldedit.world.entity.EntityType FAKE_ENTITY_TYPE = new com.sk89q.worldedit.world.entity.EntityType("plotsquared:fake"); - private boolean pistonBlocks = true; private float lastRadius; // To prevent recursion private boolean tmpTeleport = true; @@ -1539,35 +1538,28 @@ public class PlayerEvents extends PlotListener implements Listener { return; } } + if (!plot.equals(area.getOwnedPlot(location.add( + relative.getBlockX(), relative.getBlockY(), relative.getBlockZ())))) { + // This branch is only necessary to prevent pistons from extending + // if they are: on a plot edge, facing outside the plot, and not + // pushing any blocks + event.setCancelled(true); + } } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onBlockPistonRetract(BlockPistonRetractEvent event) { Block block = event.getBlock(); Location location = BukkitUtil.getLocation(block.getLocation()); + BlockFace face = event.getDirection(); + Vector relative = new Vector(face.getModX(), face.getModY(), face.getModZ()); PlotArea area = location.getPlotArea(); if (area == null) { if (!PlotSquared.get().hasPlotArea(location.getWorld())) { return; } - if (this.pistonBlocks) { - try { - for (Block pulled : event.getBlocks()) { - location = BukkitUtil.getLocation(pulled.getLocation()); - if (location.isPlotArea()) { - event.setCancelled(true); - return; - } - } - } catch (Throwable ignored) { - this.pistonBlocks = false; - } - } - if (!this.pistonBlocks && !block.getType().toString().contains("PISTON")) { - BlockFace dir = event.getDirection(); - location = BukkitUtil.getLocation(block.getLocation() - .add(dir.getModX() * 2, dir.getModY() * 2, dir.getModZ() * 2)); - if (location.isPlotArea()) { + for (Block block1 : event.getBlocks()) { + if (BukkitUtil.getLocation(block1.getLocation().add(relative)).isPlotArea()) { event.setCancelled(true); return; } @@ -1575,45 +1567,21 @@ public class PlayerEvents extends PlotListener implements Listener { return; } Plot plot = area.getOwnedPlot(location); - BlockFace dir = event.getDirection(); - // Location head = location.add(-dir.getModX(), -dir.getModY(), -dir.getModZ()); - // - // if (!Objects.equals(plot, area.getOwnedPlot(head))) { - // // FIXME: cancelling the event doesn't work here. See issue #1484 - // event.setCancelled(true); - // return; - // } - if (this.pistonBlocks) { - try { - for (Block pulled : event.getBlocks()) { - Location from = BukkitUtil.getLocation( - pulled.getLocation().add(dir.getModX(), dir.getModY(), dir.getModZ())); - Location to = BukkitUtil.getLocation(pulled.getLocation()); - if (!area.contains(to.getX(), to.getZ())) { - event.setCancelled(true); - return; - } - Plot fromPlot = area.getOwnedPlot(from); - Plot toPlot = area.getOwnedPlot(to); - if (!Objects.equals(fromPlot, toPlot)) { - event.setCancelled(true); - return; - } - } - } catch (Throwable ignored) { - this.pistonBlocks = false; - } + if (plot == null) { + event.setCancelled(true); + return; } - if (!this.pistonBlocks && !block.getType().toString().contains("PISTON")) { - location = BukkitUtil.getLocation( - block.getLocation().add(dir.getModX() * 2, dir.getModY() * 2, dir.getModZ() * 2)); - if (!area.contains(location)) { + for (Block block1 : event.getBlocks()) { + Location bloc = BukkitUtil.getLocation(block1.getLocation()); + if (!area.contains(bloc.getX(), bloc.getZ()) || !area + .contains(bloc.getX() + relative.getBlockX(), bloc.getZ() + relative.getBlockZ())) { event.setCancelled(true); return; } - Plot newPlot = area.getOwnedPlot(location); - if (!Objects.equals(plot, newPlot)) { + if (!plot.equals(area.getOwnedPlot(bloc)) || !plot.equals(area.getOwnedPlot( + bloc.add(relative.getBlockX(), relative.getBlockY(), relative.getBlockZ())))) { event.setCancelled(true); + return; } } } From cfd389883b3ae8d2ec07b67112a1306204cf2f4b Mon Sep 17 00:00:00 2001 From: Traks Date: Thu, 9 Jul 2020 18:30:45 +0200 Subject: [PATCH 45/52] Improve piston interaction with area border --- .../plotsquared/bukkit/listener/PlayerEvents.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java index 3949e0245..28fc05d4a 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java @@ -1513,11 +1513,19 @@ public class PlayerEvents extends PlotListener implements Listener { return; } for (Block block1 : event.getBlocks()) { - if (BukkitUtil.getLocation(block1.getLocation().add(relative)).isPlotArea()) { + Location bloc = BukkitUtil.getLocation(block1.getLocation()); + if (bloc.isPlotArea() || bloc.add(relative.getBlockX(), + relative.getBlockY(), relative.getBlockZ()).isPlotArea()) { event.setCancelled(true); return; } } + if (location.add(relative.getBlockX(), relative.getBlockY(), relative.getBlockZ()) + .isPlotArea()) { + // Prevent pistons from extending if they are: bordering a plot + // area, facing inside plot area, and not pushing any blocks + event.setCancelled(true); + } return; } Plot plot = area.getOwnedPlot(location); @@ -1559,7 +1567,9 @@ public class PlayerEvents extends PlotListener implements Listener { return; } for (Block block1 : event.getBlocks()) { - if (BukkitUtil.getLocation(block1.getLocation().add(relative)).isPlotArea()) { + Location bloc = BukkitUtil.getLocation(block1.getLocation()); + if (bloc.isPlotArea() || bloc.add(relative.getBlockX(), + relative.getBlockY(), relative.getBlockZ()).isPlotArea()) { event.setCancelled(true); return; } From 63c308971b530712636e9a0bb44979250fc85b80 Mon Sep 17 00:00:00 2001 From: Traks Date: Thu, 9 Jul 2020 18:31:44 +0200 Subject: [PATCH 46/52] Update location block vector on add and subtract --- Core/src/main/java/com/plotsquared/core/location/Location.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Core/src/main/java/com/plotsquared/core/location/Location.java b/Core/src/main/java/com/plotsquared/core/location/Location.java index fa9175892..08db98a19 100644 --- a/Core/src/main/java/com/plotsquared/core/location/Location.java +++ b/Core/src/main/java/com/plotsquared/core/location/Location.java @@ -190,6 +190,7 @@ public class Location implements Cloneable, Comparable { this.x += x; this.y += y; this.z += z; + this.blockVector3 = BlockVector3.at(this.x, this.y, this.z); return this; } @@ -231,6 +232,7 @@ public class Location implements Cloneable, Comparable { this.x -= x; this.y -= y; this.z -= z; + this.blockVector3 = BlockVector3.at(this.x, this.y, this.z); return this; } From b36c6427d1e32d0382d01326114b8d1e9bdf3f44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Thu, 9 Jul 2020 20:25:16 +0200 Subject: [PATCH 47/52] Split failed UUID batches into individual requests in order to identify the invalid UUIDs --- .../bukkit/uuid/SquirrelIdUUIDService.java | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/SquirrelIdUUIDService.java b/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/SquirrelIdUUIDService.java index 4580519aa..8c8dfca83 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/SquirrelIdUUIDService.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/SquirrelIdUUIDService.java @@ -26,6 +26,8 @@ package com.plotsquared.bukkit.uuid; import com.google.common.util.concurrent.RateLimiter; +import com.plotsquared.core.PlotSquared; +import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.uuid.UUIDMapping; import com.plotsquared.core.uuid.UUIDService; import com.sk89q.squirrelid.Profile; @@ -35,6 +37,7 @@ import org.jetbrains.annotations.NotNull; import java.io.IOException; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.UUID; @@ -65,8 +68,27 @@ public class SquirrelIdUUIDService implements UUIDService { final List results = new ArrayList<>(uuids.size()); this.rateLimiter.acquire(uuids.size()); try { - for (final Profile profile : this.profileService.findAllById(uuids)) { - results.add(new UUIDMapping(profile.getUniqueId(), profile.getName())); + try { + for (final Profile profile : this.profileService.findAllById(uuids)) { + results.add(new UUIDMapping(profile.getUniqueId(), profile.getName())); + } + } catch (final IllegalArgumentException illegalArgumentException) { + // + // This means that the UUID was invalid for whatever reason, we'll try to + // go through them one by one + // + if (uuids.size() >= 2) { + PlotSquared.debug(Captions.PREFIX + "(UUID) Found invalid UUID in batch. Will try each UUID individually."); + for (final UUID uuid : uuids) { + final List result = this.getNames(Collections.singletonList(uuid)); + if (result.isEmpty()) { + continue; + } + results.add(result.get(0)); + } + } else if (uuids.size() == 1) { + PlotSquared.debug(Captions.PREFIX + "(UUID) Found invalid UUID: " + uuids.get(0)); + } } } catch (IOException | InterruptedException e) { e.printStackTrace(); From fb050ac3da808273597d5ed1c5516d93e67afd18 Mon Sep 17 00:00:00 2001 From: NotMyFault Date: Thu, 9 Jul 2020 21:15:28 +0200 Subject: [PATCH 48/52] 5.12.5 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index fff3ba5eb..a0bae9c0c 100644 --- a/build.gradle +++ b/build.gradle @@ -30,7 +30,7 @@ ext { git = Grgit.open(dir: new File(rootDir.toString() + "/.git")) } -def ver = "5.12.4" +def ver = "5.12.5" def versuffix = "" ext { if (project.hasProperty("versionsuffix")) { From 96740fd2820234e7f5c875fe273d511ce9a7b14f Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Thu, 9 Jul 2020 21:52:51 +0100 Subject: [PATCH 49/52] Couple of fixes to road flag logic --- .../java/com/plotsquared/bukkit/listener/PlayerEvents.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java index ed812d09f..b088239ef 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java @@ -1878,8 +1878,7 @@ public class PlayerEvents extends PlotListener implements Listener { return; } } - if (!plot.hasOwner() && !area.isRoadFlags() && !area - .getRoadFlag(MiscInteractFlag.class)) { + if (!plot.hasOwner()) { if (!Permissions.hasPermission(pp, "plots.admin.interact.unowned")) { MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, "plots.admin.interact.unowned"); @@ -3145,7 +3144,7 @@ public class PlayerEvents extends PlotListener implements Listener { } Plot plot = location.getOwnedPlot(); if (plot == null) { - if (area.isRoadFlags() && area.getRoadFlag(ItemDropFlag.class)) { + if (area.isRoadFlags() && !area.getRoadFlag(ItemDropFlag.class)) { event.setCancelled(true); } return; From 55139eb134996d559055aea9e271d89beb979ad7 Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Thu, 9 Jul 2020 22:19:23 +0100 Subject: [PATCH 50/52] Do not respect paste on top for road schematics. --- .../main/java/com/plotsquared/core/generator/HybridUtils.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/Core/src/main/java/com/plotsquared/core/generator/HybridUtils.java b/Core/src/main/java/com/plotsquared/core/generator/HybridUtils.java index 75ada359f..ec70811db 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/HybridUtils.java +++ b/Core/src/main/java/com/plotsquared/core/generator/HybridUtils.java @@ -622,9 +622,6 @@ public abstract class HybridUtils { if (condition) { BaseBlock[] blocks = plotWorld.G_SCH.get(MathMan.pair(absX, absZ)); int minY = plotWorld.SCHEM_Y; - if (!Settings.Schematics.PASTE_ON_TOP) { - minY = 1; - } int maxY = Math.max(extend, blocks.length); for (int y = 0; y < maxY; y++) { if (y > blocks.length - 1) { From 5b260ea8da4c6955bce501aa7ab23c9f42d73d73 Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Thu, 9 Jul 2020 22:33:01 +0100 Subject: [PATCH 51/52] update bukkit pom --- Bukkit/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Bukkit/pom.xml b/Bukkit/pom.xml index f70fa0eba..cde998b9a 100644 --- a/Bukkit/pom.xml +++ b/Bukkit/pom.xml @@ -21,7 +21,7 @@ com.plotsquared PlotSquared-Core - 5.12.4 + 5.12.5 compile From 2fb76e66364737ba5609fecd2c5e53b29bb36526 Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Thu, 9 Jul 2020 22:39:06 +0100 Subject: [PATCH 52/52] Split road and plot paste-on-top settings --- .../plotsquared/core/configuration/Settings.java | 3 +++ .../plotsquared/core/generator/HybridGen.java | 3 ++- .../core/generator/HybridPlotManager.java | 16 +++++++++------- .../plotsquared/core/generator/HybridUtils.java | 14 +++++++------- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/Core/src/main/java/com/plotsquared/core/configuration/Settings.java b/Core/src/main/java/com/plotsquared/core/configuration/Settings.java index db22c46be..f575fba43 100644 --- a/Core/src/main/java/com/plotsquared/core/configuration/Settings.java +++ b/Core/src/main/java/com/plotsquared/core/configuration/Settings.java @@ -388,6 +388,9 @@ public class Settings extends Config { @Comment( "Whether schematic based generation should paste schematic on top of plots, or from Y=1") public static boolean PASTE_ON_TOP = true; + @Comment( + "Whether schematic based road generation should paste schematic on top of roads, or from Y=1") + public static boolean PASTE_ROAD_ON_TOP = true; } diff --git a/Core/src/main/java/com/plotsquared/core/generator/HybridGen.java b/Core/src/main/java/com/plotsquared/core/generator/HybridGen.java index e661e4c5f..a4f955682 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/HybridGen.java +++ b/Core/src/main/java/com/plotsquared/core/generator/HybridGen.java @@ -47,7 +47,8 @@ public class HybridGen extends IndependentPlotGenerator { private void placeSchem(HybridPlotWorld world, ScopedLocalBlockQueue result, short relativeX, short relativeZ, int x, int z, boolean isRoad) { int minY; // Math.min(world.PLOT_HEIGHT, world.ROAD_HEIGHT); - if (isRoad || Settings.Schematics.PASTE_ON_TOP) { + if ((isRoad && Settings.Schematics.PASTE_ROAD_ON_TOP) || (!isRoad + && Settings.Schematics.PASTE_ON_TOP)) { minY = world.SCHEM_Y; } else { minY = 1; diff --git a/Core/src/main/java/com/plotsquared/core/generator/HybridPlotManager.java b/Core/src/main/java/com/plotsquared/core/generator/HybridPlotManager.java index 67ad6eb8b..da4fa74b9 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/HybridPlotManager.java +++ b/Core/src/main/java/com/plotsquared/core/generator/HybridPlotManager.java @@ -112,15 +112,17 @@ public class HybridPlotManager extends ClassicPlotManager { return true; } LocalBlockQueue queue = hybridPlotWorld.getQueue(false); - createSchemAbs(queue, pos1, pos2); + createSchemAbs(queue, pos1, pos2, true); queue.enqueue(); return true; } - private void createSchemAbs(LocalBlockQueue queue, Location pos1, Location pos2) { + private void createSchemAbs(LocalBlockQueue queue, Location pos1, Location pos2, + boolean isRoad) { int size = hybridPlotWorld.SIZE; int minY; - if (Settings.Schematics.PASTE_ON_TOP) { + if ((isRoad && Settings.Schematics.PASTE_ROAD_ON_TOP) || (!isRoad + && Settings.Schematics.PASTE_ON_TOP)) { minY = hybridPlotWorld.SCHEM_Y; } else { minY = 1; @@ -172,7 +174,7 @@ public class HybridPlotManager extends ClassicPlotManager { return true; } LocalBlockQueue queue = hybridPlotWorld.getQueue(false); - createSchemAbs(queue, pos1, pos2); + createSchemAbs(queue, pos1, pos2, true); queue.enqueue(); return true; } @@ -186,9 +188,9 @@ public class HybridPlotManager extends ClassicPlotManager { pos1.setY(0); pos2.setY(Math.min(getWorldHeight(), 255)); LocalBlockQueue queue = hybridPlotWorld.getQueue(false); - createSchemAbs(queue, pos1, pos2); + createSchemAbs(queue, pos1, pos2, true); if (hybridPlotWorld.ROAD_SCHEMATIC_ENABLED) { - createSchemAbs(queue, pos1, pos2); + createSchemAbs(queue, pos1, pos2, true); } return queue.enqueue(); } @@ -267,7 +269,7 @@ public class HybridPlotManager extends ClassicPlotManager { if (!hybridPlotWorld.PLOT_SCHEMATIC) { return; } - createSchemAbs(queue, bottom, top); + createSchemAbs(queue, bottom, top, false); } /** diff --git a/Core/src/main/java/com/plotsquared/core/generator/HybridUtils.java b/Core/src/main/java/com/plotsquared/core/generator/HybridUtils.java index ec70811db..539e9e1cd 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/HybridUtils.java +++ b/Core/src/main/java/com/plotsquared/core/generator/HybridUtils.java @@ -83,6 +83,11 @@ public abstract class HybridUtils { public static PlotArea area; public static boolean UPDATE = false; + public static boolean regeneratePlotWalls(final PlotArea area) { + PlotManager plotManager = area.getPlotManager(); + return plotManager.regenerateAllPlotWalls(); + } + public void analyzeRegion(final String world, final CuboidRegion region, final RunnableVal whenDone) { // int diff, int variety, int vertices, int rotation, int height_sd @@ -501,7 +506,7 @@ public abstract class HybridUtils { PlotManager plotManager = plotworld.getPlotManager(); int sx = bot.getX() - plotworld.ROAD_WIDTH + 1; int sz = bot.getZ() + 1; - int sy = plotworld.ROAD_HEIGHT; + int sy = Settings.Schematics.PASTE_ROAD_ON_TOP ? plotworld.ROAD_HEIGHT : 1; int ex = bot.getX(); int ez = top.getZ(); int ey = get_ey(plotManager, queue, sx, ex, sz, ez, sy); @@ -621,7 +626,7 @@ public abstract class HybridUtils { } if (condition) { BaseBlock[] blocks = plotWorld.G_SCH.get(MathMan.pair(absX, absZ)); - int minY = plotWorld.SCHEM_Y; + int minY = Settings.Schematics.PASTE_ROAD_ON_TOP ? plotWorld.SCHEM_Y : 1; int maxY = Math.max(extend, blocks.length); for (int y = 0; y < maxY; y++) { if (y > blocks.length - 1) { @@ -656,9 +661,4 @@ public abstract class HybridUtils { } return false; } - - public static boolean regeneratePlotWalls(final PlotArea area) { - PlotManager plotManager = area.getPlotManager(); - return plotManager.regenerateAllPlotWalls(); - } }