mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-21 12:46:46 +01:00
Prevent blocks moving/generating below and above build height (#3641)
* fix: cancel BlockFormEvent outside of build limit * refactor: rename variables for easier readability * fix: cancel liquid flow outside build limit * refactor: implement to/from context
This commit is contained in:
parent
ae3b8c06f6
commit
0a32268784
@ -551,6 +551,10 @@ public class BlockEventListener implements Listener {
|
||||
if (plot == null) {
|
||||
return;
|
||||
}
|
||||
if (location.getY() >= area.getMaxBuildHeight() || location.getY() < area.getMinBuildHeight()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
switch (event.getNewState().getType()) {
|
||||
case SNOW:
|
||||
case SNOW_BLOCK:
|
||||
@ -750,62 +754,66 @@ public class BlockEventListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onChange(BlockFromToEvent event) {
|
||||
Block from = event.getBlock();
|
||||
Block fromBlock = event.getBlock();
|
||||
|
||||
// Check liquid flow flag inside of origin plot too
|
||||
final Location fLocation = BukkitUtil.adapt(from.getLocation());
|
||||
final PlotArea fromArea = fLocation.getPlotArea();
|
||||
final Location fromLocation = BukkitUtil.adapt(fromBlock.getLocation());
|
||||
final PlotArea fromArea = fromLocation.getPlotArea();
|
||||
if (fromArea != null) {
|
||||
final Plot plot = fromArea.getOwnedPlot(fLocation);
|
||||
if (plot != null && plot.getFlag(LiquidFlowFlag.class) == LiquidFlowFlag.FlowStatus.DISABLED && event
|
||||
final Plot fromPlot = fromArea.getOwnedPlot(fromLocation);
|
||||
if (fromPlot != null && fromPlot.getFlag(LiquidFlowFlag.class) == LiquidFlowFlag.FlowStatus.DISABLED && event
|
||||
.getBlock()
|
||||
.isLiquid()) {
|
||||
plot.debug("Liquid could not flow because liquid-flow = disabled");
|
||||
fromPlot.debug("Liquid could not flow because liquid-flow = disabled");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Block to = event.getToBlock();
|
||||
Location tLocation = BukkitUtil.adapt(to.getLocation());
|
||||
PlotArea area = tLocation.getPlotArea();
|
||||
if (area == null) {
|
||||
if (from.getType() == Material.DRAGON_EGG && fromArea != null) {
|
||||
Block toBlock = event.getToBlock();
|
||||
Location toLocation = BukkitUtil.adapt(toBlock.getLocation());
|
||||
PlotArea toArea = toLocation.getPlotArea();
|
||||
if (toArea == null) {
|
||||
if (fromBlock.getType() == Material.DRAGON_EGG && fromArea != null) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
Plot plot = area.getOwnedPlot(tLocation);
|
||||
if (toLocation.getY() >= toArea.getMaxBuildHeight() || toLocation.getY() < toArea.getMinBuildHeight()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
Plot toPlot = toArea.getOwnedPlot(toLocation);
|
||||
|
||||
if (from.getType() == Material.DRAGON_EGG && fromArea != null) {
|
||||
final Plot fromPlot = fromArea.getOwnedPlot(fLocation);
|
||||
if (fromBlock.getType() == Material.DRAGON_EGG && fromArea != null) {
|
||||
final Plot fromPlot = fromArea.getOwnedPlot(fromLocation);
|
||||
|
||||
if (fromPlot != null || plot != null) {
|
||||
if ((fromPlot == null || !fromPlot.equals(plot)) && (plot == null || !plot.equals(fromPlot))) {
|
||||
if (fromPlot != null || toPlot != null) {
|
||||
if ((fromPlot == null || !fromPlot.equals(toPlot)) && (toPlot == null || !toPlot.equals(fromPlot))) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (plot != null) {
|
||||
if (!area.contains(fLocation.getX(), fLocation.getZ()) || !Objects.equals(plot, area.getOwnedPlot(fLocation))) {
|
||||
if (toPlot != null) {
|
||||
if (!toArea.contains(fromLocation.getX(), fromLocation.getZ()) || !Objects.equals(toPlot, toArea.getOwnedPlot(fromLocation))) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (plot.getFlag(LiquidFlowFlag.class) == LiquidFlowFlag.FlowStatus.ENABLED && event.getBlock().isLiquid()) {
|
||||
if (toPlot.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");
|
||||
if (toPlot.getFlag(DisablePhysicsFlag.class)) {
|
||||
toPlot.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()) {
|
||||
plot.debug("Liquid could not flow because liquid-flow = disabled");
|
||||
if (toPlot.getFlag(LiquidFlowFlag.class) == LiquidFlowFlag.FlowStatus.DISABLED && event.getBlock().isLiquid()) {
|
||||
toPlot.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 (!toArea.contains(fromLocation.getX(), fromLocation.getZ()) || !Objects.equals(null, toArea.getOwnedPlot(fromLocation))) {
|
||||
event.setCancelled(true);
|
||||
} else if (event.getBlock().isLiquid()) {
|
||||
final org.bukkit.Location location = event.getBlock().getLocation();
|
||||
|
Loading…
Reference in New Issue
Block a user