Search in sources :

Example 51 with WorldConfiguration

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

the class BlacklistListener method onPlaceBlock.

@EventHandler(ignoreCancelled = true)
public void onPlaceBlock(final PlaceBlockEvent 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 -> wcfg.getBlacklist().check(new BlockPlaceBlacklistEvent(localPlayer, BukkitAdapter.asBlockVector(target), createTarget(target.getBlock(), event.getEffectiveMaterial())), false, false));
}
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) BlockPlaceBlacklistEvent(com.sk89q.worldguard.blacklist.event.BlockPlaceBlacklistEvent) EventHandler(org.bukkit.event.EventHandler)

Example 52 with WorldConfiguration

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

the class WorldGuardPlayerListener method handlePhysicalInteract.

/**
 * Called when a player steps on a pressure plate or tramples crops.
 *
 * @param event Thrown event
 */
private void handlePhysicalInteract(PlayerInteractEvent event) {
    if (event.useInteractedBlock() == Event.Result.DENY)
        return;
    Player player = event.getPlayer();
    // not actually clicked but whatever
    Block block = event.getClickedBlock();
    Material type = block.getType();
    World world = player.getWorld();
    WorldConfiguration wcfg = getWorldConfig(world);
    if (type == Material.FARMLAND && wcfg.disablePlayerCropTrampling) {
        event.setCancelled(true);
        return;
    }
    if (type == Material.TURTLE_EGG && wcfg.disablePlayerTurtleEggTrampling) {
        event.setCancelled(true);
        return;
    }
}
Also used : Player(org.bukkit.entity.Player) LocalPlayer(com.sk89q.worldguard.LocalPlayer) WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) Block(org.bukkit.block.Block) Material(org.bukkit.Material) World(org.bukkit.World)

Example 53 with WorldConfiguration

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

the class WorldGuardVehicleListener method onVehicleMove.

@EventHandler
public void onVehicleMove(VehicleMoveEvent event) {
    Vehicle vehicle = event.getVehicle();
    if (vehicle.getPassengers().isEmpty())
        return;
    List<Player> playerPassengers = vehicle.getPassengers().stream().filter(ent -> ent instanceof Player).map(ent -> (Player) ent).collect(Collectors.toList());
    if (playerPassengers.isEmpty()) {
        return;
    }
    World world = vehicle.getWorld();
    WorldConfiguration wcfg = getWorldConfig(world);
    if (wcfg.useRegions) {
        // Did we move a block?
        if (Locations.isDifferentBlock(BukkitAdapter.adapt(event.getFrom()), BukkitAdapter.adapt(event.getTo()))) {
            for (Player player : playerPassengers) {
                LocalPlayer localPlayer = getPlugin().wrapPlayer(player);
                Location lastValid;
                if ((lastValid = WorldGuard.getInstance().getPlatform().getSessionManager().get(localPlayer).testMoveTo(localPlayer, BukkitAdapter.adapt(event.getTo()), MoveType.RIDE)) != null) {
                    vehicle.setVelocity(new Vector(0, 0, 0));
                    vehicle.teleport(event.getFrom());
                    if (Locations.isDifferentBlock(lastValid, BukkitAdapter.adapt(event.getFrom()))) {
                        Vector dir = player.getLocation().getDirection();
                        player.teleport(BukkitAdapter.adapt(lastValid).setDirection(dir));
                    }
                    return;
                }
            }
        }
    }
}
Also used : Vehicle(org.bukkit.entity.Vehicle) WorldGuardPlugin(com.sk89q.worldguard.bukkit.WorldGuardPlugin) LocalPlayer(com.sk89q.worldguard.LocalPlayer) Player(org.bukkit.entity.Player) Collectors(java.util.stream.Collectors) Locations(com.sk89q.worldguard.util.Locations) EventHandler(org.bukkit.event.EventHandler) Vector(org.bukkit.util.Vector) MoveType(com.sk89q.worldguard.session.MoveType) List(java.util.List) WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) BukkitAdapter(com.sk89q.worldedit.bukkit.BukkitAdapter) World(org.bukkit.World) Vehicle(org.bukkit.entity.Vehicle) WorldGuard(com.sk89q.worldguard.WorldGuard) Location(com.sk89q.worldedit.util.Location) VehicleMoveEvent(org.bukkit.event.vehicle.VehicleMoveEvent) LocalPlayer(com.sk89q.worldguard.LocalPlayer) Player(org.bukkit.entity.Player) WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) LocalPlayer(com.sk89q.worldguard.LocalPlayer) World(org.bukkit.World) Vector(org.bukkit.util.Vector) Location(com.sk89q.worldedit.util.Location) EventHandler(org.bukkit.event.EventHandler)

Example 54 with WorldConfiguration

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

the class BlacklistListener method onInventoryClick.

@EventHandler(ignoreCancelled = true)
public void onInventoryClick(InventoryClickEvent event) {
    HumanEntity entity = event.getWhoClicked();
    if (!(entity instanceof Player))
        return;
    Inventory inventory = event.getInventory();
    ItemStack item = event.getCurrentItem();
    if (item != null && inventory.getHolder() != null) {
        Player player = (Player) entity;
        WorldConfiguration wcfg = getWorldConfig(player.getWorld());
        LocalPlayer localPlayer = getPlugin().wrapPlayer(player);
        if (wcfg.getBlacklist() != null && !wcfg.getBlacklist().check(new ItemAcquireBlacklistEvent(localPlayer, BukkitAdapter.asBlockVector(entity.getLocation()), createTarget(item)), false, false)) {
            event.setCancelled(true);
            if (inventory.getHolder().equals(player)) {
                event.setCurrentItem(null);
            }
        }
        ItemStack equipped = checkEquipped(event);
        if (equipped != null) {
            if (wcfg.getBlacklist() != null && !wcfg.getBlacklist().check(new ItemEquipBlacklistEvent(localPlayer, BukkitAdapter.asBlockVector(player.getLocation()), createTarget(equipped)), false, false)) {
                event.setCancelled(true);
            }
        }
    }
}
Also used : ItemAcquireBlacklistEvent(com.sk89q.worldguard.blacklist.event.ItemAcquireBlacklistEvent) Player(org.bukkit.entity.Player) LocalPlayer(com.sk89q.worldguard.LocalPlayer) BukkitWorldConfiguration(com.sk89q.worldguard.bukkit.BukkitWorldConfiguration) WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) ItemEquipBlacklistEvent(com.sk89q.worldguard.blacklist.event.ItemEquipBlacklistEvent) LocalPlayer(com.sk89q.worldguard.LocalPlayer) HumanEntity(org.bukkit.entity.HumanEntity) ItemStack(org.bukkit.inventory.ItemStack) Inventory(org.bukkit.inventory.Inventory) PlayerInventory(org.bukkit.inventory.PlayerInventory) EventHandler(org.bukkit.event.EventHandler)

Example 55 with WorldConfiguration

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

the class BlacklistListener method onBlockDispenseArmor.

@EventHandler(ignoreCancelled = true)
public void onBlockDispenseArmor(BlockDispenseArmorEvent event) {
    if (!(event.getTargetEntity() instanceof Player))
        return;
    Player player = ((Player) event.getTargetEntity());
    ItemStack stack = event.getItem();
    WorldConfiguration wcfg = getWorldConfig(player.getWorld());
    LocalPlayer localPlayer = getPlugin().wrapPlayer(player);
    if (wcfg.getBlacklist() != null && !wcfg.getBlacklist().check(new ItemEquipBlacklistEvent(localPlayer, BukkitAdapter.asBlockVector(player.getLocation()), createTarget(stack)), false, true)) {
        event.setCancelled(true);
    }
}
Also used : Player(org.bukkit.entity.Player) LocalPlayer(com.sk89q.worldguard.LocalPlayer) BukkitWorldConfiguration(com.sk89q.worldguard.bukkit.BukkitWorldConfiguration) WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) ItemEquipBlacklistEvent(com.sk89q.worldguard.blacklist.event.ItemEquipBlacklistEvent) LocalPlayer(com.sk89q.worldguard.LocalPlayer) ItemStack(org.bukkit.inventory.ItemStack) 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