From 164d7467ad6d1d55346e25c10ed742d3f2e58452 Mon Sep 17 00:00:00 2001 From: fullwall Date: Mon, 27 Feb 2012 22:35:54 +0800 Subject: [PATCH] Minor change to Editor --- src/main/java/net/citizensnpcs/EventListen.java | 2 +- src/main/java/net/citizensnpcs/editor/Editor.java | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/citizensnpcs/EventListen.java b/src/main/java/net/citizensnpcs/EventListen.java index 261b55839..71a9d7188 100644 --- a/src/main/java/net/citizensnpcs/EventListen.java +++ b/src/main/java/net/citizensnpcs/EventListen.java @@ -156,7 +156,7 @@ public class EventListen implements Listener { */ @EventHandler public void onPlayerQuit(PlayerQuitEvent event) { - Editor.leaveEditor(event.getPlayer()); + Editor.leave(event.getPlayer()); } @EventHandler diff --git a/src/main/java/net/citizensnpcs/editor/Editor.java b/src/main/java/net/citizensnpcs/editor/Editor.java index 81a26a47f..c2acccccf 100644 --- a/src/main/java/net/citizensnpcs/editor/Editor.java +++ b/src/main/java/net/citizensnpcs/editor/Editor.java @@ -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());