From a5ea5115f95657d940b43dd83cdf5b81caaeabb1 Mon Sep 17 00:00:00 2001 From: Joo200 Date: Wed, 26 Jun 2024 22:30:33 +0200 Subject: [PATCH] Fix UseBlockFlag for multiple uses at the same time, add windburst-flag --- .../com/sk89q/worldguard/bukkit/BukkitUtil.java | 17 ----------------- .../bukkit/listener/BlacklistListener.java | 6 +++--- .../listener/BuildPermissionListener.java | 10 ++++++---- .../listener/EventAbstractionListener.java | 15 ++++----------- .../listener/RegionProtectionListener.java | 4 ++-- .../listener/WorldGuardEntityListener.java | 11 ----------- .../sk89q/worldguard/bukkit/util/Materials.java | 2 +- 7 files changed, 16 insertions(+), 49 deletions(-) diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/BukkitUtil.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/BukkitUtil.java index c290b7cf..2d43d208 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/BukkitUtil.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/BukkitUtil.java @@ -55,23 +55,6 @@ public static int getPotionEffectBits(ItemStack item) { return item.getDurability() & 0x3F; } - /** - * Get a blacklist target for the given block. - * - * @param block the block - * @param effectiveMaterial The effective material, if different - * @return a target - */ - public static Target createTarget(Block block, Material effectiveMaterial) { - checkNotNull(block); - checkNotNull(block.getType()); - if (block.getType() == effectiveMaterial) { - return createTarget(block.getType()); - } else { - return createTarget(effectiveMaterial); - } - } - /** * Get a blacklist target for the given block. * diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/BlacklistListener.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/BlacklistListener.java index bfb569f5..3b907717 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/BlacklistListener.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/BlacklistListener.java @@ -96,7 +96,7 @@ public void onBreakBlock(final BreakBlockEvent event) { event.filter(target -> { if (!wcfg.getBlacklist().check( new BlockBreakBlacklistEvent(localPlayer, BukkitAdapter.asBlockVector(target), - createTarget(target.getBlock(), event.getEffectiveMaterial())), false, false)) { + createTarget(target.getBlock())), false, false)) { return false; } else if (!wcfg.getBlacklist().check( new ItemDestroyWithBlacklistEvent(localPlayer, BukkitAdapter.asBlockVector(target), @@ -124,7 +124,7 @@ public void onPlaceBlock(final PlaceBlockEvent event) { final LocalPlayer localPlayer = getPlugin().wrapPlayer(player); event.filter(target -> wcfg.getBlacklist().check(new BlockPlaceBlacklistEvent( - localPlayer, BukkitAdapter.asBlockVector(target), createTarget(target.getBlock(), event.getEffectiveMaterial())), false, false)); + localPlayer, BukkitAdapter.asBlockVector(target), createTarget(target.getBlock())), false, false)); } @EventHandler(ignoreCancelled = true) @@ -143,7 +143,7 @@ public void onUseBlock(final UseBlockEvent event) { final LocalPlayer localPlayer = getPlugin().wrapPlayer(player); event.filter(target -> wcfg.getBlacklist().check(new BlockInteractBlacklistEvent( - localPlayer, BukkitAdapter.asBlockVector(target), createTarget(target.getBlock(), event.getEffectiveMaterial())), false, false)); + localPlayer, BukkitAdapter.asBlockVector(target), createTarget(target.getBlock())), false, false)); } @EventHandler(ignoreCancelled = true) diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/BuildPermissionListener.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/BuildPermissionListener.java index 2ad78b4b..7958b685 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/BuildPermissionListener.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/BuildPermissionListener.java @@ -101,12 +101,14 @@ public void onUseBlock(final UseBlockEvent event) { if (rootCause instanceof Player) { final Player player = (Player) rootCause; - final Material material = event.getEffectiveMaterial(); - if (!hasBuildPermission(player, "block." + material.name().toLowerCase() + ".interact") - && !hasBuildPermission(player, "block.interact." + material.name().toLowerCase())) { + boolean blocked = event.filter(loc -> { + String blacklistName = loc.getBlock().getType().name().toLowerCase(); + return hasBuildPermission(player, "block." + blacklistName + ".interact") || + hasBuildPermission(player, "block.interact." + blacklistName); + }, true); + if (blocked && !event.isSilent()) { tellErrorMessage(player, event.getWorld()); - event.setCancelled(true); } } } diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java index 64e7a728..14c49c2a 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java @@ -152,7 +152,6 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import java.util.stream.Collectors; @@ -360,16 +359,10 @@ public void onEntityChangeBlock(EntityChangeBlockEvent event) { public void onEntityExplode(EntityExplodeEvent event) { Entity entity = event.getEntity(); if (entity instanceof AbstractWindCharge) { - Iterator it = event.blockList().iterator(); - while (it.hasNext()) { - Block block = it.next(); - UseBlockEvent useEvent = new UseBlockEvent(event, create(entity), block); - useEvent.setSilent(true); - Bukkit.getServer().getPluginManager().callEvent(useEvent); - if (useEvent.isCancelled()) { - it.remove(); - } - } + UseBlockEvent useEvent = new UseBlockEvent(event, create(entity), event.getLocation().getWorld(), event.blockList(), Material.AIR); + useEvent.getRelevantFlags().add(Flags.WIND_CHARGE_BURST); + useEvent.setSilent(true); + Events.fireBulkEventToCancel(event, useEvent); return; } Events.fireBulkEventToCancel(event, new BreakBlockEvent(event, create(entity), event.getLocation().getWorld(), event.blockList(), Material.AIR)); diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/RegionProtectionListener.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/RegionProtectionListener.java index e562a3be..4a86df3f 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/RegionProtectionListener.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/RegionProtectionListener.java @@ -244,13 +244,13 @@ public void onUseBlock(final UseBlockEvent event) { if (!isRegionSupportEnabled(event.getWorld())) return; // Region support disabled if (isWhitelisted(event.getCause(), event.getWorld(), false)) return; // Whitelisted cause - final Material type = event.getEffectiveMaterial(); final RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery(); final RegionAssociable associable = createRegionAssociable(event.getCause()); event.filter((Predicate) target -> { boolean canUse; String what; + final Material type = target.getBlock().getType(); /* Saplings, etc. */ if (Materials.isConsideredBuildingIfUsed(type)) { @@ -278,7 +278,7 @@ public void onUseBlock(final UseBlockEvent event) { what = "sleep"; /* Respawn Anchors */ - } else if(type == Material.RESPAWN_ANCHOR) { + } else if(target.getBlock().getType() == Material.RESPAWN_ANCHOR) { canUse = query.testBuild(BukkitAdapter.adapt(target), associable, combine(event, Flags.INTERACT, Flags.RESPAWN_ANCHORS)); what = "use anchors"; diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardEntityListener.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardEntityListener.java index b04d56b4..7ea3bf47 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardEntityListener.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardEntityListener.java @@ -44,7 +44,6 @@ import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.BlockState; -import org.bukkit.entity.AbstractWindCharge; import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Creeper; import org.bukkit.entity.EnderCrystal; @@ -523,16 +522,6 @@ public void onEntityExplode(EntityExplodeEvent event) { } } } - } else if (ent instanceof AbstractWindCharge) { - if (wcfg.useRegions) { - for (Block block : event.blockList()) { - if (!WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().getApplicableRegions(BukkitAdapter.adapt(block.getLocation())).testState(null, Flags.WIND_CHARGE_BURST)) { - event.blockList().clear(); - event.setCancelled(true); - return; - } - } - } } else { // unhandled entity if (wcfg.blockOtherExplosions) { diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java index cc0540ae..787f7836 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java @@ -835,7 +835,6 @@ private static void putMaterialTag(Tag tag, Integer value) { MATERIAL_FLAGS.put(Material.ARMADILLO_SCUTE, 0); MATERIAL_FLAGS.put(Material.WOLF_ARMOR, 0); - MATERIAL_FLAGS.put(Material.WIND_CHARGE, 0); // 1.21 MATERIAL_FLAGS.put(Material.CHISELED_TUFF, 0); @@ -876,6 +875,7 @@ private static void putMaterialTag(Tag tag, Integer value) { MATERIAL_FLAGS.put(Material.VAULT, 0); MATERIAL_FLAGS.put(Material.OMINOUS_BOTTLE, 0); MATERIAL_FLAGS.put(Material.BREEZE_ROD, 0); + MATERIAL_FLAGS.put(Material.WIND_CHARGE, 0); putMaterialTag(Tag.SHULKER_BOXES, MODIFIED_ON_RIGHT); putMaterialTag(Tag.ITEMS_BOATS, 0);