moved registerEvents() int event listeners

This commit is contained in:
Redecouverte 2011-02-28 19:05:07 +01:00
parent 8f9bfcf474
commit 2dc95da6e0
4 changed files with 58 additions and 38 deletions

View File

@ -18,6 +18,9 @@
*/
package com.sk89q.worldguard.bukkit;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.Event;
import org.bukkit.plugin.PluginManager;
import com.sk89q.worldguard.protection.regions.flags.RegionFlagContainer;
import com.sk89q.worldguard.protection.regions.flags.FlagDatabase.FlagType;
import com.nijiko.coelho.iConomy.iConomy;
@ -60,6 +63,22 @@ public WorldGuardBlockListener(WorldGuardPlugin plugin) {
this.plugin = plugin;
}
public void registerEvents() {
PluginManager pm = plugin.getServer().getPluginManager();
pm.registerEvent(Event.Type.BLOCK_DAMAGED, this, Priority.High, plugin);
pm.registerEvent(Event.Type.BLOCK_BREAK, this, Priority.High, plugin);
pm.registerEvent(Event.Type.BLOCK_FLOW, this, Priority.Normal, plugin);
pm.registerEvent(Event.Type.BLOCK_IGNITE, this, Priority.High, plugin);
pm.registerEvent(Event.Type.BLOCK_PHYSICS, this, Priority.Normal, plugin);
pm.registerEvent(Event.Type.BLOCK_INTERACT, this, Priority.High, plugin);
pm.registerEvent(Event.Type.BLOCK_PLACED, this, Priority.High, plugin);
pm.registerEvent(Event.Type.BLOCK_RIGHTCLICKED, this, Priority.High, plugin);
pm.registerEvent(Event.Type.BLOCK_BURN, this, Priority.High, plugin);
pm.registerEvent(Event.Type.REDSTONE_CHANGE, this, Priority.High, plugin);
}
/**
* Called when a block is damaged (or broken)
*

View File

@ -18,6 +18,9 @@
*/
package com.sk89q.worldguard.bukkit;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.Event;
import org.bukkit.plugin.PluginManager;
import com.sk89q.worldguard.protection.regions.flags.FlagDatabase.FlagType;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.regionmanager.RegionManager;
@ -53,6 +56,16 @@ public WorldGuardEntityListener(WorldGuardPlugin plugin) {
this.plugin = plugin;
}
public void registerEvents() {
PluginManager pm = plugin.getServer().getPluginManager();
pm.registerEvent(Event.Type.ENTITY_DAMAGED, this, Priority.High, plugin);
pm.registerEvent(Event.Type.ENTITY_EXPLODE, this, Priority.High, plugin);
pm.registerEvent(Event.Type.CREATURE_SPAWN, this, Priority.High, plugin);
}
public void onEntityDamageByBlock(EntityDamageByBlockEvent event) {
Entity defender = event.getEntity();

View File

@ -18,6 +18,9 @@
*/
package com.sk89q.worldguard.bukkit;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.Event;
import org.bukkit.plugin.PluginManager;
import com.sk89q.worldguard.protection.regions.flags.RegionFlag.RegionGroup;
import com.sk89q.worldguard.protection.regions.flags.FlagDatabase.FlagType;
import com.nijiko.coelho.iConomy.iConomy;
@ -56,6 +59,21 @@ public WorldGuardPlayerListener(WorldGuardPlugin plugin) {
this.plugin = plugin;
}
public void registerEvents() {
PluginManager pm = plugin.getServer().getPluginManager();
pm.registerEvent(Event.Type.PLAYER_ITEM, this, Priority.High, plugin);
pm.registerEvent(Event.Type.PLAYER_DROP_ITEM, this, Priority.High, plugin);
pm.registerEvent(Event.Type.PLAYER_PICKUP_ITEM, this, Priority.High, plugin);
pm.registerEvent(Event.Type.PLAYER_JOIN, this, Priority.Normal, plugin);
pm.registerEvent(Event.Type.PLAYER_LOGIN, this, Priority.Normal, plugin);
pm.registerEvent(Event.Type.PLAYER_QUIT, this, Priority.Normal, plugin);
pm.registerEvent(Event.Type.PLAYER_RESPAWN, this, Priority.High, plugin);
}
/**
* Called when a player joins a server
*

View File

@ -19,13 +19,10 @@
package com.sk89q.worldguard.bukkit;
import java.util.logging.*;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.Event;
import org.bukkit.plugin.java.JavaPlugin;
import com.sk89q.worldguard.bukkit.commands.CommandHandler;
import com.sk89q.worldguard.protection.*;
import com.sk89q.worldguard.protection.regionmanager.GlobalRegionManager;
import org.bukkit.plugin.PluginManager;
/**
* Plugin for Bukkit.
@ -55,7 +52,14 @@ public void onEnable() {
getDataFolder().mkdirs();
globalRegionManager.onEnable();
registerEvents();
playerListener.registerEvents();
blockListener.registerEvents();
entityListener.registerEvents();
// 25 equals about 1s real time
this.getServer().getScheduler().scheduleSyncRepeatingTask(this, new TimedFlagsTimer(this), 25 * 5, 25 * 5);
commandHandler.registerCommands();
logger.info("WorldGuard " + this.getDescription().getVersion() + " enabled.");
@ -71,40 +75,6 @@ public void onDisable() {
logger.info("WorldGuard " + this.getDescription().getVersion() + " disabled.");
}
/**
* Register used events.
*/
private void registerEvents() {
PluginManager pm = getServer().getPluginManager();
pm.registerEvent(Event.Type.BLOCK_DAMAGED, blockListener, Priority.High, this);
pm.registerEvent(Event.Type.BLOCK_BREAK, blockListener, Priority.High, this);
pm.registerEvent(Event.Type.BLOCK_FLOW, blockListener, Priority.Normal, this);
pm.registerEvent(Event.Type.BLOCK_IGNITE, blockListener, Priority.High, this);
pm.registerEvent(Event.Type.BLOCK_PHYSICS, blockListener, Priority.Normal, this);
pm.registerEvent(Event.Type.BLOCK_INTERACT, blockListener, Priority.High, this);
pm.registerEvent(Event.Type.BLOCK_PLACED, blockListener, Priority.High, this);
pm.registerEvent(Event.Type.BLOCK_RIGHTCLICKED, blockListener, Priority.High, this);
pm.registerEvent(Event.Type.BLOCK_BURN, blockListener, Priority.High, this);
pm.registerEvent(Event.Type.REDSTONE_CHANGE, blockListener, Priority.High, this);
pm.registerEvent(Event.Type.ENTITY_DAMAGED, entityListener, Priority.High, this);
pm.registerEvent(Event.Type.ENTITY_EXPLODE, entityListener, Priority.High, this);
pm.registerEvent(Event.Type.CREATURE_SPAWN, entityListener, Priority.High, this);
pm.registerEvent(Event.Type.PLAYER_ITEM, playerListener, Priority.High, this);
pm.registerEvent(Event.Type.PLAYER_DROP_ITEM, playerListener, Priority.High, this);
pm.registerEvent(Event.Type.PLAYER_PICKUP_ITEM, playerListener, Priority.High, this);
pm.registerEvent(Event.Type.PLAYER_JOIN, playerListener, Priority.Normal, this);
pm.registerEvent(Event.Type.PLAYER_LOGIN, playerListener, Priority.Normal, this);
pm.registerEvent(Event.Type.PLAYER_QUIT, playerListener, Priority.Normal, this);
pm.registerEvent(Event.Type.PLAYER_RESPAWN, playerListener, Priority.High, this);
// 25 equals about 1s real time
this.getServer().getScheduler().scheduleSyncRepeatingTask(this, new TimedFlagsTimer(this), 25 * 5, 25 * 5);
}
/**
* Get the GlobalRegionManager.