Search in sources :

Example 21 with WorldConfiguration

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

the class WorldGuardEntityListener method checkItemFrameProtection.

/**
 * Checks regions and config settings to protect items from being knocked
 * out of item frames.
 * @param attacker attacking entity
 * @param defender item frame being damaged
 * @return true if the event should be cancelled
 */
private boolean checkItemFrameProtection(Entity attacker, ItemFrame defender) {
    World world = defender.getWorld();
    WorldConfiguration wcfg = getWorldConfig(world);
    if (wcfg.useRegions) {
        // bukkit throws this event when a player attempts to remove an item from a frame
        if (!(attacker instanceof Player)) {
            if (!StateFlag.test(WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().queryState(BukkitAdapter.adapt(defender.getLocation()), (RegionAssociable) null, Flags.ENTITY_ITEM_FRAME_DESTROY))) {
                return true;
            }
        }
    }
    if (wcfg.blockEntityItemFrameDestroy && !(attacker instanceof Player)) {
        return true;
    }
    return false;
}
Also used : WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) BukkitWorldConfiguration(com.sk89q.worldguard.bukkit.BukkitWorldConfiguration) Player(org.bukkit.entity.Player) LocalPlayer(com.sk89q.worldguard.LocalPlayer) World(org.bukkit.World)

Example 22 with WorldConfiguration

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

the class WorldGuardPlayerListener method onPlayerInteract.

@EventHandler(priority = EventPriority.HIGH)
public void onPlayerInteract(PlayerInteractEvent event) {
    Player player = event.getPlayer();
    World world = player.getWorld();
    if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
        handleBlockRightClick(event);
    } else if (event.getAction() == Action.PHYSICAL) {
        handlePhysicalInteract(event);
    }
    ConfigurationManager cfg = getConfig();
    WorldConfiguration wcfg = getWorldConfig(world);
    if (wcfg.removeInfiniteStacks && !getPlugin().hasPermission(player, "worldguard.override.infinite-stack")) {
        int slot = player.getInventory().getHeldItemSlot();
        ItemStack heldItem = player.getInventory().getItem(slot);
        if (heldItem != null && heldItem.getAmount() < 0) {
            player.getInventory().setItem(slot, null);
            player.sendMessage(ChatColor.RED + "Infinite stack removed.");
        }
    }
}
Also used : Player(org.bukkit.entity.Player) LocalPlayer(com.sk89q.worldguard.LocalPlayer) WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) World(org.bukkit.World) ItemStack(org.bukkit.inventory.ItemStack) ConfigurationManager(com.sk89q.worldguard.config.ConfigurationManager) EventHandler(org.bukkit.event.EventHandler)

Example 23 with WorldConfiguration

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

the class WorldGuardPlayerListener method onPlayerJoin.

@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
    Player player = event.getPlayer();
    World world = player.getWorld();
    ConfigurationManager cfg = getConfig();
    WorldConfiguration wcfg = getWorldConfig(world);
    if (cfg.activityHaltToggle) {
        player.sendMessage(ChatColor.YELLOW + "Intensive server activity has been HALTED.");
        int removed = 0;
        for (Entity entity : world.getEntities()) {
            if (Entities.isIntensiveEntity(BukkitAdapter.adapt(entity))) {
                entity.remove();
                removed++;
            }
        }
        if (removed > 10) {
            log.info("Halt-Act: " + removed + " entities (>10) auto-removed from " + player.getWorld());
        }
    }
    if (wcfg.fireSpreadDisableToggle) {
        player.sendMessage(ChatColor.YELLOW + "Fire spread is currently globally disabled for this world.");
    }
    Events.fire(new ProcessPlayerEvent(player));
    WorldGuard.getInstance().getExecutorService().submit(() -> WorldGuard.getInstance().getProfileCache().put(new Profile(player.getUniqueId(), player.getName())));
}
Also used : Entity(org.bukkit.entity.Entity) Player(org.bukkit.entity.Player) LocalPlayer(com.sk89q.worldguard.LocalPlayer) WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) ProcessPlayerEvent(com.sk89q.worldguard.bukkit.event.player.ProcessPlayerEvent) World(org.bukkit.World) ConfigurationManager(com.sk89q.worldguard.config.ConfigurationManager) Profile(com.sk89q.worldguard.util.profile.Profile) EventHandler(org.bukkit.event.EventHandler)

Example 24 with WorldConfiguration

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

the class WorldGuardPlayerListener method onItemHeldChange.

@EventHandler(priority = EventPriority.HIGH)
public void onItemHeldChange(PlayerItemHeldEvent event) {
    Player player = event.getPlayer();
    WorldConfiguration wcfg = getWorldConfig(player.getWorld());
    if (wcfg.removeInfiniteStacks && !getPlugin().hasPermission(player, "worldguard.override.infinite-stack")) {
        int newSlot = event.getNewSlot();
        ItemStack heldItem = player.getInventory().getItem(newSlot);
        if (heldItem != null && heldItem.getAmount() < 0) {
            player.getInventory().setItem(newSlot, null);
            player.sendMessage(ChatColor.RED + "Infinite stack removed.");
        }
    }
}
Also used : Player(org.bukkit.entity.Player) LocalPlayer(com.sk89q.worldguard.LocalPlayer) WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Example 25 with WorldConfiguration

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

the class ToggleCommands method stopFire.

@Command(aliases = { "stopfire" }, usage = "[<world>]", desc = "Disables all fire spread temporarily", max = 1)
@CommandPermissions({ "worldguard.fire-toggle.stop" })
public void stopFire(CommandContext args, Actor sender) throws CommandException {
    World world;
    if (args.argsLength() == 0) {
        world = worldGuard.checkPlayer(sender).getWorld();
    } else {
        world = worldGuard.getPlatform().getMatcher().matchWorld(sender, args.getString(0));
    }
    WorldConfiguration wcfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager().get(world);
    if (!wcfg.fireSpreadDisableToggle) {
        worldGuard.getPlatform().broadcastNotification(LabelFormat.wrap("Fire spread has been globally disabled for '" + world.getName() + "' by " + sender.getDisplayName() + "."));
    } else {
        sender.print("Fire spread was already globally disabled.");
    }
    wcfg.fireSpreadDisableToggle = true;
}
Also used : WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) World(com.sk89q.worldedit.world.World) Command(com.sk89q.minecraft.util.commands.Command) CommandPermissions(com.sk89q.minecraft.util.commands.CommandPermissions)

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