mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-11-23 02:55:23 +01:00
Minor cleanup of blacklists
This commit is contained in:
parent
863f6cc13b
commit
344c6cf814
@ -1,28 +0,0 @@
|
||||
/*
|
||||
* WorldGuard, a suite of tools for Minecraft
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.blacklist.target;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
/**
|
||||
* Tests a data value.
|
||||
*/
|
||||
public interface DataMask extends Predicate<Short> {
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
/*
|
||||
* WorldGuard, a suite of tools for Minecraft
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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<Short> range;
|
||||
|
||||
public RangeMask(Range<Short> range) {
|
||||
checkNotNull(range);
|
||||
this.range = range;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Short data) {
|
||||
return range.contains(data);
|
||||
}
|
||||
|
||||
}
|
@ -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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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(
|
||||
|
Loading…
Reference in New Issue
Block a user