Merge pull request #100 from wizjany/master

Painting events and snow fall flag
This commit is contained in:
MonsieurApple 2011-05-13 05:20:20 -07:00
commit e59a07e232
3 changed files with 73 additions and 2 deletions

View File

@ -66,6 +66,7 @@ public void registerEvents() {
pm.registerEvent(Event.Type.BLOCK_BURN, this, Priority.High, plugin); pm.registerEvent(Event.Type.BLOCK_BURN, this, Priority.High, plugin);
pm.registerEvent(Event.Type.SIGN_CHANGE, this, Priority.High, plugin); pm.registerEvent(Event.Type.SIGN_CHANGE, this, Priority.High, plugin);
pm.registerEvent(Event.Type.REDSTONE_CHANGE, this, Priority.High, plugin); pm.registerEvent(Event.Type.REDSTONE_CHANGE, this, Priority.High, plugin);
pm.registerEvent(Event.Type.SNOW_FORM, this, Priority.High, plugin);
} }
protected WorldConfiguration getWorldConfig(World world) { protected WorldConfiguration getWorldConfig(World world) {
@ -529,6 +530,16 @@ public void onSignChange(SignChangeEvent event) {
} }
} }
@Override
public void onSnowForm(SnowFormEvent event) {
if (event.isCancelled()) {
return;
}
if (!plugin.getGlobalRegionManager().allows(DefaultFlag.SNOW_FALL, event.getBlock().getLocation())) {
event.setCancelled(true);
}
}
/** /**
* Drops a sign item and removes a sign. * Drops a sign item and removes a sign.
* *

View File

@ -27,8 +27,11 @@
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.*; import org.bukkit.entity.*;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.*; import org.bukkit.event.entity.*;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.painting.*;
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BlockType; import com.sk89q.worldedit.blocks.BlockType;
import static com.sk89q.worldguard.bukkit.BukkitUtil.*; import static com.sk89q.worldguard.bukkit.BukkitUtil.*;
@ -62,6 +65,8 @@ public void registerEvents() {
pm.registerEvent(Event.Type.ENTITY_INTERACT, this, Priority.High, plugin); pm.registerEvent(Event.Type.ENTITY_INTERACT, this, Priority.High, plugin);
pm.registerEvent(Event.Type.CREEPER_POWER, this, Priority.High, plugin); pm.registerEvent(Event.Type.CREEPER_POWER, this, Priority.High, plugin);
pm.registerEvent(Event.Type.PIG_ZAP, this, Priority.High, plugin); pm.registerEvent(Event.Type.PIG_ZAP, this, Priority.High, plugin);
pm.registerEvent(Event.Type.PAINTING_BREAK, this, Priority.High, plugin);
pm.registerEvent(Event.Type.PAINTING_PLACE, this, Priority.High, plugin);
} }
@Override @Override
@ -451,6 +456,60 @@ public void onCreeperPower(CreeperPowerEvent event) {
} }
} }
/**
* Painting related events
*/
/**
* Called when a painting is removed
*
* @param event Relevant event details
*/
@Override
public void onPaintingBreak(PaintingBreakEvent breakEvent) {
if (breakEvent.isCancelled()) {
return;
}
if (!(breakEvent instanceof PaintingBreakByEntityEvent)) {
return;
}
PaintingBreakByEntityEvent event = (PaintingBreakByEntityEvent) breakEvent;
if (!(event.getRemover() instanceof Player)) {
return;
}
Painting painting= event.getPainting();
Player player = (Player) event.getRemover();
World world = painting.getWorld();
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.get(world);
if (wcfg.useRegions) {
if (!plugin.getGlobalRegionManager().canBuild(player, painting.getLocation())) {
player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
event.setCancelled(true);
return;
}
}
}
@Override
public void onPaintingPlace(PaintingPlaceEvent event) {
Block placedOn = event.getBlock();
Player player = event.getPlayer();
World world = placedOn.getWorld();
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.get(world);
if (wcfg.useRegions) {
if (!plugin.getGlobalRegionManager().canBuild(player, placedOn.getLocation())) {
player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
event.setCancelled(true);
return;
}
}
}
/** /**
* Find a position for the player to stand that is not inside a block. * Find a position for the player to stand that is not inside a block.
* Blocks above the player will be iteratively tested until there is * Blocks above the player will be iteratively tested until there is

View File

@ -42,6 +42,7 @@ public final class DefaultFlag {
public static final StateFlag LAVA_FLOW = new StateFlag("lava-flow", true); public static final StateFlag LAVA_FLOW = new StateFlag("lava-flow", true);
public static final StateFlag USE = new StateFlag("use", false); public static final StateFlag USE = new StateFlag("use", false);
public static final StateFlag PLACE_VEHICLE = new StateFlag("vehicle-place", false); public static final StateFlag PLACE_VEHICLE = new StateFlag("vehicle-place", false);
public static final StateFlag SNOW_FALL = new StateFlag("snow-fall", true);
public static final StringFlag GREET_MESSAGE = new StringFlag("greeting"); public static final StringFlag GREET_MESSAGE = new StringFlag("greeting");
public static final StringFlag FAREWELL_MESSAGE = new StringFlag("farewell"); public static final StringFlag FAREWELL_MESSAGE = new StringFlag("farewell");
public static final BooleanFlag NOTIFY_GREET = new BooleanFlag("notify-greet"); public static final BooleanFlag NOTIFY_GREET = new BooleanFlag("notify-greet");
@ -61,7 +62,7 @@ public final class DefaultFlag {
TNT, LIGHTER, FIRE_SPREAD, LAVA_FIRE, CHEST_ACCESS, WATER_FLOW, LAVA_FLOW, TNT, LIGHTER, FIRE_SPREAD, LAVA_FIRE, CHEST_ACCESS, WATER_FLOW, LAVA_FLOW,
USE, PLACE_VEHICLE, GREET_MESSAGE, FAREWELL_MESSAGE, NOTIFY_GREET, USE, PLACE_VEHICLE, GREET_MESSAGE, FAREWELL_MESSAGE, NOTIFY_GREET,
NOTIFY_FAREWELL, DENY_SPAWN, HEAL_DELAY, HEAL_AMOUNT, TELE_LOC, NOTIFY_FAREWELL, DENY_SPAWN, HEAL_DELAY, HEAL_AMOUNT, TELE_LOC,
TELE_PERM, SPAWN_LOC, SPAWN_PERM, BUYABLE, PRICE TELE_PERM, SPAWN_LOC, SPAWN_PERM, BUYABLE, PRICE, SNOW_FALL
}; };
private DefaultFlag() { private DefaultFlag() {