Removed hMod files, simplified configuration and usage.

This commit is contained in:
sk89q
2011-01-17 02:52:57 -08:00
parent a86a96f2d0
commit d70a6e3de7
18 changed files with 102 additions and 1821 deletions

View File

@ -1,123 +0,0 @@
// $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 java.io.IOException;
import java.util.HashSet;
import java.util.logging.FileHandler;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.sk89q.util.StringUtil;
import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.LogFormat;
import com.sk89q.worldedit.snapshots.SnapshotRepository;
/**
* Configuration for hMod.
*
* @author sk89q
*/
public class HMConfiguration extends LocalConfiguration {
/**
* Logger.
*/
private static final Logger logger = Logger.getLogger("Minecraft.WorldEdit");
/**
* Properties file.
*/
private PropertiesFile properties;
/**
* Construct the object.
*/
public HMConfiguration() {
properties = new PropertiesFile("worldedit.properties");
}
/**
* Loads the configuration.
*/
public void load() {
try {
properties.load();
} catch (IOException e) {
logger.warning("worldedit.properties could not be loaded: "
+ e.getMessage());
}
profile = properties.getBoolean("debug-profile", profile);
wandItem = properties.getInt("wand-item", wandItem);
defaultChangeLimit = Math.max(-1, properties.getInt(
"default-max-blocks-changed", defaultChangeLimit));
maxChangeLimit = Math.max(-1,
properties.getInt("max-blocks-changed", maxChangeLimit));
maxRadius = Math.max(-1, properties.getInt("max-radius", maxRadius));
maxSuperPickaxeSize = Math.max(1, properties.getInt(
"max-super-pickaxe-size", maxSuperPickaxeSize));
registerHelp = properties.getBoolean("register-help", registerHelp);
logComands = properties.getBoolean("log-commands", logComands);
superPickaxeDrop = properties.getBoolean("super-pickaxe-drop-items",
superPickaxeDrop);
superPickaxeManyDrop = properties.getBoolean(
"super-pickaxe-many-drop-items", superPickaxeManyDrop);
noDoubleSlash = properties.getBoolean("no-double-slash", noDoubleSlash);
useInventory = properties.getBoolean("use-inventory", useInventory);
useInventoryOverride = properties.getBoolean("use-inventory-override",
useInventoryOverride);
maxBrushRadius = properties.getInt("max-brush-radius", maxBrushRadius);
// Get disallowed blocks
disallowedBlocks = new HashSet<Integer>();
String defdisallowedBlocks = StringUtil.joinString(defaultDisallowedBlocks, ",", 0);
for (String b : properties.getString("disallowed-blocks",
defdisallowedBlocks).split(",")) {
try {
disallowedBlocks.add(Integer.parseInt(b));
} catch (NumberFormatException e) {
}
}
String snapshotsDir = properties.getString("snapshots-dir", "");
if (!snapshotsDir.trim().equals("")) {
snapshotRepo = new SnapshotRepository(snapshotsDir);
} else {
snapshotRepo = null;
}
String type = properties.getString("shell-save-type", "").trim();
shellSaveType = type.equals("") ? null : type;
String logFile = properties.getString("log-file", "");
if (!logFile.equals("")) {
try {
FileHandler handler = new FileHandler(logFile, true);
handler.setFormatter(new LogFormat());
logger.addHandler(handler);
} catch (IOException e) {
logger.log(Level.WARNING, "Could not use log file " + logFile + ": "
+ e.getMessage());
}
} else {
for (Handler handler : logger.getHandlers()) {
logger.removeHandler(handler);
}
}
}
}

View File

@ -1,269 +0,0 @@
// $Id$
/*
* WorldEditLibrary
* 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.LocalWorld;
import com.sk89q.worldedit.ServerInterface;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.WorldVector;
import com.sk89q.worldedit.bags.BlockBag;
import com.sk89q.worldedit.blocks.BlockType;
/**
*
* @author sk89q
*/
public class HMPlayer extends LocalPlayer {
/**
* Stores the player.
*/
private Player player;
/**
* World.
*/
private HMWorld world;
/**
* Construct the object.
*
* @param player
*/
public HMPlayer(ServerInterface server, HMWorld world, Player player) {
super(server);
this.player = player;
this.world = world;
}
/**
* Move the player.
*
* @param pos
*/
public void setPosition(Vector pos) {
setPosition(pos, (float)getPitch(), (float)getYaw());
}
/**
* Get the point of the block being looked at. May return null.
*
* @param range
* @return point
*/
public WorldVector getBlockTrace(int range) {
HitBlox hitBlox = new HitBlox(player,range, 0.2);
Block block = hitBlox.getTargetBlock();
if (block == null) {
return null;
}
return new WorldVector(world, block.getX(), block.getY(), block.getZ());
}
/**
* Get the point of the block being looked at. May return null.
*
* @param range
* @return point
*/
public WorldVector getSolidBlockTrace(int range) {
HitBlox hitBlox = new HitBlox(player,range, 0.2);
Block block = null;
while (hitBlox.getNextBlock() != null
&& BlockType.canPassThrough(hitBlox.getCurBlock().getType()));
block = hitBlox.getCurBlock();
if (block == null) {
return null;
}
return new WorldVector(world, block.getX(), block.getY(), block.getZ());
}
/**
* Get the ID of the item that the player is holding.
*
* @return
*/
public int getItemInHand() {
return player.getItemInHand();
}
/**
* Get the name of the player.
*
* @return String
*/
public String getName() {
return player.getName();
}
/**
* Get the player's view pitch.
*
* @return pitch
*/
public double getPitch() {
return player.getPitch();
}
/**
* Get the player's position.
*
* @return point
*/
public WorldVector getPosition() {
return new WorldVector(world, player.getX(), player.getY(), player.getZ());
}
/**
* Get the player's world.
*
* @return point
*/
public LocalWorld getWorld() {
return world;
}
/**
* Get the player's view yaw.
*
* @return yaw
*/
public double getYaw() {
return player.getRotation();
}
/**
* Gives the player an item.
*
* @param type
* @param amt
*/
public void giveItem(int type, int amt) {
player.giveItem(type, amt);
}
/**
* Pass through the wall that you are looking at.
*
* @param range
* @return whether the player was pass through
*/
public boolean passThroughForwardWall(int range) {
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++;
if (searchDist > 20) {
return false;
}
if (BlockType.canPassThrough(block.getType())) {
if (foundNext) {
Vector v = new Vector(block.getX(), block.getY() - 1, block.getZ());
if (BlockType.canPassThrough(world.getBlockType(v))) {
setPosition(v.add(0.5, 0, 0.5));
return true;
}
}
} else {
foundNext = true;
}
}
return false;
}
/**
* Print a message.
*
* @param msg
*/
public void printRaw(String msg) {
player.sendMessage(msg);
}
/**
* 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);
}
/**
* Get a player's list of groups.
*
* @return
*/
public String[] getGroups() {
return player.getGroups();
}
/**
* Checks if a player has permission.
*
* @return
*/
public boolean hasPermission(String perm) {
return player.canUseCommand("/" + perm);
}
/**
* Get this player's block bag.
*/
public BlockBag getInventoryBlockBag() {
return new HMPlayerInventoryBlockBag(player);
}
/**
* @return the player
*/
public Player getPlayerObject() {
return player;
}
}

View File

@ -1,203 +0,0 @@
// $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.bags.*;
public class HMPlayerInventoryBlockBag extends BlockBag {
/**
* Player instance.
*/
private Player player;
/**
* The player's inventory;
*/
private Item[] items;
/**
* Construct the object.
*
* @param player
*/
public HMPlayerInventoryBlockBag(Player player) {
this.player = player;
}
/**
* Loads inventory on first use.
*/
private void loadInventory() {
if (items == null) {
items = player.getInventory().getContents();
}
}
/**
* Get the player.
*
* @return
*/
public Player getPlayer() {
return player;
}
/**
* Get a block.
*
* @param id
*/
public void fetchBlock(int id) throws BlockBagException {
if (id == 0) {
throw new IllegalArgumentException("Can't fetch air block");
}
loadInventory();
boolean found = false;
for (int slot = 0; slot < items.length; slot++) {
Item item = items[slot];
if (item == null) continue;
if (item.getItemId() == id) {
int amount = item.getAmount();
// Unlimited
if (amount < 0) {
return;
}
if (amount > 1) {
item.setAmount(amount - 1);
found = true;
} else {
items[slot] = null;
found = true;
}
break;
}
}
if (found) {
} else {
throw new OutOfBlocksException();
}
}
/**
* Store a block.
*
* @param id
*/
public void storeBlock(int id) throws BlockBagException {
if (id == 0) {
throw new IllegalArgumentException("Can't store air block");
}
loadInventory();
boolean found = false;
int freeSlot = -1;
for (int slot = 0; slot < items.length; slot++) {
Item item = items[slot];
// Delay using up a free slot until we know there are no stacks
// of this item to merge into
if (item == null) {
if (freeSlot == -1) {
freeSlot = slot;
}
continue;
}
if (item.getItemId() == id) {
int amount = item.getAmount();
// Unlimited
if (amount < 0) {
return;
}
if (amount < 64) {
item.setAmount(amount + 1);
found = true;
break;
}
}
}
if (!found && freeSlot > -1) {
items[freeSlot] = new Item(id, 1);
found = true;
}
if (found) {
} else {
throw new OutOfSpaceException(id);
}
}
/**
* Flush any changes. This is called at the end.
*/
public void flushChanges() {
if (items != null) {
setContents(player.getInventory(), items);
items = null;
}
}
/**
* Adds a position to be used a source.
*
* @param pos
* @return
*/
public void addSourcePosition(Vector pos) {
}
/**
* Adds a position to be used a source.
*
* @param pos
* @return
*/
public void addSingleSourcePosition(Vector pos) {
}
/**
* Set the contents of an ItemArray.
*
* @param itemArray
* @param contents
*/
private static void setContents(Inventory itemArray, Item[] contents) {
int size = itemArray.getContentsSize();
for (int i = 0; i < size; i++) {
if (contents[i] == null) {
itemArray.removeItem(i);
} else {
itemArray.setSlot(contents[i], i);
}
}
}
}

View File

@ -1,46 +0,0 @@
// $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 HMServerInterface extends ServerInterface {
/**
* Resolves an item name to its ID.
*
* @param name
* @return
*/
public int resolveItem(String name) {
return etc.getDataSource().getItem(name);
}
/**
* Checks if a mob type is valid.
*
* @param type
* @return
*/
public boolean isValidMobType(String type) {
return Mob.isValid(type);
}
}

View File

@ -1,368 +0,0 @@
// $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 java.util.logging.Level;
import java.util.logging.Logger;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BaseItemStack;
/**
* World for hMod.
*
* @author sk89q
*/
public class HMWorld extends LocalWorld {
/**
* Logger.
*/
private final Logger logger = Logger.getLogger("Minecraft.WorldEdit");
/**
* Set block type.
*
* @param pt
* @param type
* @return
*/
public boolean setBlockType(Vector pt, int type) {
// Can't set colored cloth or crash
if ((type >= 21 && type <= 34) || type == 36) {
return false;
}
return etc.getServer().setBlockAt(type, pt.getBlockX(), pt.getBlockY(),
pt.getBlockZ());
}
/**
* Get block type.
*
* @param pt
* @return
*/
public int getBlockType(Vector pt) {
return etc.getServer().getBlockIdAt(pt.getBlockX(), pt.getBlockY(),
pt.getBlockZ());
}
/**
* Set block data.
*
* @param pt
* @param data
* @return
*/
public void setBlockData(Vector pt, int data) {
etc.getServer().setBlockData(pt.getBlockX(), pt.getBlockY(),
pt.getBlockZ(), data);
}
/**
* Get block data.
*
* @param pt
* @return
*/
public int getBlockData(Vector pt) {
return etc.getServer().getBlockData(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());
if (signData == null) {
return;
}
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());
if (signData == null) {
return new String[]{"", "", "", ""};
}
String[] text = new String[4];
for (byte i = 0; i < 4; i++) {
text[i] = signData.getText(i);
}
return text;
}
/**
* 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 BaseItemStack[] getChestContents(Vector pt) {
ComplexBlock cblock = etc.getServer().getOnlyComplexBlock(
pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
BaseItemStack[] items;
Item[] nativeItems;
if (cblock instanceof Chest) {
Chest chest = (Chest)cblock;
nativeItems = chest.getContents();
} else {
return null;
}
items = new BaseItemStack[nativeItems.length];
for (byte i = 0; i < nativeItems.length; i++) {
Item item = nativeItems[i];
if (item != null) {
items[i] = new BaseItemStack((short)item.getItemId(),
item.getAmount(), (short)item.getDamage());
}
}
return items;
}
/**
* Sets a chest slot.
*
* @param pt
* @param contents
* @return
*/
public boolean setChestContents(Vector pt,
BaseItemStack[] contents) {
ComplexBlock cblock = etc.getServer().getOnlyComplexBlock(
pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
if (cblock instanceof Chest) {
Chest chest = (Chest)cblock;
Item[] nativeItems = new Item[contents.length];
for (int i = 0; i < contents.length; i++) {
BaseItemStack item = contents[i];
if (item != null) {
Item nativeItem =
new Item(item.getID(), item.getAmount());
nativeItem.setDamage(item.getDamage());
nativeItems[i] = nativeItem;
}
}
setContents(chest, nativeItems);
}
return false;
}
/**
* Clear a chest's contents.
*
* @param pt
*/
public boolean clearChest(Vector pt) {
ComplexBlock cblock = etc.getServer().getOnlyComplexBlock(
pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
if (cblock instanceof Chest) {
Chest chest = (Chest)cblock;
chest.clearContents();
chest.update();
return true;
}
return false;
}
/**
* Set the contents of an ItemArray.
*
* @param itemArray
* @param contents
*/
private void setContents(ItemArray<?> itemArray, Item[] contents) {
int size = contents.length;
for (int i = 0; i < size; i++) {
if (contents[i] == null) {
itemArray.removeItem(i);
} else {
itemArray.setSlot(contents[i].getItemId(),
contents[i].getAmount(), contents[i].getDamage(), i);
}
}
}
/**
* Set mob spawner mob type.
*
* @param pt
* @param mobType
*/
public void setMobSpawnerType(Vector pt, String mobType) {
ComplexBlock cblock = etc.getServer().getComplexBlock(
pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
if (!(cblock instanceof MobSpawner)) {
return;
}
MobSpawner mobSpawner = (MobSpawner)cblock;
mobSpawner.setSpawn(mobType);
mobSpawner.update();
}
/**
* Get mob spawner mob type. May return an empty string.
*
* @param pt
* @param mobType
*/
public String getMobSpawnerType(Vector pt) {
try {
return MinecraftServerInterface.getMobSpawnerType(pt);
} catch (Throwable t) {
logger.severe("Failed to get mob spawner type (do you need to update WorldEdit due to a Minecraft update?): "
+ t.getMessage());
return "";
}
}
/**
* Generate a tree at a location.
*
* @param pt
* @return
*/
public boolean generateTree(EditSession editSession, Vector pt) {
try {
return MinecraftServerInterface.generateTree(editSession, pt);
} catch (Throwable t) {
logger.log(Level.SEVERE,
"Failed to create tree (do you need to update WorldEdit " +
"due to a Minecraft update?)", t);
return false;
}
}
/**
* Generate a big tree at a location.
*
* @param pt
* @return
*/
public boolean generateBigTree(EditSession editSession, Vector pt) {
try {
return MinecraftServerInterface.generateBigTree(editSession, pt);
} catch (Throwable t) {
logger.log(Level.SEVERE,
"Failed to create big tree (do you need to update WorldEdit " +
"due to a Minecraft update?)", t);
return false;
}
}
/**
* Drop an item.
*
* @param pt
* @param type
* @param count
* @param times
*/
public void dropItem(Vector pt, int type, int count) {
etc.getServer().dropItem(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(),
type, count);
}
/**
* Drop an item.
*
* @param pt
* @param type
* @param count
* @param times
*/
public void dropItem(Vector pt, int type) {
etc.getServer().dropItem(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(),
type, 1);
}
/**
* Kill mobs in an area.
*
* @param origin
* @param radius
* @return
*/
public int killMobs(Vector origin, int radius) {
int killed = 0;
for (Mob mob : etc.getServer().getMobList()) {
Vector mobPos = new Vector(mob.getX(), mob.getY(), mob.getZ());
if (mob.getHealth() > 0
&& (radius == -1 || mobPos.distance(origin) <= radius)) {
mob.setHealth(0);
killed++;
}
}
for (Mob mob : etc.getServer().getAnimalList()) {
Vector mobPos = new Vector(mob.getX(), mob.getY(), mob.getZ());
if (mob.getHealth() > 0
&& (radius == -1 || mobPos.distance(origin) <= radius)) {
mob.setHealth(0);
killed++;
}
}
return killed;
}
@Override
public boolean equals(Object other) {
return other instanceof HMWorld;
}
@Override
public int hashCode() {
return 1;
}
}

View File

@ -1,175 +0,0 @@
// $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 java.util.Map;
import com.sk89q.worldedit.*;
/**
* The event listener for WorldEdit in hMod.
*
* @author sk89q
*/
public class HMWorldEditListener extends PluginListener {
/**
* Main WorldEdit controller.
*/
private WorldEditController controller;
/**
* Configuration.
*/
private LocalConfiguration config;
/**
* A copy of the server instance. This is where all world<->WorldEdit calls
* will go through.
*/
private ServerInterface server;
/**
* A copy of a world, not that hMod/MC supports multiple worlds.
*/
private HMWorld world;
/**
* Constructs an instance.
*
* @param server
*/
public HMWorldEditListener(ServerInterface server) {
this.server = server;
config = new HMConfiguration();
controller = new WorldEditController(server, config);
world = new HMWorld();
}
/**
*
* @param player
*/
@Override
public void onDisconnect(Player player) {
controller.handleDisconnect(wrapPlayer(player));
}
/**
* Called on arm swing.
*
* @param player
*/
public void onArmSwing(Player player) {
controller.handleArmSwing(wrapPlayer(player));
}
/**
* Called on right click.
*
* @param player
* @param blockPlaced
* @param blockClicked
* @param itemInHand
* @return false if you want the action to go through
*/
@Override
@SuppressWarnings("deprecation")
public boolean onBlockCreate(Player player, Block blockPlaced,
Block blockClicked, int itemInHand) {
WorldVector pos = new WorldVector(world, blockClicked.getX(),
blockClicked.getY(), blockClicked.getZ());
return controller.handleBlockRightClick(wrapPlayer(player), pos);
}
/**
* Called on left click.
*
* @param player
* @param blockClicked
* @param itemInHand
* @return false if you want the action to go through
*/
@Override
public boolean onBlockDestroy(Player player, Block blockClicked) {
WorldVector pos = new WorldVector(world, blockClicked.getX(),
blockClicked.getY(), blockClicked.getZ());
return controller.handleBlockLeftClick(wrapPlayer(player), pos);
}
/**
*
* @param player
* @param split
* @return whether the command was processed
*/
@Override
public boolean onCommand(Player player, String[] split) {
return controller.handleCommand(wrapPlayer(player), split);
}
/**
* Loads the configuration.
*/
public void loadConfiguration() {
config.load();
}
/**
* Register commands with help.
*/
public void registerCommands() {
if (config.registerHelp) {
for (Map.Entry<String,String> entry : controller.getCommands().entrySet()) {
etc.getInstance().addCommand(entry.getKey(), entry.getValue());
}
}
}
/**
* De-register commands.
*/
public void deregisterCommands() {
for (String key : controller.getCommands().keySet()) {
etc.getInstance().removeCommand(key);
}
}
/**
* Clear sessions.
*/
public void clearSessions() {
controller.clearSessions();
}
/**
* Gets the WorldEditLibrary session for a player. Used for the bridge.
*
* @param player
* @return
*/
public LocalSession _bridgeSession(Player player) {
return controller.getBridgeSession(wrapPlayer(player));
}
/**
* Wrap a hMod player for WorldEdit.
*
* @param player
* @return
*/
private LocalPlayer wrapPlayer(Player player) {
return new HMPlayer(server, world, player);
}
}

View File

@ -1,128 +0,0 @@
// $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 java.util.logging.Logger;
import java.util.logging.Level;
import java.util.Random;
import java.lang.reflect.*;
import sun.reflect.ReflectionFactory;
import com.sk89q.worldedit.*;
/**
*
* @author sk89q
*/
public class MinecraftServerInterface {
/**
* Logger.
*/
private static final Logger logger = Logger.getLogger("Minecraft.WorldEdit");
/**
* Random generator.
*/
private static Random random = new Random();
/**
* Proxy for the tree generator.
*/
private static MinecraftSetBlockProxy proxy;
/**
* Perform world generation at a location.
*
* @param pt
* @return
*/
private static boolean performWorldGen(EditSession editSession, Vector pt,
bt worldGen) {
if (proxy == null) {
try {
proxy = createNoConstructor(MinecraftSetBlockProxy.class);
} catch (Throwable t) {
logger.log(Level.WARNING, "setBlock() proxy class failed to construct",
t);
return false;
}
}
proxy.setEditSession(editSession);
bt gen = worldGen;
return gen.a(proxy, random,
pt.getBlockX(), pt.getBlockY() + 1, pt.getBlockZ());
}
/**
* Generate a tree at a location.
*
* @param pt
* @return
*/
public static boolean generateTree(EditSession editSession, Vector pt) {
return performWorldGen(editSession, pt, new kl());
}
/**
* Generate a big tree at a location.
*
* @param pt
* @return
*/
public static boolean generateBigTree(EditSession editSession, Vector pt) {
return performWorldGen(editSession, pt, new ib());
}
/**
* Get mob spawner mob type. May return an empty string.
*
* @param pt
* @param mobType
*/
public static String getMobSpawnerType(Vector pt) {
bg o = etc.getMCServer().e.l(
pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
if (o != null && o instanceof cq) {
String type = ((cq)o).f;
return type != null ? type : "";
}
return "";
}
/**
* Instantiate a class without calling its constructor.
*
* @param <T>
* @param clazz
* @return
* @throws Throwable
*/
@SuppressWarnings("rawtypes")
private static <T> T createNoConstructor(Class<T> clazz) throws Throwable {
try {
ReflectionFactory factory = ReflectionFactory.getReflectionFactory();
Constructor objectConstructor = Object.class.getDeclaredConstructor();
Constructor c = factory.newConstructorForSerialization(
clazz, objectConstructor
);
return clazz.cast(c.newInstance());
} catch (Throwable e) {
throw e;
}
}
}

View File

@ -1,90 +0,0 @@
// $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.EditSession;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.blocks.BaseBlock;
/**
* Proxy class to catch calls to set blocks.
*
* @author sk89q
*/
public class MinecraftSetBlockProxy extends ff {
/**
* Edit session.
*/
private EditSession editSession;
/**
* Constructor that should NOT be called.
*
* @param editSession
*/
public MinecraftSetBlockProxy(EditSession editSession) {
super(null, "", (long)0, null);
throw new IllegalStateException("MinecraftSetBlockProxy constructor called (BAD)");
}
/**
* Called to set a block.
*
* @param x
* @param y
* @param z
* @param blockType
* @return
*/
@Override
public boolean a(int x, int y, int z, int blockType) {
try {
return editSession.setBlock(new Vector(x, y, z), new BaseBlock(blockType));
} catch (MaxChangedBlocksException ex) {
return false;
}
}
/**
* Called to get a block.
*
* @param x
* @param y
* @param z
* @return
*/
@Override
public int a(int x, int y, int z) {
return editSession.getBlock(new Vector(x, y, z)).getType();
}
/**
* @return
*/
public EditSession getEditSession() {
return editSession;
}
/**
* @param editSession
*/
public void setEditSession(EditSession editSession) {
this.editSession = editSession;
}
}

View File

@ -1,133 +0,0 @@
// $Id$
/*
* WorldEditLibrary
* 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 java.util.logging.Level;
import java.util.logging.Logger;
/**
* Entry point for the plugin for hey0's mod.
*
* @author sk89q
*/
public class WorldEdit extends Plugin {
/**
* Logger.
*/
private static final Logger logger = Logger
.getLogger("Minecraft.WorldEdit");
/**
* 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;
/**
* Construct an instance of the plugin.
*/
public WorldEdit() {
listener = new HMWorldEditListener(new HMServerInterface());
}
/**
* Initializes the plugin.
*/
@Override
public void initialize() {
PluginLoader loader = etc.getLoader();
loader.addListener(PluginLoader.Hook.BLOCK_CREATED, listener, this,
PluginListener.Priority.MEDIUM);
loader.addListener(PluginLoader.Hook.BLOCK_DESTROYED, listener, this,
PluginListener.Priority.MEDIUM);
loader.addListener(PluginLoader.Hook.COMMAND, listener, this,
PluginListener.Priority.MEDIUM);
loader.addListener(PluginLoader.Hook.DISCONNECT, listener, this,
PluginListener.Priority.MEDIUM);
loader.addListener(PluginLoader.Hook.LOGIN, listener, this,
PluginListener.Priority.MEDIUM);
loader.addListener(PluginLoader.Hook.ARM_SWING, listener, this,
PluginListener.Priority.MEDIUM);
logger.log(Level.INFO, "WorldEdit version " + getVersion() + " loaded");
}
/**
* Enables the plugin.
*/
@Override
public void enable() {
listener.loadConfiguration();
listener.registerCommands();
}
/**
* Disables the plugin.
*/
@Override
public void disable() {
listener.deregisterCommands();
listener.clearSessions();
}
/**
* Get the WorldEdit 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)";
}
}
return version;
}
/**
* Returns the listener for the WorldEdit bridge.
*
* @return
*/
public HMWorldEditListener getListener() {
return listener;
}
}

View File

@ -1,130 +0,0 @@
// $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 java.lang.reflect.*;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldEditNotInstalled;
import com.sk89q.worldedit.IncompleteRegionException;
/**
* Class to access WorldEdit from another plugin.
*
* @author sk89q
*/
public class WorldEditBridge {
/**
* Invokes an object's method through reflection.
*
* @param obj
* @param name
* @param args
* @param types
* @return
* @throws InvocationTargetException
* @throws IllegalAccessException
* @throws NoSuchMethodException
*/
private static Object invokeMethod(Object obj, String name, Object[] args,
Class<?> ... types) throws InvocationTargetException, IllegalAccessException,
NoSuchMethodException {
Method method = obj.getClass().getDeclaredMethod(name, types);
return method.invoke(obj, args);
}
/**
* Invokes a method through reflection.
*
* @param obj
* @param name
* @return
* @throws InvocationTargetException
* @throws IllegalAccessException
* @throws NoSuchMethodException
*/
private static Object invokeMethod(Object obj, String name)
throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {
Method method = obj.getClass().getDeclaredMethod(name, new Class[]{});
return method.invoke(obj, new Object[]{});
}
/**
* Get a point from the currently selected region.
*
* @param player
* @param methodName
* @return
* @throws WorldEditNotInstalled
* @throws IncompleteRegionException
*/
private static Vector getRegionPoint(Player player, String methodName)
throws WorldEditNotInstalled, IncompleteRegionException {
Plugin plugin = etc.getLoader().getPlugin("WorldEdit");
if (plugin == null) {
throw new WorldEditNotInstalled();
}
try {
Object listener = invokeMethod(plugin, "getListener");
Object session = invokeMethod(listener, "_bridgeSession",
new Object[]{ player }, Player.class);
Object region = invokeMethod(session, "getRegion");
Object minPoint = invokeMethod(region, methodName);
int x = (Integer)invokeMethod(minPoint, "getBlockX");
int y = (Integer)invokeMethod(minPoint, "getBlockY");
int z = (Integer)invokeMethod(minPoint, "getBlockZ");
return new Vector(x, y, z);
} catch (InvocationTargetException e) {
String exceptionName = e.getTargetException().getClass().getCanonicalName();
if (exceptionName.equals("com.sk89q.worldedit.IncompleteRegionException")) {
throw new IncompleteRegionException();
}
throw new WorldEditNotInstalled();
} catch (IllegalAccessException e) {
throw new WorldEditNotInstalled();
} catch (NoSuchMethodException e) {
throw new WorldEditNotInstalled();
}
}
/**
* Get the selection minimum point.
*
* @param player
* @return
* @throws WorldEditNotInstalled
* @throws IncompleteRegionException
*/
public static Vector getRegionMinimumPoint(Player player)
throws WorldEditNotInstalled, IncompleteRegionException {
return getRegionPoint(player, "getMinimumPoint");
}
/**
* Get the selection maximum point.
*
* @param player
* @return
* @throws WorldEditNotInstalled
* @throws IncompleteRegionException
*/
public static Vector getRegionMaximumPoint(Player player)
throws WorldEditNotInstalled, IncompleteRegionException {
return getRegionPoint(player, "getMaximumPoint");
}
}

View File

@ -20,6 +20,9 @@
package com.sk89q.worldedit.bukkit;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.logging.Logger;
import org.bukkit.Server;
import org.bukkit.entity.Player;
@ -56,6 +59,10 @@ public class WorldEditPlugin extends JavaPlugin {
logger.info("WorldEdit " + desc.getVersion() + " loaded.");
folder.mkdirs();
createDefaultConfiguration("config.yml");
config = new BukkitConfiguration(getConfiguration(), logger);
perms = new ConfigurationPermissionsResolver(getConfiguration());
loadConfiguration();
@ -85,6 +92,42 @@ public class WorldEditPlugin extends JavaPlugin {
blockListener, Priority.Normal, this);
}
private void createDefaultConfiguration(String name) {
File actual = new File(getDataFolder(), name);
if (!actual.exists()) {
InputStream input =
WorldEditPlugin.class.getResourceAsStream("/defaults/" + name);
if (input != null) {
FileOutputStream output = null;
try {
output = new FileOutputStream(actual);
byte[] buf = new byte[8192];
int length = 0;
while ((length = input.read(buf)) > 0) {
output.write(buf, 0, length);
}
logger.info("WorldEdit: Default configuration file written: "
+ name);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (input != null)
input.close();
} catch (IOException e) {}
try {
if (output != null)
output.close();
} catch (IOException e) {}
}
}
}
}
public void loadConfiguration() {
getConfiguration().load();
config.load();