mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-10-04 17:47:41 +02:00
Move PISTONS flag to RegionFlagsListener.
This commit is contained in:
parent
d29f66563b
commit
fa14184eb4
@ -24,11 +24,14 @@
|
|||||||
import com.sk89q.worldguard.bukkit.WorldConfiguration;
|
import com.sk89q.worldguard.bukkit.WorldConfiguration;
|
||||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||||
import com.sk89q.worldguard.bukkit.event.block.BreakBlockEvent;
|
import com.sk89q.worldguard.bukkit.event.block.BreakBlockEvent;
|
||||||
|
import com.sk89q.worldguard.bukkit.event.block.PlaceBlockEvent;
|
||||||
import com.sk89q.worldguard.bukkit.event.entity.SpawnEntityEvent;
|
import com.sk89q.worldguard.bukkit.event.entity.SpawnEntityEvent;
|
||||||
import com.sk89q.worldguard.bukkit.util.Entities;
|
import com.sk89q.worldguard.bukkit.util.Entities;
|
||||||
|
import com.sk89q.worldguard.bukkit.util.Materials;
|
||||||
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
||||||
import com.sk89q.worldguard.protection.flags.StateFlag;
|
import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.entity.Creeper;
|
import org.bukkit.entity.Creeper;
|
||||||
import org.bukkit.entity.EnderDragon;
|
import org.bukkit.entity.EnderDragon;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
@ -50,29 +53,80 @@ public RegionFlagsListener(WorldGuardPlugin plugin) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||||
public void onBreakBlock(final BreakBlockEvent event) {
|
public void onPlaceBlock(final PlaceBlockEvent event) {
|
||||||
WorldConfiguration config = getWorldConfig(event.getWorld());
|
if (!isRegionSupportEnabled(event.getWorld())) return; // Region support disabled
|
||||||
|
|
||||||
RegionQuery query = getPlugin().getRegionContainer().createQuery();
|
RegionQuery query = getPlugin().getRegionContainer().createQuery();
|
||||||
|
|
||||||
Entity entity;
|
Block block;
|
||||||
if ((entity = event.getCause().getFirstEntity()) != null) {
|
if ((block = event.getCause().getFirstBlock()) != null) {
|
||||||
if (entity instanceof Creeper) { // Creeper
|
// ================================================================
|
||||||
event.filter(testState(query, DefaultFlag.CREEPER_EXPLOSION), config.explosionFlagCancellation);
|
// PISTONS flag
|
||||||
|
// ================================================================
|
||||||
} else if (entity instanceof EnderDragon) { // Enderdragon
|
|
||||||
event.filter(testState(query, DefaultFlag.ENDERDRAGON_BLOCK_DAMAGE), config.explosionFlagCancellation);
|
|
||||||
|
|
||||||
} else if (Entities.isTNTBased(entity)) { // TNT + explosive TNT carts
|
|
||||||
event.filter(testState(query, DefaultFlag.TNT), config.explosionFlagCancellation);
|
|
||||||
|
|
||||||
|
if (Materials.isPistonBlock(block.getType())) {
|
||||||
|
event.filter(testState(query, DefaultFlag.PISTONS), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||||
public void onSpawnEntity(final SpawnEntityEvent event) {
|
public void onBreakBlock(final BreakBlockEvent event) {
|
||||||
|
if (!isRegionSupportEnabled(event.getWorld())) return; // Region support disabled
|
||||||
|
|
||||||
|
WorldConfiguration config = getWorldConfig(event.getWorld());
|
||||||
RegionQuery query = getPlugin().getRegionContainer().createQuery();
|
RegionQuery query = getPlugin().getRegionContainer().createQuery();
|
||||||
|
|
||||||
|
Block block;
|
||||||
|
if ((block = event.getCause().getFirstBlock()) != null) {
|
||||||
|
// ================================================================
|
||||||
|
// PISTONS flag
|
||||||
|
// ================================================================
|
||||||
|
|
||||||
|
if (Materials.isPistonBlock(block.getType())) {
|
||||||
|
event.filter(testState(query, DefaultFlag.PISTONS), false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Entity entity;
|
||||||
|
if ((entity = event.getCause().getFirstEntity()) != null) {
|
||||||
|
// ================================================================
|
||||||
|
// CREEPER_EXPLOSION flag
|
||||||
|
// ================================================================
|
||||||
|
|
||||||
|
if (entity instanceof Creeper) { // Creeper
|
||||||
|
event.filter(testState(query, DefaultFlag.CREEPER_EXPLOSION), config.explosionFlagCancellation);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ================================================================
|
||||||
|
// ENDERDRAGON_BLOCK_DAMAGE flag
|
||||||
|
// ================================================================
|
||||||
|
|
||||||
|
if (entity instanceof EnderDragon) { // Enderdragon
|
||||||
|
event.filter(testState(query, DefaultFlag.ENDERDRAGON_BLOCK_DAMAGE), config.explosionFlagCancellation);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ================================================================
|
||||||
|
// TNT flag
|
||||||
|
// ================================================================
|
||||||
|
|
||||||
|
if (Entities.isTNTBased(entity)) { // TNT + explosive TNT carts
|
||||||
|
event.filter(testState(query, DefaultFlag.TNT), config.explosionFlagCancellation);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||||
|
public void onSpawnEntity(final SpawnEntityEvent event) {
|
||||||
|
if (!isRegionSupportEnabled(event.getWorld())) return; // Region support disabled
|
||||||
|
|
||||||
|
RegionQuery query = getPlugin().getRegionContainer().createQuery();
|
||||||
|
|
||||||
|
// ================================================================
|
||||||
|
// EXP_DROPS flag
|
||||||
|
// ================================================================
|
||||||
|
|
||||||
if (event.getEffectiveType() == EntityType.EXPERIENCE_ORB) {
|
if (event.getEffectiveType() == EntityType.EXPERIENCE_ORB) {
|
||||||
event.filter(testState(query, DefaultFlag.EXP_DROPS), false);
|
event.filter(testState(query, DefaultFlag.EXP_DROPS), false);
|
||||||
}
|
}
|
||||||
|
@ -43,8 +43,6 @@
|
|||||||
import org.bukkit.event.block.BlockIgniteEvent;
|
import org.bukkit.event.block.BlockIgniteEvent;
|
||||||
import org.bukkit.event.block.BlockIgniteEvent.IgniteCause;
|
import org.bukkit.event.block.BlockIgniteEvent.IgniteCause;
|
||||||
import org.bukkit.event.block.BlockPhysicsEvent;
|
import org.bukkit.event.block.BlockPhysicsEvent;
|
||||||
import org.bukkit.event.block.BlockPistonExtendEvent;
|
|
||||||
import org.bukkit.event.block.BlockPistonRetractEvent;
|
|
||||||
import org.bukkit.event.block.BlockPlaceEvent;
|
import org.bukkit.event.block.BlockPlaceEvent;
|
||||||
import org.bukkit.event.block.BlockRedstoneEvent;
|
import org.bukkit.event.block.BlockRedstoneEvent;
|
||||||
import org.bukkit.event.block.BlockSpreadEvent;
|
import org.bukkit.event.block.BlockSpreadEvent;
|
||||||
@ -666,43 +664,4 @@ public void onBlockFade(BlockFadeEvent event) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Called when a piston extends
|
|
||||||
*/
|
|
||||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
|
||||||
public void onBlockPistonExtend(BlockPistonExtendEvent event) {
|
|
||||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
|
||||||
WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());
|
|
||||||
|
|
||||||
if (wcfg.useRegions) {
|
|
||||||
if (!plugin.getGlobalRegionManager().allows(DefaultFlag.PISTONS, event.getBlock().getLocation())) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (Block block : event.getBlocks()) {
|
|
||||||
if (!plugin.getGlobalRegionManager().allows(DefaultFlag.PISTONS, block.getLocation())) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Called when a piston retracts
|
|
||||||
*/
|
|
||||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
|
||||||
public void onBlockPistonRetract(BlockPistonRetractEvent event) {
|
|
||||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
|
||||||
WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());
|
|
||||||
|
|
||||||
if (wcfg.useRegions && event.isSticky()) {
|
|
||||||
if (!(plugin.getGlobalRegionManager().allows(DefaultFlag.PISTONS, event.getRetractLocation()))
|
|
||||||
|| !(plugin.getGlobalRegionManager().allows(DefaultFlag.PISTONS, event.getBlock().getLocation()))) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user