From 221d299052adeeb7d5d7107bbd525e13eb59593a Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Fri, 24 Jul 2020 17:52:05 +0100 Subject: [PATCH] Fix a few remaining merge issues (+1 squashed commits) Squashed commits: [8c6b55dd4] Fix a few remaining merge issues --- Bukkit/build.gradle | 1 + .../bukkit/listener/BlockEventListener.java | 359 +++++------ .../bukkit/listener/EntityEventListener.java | 80 +-- .../bukkit/listener/EntitySpawnListener.java | 17 +- .../bukkit/listener/PlayerEventListener.java | 599 ++++++++---------- .../listener/ProjectileEventListener.java | 43 +- .../bukkit/placeholder/MVdWPlaceholders.java | 26 +- .../bukkit/placeholder/PAPIPlaceholders.java | 2 +- .../bukkit/util/BukkitEntityUtil.java | 8 +- .../java/com/plotsquared/core/plot/Plot.java | 2 +- .../core/util/EventDispatcher.java | 3 + .../placeholders/PlaceholderRegistry.java | 5 +- 12 files changed, 504 insertions(+), 641 deletions(-) diff --git a/Bukkit/build.gradle b/Bukkit/build.gradle index 59b215bc8..36151ca3d 100644 --- a/Bukkit/build.gradle +++ b/Bukkit/build.gradle @@ -42,6 +42,7 @@ dependencies { 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 } + compile('be.maximvdw:MVdWPlaceholderAPI:2.1.1-SNAPSHOT'){ transitive = false } // logging implementation('org.apache.logging.log4j:log4j-slf4j-impl:2.8.1') compile('be.maximvdw:MVdWPlaceholderAPI:3.1.1-SNAPSHOT'){ transitive = false } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/BlockEventListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/BlockEventListener.java index 32408f41e..82a01d765 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/BlockEventListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/BlockEventListener.java @@ -56,9 +56,12 @@ import com.plotsquared.core.plot.flag.implementations.SnowMeltFlag; import com.plotsquared.core.plot.flag.implementations.SoilDryFlag; import com.plotsquared.core.plot.flag.implementations.VineGrowFlag; import com.plotsquared.core.plot.flag.types.BlockTypeWrapper; +import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.Permissions; import com.plotsquared.core.util.task.TaskManager; +import com.plotsquared.core.util.task.TaskTime; +import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.world.block.BlockType; import org.bukkit.Bukkit; @@ -96,6 +99,8 @@ import org.bukkit.material.Directional; import org.bukkit.projectiles.BlockProjectileSource; import org.bukkit.util.Vector; +import javax.annotation.Nonnull; +import javax.inject.Inject; import java.util.Iterator; import java.util.List; import java.util.Objects; @@ -104,6 +109,14 @@ import java.util.UUID; @SuppressWarnings("unused") public class BlockEventListener implements Listener { + private final PlotAreaManager plotAreaManager; + private final WorldEdit worldEdit; + + @Inject public BlockEventListener(@Nonnull final PlotAreaManager plotAreaManager, @Nonnull final WorldEdit worldEdit) { + this.plotAreaManager = plotAreaManager; + this.worldEdit = worldEdit; + } + public static void sendBlockChange(final org.bukkit.Location bloc, final BlockData data) { TaskManager.runTaskLater(() -> { String world = bloc.getWorld().getName(); @@ -111,22 +124,21 @@ public class BlockEventListener implements Listener { int z = bloc.getBlockZ(); int distance = Bukkit.getViewDistance() * 16; - for (final PlotPlayer player : PlotSquared.imp().getPlayerManager().getPlayers()) { + for (final PlotPlayer player : PlotSquared.platform().getPlayerManager().getPlayers()) { Location location = player.getLocation(); - if (location.getWorld().equals(world)) { - if (16 * Math.abs(location.getX() - x) / 16 > distance - || 16 * Math.abs(location.getZ() - z) / 16 > distance) { + if (location.getWorldName().equals(world)) { + if (16 * Math.abs(location.getX() - x) / 16 > distance || 16 * Math.abs(location.getZ() - z) / 16 > distance) { continue; } ((BukkitPlayer) player).player.sendBlockChange(bloc, data); } } - }, 3); + }, TaskTime.ticks(3L)); } @EventHandler public void onRedstoneEvent(BlockRedstoneEvent event) { Block block = event.getBlock(); - Location location = BukkitUtil.getLocation(block.getLocation()); + Location location = BukkitUtil.adapt(block.getLocation()); PlotArea area = location.getPlotArea(); if (area == null) { return; @@ -149,34 +161,31 @@ public class BlockEventListener implements Listener { if (plot.isMerged()) { disable = true; for (UUID owner : plot.getOwners()) { - if (PlotSquared.imp().getPlayerManager().getPlayerIfExists(owner) != null) { + if (PlotSquared.platform().getPlayerManager().getPlayerIfExists(owner) != null) { disable = false; break; } } } else { - disable = - PlotSquared.imp().getPlayerManager().getPlayerIfExists(plot.getOwnerAbs()) - == null; + disable = PlotSquared.platform().getPlayerManager().getPlayerIfExists(plot.getOwnerAbs()) == null; } } if (disable) { for (UUID trusted : plot.getTrusted()) { - if (PlotSquared.imp().getPlayerManager().getPlayerIfExists(trusted) != null) { + if (PlotSquared.platform().getPlayerManager().getPlayerIfExists(trusted) != null) { disable = false; break; } } if (disable) { event.setNewCurrent(0); - plot.debug( - "Redstone event was cancelled because no trusted player was in the plot"); + plot.debug("Redstone event was cancelled because no trusted player was in the plot"); return; } } } if (Settings.Redstone.DISABLE_UNOCCUPIED) { - for (final PlotPlayer player : PlotSquared.imp().getPlayerManager().getPlayers()) { + for (final PlotPlayer player : PlotSquared.platform().getPlayerManager().getPlayers()) { if (plot.equals(player.getCurrentPlot())) { return; } @@ -185,12 +194,11 @@ public class BlockEventListener implements Listener { } } - @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) - public void onPhysicsEvent(BlockPhysicsEvent event) { + @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) public void onPhysicsEvent(BlockPhysicsEvent event) { switch (event.getChangedType()) { case COMPARATOR: { Block block = event.getBlock(); - Location location = BukkitUtil.getLocation(block.getLocation()); + Location location = BukkitUtil.adapt(block.getLocation()); if (location.isPlotArea()) { return; } @@ -212,7 +220,7 @@ public class BlockEventListener implements Listener { case TURTLE_HELMET: case TURTLE_SPAWN_EGG: { Block block = event.getBlock(); - Location location = BukkitUtil.getLocation(block.getLocation()); + Location location = BukkitUtil.adapt(block.getLocation()); PlotArea area = location.getPlotArea(); if (area == null) { return; @@ -233,9 +241,8 @@ public class BlockEventListener implements Listener { switch (block.getType()) { case PISTON: case STICKY_PISTON: - org.bukkit.block.data.Directional piston = - (org.bukkit.block.data.Directional) block.getBlockData(); - Location location = BukkitUtil.getLocation(block.getLocation()); + org.bukkit.block.data.Directional piston = (org.bukkit.block.data.Directional) block.getBlockData(); + Location location = BukkitUtil.adapt(block.getLocation()); PlotArea area = location.getPlotArea(); if (area == null) { return; @@ -246,23 +253,22 @@ public class BlockEventListener implements Listener { } switch (piston.getFacing()) { case EAST: - location.setX(location.getX() + 1); + location = location.add(1, 0, 0); break; case SOUTH: - location.setX(location.getX() - 1); + location = location.add(-1, 0, 0); break; case WEST: - location.setZ(location.getZ() + 1); + location = location.add(0, 0, 1); break; case NORTH: - location.setZ(location.getZ() - 1); + location = location.add(0, 0, -1); break; } Plot newPlot = area.getOwnedPlotAbs(location); if (!plot.equals(newPlot)) { event.setCancelled(true); - plot.debug( - "Prevented piston update because of invalid edge piston detection"); + plot.debug("Prevented piston update because of invalid edge piston detection"); return; } } @@ -271,28 +277,24 @@ public class BlockEventListener implements Listener { } } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void blockCreate(BlockPlaceEvent event) { - Location location = BukkitUtil.getLocation(event.getBlock().getLocation()); + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void blockCreate(BlockPlaceEvent event) { + Location location = BukkitUtil.adapt(event.getBlock().getLocation()); PlotArea area = location.getPlotArea(); if (area == null) { return; } Player player = event.getPlayer(); - BukkitPlayer pp = BukkitUtil.getPlayer(player); + BukkitPlayer pp = BukkitUtil.adapt(player); Plot plot = area.getPlot(location); if (plot != null) { - if ((location.getY() > area.getMaxBuildHeight() || location.getY() < area - .getMinBuildHeight()) && !Permissions + 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()))); + 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); + MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_BUILD_UNOWNED); event.setCancelled(true); return; } @@ -300,23 +302,19 @@ public class BlockEventListener implements Listener { List place = plot.getFlag(PlaceFlag.class); if (place != null) { Block block = event.getBlock(); - if (place.contains( - BlockTypeWrapper.get(BukkitAdapter.asBlockType(block.getType())))) { + 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); + 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"); + 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); + MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_BUILD_OTHER); event.setCancelled(true); return; } @@ -325,45 +323,38 @@ public class BlockEventListener implements Listener { 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"); + 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); + MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_BUILD_ROAD); event.setCancelled(true); } } @EventHandler(priority = EventPriority.LOWEST) public void blockDestroy(BlockBreakEvent event) { Player player = event.getPlayer(); - Location location = BukkitUtil.getLocation(event.getBlock().getLocation()); + Location location = BukkitUtil.adapt(event.getBlock().getLocation()); PlotArea area = location.getPlotArea(); if (area == null) { return; } Plot plot = area.getPlot(location); if (plot != null) { - BukkitPlayer plotPlayer = BukkitUtil.getPlayer(player); + BukkitPlayer plotPlayer = BukkitUtil.adapt(player); if (event.getBlock().getY() == 0) { - if (!Permissions - .hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_DESTROY_GROUNDLEVEL)) { - MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT, - Captions.PERMISSION_ADMIN_DESTROY_GROUNDLEVEL); + if (!Permissions.hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_DESTROY_GROUNDLEVEL)) { + MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_DESTROY_GROUNDLEVEL); event.setCancelled(true); return; } - } else if ((location.getY() > area.getMaxBuildHeight() || location.getY() < area - .getMinBuildHeight()) && !Permissions + } else if ((location.getY() > area.getMaxBuildHeight() || location.getY() < area.getMinBuildHeight()) && !Permissions .hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_BUILD_HEIGHT_LIMIT)) { event.setCancelled(true); - MainUtil.sendMessage(plotPlayer, Captions.HEIGHT_LIMIT.getTranslated() - .replace("{limit}", String.valueOf(area.getMaxBuildHeight()))); + MainUtil.sendMessage(plotPlayer, Captions.HEIGHT_LIMIT.getTranslated().replace("{limit}", String.valueOf(area.getMaxBuildHeight()))); } if (!plot.hasOwner()) { - if (!Permissions - .hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_DESTROY_UNOWNED, true)) { + if (!Permissions.hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_DESTROY_UNOWNED, true)) { event.setCancelled(true); } return; @@ -377,42 +368,36 @@ public class BlockEventListener implements Listener { return; } } - if (Permissions - .hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_DESTROY_OTHER)) { + if (Permissions.hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_DESTROY_OTHER)) { return; } - MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT, - Captions.PERMISSION_ADMIN_DESTROY_OTHER); + MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_DESTROY_OTHER); event.setCancelled(true); } else if (Settings.Done.RESTRICT_BUILDING && DoneFlag.isDone(plot)) { if (!Permissions.hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_BUILD_OTHER)) { - MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT, - Captions.PERMISSION_ADMIN_BUILD_OTHER); + MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_BUILD_OTHER); event.setCancelled(true); return; } } return; } - BukkitPlayer pp = BukkitUtil.getPlayer(player); + BukkitPlayer pp = BukkitUtil.adapt(player); if (Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_DESTROY_ROAD)) { return; } - if (PlotSquared.get().worldedit != null && pp.getAttribute("worldedit")) { - if (player.getInventory().getItemInMainHand().getType() == Material - .getMaterial(PlotSquared.get().worldedit.getConfiguration().wandItem)) { + if (this.worldEdit != null && pp.getAttribute("worldedit")) { + if (player.getInventory().getItemInMainHand().getType() == Material.getMaterial(this.worldEdit.getConfiguration().wandItem)) { return; } } - MainUtil - .sendMessage(pp, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_DESTROY_ROAD); + MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_DESTROY_ROAD); event.setCancelled(true); } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onBlockSpread(BlockSpreadEvent event) { + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onBlockSpread(BlockSpreadEvent event) { Block block = event.getBlock(); - Location location = BukkitUtil.getLocation(block.getLocation()); + Location location = BukkitUtil.adapt(block.getLocation()); if (location.isPlotRoad()) { event.setCancelled(true); return; @@ -453,10 +438,9 @@ public class BlockEventListener implements Listener { } } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onBlockForm(BlockFormEvent event) { + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onBlockForm(BlockFormEvent event) { Block block = event.getBlock(); - Location location = BukkitUtil.getLocation(block.getLocation()); + Location location = BukkitUtil.adapt(block.getLocation()); if (location.isPlotRoad()) { event.setCancelled(true); return; @@ -487,13 +471,12 @@ public class BlockEventListener implements Listener { } } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onEntityBlockForm(EntityBlockFormEvent event) { + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onEntityBlockForm(EntityBlockFormEvent event) { String world = event.getBlock().getWorld().getName(); - if (!PlotSquared.get().hasPlotArea(world)) { + if (!this.plotAreaManager.hasPlotArea(world)) { return; } - Location location = BukkitUtil.getLocation(event.getBlock().getLocation()); + Location location = BukkitUtil.adapt(event.getBlock().getLocation()); PlotArea area = location.getPlotArea(); if (area == null) { return; @@ -507,7 +490,7 @@ public class BlockEventListener implements Listener { if (entity instanceof Player) { Player player = (Player) entity; if (!plot.hasOwner()) { - BukkitPlayer plotPlayer = BukkitUtil.getPlayer(player); + BukkitPlayer plotPlayer = BukkitUtil.adapt(player); if (plot.getFlag(IceFormFlag.class)) { plot.debug("Ice could not be formed because ice-form = false"); return; @@ -515,7 +498,7 @@ public class BlockEventListener implements Listener { event.setCancelled(true); return; } - BukkitPlayer plotPlayer = BukkitUtil.getPlayer(player); + BukkitPlayer plotPlayer = BukkitUtil.adapt(player); if (!plot.isAdded(plotPlayer.getUUID())) { if (plot.getFlag(IceFormFlag.class)) { plot.debug("Ice could not be formed because ice-form = false"); @@ -531,10 +514,9 @@ public class BlockEventListener implements Listener { } } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onBlockDamage(BlockDamageEvent event) { + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onBlockDamage(BlockDamageEvent event) { Player player = event.getPlayer(); - Location location = BukkitUtil.getLocation(event.getBlock().getLocation()); + Location location = BukkitUtil.adapt(event.getBlock().getLocation()); PlotArea area = location.getPlotArea(); if (area == null) { return; @@ -557,42 +539,37 @@ public class BlockEventListener implements Listener { return; } if (!plot.hasOwner()) { - BukkitPlayer plotPlayer = BukkitUtil.getPlayer(player); - if (Permissions - .hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_DESTROY_UNOWNED)) { + BukkitPlayer plotPlayer = BukkitUtil.adapt(player); + if (Permissions.hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_DESTROY_UNOWNED)) { return; } event.setCancelled(true); return; } - BukkitPlayer plotPlayer = BukkitUtil.getPlayer(player); + BukkitPlayer plotPlayer = BukkitUtil.adapt(player); if (!plot.isAdded(plotPlayer.getUUID())) { List destroy = plot.getFlag(BreakFlag.class); Block block = event.getBlock(); - if (destroy - .contains(BlockTypeWrapper.get(BukkitAdapter.asBlockType(block.getType()))) - || Permissions + if (destroy.contains(BlockTypeWrapper.get(BukkitAdapter.asBlockType(block.getType()))) || Permissions .hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_DESTROY_OTHER)) { return; } - plot.debug(player.getName() + " could not break " + block.getType() - + " because it was not in the break flag"); + plot.debug(player.getName() + " could not break " + block.getType() + " because it was not in the break flag"); event.setCancelled(true); return; } return; } - BukkitPlayer plotPlayer = BukkitUtil.getPlayer(player); + BukkitPlayer plotPlayer = BukkitUtil.adapt(player); if (Permissions.hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_DESTROY_ROAD)) { return; } event.setCancelled(true); } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onFade(BlockFadeEvent event) { + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onFade(BlockFadeEvent event) { Block block = event.getBlock(); - Location location = BukkitUtil.getLocation(block.getLocation()); + Location location = BukkitUtil.adapt(block.getLocation()); PlotArea area = location.getPlotArea(); if (area == null) { return; @@ -649,54 +626,46 @@ public class BlockEventListener implements Listener { } } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onChange(BlockFromToEvent event) { + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onChange(BlockFromToEvent event) { Block from = event.getBlock(); // Check liquid flow flag inside of origin plot too - final Location fLocation = BukkitUtil.getLocation(from.getLocation()); + final Location fLocation = BukkitUtil.adapt(from.getLocation()); final PlotArea fromArea = fLocation.getPlotArea(); if (fromArea != null) { final Plot plot = fromArea.getOwnedPlot(fLocation); - if (plot != null - && plot.getFlag(LiquidFlowFlag.class) == LiquidFlowFlag.FlowStatus.DISABLED && event - .getBlock().isLiquid()) { - plot.debug("Liquid could not flow because liquid-flow = disabled"); + if (plot != null && plot.getFlag(LiquidFlowFlag.class) == LiquidFlowFlag.FlowStatus.DISABLED && event.getBlock().isLiquid()) { + plot.debug("Liquid could now flow because liquid-flow = disabled"); event.setCancelled(true); return; } } Block to = event.getToBlock(); - Location tLocation = BukkitUtil.getLocation(to.getLocation()); + Location tLocation = BukkitUtil.adapt(to.getLocation()); PlotArea area = tLocation.getPlotArea(); if (area == null) { return; } Plot plot = area.getOwnedPlot(tLocation); if (plot != null) { - if (!area.contains(fLocation.getX(), fLocation.getZ()) || !Objects - .equals(plot, area.getOwnedPlot(fLocation))) { + if (!area.contains(fLocation.getX(), fLocation.getZ()) || !Objects.equals(plot, area.getOwnedPlot(fLocation))) { event.setCancelled(true); return; } - if (plot.getFlag(LiquidFlowFlag.class) == LiquidFlowFlag.FlowStatus.ENABLED && event - .getBlock().isLiquid()) { + if (plot.getFlag(LiquidFlowFlag.class) == LiquidFlowFlag.FlowStatus.ENABLED && event.getBlock().isLiquid()) { return; } if (plot.getFlag(DisablePhysicsFlag.class)) { - plot.debug(event.getBlock().getType() - + " could not update because disable-physics = true"); + plot.debug(event.getBlock().getType() + " could not update because disable-physics = true"); event.setCancelled(true); return; } - if (plot.getFlag(LiquidFlowFlag.class) == LiquidFlowFlag.FlowStatus.DISABLED && event - .getBlock().isLiquid()) { + if (plot.getFlag(LiquidFlowFlag.class) == LiquidFlowFlag.FlowStatus.DISABLED && event.getBlock().isLiquid()) { plot.debug("Liquid could not flow because liquid-flow = disabled"); event.setCancelled(true); } - } else if (!area.contains(fLocation.getX(), fLocation.getZ()) || !Objects - .equals(null, area.getOwnedPlot(fLocation))) { + } else if (!area.contains(fLocation.getX(), fLocation.getZ()) || !Objects.equals(null, area.getOwnedPlot(fLocation))) { event.setCancelled(true); } else if (event.getBlock().isLiquid()) { final org.bukkit.Location location = event.getBlock().getLocation(); @@ -704,7 +673,6 @@ public class BlockEventListener implements Listener { /* X = block location A-H = potential plot locations - Z ^ | A B C @@ -713,50 +681,46 @@ public class BlockEventListener implements Listener { v <-----O-----> x */ - if (BukkitUtil.getPlot(location.clone().add(-1, 0, 1) /* A */) != null - || BukkitUtil.getPlot(location.clone().add(1, 0, 0) /* B */) != null - || BukkitUtil.getPlot(location.clone().add(1, 0, 1) /* C */) != null - || BukkitUtil.getPlot(location.clone().add(-1, 0, 0) /* D */) != null - || BukkitUtil.getPlot(location.clone().add(1, 0, 0) /* E */) != null - || BukkitUtil.getPlot(location.clone().add(-1, 0, -1) /* F */) != null - || BukkitUtil.getPlot(location.clone().add(0, 0, -1) /* G */) != null - || BukkitUtil.getPlot(location.clone().add(1, 0, 1) /* H */) != null) { + if (BukkitUtil.adapt(location.clone().add(-1, 0, 1) /* A */).getPlot() != null + || BukkitUtil.adapt(location.clone().add(1, 0, 0) /* B */).getPlot() != null + || BukkitUtil.adapt(location.clone().add(1, 0, 1) /* C */).getPlot() != null + || BukkitUtil.adapt(location.clone().add(-1, 0, 0) /* D */).getPlot() != null + || BukkitUtil.adapt(location.clone().add(1, 0, 0) /* E */).getPlot() != null + || BukkitUtil.adapt(location.clone().add(-1, 0, -1) /* F */).getPlot() != null + || BukkitUtil.adapt(location.clone().add(0, 0, -1) /* G */).getPlot() != null + || BukkitUtil.adapt(location.clone().add(1, 0, 1) /* H */).getPlot() != null) { event.setCancelled(true); } } } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onGrow(BlockGrowEvent event) { + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onGrow(BlockGrowEvent event) { Block block = event.getBlock(); - Location location = BukkitUtil.getLocation(block.getLocation()); + Location location = BukkitUtil.adapt(block.getLocation()); if (location.isUnownedPlotArea()) { event.setCancelled(true); } } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onBlockPistonExtend(BlockPistonExtendEvent event) { + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onBlockPistonExtend(BlockPistonExtendEvent event) { Block block = event.getBlock(); - Location location = BukkitUtil.getLocation(block.getLocation()); + Location location = BukkitUtil.adapt(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())) { + if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) { return; } for (Block block1 : event.getBlocks()) { - Location bloc = BukkitUtil.getLocation(block1.getLocation()); - if (bloc.isPlotArea() || bloc - .add(relative.getBlockX(), relative.getBlockY(), relative.getBlockZ()) - .isPlotArea()) { + Location bloc = BukkitUtil.adapt(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()) { + 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); @@ -769,20 +733,18 @@ public class BlockEventListener implements Listener { return; } 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())) { + Location bloc = BukkitUtil.adapt(block1.getLocation()); + if (!area.contains(bloc.getX(), bloc.getZ()) || !area.contains(bloc.getX() + relative.getBlockX(), bloc.getZ() + relative.getBlockZ())) { event.setCancelled(true); return; } - if (!plot.equals(area.getOwnedPlot(bloc)) || !plot.equals(area.getOwnedPlot( - bloc.add(relative.getBlockX(), relative.getBlockY(), relative.getBlockZ())))) { + if (!plot.equals(area.getOwnedPlot(bloc)) || !plot + .equals(area.getOwnedPlot(bloc.add(relative.getBlockX(), relative.getBlockY(), relative.getBlockZ())))) { event.setCancelled(true); return; } } - if (!plot.equals(area.getOwnedPlot( - location.add(relative.getBlockX(), relative.getBlockY(), relative.getBlockZ())))) { + 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 @@ -790,22 +752,19 @@ public class BlockEventListener implements Listener { } } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onBlockPistonRetract(BlockPistonRetractEvent event) { + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onBlockPistonRetract(BlockPistonRetractEvent event) { Block block = event.getBlock(); - Location location = BukkitUtil.getLocation(block.getLocation()); + Location location = BukkitUtil.adapt(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())) { + if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) { return; } for (Block block1 : event.getBlocks()) { - Location bloc = BukkitUtil.getLocation(block1.getLocation()); - if (bloc.isPlotArea() || bloc - .add(relative.getBlockX(), relative.getBlockY(), relative.getBlockZ()) - .isPlotArea()) { + Location bloc = BukkitUtil.adapt(block1.getLocation()); + if (bloc.isPlotArea() || bloc.add(relative.getBlockX(), relative.getBlockY(), relative.getBlockZ()).isPlotArea()) { event.setCancelled(true); return; } @@ -818,22 +777,20 @@ public class BlockEventListener implements Listener { return; } 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())) { + Location bloc = BukkitUtil.adapt(block1.getLocation()); + if (!area.contains(bloc.getX(), bloc.getZ()) || !area.contains(bloc.getX() + relative.getBlockX(), bloc.getZ() + relative.getBlockZ())) { event.setCancelled(true); return; } - if (!plot.equals(area.getOwnedPlot(bloc)) || !plot.equals(area.getOwnedPlot( - bloc.add(relative.getBlockX(), relative.getBlockY(), relative.getBlockZ())))) { + if (!plot.equals(area.getOwnedPlot(bloc)) || !plot + .equals(area.getOwnedPlot(bloc.add(relative.getBlockX(), relative.getBlockY(), relative.getBlockZ())))) { event.setCancelled(true); return; } } } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onBlockDispense(BlockDispenseEvent event) { + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onBlockDispense(BlockDispenseEvent event) { Material type = event.getItem().getType(); switch (type) { case SHULKER_BOX: @@ -870,10 +827,8 @@ public class BlockEventListener implements Listener { if (event.getBlock().getType() == Material.DROPPER) { return; } - BlockFace targetFace = - ((Directional) event.getBlock().getState().getData()).getFacing(); - Location location = - BukkitUtil.getLocation(event.getBlock().getRelative(targetFace).getLocation()); + BlockFace targetFace = ((Directional) event.getBlock().getState().getData()).getFacing(); + Location location = BukkitUtil.adapt(event.getBlock().getRelative(targetFace).getLocation()); if (location.isPlotRoad()) { event.setCancelled(true); } @@ -881,20 +836,19 @@ public class BlockEventListener implements Listener { } } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onStructureGrow(StructureGrowEvent event) { - if (!PlotSquared.get().hasPlotArea(event.getWorld().getName())) { + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onStructureGrow(StructureGrowEvent event) { + if (!this.plotAreaManager.hasPlotArea(event.getWorld().getName())) { return; } List blocks = event.getBlocks(); if (blocks.isEmpty()) { return; } - Location location = BukkitUtil.getLocation(blocks.get(0).getLocation()); + Location location = BukkitUtil.adapt(blocks.get(0).getLocation()); PlotArea area = location.getPlotArea(); if (area == null) { for (int i = blocks.size() - 1; i >= 0; i--) { - location = BukkitUtil.getLocation(blocks.get(i).getLocation()); + location = BukkitUtil.adapt(blocks.get(i).getLocation()); if (location.isPlotArea()) { blocks.remove(i); } @@ -907,7 +861,7 @@ public class BlockEventListener implements Listener { return; } for (int i = blocks.size() - 1; i >= 0; i--) { - location = BukkitUtil.getLocation(blocks.get(i).getLocation()); + location = BukkitUtil.adapt(blocks.get(i).getLocation()); if (!area.contains(location.getX(), location.getZ())) { blocks.remove(i); continue; @@ -924,7 +878,7 @@ public class BlockEventListener implements Listener { return; } for (int i = blocks.size() - 1; i >= 0; i--) { - location = BukkitUtil.getLocation(blocks.get(i).getLocation()); + location = BukkitUtil.adapt(blocks.get(i).getLocation()); Plot plot = area.getOwnedPlot(location); /* * plot → the base plot of the merged area @@ -932,26 +886,24 @@ public class BlockEventListener implements Listener { */ // Are plot and origin different AND are both plots merged - if (plot != null && !Objects.equals(plot, origin) && (!plot.isMerged() && !origin - .isMerged())) { + if (!Objects.equals(plot, origin) && (!plot.isMerged() && !origin.isMerged())) { event.getBlocks().remove(i); } } } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onBigBoom(BlockExplodeEvent event) { + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onBigBoom(BlockExplodeEvent event) { Block block = event.getBlock(); - Location location = BukkitUtil.getLocation(block.getLocation()); - String world = location.getWorld(); - if (!PlotSquared.get().hasPlotArea(world)) { + Location location = BukkitUtil.adapt(block.getLocation()); + String world = location.getWorldName(); + if (!this.plotAreaManager.hasPlotArea(world)) { return; } PlotArea area = location.getPlotArea(); if (area == null) { Iterator iterator = event.blockList().iterator(); while (iterator.hasNext()) { - location = BukkitUtil.getLocation(iterator.next().getLocation()); + location = BukkitUtil.adapt(iterator.next().getLocation()); if (location.isPlotArea()) { iterator.remove(); } @@ -965,14 +917,12 @@ public class BlockEventListener implements Listener { plot.debug("Explosion was cancelled because explosion = false"); } } - event.blockList().removeIf(blox -> plot != null && !plot - .equals(area.getOwnedPlot(BukkitUtil.getLocation(blox.getLocation())))); + event.blockList().removeIf(blox -> !plot.equals(area.getOwnedPlot(BukkitUtil.adapt(blox.getLocation())))); } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onBlockBurn(BlockBurnEvent event) { + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onBlockBurn(BlockBurnEvent event) { Block block = event.getBlock(); - Location location = BukkitUtil.getLocation(block.getLocation()); + Location location = BukkitUtil.adapt(block.getLocation()); PlotArea area = location.getPlotArea(); if (area == null) { @@ -989,13 +939,12 @@ public class BlockEventListener implements Listener { } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onBlockIgnite(BlockIgniteEvent event) { + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onBlockIgnite(BlockIgniteEvent event) { Player player = event.getPlayer(); Entity ignitingEntity = event.getIgnitingEntity(); Block block = event.getBlock(); BlockIgniteEvent.IgniteCause igniteCause = event.getCause(); - Location location1 = BukkitUtil.getLocation(block.getLocation()); + Location location1 = BukkitUtil.adapt(block.getLocation()); PlotArea area = location1.getPlotArea(); if (area == null) { return; @@ -1007,23 +956,20 @@ public class BlockEventListener implements Listener { Plot plot = area.getOwnedPlot(location1); if (player != null) { - BukkitPlayer pp = BukkitUtil.getPlayer(player); + BukkitPlayer pp = BukkitUtil.adapt(player); if (plot == null) { if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_ROAD)) { - MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, - Captions.PERMISSION_ADMIN_BUILD_ROAD); + MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_BUILD_ROAD); event.setCancelled(true); } } else if (!plot.hasOwner()) { if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_UNOWNED)) { - MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, - Captions.PERMISSION_ADMIN_BUILD_UNOWNED); + MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_BUILD_UNOWNED); event.setCancelled(true); } } else if (!plot.isAdded(pp.getUUID())) { if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_OTHER)) { - MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, - Captions.PERMISSION_ADMIN_BUILD_OTHER); + MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_BUILD_OTHER); event.setCancelled(true); } } else if (!plot.getFlag(BlockIgnitionFlag.class)) { @@ -1046,11 +992,10 @@ public class BlockEventListener implements Listener { Location location = null; if (fireball.getShooter() instanceof Entity) { Entity shooter = (Entity) fireball.getShooter(); - location = BukkitUtil.getLocation(shooter.getLocation()); + location = BukkitUtil.adapt(shooter.getLocation()); } else if (fireball.getShooter() instanceof BlockProjectileSource) { - Block shooter = - ((BlockProjectileSource) fireball.getShooter()).getBlock(); - location = BukkitUtil.getLocation(shooter.getLocation()); + Block shooter = ((BlockProjectileSource) fireball.getShooter()).getBlock(); + location = BukkitUtil.adapt(shooter.getLocation()); } if (location != null && !plot.equals(location.getPlot())) { event.setCancelled(true); @@ -1060,13 +1005,11 @@ public class BlockEventListener implements Listener { } else if (event.getIgnitingBlock() != null) { Block ignitingBlock = event.getIgnitingBlock(); - Plot plotIgnited = BukkitUtil.getLocation(ignitingBlock.getLocation()).getPlot(); - if (igniteCause == BlockIgniteEvent.IgniteCause.FLINT_AND_STEEL && ( - !plot.getFlag(BlockIgnitionFlag.class) || plotIgnited == null || !plotIgnited - .equals(plot)) || (igniteCause == BlockIgniteEvent.IgniteCause.SPREAD - || igniteCause == BlockIgniteEvent.IgniteCause.LAVA) && ( - !plot.getFlag(BlockIgnitionFlag.class) || plotIgnited == null || !plotIgnited - .equals(plot))) { + Plot plotIgnited = BukkitUtil.adapt(ignitingBlock.getLocation()).getPlot(); + if (igniteCause == BlockIgniteEvent.IgniteCause.FLINT_AND_STEEL && (!plot.getFlag(BlockIgnitionFlag.class) || plotIgnited == null + || !plotIgnited.equals(plot)) + || (igniteCause == BlockIgniteEvent.IgniteCause.SPREAD || igniteCause == BlockIgniteEvent.IgniteCause.LAVA) && ( + !plot.getFlag(BlockIgnitionFlag.class) || plotIgnited == null || !plotIgnited.equals(plot))) { event.setCancelled(true); } } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/EntityEventListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/EntityEventListener.java index 5bfb26a56..2d4162881 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/EntityEventListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/EntityEventListener.java @@ -36,6 +36,7 @@ import com.plotsquared.core.plot.flag.implementations.DisablePhysicsFlag; import com.plotsquared.core.plot.flag.implementations.ExplosionFlag; import com.plotsquared.core.plot.flag.implementations.InvincibleFlag; import com.plotsquared.core.plot.flag.implementations.MobPlaceFlag; +import com.plotsquared.core.plot.world.PlotAreaManager; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; @@ -60,30 +61,34 @@ import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.metadata.MetadataValue; import org.bukkit.plugin.Plugin; +import javax.annotation.Nonnull; +import javax.inject.Inject; import java.util.Iterator; import java.util.List; @SuppressWarnings("unused") public class EntityEventListener implements Listener { + private final PlotAreaManager plotAreaManager; private float lastRadius; - @EventHandler(priority = EventPriority.HIGHEST) - public void onEntityCombustByEntity(EntityCombustByEntityEvent event) { + @Inject public EntityEventListener(@Nonnull final PlotAreaManager plotAreaManager) { + this.plotAreaManager = plotAreaManager; + } + + @EventHandler(priority = EventPriority.HIGHEST) public void onEntityCombustByEntity(EntityCombustByEntityEvent event) { EntityDamageByEntityEvent eventChange = - new EntityDamageByEntityEvent(event.getCombuster(), event.getEntity(), - EntityDamageEvent.DamageCause.FIRE_TICK, event.getDuration()); + new EntityDamageByEntityEvent(event.getCombuster(), event.getEntity(), EntityDamageEvent.DamageCause.FIRE_TICK, event.getDuration()); onEntityDamageByEntityEvent(eventChange); if (eventChange.isCancelled()) { event.setCancelled(true); } } - @EventHandler(priority = EventPriority.HIGHEST) - public void onEntityDamageByEntityEvent(EntityDamageByEntityEvent event) { + @EventHandler(priority = EventPriority.HIGHEST) public void onEntityDamageByEntityEvent(EntityDamageByEntityEvent event) { Entity damager = event.getDamager(); - Location location = BukkitUtil.getLocation(damager); - if (!PlotSquared.get().hasPlotArea(location.getWorld())) { + Location location = BukkitUtil.adapt(damager.getLocation()); + if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) { return; } Entity victim = event.getEntity(); @@ -110,10 +115,9 @@ public class EntityEventListener implements Listener { } } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void creatureSpawnEvent(CreatureSpawnEvent event) { + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void creatureSpawnEvent(CreatureSpawnEvent event) { Entity entity = event.getEntity(); - Location location = BukkitUtil.getLocation(entity.getLocation()); + Location location = BukkitUtil.adapt(entity.getLocation()); PlotArea area = location.getPlotArea(); if (area == null) { return; @@ -180,18 +184,17 @@ public class EntityEventListener implements Listener { } } - @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) - public void onEntityFall(EntityChangeBlockEvent event) { + @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) public void onEntityFall(EntityChangeBlockEvent event) { if (event.getEntityType() != EntityType.FALLING_BLOCK) { return; } Block block = event.getBlock(); World world = block.getWorld(); String worldName = world.getName(); - if (!PlotSquared.get().hasPlotArea(worldName)) { + if (!this.plotAreaManager.hasPlotArea(worldName)) { return; } - Location location = BukkitUtil.getLocation(block.getLocation()); + Location location = BukkitUtil.adapt(block.getLocation()); PlotArea area = location.getPlotArea(); if (area == null) { return; @@ -199,9 +202,7 @@ public class EntityEventListener implements Listener { Plot plot = area.getOwnedPlotAbs(location); if (plot == null || plot.getFlag(DisablePhysicsFlag.class)) { event.setCancelled(true); - if (plot != null) { - plot.debug("Falling block event was cancelled because disable-physics = true"); - } + plot.debug("Falling block event was cancelled because disable-physics = true"); return; } if (event.getTo().hasGravity()) { @@ -216,8 +217,7 @@ public class EntityEventListener implements Listener { entity.remove(); } } else if (event.getTo() == Material.AIR) { - event.getEntity() - .setMetadata("plot", new FixedMetadataValue((Plugin) PlotSquared.get().IMP, plot)); + event.getEntity().setMetadata("plot", new FixedMetadataValue((Plugin) PlotSquared.platform(), plot)); } } @@ -225,7 +225,7 @@ public class EntityEventListener implements Listener { if (event.getEntityType() != EntityType.PLAYER) { return; } - Location location = BukkitUtil.getLocation(event.getEntity()); + Location location = BukkitUtil.adapt(event.getEntity().getLocation()); PlotArea area = location.getPlotArea(); if (area == null) { return; @@ -238,19 +238,17 @@ public class EntityEventListener implements Listener { return; } if (plot.getFlag(InvincibleFlag.class)) { - plot.debug( - event.getEntity().getName() + " could not take damage because invincible = true"); + plot.debug(event.getEntity().getName() + " could not take damage because invincible = true"); event.setCancelled(true); } } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onBigBoom(EntityExplodeEvent event) { - Location location = BukkitUtil.getLocation(event.getLocation()); + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onBigBoom(EntityExplodeEvent event) { + Location location = BukkitUtil.adapt(event.getLocation()); PlotArea area = location.getPlotArea(); boolean plotArea = location.isPlotArea(); if (!plotArea) { - if (!PlotSquared.get().hasPlotArea(location.getWorld())) { + if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) { return; } return; @@ -266,14 +264,11 @@ public class EntityEventListener implements Listener { origin = (Plot) meta.get(0).value(); } if (this.lastRadius != 0) { - List nearby = event.getEntity() - .getNearbyEntities(this.lastRadius, this.lastRadius, this.lastRadius); + List nearby = event.getEntity().getNearbyEntities(this.lastRadius, this.lastRadius, this.lastRadius); for (Entity near : nearby) { - if (near instanceof TNTPrimed || near.getType() - .equals(EntityType.MINECART_TNT)) { + if (near instanceof TNTPrimed || near.getType().equals(EntityType.MINECART_TNT)) { if (!near.hasMetadata("plot")) { - near.setMetadata("plot", - new FixedMetadataValue((Plugin) PlotSquared.get().IMP, plot)); + near.setMetadata("plot", new FixedMetadataValue((Plugin) PlotSquared.platform(), plot)); } } } @@ -282,9 +277,8 @@ public class EntityEventListener implements Listener { Iterator iterator = event.blockList().iterator(); while (iterator.hasNext()) { Block block = iterator.next(); - location = BukkitUtil.getLocation(block.getLocation()); - if (!area.contains(location.getX(), location.getZ()) || (origin != null - && !origin.equals(area.getOwnedPlot(location)))) { + location = BukkitUtil.adapt(block.getLocation()); + if (!area.contains(location.getX(), location.getZ()) || !origin.equals(area.getOwnedPlot(location))) { iterator.remove(); } } @@ -300,15 +294,13 @@ public class EntityEventListener implements Listener { public void onPeskyMobsChangeTheWorldLikeWTFEvent(EntityChangeBlockEvent event) { Entity e = event.getEntity(); if (!(e instanceof FallingBlock)) { - Location location = BukkitUtil.getLocation(event.getBlock().getLocation()); + Location location = BukkitUtil.adapt(event.getBlock().getLocation()); PlotArea area = location.getPlotArea(); if (area != null) { Plot plot = area.getOwnedPlot(location); if (plot != null && plot.getFlag(MobPlaceFlag.class)) { - return; - } - if (plot != null) { plot.debug(e.getType() + " could not change block because mob-place = false"); + return; } event.setCancelled(true); } @@ -319,10 +311,9 @@ public class EntityEventListener implements Listener { this.lastRadius = event.getRadius() + 1; } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onVehicleCreate(VehicleCreateEvent event) { + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onVehicleCreate(VehicleCreateEvent event) { Vehicle entity = event.getVehicle(); - Location location = BukkitUtil.getLocation(entity); + Location location = BukkitUtil.adapt(entity.getLocation()); PlotArea area = location.getPlotArea(); if (area == null) { return; @@ -333,8 +324,7 @@ public class EntityEventListener implements Listener { return; } if (Settings.Enabled_Components.KILL_ROAD_VEHICLES) { - entity - .setMetadata("plot", new FixedMetadataValue((Plugin) PlotSquared.get().IMP, plot)); + entity.setMetadata("plot", new FixedMetadataValue((Plugin) PlotSquared.platform(), plot)); } } } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/EntitySpawnListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/EntitySpawnListener.java index df6ca0ec3..24d22e6a0 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/EntitySpawnListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/EntitySpawnListener.java @@ -54,8 +54,8 @@ import org.bukkit.event.world.ChunkLoadEvent; import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.metadata.MetadataValue; import org.bukkit.plugin.Plugin; -import javax.annotation.Nonnull; +import javax.annotation.Nonnull; import java.util.List; public class EntitySpawnListener implements Listener { @@ -67,8 +67,7 @@ public class EntitySpawnListener implements Listener { public static void testNether(final Entity entity) { @Nonnull World world = entity.getWorld(); - if (world.getEnvironment() != World.Environment.NETHER - && world.getEnvironment() != World.Environment.THE_END) { + if (world.getEnvironment() != World.Environment.NETHER && world.getEnvironment() != World.Environment.THE_END) { return; } test(entity); @@ -92,8 +91,7 @@ public class EntitySpawnListener implements Listener { List meta = entity.getMetadata(KEY); if (meta.isEmpty()) { if (PlotSquared.get().getPlotAreaManager().hasPlotArea(world.getName())) { - entity.setMetadata(KEY, - new FixedMetadataValue((Plugin) PlotSquared.platform(), entity.getLocation())); + entity.setMetadata(KEY, new FixedMetadataValue((Plugin) PlotSquared.platform(), entity.getLocation())); } } else { org.bukkit.Location origin = (org.bukkit.Location) meta.get(0).value(); @@ -124,8 +122,7 @@ public class EntitySpawnListener implements Listener { } } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void creatureSpawnEvent(EntitySpawnEvent event) { + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void creatureSpawnEvent(EntitySpawnEvent event) { Entity entity = event.getEntity(); Location location = BukkitUtil.adapt(entity.getLocation()); PlotArea area = location.getPlotArea(); @@ -161,8 +158,7 @@ public class EntitySpawnListener implements Listener { } case SHULKER: if (!entity.hasMetadata("shulkerPlot")) { - entity.setMetadata("shulkerPlot", - new FixedMetadataValue((Plugin) PlotSquared.platform(), plot.getId())); + entity.setMetadata("shulkerPlot", new FixedMetadataValue((Plugin) PlotSquared.platform(), plot.getId())); } } } @@ -193,8 +189,7 @@ public class EntitySpawnListener implements Listener { } } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void vehicleMove(VehicleMoveEvent event) { + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void vehicleMove(VehicleMoveEvent event) { testNether(event.getVehicle()); } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEventListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEventListener.java index c4d7c6d90..0311638c3 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEventListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEventListener.java @@ -37,6 +37,8 @@ import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.listener.PlayerBlockEventType; import com.plotsquared.core.listener.PlotListener; import com.plotsquared.core.location.Location; +import com.plotsquared.core.player.MetaDataAccess; +import com.plotsquared.core.player.PlayerMetaDataKeys; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.PlotArea; @@ -65,6 +67,8 @@ import com.plotsquared.core.plot.flag.implementations.VehicleUseFlag; import com.plotsquared.core.plot.flag.implementations.VillagerInteractFlag; import com.plotsquared.core.plot.flag.types.BlockTypeWrapper; import com.plotsquared.core.plot.message.PlotMessage; +import com.plotsquared.core.plot.world.PlotAreaManager; +import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.MathMan; import com.plotsquared.core.util.Permissions; @@ -72,6 +76,8 @@ import com.plotsquared.core.util.PremiumVerification; import com.plotsquared.core.util.RegExUtil; import com.plotsquared.core.util.entity.EntityCategories; import com.plotsquared.core.util.task.TaskManager; +import com.plotsquared.core.util.task.TaskTime; +import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.world.block.BlockType; import io.papermc.lib.PaperLib; @@ -133,6 +139,8 @@ import org.bukkit.metadata.MetadataValue; import org.bukkit.plugin.Plugin; import org.bukkit.util.Vector; +import javax.annotation.Nonnull; +import javax.inject.Inject; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.HashSet; @@ -147,6 +155,9 @@ import java.util.regex.Pattern; @SuppressWarnings("unused") public class PlayerEventListener extends PlotListener implements Listener { + private final EventDispatcher eventDispatcher; + private final WorldEdit worldEdit; + private final PlotAreaManager plotAreaManager; // To prevent recursion private boolean tmpTeleport = true; private Field fieldPlayer; @@ -162,12 +173,21 @@ public class PlayerEventListener extends PlotListener implements Listener { } } + @Inject public PlayerEventListener(@Nonnull final PlotAreaManager plotAreaManager, + @Nonnull final EventDispatcher eventDispatcher, + @Nonnull final WorldEdit worldEdit) { + super(eventDispatcher); + this.eventDispatcher = eventDispatcher; + this.worldEdit = worldEdit; + this.plotAreaManager = plotAreaManager; + } + @EventHandler public void onVehicleEntityCollision(VehicleEntityCollisionEvent e) { if (e.getVehicle().getType() == EntityType.BOAT) { - Location location = BukkitUtil.getLocation(e.getEntity()); + Location location = BukkitUtil.adapt(e.getEntity().getLocation()); if (location.isPlotArea()) { if (e.getEntity() instanceof Player) { - PlotPlayer player = BukkitUtil.getPlayer((Player) e.getEntity()); + PlotPlayer player = BukkitUtil.adapt((Player) e.getEntity()); Plot plot = player.getCurrentPlot(); if (plot != null) { if (!plot.isAdded(player.getUUID())) { @@ -187,14 +207,13 @@ public class PlayerEventListener extends PlotListener implements Listener { } } - @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) - public void playerCommand(PlayerCommandPreprocessEvent event) { + @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) public void playerCommand(PlayerCommandPreprocessEvent event) { String msg = event.getMessage().toLowerCase().replaceAll("/", "").trim(); if (msg.isEmpty()) { return; } Player player = event.getPlayer(); - PlotPlayer plotPlayer = BukkitUtil.getPlayer(player); + PlotPlayer plotPlayer = BukkitUtil.adapt(player); Location location = plotPlayer.getLocation(); PlotArea area = location.getPlotArea(); if (area == null) { @@ -218,11 +237,8 @@ public class PlayerEventListener extends PlotListener implements Listener { return; } - List blockedCommands = plot != null ? - plot.getFlag(BlockedCmdsFlag.class) : - area.getFlag(BlockedCmdsFlag.class); - if (!blockedCommands.isEmpty() && !Permissions - .hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_INTERACT_BLOCKED_CMDS)) { + List blockedCommands = plot != null ? plot.getFlag(BlockedCmdsFlag.class) : area.getFlag(BlockedCmdsFlag.class); + if (!blockedCommands.isEmpty() && !Permissions.hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_INTERACT_BLOCKED_CMDS)) { String part = parts[0]; if (parts[0].contains(":")) { part = parts[0].split(":")[1]; @@ -280,16 +296,13 @@ public class PlayerEventListener extends PlotListener implements Listener { } } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onPreLoin(final AsyncPlayerPreLoginEvent event) { + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onPreLogin(final AsyncPlayerPreLoginEvent event) { final UUID uuid; if (Settings.UUID.OFFLINE) { if (Settings.UUID.FORCE_LOWERCASE) { - uuid = UUID.nameUUIDFromBytes( - ("OfflinePlayer:" + event.getName().toLowerCase()).getBytes(Charsets.UTF_8)); + uuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" + event.getName().toLowerCase()).getBytes(Charsets.UTF_8)); } else { - uuid = UUID.nameUUIDFromBytes( - ("OfflinePlayer:" + event.getName()).getBytes(Charsets.UTF_8)); + uuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" + event.getName()).getBytes(Charsets.UTF_8)); } } else { uuid = event.getUniqueId(); @@ -297,11 +310,10 @@ public class PlayerEventListener extends PlotListener implements Listener { PlotSquared.get().getImpromptuUUIDPipeline().storeImmediately(event.getName(), uuid); } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onConnect(PlayerJoinEvent event) { + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onConnect(PlayerJoinEvent event) { final Player player = event.getPlayer(); - BukkitUtil.removePlayer(player.getUniqueId()); - final PlotPlayer pp = BukkitUtil.getPlayer(player); + PlotSquared.platform().getPlayerManager().removePlayer(player.getUniqueId()); + final PlotPlayer pp = BukkitUtil.adapt(player); Location location = pp.getLocation(); PlotArea area = location.getPlotArea(); @@ -318,76 +330,72 @@ public class PlayerEventListener extends PlotListener implements Listener { if (!player.hasPlayedBefore() && player.isOnline()) { player.saveData(); } - PlotSquared.get().getEventDispatcher().doJoinTask(pp); - }, 20); + this.eventDispatcher.doJoinTask(pp); + }, TaskTime.seconds(1L)); - if (pp.hasPermission(Captions.PERMISSION_ADMIN_UPDATE_NOTIFICATION.getTranslated()) - && Settings.Enabled_Components.UPDATE_NOTIFICATIONS && PremiumVerification.isPremium() - && UpdateUtility.hasUpdate) { + if (pp.hasPermission(Captions.PERMISSION_ADMIN_UPDATE_NOTIFICATION.getTranslated()) && Settings.Enabled_Components.UPDATE_NOTIFICATIONS + && PremiumVerification.isPremium() && UpdateUtility.hasUpdate) { new PlotMessage("-----------------------------------").send(pp); - new PlotMessage(Captions.PREFIX + "There appears to be a PlotSquared update available!") - .color("$1").send(pp); - new PlotMessage( - Captions.PREFIX + "&6You are running version " + UpdateUtility.internalVersion - .versionString() + ", &6latest version is " + UpdateUtility.spigotVersion) - .color("$1").send(pp); + new PlotMessage(Captions.PREFIX + "There appears to be a PlotSquared update available!").color("$1").send(pp); + new PlotMessage(Captions.PREFIX + "&6You are running version " + UpdateUtility.internalVersion.versionString() + ", &6latest version is " + + UpdateUtility.spigotVersion).color("$1").send(pp); new PlotMessage(Captions.PREFIX + "Download at:").color("$1").send(pp); player.sendMessage(" https://www.spigotmc.org/resources/77506/updates"); new PlotMessage("-----------------------------------").send(pp); } } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void playerRespawn(PlayerRespawnEvent event) { + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void playerRespawn(PlayerRespawnEvent event) { Player player = event.getPlayer(); - PlotPlayer pp = BukkitUtil.getPlayer(player); - PlotSquared.get().getEventDispatcher().doRespawnTask(pp); + PlotPlayer pp = BukkitUtil.adapt(player); + this.eventDispatcher.doRespawnTask(pp); } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onTeleport(PlayerTeleportEvent event) { + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onTeleport(PlayerTeleportEvent event) { Player player = event.getPlayer(); - BukkitPlayer pp = BukkitUtil.getPlayer(player); - Plot lastPlot = pp.getMeta(PlotPlayer.META_LAST_PLOT); - org.bukkit.Location to = event.getTo(); - //noinspection ConstantConditions - if (to != null) { - Location location = BukkitUtil.getLocation(to); - PlotArea area = location.getPlotArea(); - if (area == null) { - if (lastPlot != null) { - plotExit(pp, lastPlot); - pp.deleteMeta(PlotPlayer.META_LAST_PLOT); + BukkitPlayer pp = BukkitUtil.adapt(player); + try (final MetaDataAccess lastPlotAccess = pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LAST_PLOT)) { + Plot lastPlot = lastPlotAccess.get().orElse(null); + org.bukkit.Location to = event.getTo(); + //noinspection ConstantConditions + if (to != null) { + Location location = BukkitUtil.adapt(to); + PlotArea area = location.getPlotArea(); + if (area == null) { + if (lastPlot != null) { + plotExit(pp, lastPlot); + lastPlotAccess.remove(); + } + try (final MetaDataAccess lastLocationAccess = pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LOCATION)) { + lastLocationAccess.remove(); + } + return; } - pp.deleteMeta(PlotPlayer.META_LOCATION); - return; - } - Plot plot = area.getPlot(location); - if (plot != null) { - final boolean result = DenyTeleportFlag.allowsTeleport(pp, plot); - // there is one possibility to still allow teleportation: - // to is identical to the plot's home location, and untrusted-visit is true - // i.e. untrusted-visit can override deny-teleport - // this is acceptable, because otherwise it wouldn't make sense to have both flags set - if (!result && !(plot.getFlag(UntrustedVisitFlag.class) && plot.getHomeSynchronous() - .equals(BukkitUtil.getLocationFull(to)))) { - MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, - Captions.PERMISSION_ADMIN_ENTRY_DENIED); - event.setCancelled(true); + Plot plot = area.getPlot(location); + if (plot != null) { + final boolean result = DenyTeleportFlag.allowsTeleport(pp, plot); + // there is one possibility to still allow teleportation: + // to is identical to the plot's home location, and untrusted-visit is true + // i.e. untrusted-visit can override deny-teleport + // this is acceptable, because otherwise it wouldn't make sense to have both flags set + if (!result && !(plot.getFlag(UntrustedVisitFlag.class) && plot.getHomeSynchronous().equals(BukkitUtil.adaptComplete(to)))) { + MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_ENTRY_DENIED); + event.setCancelled(true); + } } } } playerMove(event); } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void vehicleMove(VehicleMoveEvent event) throws IllegalAccessException { + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void vehicleMove(VehicleMoveEvent event) + throws IllegalAccessException { final org.bukkit.Location from = event.getFrom(); final org.bukkit.Location to = event.getTo(); int toX, toZ; - if ((toX = MathMan.roundInt(to.getX())) != MathMan.roundInt(from.getX()) - | (toZ = MathMan.roundInt(to.getZ())) != MathMan.roundInt(from.getZ())) { + if ((toX = MathMan.roundInt(to.getX())) != MathMan.roundInt(from.getX()) | (toZ = MathMan.roundInt(to.getZ())) != MathMan + .roundInt(from.getZ())) { Vehicle vehicle = event.getVehicle(); // Check allowed @@ -411,8 +419,7 @@ public class PlayerEventListener extends PlotListener implements Listener { org.bukkit.Location dest; if (moveTmp.isCancelled()) { dest = from; - } else if (MathMan.roundInt(moveTmp.getTo().getX()) != toX - || MathMan.roundInt(moveTmp.getTo().getZ()) != toZ) { + } else if (MathMan.roundInt(moveTmp.getTo().getX()) != toX || MathMan.roundInt(moveTmp.getTo().getZ()) != toZ) { dest = to; } else { dest = null; @@ -426,22 +433,19 @@ public class PlayerEventListener extends PlotListener implements Listener { } } if (Settings.Enabled_Components.KILL_ROAD_VEHICLES) { - final com.sk89q.worldedit.world.entity.EntityType entityType = - BukkitAdapter.adapt(vehicle.getType()); + final com.sk89q.worldedit.world.entity.EntityType entityType = BukkitAdapter.adapt(vehicle.getType()); // Horses etc are vehicles, but they're also animals // so this filters out all living entities - if (EntityCategories.VEHICLE.contains(entityType) && !EntityCategories.ANIMAL - .contains(entityType)) { + if (EntityCategories.VEHICLE.contains(entityType) && !EntityCategories.ANIMAL.contains(entityType)) { List meta = vehicle.getMetadata("plot"); - Plot toPlot = BukkitUtil.getLocation(to).getPlot(); + Plot toPlot = BukkitUtil.adapt(to).getPlot(); if (!meta.isEmpty()) { Plot origin = (Plot) meta.get(0).value(); if (origin != null && !origin.getBasePlot(false).equals(toPlot)) { vehicle.remove(); } } else if (toPlot != null) { - vehicle.setMetadata("plot", - new FixedMetadataValue((Plugin) PlotSquared.get().IMP, toPlot)); + vehicle.setMetadata("plot", new FixedMetadataValue((Plugin) PlotSquared.platform(), toPlot)); } } } @@ -450,48 +454,53 @@ public class PlayerEventListener extends PlotListener implements Listener { } } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void playerMove(PlayerMoveEvent event) { + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void playerMove(PlayerMoveEvent event) { org.bukkit.Location from = event.getFrom(); org.bukkit.Location to = event.getTo(); int x2; if (MathMan.roundInt(from.getX()) != (x2 = MathMan.roundInt(to.getX()))) { Player player = event.getPlayer(); - BukkitPlayer pp = BukkitUtil.getPlayer(player); + BukkitPlayer pp = BukkitUtil.adapt(player); // Cancel teleport - if (TaskManager.TELEPORT_QUEUE.remove(pp.getName())) { + if (TaskManager.removeFromTeleportQueue(pp.getName())) { MainUtil.sendMessage(pp, Captions.TELEPORT_FAILED); } // Set last location - Location location = BukkitUtil.getLocation(to); - pp.setMeta(PlotPlayer.META_LOCATION, location); + Location location = BukkitUtil.adapt(to); + try (final MetaDataAccess lastLocationAccess = pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LOCATION)) { + lastLocationAccess.remove(); + } PlotArea area = location.getPlotArea(); if (area == null) { - pp.deleteMeta(PlotPlayer.META_LAST_PLOT); + try (final MetaDataAccess lastPlotAccess = pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LAST_PLOT)) { + lastPlotAccess.remove(); + } return; } Plot now = area.getPlot(location); - Plot lastPlot = pp.getMeta(PlotPlayer.META_LAST_PLOT); + Plot lastPlot; + try (final MetaDataAccess lastPlotAccess = pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LAST_PLOT)) { + lastPlot = lastPlotAccess.get().orElse(null); + } if (now == null) { - if (lastPlot != null && !plotExit(pp, lastPlot) && this.tmpTeleport && !pp - .getMeta("kick", false)) { - MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, - Captions.PERMISSION_ADMIN_EXIT_DENIED); - this.tmpTeleport = false; - if (lastPlot.equals(BukkitUtil.getLocation(from).getPlot())) { - player.teleport(from); - } else { - player.teleport(player.getWorld().getSpawnLocation()); + try (final MetaDataAccess kickAccess = pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_KICK)) { + if (lastPlot != null && !plotExit(pp, lastPlot) && this.tmpTeleport && !kickAccess.get().orElse(false)) { + MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_EXIT_DENIED); + this.tmpTeleport = false; + if (lastPlot.equals(BukkitUtil.adapt(from).getPlot())) { + player.teleport(from); + } else { + player.teleport(player.getWorld().getSpawnLocation()); + } + this.tmpTeleport = true; + event.setCancelled(true); + return; } - this.tmpTeleport = true; - event.setCancelled(true); - return; } } else if (now.equals(lastPlot)) { ForceFieldListener.handleForcefield(player, pp, now); } else if (!plotEntry(pp, now) && this.tmpTeleport) { - MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, - Captions.PERMISSION_ADMIN_ENTRY_DENIED); + MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_ENTRY_DENIED); this.tmpTeleport = false; to.setX(from.getBlockX()); to.setY(from.getBlockY()); @@ -519,41 +528,47 @@ public class PlayerEventListener extends PlotListener implements Listener { int z2; if (MathMan.roundInt(from.getZ()) != (z2 = MathMan.roundInt(to.getZ()))) { Player player = event.getPlayer(); - BukkitPlayer pp = BukkitUtil.getPlayer(player); + BukkitPlayer pp = BukkitUtil.adapt(player); // Cancel teleport - if (TaskManager.TELEPORT_QUEUE.remove(pp.getName())) { + if (TaskManager.removeFromTeleportQueue(pp.getName())) { MainUtil.sendMessage(pp, Captions.TELEPORT_FAILED); } // Set last location - Location location = BukkitUtil.getLocation(to); - pp.setMeta(PlotPlayer.META_LOCATION, location); + Location location = BukkitUtil.adapt(to); + try (final MetaDataAccess lastLocationAccess = pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LOCATION)) { + lastLocationAccess.set(location); + } PlotArea area = location.getPlotArea(); if (area == null) { - pp.deleteMeta(PlotPlayer.META_LAST_PLOT); + try (final MetaDataAccess lastPlotAccess = pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LAST_PLOT)) { + lastPlotAccess.remove(); + } return; } Plot now = area.getPlot(location); - Plot lastPlot = pp.getMeta(PlotPlayer.META_LAST_PLOT); + Plot lastPlot; + try (final MetaDataAccess lastPlotAccess = pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LAST_PLOT)) { + lastPlot = lastPlotAccess.get().orElse(null); + } if (now == null) { - if (lastPlot != null && !plotExit(pp, lastPlot) && this.tmpTeleport && !pp - .getMeta("kick", false)) { - MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, - Captions.PERMISSION_ADMIN_EXIT_DENIED); - this.tmpTeleport = false; - if (lastPlot.equals(BukkitUtil.getLocation(from).getPlot())) { - player.teleport(from); - } else { - player.teleport(player.getWorld().getSpawnLocation()); + try (final MetaDataAccess kickAccess = pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_KICK)) { + if (lastPlot != null && !plotExit(pp, lastPlot) && this.tmpTeleport && !kickAccess.get().orElse(false)) { + MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_EXIT_DENIED); + this.tmpTeleport = false; + if (lastPlot.equals(BukkitUtil.adapt(from).getPlot())) { + player.teleport(from); + } else { + player.teleport(player.getWorld().getSpawnLocation()); + } + this.tmpTeleport = true; + event.setCancelled(true); + return; } - this.tmpTeleport = true; - event.setCancelled(true); - return; } } else if (now.equals(lastPlot)) { ForceFieldListener.handleForcefield(player, pp, now); } else if (!plotEntry(pp, now) && this.tmpTeleport) { - MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, - Captions.PERMISSION_ADMIN_ENTRY_DENIED); + MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_ENTRY_DENIED); this.tmpTeleport = false; player.teleport(from); to.setX(from.getBlockX()); @@ -585,7 +600,7 @@ public class PlayerEventListener extends PlotListener implements Listener { return; } - BukkitPlayer plotPlayer = BukkitUtil.getPlayer(event.getPlayer()); + BukkitPlayer plotPlayer = BukkitUtil.adapt(event.getPlayer()); Location location = plotPlayer.getLocation(); PlotArea area = location.getPlotArea(); if (area == null) { @@ -595,12 +610,10 @@ public class PlayerEventListener extends PlotListener implements Listener { if (plot == null) { return; } - if (!((plot.getFlag(ChatFlag.class) && area.isPlotChat() && plotPlayer.getAttribute("chat")) - || area.isForcingPlotChat())) { + if (!((plot.getFlag(ChatFlag.class) && area.isPlotChat() && plotPlayer.getAttribute("chat")) || area.isForcingPlotChat())) { return; } - if (plot.isDenied(plotPlayer.getUUID()) && !Permissions - .hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_CHAT_BYPASS)) { + if (plot.isDenied(plotPlayer.getUUID()) && !Permissions.hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_CHAT_BYPASS)) { return; } event.setCancelled(true); @@ -611,7 +624,7 @@ public class PlayerEventListener extends PlotListener implements Listener { Set recipients = event.getRecipients(); recipients.clear(); Set spies = new HashSet<>(); - for (final PlotPlayer pp : PlotSquared.imp().getPlayerManager().getPlayers()) { + for (final PlotPlayer pp : PlotSquared.platform().getPlayerManager().getPlayers()) { if (pp.getAttribute("chatspy")) { spies.add(((BukkitPlayer) pp).player); } else { @@ -621,8 +634,8 @@ public class PlayerEventListener extends PlotListener implements Listener { } } } - String partial = ChatColor.translateAlternateColorCodes('&', - format.replace("%plot_id%", id.getX() + ";" + id.getY()).replace("%sender%", sender)); + String partial = + ChatColor.translateAlternateColorCodes('&', format.replace("%plot_id%", id.getX() + ";" + id.getY()).replace("%sender%", sender)); if (plotPlayer.hasPermission("plots.chat.color")) { message = Captions.color(message); } @@ -631,36 +644,38 @@ public class PlayerEventListener extends PlotListener implements Listener { receiver.sendMessage(full); } if (!spies.isEmpty()) { - String spyMessage = Captions.PLOT_CHAT_SPY_FORMAT.getTranslated() - .replace("%plot_id%", id.getX() + ";" + id.getY()).replace("%sender%", sender) - .replace("%msg%", message); + String spyMessage = + Captions.PLOT_CHAT_SPY_FORMAT.getTranslated().replace("%plot_id%", id.getX() + ";" + id.getY()).replace("%sender%", sender) + .replace("%msg%", message); for (Player player : spies) { player.sendMessage(spyMessage); } } - PlotSquared.debug(full); + // TODO: Re-implement + // PlotSquared.debug(full); } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onWorldChanged(PlayerChangedWorldEvent event) { + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onWorldChanged(PlayerChangedWorldEvent event) { Player player = event.getPlayer(); - BukkitPlayer pp = BukkitUtil.getPlayer(player); + BukkitPlayer pp = BukkitUtil.adapt(player); // Delete last location - Plot plot = (Plot) pp.deleteMeta(PlotPlayer.META_LAST_PLOT); - pp.deleteMeta(PlotPlayer.META_LOCATION); + Plot plot; + try (final MetaDataAccess lastPlotAccess = pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LAST_PLOT)) { + plot = lastPlotAccess.remove(); + } + try (final MetaDataAccess lastLocationAccess = pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LOCATION)) { + lastLocationAccess.remove(); + } if (plot != null) { plotExit(pp, plot); } - if (PlotSquared.get().worldedit != null) { + if (this.worldEdit != null) { if (!Permissions.hasPermission(pp, Captions.PERMISSION_WORLDEDIT_BYPASS)) { if (pp.getAttribute("worldedit")) { pp.removeAttribute("worldedit"); } } } - if (Settings.Enabled_Components.PERMISSION_CACHE) { - pp.deleteMeta("perm"); - } Location location = pp.getLocation(); PlotArea area = location.getPlotArea(); if (location.isPlotArea()) { @@ -671,16 +686,14 @@ public class PlayerEventListener extends PlotListener implements Listener { } } - @SuppressWarnings("deprecation") - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + @SuppressWarnings("deprecation") @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onInventoryClick(InventoryClickEvent event) { /*if (!event.isLeftClick() || (event.getAction() != InventoryAction.PLACE_ALL) || event .isShiftClick()) { return; }*/ HumanEntity entity = event.getWhoClicked(); - if (!(entity instanceof Player) || !PlotSquared.get() - .hasPlotArea(entity.getWorld().getName())) { + if (!(entity instanceof Player) || !this.plotAreaManager.hasPlotArea(entity.getWorld().getName())) { return; } @@ -689,7 +702,7 @@ public class PlayerEventListener extends PlotListener implements Listener { return; } Player player = (Player) clicker; - BukkitPlayer pp = BukkitUtil.getPlayer(player); + BukkitPlayer pp = BukkitUtil.adapt(player); final PlotInventory inventory = PlotInventory.getOpenPlotInventory(pp); if (inventory != null && event.getRawSlot() == event.getSlot()) { if (!inventory.onClick(event.getSlot())) { @@ -705,30 +718,22 @@ public class PlayerEventListener extends PlotListener implements Listener { } ItemStack current = inv.getItemInHand(); ItemStack newItem = event.getCursor(); - if (newItem == null) { - return; - } ItemMeta newMeta = newItem.getItemMeta(); ItemMeta oldMeta = newItem.getItemMeta(); if (event.getClick() == ClickType.CREATIVE) { final Plot plot = pp.getCurrentPlot(); if (plot != null) { - if (plot.getFlag(PreventCreativeCopyFlag.class) && !plot - .isAdded(player.getUniqueId()) && !Permissions + 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()); + 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"); + plot.debug(player.getName() + " could not creative-copy an item because prevent-creative-copy = true"); } } else { PlotArea area = pp.getPlotAreaAbs(); - if (area != null && area.isRoadFlags() && area - .getRoadFlag(PreventCreativeCopyFlag.class)) { - final ItemStack newStack = - new ItemStack(newItem.getType(), newItem.getAmount()); + if (area != null && area.isRoadFlags() && area.getRoadFlag(PreventCreativeCopyFlag.class)) { + final ItemStack newStack = new ItemStack(newItem.getType(), newItem.getAmount()); event.setCursor(newStack); } } @@ -779,7 +784,7 @@ public class PlayerEventListener extends PlotListener implements Listener { return; } } - Location location = BukkitUtil.getLocation(state.getLocation()); + Location location = BukkitUtil.adapt(state.getLocation()); PlotArea area = location.getPlotArea(); if (area == null) { return; @@ -793,66 +798,57 @@ public class PlayerEventListener extends PlotListener implements Listener { } } else if (!plot.hasOwner()) { if (!Permissions.hasPermission(pp, "plots.admin.interact.unowned")) { - MainUtil - .sendMessage(pp, Captions.NO_PERMISSION_EVENT, "plots.admin.interact.unowned"); + MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, "plots.admin.interact.unowned"); cancelled = true; } } else { UUID uuid = pp.getUUID(); if (!plot.isAdded(uuid)) { if (!Permissions.hasPermission(pp, "plots.admin.interact.other")) { - MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, - "plots.admin.interact.other"); + MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, "plots.admin.interact.other"); cancelled = true; } } } if (cancelled) { - if ((current.getType() == newItem.getType()) && (current.getDurability() == newItem - .getDurability())) { - event.setCursor( - new ItemStack(newItem.getType(), newItem.getAmount(), newItem.getDurability())); + if ((current.getType() == newItem.getType()) && (current.getDurability() == newItem.getDurability())) { + event.setCursor(new ItemStack(newItem.getType(), newItem.getAmount(), newItem.getDurability())); event.setCancelled(true); return; } - event.setCursor( - new ItemStack(newItem.getType(), newItem.getAmount(), newItem.getDurability())); + event.setCursor(new ItemStack(newItem.getType(), newItem.getAmount(), newItem.getDurability())); } } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onInteract(PlayerInteractAtEntityEvent e) { + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onInteract(PlayerInteractAtEntityEvent e) { Entity entity = e.getRightClicked(); if (!(entity instanceof ArmorStand) && !(entity instanceof ItemFrame)) { return; } - Location location = BukkitUtil.getLocation(e.getRightClicked().getLocation()); + Location location = BukkitUtil.adapt(e.getRightClicked().getLocation()); PlotArea area = location.getPlotArea(); if (area == null) { return; } EntitySpawnListener.testNether(entity); Plot plot = location.getPlotAbs(); - BukkitPlayer pp = BukkitUtil.getPlayer(e.getPlayer()); + BukkitPlayer pp = BukkitUtil.adapt(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); } } 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); + MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_BUILD_OTHER); e.setCancelled(true); return; } } if (!plot.hasOwner()) { if (!Permissions.hasPermission(pp, "plots.admin.interact.unowned")) { - MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, - "plots.admin.interact.unowned"); + MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, "plots.admin.interact.unowned"); e.setCancelled(true); } } else { @@ -864,21 +860,18 @@ public class PlayerEventListener extends PlotListener implements Listener { return; } if (!Permissions.hasPermission(pp, "plots.admin.interact.other")) { - MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, - "plots.admin.interact.other"); + MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, "plots.admin.interact.other"); e.setCancelled(true); - plot.debug(pp.getName() + " could not interact with " + entity.getType() - + " bcause misc-interact = false"); + plot.debug(pp.getName() + " could not interact with " + entity.getType() + " bcause misc-interact = false"); } } } } - @EventHandler(priority = EventPriority.LOW) - public void onCancelledInteract(PlayerInteractEvent event) { + @EventHandler(priority = EventPriority.LOW) public void onCancelledInteract(PlayerInteractEvent event) { if (event.isCancelled() && event.getAction() == Action.RIGHT_CLICK_AIR) { Player player = event.getPlayer(); - BukkitPlayer pp = BukkitUtil.getPlayer(player); + BukkitPlayer pp = BukkitUtil.adapt(player); PlotArea area = pp.getPlotAreaAbs(); if (area == null) { return; @@ -900,10 +893,8 @@ public class PlayerEventListener extends PlotListener implements Listener { if (type.toString().toLowerCase().endsWith("_egg")) { Block block = player.getTargetBlockExact(5, FluidCollisionMode.SOURCE_ONLY); if (block != null && block.getType() != Material.AIR) { - Location location = BukkitUtil.getLocation(block.getLocation()); - if (!PlotSquared.get().getEventDispatcher() - .checkPlayerBlockEvent(pp, PlayerBlockEventType.SPAWN_MOB, location, null, - true)) { + Location location = BukkitUtil.adapt(block.getLocation()); + if (!this.eventDispatcher.checkPlayerBlockEvent(pp, PlayerBlockEventType.SPAWN_MOB, location, null, true)) { event.setCancelled(true); event.setUseItemInHand(Event.Result.DENY); } @@ -912,10 +903,9 @@ public class PlayerEventListener extends PlotListener implements Listener { } } - @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) - public void onInteract(PlayerInteractEvent event) { + @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onInteract(PlayerInteractEvent event) { Player player = event.getPlayer(); - BukkitPlayer pp = BukkitUtil.getPlayer(player); + BukkitPlayer pp = BukkitUtil.adapt(player); PlotArea area = pp.getPlotAreaAbs(); if (area == null) { return; @@ -923,10 +913,7 @@ public class PlayerEventListener extends PlotListener implements Listener { PlayerBlockEventType eventType = null; BlockType blocktype1; Block block = event.getClickedBlock(); - if (block == null) { - return; - } - Location location = BukkitUtil.getLocation(block.getLocation()); + Location location = BukkitUtil.adapt(block.getLocation()); Action action = event.getAction(); outer: switch (action) { @@ -976,12 +963,12 @@ public class PlayerEventListener extends PlotListener implements Listener { if (PaperLib.isPaper()) { if (MaterialTags.SPAWN_EGGS.isTagged(type) || Material.EGG.equals(type)) { eventType = PlayerBlockEventType.SPAWN_MOB; - break; + break outer; } } else { if (type.toString().toLowerCase().endsWith("egg")) { eventType = PlayerBlockEventType.SPAWN_MOB; - break; + break outer; } } if (type.isEdible()) { @@ -1014,15 +1001,14 @@ public class PlayerEventListener extends PlotListener implements Listener { eventType = PlayerBlockEventType.READ; break outer; case ARMOR_STAND: - location = BukkitUtil - .getLocation(block.getRelative(event.getBlockFace()).getLocation()); + location = BukkitUtil.adapt(block.getRelative(event.getBlockFace()).getLocation()); eventType = PlayerBlockEventType.PLACE_MISC; break outer; } break; } case LEFT_CLICK_BLOCK: { - location = BukkitUtil.getLocation(block.getLocation()); + location = BukkitUtil.adapt(block.getLocation()); //eventType = PlayerBlockEventType.BREAK_BLOCK; blocktype1 = BukkitAdapter.asBlockType(block.getType()); if (block.getType() == Material.DRAGON_EGG) { @@ -1035,45 +1021,38 @@ public class PlayerEventListener extends PlotListener implements Listener { default: return; } - if (PlotSquared.get().worldedit != null && pp.getAttribute("worldedit")) { - if (event.getMaterial() == Material - .getMaterial(PlotSquared.get().worldedit.getConfiguration().wandItem)) { + if (this.worldEdit != null && pp.getAttribute("worldedit")) { + if (event.getMaterial() == Material.getMaterial(this.worldEdit.getConfiguration().wandItem)) { return; } } - if (!PlotSquared.get().getEventDispatcher() - .checkPlayerBlockEvent(pp, eventType, location, blocktype1, true)) { + if (!this.eventDispatcher.checkPlayerBlockEvent(pp, eventType, location, blocktype1, true)) { event.setCancelled(true); event.setUseInteractedBlock(Event.Result.DENY); } } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onBucketEmpty(PlayerBucketEmptyEvent event) { + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onBucketEmpty(PlayerBucketEmptyEvent event) { BlockFace bf = event.getBlockFace(); - Block block = - event.getBlockClicked().getLocation().add(bf.getModX(), bf.getModY(), bf.getModZ()) - .getBlock(); - Location location = BukkitUtil.getLocation(block.getLocation()); + Block block = event.getBlockClicked().getLocation().add(bf.getModX(), bf.getModY(), bf.getModZ()).getBlock(); + Location location = BukkitUtil.adapt(block.getLocation()); PlotArea area = location.getPlotArea(); if (area == null) { return; } - BukkitPlayer pp = BukkitUtil.getPlayer(event.getPlayer()); + BukkitPlayer pp = BukkitUtil.adapt(event.getPlayer()); Plot plot = area.getPlot(location); if (plot == null) { if (Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_ROAD)) { return; } - MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, - Captions.PERMISSION_ADMIN_BUILD_ROAD); + MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_BUILD_ROAD); event.setCancelled(true); } else if (!plot.hasOwner()) { if (Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_UNOWNED)) { return; } - MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, - Captions.PERMISSION_ADMIN_BUILD_UNOWNED); + MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_BUILD_UNOWNED); event.setCancelled(true); } else if (!plot.isAdded(pp.getUUID())) { List use = plot.getFlag(UseFlag.class); @@ -1086,59 +1065,53 @@ public class PlayerEventListener extends PlotListener implements Listener { if (Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_OTHER)) { return; } - MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, - Captions.PERMISSION_ADMIN_BUILD_OTHER); + MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_BUILD_OTHER); event.setCancelled(true); } 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); + MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_BUILD_OTHER); event.setCancelled(true); } } } - @EventHandler(priority = EventPriority.HIGHEST) - public void onInventoryClose(InventoryCloseEvent event) { + @EventHandler(priority = EventPriority.HIGHEST) public void onInventoryClose(InventoryCloseEvent event) { HumanEntity closer = event.getPlayer(); if (!(closer instanceof Player)) { return; } Player player = (Player) closer; - PlotInventory.removePlotInventoryOpen(BukkitUtil.getPlayer(player)); + PlotInventory.removePlotInventoryOpen(BukkitUtil.adapt(player)); } @EventHandler(priority = EventPriority.MONITOR) public void onLeave(PlayerQuitEvent event) { - TaskManager.TELEPORT_QUEUE.remove(event.getPlayer().getName()); - BukkitPlayer pp = BukkitUtil.getPlayer(event.getPlayer()); + TaskManager.removeFromTeleportQueue(event.getPlayer().getName()); + BukkitPlayer pp = BukkitUtil.adapt(event.getPlayer()); pp.unregister(); - PlotListener.logout(pp.getUUID()); + this.logout(pp.getUUID()); } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onBucketFill(PlayerBucketFillEvent event) { + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onBucketFill(PlayerBucketFillEvent event) { Block blockClicked = event.getBlockClicked(); - Location location = BukkitUtil.getLocation(blockClicked.getLocation()); + Location location = BukkitUtil.adapt(blockClicked.getLocation()); PlotArea area = location.getPlotArea(); if (area == null) { return; } Player player = event.getPlayer(); - BukkitPlayer plotPlayer = BukkitUtil.getPlayer(player); + BukkitPlayer plotPlayer = BukkitUtil.adapt(player); Plot plot = area.getPlot(location); if (plot == null) { if (Permissions.hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_BUILD_ROAD)) { return; } - MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT, - Captions.PERMISSION_ADMIN_BUILD_ROAD); + MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_BUILD_ROAD); event.setCancelled(true); } else if (!plot.hasOwner()) { if (Permissions.hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_BUILD_UNOWNED)) { return; } - MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT, - Captions.PERMISSION_ADMIN_BUILD_UNOWNED); + MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_BUILD_UNOWNED); event.setCancelled(true); } else if (!plot.isAdded(plotPlayer.getUUID())) { List use = plot.getFlag(UseFlag.class); @@ -1152,45 +1125,39 @@ public class PlayerEventListener extends PlotListener implements Listener { if (Permissions.hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_BUILD_OTHER)) { return; } - MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT, - Captions.PERMISSION_ADMIN_BUILD_OTHER); + MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_BUILD_OTHER); event.setCancelled(true); } else if (Settings.Done.RESTRICT_BUILDING && DoneFlag.isDone(plot)) { if (!Permissions.hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_BUILD_OTHER)) { - MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT, - Captions.PERMISSION_ADMIN_BUILD_OTHER); + MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_BUILD_OTHER); event.setCancelled(true); } } } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onHangingPlace(HangingPlaceEvent event) { + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onHangingPlace(HangingPlaceEvent event) { Block block = event.getBlock().getRelative(event.getBlockFace()); - Location location = BukkitUtil.getLocation(block.getLocation()); + Location location = BukkitUtil.adapt(block.getLocation()); PlotArea area = location.getPlotArea(); if (area == null) { return; } Player p = event.getPlayer(); if (p == null) { - PlotSquared.debug("PlotSquared does not support HangingPlaceEvent for non-players."); event.setCancelled(true); return; } - BukkitPlayer pp = BukkitUtil.getPlayer(p); + BukkitPlayer pp = BukkitUtil.adapt(p); Plot plot = area.getPlot(location); if (plot == null) { if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_ROAD)) { - MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, - Captions.PERMISSION_ADMIN_BUILD_ROAD); + MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_BUILD_ROAD); event.setCancelled(true); } } else { if (!plot.hasOwner()) { if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_UNOWNED)) { - MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, - Captions.PERMISSION_ADMIN_BUILD_UNOWNED); + MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_BUILD_UNOWNED); event.setCancelled(true); } return; @@ -1198,8 +1165,7 @@ public class PlayerEventListener extends PlotListener implements Listener { if (!plot.isAdded(pp.getUUID())) { if (!plot.getFlag(HangingPlaceFlag.class)) { if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_OTHER)) { - MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, - Captions.PERMISSION_ADMIN_BUILD_OTHER); + MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_BUILD_OTHER); event.setCancelled(true); } return; @@ -1212,28 +1178,25 @@ public class PlayerEventListener extends PlotListener implements Listener { } } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onHangingBreakByEntity(HangingBreakByEntityEvent event) { + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onHangingBreakByEntity(HangingBreakByEntityEvent event) { Entity remover = event.getRemover(); if (remover instanceof Player) { Player p = (Player) remover; - Location location = BukkitUtil.getLocation(event.getEntity()); + Location location = BukkitUtil.adapt(event.getEntity().getLocation()); PlotArea area = location.getPlotArea(); if (area == null) { return; } - BukkitPlayer pp = BukkitUtil.getPlayer(p); + BukkitPlayer pp = BukkitUtil.adapt(p); Plot plot = area.getPlot(location); if (plot == null) { if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_DESTROY_ROAD)) { - MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, - Captions.PERMISSION_ADMIN_DESTROY_ROAD); + MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_DESTROY_ROAD); event.setCancelled(true); } } else if (!plot.hasOwner()) { if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_DESTROY_UNOWNED)) { - MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, - Captions.PERMISSION_ADMIN_DESTROY_UNOWNED); + MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_DESTROY_UNOWNED); event.setCancelled(true); } } else if (!plot.isAdded(pp.getUUID())) { @@ -1241,41 +1204,34 @@ public class PlayerEventListener extends PlotListener implements Listener { return; } if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_DESTROY_OTHER)) { - MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, - Captions.PERMISSION_ADMIN_DESTROY_OTHER); + MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_DESTROY_OTHER); event.setCancelled(true); - plot.debug(p.getName() - + " could not break hanging entity because hanging-break = false"); + plot.debug(p.getName() + " could not break hanging entity because hanging-break = false"); } } } else if (remover instanceof Projectile) { Projectile p = (Projectile) remover; if (p.getShooter() instanceof Player) { Player shooter = (Player) p.getShooter(); - Location location = BukkitUtil.getLocation(event.getEntity()); + Location location = BukkitUtil.adapt(event.getEntity().getLocation()); PlotArea area = location.getPlotArea(); if (area == null) { return; } - BukkitPlayer player = BukkitUtil.getPlayer(shooter); - Plot plot = area.getPlot(BukkitUtil.getLocation(event.getEntity())); + BukkitPlayer player = BukkitUtil.adapt(shooter); + Plot plot = area.getPlot(BukkitUtil.adapt(event.getEntity().getLocation())); if (plot != null) { if (!plot.hasOwner()) { - if (!Permissions - .hasPermission(player, Captions.PERMISSION_ADMIN_DESTROY_UNOWNED)) { - MainUtil.sendMessage(player, Captions.NO_PERMISSION_EVENT, - Captions.PERMISSION_ADMIN_DESTROY_UNOWNED); + if (!Permissions.hasPermission(player, Captions.PERMISSION_ADMIN_DESTROY_UNOWNED)) { + MainUtil.sendMessage(player, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_DESTROY_UNOWNED); event.setCancelled(true); } } else if (!plot.isAdded(player.getUUID())) { if (!plot.getFlag(HangingBreakFlag.class)) { - if (!Permissions - .hasPermission(player, Captions.PERMISSION_ADMIN_DESTROY_OTHER)) { - MainUtil.sendMessage(player, Captions.NO_PERMISSION_EVENT, - Captions.PERMISSION_ADMIN_DESTROY_OTHER); + if (!Permissions.hasPermission(player, Captions.PERMISSION_ADMIN_DESTROY_OTHER)) { + MainUtil.sendMessage(player, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_DESTROY_OTHER); event.setCancelled(true); - plot.debug(player.getName() - + " could not break hanging entity because hanging-break = false"); + plot.debug(player.getName() + " could not break hanging entity because hanging-break = false"); } } } @@ -1286,33 +1242,28 @@ public class PlayerEventListener extends PlotListener implements Listener { } } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onPlayerInteractEntity(PlayerInteractEntityEvent event) { - Location location = BukkitUtil.getLocation(event.getRightClicked().getLocation()); + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onPlayerInteractEntity(PlayerInteractEntityEvent event) { + Location location = BukkitUtil.adapt(event.getRightClicked().getLocation()); PlotArea area = location.getPlotArea(); if (area == null) { return; } Player p = event.getPlayer(); - BukkitPlayer pp = BukkitUtil.getPlayer(p); + BukkitPlayer pp = BukkitUtil.adapt(p); Plot plot = area.getPlot(location); 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); + MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_INTERACT_ROAD); event.setCancelled(true); } } 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); + MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_INTERACT_UNOWNED); event.setCancelled(true); } - } else if ((plot != null && !plot.isAdded(pp.getUUID())) || (plot == null && 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()); + final com.sk89q.worldedit.world.entity.EntityType entityType = BukkitAdapter.adapt(entity.getType()); FlagContainer flagContainer; if (plot == null) { @@ -1321,55 +1272,46 @@ public class PlayerEventListener extends PlotListener implements Listener { flagContainer = plot.getFlagContainer(); } - if (EntityCategories.HOSTILE.contains(entityType) && flagContainer - .getFlag(HostileInteractFlag.class).getValue()) { + if (EntityCategories.HOSTILE.contains(entityType) && flagContainer.getFlag(HostileInteractFlag.class).getValue()) { return; } - if (EntityCategories.ANIMAL.contains(entityType) && flagContainer - .getFlag(AnimalInteractFlag.class).getValue()) { + 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() && flagContainer - .getFlag(TamedInteractFlag.class).getValue()) { + if (entity instanceof Tameable && ((Tameable) entity).isTamed() && flagContainer.getFlag(TamedInteractFlag.class).getValue()) { return; } - if (EntityCategories.VEHICLE.contains(entityType) && flagContainer - .getFlag(VehicleUseFlag.class).getValue()) { + if (EntityCategories.VEHICLE.contains(entityType) && flagContainer.getFlag(VehicleUseFlag.class).getValue()) { return; } - if (EntityCategories.PLAYER.contains(entityType) && flagContainer - .getFlag(PlayerInteractFlag.class).getValue()) { + if (EntityCategories.PLAYER.contains(entityType) && flagContainer.getFlag(PlayerInteractFlag.class).getValue()) { return; } - if (EntityCategories.VILLAGER.contains(entityType) && flagContainer - .getFlag(VillagerInteractFlag.class).getValue()) { + if (EntityCategories.VILLAGER.contains(entityType) && flagContainer.getFlag(VillagerInteractFlag.class).getValue()) { return; } - if ((EntityCategories.HANGING.contains(entityType) || EntityCategories.OTHER - .contains(entityType)) && flagContainer.getFlag(MiscInteractFlag.class) - .getValue()) { + if ((EntityCategories.HANGING.contains(entityType) || EntityCategories.OTHER.contains(entityType)) && flagContainer + .getFlag(MiscInteractFlag.class).getValue()) { return; } if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_INTERACT_OTHER)) { - MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, - Captions.PERMISSION_ADMIN_INTERACT_OTHER); + MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_INTERACT_OTHER); event.setCancelled(true); } } } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onVehicleDestroy(VehicleDestroyEvent event) { - Location location = BukkitUtil.getLocation(event.getVehicle()); + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onVehicleDestroy(VehicleDestroyEvent event) { + Location location = BukkitUtil.adapt(event.getVehicle().getLocation()); PlotArea area = location.getPlotArea(); if (area == null) { return; @@ -1377,19 +1319,17 @@ public class PlayerEventListener extends PlotListener implements Listener { Entity attacker = event.getAttacker(); if (attacker instanceof Player) { Player p = (Player) attacker; - BukkitPlayer pp = BukkitUtil.getPlayer(p); + BukkitPlayer pp = BukkitUtil.adapt(p); Plot plot = area.getPlot(location); if (plot == null) { if (!Permissions.hasPermission(pp, "plots.admin.vehicle.break.road")) { - MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, - "plots.admin.vehicle.break.road"); + MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, "plots.admin.vehicle.break.road"); event.setCancelled(true); } } else { if (!plot.hasOwner()) { if (!Permissions.hasPermission(pp, "plots.admin.vehicle.break.unowned")) { - MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, - "plots.admin.vehicle.break.unowned"); + MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, "plots.admin.vehicle.break.unowned"); event.setCancelled(true); return; } @@ -1400,43 +1340,37 @@ public class PlayerEventListener extends PlotListener implements Listener { return; } if (!Permissions.hasPermission(pp, "plots.admin.vehicle.break.other")) { - MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, - "plots.admin.vehicle.break.other"); + MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, "plots.admin.vehicle.break.other"); event.setCancelled(true); - plot.debug(pp.getName() - + " could not break vehicle because vehicle-break = false"); + plot.debug(pp.getName() + " could not break vehicle because vehicle-break = false"); } } } } } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onPlayerEggThrow(PlayerEggThrowEvent event) { - Location location = BukkitUtil.getLocation(event.getEgg().getLocation()); + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onPlayerEggThrow(PlayerEggThrowEvent event) { + Location location = BukkitUtil.adapt(event.getEgg().getLocation()); PlotArea area = location.getPlotArea(); if (area == null) { return; } Player player = event.getPlayer(); - BukkitPlayer plotPlayer = BukkitUtil.getPlayer(player); + BukkitPlayer plotPlayer = BukkitUtil.adapt(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"); + 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"); + 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"); + MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT, "plots.admin.projectile.other"); event.setHatching(false); } } @@ -1444,7 +1378,7 @@ public class PlayerEventListener extends PlotListener implements Listener { @EventHandler public void onItemDrop(PlayerDropItemEvent event) { Player player = event.getPlayer(); - BukkitPlayer pp = BukkitUtil.getPlayer(player); + BukkitPlayer pp = BukkitUtil.adapt(player); Location location = pp.getLocation(); PlotArea area = location.getPlotArea(); if (area == null) { @@ -1470,7 +1404,7 @@ public class PlayerEventListener extends PlotListener implements Listener { LivingEntity ent = event.getEntity(); if (ent instanceof Player) { Player player = (Player) ent; - BukkitPlayer pp = BukkitUtil.getPlayer(player); + BukkitPlayer pp = BukkitUtil.adapt(player); Location location = pp.getLocation(); PlotArea area = location.getPlotArea(); if (area == null) { @@ -1485,15 +1419,14 @@ public class PlayerEventListener extends PlotListener implements Listener { } 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"); + 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()); + Location location = BukkitUtil.adapt(event.getEntity().getLocation()); PlotArea area = location.getPlotArea(); if (area == null) { return; @@ -1507,9 +1440,7 @@ public class PlayerEventListener extends PlotListener implements Listener { } if (plot.getFlag(KeepInventoryFlag.class)) { if (plot.getFlag(KeepInventoryFlag.class)) { - plot.debug(event.getEntity().getName() - + " kept their inventory because of keep-inventory = true"); - event.getDrops().clear(); + plot.debug(event.getEntity().getName() + " kept their inventory because of keep-inventory = true"); event.setKeepInventory(true); } } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ProjectileEventListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ProjectileEventListener.java index a4cfd6171..4a5f78bc3 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ProjectileEventListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ProjectileEventListener.java @@ -27,13 +27,13 @@ package com.plotsquared.bukkit.listener; import com.plotsquared.bukkit.util.BukkitEntityUtil; import com.plotsquared.bukkit.util.BukkitUtil; -import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.location.Location; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.plot.PlotHandler; +import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.util.Permissions; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; @@ -50,14 +50,22 @@ import org.bukkit.event.entity.ProjectileLaunchEvent; import org.bukkit.projectiles.BlockProjectileSource; import org.bukkit.projectiles.ProjectileSource; +import javax.annotation.Nonnull; +import javax.inject.Inject; + @SuppressWarnings("unused") public class ProjectileEventListener implements Listener { - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onPotionSplash(LingeringPotionSplashEvent event) { + private final PlotAreaManager plotAreaManager; + + @Inject public ProjectileEventListener(@Nonnull final PlotAreaManager plotAreaManager) { + this.plotAreaManager = plotAreaManager; + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onPotionSplash(LingeringPotionSplashEvent event) { Projectile entity = event.getEntity(); - Location location = BukkitUtil.getLocation(entity); - if (!PlotSquared.get().hasPlotArea(location.getWorld())) { + Location location = BukkitUtil.adapt(entity.getLocation()); + if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) { return; } if (!this.onProjectileHit(event)) { @@ -65,11 +73,10 @@ public class ProjectileEventListener implements Listener { } } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onPotionSplash(PotionSplashEvent event) { + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onPotionSplash(PotionSplashEvent event) { ThrownPotion damager = event.getPotion(); - Location location = BukkitUtil.getLocation(damager); - if (!PlotSquared.get().hasPlotArea(location.getWorld())) { + Location location = BukkitUtil.adapt(damager.getLocation()); + if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) { return; } int count = 0; @@ -93,11 +100,11 @@ public class ProjectileEventListener implements Listener { if (!(shooter instanceof Player)) { return; } - Location location = BukkitUtil.getLocation(entity); - if (!PlotSquared.get().hasPlotArea(location.getWorld())) { + Location location = BukkitUtil.adapt(entity.getLocation()); + if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) { return; } - PlotPlayer pp = BukkitUtil.getPlayer((Player) shooter); + PlotPlayer pp = BukkitUtil.adapt((Player) shooter); Plot plot = location.getOwnedPlot(); if (plot != null && !plot.isAdded(pp.getUUID())) { entity.remove(); @@ -108,8 +115,8 @@ public class ProjectileEventListener implements Listener { @SuppressWarnings({"BooleanMethodIsAlwaysInverted", "cos it's not... dum IntelliJ"}) @EventHandler public boolean onProjectileHit(ProjectileHitEvent event) { Projectile entity = event.getEntity(); - Location location = BukkitUtil.getLocation(entity); - if (!PlotSquared.get().hasPlotArea(location.getWorld())) { + Location location = BukkitUtil.adapt(entity.getLocation()); + if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) { return true; } PlotArea area = location.getPlotArea(); @@ -119,7 +126,7 @@ public class ProjectileEventListener implements Listener { Plot plot = area.getPlot(location); ProjectileSource shooter = entity.getShooter(); if (shooter instanceof Player) { - PlotPlayer pp = BukkitUtil.getPlayer((Player) shooter); + PlotPlayer pp = BukkitUtil.adapt((Player) shooter); if (plot == null) { if (!Permissions.hasPermission(pp, Captions.PERMISSION_PROJECTILE_UNOWNED)) { entity.remove(); @@ -127,8 +134,7 @@ public class ProjectileEventListener implements Listener { } return true; } - if (plot.isAdded(pp.getUUID()) || Permissions - .hasPermission(pp, Captions.PERMISSION_PROJECTILE_OTHER)) { + if (plot.isAdded(pp.getUUID()) || Permissions.hasPermission(pp, Captions.PERMISSION_PROJECTILE_OTHER)) { return true; } entity.remove(); @@ -139,8 +145,7 @@ public class ProjectileEventListener implements Listener { entity.remove(); return false; } - Location sLoc = - BukkitUtil.getLocation(((BlockProjectileSource) shooter).getBlock().getLocation()); + Location sLoc = BukkitUtil.adapt(((BlockProjectileSource) shooter).getBlock().getLocation()); if (!area.contains(sLoc.getX(), sLoc.getZ())) { entity.remove(); return false; diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/MVdWPlaceholders.java b/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/MVdWPlaceholders.java index 599a1122b..0549d1529 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/MVdWPlaceholders.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/MVdWPlaceholders.java @@ -45,8 +45,7 @@ public class MVdWPlaceholders { private final Plugin plugin; private final PlaceholderRegistry registry; - public MVdWPlaceholders(@NotNull final Plugin plugin, - @NotNull final PlaceholderRegistry registry) { + public MVdWPlaceholders(@NotNull final Plugin plugin, @NotNull final PlaceholderRegistry registry) { this.plugin = plugin; this.registry = registry; for (final Placeholder placeholder : registry.getPlaceholders()) { @@ -55,24 +54,19 @@ public class MVdWPlaceholders { PlotSquared.get().getEventDispatcher().registerListener(this); } - @Subscribe public void onNewPlaceholder(@NotNull final - PlaceholderRegistry.PlaceholderAddedEvent event) { + @Subscribe public void onNewPlaceholder(@NotNull final PlaceholderRegistry.PlaceholderAddedEvent event) { this.addPlaceholder(event.getPlaceholder()); } private void addPlaceholder(@NotNull final Placeholder placeholder) { - PlaceholderAPI.registerPlaceholder(plugin, PREFIX + String.format("%s", placeholder.getKey()), - placeholderReplaceEvent -> { - if (!placeholderReplaceEvent.isOnline() || placeholderReplaceEvent.getPlayer() == null) { - return ""; - } - final PlotPlayer player = BukkitUtil.getPlayer(placeholderReplaceEvent.getPlayer()); - if (player == null) { - return ""; - } - String key = placeholderReplaceEvent.getPlaceholder().substring(PREFIX.length()); - return registry.getPlaceholderValue(key, player); - }); + PlaceholderAPI.registerPlaceholder(plugin, PREFIX + String.format("%s", placeholder.getKey()), placeholderReplaceEvent -> { + if (!placeholderReplaceEvent.isOnline() || placeholderReplaceEvent.getPlayer() == null) { + return ""; + } + final PlotPlayer player = BukkitUtil.adapt(placeholderReplaceEvent.getPlayer()); + String key = placeholderReplaceEvent.getPlaceholder().substring(PREFIX.length()); + return registry.getPlaceholderValue(key, player); + }); } } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/PAPIPlaceholders.java b/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/PAPIPlaceholders.java index 52d30d5ed..9a5ebdb82 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/PAPIPlaceholders.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/PAPIPlaceholders.java @@ -57,7 +57,7 @@ public class PAPIPlaceholders extends PlaceholderExpansion { } @Override public String onPlaceholderRequest(Player p, String identifier) { - final PlotPlayer pl = PlotSquared.imp().getPlayerManager().getPlayerIfExists(p.getUniqueId()); + final PlotPlayer pl = PlotSquared.platform().getPlayerManager().getPlayerIfExists(p.getUniqueId()); if (pl == null) { return ""; diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEntityUtil.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEntityUtil.java index d5ef32ba3..17291eec9 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEntityUtil.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEntityUtil.java @@ -73,8 +73,8 @@ public class BukkitEntityUtil { public static boolean entityDamage(Entity damager, Entity victim, EntityDamageEvent.DamageCause cause) { - Location dloc = BukkitUtil.getLocation(damager); - Location vloc = BukkitUtil.getLocation(victim); + Location dloc = BukkitUtil.adapt(damager.getLocation()); + Location vloc = BukkitUtil.adapt(victim.getLocation()); PlotArea dArea = dloc.getPlotArea(); PlotArea vArea; if (dArea != null && dArea.contains(vloc.getX(), vloc.getZ())) { @@ -152,7 +152,7 @@ public class BukkitEntityUtil { } else { // shooter is not player if (shooter instanceof BlockProjectileSource) { Location sLoc = BukkitUtil - .getLocation(((BlockProjectileSource) shooter).getBlock().getLocation()); + .adapt(((BlockProjectileSource) shooter).getBlock().getLocation()); dplot = dArea.getPlot(sLoc); } player = null; @@ -161,7 +161,7 @@ public class BukkitEntityUtil { player = null; } if (player != null) { - BukkitPlayer plotPlayer = BukkitUtil.getPlayer(player); + BukkitPlayer plotPlayer = BukkitUtil.adapt(player); final com.sk89q.worldedit.world.entity.EntityType entityType; 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 ed483be9d..b0c345adc 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/Plot.java +++ b/Core/src/main/java/com/plotsquared/core/plot/Plot.java @@ -2351,7 +2351,7 @@ public class Plot { * * @return The plot alias */ - @NotNull public String getAlias() { + @Nonnull public String getAlias() { if (this.settings == null) { return ""; } diff --git a/Core/src/main/java/com/plotsquared/core/util/EventDispatcher.java b/Core/src/main/java/com/plotsquared/core/util/EventDispatcher.java index 47ae83d29..eefaec5c4 100644 --- a/Core/src/main/java/com/plotsquared/core/util/EventDispatcher.java +++ b/Core/src/main/java/com/plotsquared/core/util/EventDispatcher.java @@ -104,6 +104,9 @@ public class EventDispatcher { eventBus.unregister(listener); } } + public void callGenericEvent(@Nonnull final Object event) { + eventBus.post(event); + } public void callEvent(@Nonnull final PlotEvent event) { eventBus.post(event); diff --git a/Core/src/main/java/com/plotsquared/core/util/placeholders/PlaceholderRegistry.java b/Core/src/main/java/com/plotsquared/core/util/placeholders/PlaceholderRegistry.java index d18859b2e..11afc948d 100644 --- a/Core/src/main/java/com/plotsquared/core/util/placeholders/PlaceholderRegistry.java +++ b/Core/src/main/java/com/plotsquared/core/util/placeholders/PlaceholderRegistry.java @@ -34,6 +34,7 @@ import com.plotsquared.core.plot.flag.GlobalFlagContainer; import com.plotsquared.core.plot.flag.PlotFlag; import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.MainUtil; +import com.plotsquared.core.util.PlayerManager; import lombok.Getter; import lombok.RequiredArgsConstructor; import org.jetbrains.annotations.NotNull; @@ -70,7 +71,7 @@ public final class PlaceholderRegistry { this.registerPlaceholder(new PlotFlagPlaceholder(flag, true)); this.registerPlaceholder(new PlotFlagPlaceholder(flag, false)); }); - this.createPlaceholder("currentplot_world", player -> player.getLocation().getWorld()); + this.createPlaceholder("currentplot_world", player -> player.getLocation().getWorldName()); this.createPlaceholder("has_plot", player -> player.getPlotCount() > 0 ? "true" : "false"); this.createPlaceholder("allowed_plot_count", player -> Integer.toString(player.getAllowedPlots())); this.createPlaceholder("plot_count", player -> Integer.toString(player.getPlotCount())); @@ -82,7 +83,7 @@ public final class PlaceholderRegistry { } try { - return MainUtil.getName(plotOwner, false); + return PlayerManager.getName(plotOwner, false); } catch (final Exception ignored) {} return "unknown";