Search in sources :

Example 31 with WorldConfiguration

use of com.sk89q.worldguard.config.WorldConfiguration in project WorldGuard by EngineHub.

the class EventAbstractionListener method onInventoryMoveItem.

@EventHandler(ignoreCancelled = true)
public void onInventoryMoveItem(InventoryMoveItemEvent event) {
    InventoryHolder causeHolder;
    if (HAS_SNAPSHOT_INVHOLDER) {
        causeHolder = event.getInitiator().getHolder(false);
    } else {
        causeHolder = event.getInitiator().getHolder();
    }
    WorldConfiguration wcfg = null;
    if (causeHolder instanceof Hopper && (wcfg = getWorldConfig((((Hopper) causeHolder).getWorld()))).ignoreHopperMoveEvents) {
        return;
    } else if (causeHolder instanceof HopperMinecart && (wcfg = getWorldConfig((((HopperMinecart) causeHolder).getWorld()))).ignoreHopperMoveEvents) {
        return;
    }
    Entry entry;
    if ((entry = moveItemDebounce.tryDebounce(event)) != null) {
        InventoryHolder sourceHolder;
        InventoryHolder targetHolder;
        /*if (HAS_SNAPSHOT_INVHOLDER) {
                sourceHolder = event.getSource().getHolder(false);
                targetHolder = event.getDestination().getHolder(false);
            } else {*/
        sourceHolder = event.getSource().getHolder();
        targetHolder = event.getDestination().getHolder();
        // }
        Cause cause;
        if (causeHolder instanceof Entity) {
            cause = create(causeHolder);
        } else if (causeHolder instanceof BlockState) {
            cause = create(((BlockState) causeHolder).getBlock());
        } else {
            cause = Cause.unknown();
        }
        if (causeHolder != null && !causeHolder.equals(sourceHolder)) {
            handleInventoryHolderUse(event, cause, sourceHolder);
        }
        handleInventoryHolderUse(event, cause, targetHolder);
        if (event.isCancelled() && causeHolder instanceof Hopper && wcfg.breakDeniedHoppers) {
            Bukkit.getScheduler().scheduleSyncDelayedTask(getPlugin(), () -> ((Hopper) causeHolder).getBlock().breakNaturally());
        } else {
            entry.setCancelled(event.isCancelled());
        }
    }
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) BukkitWorldConfiguration(com.sk89q.worldguard.bukkit.BukkitWorldConfiguration) HopperMinecart(org.bukkit.entity.minecart.HopperMinecart) Entry(com.sk89q.worldguard.bukkit.listener.debounce.legacy.AbstractEventDebounce.Entry) BlockState(org.bukkit.block.BlockState) Cause(com.sk89q.worldguard.bukkit.cause.Cause) Hopper(org.bukkit.block.Hopper) InventoryHolder(org.bukkit.inventory.InventoryHolder) EventHandler(org.bukkit.event.EventHandler)

Example 32 with WorldConfiguration

use of com.sk89q.worldguard.config.WorldConfiguration in project WorldGuard by EngineHub.

the class WorldGuardBlockListener method onBlockFromTo.

/*
     * Called when fluids flow.
     */
@EventHandler(ignoreCancelled = true)
public void onBlockFromTo(BlockFromToEvent event) {
    World world = event.getBlock().getWorld();
    Block blockFrom = event.getBlock();
    Block blockTo = event.getToBlock();
    ConfigurationManager cfg = getConfig();
    if (cfg.activityHaltToggle) {
        event.setCancelled(true);
        return;
    }
    Material fromType = blockFrom.getType();
    boolean isWater = Materials.isWater(fromType);
    boolean isLava = fromType == Material.LAVA;
    boolean isAir = fromType == Material.AIR;
    WorldConfiguration wcfg = getWorldConfig(world);
    if (wcfg.simulateSponge && isWater) {
        int ox = blockTo.getX();
        int oy = blockTo.getY();
        int oz = blockTo.getZ();
        for (int cx = -wcfg.spongeRadius; cx <= wcfg.spongeRadius; cx++) {
            for (int cy = -wcfg.spongeRadius; cy <= wcfg.spongeRadius; cy++) {
                for (int cz = -wcfg.spongeRadius; cz <= wcfg.spongeRadius; cz++) {
                    Block sponge = world.getBlockAt(ox + cx, oy + cy, oz + cz);
                    if (sponge.getType() == Material.SPONGE && (!wcfg.redstoneSponges || !sponge.isBlockIndirectlyPowered())) {
                        event.setCancelled(true);
                        return;
                    }
                }
            }
        }
    }
    // If so and the target block is protected, cancel the event
    if (!wcfg.preventWaterDamage.isEmpty()) {
        Material targetId = blockTo.getType();
        if ((isAir || isWater) && wcfg.preventWaterDamage.contains(BukkitAdapter.asBlockType(targetId).getId())) {
            event.setCancelled(true);
            return;
        }
    }
    if (!wcfg.allowedLavaSpreadOver.isEmpty() && isLava) {
        Material targetId = blockTo.getRelative(0, -1, 0).getType();
        if (!wcfg.allowedLavaSpreadOver.contains(BukkitAdapter.asBlockType(targetId).getId())) {
            event.setCancelled(true);
            return;
        }
    }
    if (wcfg.highFreqFlags && (isWater || blockFrom.getBlockData() instanceof Waterlogged) && WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().queryState(BukkitAdapter.adapt(blockFrom.getLocation()), (RegionAssociable) null, Flags.WATER_FLOW) == StateFlag.State.DENY) {
        event.setCancelled(true);
        return;
    }
    if (wcfg.highFreqFlags && isLava && !StateFlag.test(WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().queryState(BukkitAdapter.adapt(blockFrom.getLocation()), (RegionAssociable) null, Flags.LAVA_FLOW))) {
        event.setCancelled(true);
        return;
    }
}
Also used : RegionAssociable(com.sk89q.worldguard.protection.association.RegionAssociable) BukkitWorldConfiguration(com.sk89q.worldguard.bukkit.BukkitWorldConfiguration) WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) Block(org.bukkit.block.Block) Material(org.bukkit.Material) Waterlogged(org.bukkit.block.data.Waterlogged) World(org.bukkit.World) ConfigurationManager(com.sk89q.worldguard.config.ConfigurationManager) EventHandler(org.bukkit.event.EventHandler)

Example 33 with WorldConfiguration

use of com.sk89q.worldguard.config.WorldConfiguration in project WorldGuard by EngineHub.

the class WorldGuardBlockListener method onBlockPhysics.

/*
     * Called when block physics occurs.
     */
@EventHandler(ignoreCancelled = true)
public void onBlockPhysics(BlockPhysicsEvent event) {
    ConfigurationManager cfg = getConfig();
    if (cfg.activityHaltToggle) {
        event.setCancelled(true);
        return;
    }
    WorldConfiguration wcfg = getWorldConfig(event.getBlock().getWorld());
    final Material id = event.getBlock().getType();
    if (id == Material.GRAVEL && wcfg.noPhysicsGravel) {
        event.setCancelled(true);
        return;
    }
    if ((id == Material.SAND || id == Material.RED_SAND) && wcfg.noPhysicsSand) {
        event.setCancelled(true);
        return;
    }
    if (id == Material.NETHER_PORTAL && wcfg.allowPortalAnywhere) {
        event.setCancelled(true);
        return;
    }
    if (id == Material.LADDER && wcfg.ropeLadders) {
        if (event.getBlock().getRelative(0, 1, 0).getType() == Material.LADDER) {
            event.setCancelled(true);
            return;
        }
    }
}
Also used : BukkitWorldConfiguration(com.sk89q.worldguard.bukkit.BukkitWorldConfiguration) WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) Material(org.bukkit.Material) ConfigurationManager(com.sk89q.worldguard.config.ConfigurationManager) EventHandler(org.bukkit.event.EventHandler)

Example 34 with WorldConfiguration

use of com.sk89q.worldguard.config.WorldConfiguration in project WorldGuard by EngineHub.

the class WorldGuardBlockListener method onBlockPlace.

/*
     * Called when a player places a block.
     */
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onBlockPlace(BlockPlaceEvent event) {
    Block target = event.getBlock();
    World world = target.getWorld();
    WorldConfiguration wcfg = getWorldConfig(world);
    if (wcfg.simulateSponge && target.getType() == Material.SPONGE) {
        if (wcfg.redstoneSponges && target.isBlockIndirectlyPowered()) {
            return;
        }
        int ox = target.getX();
        int oy = target.getY();
        int oz = target.getZ();
        SpongeUtil.clearSpongeWater(BukkitAdapter.adapt(world), ox, oy, oz);
    }
}
Also used : BukkitWorldConfiguration(com.sk89q.worldguard.bukkit.BukkitWorldConfiguration) WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) Block(org.bukkit.block.Block) World(org.bukkit.World) EventHandler(org.bukkit.event.EventHandler)

Example 35 with WorldConfiguration

use of com.sk89q.worldguard.config.WorldConfiguration in project WorldGuard by EngineHub.

the class WorldGuardBlockListener method onBlockBreak.

/*
     * Called when a block is broken.
     */
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) {
    Player player = event.getPlayer();
    WorldConfiguration wcfg = getWorldConfig(player.getWorld());
    if (!wcfg.itemDurability) {
        ItemStack held = player.getInventory().getItemInMainHand();
        ItemMeta meta = held.getItemMeta();
        if (meta != null) {
            ((Damageable) meta).setDamage(0);
            held.setItemMeta(meta);
            player.getInventory().setItemInMainHand(held);
        }
    }
}
Also used : Player(org.bukkit.entity.Player) BukkitWorldConfiguration(com.sk89q.worldguard.bukkit.BukkitWorldConfiguration) WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) Damageable(org.bukkit.inventory.meta.Damageable) ItemStack(org.bukkit.inventory.ItemStack) ItemMeta(org.bukkit.inventory.meta.ItemMeta) EventHandler(org.bukkit.event.EventHandler)

Aggregations

WorldConfiguration (com.sk89q.worldguard.config.WorldConfiguration)59 EventHandler (org.bukkit.event.EventHandler)45 BukkitWorldConfiguration (com.sk89q.worldguard.bukkit.BukkitWorldConfiguration)37 Player (org.bukkit.entity.Player)33 LocalPlayer (com.sk89q.worldguard.LocalPlayer)32 HumanEntity (org.bukkit.entity.HumanEntity)14 ConfigurationManager (com.sk89q.worldguard.config.ConfigurationManager)13 Entity (org.bukkit.entity.Entity)13 ApplicableRegionSet (com.sk89q.worldguard.protection.ApplicableRegionSet)11 Material (org.bukkit.Material)11 World (org.bukkit.World)11 LivingEntity (org.bukkit.entity.LivingEntity)11 Block (org.bukkit.block.Block)10 ItemStack (org.bukkit.inventory.ItemStack)10 World (com.sk89q.worldedit.world.World)4 ItemAcquireBlacklistEvent (com.sk89q.worldguard.blacklist.event.ItemAcquireBlacklistEvent)4 ItemEquipBlacklistEvent (com.sk89q.worldguard.blacklist.event.ItemEquipBlacklistEvent)4 RegionAssociable (com.sk89q.worldguard.protection.association.RegionAssociable)4 RegionQuery (com.sk89q.worldguard.protection.regions.RegionQuery)4 Command (com.sk89q.minecraft.util.commands.Command)3