Minor change to Editor

This commit is contained in:
fullwall 2012-02-27 22:35:54 +08:00
parent 0ef4192769
commit 164d7467ad
2 changed files with 14 additions and 3 deletions

View File

@ -156,7 +156,7 @@ public class EventListen implements Listener {
*/
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
Editor.leaveEditor(event.getPlayer());
Editor.leave(event.getPlayer());
}
@EventHandler

View File

@ -16,7 +16,7 @@ public abstract class Editor implements Listener {
public abstract void end();
public static void enterEditor(Player player, Editor editor) {
public static void enter(Player player, Editor editor) {
if (editing.containsKey(player.getName())) {
Messaging.sendError(player, "You're already in an editor!");
return;
@ -26,7 +26,18 @@ public abstract class Editor implements Listener {
editing.put(player.getName(), editor);
}
public static void leaveEditor(Player player) {
public static void enterOrLeave(Player player, Editor editor) {
Editor edit = editing.get(player.getName());
if (edit == null) {
enter(player, editor);
} else if (edit.getClass() == editor.getClass()) {
leave(player);
} else {
Messaging.sendError(player, "You're already in an editor!");
}
}
public static void leave(Player player) {
if (!editing.containsKey(player.getName()))
return;
Editor editor = editing.remove(player.getName());