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);
}
}
}
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();
}
Aggregations