Search in sources :

Example 46 with WorldConfiguration

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

the class WorldGuardPlayerListener method onPlayerTeleport.

@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPlayerTeleport(PlayerTeleportEvent event) {
    Player player = event.getPlayer();
    LocalPlayer localPlayer = getPlugin().wrapPlayer(player);
    ConfigurationManager cfg = getConfig();
    WorldConfiguration wcfg = getWorldConfig(player.getWorld());
    if (wcfg.useRegions && cfg.usePlayerTeleports) {
        RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery();
        ApplicableRegionSet set = query.getApplicableRegions(BukkitAdapter.adapt(event.getTo()));
        ApplicableRegionSet setFrom = query.getApplicableRegions(BukkitAdapter.adapt(event.getFrom()));
        if (event.getCause() == TeleportCause.ENDER_PEARL) {
            if (!WorldGuard.getInstance().getPlatform().getSessionManager().hasBypass(localPlayer, localPlayer.getWorld())) {
                boolean cancel = false;
                String message = null;
                if (!setFrom.testState(localPlayer, Flags.ENDERPEARL)) {
                    cancel = true;
                    message = setFrom.queryValue(localPlayer, Flags.EXIT_DENY_MESSAGE);
                } else if (!set.testState(localPlayer, Flags.ENDERPEARL)) {
                    cancel = true;
                    message = set.queryValue(localPlayer, Flags.ENTRY_DENY_MESSAGE);
                }
                if (cancel) {
                    if (message != null && !message.isEmpty()) {
                        player.sendMessage(message);
                    }
                    event.setCancelled(true);
                    return;
                }
            }
        } else if (event.getCause() == TeleportCause.CHORUS_FRUIT) {
            if (!WorldGuard.getInstance().getPlatform().getSessionManager().hasBypass(localPlayer, localPlayer.getWorld())) {
                boolean cancel = false;
                String message = null;
                if (!setFrom.testState(localPlayer, Flags.CHORUS_TELEPORT)) {
                    cancel = true;
                    message = setFrom.queryValue(localPlayer, Flags.EXIT_DENY_MESSAGE);
                } else if (!set.testState(localPlayer, Flags.CHORUS_TELEPORT)) {
                    cancel = true;
                    message = set.queryValue(localPlayer, Flags.ENTRY_DENY_MESSAGE);
                }
                if (cancel) {
                    if (message != null && !message.isEmpty()) {
                        player.sendMessage(message);
                    }
                    event.setCancelled(true);
                    return;
                }
            }
        }
        if (null != WorldGuard.getInstance().getPlatform().getSessionManager().get(localPlayer).testMoveTo(localPlayer, BukkitAdapter.adapt(event.getTo()), MoveType.TELEPORT)) {
            event.setCancelled(true);
            return;
        }
    }
}
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) ConfigurationManager(com.sk89q.worldguard.config.ConfigurationManager) ApplicableRegionSet(com.sk89q.worldguard.protection.ApplicableRegionSet) EventHandler(org.bukkit.event.EventHandler)

Example 47 with WorldConfiguration

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

the class WorldGuardPlayerListener method onPlayerRespawn.

@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerRespawn(PlayerRespawnEvent event) {
    Player player = event.getPlayer();
    WorldConfiguration wcfg = getWorldConfig(player.getWorld());
    if (wcfg.useRegions) {
        LocalPlayer localPlayer = getPlugin().wrapPlayer(player);
        ApplicableRegionSet set = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().getApplicableRegions(localPlayer.getLocation());
        com.sk89q.worldedit.util.Location spawn = set.queryValue(localPlayer, Flags.SPAWN_LOC);
        if (spawn != null) {
            event.setRespawnLocation(BukkitAdapter.adapt(spawn));
        }
    }
}
Also used : Player(org.bukkit.entity.Player) LocalPlayer(com.sk89q.worldguard.LocalPlayer) WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) LocalPlayer(com.sk89q.worldguard.LocalPlayer) ApplicableRegionSet(com.sk89q.worldguard.protection.ApplicableRegionSet) EventHandler(org.bukkit.event.EventHandler)

Example 48 with WorldConfiguration

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

the class RegionFlagsListener method onBreakBlock.

@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onBreakBlock(final BreakBlockEvent event) {
    // Region support disabled
    if (!isRegionSupportEnabled(event.getWorld()))
        return;
    WorldConfiguration config = getWorldConfig(event.getWorld());
    RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery();
    Block block;
    if ((block = event.getCause().getFirstBlock()) != null) {
        if (Materials.isPistonBlock(block.getType())) {
            event.filter(testState(query, Flags.PISTONS), false);
        }
    }
    if (event.getCause().find(EntityType.CREEPER) != null) {
        // Creeper
        event.filter(testState(query, Flags.CREEPER_EXPLOSION), config.explosionFlagCancellation);
    }
    if (event.getCause().find(EntityType.ENDER_DRAGON) != null) {
        // Enderdragon
        event.filter(testState(query, Flags.ENDERDRAGON_BLOCK_DAMAGE), config.explosionFlagCancellation);
    }
    if (event.getCause().find(EntityType.ENDER_CRYSTAL) != null) {
        // EnderCrystal
        event.filter(testState(query, Flags.OTHER_EXPLOSION), config.explosionFlagCancellation);
    }
    if (event.getCause().find(EntityType.ENDERMAN) != null) {
        event.filter(testState(query, Flags.ENDER_BUILD), false);
    }
    if (event.getCause().find(EntityType.RAVAGER) != null) {
        event.filter(testState(query, Flags.RAVAGER_RAVAGE), false);
    }
}
Also used : WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) RegionQuery(com.sk89q.worldguard.protection.regions.RegionQuery) Block(org.bukkit.block.Block) EventHandler(org.bukkit.event.EventHandler)

Example 49 with WorldConfiguration

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

the class BlacklistListener method onBreakBlock.

@EventHandler(ignoreCancelled = true)
public void onBreakBlock(final BreakBlockEvent event) {
    final WorldConfiguration wcfg = getWorldConfig(event.getWorld());
    // Blacklist guard
    if (wcfg.getBlacklist() == null) {
        return;
    }
    Player player = event.getCause().getFirstPlayer();
    if (player == null) {
        return;
    }
    final LocalPlayer localPlayer = getPlugin().wrapPlayer(player);
    event.filter(target -> {
        if (!wcfg.getBlacklist().check(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.getInventory().getItemInMainHand())), false, false)) {
            return false;
        }
        return true;
    });
}
Also used : BukkitWorldConfiguration(com.sk89q.worldguard.bukkit.BukkitWorldConfiguration) WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) Player(org.bukkit.entity.Player) LocalPlayer(com.sk89q.worldguard.LocalPlayer) LocalPlayer(com.sk89q.worldguard.LocalPlayer) BlockBreakBlacklistEvent(com.sk89q.worldguard.blacklist.event.BlockBreakBlacklistEvent) ItemDestroyWithBlacklistEvent(com.sk89q.worldguard.blacklist.event.ItemDestroyWithBlacklistEvent) EventHandler(org.bukkit.event.EventHandler)

Example 50 with WorldConfiguration

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

the class BlacklistListener method onSpawnEntity.

@EventHandler(ignoreCancelled = true)
public void onSpawnEntity(SpawnEntityEvent event) {
    final WorldConfiguration wcfg = getWorldConfig(event.getWorld());
    // Blacklist guard
    if (wcfg.getBlacklist() == null) {
        return;
    }
    Player player = event.getCause().getFirstPlayer();
    if (player == null) {
        return;
    }
    final LocalPlayer localPlayer = getPlugin().wrapPlayer(player);
    Material material = Materials.getRelatedMaterial(event.getEffectiveType());
    if (material != null) {
        if (!wcfg.getBlacklist().check(new ItemUseBlacklistEvent(localPlayer, BukkitAdapter.asBlockVector(event.getTarget()), createTarget(material)), false, false)) {
            event.setCancelled(true);
        }
    }
}
Also used : BukkitWorldConfiguration(com.sk89q.worldguard.bukkit.BukkitWorldConfiguration) WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) Player(org.bukkit.entity.Player) LocalPlayer(com.sk89q.worldguard.LocalPlayer) LocalPlayer(com.sk89q.worldguard.LocalPlayer) Material(org.bukkit.Material) ItemUseBlacklistEvent(com.sk89q.worldguard.blacklist.event.ItemUseBlacklistEvent) 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