From 3960726d7a85bbd36b8d6928959768996f3abab0 Mon Sep 17 00:00:00 2001 From: TomyLobo Date: Tue, 13 Dec 2011 03:27:06 +0100 Subject: [PATCH] Installed a LocalCommandSender class atop LocalPlayer in the hierarchy and moved the relevant methods there. Also changed equals to work on LocalCommandSender instead of LocalPlayer. --- .../sk89q/worldedit/LocalCommandSender.java | 117 ++++++++++++++++++ .../java/com/sk89q/worldedit/LocalPlayer.java | 112 +---------------- 2 files changed, 119 insertions(+), 110 deletions(-) create mode 100644 src/main/java/com/sk89q/worldedit/LocalCommandSender.java diff --git a/src/main/java/com/sk89q/worldedit/LocalCommandSender.java b/src/main/java/com/sk89q/worldedit/LocalCommandSender.java new file mode 100644 index 000000000..f60c96921 --- /dev/null +++ b/src/main/java/com/sk89q/worldedit/LocalCommandSender.java @@ -0,0 +1,117 @@ +package com.sk89q.worldedit; + +import java.io.File; + +public abstract class LocalCommandSender { + /** + * Server. + */ + protected ServerInterface server; + + public LocalCommandSender(ServerInterface server) { + this.server = server; + } + + /** + * Get the name of the player. + * + * @return String + */ + public abstract String getName(); + + /** + * Print a message. + * + * @param msg + */ + public abstract void printRaw(String msg); + + /** + * Print a WorldEdit message. + * + * @param msg + */ + public abstract void printDebug(String msg); + + /** + * Print a WorldEdit message. + * + * @param msg + */ + public abstract void print(String msg); + + /** + * Print a WorldEdit error. + * + * @param msg + */ + public abstract void printError(String msg); + + /** + * Get a player's list of groups. + * + * @return + */ + public abstract String[] getGroups(); + + /** + * Checks if a player has permission. + * + * @param perm + * @return + */ + public abstract boolean hasPermission(String perm); + + public void checkPermission(String permission) throws WorldEditPermissionException { + if (!hasPermission(permission)) { + throw new WorldEditPermissionException(); + } + } + + /** + * Open a file open dialog. + * + * @param extensions null to allow all + * @return + */ + public File openFileOpenDialog(String[] extensions) { + printError("File dialogs are not supported in your environment."); + return null; + } + + /** + * Open a file save dialog. + * + * @param extensions null to allow all + * @return + */ + public File openFileSaveDialog(String[] extensions) { + printError("File dialogs are not supported in your environment."); + return null; + } + + /** + * Returns true if equal. + * + * @param other + * @return whether the other object is equivalent + */ + @Override + public boolean equals(Object other) { + if (!(other instanceof LocalCommandSender)) { + return false; + } + LocalCommandSender other2 = (LocalCommandSender) other; + return other2.getName().equals(getName()); + } + + /** + * Gets the hash code. + * + * @return hash code + */ + @Override + public int hashCode() { + return getName().hashCode(); + } +} diff --git a/src/main/java/com/sk89q/worldedit/LocalPlayer.java b/src/main/java/com/sk89q/worldedit/LocalPlayer.java index 7e8971c63..c801e0299 100644 --- a/src/main/java/com/sk89q/worldedit/LocalPlayer.java +++ b/src/main/java/com/sk89q/worldedit/LocalPlayer.java @@ -19,7 +19,6 @@ package com.sk89q.worldedit; -import java.io.File; import com.sk89q.worldedit.bags.BlockBag; import com.sk89q.worldedit.blocks.BlockID; import com.sk89q.worldedit.blocks.BlockType; @@ -31,19 +30,14 @@ import com.sk89q.worldedit.util.TargetBlock; * * @author sk89q */ -public abstract class LocalPlayer { - /** - * Server. - */ - protected ServerInterface server; - +public abstract class LocalPlayer extends LocalCommandSender { /** * Construct the object. * * @param server */ protected LocalPlayer(ServerInterface server) { - this.server = server; + super(server); } /** @@ -412,13 +406,6 @@ public abstract class LocalPlayer { */ public abstract int getItemInHand(); - /** - * Get the name of the player. - * - * @return String - */ - public abstract String getName(); - /** * Get the player's position. * @@ -514,34 +501,6 @@ public abstract class LocalPlayer { return false; } - /** - * Print a message. - * - * @param msg - */ - public abstract void printRaw(String msg); - - /** - * Print a WorldEdit message. - * - * @param msg - */ - public abstract void printDebug(String msg); - - /** - * Print a WorldEdit message. - * - * @param msg - */ - public abstract void print(String msg); - - /** - * Print a WorldEdit error. - * - * @param msg - */ - public abstract void printError(String msg); - /** * Move the player. * @@ -560,13 +519,6 @@ public abstract class LocalPlayer { setPosition(pos, (float) getPitch(), (float) getYaw()); } - /** - * Get a player's list of groups. - * - * @return - */ - public abstract String[] getGroups(); - /** * Get this player's block bag. * @@ -574,36 +526,6 @@ public abstract class LocalPlayer { */ public abstract BlockBag getInventoryBlockBag(); - /** - * Checks if a player has permission. - * - * @param perm - * @return - */ - public abstract boolean hasPermission(String perm); - - /** - * Open a file open dialog. - * - * @param extensions null to allow all - * @return - */ - public File openFileOpenDialog(String[] extensions) { - printError("File dialogs are not supported in your environment."); - return null; - } - - /** - * Open a file save dialog. - * - * @param extensions null to allow all - * @return - */ - public File openFileSaveDialog(String[] extensions) { - printError("File dialogs are not supported in your environment."); - return null; - } - /** * Returns true if the player can destroy bedrock. * @@ -627,34 +549,4 @@ public abstract class LocalPlayer { public void dispatchCUIHandshake() { } - /** - * Returns true if equal. - * - * @param other - * @return whether the other object is equivalent - */ - @Override - public boolean equals(Object other) { - if (!(other instanceof LocalPlayer)) { - return false; - } - LocalPlayer other2 = (LocalPlayer) other; - return other2.getName().equals(getName()); - } - - /** - * Gets the hash code. - * - * @return hash code - */ - @Override - public int hashCode() { - return getName().hashCode(); - } - - public void checkPermission(String permission) throws WorldEditPermissionException { - if (!hasPermission(permission)) { - throw new WorldEditPermissionException(); - } - } }