use of com.sk89q.worldguard.protection.association.RegionAssociable in project WorldGuard by EngineHub.
the class RegionProtectionListener method onUseEntity.
@EventHandler(ignoreCancelled = true)
public void onUseEntity(UseEntityEvent event) {
// Don't care about events that have been pre-allowed
if (event.getResult() == Result.ALLOW)
return;
// Region support disabled
if (!isRegionSupportEnabled(event.getWorld()))
return;
// Whitelisted cause
if (isWhitelisted(event.getCause(), event.getWorld(), false))
return;
Location target = event.getTarget();
RegionAssociable associable = createRegionAssociable(event.getCause());
RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery();
boolean canUse;
String what;
/* Hostile / ambient mob override */
final Entity entity = event.getEntity();
final EntityType type = entity.getType();
if (Entities.isHostile(entity) || Entities.isAmbient(entity) || Entities.isNPC(entity) || entity instanceof Player) {
canUse = event.getRelevantFlags().isEmpty() || query.queryState(BukkitAdapter.adapt(target), associable, combine(event)) != State.DENY;
what = "use that";
/* Paintings, item frames, etc. */
} else if (Entities.isConsideredBuildingIfUsed(entity)) {
if ((type == EntityType.ITEM_FRAME || type == EntityType.GLOW_ITEM_FRAME) && event.getCause().getFirstPlayer() != null && ((ItemFrame) entity).getItem().getType() != Material.AIR) {
canUse = query.testBuild(BukkitAdapter.adapt(target), associable, combine(event, Flags.ITEM_FRAME_ROTATE));
what = "change that";
} else if (Entities.isMinecart(type)) {
canUse = query.testBuild(BukkitAdapter.adapt(target), associable, combine(event, Flags.CHEST_ACCESS));
what = "open that";
} else {
canUse = query.testBuild(BukkitAdapter.adapt(target), associable, combine(event));
what = "change that";
}
/* Ridden on use */
} else if (Entities.isRiddenOnUse(entity)) {
canUse = query.testBuild(BukkitAdapter.adapt(target), associable, combine(event, Flags.RIDE, Flags.INTERACT));
what = "ride that";
/* Everything else */
} else {
canUse = query.testBuild(BukkitAdapter.adapt(target), associable, combine(event, Flags.INTERACT));
what = "use that";
}
if (!canUse) {
tellErrorMessage(event, event.getCause(), target, what);
event.setCancelled(true);
}
}
use of com.sk89q.worldguard.protection.association.RegionAssociable in project WorldGuard by EngineHub.
the class RegionProtectionListener method onSpawnEntity.
@EventHandler(ignoreCancelled = true)
public void onSpawnEntity(SpawnEntityEvent event) {
// Don't care about events that have been pre-allowed
if (event.getResult() == Result.ALLOW)
return;
// Region support disabled
if (!isRegionSupportEnabled(event.getWorld()))
return;
// Whitelisted cause
if (isWhitelisted(event.getCause(), event.getWorld(), false))
return;
Location target = event.getTarget();
EntityType type = event.getEffectiveType();
RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery();
RegionAssociable associable = createRegionAssociable(event.getCause());
boolean canSpawn;
String what;
/* Vehicles */
if (Entities.isVehicle(type)) {
canSpawn = query.testBuild(BukkitAdapter.adapt(target), associable, combine(event, Flags.PLACE_VEHICLE));
what = "place vehicles";
/* Item pickup */
} else if (event.getEntity() instanceof Item) {
canSpawn = query.testBuild(BukkitAdapter.adapt(target), associable, combine(event, Flags.ITEM_DROP));
what = "drop items";
/* XP drops */
} else if (type == EntityType.EXPERIENCE_ORB) {
canSpawn = query.testBuild(BukkitAdapter.adapt(target), associable, combine(event, Flags.EXP_DROPS));
what = "drop XP";
} else if (Entities.isAoECloud(type)) {
canSpawn = query.testBuild(BukkitAdapter.adapt(target), associable, combine(event, Flags.POTION_SPLASH));
what = "use lingering potions";
/* Everything else */
} else {
canSpawn = query.testBuild(BukkitAdapter.adapt(target), associable, combine(event));
what = "place things";
}
if (!canSpawn) {
tellErrorMessage(event, event.getCause(), target, what);
event.setCancelled(true);
}
}
use of com.sk89q.worldguard.protection.association.RegionAssociable in project WorldGuard by EngineHub.
the class RegionProtectionListener method onPlaceBlock.
@EventHandler(ignoreCancelled = true)
public void onPlaceBlock(final PlaceBlockEvent event) {
// Don't care about events that have been pre-allowed
if (event.getResult() == Result.ALLOW)
return;
// Region support disabled
if (!isRegionSupportEnabled(event.getWorld()))
return;
// Whitelisted cause
if (isWhitelisted(event.getCause(), event.getWorld(), false))
return;
final Material type = event.getEffectiveMaterial();
final RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery();
final RegionAssociable associable = createRegionAssociable(event.getCause());
// Don't check liquid flow unless it's enabled
if (event.getCause().getRootCause() instanceof Block && Materials.isLiquid(type) && !getWorldConfig(event.getWorld()).checkLiquidFlow) {
return;
}
event.filter((Predicate<Location>) target -> {
boolean canPlace;
String what;
if (Materials.isFire(type)) {
Block block = event.getCause().getFirstBlock();
boolean fire = block != null && Materials.isFire(type);
boolean lava = block != null && Materials.isLava(block.getType());
List<StateFlag> flags = new ArrayList<>();
flags.add(Flags.BLOCK_PLACE);
flags.add(Flags.LIGHTER);
if (fire)
flags.add(Flags.FIRE_SPREAD);
if (lava)
flags.add(Flags.LAVA_FIRE);
canPlace = query.testBuild(BukkitAdapter.adapt(target), associable, combine(event, flags.toArray(new StateFlag[flags.size()])));
what = "place fire";
} else if (type == Material.FROSTED_ICE) {
event.setSilent(true);
canPlace = query.testBuild(BukkitAdapter.adapt(target), associable, combine(event, Flags.BLOCK_PLACE, Flags.FROSTED_ICE_FORM));
what = "use frostwalker";
} else {
canPlace = query.testBuild(BukkitAdapter.adapt(target), associable, combine(event, Flags.BLOCK_PLACE));
what = "place that block";
}
if (!canPlace) {
tellErrorMessage(event, event.getCause(), target, what);
return false;
}
return true;
});
}
use of com.sk89q.worldguard.protection.association.RegionAssociable in project WorldGuard by EngineHub.
the class WorldGuardBlockListener method onBlockForm.
/*
* Called when a block is formed based on world conditions.
*/
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onBlockForm(BlockFormEvent event) {
ConfigurationManager cfg = getConfig();
if (cfg.activityHaltToggle) {
event.setCancelled(true);
return;
}
WorldConfiguration wcfg = getWorldConfig(event.getBlock().getWorld());
Material type = event.getNewState().getType();
if (event instanceof EntityBlockFormEvent) {
if (((EntityBlockFormEvent) event).getEntity() instanceof Snowman) {
if (wcfg.disableSnowmanTrails) {
event.setCancelled(true);
return;
}
}
return;
}
if (type == Material.ICE) {
if (wcfg.disableIceFormation) {
event.setCancelled(true);
return;
}
if (wcfg.useRegions && !StateFlag.test(WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().queryState(BukkitAdapter.adapt(event.getBlock().getLocation()), (RegionAssociable) null, Flags.ICE_FORM))) {
event.setCancelled(true);
return;
}
}
if (type == Material.SNOW) {
if (wcfg.disableSnowFormation) {
event.setCancelled(true);
return;
}
if (!wcfg.allowedSnowFallOver.isEmpty()) {
Material targetId = event.getBlock().getRelative(0, -1, 0).getType();
if (!wcfg.allowedSnowFallOver.contains(BukkitAdapter.asBlockType(targetId).getId())) {
event.setCancelled(true);
return;
}
}
if (wcfg.useRegions && !StateFlag.test(WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().queryState(BukkitAdapter.adapt(event.getBlock().getLocation()), (RegionAssociable) null, Flags.SNOW_FALL))) {
event.setCancelled(true);
return;
}
}
}
use of com.sk89q.worldguard.protection.association.RegionAssociable in project WorldGuard by EngineHub.
the class RegionProtectionListener method onBreakBlock.
@EventHandler(ignoreCancelled = true)
public void onBreakBlock(final BreakBlockEvent event) {
// Don't care about events that have been pre-allowed
if (event.getResult() == Result.ALLOW)
return;
// Region support disabled
if (!isRegionSupportEnabled(event.getWorld()))
return;
// Whitelisted cause
if (isWhitelisted(event.getCause(), event.getWorld(), false))
return;
final RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery();
if (!event.isCancelled()) {
final RegionAssociable associable = createRegionAssociable(event.getCause());
event.filter((Predicate<Location>) target -> {
boolean canBreak;
String what;
if (event.getCause().find(EntityType.PRIMED_TNT, EntityType.MINECART_TNT) != null) {
canBreak = query.testBuild(BukkitAdapter.adapt(target), associable, combine(event, Flags.BLOCK_BREAK, Flags.TNT));
what = "use dynamite";
} else {
canBreak = query.testBuild(BukkitAdapter.adapt(target), associable, combine(event, Flags.BLOCK_BREAK));
what = "break that block";
}
if (!canBreak) {
tellErrorMessage(event, event.getCause(), target, what);
return false;
}
return true;
});
}
}
Aggregations