New Event code for EssentialsSpawn

This commit is contained in:
snowleo 2012-01-20 05:34:28 +01:00
parent 792f70efa5
commit 04a43eb5d0
4 changed files with 34 additions and 16 deletions

View File

@ -6,7 +6,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import org.bukkit.ChatColor;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.EventPriority;
public interface ISettings extends IConf
@ -151,7 +151,7 @@ public interface ISettings extends IConf
boolean getDisableItemPickupWhileAfk();
Priority getRespawnPriority();
EventPriority getRespawnPriority();
long getTpaAcceptCancellation();
}

View File

@ -8,7 +8,7 @@ import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.ChatColor;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.EventPriority;
import org.bukkit.inventory.ItemStack;
@ -599,30 +599,30 @@ public class Settings implements ISettings
}
@Override
public Priority getRespawnPriority()
public EventPriority getRespawnPriority()
{
String priority = config.getString("respawn-listener-priority", "normal").toLowerCase(Locale.ENGLISH);
if ("lowest".equals(priority))
{
return Priority.Lowest;
return EventPriority.LOWEST;
}
if ("low".equals(priority))
{
return Priority.Low;
return EventPriority.LOW;
}
if ("normal".equals(priority))
{
return Priority.Normal;
return EventPriority.NORMAL;
}
if ("high".equals(priority))
{
return Priority.High;
return EventPriority.HIGH;
}
if ("highest".equals(priority))
{
return Priority.Highest;
return EventPriority.HIGHEST;
}
return Priority.Normal;
return EventPriority.NORMAL;
}
@Override

View File

@ -8,8 +8,14 @@ import java.util.logging.Logger;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
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.event.EventException;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.plugin.EventExecutor;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
@ -38,8 +44,22 @@ public class EssentialsSpawn extends JavaPlugin
ess.addReloadListener(spawns);
final EssentialsSpawnPlayerListener playerListener = new EssentialsSpawnPlayerListener(ess, spawns);
pluginManager.registerEvent(Type.PLAYER_RESPAWN, playerListener, ess.getSettings().getRespawnPriority(), this);
pluginManager.registerEvent(Type.PLAYER_JOIN, playerListener, ess.getSettings().getRespawnPriority(), this);
pluginManager.registerEvent(PlayerRespawnEvent.class, playerListener, ess.getSettings().getRespawnPriority(), new EventExecutor()
{
@Override
public void execute(final Listener ll, final Event event) throws EventException
{
((EssentialsSpawnPlayerListener)ll).onPlayerRespawn((PlayerRespawnEvent)event);
}
}, this);
pluginManager.registerEvent(PlayerJoinEvent.class, playerListener, ess.getSettings().getRespawnPriority(), new EventExecutor()
{
@Override
public void execute(final Listener ll, final Event event) throws EventException
{
((EssentialsSpawnPlayerListener)ll).onPlayerJoin((PlayerJoinEvent)event);
}
}, this);
LOGGER.info(_("loadinfo", this.getDescription().getName(), this.getDescription().getVersion(), "essentials team"));
}

View File

@ -7,13 +7,13 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerListener;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
public class EssentialsSpawnPlayerListener extends PlayerListener
public class EssentialsSpawnPlayerListener implements Listener
{
private final transient IEssentials ess;
private final transient SpawnStorage spawns;
@ -26,7 +26,6 @@ public class EssentialsSpawnPlayerListener extends PlayerListener
this.spawns = spawns;
}
@Override
public void onPlayerRespawn(final PlayerRespawnEvent event)
{
final User user = ess.getUser(event.getPlayer());
@ -51,7 +50,6 @@ public class EssentialsSpawnPlayerListener extends PlayerListener
}
}
@Override
public void onPlayerJoin(final PlayerJoinEvent event)
{
final User user = ess.getUser(event.getPlayer());