mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-01-10 02:19:30 +01:00
Prevents liquids from being placed from dispenser outside island area.
Fixes #1869
This commit is contained in:
parent
9643f617b6
commit
9ec8730359
@ -256,6 +256,14 @@ public abstract class FlagListener implements Listener {
|
||||
return plugin.getIslands();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the island database manager
|
||||
* @return the island database manager
|
||||
*/
|
||||
protected IslandsManager getIslandsManager() {
|
||||
return plugin.getIslands();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the island world manager
|
||||
* @return Island World Manager
|
||||
|
@ -2,9 +2,12 @@ package world.bentobox.bentobox.listeners.flags.worldsettings;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.BlockDispenseEvent;
|
||||
import org.bukkit.event.block.BlockFromToEvent;
|
||||
|
||||
import world.bentobox.bentobox.api.flags.FlagListener;
|
||||
@ -43,4 +46,38 @@ public class LiquidsFlowingOutListener extends FlagListener {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Prevents players from dispensing water, lava and powdered snow from dispenser outside island
|
||||
* if Flags.LIQUIDS_FLOWING_OUT is disabled.
|
||||
* @param event BlockDispenseEvent
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public void onDispenserLiquid(BlockDispenseEvent event)
|
||||
{
|
||||
Location from = event.getBlock().getLocation();
|
||||
|
||||
if (!this.getIWM().inWorld(from) || Flags.LIQUIDS_FLOWING_OUT.isSetForWorld(from.getWorld())) {
|
||||
// We do not want to run any check if this is not the right world or if it is allowed.
|
||||
return;
|
||||
}
|
||||
|
||||
Location to = event.getVelocity().toLocation(event.getBlock().getWorld());
|
||||
|
||||
if (!event.getItem().getType().equals(Material.WATER_BUCKET) &&
|
||||
!event.getItem().getType().equals(Material.LAVA_BUCKET) &&
|
||||
!event.getItem().getType().equals(Material.POWDER_SNOW_BUCKET))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Only prevent if it is flowing into the area between islands or into another island.
|
||||
Optional<Island> fromIsland = this.getIslandsManager().getProtectedIslandAt(from);
|
||||
Optional<Island> toIsland = this.getIslandsManager().getProtectedIslandAt(to);
|
||||
|
||||
if (toIsland.isEmpty() || (fromIsland.isPresent() && !fromIsland.equals(toIsland)))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user