This commit is contained in:
sk89q 2011-05-03 01:31:49 -07:00
commit 428a47f889
6 changed files with 232 additions and 4 deletions

View File

@ -48,15 +48,14 @@ fire:
lava-spread-blocks: []
weather:
disable-lightning-strike-fire: off
prevent-lightning-strike-blocks: []
# The following don't work yet
disable-weather: off
disable-thunderstorm: off
disable-pig-zombification: off
disable-powered-creepers: off
disable-lightning-strike-fire: off
prevent-lightning-strike-blocks: []
always-raining: off
always-thundering: off
disable-powered-creepers: off
mobs:
block-creeper-explosions: off

View File

@ -65,6 +65,8 @@ public void registerEvents() {
pm.registerEvent(Event.Type.ENTITY_EXPLODE, this, Priority.High, plugin);
pm.registerEvent(Event.Type.CREATURE_SPAWN, 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.PIG_ZAP, this, Priority.High, plugin);
}
@Override
@ -423,6 +425,37 @@ public void onCreatureSpawn(CreatureSpawnEvent event) {
}
}
/**
* Weather related entity events.
*/
@Override
public void onPigZap(PigZapEvent event) {
if (event.isCancelled()) {
return;
}
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.get(event.getEntity().getWorld());
if (wcfg.disablePigZap) {
event.setCancelled(true);
}
}
@Override
public void onCreeperPower(CreeperPowerEvent event) {
if (event.isCancelled()) {
return;
}
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.get(event.getEntity().getWorld());
if (wcfg.disableCreeperPower) {
event.setCancelled(true);
}
}
/**
* 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

View File

@ -101,6 +101,7 @@ public void onPlayerInteract(PlayerInteractEvent event) {
}
}
<<<<<<< HEAD
/**
* Called when a player left clicks air.
*
@ -149,6 +150,56 @@ public void handleBlockLeftClick(PlayerInteractEvent event) {
}
/**
=======
/**
* Called when a player left clicks air.
*
* @param event
*/
public void handleAirLeftClick(PlayerInteractEvent event) {
//I don't think we have to do anything here yet.
return;
}
/**
* Called when a player left clicks a block.
*
* @param event
*/
public void handleBlockLeftClick(PlayerInteractEvent event) {
if (event.isCancelled()) return;
Player player = event.getPlayer();
Block block = event.getClickedBlock();
Material type = block.getType();
World world = player.getWorld();
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.get(world);
if (wcfg.useRegions) {
Vector pt = toVector(block);
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
ApplicableRegionSet set = mgr.getApplicableRegions(pt);
LocalPlayer localPlayer = plugin.wrapPlayer(player);
if (type == Material.STONE_BUTTON
|| type == Material.LEVER
|| type == Material.WOODEN_DOOR
|| type == Material.NOTE_BLOCK) {
if (!plugin.getGlobalRegionManager().hasBypass(player, world)
&& !set.allows(DefaultFlag.USE)
&& !set.canBuild(localPlayer)) {
player.sendMessage(ChatColor.DARK_RED + "You don't have permission to use that in this area.");
event.setCancelled(true);
return;
}
}
}
}
/**
>>>>>>> 19d447d67d0c4620368069a00c20812325916b2e
* Called when a player right clicks air.
*
* @param event

View File

@ -132,6 +132,7 @@ public void onEnable() {
(new WorldGuardPlayerListener(this)).registerEvents();
(new WorldGuardBlockListener(this)).registerEvents();
(new WorldGuardEntityListener(this)).registerEvents();
(new WorldGuardWeatherListener(this)).registerEvents();
// 25 equals about 1s real time
getServer().getScheduler().scheduleAsyncRepeatingTask(this, new TimedFlagsTimer(this), 0, 5);

View File

@ -0,0 +1,134 @@
// $Id$
/*
* WorldGuard
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.bukkit;
import org.bukkit.block.Block;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.Event;
import org.bukkit.plugin.PluginManager;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.*;
import org.bukkit.event.weather.*;
import org.bukkit.event.entity.*;
import org.bukkit.event.entity.PigZapEvent;
import org.bukkit.event.entity.CreeperPowerEvent;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BlockType;
import static com.sk89q.worldguard.bukkit.BukkitUtil.*;
import com.sk89q.worldguard.protection.flags.DefaultFlag;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
public class WorldGuardWeatherListener extends WeatherListener {
/**
* Plugin.
*/
private WorldGuardPlugin plugin;
/**
* Construct the object;
*
* @param plugin
*/
public WorldGuardWeatherListener(WorldGuardPlugin plugin) {
this.plugin = plugin;
}
public void registerEvents() {
PluginManager pm = plugin.getServer().getPluginManager();
pm.registerEvent(Event.Type.LIGHTNING_STRIKE, this, Priority.High, plugin);
pm.registerEvent(Event.Type.THUNDER_CHANGE, this, Priority.High, plugin);
pm.registerEvent(Event.Type.WEATHER_CHANGE, this, Priority.High, plugin);
}
@Override
public void onWeatherChange(WeatherChangeEvent event) {
if (event.isCancelled()) {
return;
}
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.get(event.getWorld());
if (event.toWeatherState()) {
if (wcfg.disableWeather) {
event.setCancelled(true);
}
} else {
if (!wcfg.disableWeather && wcfg.alwaysRaining) {
event.setCancelled(true);
}
}
}
@Override
public void onThunderChange(ThunderChangeEvent event) {
if (event.isCancelled()) {
return;
}
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.get(event.getWorld());
if (event.toThunderState()) {
if (wcfg.disableThunder) {
event.setCancelled(true);
}
} else {
if (!wcfg.disableWeather && wcfg.alwaysThundering) {
event.setCancelled(true);
}
}
}
@Override
public void onLightningStrike(LightningStrikeEvent event) {
if (event.isCancelled()) {
return;
}
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.get(event.getWorld());
if (wcfg.disallowedLightningBlocks.size() > 0) {
int targetId = event.getLightning().getLocation().getBlock().getTypeId();
if (wcfg.disallowedLightningBlocks.contains(targetId)) {
event.setCancelled(true);
}
}
Location loc = event.getLightning().getLocation();
if (wcfg.useRegions) {
Vector pt = toVector(loc);
RegionManager mgr = plugin.getGlobalRegionManager().get(loc.getWorld());
ApplicableRegionSet set = mgr.getApplicableRegions(pt);
if (!set.allows(DefaultFlag.LIGHTNING)) {
event.setCancelled(true);
}
}
}
}

View File

@ -36,6 +36,7 @@ public final class DefaultFlag {
public static final StateFlag LIGHTER = new StateFlag("lighter", 'l', true);
public static final StateFlag FIRE_SPREAD = new StateFlag("fire-spread", 'f', true);
public static final StateFlag LAVA_FIRE = new StateFlag("lava-fire", 'F', true);
public static final StateFlag LIGHTNING = new StateFlag("lightning", true);
public static final StateFlag CHEST_ACCESS = new StateFlag("chest-access", 'C', false);
public static final StateFlag WATER_FLOW = new StateFlag("water-flow", true);
public static final StateFlag LAVA_FLOW = new StateFlag("lava-flow", true);
@ -56,11 +57,20 @@ public final class DefaultFlag {
public static final DoubleFlag PRICE = new DoubleFlag("price");
public static final Flag<?>[] flagsList = new Flag<?>[] {
<<<<<<< HEAD
PASSTHROUGH, BUILD, PVP, MOB_DAMAGE, MOB_SPAWNING, CREEPER_EXPLOSION, SLEEP,
TNT, LIGHTER, FIRE_SPREAD, LAVA_FIRE, CHEST_ACCESS, WATER_FLOW, LAVA_FLOW,
USE, PLACE_VEHICLE, GREET_MESSAGE, FAREWELL_MESSAGE, NOTIFY_GREET,
NOTIFY_FAREWELL, DENY_SPAWN, HEAL_DELAY, HEAL_AMOUNT, TELE_LOC,
TELE_PERM, SPAWN_LOC, SPAWN_PERM, BUYABLE, PRICE
=======
PASSTHROUGH, BUILD, PVP, MOB_DAMAGE, MOB_SPAWNING, CREEPER_EXPLOSION,
TNT, LIGHTER, FIRE_SPREAD, LAVA_FIRE, LIGHTNING, CHEST_ACCESS,
WATER_FLOW, LAVA_FLOW, USE, PLACE_VEHICLE, GREET_MESSAGE,
FAREWELL_MESSAGE, NOTIFY_GREET, NOTIFY_FAREWELL, DENY_SPAWN,
HEAL_DELAY, HEAL_AMOUNT, TELE_LOC,TELE_PERM, SPAWN_LOC, SPAWN_PERM,
BUYABLE, PRICE, SLEEP
>>>>>>> 19d447d67d0c4620368069a00c20812325916b2e
};
private DefaultFlag() {