geforkt von Mirrors/FastAsyncWorldEdit
Added support for block data and sign texts. Decoupled more code from the server modification.
Dieser Commit ist enthalten in:
Ursprung
d1eca7c429
Commit
3bf7c08ad6
@ -17,11 +17,15 @@
|
||||
* 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 java.io.*;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import com.sk89q.worldedit.*;
|
||||
|
||||
/**
|
||||
@ -220,24 +224,44 @@ public class CuboidClipboard {
|
||||
schematic.put("Height", new ShortTag("Height", (short)height));
|
||||
schematic.put("Materials", new StringTag("Materials", "Alpha"));
|
||||
|
||||
// Copy blocks
|
||||
// Copy
|
||||
byte[] blocks = 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 y = 0; y < height; y++) {
|
||||
for (int z = 0; z < length; z++) {
|
||||
int index = y * width * length + z * width + x;
|
||||
blocks[index] = (byte)data[x][y][z].getType();
|
||||
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("Data", new ByteArrayTag("Data", blockData));
|
||||
|
||||
// These are not stored either
|
||||
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
|
||||
CompoundTag schematicTag = new CompoundTag("Schematic", schematic);
|
||||
@ -259,34 +283,92 @@ public class CuboidClipboard {
|
||||
throws SchematicException, IOException {
|
||||
FileInputStream stream = new FileInputStream(path);
|
||||
NBTInputStream nbtStream = new NBTInputStream(stream);
|
||||
|
||||
// Schematic tag
|
||||
CompoundTag schematicTag = (CompoundTag)nbtStream.readTag();
|
||||
if (!schematicTag.getName().equals("Schematic")) {
|
||||
throw new SchematicException("Tag \"Schematic\" does not exist or is not first");
|
||||
}
|
||||
|
||||
// Check
|
||||
Map<String,Tag> schematic = schematicTag.getValue();
|
||||
if (!schematic.containsKey("Blocks")) {
|
||||
throw new SchematicException("Schematic file is missing a \"Blocks\" tag");
|
||||
}
|
||||
|
||||
// Get information
|
||||
short width = (Short)getChildTag(schematic, "Width", ShortTag.class).getValue();
|
||||
short length = (Short)getChildTag(schematic, "Length", 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();
|
||||
if (!materials.equals("Alpha")) {
|
||||
throw new SchematicException("Schematic file is not an Alpha schematic");
|
||||
}
|
||||
|
||||
// Get blocks
|
||||
byte[] blocks = (byte[])getChildTag(schematic, "Blocks", 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);
|
||||
|
||||
for (int x = 0; x < width; x++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int z = 0; z < length; z++) {
|
||||
int index = y * width * length + z * width + x;
|
||||
clipboard.data[x][y][z] =
|
||||
new BaseBlock(blocks[index], blockData[index]);
|
||||
BlockVector pt = new BlockVector(x, y, z);
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,10 @@
|
||||
* 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.HashMap;
|
||||
import java.util.HashSet;
|
||||
@ -34,6 +38,11 @@ import com.sk89q.worldedit.*;
|
||||
* @author sk89q
|
||||
*/
|
||||
public class EditSession {
|
||||
/**
|
||||
* Server interface.
|
||||
*/
|
||||
public static ServerInterface server;
|
||||
|
||||
/**
|
||||
* Stores the original blocks before modification.
|
||||
*/
|
||||
@ -99,10 +108,15 @@ public class EditSession {
|
||||
* @return Whether the block changed
|
||||
*/
|
||||
private boolean rawSetBlock(Vector pt, BaseBlock block) {
|
||||
boolean result = etc.getMCServer().e.d(pt.getBlockX(), pt.getBlockY(),
|
||||
pt.getBlockZ(), block.getType());
|
||||
etc.getMCServer().e.c(pt.getBlockX(), pt.getBlockY(),
|
||||
pt.getBlockZ(), block.getData());
|
||||
boolean result = server.setBlockType(pt, block.getType());
|
||||
server.setBlockData(pt, block.getData());
|
||||
|
||||
// Signs
|
||||
if (block instanceof SignBlock) {
|
||||
SignBlock signBlock = (SignBlock)block;
|
||||
String[] text = signBlock.getText();
|
||||
server.setSignText(pt, text);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -187,10 +201,8 @@ public class EditSession {
|
||||
return current.get(blockPt);
|
||||
}
|
||||
}
|
||||
return new BaseBlock(
|
||||
(short)etc.getMCServer().e.a(pt.getBlockX(),
|
||||
pt.getBlockY(),
|
||||
pt.getBlockZ()));
|
||||
|
||||
return rawGetBlock(pt);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -200,9 +212,16 @@ public class EditSession {
|
||||
* @return BaseBlock
|
||||
*/
|
||||
public BaseBlock rawGetBlock(Vector pt) {
|
||||
int type = etc.getMCServer().e.a(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
|
||||
int data = etc.getMCServer().e.b(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
|
||||
return new BaseBlock(type, data);
|
||||
int type = server.getBlockType(pt);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
101
src/SMServerInterface.java
Normale Datei
101
src/SMServerInterface.java
Normale Datei
@ -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
187
src/SMWorldEditPlayer.java
Normale Datei
@ -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();
|
||||
}
|
||||
}
|
@ -17,6 +17,8 @@
|
||||
* 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.HashSet;
|
||||
import java.util.Arrays;
|
||||
|
@ -18,85 +18,60 @@
|
||||
*/
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.ServerInterface;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class WorldEditPlayer {
|
||||
private Player player;
|
||||
|
||||
public abstract class WorldEditPlayer {
|
||||
/**
|
||||
* Construct a WorldEditPlayer.
|
||||
*
|
||||
* @param player
|
||||
* Server interface.
|
||||
*/
|
||||
public WorldEditPlayer(Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public static ServerInterface server;
|
||||
|
||||
/**
|
||||
* Get the name of the player.
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public String getName() {
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
public abstract String 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());
|
||||
}
|
||||
|
||||
public abstract Vector getBlockOn();
|
||||
/**
|
||||
* 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());
|
||||
}
|
||||
|
||||
public abstract Vector getBlockIn();
|
||||
/**
|
||||
* Get the player's position.
|
||||
*
|
||||
* @return point
|
||||
*/
|
||||
public Vector getPosition() {
|
||||
return new Vector(player.getX(), player.getY(), player.getZ());
|
||||
}
|
||||
|
||||
public abstract Vector getPosition();
|
||||
/**
|
||||
* Get the player's view pitch.
|
||||
*
|
||||
* @return pitch
|
||||
*/
|
||||
public double getPitch() {
|
||||
return player.getPitch();
|
||||
}
|
||||
|
||||
public abstract double getPitch();
|
||||
/**
|
||||
* Get the player's view yaw.
|
||||
*
|
||||
* @return yaw
|
||||
*/
|
||||
public double getYaw() {
|
||||
return player.getRotation();
|
||||
}
|
||||
|
||||
public abstract double getYaw();
|
||||
/**
|
||||
* Get the ID of the item that the player is holding.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getItemInHand() {
|
||||
return player.getItemInHand();
|
||||
}
|
||||
public abstract int getItemInHand();
|
||||
|
||||
/**
|
||||
* Returns true if the player is holding a pick axe.
|
||||
@ -114,33 +89,21 @@ public class WorldEditPlayer {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getCardinalDirection() {
|
||||
// From hey0's code
|
||||
double rot = (getYaw() - 90) % 360;
|
||||
if (rot < 0) {
|
||||
rot += 360.0;
|
||||
}
|
||||
|
||||
return etc.getCompassPointForDirection(rot).toLowerCase();
|
||||
}
|
||||
public abstract String getCardinalDirection();
|
||||
|
||||
/**
|
||||
* Print a WorldEdit message.
|
||||
*
|
||||
* @param msg
|
||||
*/
|
||||
public void print(String msg) {
|
||||
player.sendMessage(Colors.LightPurple + msg);
|
||||
}
|
||||
public abstract void print(String msg);
|
||||
|
||||
/**
|
||||
* Print a WorldEdit error.
|
||||
*
|
||||
* @param msg
|
||||
*/
|
||||
public void printError(String msg) {
|
||||
player.sendMessage(Colors.Rose + msg);
|
||||
}
|
||||
public abstract void printError(String msg);
|
||||
|
||||
/**
|
||||
* Move the player.
|
||||
@ -149,15 +112,7 @@ public class WorldEditPlayer {
|
||||
* @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);
|
||||
}
|
||||
public abstract void setPosition(Vector pos, float pitch, float yaw);
|
||||
|
||||
/**
|
||||
* Move the player.
|
||||
@ -165,13 +120,7 @@ public class WorldEditPlayer {
|
||||
* @param pos
|
||||
*/
|
||||
public void setPosition(Vector pos) {
|
||||
Location loc = new Location();
|
||||
loc.x = pos.getX();
|
||||
loc.y = pos.getY();
|
||||
loc.z = pos.getZ();
|
||||
loc.rotX = (float)getYaw();
|
||||
loc.rotY = (float)getPitch();
|
||||
player.teleportTo(loc);
|
||||
setPosition(pos, (float)getPitch(), (float)getYaw());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -181,10 +130,11 @@ public class WorldEditPlayer {
|
||||
* that free position.
|
||||
*/
|
||||
public void findFreePosition() {
|
||||
int x = (int)Math.floor(player.getX());
|
||||
int y = (int)Math.floor(player.getY());
|
||||
Vector pos = getPosition();
|
||||
int x = pos.getBlockX();
|
||||
int y = pos.getBlockY();
|
||||
int origY = y;
|
||||
int z = (int)Math.floor(player.getZ());
|
||||
int z = pos.getBlockZ();
|
||||
|
||||
byte free = 0;
|
||||
|
||||
@ -197,13 +147,7 @@ public class WorldEditPlayer {
|
||||
|
||||
if (free == 2) {
|
||||
if (y - 1 != origY) {
|
||||
Location loc = new Location();
|
||||
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);
|
||||
setPosition(new Vector(x + 0.5, y - 1, z + 0.5));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -218,16 +162,17 @@ public class WorldEditPlayer {
|
||||
* @return true if a spot was found
|
||||
*/
|
||||
public boolean ascendLevel() {
|
||||
int x = (int)Math.floor(player.getX());
|
||||
int y = (int)Math.floor(player.getY());
|
||||
int z = (int)Math.floor(player.getZ());
|
||||
Vector pos = getPosition();
|
||||
int x = pos.getBlockX();
|
||||
int y = pos.getBlockY();
|
||||
int z = pos.getBlockZ();
|
||||
|
||||
byte free = 0;
|
||||
byte spots = 0;
|
||||
boolean inFree = false;
|
||||
|
||||
while (y <= 129) {
|
||||
if (etc.getServer().getBlockIdAt(x, y, z) == 0) {
|
||||
if (server.getBlockType(new Vector(x, y, z)) == 0) {
|
||||
free++;
|
||||
} else {
|
||||
free = 0;
|
||||
@ -255,14 +200,15 @@ public class WorldEditPlayer {
|
||||
* @return true if a spot was found
|
||||
*/
|
||||
public boolean descendLevel() {
|
||||
int x = (int)Math.floor(player.getX());
|
||||
int y = (int)Math.floor(player.getY()) - 1;
|
||||
int z = (int)Math.floor(player.getZ());
|
||||
Vector pos = getPosition();
|
||||
int x = pos.getBlockX();
|
||||
int y = pos.getBlockY() - 1;
|
||||
int z = pos.getBlockZ();
|
||||
|
||||
byte free = 0;
|
||||
|
||||
while (y >= 0) {
|
||||
if (etc.getServer().getBlockIdAt(x, y, z) == 0) {
|
||||
if (server.getBlockType(new Vector(x, y, z)) == 0) {
|
||||
free++;
|
||||
} else {
|
||||
free = 0;
|
||||
@ -285,9 +231,7 @@ public class WorldEditPlayer {
|
||||
* @param type
|
||||
* @param amt
|
||||
*/
|
||||
public void giveItem(int type, int amt) {
|
||||
player.giveItem(type, amt);
|
||||
}
|
||||
public abstract void giveItem(int type, int amt);
|
||||
|
||||
/**
|
||||
* Returns true if equal.
|
||||
@ -301,7 +245,7 @@ public class WorldEditPlayer {
|
||||
return false;
|
||||
}
|
||||
WorldEditPlayer other2 = (WorldEditPlayer)other;
|
||||
return other2.getName().equals(player.getName());
|
||||
return other2.getName().equals(getName());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.HashSet;
|
||||
import com.sk89q.worldedit.ServerInterface;
|
||||
|
||||
/**
|
||||
* Entry point for the plugin for hey0's mod.
|
||||
@ -48,6 +49,10 @@ 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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -45,7 +45,7 @@ public class WorldEditSMListener extends PluginListener {
|
||||
*/
|
||||
@Override
|
||||
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
|
||||
public boolean onBlockCreate(Player modPlayer, Block blockPlaced,
|
||||
Block blockClicked, int itemInHand) {
|
||||
WorldEditPlayer player = new WorldEditPlayer(modPlayer);
|
||||
WorldEditPlayer player = new SMWorldEditPlayer(modPlayer);
|
||||
|
||||
if (itemInHand != 271) { return false; }
|
||||
if (!modPlayer.canUseCommand("/editpos2")) { return false; }
|
||||
@ -94,7 +94,7 @@ public class WorldEditSMListener extends PluginListener {
|
||||
if (!modPlayer.canUseCommand("/editpos1")
|
||||
&& !modPlayer.canUseCommand("/.")) { return false; }
|
||||
|
||||
WorldEditPlayer player = new WorldEditPlayer(modPlayer);
|
||||
WorldEditPlayer player = new SMWorldEditPlayer(modPlayer);
|
||||
WorldEditSession session = worldEdit.getSession(player);
|
||||
|
||||
if (player.isHoldingPickAxe()) {
|
||||
@ -136,7 +136,7 @@ public class WorldEditSMListener extends PluginListener {
|
||||
try {
|
||||
if (worldEdit.getCommands().containsKey(split[0])) {
|
||||
if (modPlayer.canUseCommand(split[0])) {
|
||||
WorldEditPlayer player = new WorldEditPlayer(modPlayer);
|
||||
WorldEditPlayer player = new SMWorldEditPlayer(modPlayer);
|
||||
WorldEditSession session = worldEdit.getSession(player);
|
||||
EditSession editSession =
|
||||
new EditSession(session.getBlockChangeLimit());
|
||||
|
@ -17,6 +17,8 @@
|
||||
* 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 java.util.LinkedList;
|
||||
|
||||
|
71
src/com/sk89q/worldedit/ServerInterface.java
Normale Datei
71
src/com/sk89q/worldedit/ServerInterface.java
Normale Datei
@ -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);
|
||||
}
|
@ -17,7 +17,7 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit;
|
||||
package com.sk89q.worldedit.blocks;
|
||||
|
||||
/**
|
||||
* Represents a block.
|
137
src/com/sk89q/worldedit/blocks/SignBlock.java
Normale Datei
137
src/com/sk89q/worldedit/blocks/SignBlock.java
Normale Datei
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
54
src/com/sk89q/worldedit/blocks/TileEntityBlock.java
Normale Datei
54
src/com/sk89q/worldedit/blocks/TileEntityBlock.java
Normale Datei
@ -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 ;
|
||||
}
|
@ -17,8 +17,9 @@
|
||||
* 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;
|
||||
|
||||
/**
|
@ -17,7 +17,9 @@
|
||||
* 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;
|
||||
|
||||
/**
|
||||
*
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren