Using new event system.

This commit is contained in:
Olof Larsson 2012-01-25 14:36:33 +01:00
parent e0b79d504d
commit 689d8b3280
5 changed files with 41 additions and 63 deletions

View File

@ -1,8 +1,7 @@
name: mcore1 name: mcore1
version: 1 version: 1.0.0
depend: [Spout]
main: com.massivecraft.mcore1.MCore main: com.massivecraft.mcore1.MCore
authors: [Olof Larsson] authors: [Olof Larsson, Brett Flannigan]
commands: commands:
mcoresilenteater: mcoresilenteater:
description: ignore me. description: ignore me.

View File

@ -1,24 +1,29 @@
package com.massivecraft.mcore1; package com.massivecraft.mcore1;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerListener;
import org.bukkit.event.player.PlayerPreLoginEvent; import org.bukkit.event.player.PlayerPreLoginEvent;
import org.bukkit.event.server.ServerCommandEvent;
import com.massivecraft.mcore1.persist.IClassManager; import com.massivecraft.mcore1.persist.IClassManager;
import com.massivecraft.mcore1.persist.Persist; import com.massivecraft.mcore1.persist.Persist;
import com.massivecraft.mcore1.util.PlayerUtil; import com.massivecraft.mcore1.util.PlayerUtil;
public class MCorePlayerListener extends PlayerListener public class InternalListener implements Listener
{ {
MCore p; MCore p;
public MCorePlayerListener(MCore p) public InternalListener(MCore p)
{ {
this.p = p; this.p = p;
Bukkit.getServer().getPluginManager().registerEvents(this, this.p);
} }
@Override @EventHandler(priority = EventPriority.LOWEST)
public void onPlayerPreLogin(PlayerPreLoginEvent event) public void onPlayerPreLogin(PlayerPreLoginEvent event)
{ {
String id = event.getName(); String id = event.getName();
@ -36,7 +41,7 @@ public class MCorePlayerListener extends PlayerListener
} }
} }
@Override @EventHandler(priority = EventPriority.LOWEST)
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event)
{ {
if (event.isCancelled()) return; if (event.isCancelled()) return;
@ -45,4 +50,15 @@ public class MCorePlayerListener extends PlayerListener
event.setCancelled(true); event.setCancelled(true);
} }
} }
private final static String refCommand = "mcoresilenteater";
@EventHandler(priority = EventPriority.LOWEST)
public void onServerCommand(ServerCommandEvent event)
{
if (event.getCommand().length() == 0) return;
if (MCore.handleCommand(event.getSender(), event.getCommand(), false))
{
event.setCommand(refCommand);
}
}
} }

View File

@ -10,14 +10,9 @@ import java.util.Random;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.event.Event;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.Event.Type;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import com.massivecraft.mcore1.cmd.Cmd; import com.massivecraft.mcore1.cmd.Cmd;
import com.massivecraft.mcore1.lib.gson.GsonBuilder; import com.massivecraft.mcore1.lib.gson.GsonBuilder;
import com.massivecraft.mcore1.persist.One; import com.massivecraft.mcore1.persist.One;
@ -28,9 +23,7 @@ import com.massivecraft.mcore1.util.Txt;
public class MCore extends JavaPlugin public class MCore extends JavaPlugin
{ {
MCoreServerListener serverListener; InternalListener listener;
MCoreServerListenerMonitor serverListenerMonitor;
MCorePlayerListener playerListener;
// -------------------------------------------- // // -------------------------------------------- //
// PERSIST // PERSIST
@ -104,9 +97,7 @@ public class MCore extends JavaPlugin
public MCore() public MCore()
{ {
this.serverListener = new MCoreServerListener(this);
this.serverListenerMonitor = new MCoreServerListenerMonitor(this);
this.playerListener = new MCorePlayerListener(this);
} }
@Override @Override
@ -128,9 +119,7 @@ public class MCore extends JavaPlugin
getPersistInstances().clear(); getPersistInstances().clear();
// Register events // Register events
Bukkit.getPluginManager().registerEvent(Type.PLAYER_PRELOGIN, this.playerListener, Priority.Lowest, this); this.listener = new InternalListener(this);
Bukkit.getPluginManager().registerEvent(Type.PLAYER_COMMAND_PREPROCESS, this.playerListener, Event.Priority.Lowest, this);
Bukkit.getPluginManager().registerEvent(Type.SERVER_COMMAND, this.serverListener, Event.Priority.Lowest, this);
} }
public static GsonBuilder getGsonBuilder() public static GsonBuilder getGsonBuilder()
@ -141,6 +130,21 @@ public class MCore extends JavaPlugin
.excludeFieldsWithModifiers(Modifier.TRANSIENT); .excludeFieldsWithModifiers(Modifier.TRANSIENT);
} }
// -------------------------------------------- //
// SPOUT INTEGRATION
// -------------------------------------------- //
/*protected boolean spoutIsIntegrated = false;
protected void integrateSpout()
{
if (spoutIsIntegrated) return;
if ( ! Bukkit.getPluginManager().isPluginEnabled("Spout")) return;
// Ok we should be safe :) Lets integrate!
this.spoutIsIntegrated = true;
}*/
// -------------------------------------------- // // -------------------------------------------- //
// LOGGING // LOGGING
// -------------------------------------------- // // -------------------------------------------- //

View File

@ -1,27 +0,0 @@
package com.massivecraft.mcore1;
import org.bukkit.event.server.ServerCommandEvent;
import org.bukkit.event.server.ServerListener;
public class MCoreServerListener extends ServerListener
{
MCore p;
private final static String refCommand = "mcoresilenteater";
public MCoreServerListener(MCore p)
{
this.p = p;
}
@Override
public void onServerCommand(ServerCommandEvent event)
{
if (event.getCommand().length() == 0) return;
if (MCore.handleCommand(event.getSender(), event.getCommand(), false))
{
event.setCommand(refCommand);
}
}
}

View File

@ -1,14 +0,0 @@
package com.massivecraft.mcore1;
import org.bukkit.event.server.ServerListener;
public class MCoreServerListenerMonitor extends ServerListener
{
MCore p;
public MCoreServerListenerMonitor(MCore p)
{
this.p = p;
}
}