Search in sources :

Example 26 with WorldConfiguration

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

the class WorldGuardPlayerListener method onPlayerGameModeChange.

@EventHandler
public void onPlayerGameModeChange(PlayerGameModeChangeEvent event) {
    Player player = event.getPlayer();
    LocalPlayer localPlayer = getPlugin().wrapPlayer(player);
    WorldConfiguration wcfg = getWorldConfig(player.getWorld());
    Session session = WorldGuard.getInstance().getPlatform().getSessionManager().getIfPresent(localPlayer);
    if (session != null) {
        GameModeFlag handler = session.getHandler(GameModeFlag.class);
        if (handler != null && wcfg.useRegions && !WorldGuard.getInstance().getPlatform().getSessionManager().hasBypass(localPlayer, localPlayer.getWorld())) {
            GameMode expected = handler.getSetGameMode();
            if (handler.getOriginalGameMode() != null && expected != null && expected != BukkitAdapter.adapt(event.getNewGameMode())) {
                log.info("Game mode change on " + player.getName() + " has been blocked due to the region GAMEMODE flag");
                event.setCancelled(true);
            }
        }
    }
}
Also used : GameMode(com.sk89q.worldedit.world.gamemode.GameMode) Player(org.bukkit.entity.Player) LocalPlayer(com.sk89q.worldguard.LocalPlayer) WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) GameModeFlag(com.sk89q.worldguard.session.handler.GameModeFlag) LocalPlayer(com.sk89q.worldguard.LocalPlayer) Session(com.sk89q.worldguard.session.Session) EventHandler(org.bukkit.event.EventHandler)

Example 27 with WorldConfiguration

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

the class WorldGuardPlayerListener method onPlayerCommandPreprocess.

@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
    Player player = event.getPlayer();
    LocalPlayer localPlayer = getPlugin().wrapPlayer(player);
    ConfigurationManager cfg = getConfig();
    WorldConfiguration wcfg = getWorldConfig(player.getWorld());
    if (wcfg.useRegions && !WorldGuard.getInstance().getPlatform().getSessionManager().hasBypass(localPlayer, localPlayer.getWorld())) {
        ApplicableRegionSet set = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().getApplicableRegions(localPlayer.getLocation());
        Set<String> allowedCommands = set.queryValue(localPlayer, Flags.ALLOWED_CMDS);
        Set<String> blockedCommands = set.queryValue(localPlayer, Flags.BLOCKED_CMDS);
        CommandFilter test = new CommandFilter(allowedCommands, blockedCommands);
        if (!test.apply(event.getMessage())) {
            String message = set.queryValue(localPlayer, Flags.DENY_MESSAGE);
            RegionProtectionListener.formatAndSendDenyMessage("use " + event.getMessage(), localPlayer, message);
            event.setCancelled(true);
            return;
        }
    }
    if (cfg.blockInGameOp) {
        if (opPattern.matcher(event.getMessage()).matches()) {
            player.sendMessage(ChatColor.RED + "/op and /deop can only be used in console (as set by a WG setting).");
            event.setCancelled(true);
            return;
        }
    }
}
Also used : CommandFilter(com.sk89q.worldguard.util.command.CommandFilter) Player(org.bukkit.entity.Player) LocalPlayer(com.sk89q.worldguard.LocalPlayer) WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) LocalPlayer(com.sk89q.worldguard.LocalPlayer) ConfigurationManager(com.sk89q.worldguard.config.ConfigurationManager) ApplicableRegionSet(com.sk89q.worldguard.protection.ApplicableRegionSet) EventHandler(org.bukkit.event.EventHandler)

Example 28 with WorldConfiguration

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

the class WorldGuardPlayerListener method handleBlockRightClick.

/**
 * Called when a player right clicks a block.
 *
 * @param event Thrown event
 */
private void handleBlockRightClick(PlayerInteractEvent event) {
    if (event.useItemInHand() == Event.Result.DENY) {
        return;
    }
    Block block = event.getClickedBlock();
    World world = block.getWorld();
    Material type = block.getType();
    Player player = event.getPlayer();
    @Nullable ItemStack item = event.getItem();
    WorldConfiguration wcfg = getWorldConfig(world);
    // Infinite stack removal
    if (Materials.isInventoryBlock(type) && wcfg.removeInfiniteStacks && !getPlugin().hasPermission(player, "worldguard.override.infinite-stack")) {
        for (int slot = 0; slot < 40; slot++) {
            ItemStack heldItem = player.getInventory().getItem(slot);
            if (heldItem != null && heldItem.getAmount() < 0) {
                player.getInventory().setItem(slot, null);
                player.sendMessage(ChatColor.RED + "Infinite stack in slot #" + slot + " removed.");
            }
        }
    }
    if (wcfg.useRegions) {
        // Block placedIn = block.getRelative(event.getBlockFace());
        ApplicableRegionSet set = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().getApplicableRegions(BukkitAdapter.adapt(block.getLocation()));
        // ApplicableRegionSet placedInSet = plugin.getRegionContainer().createQuery().getApplicableRegions(placedIn.getLocation());
        LocalPlayer localPlayer = getPlugin().wrapPlayer(player);
        if (item != null && item.getType().getKey().toString().equals(wcfg.regionWand) && getPlugin().hasPermission(player, "worldguard.region.wand")) {
            if (set.size() > 0) {
                player.sendMessage(ChatColor.YELLOW + "Can you build? " + (set.testState(localPlayer, Flags.BUILD) ? "Yes" : "No"));
                StringBuilder str = new StringBuilder();
                for (Iterator<ProtectedRegion> it = set.iterator(); it.hasNext(); ) {
                    str.append(it.next().getId());
                    if (it.hasNext()) {
                        str.append(", ");
                    }
                }
                localPlayer.print("Applicable regions: " + str);
            } else {
                localPlayer.print("WorldGuard: No defined regions here!");
            }
            event.setUseItemInHand(Event.Result.DENY);
        }
    }
}
Also used : Player(org.bukkit.entity.Player) LocalPlayer(com.sk89q.worldguard.LocalPlayer) LocalPlayer(com.sk89q.worldguard.LocalPlayer) Material(org.bukkit.Material) World(org.bukkit.World) WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) Block(org.bukkit.block.Block) ItemStack(org.bukkit.inventory.ItemStack) Nullable(javax.annotation.Nullable) ApplicableRegionSet(com.sk89q.worldguard.protection.ApplicableRegionSet)

Example 29 with WorldConfiguration

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

the class WorldGuardPlayerListener method onPlayerChat.

@EventHandler(ignoreCancelled = true)
public void onPlayerChat(AsyncPlayerChatEvent event) {
    Player player = event.getPlayer();
    LocalPlayer localPlayer = getPlugin().wrapPlayer(player);
    WorldConfiguration wcfg = getWorldConfig(player.getWorld());
    if (wcfg.useRegions) {
        RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery();
        ApplicableRegionSet chatFrom = query.getApplicableRegions(localPlayer.getLocation());
        if (!chatFrom.testState(localPlayer, Flags.SEND_CHAT)) {
            String message = chatFrom.queryValue(localPlayer, Flags.DENY_MESSAGE);
            RegionProtectionListener.formatAndSendDenyMessage("chat", localPlayer, message);
            event.setCancelled(true);
            return;
        }
        boolean anyRemoved = false;
        for (Iterator<Player> i = event.getRecipients().iterator(); i.hasNext(); ) {
            Player rPlayer = i.next();
            LocalPlayer rLocal = getPlugin().wrapPlayer(rPlayer);
            if (!query.testState(rLocal.getLocation(), rLocal, Flags.RECEIVE_CHAT)) {
                i.remove();
                anyRemoved = true;
            }
        }
        if (anyRemoved && event.getRecipients().isEmpty() && wcfg.regionCancelEmptyChatEvents) {
            event.setCancelled(true);
        }
    }
}
Also used : Player(org.bukkit.entity.Player) LocalPlayer(com.sk89q.worldguard.LocalPlayer) WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) LocalPlayer(com.sk89q.worldguard.LocalPlayer) RegionQuery(com.sk89q.worldguard.protection.regions.RegionQuery) ApplicableRegionSet(com.sk89q.worldguard.protection.ApplicableRegionSet) EventHandler(org.bukkit.event.EventHandler)

Example 30 with WorldConfiguration

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

the class WorldGuardWeatherListener method onLightningStrike.

@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onLightningStrike(LightningStrikeEvent event) {
    WorldConfiguration wcfg = getWorldConfig(event.getWorld());
    if (!wcfg.disallowedLightningBlocks.isEmpty()) {
        final Block target = event.getLightning().getLocation().getBlock();
        Material targetId = target.getType();
        if (targetId == Material.AIR) {
            targetId = target.getRelative(BlockFace.DOWN).getType();
        }
        if (wcfg.disallowedLightningBlocks.contains(BukkitAdapter.asBlockType(targetId).getId())) {
            event.setCancelled(true);
        }
    }
    Location loc = event.getLightning().getLocation();
    if (wcfg.useRegions) {
        if (!StateFlag.test(WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().queryState(BukkitAdapter.adapt(loc), (RegionAssociable) null, Flags.LIGHTNING))) {
            event.setCancelled(true);
        }
    }
}
Also used : WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) Block(org.bukkit.block.Block) Material(org.bukkit.Material) Location(org.bukkit.Location) 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