From 344c6cf814cf7b10674212a1c0c873d7dce9f2b6 Mon Sep 17 00:00:00 2001 From: Matthew Miller Date: Fri, 21 Dec 2018 22:33:10 +1000 Subject: [PATCH] Minor cleanup of blacklists --- .../worldguard/blacklist/target/DataMask.java | 28 ------------- .../blacklist/target/RangeMask.java | 40 ------------------- .../sk89q/worldguard/bukkit/BukkitUtil.java | 19 ++++++++- .../bukkit/listener/BlacklistListener.java | 30 +++++++------- 4 files changed, 33 insertions(+), 84 deletions(-) delete mode 100644 worldguard-core/src/main/java/com/sk89q/worldguard/blacklist/target/DataMask.java delete mode 100644 worldguard-core/src/main/java/com/sk89q/worldguard/blacklist/target/RangeMask.java diff --git a/worldguard-core/src/main/java/com/sk89q/worldguard/blacklist/target/DataMask.java b/worldguard-core/src/main/java/com/sk89q/worldguard/blacklist/target/DataMask.java deleted file mode 100644 index 132980ad0..000000000 --- a/worldguard-core/src/main/java/com/sk89q/worldguard/blacklist/target/DataMask.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * WorldGuard, a suite of tools for Minecraft - * Copyright (C) sk89q - * Copyright (C) WorldGuard team and contributors - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package com.sk89q.worldguard.blacklist.target; - -import com.google.common.base.Predicate; - -/** - * Tests a data value. - */ -public interface DataMask extends Predicate { -} diff --git a/worldguard-core/src/main/java/com/sk89q/worldguard/blacklist/target/RangeMask.java b/worldguard-core/src/main/java/com/sk89q/worldguard/blacklist/target/RangeMask.java deleted file mode 100644 index 9f75cdd11..000000000 --- a/worldguard-core/src/main/java/com/sk89q/worldguard/blacklist/target/RangeMask.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * WorldGuard, a suite of tools for Minecraft - * Copyright (C) sk89q - * Copyright (C) WorldGuard team and contributors - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package com.sk89q.worldguard.blacklist.target; - -import com.google.common.collect.Range; - -import static com.google.common.base.Preconditions.checkNotNull; - -public class RangeMask implements DataMask { - - private final Range range; - - public RangeMask(Range range) { - checkNotNull(range); - this.range = range; - } - - @Override - public boolean apply(Short data) { - return range.contains(data); - } - -} diff --git a/worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/BukkitUtil.java b/worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/BukkitUtil.java index f003ea4a1..7f9040349 100644 --- a/worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/BukkitUtil.java +++ b/worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/BukkitUtil.java @@ -128,6 +128,23 @@ public static boolean isIntensiveEntity(Entity entity) { && !(entity instanceof ArmorStand)); } + /** + * 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. * @@ -137,7 +154,7 @@ public static boolean isIntensiveEntity(Entity entity) { public static Target createTarget(Block block) { checkNotNull(block); checkNotNull(block.getType()); - return new BlockTarget(BukkitAdapter.asBlockType(block.getType())); + return createTarget(block.getType()); } /** diff --git a/worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/listener/BlacklistListener.java b/worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/listener/BlacklistListener.java index 3b1183008..39a96c906 100644 --- a/worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/listener/BlacklistListener.java +++ b/worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/listener/BlacklistListener.java @@ -32,7 +32,6 @@ import com.sk89q.worldguard.blacklist.event.ItemDestroyWithBlacklistEvent; import com.sk89q.worldguard.blacklist.event.ItemDropBlacklistEvent; import com.sk89q.worldguard.blacklist.event.ItemUseBlacklistEvent; -import com.sk89q.worldguard.bukkit.BukkitWorldConfiguration; import com.sk89q.worldguard.bukkit.WorldGuardPlugin; import com.sk89q.worldguard.bukkit.event.block.BreakBlockEvent; import com.sk89q.worldguard.bukkit.event.block.PlaceBlockEvent; @@ -42,6 +41,7 @@ import com.sk89q.worldguard.bukkit.event.inventory.UseItemEvent; import com.sk89q.worldguard.bukkit.util.Materials; import com.sk89q.worldguard.config.ConfigurationManager; +import com.sk89q.worldguard.config.WorldConfiguration; import org.bukkit.Material; import org.bukkit.entity.Entity; import org.bukkit.entity.HumanEntity; @@ -79,7 +79,7 @@ public void onBreakBlock(final BreakBlockEvent event) { } final LocalPlayer localPlayer = getPlugin().wrapPlayer(player); - final BukkitWorldConfiguration wcfg = getWorldConfig(localPlayer); + final WorldConfiguration wcfg = getWorldConfig(localPlayer); // Blacklist guard if (wcfg.getBlacklist() == null) { @@ -88,7 +88,7 @@ public void onBreakBlock(final BreakBlockEvent event) { event.filter(target -> { if (!wcfg.getBlacklist().check( - new BlockBreakBlacklistEvent(localPlayer, BukkitAdapter.asBlockVector(target), createTarget(target.getBlock())), false, false)) { + new BlockBreakBlacklistEvent(localPlayer, BukkitAdapter.asBlockVector(target), createTarget(target.getBlock(), event.getEffectiveMaterial())), false, false)) { return false; } else if (!wcfg.getBlacklist().check( new ItemDestroyWithBlacklistEvent(localPlayer, BukkitAdapter.asBlockVector(target), createTarget(player.getItemInHand())), false, false)) { @@ -108,7 +108,7 @@ public void onPlaceBlock(final PlaceBlockEvent event) { } final LocalPlayer localPlayer = getPlugin().wrapPlayer(player); - final BukkitWorldConfiguration wcfg = getWorldConfig(localPlayer); + final WorldConfiguration wcfg = getWorldConfig(localPlayer); // Blacklist guard if (wcfg.getBlacklist() == null) { @@ -116,7 +116,7 @@ public void onPlaceBlock(final PlaceBlockEvent event) { } event.filter(target -> wcfg.getBlacklist().check(new BlockPlaceBlacklistEvent( - localPlayer, BukkitAdapter.asBlockVector(target), createTarget(target.getBlock())), false, false)); + localPlayer, BukkitAdapter.asBlockVector(target), createTarget(target.getBlock(), event.getEffectiveMaterial())), false, false)); } @EventHandler(ignoreCancelled = true) @@ -128,7 +128,7 @@ public void onUseBlock(final UseBlockEvent event) { } final LocalPlayer localPlayer = getPlugin().wrapPlayer(player); - final BukkitWorldConfiguration wcfg = getWorldConfig(localPlayer); + final WorldConfiguration wcfg = getWorldConfig(localPlayer); // Blacklist guard if (wcfg.getBlacklist() == null) { @@ -136,7 +136,7 @@ public void onUseBlock(final UseBlockEvent event) { } event.filter(target -> wcfg.getBlacklist().check(new BlockInteractBlacklistEvent( - localPlayer, BukkitAdapter.asBlockVector(target), createTarget(target.getBlock())), false, false)); + localPlayer, BukkitAdapter.asBlockVector(target), createTarget(target.getBlock(), event.getEffectiveMaterial())), false, false)); } @EventHandler(ignoreCancelled = true) @@ -148,7 +148,7 @@ public void onSpawnEntity(SpawnEntityEvent event) { } LocalPlayer localPlayer = getPlugin().wrapPlayer(player); - BukkitWorldConfiguration wcfg = getWorldConfig(localPlayer); + WorldConfiguration wcfg = getWorldConfig(localPlayer); // Blacklist guard if (wcfg.getBlacklist() == null) { @@ -173,7 +173,7 @@ public void onDestroyEntity(DestroyEntityEvent event) { LocalPlayer localPlayer = getPlugin().wrapPlayer(player); Entity target = event.getEntity(); - BukkitWorldConfiguration wcfg = getWorldConfig(localPlayer); + WorldConfiguration wcfg = getWorldConfig(localPlayer); // Blacklist guard if (wcfg.getBlacklist() == null) { @@ -209,7 +209,7 @@ public void onUseItem(UseItemEvent event) { LocalPlayer localPlayer = getPlugin().wrapPlayer(player); ItemStack target = event.getItemStack(); - BukkitWorldConfiguration wcfg = getWorldConfig(localPlayer); + WorldConfiguration wcfg = getWorldConfig(localPlayer); // Blacklist guard if (wcfg.getBlacklist() == null) { @@ -224,7 +224,7 @@ public void onUseItem(UseItemEvent event) { @EventHandler(ignoreCancelled = true) public void onPlayerDropItem(PlayerDropItemEvent event) { ConfigurationManager cfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager(); - BukkitWorldConfiguration wcfg = (BukkitWorldConfiguration) cfg.get(BukkitAdapter.adapt(event.getPlayer().getWorld())); + WorldConfiguration wcfg = cfg.get(BukkitAdapter.adapt(event.getPlayer().getWorld())); if (wcfg.getBlacklist() != null) { Item ci = event.getItemDrop(); @@ -240,7 +240,7 @@ public void onPlayerDropItem(PlayerDropItemEvent event) { @EventHandler(ignoreCancelled = true) public void onBlockDispense(BlockDispenseEvent event) { ConfigurationManager cfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager(); - BukkitWorldConfiguration wcfg = (BukkitWorldConfiguration) cfg.get(BukkitAdapter.adapt(event.getBlock().getWorld())); + WorldConfiguration wcfg = cfg.get(BukkitAdapter.adapt(event.getBlock().getWorld())); if (wcfg.getBlacklist() != null) { if (!wcfg.getBlacklist().check(new BlockDispenseBlacklistEvent(null, BukkitAdapter.asBlockVector(event.getBlock().getLocation()), @@ -259,7 +259,7 @@ public void onInventoryClick(InventoryClickEvent event) { if (item != null && inventory != null && inventory.getHolder() != null && entity instanceof Player) { Player player = (Player) entity; ConfigurationManager cfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager(); - BukkitWorldConfiguration wcfg = (BukkitWorldConfiguration) cfg.get(BukkitAdapter.adapt(entity.getWorld())); + WorldConfiguration wcfg = cfg.get(BukkitAdapter.adapt(entity.getWorld())); LocalPlayer localPlayer = getPlugin().wrapPlayer(player); if (wcfg.getBlacklist() != null && !wcfg.getBlacklist().check( @@ -281,7 +281,7 @@ public void onInventoryCreative(InventoryCreativeEvent event) { if (item != null && entity instanceof Player) { Player player = (Player) entity; ConfigurationManager cfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager(); - BukkitWorldConfiguration wcfg = (BukkitWorldConfiguration) cfg.get(BukkitAdapter.adapt(entity.getWorld())); + WorldConfiguration wcfg = cfg.get(BukkitAdapter.adapt(entity.getWorld())); LocalPlayer localPlayer = getPlugin().wrapPlayer(player); if (wcfg.getBlacklist() != null && !wcfg.getBlacklist().check( @@ -300,7 +300,7 @@ public void onPlayerItemHeld(PlayerItemHeldEvent event) { if (item != null) { ConfigurationManager cfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager(); - BukkitWorldConfiguration wcfg = (BukkitWorldConfiguration) cfg.get(BukkitAdapter.adapt(player.getWorld())); + WorldConfiguration wcfg = cfg.get(BukkitAdapter.adapt(player.getWorld())); LocalPlayer localPlayer = getPlugin().wrapPlayer(player); if (wcfg.getBlacklist() != null && !wcfg.getBlacklist().check(