2010-10-14 10:31:05 +02:00
|
|
|
// $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.*;
|
2010-10-25 08:42:56 +02:00
|
|
|
import com.sk89q.worldedit.blocks.BaseItem;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.HashMap;
|
2010-10-14 10:31:05 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @author sk89q
|
|
|
|
*/
|
|
|
|
public class SMServerInterface implements ServerInterface {
|
|
|
|
/**
|
|
|
|
* Set block type.
|
|
|
|
*
|
|
|
|
* @param pt
|
|
|
|
* @param type
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public boolean setBlockType(Vector pt, int type) {
|
2010-10-15 09:26:29 +02:00
|
|
|
// Can't set colored cloth or crash
|
|
|
|
if ((type >= 21 && type <= 34) || type == 36) {
|
|
|
|
return false;
|
|
|
|
}
|
2010-10-31 02:40:02 +02:00
|
|
|
etc.getServer().setBlockAt(type, pt.getBlockX(), pt.getBlockY(),
|
|
|
|
pt.getBlockZ());
|
|
|
|
return true;
|
2010-10-14 10:31:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get block type.
|
|
|
|
*
|
|
|
|
* @param pt
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public int getBlockType(Vector pt) {
|
2010-10-31 02:40:02 +02:00
|
|
|
return etc.getServer().getBlockIdAt(pt.getBlockX(), pt.getBlockY(),
|
|
|
|
pt.getBlockZ());
|
2010-10-14 10:31:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set block data.
|
|
|
|
*
|
|
|
|
* @param pt
|
|
|
|
* @param data
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public void setBlockData(Vector pt, int data) {
|
2010-10-25 08:45:49 +02:00
|
|
|
etc.getServer().setBlockData(pt.getBlockX(), pt.getBlockY(),
|
2010-10-14 10:31:05 +02:00
|
|
|
pt.getBlockZ(), data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get block data.
|
|
|
|
*
|
|
|
|
* @param pt
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public int getBlockData(Vector pt) {
|
2010-10-31 02:40:02 +02:00
|
|
|
return etc.getServer().getBlockData(pt.getBlockX(), pt.getBlockY(),
|
|
|
|
pt.getBlockZ());
|
2010-10-14 10:31:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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());
|
2010-10-17 01:45:31 +02:00
|
|
|
if (signData == null) {
|
|
|
|
return;
|
|
|
|
}
|
2010-10-14 10:31:05 +02:00
|
|
|
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());
|
2010-10-17 01:45:31 +02:00
|
|
|
if (signData == null) {
|
|
|
|
return new String[]{"", "", "", ""};
|
|
|
|
}
|
2010-10-14 10:31:05 +02:00
|
|
|
String[] text = new String[4];
|
|
|
|
for (byte i = 0; i < 4; i++) {
|
|
|
|
text[i] = signData.getText(i);
|
|
|
|
}
|
|
|
|
return text;
|
|
|
|
}
|
2010-10-25 08:42:56 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the contents of chests.
|
|
|
|
*
|
|
|
|
* @param pt
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public Map<Byte,Countable<BaseItem>> getChestContents(Vector pt) {
|
|
|
|
ComplexBlock cblock = etc.getServer().getComplexBlock(
|
|
|
|
pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
|
|
|
|
|
|
|
|
if (!(cblock instanceof Chest)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
Chest chest = (Chest)cblock;
|
|
|
|
Map<Byte,Countable<BaseItem>> items =
|
|
|
|
new HashMap<Byte,Countable<BaseItem>>();
|
|
|
|
|
|
|
|
for (byte i = 0; i <= 26; i++) {
|
|
|
|
Item item = chest.getItemFromSlot(i);
|
|
|
|
if (item != null) {
|
|
|
|
items.put(i, new Countable(new BaseItem((short)item.getItemId()), item.getAmount()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return items;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets a chest slot.
|
|
|
|
*
|
|
|
|
* @param pt
|
|
|
|
* @param slot
|
|
|
|
* @param item
|
|
|
|
* @param amount
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public boolean setChestSlot(Vector pt, byte slot, BaseItem item, int amount) {
|
|
|
|
ComplexBlock cblock = etc.getServer().getComplexBlock(
|
|
|
|
pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
|
|
|
|
|
|
|
|
if (!(cblock instanceof Chest)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Chest chest = (Chest)cblock;
|
|
|
|
chest.addItem(new Item(item.getID(), amount, slot));
|
|
|
|
chest.update();
|
|
|
|
return true;
|
|
|
|
}
|
2010-10-14 10:31:05 +02:00
|
|
|
}
|