Fixed loaders can be moved with pistons

This commit is contained in:
OmerBenGera 2021-08-31 20:43:52 +03:00
parent 17f8e72b2a
commit 96856729a7
1 changed files with 26 additions and 0 deletions

View File

@ -14,6 +14,8 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPistonRetractEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.player.PlayerInteractEvent;
@ -89,6 +91,30 @@ public final class BlocksListener implements Listener {
e.setCancelled(true);
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onLoaderPistonRetract(BlockPistonRetractEvent e) {
try {
for (Block block : e.getBlocks()) {
if(plugin.getLoaders().getChunkLoader(block.getLocation()).isPresent()) {
e.setCancelled(true);
return;
}
}
} catch (Throwable ignored) {}
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onLoaderPistonExtend(BlockPistonExtendEvent e) {
try {
for (Block block : e.getBlocks()) {
if(plugin.getLoaders().getChunkLoader(block.getLocation()).isPresent()) {
e.setCancelled(true);
return;
}
}
} catch (Throwable ignored) {}
}
private boolean handleLoaderBreak(Block block, boolean dropItem){
Location blockLoc = block.getLocation();
Optional<ChunkLoader> optionalChunkLoader = plugin.getLoaders().getChunkLoader(blockLoc);