Skip to content

Commit

Permalink
fix #243
Browse files Browse the repository at this point in the history
  • Loading branch information
xGinko committed Dec 31, 2024
1 parent 316b180 commit 0100fdd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
import org.bukkit.event.EventPriority;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockDispenseEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.player.PlayerInteractEvent;

import java.util.EnumMap;
import java.util.Map;
Expand Down Expand Up @@ -153,10 +156,18 @@ public void disable() {

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onBlockPlace(BlockPlaceEvent event) {
if (
blockLimits.containsKey(event.getBlock().getType())
&& exceedsPerChunkLimit(event.getBlock().getType(), event.getBlock().getChunk())
) {
if (blockLimits.containsKey(event.getBlock().getType())
&& exceedsPerChunkLimit(event.getBlock().getType(), event.getBlock().getChunk())) {
event.setCancelled(true);
}
}

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onPlayerInteract(PlayerInteractEvent event) {
if (event.getAction().isLeftClick()) return;

if (blockLimits.containsKey(event.getMaterial())
&& exceedsPerChunkLimit(event.getMaterial(), event.getPlayer().getChunk())) {
event.setCancelled(true);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
import org.bukkit.event.EventPriority;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.player.PlayerInteractEvent;

import java.util.EnumMap;
import java.util.Map;
Expand Down Expand Up @@ -154,10 +156,18 @@ public void disable() {

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onBlockPlace(BlockPlaceEvent event) {
if (
blockLimits.containsKey(event.getBlock().getType())
&& exceedsPerChunkLimit(event.getBlock().getType(), event.getBlock().getChunk())
) {
if (blockLimits.containsKey(event.getBlock().getType())
&& exceedsPerChunkLimit(event.getBlock().getType(), event.getBlock().getChunk())) {
event.setCancelled(true);
}
}

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onPlayerInteract(PlayerInteractEvent event) {
if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK) return;

if (blockLimits.containsKey(event.getMaterial())
&& exceedsPerChunkLimit(event.getMaterial(), event.getPlayer().getChunk())) {
event.setCancelled(true);
}
}
Expand Down

0 comments on commit 0100fdd

Please sign in to comment.