Search in sources :

Example 11 with BukkitWorldConfiguration

use of com.sk89q.worldguard.bukkit.BukkitWorldConfiguration in project WorldGuard by EngineHub.

the class ChestProtectionListener method onSignChange.

@EventHandler(ignoreCancelled = true)
public void onSignChange(SignChangeEvent event) {
    Player player = event.getPlayer();
    final BukkitWorldConfiguration wcfg = getWorldConfig(event.getBlock().getWorld());
    if (wcfg.signChestProtection) {
        if ("[Lock]".equalsIgnoreCase(event.getLine(0))) {
            if (wcfg.isChestProtectedPlacement(BukkitAdapter.adapt(event.getBlock().getLocation()), WorldGuardPlugin.inst().wrapPlayer(player))) {
                player.sendMessage(ChatColor.DARK_RED + "You do not own the adjacent chest.");
                event.getBlock().breakNaturally();
                event.setCancelled(true);
                return;
            }
            if (!Tag.STANDING_SIGNS.isTagged(event.getBlock().getType())) {
                player.sendMessage(ChatColor.RED + "The [Lock] sign must be a sign post, not a wall sign.");
                event.getBlock().breakNaturally();
                event.setCancelled(true);
                return;
            }
            if (!player.getName().equalsIgnoreCase(event.getLine(1))) {
                player.sendMessage(ChatColor.RED + "The first owner line must be your name.");
                event.getBlock().breakNaturally();
                event.setCancelled(true);
                return;
            }
            Material below = event.getBlock().getRelative(0, -1, 0).getType();
            if (below == Material.TNT || below == Material.SAND || below == Material.GRAVEL || Tag.STANDING_SIGNS.isTagged(below)) {
                player.sendMessage(ChatColor.RED + "That is not a safe block that you're putting this sign on.");
                event.getBlock().breakNaturally();
                event.setCancelled(true);
                return;
            }
            event.setLine(0, "[Lock]");
            player.sendMessage(ChatColor.YELLOW + "A chest or double chest above is now protected.");
        }
    } else if (!wcfg.disableSignChestProtectionCheck) {
        if ("[Lock]".equalsIgnoreCase(event.getLine(0))) {
            player.sendMessage(ChatColor.RED + "WorldGuard's sign chest protection is disabled.");
            event.getBlock().breakNaturally();
            event.setCancelled(true);
        }
    }
}
Also used : LocalPlayer(com.sk89q.worldguard.LocalPlayer) Player(org.bukkit.entity.Player) BukkitWorldConfiguration(com.sk89q.worldguard.bukkit.BukkitWorldConfiguration) Material(org.bukkit.Material) EventHandler(org.bukkit.event.EventHandler)

Example 12 with BukkitWorldConfiguration

use of com.sk89q.worldguard.bukkit.BukkitWorldConfiguration in project WorldGuard by EngineHub.

the class ChestProtectionListener method onBreakBlock.

@EventHandler(ignoreCancelled = true)
public void onBreakBlock(final BreakBlockEvent event) {
    final Player player = event.getCause().getFirstPlayer();
    final BukkitWorldConfiguration wcfg = getWorldConfig(event.getWorld());
    // Early guard
    if (!wcfg.signChestProtection) {
        return;
    }
    if (player != null) {
        final LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
        event.filter(target -> {
            if (wcfg.isChestProtected(BukkitAdapter.adapt(target.getBlock().getLocation()), localPlayer)) {
                sendMessage(event, player, ChatColor.DARK_RED + "This chest is protected.");
                return false;
            }
            return true;
        }, true);
    } else {
        event.filter(target -> !wcfg.isChestProtected(BukkitAdapter.adapt(target.getBlock().getLocation())));
    }
}
Also used : LocalPlayer(com.sk89q.worldguard.LocalPlayer) Player(org.bukkit.entity.Player) BukkitWorldConfiguration(com.sk89q.worldguard.bukkit.BukkitWorldConfiguration) LocalPlayer(com.sk89q.worldguard.LocalPlayer) EventHandler(org.bukkit.event.EventHandler)

Aggregations

BukkitWorldConfiguration (com.sk89q.worldguard.bukkit.BukkitWorldConfiguration)12 EventHandler (org.bukkit.event.EventHandler)9 Player (org.bukkit.entity.Player)7 LocalPlayer (com.sk89q.worldguard.LocalPlayer)5 ConfigurationManager (com.sk89q.worldguard.config.ConfigurationManager)4 Entity (org.bukkit.entity.Entity)4 Block (org.bukkit.block.Block)3 HumanEntity (org.bukkit.entity.HumanEntity)2 LivingEntity (org.bukkit.entity.LivingEntity)2 TNTPrimed (org.bukkit.entity.TNTPrimed)2 PotionEffect (org.bukkit.potion.PotionEffect)2 PotionEffectType (org.bukkit.potion.PotionEffectType)2 BukkitPlayer (com.sk89q.worldguard.bukkit.BukkitPlayer)1 ApplicableRegionSet (com.sk89q.worldguard.protection.ApplicableRegionSet)1 DelayedRegionOverlapAssociation (com.sk89q.worldguard.protection.association.DelayedRegionOverlapAssociation)1 RegionQuery (com.sk89q.worldguard.protection.regions.RegionQuery)1 Location (org.bukkit.Location)1 Material (org.bukkit.Material)1 OfflinePlayer (org.bukkit.OfflinePlayer)1 Arrow (org.bukkit.entity.Arrow)1