mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 05:06:44 +01:00
Fix sponge absorbing water across plot borders (#3191)
* Fix sponge absorbing water across plot borders * Shorten for-loops by using removeIf * Use 'Location' instead of 'var' Co-authored-by: NotMyFault <mc.cache@web.de>
This commit is contained in:
parent
e7fa057abe
commit
fd4cec39c4
@ -101,6 +101,7 @@ import org.bukkit.event.block.BlockSpreadEvent;
|
|||||||
import org.bukkit.event.block.CauldronLevelChangeEvent;
|
import org.bukkit.event.block.CauldronLevelChangeEvent;
|
||||||
import org.bukkit.event.block.EntityBlockFormEvent;
|
import org.bukkit.event.block.EntityBlockFormEvent;
|
||||||
import org.bukkit.event.block.LeavesDecayEvent;
|
import org.bukkit.event.block.LeavesDecayEvent;
|
||||||
|
import org.bukkit.event.block.SpongeAbsorbEvent;
|
||||||
import org.bukkit.event.world.StructureGrowEvent;
|
import org.bukkit.event.world.StructureGrowEvent;
|
||||||
import org.bukkit.material.Directional;
|
import org.bukkit.material.Directional;
|
||||||
import org.bukkit.projectiles.BlockProjectileSource;
|
import org.bukkit.projectiles.BlockProjectileSource;
|
||||||
@ -1183,4 +1184,29 @@ public class BlockEventListener implements Listener {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler(ignoreCancelled = true)
|
||||||
|
public void onSpongeAbsorb(SpongeAbsorbEvent event) {
|
||||||
|
Block sponge = event.getBlock();
|
||||||
|
Location location = BukkitUtil.adapt(sponge.getLocation());
|
||||||
|
PlotArea area = location.getPlotArea();
|
||||||
|
List<org.bukkit.block.BlockState> blocks = event.getBlocks();
|
||||||
|
if (area == null) {
|
||||||
|
blocks.removeIf(block -> BukkitUtil.adapt(block.getLocation()).isPlotArea());
|
||||||
|
} else {
|
||||||
|
Plot origin = area.getOwnedPlot(location);
|
||||||
|
blocks.removeIf(block -> {
|
||||||
|
Location blockLocation = BukkitUtil.adapt(block.getLocation());
|
||||||
|
if (!area.contains(blockLocation.getX(), blockLocation.getZ())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
Plot plot = area.getOwnedPlot(blockLocation);
|
||||||
|
return !Objects.equals(plot, origin);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (blocks.isEmpty()) {
|
||||||
|
// Cancel event so the sponge block doesn't turn into a wet sponge
|
||||||
|
// if no water is being absorbed
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user