Permalink
Browse files

Cleanup usage of BukkitWorldConfiguration

  • Loading branch information...
me4502 committed Dec 26, 2018
1 parent d4d7601 commit 405b210fb5393b634aa50042baf30ab95e4a1c2f
@@ -27,6 +27,7 @@
import com.sk89q.worldguard.bukkit.BukkitWorldConfiguration;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.config.ConfigurationManager;
import com.sk89q.worldguard.config.WorldConfiguration;
import org.bukkit.event.Listener;

/**
@@ -77,8 +78,8 @@ protected ConfigurationManager getConfig() {
* @param world The world to get the configuration for.
* @return The configuration for {@code world}
*/
protected BukkitWorldConfiguration getWorldConfig(World world) {
return (BukkitWorldConfiguration) getConfig().get(world);
protected WorldConfiguration getWorldConfig(World world) {
return getConfig().get(world);
}

/**
@@ -87,7 +88,7 @@ protected BukkitWorldConfiguration getWorldConfig(World world) {
* @param player The player to get the wold from
* @return The {@link BukkitWorldConfiguration} for the player's world
*/
protected BukkitWorldConfiguration getWorldConfig(LocalPlayer player) {
protected WorldConfiguration getWorldConfig(LocalPlayer player) {
return getWorldConfig((World) player.getExtent());
}

@@ -58,7 +58,7 @@ public void onPlaceBlock(final PlaceBlockEvent event) {
final Player player = event.getCause().getFirstPlayer();

if (player != null) {
final BukkitWorldConfiguration wcfg = getWorldConfig(WorldGuardPlugin.inst().wrapPlayer(player));
final BukkitWorldConfiguration wcfg = (BukkitWorldConfiguration) getWorldConfig(WorldGuardPlugin.inst().wrapPlayer(player));

// Early guard
if (!wcfg.signChestProtection) {
@@ -81,7 +81,7 @@ public void onPlaceBlock(final PlaceBlockEvent event) {
public void onBreakBlock(final BreakBlockEvent event) {
final Player player = event.getCause().getFirstPlayer();

final BukkitWorldConfiguration wcfg = getWorldConfig(BukkitAdapter.adapt(event.getWorld()));
final BukkitWorldConfiguration wcfg = (BukkitWorldConfiguration) getWorldConfig(BukkitAdapter.adapt(event.getWorld()));

// Early guard
if (!wcfg.signChestProtection) {
@@ -107,7 +107,7 @@ public void onBreakBlock(final BreakBlockEvent event) {
public void onUseBlock(final UseBlockEvent event) {
final Player player = event.getCause().getFirstPlayer();

final BukkitWorldConfiguration wcfg = getWorldConfig(BukkitAdapter.adapt(event.getWorld()));
final BukkitWorldConfiguration wcfg = (BukkitWorldConfiguration) getWorldConfig(BukkitAdapter.adapt(event.getWorld()));

// Early guard
if (!wcfg.signChestProtection) {
@@ -132,7 +132,7 @@ public void onUseBlock(final UseBlockEvent event) {
@EventHandler(ignoreCancelled = true)
public void onSignChange(SignChangeEvent event) {
Player player = event.getPlayer();
BukkitWorldConfiguration wcfg = getWorldConfig(WorldGuardPlugin.inst().wrapPlayer(player));
BukkitWorldConfiguration wcfg = (BukkitWorldConfiguration) getWorldConfig(WorldGuardPlugin.inst().wrapPlayer(player));

if (wcfg.signChestProtection) {
if (event.getLine(0).equalsIgnoreCase("[Lock]")) {
@@ -47,6 +47,7 @@
import com.sk89q.worldguard.bukkit.util.Entities;
import com.sk89q.worldguard.bukkit.util.Events;
import com.sk89q.worldguard.bukkit.util.Materials;
import com.sk89q.worldguard.config.WorldConfiguration;
import com.sk89q.worldguard.protection.flags.Flags;
import org.bukkit.Bukkit;
import org.bukkit.Effect;
@@ -163,10 +164,6 @@ public void registerEvents() {
getPlugin().getServer().getPluginManager().registerEvents(new SpigotCompatListener(), getPlugin());
} catch (LinkageError ignored) {
}
try {
getPlugin().getServer().getPluginManager().registerEvents(new LingeringPotionListener(), getPlugin());
} catch (NoClassDefFoundError ignored) {
}
}

//-------------------------------------------------------------------------
@@ -463,7 +460,7 @@ public void onPlayerInteract(PlayerInteractEvent event) {
// emit a "use block here" event where the player is
// standing, which is a hack to protect items that don't
// throw events
if (item != null && getWorldConfig(BukkitAdapter.adapt(player.getWorld())).blockUseAtFeet.test(item)) {
if (item != null && ((BukkitWorldConfiguration) getWorldConfig(BukkitAdapter.adapt(player.getWorld()))).blockUseAtFeet.test(item)) {
if (Events.fireAndTestCancel(new UseBlockEvent(event, cause, player.getLocation().getBlock()))) {
event.setCancelled(true);
}
@@ -570,7 +567,7 @@ public void onPlayerBucketFill(PlayerBucketFillEvent event) {

@EventHandler(ignoreCancelled = true)
public void onBlockFromTo(BlockFromToEvent event) {
BukkitWorldConfiguration config = getWorldConfig(BukkitAdapter.adapt(event.getBlock().getWorld()));
WorldConfiguration config = getWorldConfig(BukkitAdapter.adapt(event.getBlock().getWorld()));

// This only applies to regions but nothing else cares about high
// frequency events at the moment
@@ -939,6 +936,23 @@ public void onBlockDispense(BlockDispenseEvent event) {
}
}

@EventHandler(ignoreCancelled = true)
public void onLingeringSplash(LingeringPotionSplashEvent event) {
AreaEffectCloud aec = event.getAreaEffectCloud();
LingeringPotion potion = event.getEntity();
World world = potion.getWorld();
Cause cause = create(event.getEntity());

// Fire item interaction event
Events.fireToCancel(event, new UseItemEvent(event, cause, world, potion.getItem()));

// Fire entity spawn event
if (!event.isCancelled()) {
// radius unfortunately doesn't go through with this, so only a single location is tested
Events.fireToCancel(event, new SpawnEntityEvent(event, cause, aec.getLocation().add(0.5, 0, 0.5), EntityType.AREA_EFFECT_CLOUD));
}
}

/**
* Handle the right click of a block while an item is held.
*
@@ -1027,11 +1041,11 @@ public void onBlockDispense(BlockDispenseEvent event) {
}

private boolean hasInteractBypass(Block block) {
return getWorldConfig(BukkitAdapter.adapt(block.getWorld())).allowAllInteract.test(block);
return ((BukkitWorldConfiguration) getWorldConfig(BukkitAdapter.adapt(block.getWorld()))).allowAllInteract.test(block);
}

private boolean hasInteractBypass(World world, ItemStack item) {
return getWorldConfig(BukkitAdapter.adapt(world)).allowAllInteract.test(item);
return ((BukkitWorldConfiguration) getWorldConfig(BukkitAdapter.adapt(world))).allowAllInteract.test(item);
}

private boolean isBlockModifiedOnClick(Block block, boolean rightClick) {
@@ -1069,23 +1083,4 @@ public void onBlockExplode(BlockExplodeEvent event) {
event.getBlock().getLocation().getWorld(), event.blockList(), Material.AIR));
}
}

public class LingeringPotionListener implements Listener {
@EventHandler(ignoreCancelled = true)
public void onLingeringSplash(LingeringPotionSplashEvent event) {
AreaEffectCloud aec = event.getAreaEffectCloud();
LingeringPotion potion = event.getEntity();
World world = potion.getWorld();
Cause cause = create(event.getEntity());

// Fire item interaction event
Events.fireToCancel(event, new UseItemEvent(event, cause, world, potion.getItem()));

// Fire entity spawn event
if (!event.isCancelled()) {
// radius unfortunately doesn't go through with this, so only a single location is tested
Events.fireToCancel(event, new SpawnEntityEvent(event, cause, aec.getLocation().add(0.5, 0, 0.5), EntityType.AREA_EFFECT_CLOUD));
}
}
}
}
@@ -22,12 +22,11 @@
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.WorldGuard;
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;
import com.sk89q.worldguard.bukkit.util.Entities;
import com.sk89q.worldguard.bukkit.util.Materials;
import com.sk89q.worldguard.config.WorldConfiguration;
import com.sk89q.worldguard.protection.association.RegionAssociable;
import com.sk89q.worldguard.protection.flags.Flags;
import com.sk89q.worldguard.protection.flags.StateFlag;
@@ -77,7 +76,7 @@ public void onBreakBlock(final BreakBlockEvent event) {
com.sk89q.worldedit.world.World weWorld = BukkitAdapter.adapt(event.getWorld());
if (!isRegionSupportEnabled(weWorld)) return; // Region support disabled

BukkitWorldConfiguration config = getWorldConfig(weWorld);
WorldConfiguration config = getWorldConfig(weWorld);
RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery();

Block block;
@@ -23,7 +23,6 @@
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.bukkit.BukkitWorldConfiguration;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.bukkit.cause.Cause;
import com.sk89q.worldguard.bukkit.event.DelegateEvent;
@@ -35,14 +34,15 @@
import com.sk89q.worldguard.bukkit.event.entity.SpawnEntityEvent;
import com.sk89q.worldguard.bukkit.event.entity.UseEntityEvent;
import com.sk89q.worldguard.bukkit.internal.WGMetadata;
import com.sk89q.worldguard.protection.DelayedRegionOverlapAssociation;
import com.sk89q.worldguard.bukkit.protection.events.DisallowedPVPEvent;
import com.sk89q.worldguard.bukkit.util.Entities;
import com.sk89q.worldguard.bukkit.util.Events;
import com.sk89q.worldguard.bukkit.util.InteropUtils;
import com.sk89q.worldguard.bukkit.util.Materials;
import com.sk89q.worldguard.config.WorldConfiguration;
import com.sk89q.worldguard.domains.Association;
import com.sk89q.worldguard.internal.permission.RegionPermissionModel;
import com.sk89q.worldguard.protection.DelayedRegionOverlapAssociation;
import com.sk89q.worldguard.protection.association.Associables;
import com.sk89q.worldguard.protection.association.RegionAssociable;
import com.sk89q.worldguard.protection.flags.Flags;
@@ -136,7 +136,7 @@ private boolean isWhitelisted(Cause cause, World world, boolean pvp) {
} else if (rootCause instanceof Player) {
Player player = (Player) rootCause;
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
BukkitWorldConfiguration config = getWorldConfig(BukkitAdapter.adapt(world));
WorldConfiguration config = getWorldConfig(BukkitAdapter.adapt(world));

if (config.fakePlayerBuildOverride && InteropUtils.isFakePlayer(player)) {
return true;
@@ -26,6 +26,7 @@
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.bukkit.util.Entities;
import com.sk89q.worldguard.config.ConfigurationManager;
import com.sk89q.worldguard.config.WorldConfiguration;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.association.RegionAssociable;
import com.sk89q.worldguard.protection.flags.Flags;
@@ -109,7 +110,7 @@ public void onEntityInteract(EntityInteractEvent event) {
Block block = event.getBlock();

ConfigurationManager cfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager();
BukkitWorldConfiguration wcfg = (BukkitWorldConfiguration) cfg.get(BukkitAdapter.adapt(entity.getWorld()));
WorldConfiguration wcfg = cfg.get(BukkitAdapter.adapt(entity.getWorld()));

if (block.getType() == Material.FARMLAND) {
if (/* entity instanceof Creature && // catch for any entity (not thrown for players) */
@@ -121,8 +122,8 @@ public void onEntityInteract(EntityInteractEvent event) {

@EventHandler(priority = EventPriority.HIGH)
public void onEntityDeath(EntityDeathEvent event) {
BukkitWorldConfiguration wcfg =
(BukkitWorldConfiguration) WorldGuard.getInstance().getPlatform().getGlobalStateManager().get(BukkitAdapter.adapt(event.getEntity().getWorld()));
WorldConfiguration wcfg =
WorldGuard.getInstance().getPlatform().getGlobalStateManager().get(BukkitAdapter.adapt(event.getEntity().getWorld()));

if (event instanceof PlayerDeathEvent && wcfg.disableDeathMessages) {
((PlayerDeathEvent) event).setDeathMessage("");
@@ -134,7 +135,7 @@ private void onEntityDamageByBlock(EntityDamageByBlockEvent event) {
DamageCause type = event.getCause();

ConfigurationManager cfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager();
BukkitWorldConfiguration wcfg = (BukkitWorldConfiguration) cfg.get(BukkitAdapter.adapt(defender.getWorld()));
WorldConfiguration wcfg = cfg.get(BukkitAdapter.adapt(defender.getWorld()));

if (defender instanceof Wolf && ((Wolf) defender).isTamed()) {
if (wcfg.antiWolfDumbness && !(type == DamageCause.VOID)) {
@@ -201,8 +202,8 @@ private void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
Entity attacker = event.getDamager();
Entity defender = event.getEntity();

BukkitWorldConfiguration wcfg =
(BukkitWorldConfiguration) WorldGuard.getInstance().getPlatform().getGlobalStateManager().get(BukkitAdapter.adapt(defender.getWorld()));
WorldConfiguration wcfg =
WorldGuard.getInstance().getPlatform().getGlobalStateManager().get(BukkitAdapter.adapt(defender.getWorld()));

if (defender instanceof ItemFrame) {
if (checkItemFrameProtection(attacker, (ItemFrame) defender)) {
@@ -297,7 +298,7 @@ private void onEntityDamageByProjectile(EntityDamageByEntityEvent event) {
}

ConfigurationManager cfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager();
BukkitWorldConfiguration wcfg = (BukkitWorldConfiguration) cfg.get(BukkitAdapter.adapt(defender.getWorld()));
WorldConfiguration wcfg = cfg.get(BukkitAdapter.adapt(defender.getWorld()));
if (defender instanceof Player) {
Player player = (Player) defender;
LocalPlayer localPlayer = plugin.wrapPlayer(player);
@@ -366,7 +367,7 @@ public void onEntityDamage(EntityDamageEvent event) {
DamageCause type = event.getCause();

ConfigurationManager cfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager();
BukkitWorldConfiguration wcfg = (BukkitWorldConfiguration) cfg.get(BukkitAdapter.adapt(defender.getWorld()));
WorldConfiguration wcfg = cfg.get(BukkitAdapter.adapt(defender.getWorld()));

if (defender instanceof Wolf && ((Wolf) defender).isTamed()) {
if (wcfg.antiWolfDumbness) {
@@ -567,7 +568,7 @@ public void onEntityExplode(EntityExplodeEvent event) {
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onExplosionPrime(ExplosionPrimeEvent event) {
ConfigurationManager cfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager();
BukkitWorldConfiguration wcfg = (BukkitWorldConfiguration) cfg.get(BukkitAdapter.adapt(event.getEntity().getWorld()));
WorldConfiguration wcfg = cfg.get(BukkitAdapter.adapt(event.getEntity().getWorld()));
Entity ent = event.getEntity();

if (cfg.activityHaltToggle) {
@@ -614,7 +615,7 @@ public void onCreatureSpawn(CreatureSpawnEvent event) {
return;
}

BukkitWorldConfiguration wcfg = (BukkitWorldConfiguration) cfg.get(BukkitAdapter.adapt(event.getEntity().getWorld()));
WorldConfiguration wcfg = cfg.get(BukkitAdapter.adapt(event.getEntity().getWorld()));

// allow spawning of creatures from plugins
if (!wcfg.blockPluginSpawning && event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.CUSTOM) {
@@ -670,7 +671,7 @@ public void onCreatureSpawn(CreatureSpawnEvent event) {
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onCreatePortal(EntityCreatePortalEvent event) {
ConfigurationManager cfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager();
BukkitWorldConfiguration wcfg = (BukkitWorldConfiguration) cfg.get(BukkitAdapter.adapt(event.getEntity().getWorld()));
WorldConfiguration wcfg = cfg.get(BukkitAdapter.adapt(event.getEntity().getWorld()));

switch (event.getEntityType()) {
case ENDER_DRAGON:
@@ -682,7 +683,7 @@ public void onCreatePortal(EntityCreatePortalEvent event) {
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPigZap(PigZapEvent event) {
ConfigurationManager cfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager();
BukkitWorldConfiguration wcfg = (BukkitWorldConfiguration) cfg.get(BukkitAdapter.adapt(event.getEntity().getWorld()));
WorldConfiguration wcfg = cfg.get(BukkitAdapter.adapt(event.getEntity().getWorld()));

if (wcfg.disablePigZap) {
event.setCancelled(true);
@@ -692,7 +693,7 @@ public void onPigZap(PigZapEvent event) {
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onCreeperPower(CreeperPowerEvent event) {
ConfigurationManager cfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager();
BukkitWorldConfiguration wcfg = (BukkitWorldConfiguration) cfg.get(BukkitAdapter.adapt(event.getEntity().getWorld()));
WorldConfiguration wcfg = cfg.get(BukkitAdapter.adapt(event.getEntity().getWorld()));

if (wcfg.disableCreeperPower) {
event.setCancelled(true);
@@ -706,7 +707,7 @@ public void onEntityRegainHealth(EntityRegainHealthEvent event) {
World world = ent.getWorld();

ConfigurationManager cfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager();
BukkitWorldConfiguration wcfg = (BukkitWorldConfiguration) cfg.get(BukkitAdapter.adapt(world));
WorldConfiguration wcfg = cfg.get(BukkitAdapter.adapt(world));

if (wcfg.disableHealthRegain) {
event.setCancelled(true);
@@ -726,7 +727,7 @@ public void onEntityChangeBlock(EntityChangeBlockEvent event) {
Location location = block.getLocation();

ConfigurationManager cfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager();
BukkitWorldConfiguration wcfg = (BukkitWorldConfiguration) cfg.get(BukkitAdapter.adapt(ent.getWorld()));
WorldConfiguration wcfg = cfg.get(BukkitAdapter.adapt(ent.getWorld()));
if (ent instanceof Enderman) {
if (wcfg.disableEndermanGriefing) {
event.setCancelled(true);
@@ -768,7 +769,7 @@ public void onEntityChangeBlock(EntityChangeBlockEvent event) {
private boolean checkItemFrameProtection(Entity attacker, ItemFrame defender) {
World world = attacker.getWorld();
ConfigurationManager cfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager();
BukkitWorldConfiguration wcfg = (BukkitWorldConfiguration) cfg.get(BukkitAdapter.adapt(world));
WorldConfiguration wcfg = cfg.get(BukkitAdapter.adapt(world));
if (wcfg.useRegions) {
// bukkit throws this event when a player attempts to remove an item from a frame
if (!(attacker instanceof Player)) {
Oops, something went wrong.

0 comments on commit 405b210

Please sign in to comment.