Fix a few remaining merge issues (+1 squashed commits)

Squashed commits:

[8c6b55dd4] Fix a few remaining merge issues
This commit is contained in:
dordsor21 2020-07-24 17:52:05 +01:00
parent 3180d2ddf2
commit 221d299052
No known key found for this signature in database
GPG Key ID: 1E53E88969FFCF0B
12 changed files with 504 additions and 641 deletions

View File

@ -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 }

View File

@ -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<BlockTypeWrapper> 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<BlockTypeWrapper> 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<org.bukkit.block.BlockState> 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<Block> 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);
}
}

View File

@ -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<Entity> nearby = event.getEntity()
.getNearbyEntities(this.lastRadius, this.lastRadius, this.lastRadius);
List<Entity> 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<Block> 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));
}
}
}

View File

@ -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<MetadataValue> 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());
}

View File

@ -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<Player> pp = BukkitUtil.getPlayer((Player) shooter);
PlotPlayer<Player> 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;

View File

@ -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> 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> player = BukkitUtil.adapt(placeholderReplaceEvent.getPlayer());
String key = placeholderReplaceEvent.getPlaceholder().substring(PREFIX.length());
return registry.getPlaceholderValue(key, player);
});
}
}

View File

@ -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 "";

View File

@ -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;

View File

@ -2351,7 +2351,7 @@ public class Plot {
*
* @return The plot alias
*/
@NotNull public String getAlias() {
@Nonnull public String getAlias() {
if (this.settings == null) {
return "";
}

View File

@ -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);

View File

@ -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";