Renamed hey0's plugin to SMWorldEdit. Made WorldEdit somewhat a singleton to hold the ServerInterface instance.

This commit is contained in:
sk89q 2010-10-14 11:59:45 -07:00
parent 5f1a014bfb
commit 92dc88562c
5 changed files with 73 additions and 26 deletions

View File

@ -41,7 +41,7 @@ public class EditSession {
/**
* Server interface.
*/
public static ServerInterface server;
protected ServerInterface server;
/**
* Stores the original blocks before modification.
@ -88,6 +88,7 @@ public class EditSession {
* Default constructor. There is no maximum blocks limit.
*/
public EditSession() {
server = WorldEdit.getServer();
}
/**
@ -98,6 +99,8 @@ public class EditSession {
throw new IllegalArgumentException("Max blocks must be >= -1");
}
this.maxBlocks = maxBlocks;
server = WorldEdit.getServer();
}
/**

View File

@ -26,11 +26,21 @@ import com.sk89q.worldedit.ServerInterface;
*
* @author sk89q
*/
public class WorldEditSM extends Plugin {
public class SMWorldEdit extends Plugin {
/**
* WorldEdit's properties file.
*/
private PropertiesFile properties;
private static final WorldEdit worldEdit = new WorldEdit();
private static final WorldEditSMListener listener =
new WorldEditSMListener(worldEdit);
/**
* WorldEdit instance.
*/
private static final WorldEdit worldEdit =
WorldEdit.setup(new SMServerInterface());
/**
* Listener for the plugin system.
*/
private static final SMWorldEditListener listener =
new SMWorldEditListener();
/**
* Initializes the plugin.
@ -49,10 +59,6 @@ public class WorldEditSM extends Plugin {
PluginListener.Priority.MEDIUM);
loader.addListener(PluginLoader.Hook.LOGIN, listener, this,
PluginListener.Priority.MEDIUM);
ServerInterface server = new SMServerInterface();
WorldEditPlayer.server = server;
EditSession.server = server;
}
/**

View File

@ -24,27 +24,14 @@ import com.sk89q.worldedit.*;
*
* @author sk89q
*/
public class WorldEditSMListener extends PluginListener {
/**
* Stores a reference to the WorldEdit object.
*/
private WorldEdit worldEdit;
/**
* Construct the listener with a reference to the WorldEdit object.
*
* @param worldEdit
*/
public WorldEditSMListener(WorldEdit worldEdit) {
this.worldEdit = worldEdit;
}
public class SMWorldEditListener extends PluginListener {
/**
*
* @param player
*/
@Override
public void onDisconnect(Player player) {
WorldEdit worldEdit = WorldEdit.getInstance();
worldEdit.removeSession(new SMWorldEditPlayer(player));
}
@ -60,6 +47,7 @@ public class WorldEditSMListener extends PluginListener {
@Override
public boolean onBlockCreate(Player modPlayer, Block blockPlaced,
Block blockClicked, int itemInHand) {
WorldEdit worldEdit = WorldEdit.getInstance();
WorldEditPlayer player = new SMWorldEditPlayer(modPlayer);
if (itemInHand != 271) { return false; }
@ -94,6 +82,7 @@ public class WorldEditSMListener extends PluginListener {
if (!modPlayer.canUseCommand("/editpos1")
&& !modPlayer.canUseCommand("/.")) { return false; }
WorldEdit worldEdit = WorldEdit.getInstance();
WorldEditPlayer player = new SMWorldEditPlayer(modPlayer);
WorldEditSession session = worldEdit.getSession(player);
@ -133,6 +122,8 @@ public class WorldEditSMListener extends PluginListener {
*/
@Override
public boolean onCommand(Player modPlayer, String[] split) {
WorldEdit worldEdit = WorldEdit.getInstance();
try {
if (worldEdit.getCommands().containsKey(split[0])) {
if (modPlayer.canUseCommand(split[0])) {

View File

@ -33,6 +33,15 @@ import com.sk89q.worldedit.*;
* @author sk89q
*/
public class WorldEdit {
/**
* WorldEdit instance.
*/
private static WorldEdit instance;
/**
* Server interface.
*/
private ServerInterface server;
/**
* List of default allowed blocks.
*/
@ -65,10 +74,41 @@ public class WorldEdit {
*/
private int defaultChangeLimit = -1;
/**
* Set up an instance.
*
* @param server
* @return
*/
public static WorldEdit setup(ServerInterface server) {
WorldEdit worldEdit = new WorldEdit();
worldEdit.server = server;
instance = worldEdit;
return worldEdit;
}
/**
* Get WorldEdit instance.
*
* @return
*/
public static WorldEdit getInstance() {
return instance;
}
/**
* Get server interface.
*
* @return
*/
public static ServerInterface getServer() {
return instance.server;
}
/**
* Construct an instance of the plugin.
*/
public WorldEdit() {
private WorldEdit() {
commands.put("/editpos1", "Set editing position #1");
commands.put("/editpos2", "Set editing position #2");
commands.put("/toggleplace", "Toggle placing at pos #1");

View File

@ -28,7 +28,14 @@ public abstract class WorldEditPlayer {
/**
* Server interface.
*/
public static ServerInterface server;
protected ServerInterface server;
/**
* Construct the player.
*/
public WorldEditPlayer() {
server = WorldEdit.getServer();
}
/**
* Get the name of the player.