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.
Dieser Commit ist enthalten in:
TomyLobo 2011-12-13 03:27:06 +01:00
Ursprung f5c6678da6
Commit 3960726d7a
2 geänderte Dateien mit 119 neuen und 110 gelöschten Zeilen

Datei anzeigen

@ -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();
}
}

Datei anzeigen

@ -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();
}
}
}