mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 13:16:45 +01:00
Improve piston interaction with plot border
Fixes retracting pistons being able to modify plot borders. Prevents piston heads from sticking outside plots.
This commit is contained in:
parent
89cb6450fb
commit
4576cfd961
@ -230,7 +230,6 @@ public class PlayerEvents extends PlotListener implements Listener {
|
|||||||
public static final com.sk89q.worldedit.world.entity.EntityType FAKE_ENTITY_TYPE =
|
public static final com.sk89q.worldedit.world.entity.EntityType FAKE_ENTITY_TYPE =
|
||||||
new com.sk89q.worldedit.world.entity.EntityType("plotsquared:fake");
|
new com.sk89q.worldedit.world.entity.EntityType("plotsquared:fake");
|
||||||
|
|
||||||
private boolean pistonBlocks = true;
|
|
||||||
private float lastRadius;
|
private float lastRadius;
|
||||||
// To prevent recursion
|
// To prevent recursion
|
||||||
private boolean tmpTeleport = true;
|
private boolean tmpTeleport = true;
|
||||||
@ -1539,35 +1538,28 @@ public class PlayerEvents extends PlotListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!plot.equals(area.getOwnedPlot(location.add(
|
||||||
|
relative.getBlockX(), relative.getBlockY(), relative.getBlockZ())))) {
|
||||||
|
// This branch is only necessary to prevent pistons from extending
|
||||||
|
// if they are: on a plot edge, facing outside the plot, and not
|
||||||
|
// pushing any blocks
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onBlockPistonRetract(BlockPistonRetractEvent event) {
|
public void onBlockPistonRetract(BlockPistonRetractEvent event) {
|
||||||
Block block = event.getBlock();
|
Block block = event.getBlock();
|
||||||
Location location = BukkitUtil.getLocation(block.getLocation());
|
Location location = BukkitUtil.getLocation(block.getLocation());
|
||||||
|
BlockFace face = event.getDirection();
|
||||||
|
Vector relative = new Vector(face.getModX(), face.getModY(), face.getModZ());
|
||||||
PlotArea area = location.getPlotArea();
|
PlotArea area = location.getPlotArea();
|
||||||
if (area == null) {
|
if (area == null) {
|
||||||
if (!PlotSquared.get().hasPlotArea(location.getWorld())) {
|
if (!PlotSquared.get().hasPlotArea(location.getWorld())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this.pistonBlocks) {
|
for (Block block1 : event.getBlocks()) {
|
||||||
try {
|
if (BukkitUtil.getLocation(block1.getLocation().add(relative)).isPlotArea()) {
|
||||||
for (Block pulled : event.getBlocks()) {
|
|
||||||
location = BukkitUtil.getLocation(pulled.getLocation());
|
|
||||||
if (location.isPlotArea()) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Throwable ignored) {
|
|
||||||
this.pistonBlocks = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!this.pistonBlocks && !block.getType().toString().contains("PISTON")) {
|
|
||||||
BlockFace dir = event.getDirection();
|
|
||||||
location = BukkitUtil.getLocation(block.getLocation()
|
|
||||||
.add(dir.getModX() * 2, dir.getModY() * 2, dir.getModZ() * 2));
|
|
||||||
if (location.isPlotArea()) {
|
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1575,46 +1567,22 @@ public class PlayerEvents extends PlotListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Plot plot = area.getOwnedPlot(location);
|
Plot plot = area.getOwnedPlot(location);
|
||||||
BlockFace dir = event.getDirection();
|
if (plot == null) {
|
||||||
// Location head = location.add(-dir.getModX(), -dir.getModY(), -dir.getModZ());
|
|
||||||
//
|
|
||||||
// if (!Objects.equals(plot, area.getOwnedPlot(head))) {
|
|
||||||
// // FIXME: cancelling the event doesn't work here. See issue #1484
|
|
||||||
// event.setCancelled(true);
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
if (this.pistonBlocks) {
|
|
||||||
try {
|
|
||||||
for (Block pulled : event.getBlocks()) {
|
|
||||||
Location from = BukkitUtil.getLocation(
|
|
||||||
pulled.getLocation().add(dir.getModX(), dir.getModY(), dir.getModZ()));
|
|
||||||
Location to = BukkitUtil.getLocation(pulled.getLocation());
|
|
||||||
if (!area.contains(to.getX(), to.getZ())) {
|
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Plot fromPlot = area.getOwnedPlot(from);
|
for (Block block1 : event.getBlocks()) {
|
||||||
Plot toPlot = area.getOwnedPlot(to);
|
Location bloc = BukkitUtil.getLocation(block1.getLocation());
|
||||||
if (!Objects.equals(fromPlot, toPlot)) {
|
if (!area.contains(bloc.getX(), bloc.getZ()) || !area
|
||||||
|
.contains(bloc.getX() + relative.getBlockX(), bloc.getZ() + relative.getBlockZ())) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
if (!plot.equals(area.getOwnedPlot(bloc)) || !plot.equals(area.getOwnedPlot(
|
||||||
} catch (Throwable ignored) {
|
bloc.add(relative.getBlockX(), relative.getBlockY(), relative.getBlockZ())))) {
|
||||||
this.pistonBlocks = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!this.pistonBlocks && !block.getType().toString().contains("PISTON")) {
|
|
||||||
location = BukkitUtil.getLocation(
|
|
||||||
block.getLocation().add(dir.getModX() * 2, dir.getModY() * 2, dir.getModZ() * 2));
|
|
||||||
if (!area.contains(location)) {
|
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Plot newPlot = area.getOwnedPlot(location);
|
|
||||||
if (!Objects.equals(plot, newPlot)) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user