Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Events update

  • Loading branch information...
commit 00f22cce87c0802bbbd0d9837a20878b108671e0 1 parent c18e8f8
@mbax mbax authored
View
12 com/ensifera/animosity/craftirc/CraftIRC.java
@@ -26,7 +26,6 @@
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.entity.Player;
-import org.bukkit.event.Event.Priority;
import org.bukkit.event.Event;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
@@ -82,12 +81,6 @@ public void onEnable() {
cfield.setAccessible(true);
console = (MinecraftServer) cfield.get((CraftServer)getServer());
- //Load node lists. Bukkit does it now, hurray!
- if (null == getConfiguration()) {
- CraftIRC.log.info(String.format(CraftIRC.NAME + " config.yml could not be found in plugins/CraftIRC/ -- disabling!"));
- getServer().getPluginManager().disablePlugin(((Plugin) (this)));
- return;
- }
bots = new ArrayList<ConfigurationNode>(getConfiguration().getNodeList("bots", null));
colormap = new ArrayList<ConfigurationNode>(getConfiguration().getNodeList("colormap", null));
channodes = new HashMap<Integer, ArrayList<ConfigurationNode>>();
@@ -107,10 +100,7 @@ public void onEnable() {
if (this.isDebug()) CraftIRC.log.info(String.format(CraftIRC.NAME + " Channel tag map: " + chanTagMap.toString()));
//Event listeners
- getServer().getPluginManager().registerEvent(Event.Type.PLAYER_COMMAND_PREPROCESS, listener, Priority.Monitor, this);
- getServer().getPluginManager().registerEvent(Event.Type.PLAYER_JOIN, listener, Priority.Monitor, this);
- getServer().getPluginManager().registerEvent(Event.Type.PLAYER_QUIT, listener, Priority.Monitor, this);
- getServer().getPluginManager().registerEvent(Event.Type.PLAYER_CHAT, listener, Priority.Monitor, this);
+ getServer().getPluginManager().registerEvents(listener, this);
//Create bots
instances = new ArrayList<Minebot>();
View
19 com/ensifera/animosity/craftirc/CraftIRCListener.java
@@ -1,22 +1,16 @@
package com.ensifera.animosity.craftirc;
import java.lang.Exception;
-import java.util.ArrayList;
-import java.util.Iterator;
-import org.bukkit.entity.Player;
-import org.bukkit.ChatColor;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.EventPriority;
+import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
-import org.bukkit.event.player.PlayerEvent;
import org.bukkit.event.player.PlayerKickEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
-import org.bukkit.event.player.PlayerListener;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandSender;
-import org.bukkit.command.ConsoleCommandSender;
-public class CraftIRCListener extends PlayerListener {
+public class CraftIRCListener implements Listener {
private CraftIRC plugin = null;
@@ -24,6 +18,7 @@ public CraftIRCListener(CraftIRC plugin) {
this.plugin = plugin;
}
+ @EventHandler(priority=EventPriority.MONITOR)
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
try {
String[] split = event.getMessage().split(" ");
@@ -40,6 +35,7 @@ public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
}
}
+ @EventHandler(priority=EventPriority.MONITOR)
public void onPlayerChat(PlayerChatEvent event) {
if (this.plugin.isHeld(CraftIRC.HoldType.CHAT)) {
@@ -65,6 +61,7 @@ public void onPlayerChat(PlayerChatEvent event) {
}
}
+ @EventHandler(priority=EventPriority.MONITOR)
public void onPlayerJoin(PlayerJoinEvent event) {
if (this.plugin.isHeld(CraftIRC.HoldType.JOINS))
return;
@@ -79,6 +76,7 @@ public void onPlayerJoin(PlayerJoinEvent event) {
}
}
+ @EventHandler(priority=EventPriority.MONITOR)
public void onPlayerQuit(PlayerQuitEvent event) {
if (this.plugin.isHeld(CraftIRC.HoldType.QUITS))
return;
@@ -94,6 +92,7 @@ public void onPlayerQuit(PlayerQuitEvent event) {
}
}
+ @EventHandler(priority=EventPriority.MONITOR)
public void onPlayerKick(PlayerKickEvent event) {
if (this.plugin.isHeld(CraftIRC.HoldType.KICKS))
return;
View
12 com/ensifera/animosity/craftirc/IRCEvent.java
@@ -4,8 +4,11 @@
package com.ensifera.animosity.craftirc;
import org.bukkit.event.Event;
+import org.bukkit.event.HandlerList;
+@SuppressWarnings("serial")
public class IRCEvent extends Event {
+ private static final HandlerList handlers = new HandlerList();
Minebot bot;
public Mode eventMode;
public RelayedMessage msgData;
@@ -81,5 +84,14 @@ public boolean isHandled() {
else
return false;
}
+
+ @Override
+ public HandlerList getHandlers() {
+ return IRCEvent.handlers;
+ }
+
+ public static HandlerList getHandlerList() {
+ return IRCEvent.handlers;
+ }
}
View
19 com/ensifera/animosity/craftirc/example/CraftIRCPluginExample.java
@@ -1,17 +1,8 @@
-/**
- *
- */
package com.ensifera.animosity.craftirc.example;
-import java.io.File;
import java.util.ArrayList;
import java.util.logging.Logger;
-import org.bukkit.Server;
-import org.bukkit.event.Event;
-import org.bukkit.event.Event.Priority;
import org.bukkit.plugin.Plugin;
-import org.bukkit.plugin.PluginDescriptionFile;
-import org.bukkit.plugin.PluginLoader;
import org.bukkit.plugin.java.JavaPlugin;
import com.ensifera.animosity.craftirc.CraftIRC;
@@ -25,10 +16,6 @@
protected CraftIRCPluginExampleListener ircListener;
ArrayList<String> ircTags = new ArrayList<String>();
- /* (non-Javadoc)
- * @see org.bukkit.plugin.Plugin#onEnable()
- */
-
public void onEnable() {
Plugin checkplugin = this.getServer().getPluginManager().getPlugin("CraftIRC");
if (checkplugin == null || !checkplugin.isEnabled()) {
@@ -40,8 +27,7 @@ public void onEnable() {
// Get handle to CraftIRC, add&register your custom listener
craftircHandle = (CraftIRC) checkplugin;
ircListener = new CraftIRCPluginExampleListener(craftircHandle);
- this.getServer().getPluginManager()
- .registerEvent(Event.Type.CUSTOM_EVENT, ircListener, Priority.Monitor, this);
+ this.getServer().getPluginManager().registerEvents(ircListener, this);
// Server owners who use CraftIRC can assign 'tags' to their bots or IRC channels, they should specify
// which of these tags to associate with your plugin, in your plugin's configuration.
@@ -60,9 +46,6 @@ public void onEnable() {
}
- /* (non-Javadoc)
- * @see org.bukkit.plugin.Plugin#onDisable()
- */
@Override
public void onDisable() {
View
42 com/ensifera/animosity/craftirc/example/CraftIRCPluginExampleListener.java
@@ -3,10 +3,8 @@
*/
package com.ensifera.animosity.craftirc.example;
-import org.bukkit.event.Event.Type;
-import org.bukkit.event.Event;
+import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
-import org.bukkit.event.CustomEventListener;
import com.ensifera.animosity.craftirc.CraftIRC;
import com.ensifera.animosity.craftirc.IRCEvent;
@@ -15,35 +13,31 @@
* @author Animosity
*
*/
-public class CraftIRCPluginExampleListener extends CustomEventListener implements Listener {
+public class CraftIRCPluginExampleListener implements Listener {
private CraftIRC plugin = null;
public CraftIRCPluginExampleListener(CraftIRC plugin) {
this.plugin = (CraftIRC) plugin;
}
- public void onCustomEvent(Event event) {
- if (!(event instanceof IRCEvent))
- return;
- else {
- IRCEvent ircEvent = (IRCEvent) event;
- if (!ircEvent.isHandled()) {
- switch (ircEvent.eventMode) {
- case COMMAND:
- if (ircEvent.msgData.message.startsWith("example")) {
- this.plugin.sendMessageToTag("This is an example custom CraftIRC command. The pen is %red%rrrrrrr%blue%oyal blue!",
- ircEvent.msgData.srcChannelTag);
- ircEvent.setHandled(true);
- }
- case AUTHED_COMMAND:
- if (ircEvent.msgData.message.startsWith("authexample")) {
- this.plugin.sendMessageToTag("This is an example custom %u%authenticated%u% CraftIRC command.",
- ircEvent.msgData.srcChannelTag);
- ircEvent.setHandled(true);
- }
+ @EventHandler
+ public void onCustomEvent(IRCEvent event) {
+ IRCEvent ircEvent = (IRCEvent) event;
+ if (!ircEvent.isHandled()) {
+ switch (ircEvent.eventMode) {
+ case COMMAND:
+ if (ircEvent.msgData.message.startsWith("example")) {
+ this.plugin.sendMessageToTag("This is an example custom CraftIRC command. The pen is %red%rrrrrrr%blue%oyal blue!",
+ ircEvent.msgData.srcChannelTag);
+ ircEvent.setHandled(true);
+ }
+ case AUTHED_COMMAND:
+ if (ircEvent.msgData.message.startsWith("authexample")) {
+ this.plugin.sendMessageToTag("This is an example custom %u%authenticated%u% CraftIRC command.",
+ ircEvent.msgData.srcChannelTag);
+ ircEvent.setHandled(true);
}
}
-
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.