Cleaned up some code, changed WorldEdit to be world-aware (finally).

Dieser Commit ist enthalten in:
sk89q 2011-01-01 10:33:18 -08:00
Ursprung 6d172891e2
Commit ac4e6e8ddf
12 geänderte Dateien mit 783 neuen und 442 gelöschten Zeilen

Datei anzeigen

@ -17,9 +17,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.ServerInterface;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldEditPlayer;
import com.sk89q.worldedit.WorldVector;
import com.sk89q.worldedit.bags.BlockBag;
import com.sk89q.worldedit.blocks.BlockType;
@ -38,8 +40,8 @@ public class HMPlayer extends WorldEditPlayer {
*
* @param player
*/
public HMPlayer(Player player) {
super();
public HMPlayer(ServerInterface server, Player player) {
super(server);
this.player = player;
}
@ -58,13 +60,13 @@ public class HMPlayer extends WorldEditPlayer {
* @param range
* @return point
*/
public Vector getBlockTrace(int range) {
public WorldVector getBlockTrace(int range) {
HitBlox hitBlox = new HitBlox(player,range, 0.2);
Block block = hitBlox.getTargetBlock();
if (block == null) {
return null;
}
return new Vector(block.getX(), block.getY(), block.getZ());
return new WorldVector(null, block.getX(), block.getY(), block.getZ());
}
/**
@ -73,7 +75,7 @@ public class HMPlayer extends WorldEditPlayer {
* @param range
* @return point
*/
public Vector getSolidBlockTrace(int range) {
public WorldVector getSolidBlockTrace(int range) {
HitBlox hitBlox = new HitBlox(player,range, 0.2);
Block block = null;
@ -85,7 +87,7 @@ public class HMPlayer extends WorldEditPlayer {
if (block == null) {
return null;
}
return new Vector(block.getX(), block.getY(), block.getZ());
return new WorldVector(null, block.getX(), block.getY(), block.getZ());
}
/**
@ -130,8 +132,17 @@ public class HMPlayer extends WorldEditPlayer {
*
* @return point
*/
public Vector getPosition() {
return new Vector(player.getX(), player.getY(), player.getZ());
public WorldVector getPosition() {
return new WorldVector(null, player.getX(), player.getY(), player.getZ());
}
/**
* Get the player's world.
*
* @return point
*/
public LocalWorld getWorld() {
return null;
}
/**
@ -174,6 +185,7 @@ public class HMPlayer extends WorldEditPlayer {
boolean foundNext = false;
int searchDist = 0;
HitBlox hitBlox = new HitBlox(player,range, 0.2);
LocalWorld world = getPosition().getWorld();
Block block;
while ((block = hitBlox.getNextBlock()) != null) {
searchDist++;
@ -183,7 +195,7 @@ public class HMPlayer extends WorldEditPlayer {
if (block.getType() == 0) {
if (foundNext) {
Vector v = new Vector(block.getX(), block.getY() - 1, block.getZ());
if (server.getBlockType(v) == 0) {
if (server.getBlockType(world, v) == 0) {
setPosition(v.add(0.5, 0, 0.5));
return true;
}

Datei anzeigen

@ -43,7 +43,7 @@ public class HMServerInterface extends ServerInterface {
* @param type
* @return
*/
public boolean setBlockType(Vector pt, int type) {
public boolean setBlockType(LocalWorld world, Vector pt, int type) {
// Can't set colored cloth or crash
if ((type >= 21 && type <= 34) || type == 36) {
return false;
@ -58,7 +58,7 @@ public class HMServerInterface extends ServerInterface {
* @param pt
* @return
*/
public int getBlockType(Vector pt) {
public int getBlockType(LocalWorld world, Vector pt) {
return etc.getServer().getBlockIdAt(pt.getBlockX(), pt.getBlockY(),
pt.getBlockZ());
}
@ -70,7 +70,7 @@ public class HMServerInterface extends ServerInterface {
* @param data
* @return
*/
public void setBlockData(Vector pt, int data) {
public void setBlockData(LocalWorld world, Vector pt, int data) {
etc.getServer().setBlockData(pt.getBlockX(), pt.getBlockY(),
pt.getBlockZ(), data);
}
@ -81,7 +81,7 @@ public class HMServerInterface extends ServerInterface {
* @param pt
* @return
*/
public int getBlockData(Vector pt) {
public int getBlockData(LocalWorld world, Vector pt) {
return etc.getServer().getBlockData(pt.getBlockX(), pt.getBlockY(),
pt.getBlockZ());
}
@ -92,7 +92,7 @@ public class HMServerInterface extends ServerInterface {
* @param pt
* @param text
*/
public void setSignText(Vector pt, String[] text) {
public void setSignText(LocalWorld world, Vector pt, String[] text) {
Sign signData = (Sign)etc.getServer().getComplexBlock(
pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
if (signData == null) {
@ -110,7 +110,7 @@ public class HMServerInterface extends ServerInterface {
* @param pt
* @return
*/
public String[] getSignText(Vector pt) {
public String[] getSignText(LocalWorld world, Vector pt) {
Sign signData = (Sign)etc.getServer().getComplexBlock(
pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
if (signData == null) {
@ -130,7 +130,7 @@ public class HMServerInterface extends ServerInterface {
* @param pt
* @return
*/
public BaseItemStack[] getChestContents(Vector pt) {
public BaseItemStack[] getChestContents(LocalWorld world, Vector pt) {
ComplexBlock cblock = etc.getServer().getOnlyComplexBlock(
pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
@ -165,7 +165,7 @@ public class HMServerInterface extends ServerInterface {
* @param contents
* @return
*/
public boolean setChestContents(Vector pt,
public boolean setChestContents(LocalWorld world, Vector pt,
BaseItemStack[] contents) {
ComplexBlock cblock = etc.getServer().getOnlyComplexBlock(
@ -197,7 +197,7 @@ public class HMServerInterface extends ServerInterface {
*
* @param pt
*/
public boolean clearChest(Vector pt) {
public boolean clearChest(LocalWorld world, Vector pt) {
ComplexBlock cblock = etc.getServer().getOnlyComplexBlock(
pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
@ -247,7 +247,7 @@ public class HMServerInterface extends ServerInterface {
* @param pt
* @param mobType
*/
public void setMobSpawnerType(Vector pt, String mobType) {
public void setMobSpawnerType(LocalWorld world, Vector pt, String mobType) {
ComplexBlock cblock = etc.getServer().getComplexBlock(
pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
@ -266,7 +266,7 @@ public class HMServerInterface extends ServerInterface {
* @param pt
* @param mobType
*/
public String getMobSpawnerType(Vector pt) {
public String getMobSpawnerType(LocalWorld world, Vector pt) {
try {
return MinecraftServerInterface.getMobSpawnerType(pt);
} catch (Throwable t) {
@ -282,7 +282,7 @@ public class HMServerInterface extends ServerInterface {
* @param pt
* @return
*/
public boolean generateTree(EditSession editSession, Vector pt) {
public boolean generateTree(EditSession editSession, LocalWorld world, Vector pt) {
try {
return MinecraftServerInterface.generateTree(editSession, pt);
} catch (Throwable t) {
@ -300,7 +300,7 @@ public class HMServerInterface extends ServerInterface {
* @param count
* @param times
*/
public void dropItem(Vector pt, int type, int count, int times) {
public void dropItem(LocalWorld world, Vector pt, int type, int count, int times) {
for (int i = 0; i < times; i++) {
etc.getServer().dropItem(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(),
type, count);
@ -315,7 +315,7 @@ public class HMServerInterface extends ServerInterface {
* @param count
* @param times
*/
public void dropItem(Vector pt, int type, int count) {
public void dropItem(LocalWorld world, Vector pt, int type, int count) {
etc.getServer().dropItem(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(),
type, count);
}
@ -328,7 +328,7 @@ public class HMServerInterface extends ServerInterface {
* @param count
* @param times
*/
public void dropItem(Vector pt, int type) {
public void dropItem(LocalWorld world, Vector pt, int type) {
etc.getServer().dropItem(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(),
type, 1);
}
@ -338,57 +338,57 @@ public class HMServerInterface extends ServerInterface {
*
* @param pt
*/
public void simulateBlockMine(Vector pt) {
int type = getBlockType(pt);
setBlockType(pt, 0);
public void simulateBlockMine(LocalWorld world, Vector pt) {
int type = getBlockType(world, pt);
setBlockType(world, pt, 0);
if (type == 1) { dropItem(pt, 4); } // Stone
else if (type == 2) { dropItem(pt, 3); } // Grass
if (type == 1) { dropItem(world, pt, 4); } // Stone
else if (type == 2) { dropItem(world, pt, 3); } // Grass
else if (type == 7) { } // Bedrock
else if (type == 8) { } // Water
else if (type == 9) { } // Water
else if (type == 10) { } // Lava
else if (type == 11) { } // Lava
else if (type == 13) { // Gravel
dropItem(pt, type);
dropItem(world, pt, type);
if (random.nextDouble() >= 0.9) {
dropItem(pt, 318);
dropItem(world, pt, 318);
}
}
else if (type == 16) { dropItem(pt, 263); } // Coal ore
else if (type == 16) { dropItem(world, pt, 263); } // Coal ore
else if (type == 18) { // Leaves
if (random.nextDouble() > 0.95) {
dropItem(pt, 6);
dropItem(world, pt, 6);
}
}
else if (type == 20) { } // Glass
else if (type == 43) { dropItem(pt, 44); } // Double step
else if (type == 43) { dropItem(world, pt, 44); } // Double step
else if (type == 47) { } // Bookshelves
else if (type == 51) { } // Fire
else if (type == 52) { } // Mob spawner
else if (type == 53) { dropItem(pt, 5); } // Wooden stairs
else if (type == 55) { dropItem(pt, 331); } // Redstone wire
else if (type == 56) { dropItem(pt, 264); } // Diamond ore
else if (type == 59) { dropItem(pt, 295); } // Crops
else if (type == 60) { dropItem(pt, 3); } // Soil
else if (type == 62) { dropItem(pt, 61); } // Furnace
else if (type == 63) { dropItem(pt, 323); } // Sign post
else if (type == 64) { dropItem(pt, 324); } // Wood door
else if (type == 67) { dropItem(pt, 4); } // Cobblestone stairs
else if (type == 68) { dropItem(pt, 323); } // Wall sign
else if (type == 71) { dropItem(pt, 330); } // Iron door
else if (type == 73) { dropItem(pt, 331, 1, 4); } // Redstone ore
else if (type == 74) { dropItem(pt, 331, 1, 4); } // Glowing redstone ore
else if (type == 75) { dropItem(pt, 76); } // Redstone torch
else if (type == 53) { dropItem(world, pt, 5); } // Wooden stairs
else if (type == 55) { dropItem(world, pt, 331); } // Redstone wire
else if (type == 56) { dropItem(world, pt, 264); } // Diamond ore
else if (type == 59) { dropItem(world, pt, 295); } // Crops
else if (type == 60) { dropItem(world, pt, 3); } // Soil
else if (type == 62) { dropItem(world, pt, 61); } // Furnace
else if (type == 63) { dropItem(world, pt, 323); } // Sign post
else if (type == 64) { dropItem(world, pt, 324); } // Wood door
else if (type == 67) { dropItem(world, pt, 4); } // Cobblestone stairs
else if (type == 68) { dropItem(world, pt, 323); } // Wall sign
else if (type == 71) { dropItem(world, pt, 330); } // Iron door
else if (type == 73) { dropItem(world, pt, 331, 1, 4); } // Redstone ore
else if (type == 74) { dropItem(world, pt, 331, 1, 4); } // Glowing redstone ore
else if (type == 75) { dropItem(world, pt, 76); } // Redstone torch
else if (type == 78) { } // Snow
else if (type == 79) { } // Ice
else if (type == 82) { dropItem(pt, 337, 1, 4); } // Clay
else if (type == 83) { dropItem(pt, 338); } // Reed
else if (type == 89) { dropItem(pt, 348); } // Lightstone
else if (type == 82) { dropItem(world, pt, 337, 1, 4); } // Clay
else if (type == 83) { dropItem(world, pt, 338); } // Reed
else if (type == 89) { dropItem(world, pt, 348); } // Lightstone
else if (type == 90) { } // Portal
else if (type != 0) {
dropItem(pt, type);
dropItem(world, pt, type);
}
}
@ -409,7 +409,7 @@ public class HMServerInterface extends ServerInterface {
* @param radius
* @return
*/
public int killMobs(Vector origin, int radius) {
public int killMobs(LocalWorld world, Vector origin, int radius) {
int killed = 0;
for (Mob mob : etc.getServer().getMobList()) {

Datei anzeigen

@ -17,11 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;
import java.util.Set;
import java.util.HashSet;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -29,16 +25,10 @@ import java.util.logging.Handler;
import java.util.logging.FileHandler;
import java.io.*;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.bags.BlockBag;
import com.sk89q.worldedit.blocks.*;
import com.sk89q.worldedit.data.*;
import com.sk89q.worldedit.filters.*;
import com.sk89q.worldedit.snapshots.*;
import com.sk89q.worldedit.regions.*;
import com.sk89q.worldedit.patterns.*;
/**
* Plugin base.
* The event listener for WorldEdit in hMod.
*
* @author sk89q
*/
@ -47,23 +37,36 @@ public class HMWorldEditListener extends PluginListener {
* Logger.
*/
private static final Logger logger = Logger.getLogger("Minecraft.WorldEdit");
/**
* WorldEditLibrary's properties file.
* Properties file.
*/
private PropertiesFile properties;
/**
* Main WorldEdit controller.
*/
private WorldEditController controller = new WorldEditController();
private WorldEditController controller;
/**
* A copy of the server instance. This is where all world<->WorldEdit calls
* will go through.
*/
private ServerInterface server;
/**
* Constructs an instance.
*
* @param server
*/
public HMWorldEditListener(ServerInterface server) {
this.server = server;
}
/**
*
* @param player
*/
@Override
public void onDisconnect(Player player) {
controller.handleDisconnect(new HMPlayer(player));
controller.handleDisconnect(wrapPlayer(player));
}
/**
@ -72,7 +75,7 @@ public class HMWorldEditListener extends PluginListener {
* @param player
*/
public void onArmSwing(Player player) {
controller.handleArmSwing(new HMPlayer(player));
controller.handleArmSwing(wrapPlayer(player));
}
/**
@ -91,7 +94,7 @@ public class HMWorldEditListener extends PluginListener {
Vector pos = new Vector(blockClicked.getX(),
blockClicked.getY(),
blockClicked.getZ());
return controller.handleBlockRightClick(new HMPlayer(player), pos);
return controller.handleBlockRightClick(wrapPlayer(player), pos);
}
/**
@ -107,7 +110,7 @@ public class HMWorldEditListener extends PluginListener {
Vector pos = new Vector(blockClicked.getX(),
blockClicked.getY(),
blockClicked.getZ());
return controller.handleBlockLeftClick(new HMPlayer(player), pos);
return controller.handleBlockLeftClick(wrapPlayer(player), pos);
}
/**
@ -118,7 +121,7 @@ public class HMWorldEditListener extends PluginListener {
*/
@Override
public boolean onCommand(Player player, String[] split) {
return controller.handleCommand(new HMPlayer(player), split);
return controller.handleCommand(wrapPlayer(player), split);
}
/**
@ -222,6 +225,10 @@ public class HMWorldEditListener extends PluginListener {
* @return
*/
public WorldEditSession _bridgeSession(Player player) {
return controller.getBridgeSession(new HMPlayer(player));
return controller.getBridgeSession(wrapPlayer(player));
}
private WorldEditPlayer wrapPlayer(Player player) {
return new HMPlayer(server, player);
}
}

Datei anzeigen

@ -15,7 +15,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
import java.util.logging.Level;
import java.util.logging.Logger;
@ -31,22 +31,28 @@ public class WorldEdit extends Plugin {
/**
* Logger.
*/
private static final Logger logger = Logger.getLogger("Minecraft.WorldEdit");
/**
* WorldEditLibrary instance.
*/
private static HMWorldEditListener listener;
private static final Logger logger = Logger
.getLogger("Minecraft.WorldEdit");
/**
* WorldEdit version, fetched from the .jar's manifest. Used to print the
* WorldEdit version in various places.
* The event listener for WorldEdit an hMod. Configuration and such is
* also loaded here as well, although the core of the WorldEdit is
* actually in com.sk89q.worldedit.WorldEditController and is merely
* loaded by this listener.
*/
private final HMWorldEditListener listener;
/**
* WorldEdit version, fetched from the .jar's manifest.
*/
private String version;
public WorldEdit() {
ServerInterface.setup(new HMServerInterface());
listener = new HMWorldEditListener();
}
/**
* Construct an instance of the plugin.
*/
public WorldEdit() {
listener = new HMWorldEditListener(new HMServerInterface());
}
/**
* Initializes the plugin.
@ -91,25 +97,25 @@ public class WorldEdit extends Plugin {
/**
* Get the CraftBook version.
*
*
* @return
*/
public String getVersion() {
if (version != null) {
return version;
}
Package p = WorldEdit.class.getPackage();
if (p == null) {
p = Package.getPackage("com.sk89q.worldedit");
}
if (p == null) {
version = "(unknown)";
} else {
version = p.getImplementationVersion();
if (version == null) {
version = "(unknown)";
}
@ -117,13 +123,4 @@ public class WorldEdit extends Plugin {
return version;
}
/**
* Returns the listener.
*
* @return
*/
public HMWorldEditListener getListener() {
return listener;
}
}

Datei anzeigen

@ -0,0 +1,101 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit;
/**
* Extension of Vector that supports being compared as ints (for accuracy).
*
* @author sk89q
*/
public class BlockWorldVector extends WorldVector {
/**
* Construct the Vector object.
*
* @param pt
*/
public BlockWorldVector(WorldVector pt) {
super(pt.getWorld(), pt);
}
/**
* Construct the Vector object.
*
* @param pt
*/
public BlockWorldVector(LocalWorld world, Vector pt) {
super(world, pt);
}
/**
* Construct the Vector object.
*
* @param pt
*/
public BlockWorldVector(LocalWorld world, int x, int y, int z) {
super(world, x, y, z);
}
/**
* Construct the Vector object.
*
* @param pt
*/
public BlockWorldVector(LocalWorld world, float x, float y, float z) {
super(world, x, y, z);
}
/**
* Construct the Vector object.
*
* @param pt
*/
public BlockWorldVector(LocalWorld world, double x, double y, double z) {
super(world, x, y, z);
}
/**
* Checks if another object is equivalent.
*
* @param obj
* @return whether the other object is equivalent
*/
@Override
public boolean equals(Object obj) {
if (!(obj instanceof WorldVector)) {
return false;
}
WorldVector other = (WorldVector)obj;
return (int)other.x == (int)this.x && (int)other.y == (int)this.y
&& (int)other.z == (int)this.z;
}
/**
* Gets the hash code.
*
* @return hash code
*/
@Override
public int hashCode() {
return (Integer.valueOf((int)x).hashCode() >> 13) ^
(Integer.valueOf((int)y).hashCode() >> 7) ^
Integer.valueOf((int)z).hashCode();
}
}

Datei-Diff unterdrückt, da er zu groß ist Diff laden

Datei anzeigen

@ -0,0 +1,41 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit;
/**
* Represents a world.
*
* @author sk89q
*/
public abstract class LocalWorld {
/**
* Compare if the other world is equal.
*
* @param other
* @return
*/
public abstract boolean equals(Object other);
/**
* Hash code.
*
* @return
*/
public abstract int hashCode();
}

Datei anzeigen

@ -15,113 +15,92 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
package com.sk89q.worldedit;
import com.sk89q.worldedit.blocks.BaseItemStack;
/**
*
*
* @author sk89q
*/
public abstract class ServerInterface {
/**
* Instance.
*/
private static ServerInterface instance;
/**
* Get the current instance.
*
* @return
*/
public static ServerInterface getInstance() {
return instance;
}
/**
* Set up an instance.
* @param instance
*/
public static void setup(ServerInterface instance) {
ServerInterface.instance = instance;
}
/**
* Set block type.
*
*
* @param pt
* @param type
* @return
*/
public abstract boolean setBlockType(Vector pt, int type);
public abstract boolean setBlockType(LocalWorld world, Vector pt, int type);
/**
* Get block type.
*
*
* @param pt
* @return
*/
public abstract int getBlockType(Vector pt);
public abstract int getBlockType(LocalWorld world, Vector pt);
/**
* Set block data.
*
*
* @param pt
* @param data
* @return
*/
public abstract void setBlockData(Vector pt, int data);
public abstract void setBlockData(LocalWorld world, Vector pt, int data);
/**
* Get block data.
*
*
* @param pt
* @return
*/
public abstract int getBlockData(Vector pt);
public abstract int getBlockData(LocalWorld world, Vector pt);
/**
* Set sign text.
*
*
* @param pt
* @param text
*/
public abstract void setSignText(Vector pt, String[] text);
public abstract void setSignText(LocalWorld world, Vector pt, String[] text);
/**
* Get sign text.
*
*
* @param pt
* @return
*/
public abstract String[] getSignText(Vector pt);
public abstract String[] getSignText(LocalWorld world, Vector pt);
/**
* Gets the contents of chests. Will return null if the chest does not
* really exist or it is the second block for a double chest.
*
*
* @param pt
* @return
*/
public abstract BaseItemStack[] getChestContents(Vector pt);
public abstract BaseItemStack[] getChestContents(LocalWorld world, Vector pt);
/**
* Sets a chest slot.
*
*
* @param pt
* @param contents
* @return
*/
public abstract boolean setChestContents(Vector pt, BaseItemStack[] contents);
public abstract boolean setChestContents(LocalWorld world, Vector pt,
BaseItemStack[] contents);
/**
* Clear a chest's contents.
*
* @param pt
*/
public abstract boolean clearChest(Vector pt);
public abstract boolean clearChest(LocalWorld world, Vector pt);
/**
* Checks if a mob type is valid.
@ -133,19 +112,20 @@ public abstract class ServerInterface {
/**
* Set mob spawner mob type.
*
*
* @param pt
* @param mobType
*/
public abstract void setMobSpawnerType(Vector pt, String mobType);
public abstract void setMobSpawnerType(LocalWorld world, Vector pt,
String mobType);
/**
* Get mob spawner mob type. May return an empty string.
*
*
* @param pt
* @param mobType
*/
public abstract String getMobSpawnerType(Vector pt);
public abstract String getMobSpawnerType(LocalWorld world, Vector pt);
/**
* Generate a tree at a location.
@ -153,45 +133,48 @@ public abstract class ServerInterface {
* @param pt
* @return
*/
public abstract boolean generateTree(EditSession editSession, Vector pt);
public abstract boolean generateTree(EditSession editSession,
LocalWorld world, Vector pt);
/**
* Drop an item.
*
*
* @param pt
* @param type
* @param count
* @param times
*/
public abstract void dropItem(Vector pt, int type, int count, int times);
public abstract void dropItem(LocalWorld world, Vector pt, int type,
int count, int times);
/**
* Drop an item.
*
*
* @param pt
* @param type
* @param count
* @param times
*/
public abstract void dropItem(Vector pt, int type, int count);
public abstract void dropItem(LocalWorld world, Vector pt, int type,
int count);
/**
* Drop an item.
*
*
* @param pt
* @param type
* @param count
* @param times
*/
public abstract void dropItem(Vector pt, int type);
public abstract void dropItem(LocalWorld world, Vector pt, int type);
/**
* Simulate a block being mined.
*
* @param pt
*/
public abstract void simulateBlockMine(Vector pt);
public abstract void simulateBlockMine(LocalWorld world, Vector pt);
/**
* Resolves an item name to its ID.
*
@ -207,5 +190,5 @@ public abstract class ServerInterface {
* @param radius
* @return
*/
public abstract int killMobs(Vector origin, int radius);
public abstract int killMobs(LocalWorld world, Vector origin, int radius);
}

Datei anzeigen

@ -21,7 +21,7 @@ package com.sk89q.worldedit;
/**
*
* @author Albert
* @author sk89q
*/
public class Vector {
protected final double x, y, z;

Datei anzeigen

@ -95,10 +95,12 @@ public class WorldEditController {
public boolean useInventoryOverride = false;
/**
* Construct an instance of the plugin.
* Construct an instance of the plugin
*
* @param server
*/
public WorldEditController() {
server = ServerInterface.getInstance();
public WorldEditController(ServerInterface server) {
this.server = server;
// Note: Commands should only have the phrase 'air' at the end
// for now (see SMWorldEditListener.canUseCommand)
@ -442,9 +444,9 @@ public class WorldEditController {
// Jump to the block in sight
} else if (split[0].equalsIgnoreCase("/jumpto")) {
checkArgs(split, 0, 0, split[0]);
Vector pos = player.getSolidBlockTrace(300);
WorldVector pos = player.getSolidBlockTrace(300);
if (pos != null) {
player.findFreePosition(pos);
player.findFreePosition(pos.getWorld(), pos);
player.print("Poof!");
} else {
player.printError("No block in sight!");
@ -1323,7 +1325,7 @@ public class WorldEditController {
Math.max(1, Integer.parseInt(split[1])) : -1;
Vector origin = session.getPlacementPosition(player);
int killed = server.killMobs(origin, radius);
int killed = server.killMobs(player.getWorld(), origin, radius);
player.print("Killed " + killed + " mobs.");
return true;
@ -1732,10 +1734,10 @@ public class WorldEditController {
} else if (player.isHoldingPickAxe()
&& session.getTool() == WorldEditSession.Tool.TREE) {
EditSession editSession =
new EditSession(session.getBlockChangeLimit());
new EditSession(server, player.getWorld(), session.getBlockChangeLimit());
try {
if (!server.generateTree(editSession, clicked)) {
if (!server.generateTree(editSession, player.getWorld(), clicked)) {
player.printError("Notch won't let you put a tree there.");
}
} finally {
@ -1745,7 +1747,7 @@ public class WorldEditController {
return true;
} else if (player.isHoldingPickAxe()
&& session.getTool() == WorldEditSession.Tool.INFO) {
BaseBlock block = (new EditSession(0)).rawGetBlock(clicked);
BaseBlock block = (new EditSession(server, player.getWorld(), 0)).rawGetBlock(clicked);
player.print("\u00A79@" + clicked + ": " + "\u00A7e"
+ "Type: " + block.getID() + "\u00A77" + " ("
@ -1805,20 +1807,22 @@ public class WorldEditController {
} else if (player.isHoldingPickAxe()) {
if (session.hasSuperPickAxe()) {
boolean canBedrock = canUseCommand(player, "/worldeditbedrock");
LocalWorld world = player.getWorld();
// Single block super pickaxe
if (session.getSuperPickaxeMode() ==
WorldEditSession.SuperPickaxeMode.SINGLE) {
if (server.getBlockType(clicked) == 7 && !canBedrock) {
if (server.getBlockType(world, clicked) == 7 && !canBedrock) {
return true;
} else if (server.getBlockType(clicked) == 46) {
} else if (server.getBlockType(world, clicked) == 46) {
return false;
}
if (superPickaxeDrop) {
server.simulateBlockMine(clicked);
server.simulateBlockMine(world, clicked);
} else {
server.setBlockType(clicked, 0);
server.setBlockType(world, clicked, 0);
}
// Area super pickaxe
@ -1828,7 +1832,7 @@ public class WorldEditController {
int oy = clicked.getBlockY();
int oz = clicked.getBlockZ();
int size = session.getSuperPickaxeRange();
int initialType = server.getBlockType(clicked);
int initialType = server.getBlockType(world, clicked);
if (initialType == 7 && !canBedrock) {
return true;
@ -1838,11 +1842,11 @@ public class WorldEditController {
for (int y = oy - size; y <= oy + size; y++) {
for (int z = oz - size; z <= oz + size; z++) {
Vector pos = new Vector(x, y, z);
if (server.getBlockType(pos) == initialType) {
if (server.getBlockType(world, pos) == initialType) {
if (superPickaxeManyDrop) {
server.simulateBlockMine(pos);
server.simulateBlockMine(world, pos);
} else {
server.setBlockType(pos, 0);
server.setBlockType(world, pos, 0);
}
}
}
@ -1855,13 +1859,13 @@ public class WorldEditController {
} else if (session.getSuperPickaxeMode() ==
WorldEditSession.SuperPickaxeMode.SAME_TYPE_RECURSIVE) {
int size = session.getSuperPickaxeRange();
int initialType = server.getBlockType(clicked);
int initialType = server.getBlockType(world, clicked);
if (initialType == 7 && !canBedrock) {
return true;
}
recursiveSuperPickaxe(clicked.toBlockVector(), clicked, size,
recursiveSuperPickaxe(world, clicked.toBlockVector(), clicked, size,
initialType, new HashSet<BlockVector>());
return true;
@ -1881,7 +1885,7 @@ public class WorldEditController {
* @param canBedrock
* @return
*/
private void recursiveSuperPickaxe(BlockVector pos, Vector origin,
private void recursiveSuperPickaxe(LocalWorld world, BlockVector pos, Vector origin,
int size, int initialType, Set<BlockVector> visited) {
if (origin.distance(pos) > size || visited.contains(pos)) {
return;
@ -1889,27 +1893,27 @@ public class WorldEditController {
visited.add(pos);
if (server.getBlockType(pos) == initialType) {
if (server.getBlockType(world, pos) == initialType) {
if (superPickaxeManyDrop) {
server.simulateBlockMine(pos);
server.simulateBlockMine(world, pos);
} else {
server.setBlockType(pos, 0);
server.setBlockType(world, pos, 0);
}
} else {
return;
}
recursiveSuperPickaxe(pos.add(1, 0, 0).toBlockVector(), origin, size,
recursiveSuperPickaxe(world, pos.add(1, 0, 0).toBlockVector(), origin, size,
initialType, visited);
recursiveSuperPickaxe(pos.add(-1, 0, 0).toBlockVector(), origin, size,
recursiveSuperPickaxe(world, pos.add(-1, 0, 0).toBlockVector(), origin, size,
initialType, visited);
recursiveSuperPickaxe(pos.add(0, 0, 1).toBlockVector(), origin, size,
recursiveSuperPickaxe(world, pos.add(0, 0, 1).toBlockVector(), origin, size,
initialType, visited);
recursiveSuperPickaxe(pos.add(0, 0, -1).toBlockVector(), origin, size,
recursiveSuperPickaxe(world, pos.add(0, 0, -1).toBlockVector(), origin, size,
initialType, visited);
recursiveSuperPickaxe(pos.add(0, 1, 0).toBlockVector(), origin, size,
recursiveSuperPickaxe(world, pos.add(0, 1, 0).toBlockVector(), origin, size,
initialType, visited);
recursiveSuperPickaxe(pos.add(0, -1, 0).toBlockVector(), origin, size,
recursiveSuperPickaxe(world, pos.add(0, -1, 0).toBlockVector(), origin, size,
initialType, visited);
}
@ -1943,7 +1947,8 @@ public class WorldEditController {
BlockBag blockBag = session.getBlockBag(player);
EditSession editSession =
new EditSession(session.getBlockChangeLimit(), blockBag);
new EditSession(server, player.getWorld(),
session.getBlockChangeLimit(), blockBag);
editSession.enableQueue();
long start = System.currentTimeMillis();

Datei anzeigen

@ -48,9 +48,11 @@ public abstract class WorldEditPlayer {
/**
* Construct the object.
*
* @param server
*/
protected WorldEditPlayer() {
server = ServerInterface.getInstance();
protected WorldEditPlayer(ServerInterface server) {
this.server = server;
}
/**
@ -72,7 +74,7 @@ public abstract class WorldEditPlayer {
*
* @param searchPos search position
*/
public void findFreePosition(Vector searchPos) {
public void findFreePosition(LocalWorld world, Vector searchPos) {
int x = searchPos.getBlockX();
int y = Math.max(0, searchPos.getBlockY());
int origY = y;
@ -81,7 +83,8 @@ public abstract class WorldEditPlayer {
byte free = 0;
while (y <= 129) {
if (BlockType.canPassThrough(server.getBlockType(new Vector(x, y, z)))) {
if (BlockType.canPassThrough(server.getBlockType(world,
new Vector(x, y, z)))) {
free++;
} else {
free = 0;
@ -106,7 +109,7 @@ public abstract class WorldEditPlayer {
* that free position.
*/
public void findFreePosition() {
findFreePosition(getBlockIn());
findFreePosition(getPosition().getWorld(), getBlockIn());
}
/**
@ -119,12 +122,13 @@ public abstract class WorldEditPlayer {
int x = pos.getBlockX();
int y = Math.max(0, pos.getBlockY());
int z = pos.getBlockZ();
LocalWorld world = getPosition().getWorld();
byte free = 0;
byte spots = 0;
while (y <= 129) {
if (BlockType.canPassThrough(server.getBlockType(new Vector(x, y, z)))) {
if (BlockType.canPassThrough(server.getBlockType(world, new Vector(x, y, z)))) {
free++;
} else {
free = 0;
@ -133,7 +137,7 @@ public abstract class WorldEditPlayer {
if (free == 2) {
spots++;
if (spots == 2) {
int type = server.getBlockType(new Vector(x, y - 2, z));
int type = server.getBlockType(world, new Vector(x, y - 2, z));
// Don't get put in lava!
if (type == 10 || type == 11) {
@ -161,11 +165,12 @@ public abstract class WorldEditPlayer {
int x = pos.getBlockX();
int y = Math.max(0, pos.getBlockY() - 1);
int z = pos.getBlockZ();
LocalWorld world = getPosition().getWorld();
byte free = 0;
while (y >= 1) {
if (BlockType.canPassThrough(server.getBlockType(new Vector(x, y, z)))) {
if (BlockType.canPassThrough(server.getBlockType(world, new Vector(x, y, z)))) {
free++;
} else {
free = 0;
@ -176,7 +181,7 @@ public abstract class WorldEditPlayer {
// lightly and also check to see if there's something to
// stand upon
while (y >= 0) {
int type = server.getBlockType(new Vector(x, y, z));
int type = server.getBlockType(world, new Vector(x, y, z));
// Don't want to end up in lava
if (type != 0 && type != 10 && type != 11) {
@ -209,17 +214,18 @@ public abstract class WorldEditPlayer {
int initialY = Math.max(0, pos.getBlockY());
int y = Math.max(0, pos.getBlockY() + 2);
int z = pos.getBlockZ();
LocalWorld world = getPosition().getWorld();
// No free space above
if (server.getBlockType(new Vector(x, y, z)) != 0) {
if (server.getBlockType(world, new Vector(x, y, z)) != 0) {
return false;
}
while (y <= 127) {
// Found a ceiling!
if (!BlockType.canPassThrough(server.getBlockType(new Vector(x, y, z)))) {
if (!BlockType.canPassThrough(server.getBlockType(world, new Vector(x, y, z)))) {
int platformY = Math.max(initialY, y - 3 - clearance);
server.setBlockType(new Vector(x, platformY, z),
server.setBlockType(world, new Vector(x, platformY, z),
BlockType.GLASS.getID());
setPosition(new Vector(x + 0.5, platformY + 1, z + 0.5));
return true;
@ -244,14 +250,15 @@ public abstract class WorldEditPlayer {
int y = Math.max(0, pos.getBlockY() + 1);
int z = pos.getBlockZ();
int maxY = Math.min(128, initialY + distance);
LocalWorld world = getPosition().getWorld();
while (y <= 129) {
if (!BlockType.canPassThrough(server.getBlockType(new Vector(x, y, z)))) {
if (!BlockType.canPassThrough(server.getBlockType(world, new Vector(x, y, z)))) {
break; // Hit something
} else if (y > maxY + 1) {
break;
} else if (y == maxY + 1) {
server.setBlockType(new Vector(x, y - 2, z),
server.setBlockType(world, new Vector(x, y - 2, z),
BlockType.GLASS.getID());
setPosition(new Vector(x + 0.5, y - 1, z + 0.5));
return true;
@ -268,8 +275,8 @@ public abstract class WorldEditPlayer {
*
* @return point
*/
public Vector getBlockIn() {
return getPosition().toBlockVector();
public WorldVector getBlockIn() {
return getPosition();
}
/**
@ -277,8 +284,9 @@ public abstract class WorldEditPlayer {
*
* @return point
*/
public Vector getBlockOn() {
return getPosition().subtract(0, 1, 0).toBlockVector();
public WorldVector getBlockOn() {
WorldVector pos = getPosition();
return new WorldVector(pos.getWorld(), pos.subtract(0, 1, 0));
}
/**
@ -287,7 +295,7 @@ public abstract class WorldEditPlayer {
* @param range
* @return point
*/
public abstract Vector getBlockTrace(int range);
public abstract WorldVector getBlockTrace(int range);
/**
* Get the point of the block being looked at. May return null.
@ -295,7 +303,7 @@ public abstract class WorldEditPlayer {
* @param range
* @return point
*/
public abstract Vector getSolidBlockTrace(int range);
public abstract WorldVector getSolidBlockTrace(int range);
/**
* Get the player's cardinal direction (N, W, NW, etc.). May return null.
@ -360,7 +368,14 @@ public abstract class WorldEditPlayer {
*
* @return point
*/
public abstract Vector getPosition();
public abstract WorldVector getPosition();
/**
* Get the player's world.
*
* @return point
*/
public abstract LocalWorld getWorld();
/**
* Get the player's view pitch.

Datei anzeigen

@ -0,0 +1,104 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit;
/**
* A vector with a world component.
*
* @author sk89q
*/
public class WorldVector extends Vector {
/**
* Represents the world.
*/
private LocalWorld world;
/**
* Construct the Vector object.
*
* @param x
* @param y
* @param z
*/
public WorldVector(LocalWorld world, double x, double y, double z) {
super(x, y, z);
this.world = world;
}
/**
* Construct the Vector object.
*
* @param x
* @param y
* @param z
*/
public WorldVector(LocalWorld world, int x, int y, int z) {
super(x, y, z);
this.world = world;
}
/**
* Construct the Vector object.
*
* @param x
* @param y
* @param z
*/
public WorldVector(LocalWorld world, float x, float y, float z) {
super(x, y, z);
this.world = world;
}
/**
* Construct the Vector object.
*
* @param pt
*/
public WorldVector(LocalWorld world, Vector pt) {
super(pt);
this.world = world;
}
/**
* Construct the Vector object.
*/
public WorldVector(LocalWorld world) {
super();
this.world = world;
}
/**
* Get the world.
*
* @return
*/
public LocalWorld getWorld() {
return world;
}
/**
* Gets a BlockVector version.
*
* @return BlockWorldVector
*/
public BlockWorldVector toWorldBlockVector() {
return new BlockWorldVector(this);
}
}