Skip to content

Commit

Permalink
Minor cleanup of blacklists
Browse files Browse the repository at this point in the history
  • Loading branch information
me4502 committed Dec 21, 2018
1 parent 863f6cc commit 344c6cf
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 84 deletions.

This file was deleted.

This file was deleted.

Expand Up @@ -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.
*
Expand All @@ -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());
}

/**
Expand Down
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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)) {
Expand All @@ -108,15 +108,15 @@ 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) {
return;
}

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)
Expand All @@ -128,15 +128,15 @@ 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) {
return;
}

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)
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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();
Expand All @@ -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()),
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand Down

0 comments on commit 344c6cf

Please sign in to comment.