Added support for block data and sign texts. Decoupled more code from the server modification.

Dieser Commit ist enthalten in:
sk89q 2010-10-14 01:31:05 -07:00
Ursprung d1eca7c429
Commit 3bf7c08ad6
15 geänderte Dateien mit 722 neuen und 115 gelöschten Zeilen

Datei anzeigen

@ -17,11 +17,15 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
import com.sk89q.worldedit.blocks.TileEntityBlock;
import com.sk89q.worldedit.blocks.SignBlock;
import com.sk89q.worldedit.blocks.BaseBlock;
import org.jnbt.*; import org.jnbt.*;
import java.io.*; import java.io.*;
import java.util.Map; import java.util.Map;
import java.util.HashMap; import java.util.HashMap;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import com.sk89q.worldedit.*; import com.sk89q.worldedit.*;
/** /**
@ -220,24 +224,44 @@ public class CuboidClipboard {
schematic.put("Height", new ShortTag("Height", (short)height)); schematic.put("Height", new ShortTag("Height", (short)height));
schematic.put("Materials", new StringTag("Materials", "Alpha")); schematic.put("Materials", new StringTag("Materials", "Alpha"));
// Copy blocks // Copy
byte[] blocks = new byte[width * height * length]; byte[] blocks = new byte[width * height * length];
byte[] blockData = new byte[width * height * length]; byte[] blockData = new byte[width * height * length];
ArrayList<Tag> tileEntities = new ArrayList<Tag>();
for (int x = 0; x < width; x++) { for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) { for (int y = 0; y < height; y++) {
for (int z = 0; z < length; z++) { for (int z = 0; z < length; z++) {
int index = y * width * length + z * width + x; int index = y * width * length + z * width + x;
blocks[index] = (byte)data[x][y][z].getType(); blocks[index] = (byte)data[x][y][z].getType();
blockData[index] = (byte)data[x][y][z].getData(); blockData[index] = (byte)data[x][y][z].getData();
// Store TileEntity data
if (data[x][y][z] instanceof TileEntityBlock) {
TileEntityBlock tileEntityBlock =
(TileEntityBlock)data[x][y][z];
// Get the list of key/values from the block
Map<String,Tag> values = tileEntityBlock.toTileEntityNBT();
if (values != null) {
values.put("id", new StringTag("id",
tileEntityBlock.getTileEntityID()));
values.put("x", new IntTag("x", x));
values.put("y", new IntTag("y", y));
values.put("z", new IntTag("z", z));
CompoundTag tileEntityTag =
new CompoundTag("TileEntity", values);
tileEntities.add(tileEntityTag);
} }
} }
} }
}
}
schematic.put("Blocks", new ByteArrayTag("Blocks", blocks)); schematic.put("Blocks", new ByteArrayTag("Blocks", blocks));
schematic.put("Data", new ByteArrayTag("Data", blockData)); schematic.put("Data", new ByteArrayTag("Data", blockData));
// These are not stored either
schematic.put("Entities", new ListTag("Entities", CompoundTag.class, new ArrayList<Tag>())); schematic.put("Entities", new ListTag("Entities", CompoundTag.class, new ArrayList<Tag>()));
schematic.put("TileEntities", new ListTag("TileEntities", CompoundTag.class, new ArrayList<Tag>())); schematic.put("TileEntities", new ListTag("TileEntities", CompoundTag.class, tileEntities));
// Build and output // Build and output
CompoundTag schematicTag = new CompoundTag("Schematic", schematic); CompoundTag schematicTag = new CompoundTag("Schematic", schematic);
@ -259,34 +283,92 @@ public class CuboidClipboard {
throws SchematicException, IOException { throws SchematicException, IOException {
FileInputStream stream = new FileInputStream(path); FileInputStream stream = new FileInputStream(path);
NBTInputStream nbtStream = new NBTInputStream(stream); NBTInputStream nbtStream = new NBTInputStream(stream);
// Schematic tag
CompoundTag schematicTag = (CompoundTag)nbtStream.readTag(); CompoundTag schematicTag = (CompoundTag)nbtStream.readTag();
if (!schematicTag.getName().equals("Schematic")) { if (!schematicTag.getName().equals("Schematic")) {
throw new SchematicException("Tag \"Schematic\" does not exist or is not first"); throw new SchematicException("Tag \"Schematic\" does not exist or is not first");
} }
// Check
Map<String,Tag> schematic = schematicTag.getValue(); Map<String,Tag> schematic = schematicTag.getValue();
if (!schematic.containsKey("Blocks")) { if (!schematic.containsKey("Blocks")) {
throw new SchematicException("Schematic file is missing a \"Blocks\" tag"); throw new SchematicException("Schematic file is missing a \"Blocks\" tag");
} }
// Get information
short width = (Short)getChildTag(schematic, "Width", ShortTag.class).getValue(); short width = (Short)getChildTag(schematic, "Width", ShortTag.class).getValue();
short length = (Short)getChildTag(schematic, "Length", ShortTag.class).getValue(); short length = (Short)getChildTag(schematic, "Length", ShortTag.class).getValue();
short height = (Short)getChildTag(schematic, "Height", ShortTag.class).getValue(); short height = (Short)getChildTag(schematic, "Height", ShortTag.class).getValue();
// Check type of Schematic
String materials = (String)getChildTag(schematic, "Materials", StringTag.class).getValue(); String materials = (String)getChildTag(schematic, "Materials", StringTag.class).getValue();
if (!materials.equals("Alpha")) { if (!materials.equals("Alpha")) {
throw new SchematicException("Schematic file is not an Alpha schematic"); throw new SchematicException("Schematic file is not an Alpha schematic");
} }
// Get blocks
byte[] blocks = (byte[])getChildTag(schematic, "Blocks", ByteArrayTag.class).getValue(); byte[] blocks = (byte[])getChildTag(schematic, "Blocks", ByteArrayTag.class).getValue();
byte[] blockData = (byte[])getChildTag(schematic, "Data", ByteArrayTag.class).getValue(); byte[] blockData = (byte[])getChildTag(schematic, "Data", ByteArrayTag.class).getValue();
Vector size = new Vector(width, height, length); // Need to pull out tile entities
List<Tag> tileEntities = (List<Tag>)getChildTag(schematic, "TileEntities", ListTag.class).getValue();
Map<BlockVector,Map<String,Tag>> tileEntitiesMap =
new HashMap<BlockVector,Map<String,Tag>>();
for (Tag tag : tileEntities) {
if (!(tag instanceof CompoundTag)) continue;
CompoundTag t = (CompoundTag)tag;
int x = 0;
int y = 0;
int z = 0;
Map<String,Tag> values = new HashMap<String,Tag>();
for (Map.Entry<String,Tag> entry : t.getValue().entrySet()) {
if (entry.getKey().equals("x")) {
if (entry.getValue() instanceof IntTag) {
x = ((IntTag)entry.getValue()).getValue();
}
} else if (entry.getKey().equals("y")) {
if (entry.getValue() instanceof IntTag) {
y = ((IntTag)entry.getValue()).getValue();
}
} else if (entry.getKey().equals("z")) {
if (entry.getValue() instanceof IntTag) {
z = ((IntTag)entry.getValue()).getValue();
}
}
values.put(entry.getKey(), entry.getValue());
}
BlockVector vec = new BlockVector(x, y, z);
tileEntitiesMap.put(vec, values);
}
Vector size = new Vector(width, height, length);
CuboidClipboard clipboard = new CuboidClipboard(size); CuboidClipboard clipboard = new CuboidClipboard(size);
for (int x = 0; x < width; x++) { for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) { for (int y = 0; y < height; y++) {
for (int z = 0; z < length; z++) { for (int z = 0; z < length; z++) {
int index = y * width * length + z * width + x; int index = y * width * length + z * width + x;
clipboard.data[x][y][z] = BlockVector pt = new BlockVector(x, y, z);
new BaseBlock(blocks[index], blockData[index]); BaseBlock block;
if (blocks[index] == 63 || blocks[index] == 68) {
block = new SignBlock(blocks[index], blockData[index]);
if (tileEntitiesMap.containsKey(pt)) {
((TileEntityBlock)block).fromTileEntityNBT(
tileEntitiesMap.get(pt));
}
} else {
block = new BaseBlock(blocks[index], blockData[index]);
}
clipboard.data[x][y][z] = block;
} }
} }
} }

Datei anzeigen

@ -17,6 +17,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.blocks.SignBlock;
import com.sk89q.worldedit.blocks.BaseBlock;
import java.util.Map; import java.util.Map;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
@ -34,6 +38,11 @@ import com.sk89q.worldedit.*;
* @author sk89q * @author sk89q
*/ */
public class EditSession { public class EditSession {
/**
* Server interface.
*/
public static ServerInterface server;
/** /**
* Stores the original blocks before modification. * Stores the original blocks before modification.
*/ */
@ -99,10 +108,15 @@ public class EditSession {
* @return Whether the block changed * @return Whether the block changed
*/ */
private boolean rawSetBlock(Vector pt, BaseBlock block) { private boolean rawSetBlock(Vector pt, BaseBlock block) {
boolean result = etc.getMCServer().e.d(pt.getBlockX(), pt.getBlockY(), boolean result = server.setBlockType(pt, block.getType());
pt.getBlockZ(), block.getType()); server.setBlockData(pt, block.getData());
etc.getMCServer().e.c(pt.getBlockX(), pt.getBlockY(),
pt.getBlockZ(), block.getData()); // Signs
if (block instanceof SignBlock) {
SignBlock signBlock = (SignBlock)block;
String[] text = signBlock.getText();
server.setSignText(pt, text);
}
return result; return result;
} }
@ -187,10 +201,8 @@ public class EditSession {
return current.get(blockPt); return current.get(blockPt);
} }
} }
return new BaseBlock(
(short)etc.getMCServer().e.a(pt.getBlockX(), return rawGetBlock(pt);
pt.getBlockY(),
pt.getBlockZ()));
} }
/** /**
@ -200,10 +212,17 @@ public class EditSession {
* @return BaseBlock * @return BaseBlock
*/ */
public BaseBlock rawGetBlock(Vector pt) { public BaseBlock rawGetBlock(Vector pt) {
int type = etc.getMCServer().e.a(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()); int type = server.getBlockType(pt);
int data = etc.getMCServer().e.b(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()); int data = server.getBlockData(pt);
// Sign
if (type == 63 || type == 68) {
String[] text = server.getSignText(pt);
return new SignBlock(type, data, text);
} else {
return new BaseBlock(type, data); return new BaseBlock(type, data);
} }
}
/** /**
* Restores all blocks to their initial state. * Restores all blocks to their initial state.

101
src/SMServerInterface.java Normale Datei
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/>.
*/
import com.sk89q.worldedit.*;
/**
*
* @author sk89q
*/
public class SMServerInterface implements ServerInterface {
/**
* Set block type.
*
* @param pt
* @param type
* @return
*/
public boolean setBlockType(Vector pt, int type) {
return etc.getMCServer().e.d(pt.getBlockX(), pt.getBlockY(),
pt.getBlockZ(), type);
}
/**
* Get block type.
*
* @param pt
* @return
*/
public int getBlockType(Vector pt) {
return etc.getMCServer().e.a(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
}
/**
* Set block data.
*
* @param pt
* @param data
* @return
*/
public void setBlockData(Vector pt, int data) {
etc.getMCServer().e.c(pt.getBlockX(), pt.getBlockY(),
pt.getBlockZ(), data);
}
/**
* Get block data.
*
* @param pt
* @return
*/
public int getBlockData(Vector pt) {
return etc.getMCServer().e.b(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
}
/**
* Set sign text.
*
* @param pt
* @param text
*/
public void setSignText(Vector pt, String[] text) {
Sign signData = (Sign)etc.getServer().getComplexBlock(
pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
for (byte i = 0; i < 4; i++) {
signData.setText(i, text[i]);
}
signData.update();
}
/**
* Get sign text.
*
* @param pt
* @return
*/
public String[] getSignText(Vector pt) {
Sign signData = (Sign)etc.getServer().getComplexBlock(
pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
String[] text = new String[4];
for (byte i = 0; i < 4; i++) {
text[i] = signData.getText(i);
}
return text;
}
}

187
src/SMWorldEditPlayer.java Normale Datei
Datei anzeigen

@ -0,0 +1,187 @@
// $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/>.
*/
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.ServerInterface;
/**
*
* @author sk89q
*/
public class SMWorldEditPlayer extends WorldEditPlayer {
private Player player;
/**
* Construct a WorldEditPlayer.
*
* @param player
*/
public SMWorldEditPlayer(Player player) {
super();
this.player = player;
}
/**
* Get the name of the player.
*
* @return String
*/
public String getName() {
return player.getName();
}
/**
* Get the point of the block that is being stood upon.
*
* @return point
*/
public Vector getBlockOn() {
return Vector.toBlockPoint(player.getX(), player.getY() - 1, player.getZ());
}
/**
* Get the point of the block that is being stood in.
*
* @return point
*/
public Vector getBlockIn() {
return Vector.toBlockPoint(player.getX(), player.getY(), player.getZ());
}
/**
* Get the player's position.
*
* @return point
*/
public Vector getPosition() {
return new Vector(player.getX(), player.getY(), player.getZ());
}
/**
* Get the player's view pitch.
*
* @return pitch
*/
public double getPitch() {
return player.getPitch();
}
/**
* Get the player's view yaw.
*
* @return yaw
*/
public double getYaw() {
return player.getRotation();
}
/**
* Get the ID of the item that the player is holding.
*
* @return
*/
public int getItemInHand() {
return player.getItemInHand();
}
/**
* Get the player's cardinal direction (N, W, NW, etc.).
*
* @return
*/
public String getCardinalDirection() {
// From hey0's code
double rot = (getYaw() - 90) % 360;
if (rot < 0) {
rot += 360.0;
}
return etc.getCompassPointForDirection(rot).toLowerCase();
}
/**
* Print a WorldEdit message.
*
* @param msg
*/
public void print(String msg) {
player.sendMessage(Colors.LightPurple + msg);
}
/**
* Print a WorldEdit error.
*
* @param msg
*/
public void printError(String msg) {
player.sendMessage(Colors.Rose + msg);
}
/**
* Move the player.
*
* @param pos
* @param pitch
* @param yaw
*/
public void setPosition(Vector pos, float pitch, float yaw) {
Location loc = new Location();
loc.x = pos.getX();
loc.y = pos.getY();
loc.z = pos.getZ();
loc.rotX = (float)yaw;
loc.rotY = (float)pitch;
player.teleportTo(loc);
}
/**
* Gives the player an item.
*
* @param type
* @param amt
*/
public void giveItem(int type, int amt) {
player.giveItem(type, amt);
}
/**
* Returns true if equal.
*
* @param other
* @return whether the other object is equivalent
*/
@Override
public boolean equals(Object other) {
if (!(other instanceof WorldEditPlayer)) {
return false;
}
WorldEditPlayer other2 = (WorldEditPlayer)other;
return other2.getName().equals(player.getName());
}
/**
* Gets the hash code.
*
* @return hash code
*/
@Override
public int hashCode() {
return getName().hashCode();
}
}

Datei anzeigen

@ -17,6 +17,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.blocks.BaseBlock;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Arrays; import java.util.Arrays;

Datei anzeigen

@ -18,85 +18,60 @@
*/ */
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.ServerInterface;
/** /**
* *
* @author sk89q * @author sk89q
*/ */
public class WorldEditPlayer { public abstract class WorldEditPlayer {
private Player player;
/** /**
* Construct a WorldEditPlayer. * Server interface.
*
* @param player
*/ */
public WorldEditPlayer(Player player) { public static ServerInterface server;
this.player = player;
}
/** /**
* Get the name of the player. * Get the name of the player.
* *
* @return String * @return String
*/ */
public String getName() { public abstract String getName();
return player.getName();
}
/** /**
* Get the point of the block that is being stood upon. * Get the point of the block that is being stood upon.
* *
* @return point * @return point
*/ */
public Vector getBlockOn() { public abstract Vector getBlockOn();
return Vector.toBlockPoint(player.getX(), player.getY() - 1, player.getZ());
}
/** /**
* Get the point of the block that is being stood in. * Get the point of the block that is being stood in.
* *
* @return point * @return point
*/ */
public Vector getBlockIn() { public abstract Vector getBlockIn();
return Vector.toBlockPoint(player.getX(), player.getY(), player.getZ());
}
/** /**
* Get the player's position. * Get the player's position.
* *
* @return point * @return point
*/ */
public Vector getPosition() { public abstract Vector getPosition();
return new Vector(player.getX(), player.getY(), player.getZ());
}
/** /**
* Get the player's view pitch. * Get the player's view pitch.
* *
* @return pitch * @return pitch
*/ */
public double getPitch() { public abstract double getPitch();
return player.getPitch();
}
/** /**
* Get the player's view yaw. * Get the player's view yaw.
* *
* @return yaw * @return yaw
*/ */
public double getYaw() { public abstract double getYaw();
return player.getRotation();
}
/** /**
* Get the ID of the item that the player is holding. * Get the ID of the item that the player is holding.
* *
* @return * @return
*/ */
public int getItemInHand() { public abstract int getItemInHand();
return player.getItemInHand();
}
/** /**
* Returns true if the player is holding a pick axe. * Returns true if the player is holding a pick axe.
@ -114,33 +89,21 @@ public class WorldEditPlayer {
* *
* @return * @return
*/ */
public String getCardinalDirection() { public abstract String getCardinalDirection();
// From hey0's code
double rot = (getYaw() - 90) % 360;
if (rot < 0) {
rot += 360.0;
}
return etc.getCompassPointForDirection(rot).toLowerCase();
}
/** /**
* Print a WorldEdit message. * Print a WorldEdit message.
* *
* @param msg * @param msg
*/ */
public void print(String msg) { public abstract void print(String msg);
player.sendMessage(Colors.LightPurple + msg);
}
/** /**
* Print a WorldEdit error. * Print a WorldEdit error.
* *
* @param msg * @param msg
*/ */
public void printError(String msg) { public abstract void printError(String msg);
player.sendMessage(Colors.Rose + msg);
}
/** /**
* Move the player. * Move the player.
@ -149,15 +112,7 @@ public class WorldEditPlayer {
* @param pitch * @param pitch
* @param yaw * @param yaw
*/ */
public void setPosition(Vector pos, float pitch, float yaw) { public abstract void setPosition(Vector pos, float pitch, float yaw);
Location loc = new Location();
loc.x = pos.getX();
loc.y = pos.getY();
loc.z = pos.getZ();
loc.rotX = (float)yaw;
loc.rotY = (float)pitch;
player.teleportTo(loc);
}
/** /**
* Move the player. * Move the player.
@ -165,13 +120,7 @@ public class WorldEditPlayer {
* @param pos * @param pos
*/ */
public void setPosition(Vector pos) { public void setPosition(Vector pos) {
Location loc = new Location(); setPosition(pos, (float)getPitch(), (float)getYaw());
loc.x = pos.getX();
loc.y = pos.getY();
loc.z = pos.getZ();
loc.rotX = (float)getYaw();
loc.rotY = (float)getPitch();
player.teleportTo(loc);
} }
/** /**
@ -181,10 +130,11 @@ public class WorldEditPlayer {
* that free position. * that free position.
*/ */
public void findFreePosition() { public void findFreePosition() {
int x = (int)Math.floor(player.getX()); Vector pos = getPosition();
int y = (int)Math.floor(player.getY()); int x = pos.getBlockX();
int y = pos.getBlockY();
int origY = y; int origY = y;
int z = (int)Math.floor(player.getZ()); int z = pos.getBlockZ();
byte free = 0; byte free = 0;
@ -197,13 +147,7 @@ public class WorldEditPlayer {
if (free == 2) { if (free == 2) {
if (y - 1 != origY) { if (y - 1 != origY) {
Location loc = new Location(); setPosition(new Vector(x + 0.5, y - 1, z + 0.5));
loc.x = x + 0.5;
loc.y = y - 1;
loc.z = z + 0.5;
loc.rotX = player.getRotation();
loc.rotY = player.getPitch();
player.teleportTo(loc);
return; return;
} }
} }
@ -218,16 +162,17 @@ public class WorldEditPlayer {
* @return true if a spot was found * @return true if a spot was found
*/ */
public boolean ascendLevel() { public boolean ascendLevel() {
int x = (int)Math.floor(player.getX()); Vector pos = getPosition();
int y = (int)Math.floor(player.getY()); int x = pos.getBlockX();
int z = (int)Math.floor(player.getZ()); int y = pos.getBlockY();
int z = pos.getBlockZ();
byte free = 0; byte free = 0;
byte spots = 0; byte spots = 0;
boolean inFree = false; boolean inFree = false;
while (y <= 129) { while (y <= 129) {
if (etc.getServer().getBlockIdAt(x, y, z) == 0) { if (server.getBlockType(new Vector(x, y, z)) == 0) {
free++; free++;
} else { } else {
free = 0; free = 0;
@ -255,14 +200,15 @@ public class WorldEditPlayer {
* @return true if a spot was found * @return true if a spot was found
*/ */
public boolean descendLevel() { public boolean descendLevel() {
int x = (int)Math.floor(player.getX()); Vector pos = getPosition();
int y = (int)Math.floor(player.getY()) - 1; int x = pos.getBlockX();
int z = (int)Math.floor(player.getZ()); int y = pos.getBlockY() - 1;
int z = pos.getBlockZ();
byte free = 0; byte free = 0;
while (y >= 0) { while (y >= 0) {
if (etc.getServer().getBlockIdAt(x, y, z) == 0) { if (server.getBlockType(new Vector(x, y, z)) == 0) {
free++; free++;
} else { } else {
free = 0; free = 0;
@ -285,9 +231,7 @@ public class WorldEditPlayer {
* @param type * @param type
* @param amt * @param amt
*/ */
public void giveItem(int type, int amt) { public abstract void giveItem(int type, int amt);
player.giveItem(type, amt);
}
/** /**
* Returns true if equal. * Returns true if equal.
@ -301,7 +245,7 @@ public class WorldEditPlayer {
return false; return false;
} }
WorldEditPlayer other2 = (WorldEditPlayer)other; WorldEditPlayer other2 = (WorldEditPlayer)other;
return other2.getName().equals(player.getName()); return other2.getName().equals(getName());
} }
/** /**

Datei anzeigen

@ -19,6 +19,7 @@
import java.util.Map; import java.util.Map;
import java.util.HashSet; import java.util.HashSet;
import com.sk89q.worldedit.ServerInterface;
/** /**
* Entry point for the plugin for hey0's mod. * Entry point for the plugin for hey0's mod.
@ -48,6 +49,10 @@ public class WorldEditSM extends Plugin {
PluginListener.Priority.MEDIUM); PluginListener.Priority.MEDIUM);
loader.addListener(PluginLoader.Hook.LOGIN, listener, this, loader.addListener(PluginLoader.Hook.LOGIN, listener, this,
PluginListener.Priority.MEDIUM); PluginListener.Priority.MEDIUM);
ServerInterface server = new SMServerInterface();
WorldEditPlayer.server = server;
EditSession.server = server;
} }
/** /**

Datei anzeigen

@ -45,7 +45,7 @@ public class WorldEditSMListener extends PluginListener {
*/ */
@Override @Override
public void onDisconnect(Player player) { public void onDisconnect(Player player) {
worldEdit.removeSession(new WorldEditPlayer(player)); worldEdit.removeSession(new SMWorldEditPlayer(player));
} }
/** /**
@ -60,7 +60,7 @@ public class WorldEditSMListener extends PluginListener {
@Override @Override
public boolean onBlockCreate(Player modPlayer, Block blockPlaced, public boolean onBlockCreate(Player modPlayer, Block blockPlaced,
Block blockClicked, int itemInHand) { Block blockClicked, int itemInHand) {
WorldEditPlayer player = new WorldEditPlayer(modPlayer); WorldEditPlayer player = new SMWorldEditPlayer(modPlayer);
if (itemInHand != 271) { return false; } if (itemInHand != 271) { return false; }
if (!modPlayer.canUseCommand("/editpos2")) { return false; } if (!modPlayer.canUseCommand("/editpos2")) { return false; }
@ -94,7 +94,7 @@ public class WorldEditSMListener extends PluginListener {
if (!modPlayer.canUseCommand("/editpos1") if (!modPlayer.canUseCommand("/editpos1")
&& !modPlayer.canUseCommand("/.")) { return false; } && !modPlayer.canUseCommand("/.")) { return false; }
WorldEditPlayer player = new WorldEditPlayer(modPlayer); WorldEditPlayer player = new SMWorldEditPlayer(modPlayer);
WorldEditSession session = worldEdit.getSession(player); WorldEditSession session = worldEdit.getSession(player);
if (player.isHoldingPickAxe()) { if (player.isHoldingPickAxe()) {
@ -136,7 +136,7 @@ public class WorldEditSMListener extends PluginListener {
try { try {
if (worldEdit.getCommands().containsKey(split[0])) { if (worldEdit.getCommands().containsKey(split[0])) {
if (modPlayer.canUseCommand(split[0])) { if (modPlayer.canUseCommand(split[0])) {
WorldEditPlayer player = new WorldEditPlayer(modPlayer); WorldEditPlayer player = new SMWorldEditPlayer(modPlayer);
WorldEditSession session = worldEdit.getSession(player); WorldEditSession session = worldEdit.getSession(player);
EditSession editSession = EditSession editSession =
new EditSession(session.getBlockChangeLimit()); new EditSession(session.getBlockChangeLimit());

Datei anzeigen

@ -17,6 +17,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.*; import com.sk89q.worldedit.*;
import java.util.LinkedList; import java.util.LinkedList;

Datei anzeigen

@ -0,0 +1,71 @@
// $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;
/**
*
* @author sk89q
*/
public interface ServerInterface {
/**
* Set block type.
*
* @param pt
* @param type
* @return
*/
public boolean setBlockType(Vector pt, int type);
/**
* Get block type.
*
* @param pt
* @return
*/
public int getBlockType(Vector pt);
/**
* Set block data.
*
* @param pt
* @param data
* @return
*/
public void setBlockData(Vector pt, int data);
/**
* Get block data.
*
* @param pt
* @return
*/
public int getBlockData(Vector pt);
/**
* Set sign text.
*
* @param pt
* @param text
*/
public void setSignText(Vector pt, String[] text);
/**
* Get sign text.
*
* @param pt
* @return
*/
public String[] getSignText(Vector pt);
}

Datei anzeigen

@ -17,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.sk89q.worldedit; package com.sk89q.worldedit.blocks;
/** /**
* Represents a block. * Represents a block.

Datei anzeigen

@ -0,0 +1,137 @@
// $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.blocks;
import com.sk89q.worldedit.SchematicException;
import java.util.Map;
import java.util.HashMap;
import org.jnbt.*;
/**
*
* @author sk89q
*/
public class SignBlock extends BaseBlock implements TileEntityBlock {
/**
* Stores the sign's text.
*/
private String[] text;
/**
* Construct the sign without text.
*
* @param text
*/
public SignBlock(int type, int data) {
super(type, data);
this.text = new String[]{ "", "", "", "" };
}
/**
* Construct the sign with text.
*
* @param text
*/
public SignBlock(int type, int data, String[] text) {
super(type, data);
this.text = text;
}
/**
* @return the text
*/
public String[] getText() {
return text;
}
/**
* @param text the text to set
*/
public void setText(String[] text) {
this.text = text;
}
/**
* Return the name of the title entity ID.
*
* @return title entity ID
*/
public String getTileEntityID() {
return "Sign";
}
/**
* Store additional tile entity data. Returns true if the data is used.
*
* @return map of values
* @throws SchematicException
*/
public Map<String,Tag> toTileEntityNBT()
throws SchematicException {
Map<String,Tag> values = new HashMap<String,Tag>();
values.put("Text1", new StringTag("Text1", text[0]));
values.put("Text2", new StringTag("Text2", text[1]));
values.put("Text3", new StringTag("Text3", text[2]));
values.put("Text4", new StringTag("Text4", text[3]));
return values;
}
/**
* Get additional information from the title entity data.
*
* @param values
* @throws SchematicException
*/
public void fromTileEntityNBT(Map<String,Tag> values)
throws SchematicException {
if (values == null) {
return;
}
Tag t;
text = new String[]{ "", "", "", "" };
t = values.get("id");
if (!(t instanceof StringTag) || !((StringTag)t).getValue().equals("Sign")) {
throw new SchematicException("'Sign' tile entity expected");
}
t = values.get("Text1");
if (t instanceof StringTag) {
text[0] = ((StringTag)t).getValue();
}
t = values.get("Text2");
if (t instanceof StringTag) {
text[1] = ((StringTag)t).getValue();
}
t = values.get("Text3");
if (t instanceof StringTag) {
text[2] = ((StringTag)t).getValue();
}
t = values.get("Text4");
if (t instanceof StringTag) {
text[3] = ((StringTag)t).getValue();
}
}
}

Datei anzeigen

@ -0,0 +1,54 @@
// $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.blocks;
import com.sk89q.worldedit.SchematicException;
import java.util.Map;
import org.jnbt.Tag;
/**
* A class implementing this interface has extra TileEntityBlock data to store.
*
* @author sk89q
*/
public interface TileEntityBlock {
/**
* Return the name of the title entity ID.
*
* @return title entity ID
*/
public String getTileEntityID();
/**
* Store additional tile entity data.
*
* @return map of values
* @throws SchematicException
*/
public Map<String,Tag> toTileEntityNBT()
throws SchematicException ;
/**
* Get additional information from the title entity data.
*
* @param values
* @throws SchematicException
*/
public void fromTileEntityNBT(Map<String,Tag> values)
throws SchematicException ;
}

Datei anzeigen

@ -17,8 +17,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.sk89q.worldedit; package com.sk89q.worldedit.regions;
import com.sk89q.worldedit.Vector;
import java.util.Iterator; import java.util.Iterator;
/** /**

Datei anzeigen

@ -17,7 +17,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.sk89q.worldedit; package com.sk89q.worldedit.regions;
import com.sk89q.worldedit.Vector;
/** /**
* *