From 2119dfe015993fea1c02c9618fd8ddcaa1602b85 Mon Sep 17 00:00:00 2001 From: Redempt Date: Sat, 23 May 2020 21:34:27 -0400 Subject: [PATCH] Added USE_BUCKET protection type --- .../redlib/region/ProtectionPolicy.java | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/redempt/redlib/region/ProtectionPolicy.java b/src/redempt/redlib/region/ProtectionPolicy.java index 39fee82..e40ed16 100644 --- a/src/redempt/redlib/region/ProtectionPolicy.java +++ b/src/redempt/redlib/region/ProtectionPolicy.java @@ -24,6 +24,8 @@ import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; import org.bukkit.event.entity.EntityChangeBlockEvent; import org.bukkit.event.entity.EntityExplodeEvent; +import org.bukkit.event.player.PlayerBucketEmptyEvent; +import org.bukkit.event.player.PlayerBucketFillEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.InventoryHolder; @@ -185,6 +187,26 @@ public void onInteract(PlayerInteractEvent e) { } } + @EventHandler + public void onBucketEmpty(PlayerBucketEmptyEvent e) { + if (protections.contains(ProtectionType.USE_BUCKETS) + && protectionCheck.test(e.getBlockClicked()) + && !canBypass(e.getPlayer(), ProtectionType.USE_BUCKETS, e.getBlockClicked())) { + e.setCancelled(true); + sendMessage(e.getPlayer(), ProtectionType.USE_BUCKETS); + } + } + + @EventHandler + public void onBucketFill(PlayerBucketFillEvent e) { + if (protections.contains(ProtectionType.USE_BUCKETS) + && protectionCheck.test(e.getBlockClicked()) + && !canBypass(e.getPlayer(), ProtectionType.USE_BUCKETS, e.getBlockClicked())) { + e.setCancelled(true); + sendMessage(e.getPlayer(), ProtectionType.USE_BUCKETS); + } + } + @EventHandler(priority = EventPriority.HIGHEST) public void onEntityExplode(EntityExplodeEvent e) { if (protections.contains(ProtectionType.ENTITY_EXPLOSION)) { @@ -292,6 +314,10 @@ public static enum ProtectionType { * Players interacting with non-container blocks */ INTERACT, + /** + * Players using buckets to place or collect liquids + */ + USE_BUCKETS, /** * Players opening containers */ @@ -344,7 +370,7 @@ public static enum ProtectionType { /** * All protection types relating to actions taken directly by players - Breaking, placing, and interacting with blocks */ - public static final ProtectionType[] DIRECT_PLAYERS = {BREAK_BLOCK, PLACE_BLOCK, INTERACT, CONTAINER_ACCESS}; + public static final ProtectionType[] DIRECT_PLAYERS = {BREAK_BLOCK, PLACE_BLOCK, INTERACT, CONTAINER_ACCESS, USE_BUCKETS}; /** * All protection types relating to actions usually taken by players which indirectly affect blocks - Pistons, redstone, explosions, and falling blocks */