Search in sources :

Example 11 with RegionAssociable

use of com.sk89q.worldguard.protection.association.RegionAssociable in project WorldGuard by EngineHub.

the class WorldGuardHangingListener method onHangingBreak.

@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onHangingBreak(HangingBreakEvent event) {
    Hanging hanging = event.getEntity();
    World world = hanging.getWorld();
    WorldConfiguration wcfg = getWorldConfig(world);
    if (event instanceof HangingBreakByEntityEvent) {
        HangingBreakByEntityEvent entityEvent = (HangingBreakByEntityEvent) event;
        Entity removerEntity = entityEvent.getRemover();
        if (removerEntity instanceof Projectile) {
            Projectile projectile = (Projectile) removerEntity;
            ProjectileSource remover = projectile.getShooter();
            removerEntity = (remover instanceof LivingEntity ? (LivingEntity) remover : null);
        }
        if (!(removerEntity instanceof Player)) {
            if (removerEntity instanceof Creeper) {
                if (wcfg.blockCreeperBlockDamage || wcfg.blockCreeperExplosions) {
                    event.setCancelled(true);
                    return;
                }
                if (wcfg.useRegions && !StateFlag.test(WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().queryState(BukkitAdapter.adapt(hanging.getLocation()), (RegionAssociable) null, Flags.CREEPER_EXPLOSION))) {
                    event.setCancelled(true);
                    return;
                }
            }
            // due to a non-LivingEntity ProjectileSource
            if (hanging instanceof Painting && (wcfg.blockEntityPaintingDestroy || (wcfg.useRegions && !StateFlag.test(WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().queryState(BukkitAdapter.adapt(hanging.getLocation()), (RegionAssociable) null, Flags.ENTITY_PAINTING_DESTROY))))) {
                event.setCancelled(true);
            } else if (hanging instanceof ItemFrame && (wcfg.blockEntityItemFrameDestroy || (wcfg.useRegions && !StateFlag.test(WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().queryState(BukkitAdapter.adapt(hanging.getLocation()), (RegionAssociable) null, Flags.ENTITY_ITEM_FRAME_DESTROY))))) {
                event.setCancelled(true);
            }
        }
    } else {
        // Explosions from mobs are not covered by HangingBreakByEntity
        if (hanging instanceof Painting && wcfg.blockEntityPaintingDestroy && event.getCause() == RemoveCause.EXPLOSION) {
            event.setCancelled(true);
        } else if (hanging instanceof ItemFrame && wcfg.blockEntityItemFrameDestroy && event.getCause() == RemoveCause.EXPLOSION) {
            event.setCancelled(true);
        }
    }
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) Creeper(org.bukkit.entity.Creeper) ItemFrame(org.bukkit.entity.ItemFrame) World(org.bukkit.World) Projectile(org.bukkit.entity.Projectile) Painting(org.bukkit.entity.Painting) LivingEntity(org.bukkit.entity.LivingEntity) RegionAssociable(com.sk89q.worldguard.protection.association.RegionAssociable) WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) HangingBreakByEntityEvent(org.bukkit.event.hanging.HangingBreakByEntityEvent) Hanging(org.bukkit.entity.Hanging) ProjectileSource(org.bukkit.projectiles.ProjectileSource) EventHandler(org.bukkit.event.EventHandler)

Example 12 with RegionAssociable

use of com.sk89q.worldguard.protection.association.RegionAssociable in project WorldGuard by EngineHub.

the class RegionPrintoutBuilder method appendBounds.

/**
 * Add information about coordinates.
 */
public void appendBounds() {
    BlockVector3 min = region.getMinimumPoint();
    BlockVector3 max = region.getMaximumPoint();
    builder.append(TextComponent.of("Bounds:", TextColor.BLUE));
    TextComponent bound = TextComponent.of(" " + min + " -> " + max, TextColor.YELLOW);
    if (perms != null && perms.maySelect(region)) {
        bound = bound.hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to select"))).clickEvent(ClickEvent.of(ClickEvent.Action.RUN_COMMAND, "/rg select " + region.getId()));
    }
    builder.append(bound);
    final Location teleFlag = FlagValueCalculator.getEffectiveFlagOf(region, Flags.TELE_LOC, perms != null && perms.getSender() instanceof RegionAssociable ? (RegionAssociable) perms.getSender() : null);
    if (teleFlag != null && perms != null && perms.mayTeleportTo(region)) {
        builder.append(TextComponent.space().append(TextComponent.of("[Teleport]", TextColor.GRAY).hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to teleport").append(TextComponent.newline()).append(TextComponent.of(teleFlag.getBlockX() + ", " + teleFlag.getBlockY() + ", " + teleFlag.getBlockZ())))).clickEvent(ClickEvent.of(ClickEvent.Action.RUN_COMMAND, "/rg tp -w \"" + world + "\" " + region.getId()))));
    } else if (perms != null && perms.mayTeleportToCenter(region) && region.isPhysicalArea()) {
        builder.append(TextComponent.space().append(TextComponent.of("[Center Teleport]", TextColor.GRAY).hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to teleport to the center of the region"))).clickEvent(ClickEvent.of(ClickEvent.Action.RUN_COMMAND, "/rg tp -c -w \"" + world + "\" " + region.getId()))));
    }
    newline();
}
Also used : TextComponent(com.sk89q.worldedit.util.formatting.text.TextComponent) RegionAssociable(com.sk89q.worldguard.protection.association.RegionAssociable) BlockVector3(com.sk89q.worldedit.math.BlockVector3) Location(com.sk89q.worldedit.util.Location)

Aggregations

RegionAssociable (com.sk89q.worldguard.protection.association.RegionAssociable)12 EventHandler (org.bukkit.event.EventHandler)11 WorldConfiguration (com.sk89q.worldguard.config.WorldConfiguration)7 RegionQuery (com.sk89q.worldguard.protection.regions.RegionQuery)7 Location (org.bukkit.Location)6 Material (org.bukkit.Material)6 EntityType (org.bukkit.entity.EntityType)6 Player (org.bukkit.entity.Player)6 LocalPlayer (com.sk89q.worldguard.LocalPlayer)5 Entity (org.bukkit.entity.Entity)5 Item (org.bukkit.entity.Item)5 ItemFrame (org.bukkit.entity.ItemFrame)5 DisallowedPVPEvent (com.sk89q.worldguard.bukkit.protection.events.DisallowedPVPEvent)4 World (org.bukkit.World)4 Predicate (com.google.common.base.Predicate)3 BukkitAdapter (com.sk89q.worldedit.bukkit.BukkitAdapter)3 WorldGuard (com.sk89q.worldguard.WorldGuard)3 BukkitWorldConfiguration (com.sk89q.worldguard.bukkit.BukkitWorldConfiguration)3 WorldGuardPlugin (com.sk89q.worldguard.bukkit.WorldGuardPlugin)3 Cause (com.sk89q.worldguard.bukkit.cause.Cause)3