3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-11-09 21:10:05 +01:00

Finished abstraction.

Dieser Commit ist enthalten in:
sk89q 2010-12-31 17:40:07 -08:00
Ursprung ecce855db2
Commit 16761dfb5c
9 geänderte Dateien mit 2396 neuen und 2278 gelöschten Zeilen

Datei anzeigen

@ -261,7 +261,7 @@ public class HMPlayer extends WorldEditPlayer {
* Get this player's block bag. * Get this player's block bag.
*/ */
public BlockBag getInventoryBlockBag() { public BlockBag getInventoryBlockBag() {
return new PlayerInventoryBlockBag(player); return new HMPlayerInventoryBlockBag(player);
} }
/** /**

Datei anzeigen

@ -20,7 +20,7 @@
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.bags.*; import com.sk89q.worldedit.bags.*;
public class PlayerInventoryBlockBag extends BlockBag { public class HMPlayerInventoryBlockBag extends BlockBag {
/** /**
* Player instance. * Player instance.
*/ */
@ -35,7 +35,7 @@ public class PlayerInventoryBlockBag extends BlockBag {
* *
* @param player * @param player
*/ */
public PlayerInventoryBlockBag(Player player) { public HMPlayerInventoryBlockBag(Player player) {
this.player = player; this.player = player;
} }

Datei anzeigen

@ -391,4 +391,36 @@ public class HMServerInterface extends ServerInterface {
dropItem(pt, type); dropItem(pt, type);
} }
} }
/**
* Resolves an item name to its ID.
*
* @param name
* @return
*/
public int resolveItem(String name) {
return etc.getDataSource().getItem(name);
}
/**
* 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++;
}
}
return killed;
}
} }

227
src/HMWorldEditListener.java Ausführbare Datei
Datei anzeigen

@ -0,0 +1,227 @@
// $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.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;
import java.util.Set;
import java.util.HashSet;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.Handler;
import java.util.logging.FileHandler;
import java.io.*;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.bags.BlockBag;
import com.sk89q.worldedit.blocks.*;
import com.sk89q.worldedit.data.*;
import com.sk89q.worldedit.filters.*;
import com.sk89q.worldedit.snapshots.*;
import com.sk89q.worldedit.regions.*;
import com.sk89q.worldedit.patterns.*;
/**
* Plugin base.
*
* @author sk89q
*/
public class HMWorldEditListener extends PluginListener {
/**
* Logger.
*/
private static final Logger logger = Logger.getLogger("Minecraft.WorldEdit");
/**
* WorldEditLibrary's properties file.
*/
private PropertiesFile properties;
/**
* Main WorldEdit controller.
*/
private WorldEditController controller = new WorldEditController();
/**
*
* @param player
*/
@Override
public void onDisconnect(Player player) {
controller.handleDisconnect(new HMPlayer(player));
}
/**
* Called on arm swing.
*
* @param player
*/
public void onArmSwing(Player player) {
controller.handleArmSwing(new HMPlayer(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) {
Vector pos = new Vector(blockClicked.getX(),
blockClicked.getY(),
blockClicked.getZ());
return controller.handleBlockRightClick(new HMPlayer(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) {
Vector pos = new Vector(blockClicked.getX(),
blockClicked.getY(),
blockClicked.getZ());
return controller.handleBlockLeftClick(new HMPlayer(player), pos);
}
/**
*
* @param player
* @param split
* @return whether the command was processed
*/
@Override
public boolean onCommand(Player player, String[] split) {
return controller.handleCommand(new HMPlayer(player), split);
}
/**
* Loads the configuration.
*/
public void loadConfiguration() {
if (properties == null) {
properties = new PropertiesFile("worldedit.properties");
} else {
try {
properties.load();
} catch (IOException e) {
logger.warning("worldedit.properties could not be loaded: "
+ e.getMessage());
}
}
controller.profile = properties.getBoolean("debug-profile", false);
controller.wandItem = properties.getInt("wand-item", 271);
controller.defaultChangeLimit = Math.max(-1, properties.getInt("default-max-blocks-changed", -1));
controller.maxChangeLimit = Math.max(-1, properties.getInt("max-blocks-changed", -1));
controller.maxRadius = Math.max(-1, properties.getInt("max-radius", -1));
controller.maxSuperPickaxeSize = Math.max(1, properties.getInt("max-super-pickaxe-size", 5));
controller.registerHelp = properties.getBoolean("register-help", true);
controller.logComands = properties.getBoolean("log-commands", false);
controller.superPickaxeDrop = properties.getBoolean("super-pickaxe-drop-items", true);
controller.superPickaxeManyDrop = properties.getBoolean("super-pickaxe-many-drop-items", false);
controller.noDoubleSlash = properties.getBoolean("no-double-slash", false);
controller.useInventory = properties.getBoolean("use-inventory", false);
controller.useInventoryOverride = properties.getBoolean("use-inventory-override", false);
// Get allowed blocks
controller.allowedBlocks = new HashSet<Integer>();
for (String b : properties.getString("allowed-blocks",
WorldEditController.getDefaultAllowedBlocks()).split(",")) {
try {
controller.allowedBlocks.add(Integer.parseInt(b));
} catch (NumberFormatException e) {
}
}
String snapshotsDir = properties.getString("snapshots-dir", "");
if (!snapshotsDir.trim().equals("")) {
controller.snapshotRepo = new SnapshotRepository(snapshotsDir);
} else {
controller.snapshotRepo = null;
}
String type = properties.getString("shell-save-type", "").trim();
controller.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);
}
}
}
/**
* Register commands with help.
*/
public void registerCommands() {
if (controller.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 WorldEditSession _bridgeSession(Player player) {
return controller.getBridgeSession(new HMPlayer(player));
}
}

Datei anzeigen

@ -20,6 +20,8 @@
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import com.sk89q.worldedit.ServerInterface;
/** /**
* Entry point for the plugin for hey0's mod. * Entry point for the plugin for hey0's mod.
* *
@ -33,7 +35,7 @@ public class WorldEdit extends Plugin {
/** /**
* WorldEditLibrary instance. * WorldEditLibrary instance.
*/ */
private static final WorldEditListener listener = new WorldEditListener(); private static final HMWorldEditListener listener = new HMWorldEditListener();
/** /**
* WorldEdit version, fetched from the .jar's manifest. Used to print the * WorldEdit version, fetched from the .jar's manifest. Used to print the
@ -61,6 +63,8 @@ public class WorldEdit extends Plugin {
loader.addListener(PluginLoader.Hook.ARM_SWING, listener, this, loader.addListener(PluginLoader.Hook.ARM_SWING, listener, this,
PluginListener.Priority.MEDIUM); PluginListener.Priority.MEDIUM);
ServerInterface.setup(new HMServerInterface());
logger.log(Level.INFO, "WorldEdit version " + getVersion() + " loaded"); logger.log(Level.INFO, "WorldEdit version " + getVersion() + " loaded");
} }
@ -116,7 +120,7 @@ public class WorldEdit extends Plugin {
* *
* @return * @return
*/ */
public WorldEditListener getListener() { public HMWorldEditListener getListener() {
return listener; return listener;
} }
} }

Datei anzeigen

@ -1,3 +1,4 @@
package com.sk89q.worldedit;
// $Id$ // $Id$
/* /*
* WorldEditLibrary * WorldEditLibrary
@ -17,9 +18,6 @@
* 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.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.filters.HeightMapFilter; import com.sk89q.worldedit.filters.HeightMapFilter;
import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.Region;

Datei anzeigen

@ -1,4 +1,3 @@
package com.sk89q.worldedit;
// $Id$ // $Id$
/* /*
* WorldEdit * WorldEdit
@ -18,7 +17,8 @@ package com.sk89q.worldedit;
* 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.bags.BlockBag; package com.sk89q.worldedit;
import com.sk89q.worldedit.blocks.BaseItemStack; import com.sk89q.worldedit.blocks.BaseItemStack;
/** /**
@ -191,4 +191,21 @@ public abstract class ServerInterface {
* @param pt * @param pt
*/ */
public abstract void simulateBlockMine(Vector pt); public abstract void simulateBlockMine(Vector pt);
/**
* Resolves an item name to its ID.
*
* @param name
* @return
*/
public abstract int resolveItem(String name);
/**
* Kill mobs in an area.
*
* @param origin
* @param radius
* @return
*/
public abstract int killMobs(Vector origin, int radius);
} }

Datei anzeigen

@ -17,18 +17,16 @@
* 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;
import java.util.List; import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap; import java.util.HashMap;
import java.util.Set; import java.util.Set;
import java.util.HashSet; import java.util.HashSet;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.util.logging.Handler;
import java.util.logging.FileHandler;
import java.io.*; import java.io.*;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.bags.BlockBag; import com.sk89q.worldedit.bags.BlockBag;
import com.sk89q.worldedit.blocks.*; import com.sk89q.worldedit.blocks.*;
import com.sk89q.worldedit.data.*; import com.sk89q.worldedit.data.*;
@ -42,7 +40,7 @@ import com.sk89q.worldedit.patterns.*;
* *
* @author sk89q * @author sk89q
*/ */
public class WorldEditListener extends PluginListener { public class WorldEditController {
/** /**
* Logger. * Logger.
*/ */
@ -62,10 +60,6 @@ public class WorldEditListener extends PluginListener {
*/ */
private ServerInterface server; private ServerInterface server;
/**
* WorldEditLibrary's properties file.
*/
private PropertiesFile properties;
/** /**
* Stores a list of WorldEdit sessions, keyed by players' names. Sessions * Stores a list of WorldEdit sessions, keyed by players' names. Sessions
* persist only for the user's session. On disconnect, the session will be * persist only for the user's session. On disconnect, the session will be
@ -75,6 +69,7 @@ public class WorldEditListener extends PluginListener {
*/ */
private HashMap<WorldEditPlayer,WorldEditSession> sessions = private HashMap<WorldEditPlayer,WorldEditSession> sessions =
new HashMap<WorldEditPlayer,WorldEditSession>(); new HashMap<WorldEditPlayer,WorldEditSession>();
/** /**
* List of commands. These are checked when onCommand() is called, so * List of commands. These are checked when onCommand() is called, so
* the list must know about every command. On plugin load, the commands * the list must know about every command. On plugin load, the commands
@ -82,27 +77,27 @@ public class WorldEditListener extends PluginListener {
*/ */
private HashMap<String,String> commands = new HashMap<String,String>(); private HashMap<String,String> commands = new HashMap<String,String>();
private boolean profile; public boolean profile;
private HashSet<Integer> allowedBlocks; public HashSet<Integer> allowedBlocks;
private int defaultChangeLimit = -1; public int defaultChangeLimit = -1;
private int maxChangeLimit = -1; public int maxChangeLimit = -1;
private String shellSaveType; public String shellSaveType;
private SnapshotRepository snapshotRepo; public SnapshotRepository snapshotRepo;
private int maxRadius = -1; public int maxRadius = -1;
private int maxSuperPickaxeSize = 5; public int maxSuperPickaxeSize = 5;
private boolean logComands = false; public boolean logComands = false;
private boolean registerHelp = true; public boolean registerHelp = true;
private int wandItem = 271; public int wandItem = 271;
private boolean superPickaxeDrop = true; public boolean superPickaxeDrop = true;
private boolean superPickaxeManyDrop = true; public boolean superPickaxeManyDrop = true;
private boolean noDoubleSlash = false; public boolean noDoubleSlash = false;
private boolean useInventory = false; public boolean useInventory = false;
private boolean useInventoryOverride = false; public boolean useInventoryOverride = false;
/** /**
* Construct an instance of the plugin. * Construct an instance of the plugin.
*/ */
public WorldEditListener() { public WorldEditController() {
server = ServerInterface.getInstance(); server = ServerInterface.getInstance();
// Note: Commands should only have the phrase 'air' at the end // Note: Commands should only have the phrase 'air' at the end
@ -256,7 +251,7 @@ public class WorldEditListener extends PluginListener {
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
blockType = BlockType.lookup(testID); blockType = BlockType.lookup(testID);
if (blockType == null) { if (blockType == null) {
int t = etc.getDataSource().getItem(testID); int t = server.resolveItem(testID);
if (t > 0 && t < 256) { if (t > 0 && t < 256) {
blockType = BlockType.fromID(t); blockType = BlockType.fromID(t);
} }
@ -1328,17 +1323,7 @@ public class WorldEditListener extends PluginListener {
Math.max(1, Integer.parseInt(split[1])) : -1; Math.max(1, Integer.parseInt(split[1])) : -1;
Vector origin = session.getPlacementPosition(player); Vector origin = session.getPlacementPosition(player);
int killed = 0; int killed = server.killMobs(origin, radius);
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++;
}
}
player.print("Killed " + killed + " mobs."); player.print("Killed " + killed + " mobs.");
return true; return true;
@ -1697,13 +1682,13 @@ public class WorldEditListener extends PluginListener {
} }
return b.substring(0, b.length() - 1); return b.substring(0, b.length() - 1);
} }
/** /**
* *
* @param player * @param player
*/ */
@Override public void handleDisconnect(WorldEditPlayer player) {
public void onDisconnect(Player player) { removeSession(player);
removeSession(new HMPlayer(player));
} }
/** /**
@ -1711,55 +1696,21 @@ public class WorldEditListener extends PluginListener {
* *
* @param player * @param player
*/ */
public void onArmSwing(Player modPlayer) { public void handleArmSwing(WorldEditPlayer player) {
WorldEditPlayer player = new HMPlayer(modPlayer); if (!canUseCommand(player, "//"))
return;
if (!canUseCommand(player, "//")) { return; }
WorldEditSession session = getSession(player);
if (player.isHoldingPickAxe()) {
if (session.hasSuperPickAxe()) {
HitBlox hitBlox = new HitBlox(modPlayer, 5, 0.2);
Block block = null;
Set<BlockVector> pathBlocks = new HashSet<BlockVector>();
// Get blocks along the way.
while (hitBlox.getNextBlock() != null
&& BlockType.canPassThrough(hitBlox.getCurBlock().getType())) {
block = hitBlox.getCurBlock();
pathBlocks.add(new BlockVector(block.getX(), block.getY(), block.getZ()));
}
if (pathBlocks.size() > 0) {
// Loop through the list of mobs and find the ones to kill
for (Mob mob : etc.getServer().getMobList()) {
Vector mobPos = new BlockVector(mob.getX(), mob.getY(), mob.getZ());
if (mob.getHealth() > 0 && pathBlocks.contains(mobPos.toBlockVector())
|| pathBlocks.contains(mobPos.add(0, 1, 0).toBlockVector())
|| pathBlocks.contains(mobPos.add(0, -1, 0).toBlockVector())) {
mob.setHealth(0);
}
}
}
}
}
} }
/** /**
* Called on right click. * Called on right click.
* *
* @param modPlayer * @param player
* @param blockPlaced * @param clicked
* @param blockClicked
* @param itemInHand
* @return false if you want the action to go through * @return false if you want the action to go through
*/ */
@Override
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public boolean onBlockCreate(Player modPlayer, Block blockPlaced, public boolean handleBlockRightClick(WorldEditPlayer player, Vector clicked) {
Block blockClicked, int itemInHand) { int itemInHand = player.getItemInHand();
WorldEditPlayer player = new HMPlayer(modPlayer);
// This prevents needless sessions from being created // This prevents needless sessions from being created
if (!hasSession(player) && !(itemInHand == wandItem && if (!hasSession(player) && !(itemInHand == wandItem &&
@ -1769,30 +1720,22 @@ public class WorldEditListener extends PluginListener {
if (itemInHand == wandItem && session.isToolControlEnabled() if (itemInHand == wandItem && session.isToolControlEnabled()
&& canUseCommand(player, "//pos2")) { && canUseCommand(player, "//pos2")) {
Vector cur = Vector.toBlockPoint(blockClicked.getX(), session.setPos2(clicked);
blockClicked.getY(),
blockClicked.getZ());
session.setPos2(cur);
try { try {
player.print("Second position set to " + cur player.print("Second position set to " + clicked
+ " (" + session.getRegion().getSize() + ")."); + " (" + session.getRegion().getSize() + ").");
} catch (IncompleteRegionException e) { } catch (IncompleteRegionException e) {
player.print("Second position set to " + cur + "."); player.print("Second position set to " + clicked + ".");
} }
return true; return true;
} else if (player.isHoldingPickAxe() } else if (player.isHoldingPickAxe()
&& session.getTool() == WorldEditSession.Tool.TREE) { && session.getTool() == WorldEditSession.Tool.TREE) {
Vector pos = Vector.toBlockPoint(blockClicked.getX(),
blockClicked.getY() + 1,
blockClicked.getZ());
EditSession editSession = EditSession editSession =
new EditSession(session.getBlockChangeLimit()); new EditSession(session.getBlockChangeLimit());
try { try {
if (!server.generateTree(editSession, pos)) { if (!server.generateTree(editSession, clicked)) {
player.printError("Notch won't let you put a tree there."); player.printError("Notch won't let you put a tree there.");
} }
} finally { } finally {
@ -1802,20 +1745,17 @@ public class WorldEditListener extends PluginListener {
return true; return true;
} else if (player.isHoldingPickAxe() } else if (player.isHoldingPickAxe()
&& session.getTool() == WorldEditSession.Tool.INFO) { && session.getTool() == WorldEditSession.Tool.INFO) {
Vector pos = Vector.toBlockPoint(blockClicked.getX(), BaseBlock block = (new EditSession(0)).rawGetBlock(clicked);
blockClicked.getY(),
blockClicked.getZ());
BaseBlock block = (new EditSession(0)).rawGetBlock(pos); player.print("\u00A79@" + clicked + ": " + "\u00A7e"
+ "Type: " + block.getID() + "\u00A77" + " ("
player.printRaw(Colors.LightPurple + "@" + pos + ": " + Colors.Yellow
+ "Type: " + block.getID() + Colors.LightGray + " ("
+ BlockType.fromID(block.getID()).getName() + ") " + BlockType.fromID(block.getID()).getName() + ") "
+ Colors.White + "\u00A7f"
+ "[" + block.getData() + "]"); + "[" + block.getData() + "]");
if (block instanceof MobSpawnerBlock) { if (block instanceof MobSpawnerBlock) {
player.printRaw(Colors.Yellow + "Mob Type: " + ((MobSpawnerBlock)block).getMobType()); player.printRaw("\u00A7e" + "Mob Type: "
+ ((MobSpawnerBlock)block).getMobType());
} }
return true; return true;
@ -1827,15 +1767,11 @@ public class WorldEditListener extends PluginListener {
/** /**
* Called on left click. * Called on left click.
* *
* @param modPlayer * @param player
* @param blockClicked * @param clicked
* @param itemInHand
* @return false if you want the action to go through * @return false if you want the action to go through
*/ */
@Override public boolean handleBlockLeftClick(WorldEditPlayer player, Vector clicked) {
public boolean onBlockDestroy(Player modPlayer, Block blockClicked) {
WorldEditPlayer player = new HMPlayer(modPlayer);
if (!canUseCommand(player, "//pos1") if (!canUseCommand(player, "//pos1")
&& !canUseCommand(player, "//")) { return false; } && !canUseCommand(player, "//")) { return false; }
@ -1843,29 +1779,25 @@ public class WorldEditListener extends PluginListener {
if (player.getItemInHand() == wandItem) { if (player.getItemInHand() == wandItem) {
if (session.isToolControlEnabled()) { if (session.isToolControlEnabled()) {
Vector cur = Vector.toBlockPoint(blockClicked.getX(),
blockClicked.getY(),
blockClicked.getZ());
// Bug workaround // Bug workaround
if (cur.getBlockX() == 0 && cur.getBlockY() == 0 if (clicked.getBlockX() == 0 && clicked.getBlockY() == 0
&& cur.getBlockZ() == 0) { && clicked.getBlockZ() == 0) {
return false; return false;
} }
try { try {
if (session.getPos1().equals(cur)) { if (session.getPos1().equals(clicked)) {
return false; return false;
} }
} catch (IncompleteRegionException e) { } catch (IncompleteRegionException e) {
} }
session.setPos1(cur); session.setPos1(clicked);
try { try {
player.print("First position set to " + cur player.print("First position set to " + clicked
+ " (" + session.getRegion().getSize() + ")."); + " (" + session.getRegion().getSize() + ").");
} catch (IncompleteRegionException e) { } catch (IncompleteRegionException e) {
player.print("First position set to " + cur + "."); player.print("First position set to " + clicked + ".");
} }
return true; return true;
@ -1877,30 +1809,26 @@ public class WorldEditListener extends PluginListener {
// Single block super pickaxe // Single block super pickaxe
if (session.getSuperPickaxeMode() == if (session.getSuperPickaxeMode() ==
WorldEditSession.SuperPickaxeMode.SINGLE) { WorldEditSession.SuperPickaxeMode.SINGLE) {
Vector pos = new Vector(blockClicked.getX(), if (server.getBlockType(clicked) == 7 && !canBedrock) {
blockClicked.getY(), blockClicked.getZ());
if (server.getBlockType(pos) == 7 && !canBedrock) {
return true; return true;
} else if (server.getBlockType(pos) == 46) { } else if (server.getBlockType(clicked) == 46) {
return false; return false;
} }
if (superPickaxeDrop) { if (superPickaxeDrop) {
server.simulateBlockMine(pos); server.simulateBlockMine(clicked);
} else { } else {
server.setBlockType(pos, 0); server.setBlockType(clicked, 0);
} }
// Area super pickaxe // Area super pickaxe
} else if (session.getSuperPickaxeMode() == } else if (session.getSuperPickaxeMode() ==
WorldEditSession.SuperPickaxeMode.SAME_TYPE_AREA) { WorldEditSession.SuperPickaxeMode.SAME_TYPE_AREA) {
Vector origin = new Vector(blockClicked.getX(), int ox = clicked.getBlockX();
blockClicked.getY(), blockClicked.getZ()); int oy = clicked.getBlockY();
int ox = blockClicked.getX(); int oz = clicked.getBlockZ();
int oy = blockClicked.getY();
int oz = blockClicked.getZ();
int size = session.getSuperPickaxeRange(); int size = session.getSuperPickaxeRange();
int initialType = server.getBlockType(origin); int initialType = server.getBlockType(clicked);
if (initialType == 7 && !canBedrock) { if (initialType == 7 && !canBedrock) {
return true; return true;
@ -1926,16 +1854,14 @@ public class WorldEditListener extends PluginListener {
// Area super pickaxe // Area super pickaxe
} else if (session.getSuperPickaxeMode() == } else if (session.getSuperPickaxeMode() ==
WorldEditSession.SuperPickaxeMode.SAME_TYPE_RECURSIVE) { WorldEditSession.SuperPickaxeMode.SAME_TYPE_RECURSIVE) {
Vector origin = new Vector(blockClicked.getX(),
blockClicked.getY(), blockClicked.getZ());
int size = session.getSuperPickaxeRange(); int size = session.getSuperPickaxeRange();
int initialType = server.getBlockType(origin); int initialType = server.getBlockType(clicked);
if (initialType == 7 && !canBedrock) { if (initialType == 7 && !canBedrock) {
return true; return true;
} }
recursiveSuperPickaxe(origin.toBlockVector(), origin, size, recursiveSuperPickaxe(clicked.toBlockVector(), clicked, size,
initialType, new HashSet<BlockVector>()); initialType, new HashSet<BlockVector>());
return true; return true;
@ -1989,12 +1915,11 @@ public class WorldEditListener extends PluginListener {
/** /**
* *
* @param ply * @param player
* @param split * @param split
* @return whether the command was processed * @return whether the command was processed
*/ */
@Override public boolean handleCommand(WorldEditPlayer player, String[] split) {
public boolean onCommand(Player ply, String[] split) {
try { try {
// Legacy /, command // Legacy /, command
if (split[0].equals("/,")) { if (split[0].equals("/,")) {
@ -2013,8 +1938,6 @@ public class WorldEditListener extends PluginListener {
split[0] = split[0].substring(1); split[0] = split[0].substring(1);
} }
WorldEditPlayer player = new HMPlayer(ply);
if (canUseCommand(player, split[0])) { if (canUseCommand(player, split[0])) {
WorldEditSession session = getSession(player); WorldEditSession session = getSession(player);
BlockBag blockBag = session.getBlockBag(player); BlockBag blockBag = session.getBlockBag(player);
@ -2033,7 +1956,7 @@ public class WorldEditListener extends PluginListener {
if (profile) { if (profile) {
long time = System.currentTimeMillis() - start; long time = System.currentTimeMillis() - start;
ply.sendMessage(Colors.Yellow + (time / 1000.0) + "s elapsed"); player.print(( time / 1000.0) + "s elapsed");
} }
flushBlockBag(player, editSession); flushBlockBag(player, editSession);
@ -2043,31 +1966,31 @@ public class WorldEditListener extends PluginListener {
return false; return false;
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
ply.sendMessage(Colors.Rose + "Number expected; string given."); player.printError("Number expected; string given.");
} catch (IncompleteRegionException e2) { } catch (IncompleteRegionException e2) {
ply.sendMessage(Colors.Rose + "The edit region has not been fully defined."); player.printError("The edit region has not been fully defined.");
} catch (UnknownItemException e3) { } catch (UnknownItemException e3) {
ply.sendMessage(Colors.Rose + "Block name '" + e3.getID() + "' was not recognized."); player.printError("Block name '" + e3.getID() + "' was not recognized.");
} catch (InvalidItemException e4) { } catch (InvalidItemException e4) {
ply.sendMessage(Colors.Rose + e4.getMessage()); player.printError(e4.getMessage());
} catch (DisallowedItemException e4) { } catch (DisallowedItemException e4) {
ply.sendMessage(Colors.Rose + "Block '" + e4.getID() + "' not allowed (see WorldEdit configuration)."); player.printError("Block '" + e4.getID() + "' not allowed (see WorldEdit configuration).");
} catch (MaxChangedBlocksException e5) { } catch (MaxChangedBlocksException e5) {
ply.sendMessage(Colors.Rose + "Max blocks changed in an operation reached (" player.printError("Max blocks changed in an operation reached ("
+ e5.getBlockLimit() + ")."); + e5.getBlockLimit() + ").");
} catch (MaxRadiusException e) { } catch (MaxRadiusException e) {
ply.sendMessage(Colors.Rose + "Maximum radius: " + maxRadius); player.printError("Maximum radius: " + maxRadius);
} catch (UnknownDirectionException ue) { } catch (UnknownDirectionException ue) {
ply.sendMessage(Colors.Rose + "Unknown direction: " + ue.getDirection()); player.printError("Unknown direction: " + ue.getDirection());
} catch (InsufficientArgumentsException e6) { } catch (InsufficientArgumentsException e6) {
ply.sendMessage(Colors.Rose + e6.getMessage()); player.printError(e6.getMessage());
} catch (EmptyClipboardException ec) { } catch (EmptyClipboardException ec) {
ply.sendMessage(Colors.Rose + "Your clipboard is empty."); player.printError("Your clipboard is empty.");
} catch (WorldEditException e7) { } catch (WorldEditException e7) {
ply.sendMessage(Colors.Rose + e7.getMessage()); player.printError(e7.getMessage());
} catch (Throwable excp) { } catch (Throwable excp) {
ply.sendMessage(Colors.Rose + "Please report this error: [See console]"); player.printError("Please report this error: [See console]");
ply.sendMessage(excp.getClass().getName() + ": " + excp.getMessage()); player.printRaw(excp.getClass().getName() + ": " + excp.getMessage());
excp.printStackTrace(); excp.printStackTrace();
} }
@ -2138,112 +2061,6 @@ public class WorldEditListener extends PluginListener {
|| player.hasPermission("/worldedit"); || player.hasPermission("/worldedit");
} }
/**
* Loads the configuration.
*/
public void loadConfiguration() {
if (properties == null) {
properties = new PropertiesFile("worldedit.properties");
} else {
try {
properties.load();
} catch (IOException e) {
logger.warning("worldedit.properties could not be loaded: "
+ e.getMessage());
}
}
profile = properties.getBoolean("debug-profile", false);
wandItem = properties.getInt("wand-item", 271);
defaultChangeLimit = Math.max(-1, properties.getInt("default-max-blocks-changed", -1));
maxChangeLimit = Math.max(-1, properties.getInt("max-blocks-changed", -1));
maxRadius = Math.max(-1, properties.getInt("max-radius", -1));
maxSuperPickaxeSize = Math.max(1, properties.getInt("max-super-pickaxe-size", 5));
registerHelp = properties.getBoolean("register-help", true);
logComands = properties.getBoolean("log-commands", false);
superPickaxeDrop = properties.getBoolean("super-pickaxe-drop-items", true);
superPickaxeManyDrop = properties.getBoolean("super-pickaxe-many-drop-items", false);
noDoubleSlash = properties.getBoolean("no-double-slash", false);
useInventory = properties.getBoolean("use-inventory", false);
useInventoryOverride = properties.getBoolean("use-inventory-override", false);
// Get allowed blocks
allowedBlocks = new HashSet<Integer>();
for (String b : properties.getString("allowed-blocks",
WorldEditListener.getDefaultAllowedBlocks()).split(",")) {
try {
allowedBlocks.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);
}
}
}
/**
* Register commands with help.
*/
public void registerCommands() {
if (registerHelp) {
for (Map.Entry<String,String> entry : commands.entrySet()) {
etc.getInstance().addCommand(entry.getKey(), entry.getValue());
}
}
}
/**
* De-register commands.
*/
public void deregisterCommands() {
for (String key : commands.keySet()) {
etc.getInstance().removeCommand(key);
}
}
/**
* Gets the WorldEditLibrary session for a player. Used for the bridge.
*
* @param player
* @return
*/
public WorldEditSession _bridgeSession(Player pl) {
WorldEditPlayer player = new HMPlayer(pl);
if (sessions.containsKey(player)) {
return sessions.get(player);
} else {
WorldEditSession session = new WorldEditSession();
session.setBlockChangeLimit(defaultChangeLimit);
sessions.put(player, session);
return session;
}
}
/** /**
* Joins a string from an array of strings. * Joins a string from an array of strings.
* *
@ -2261,4 +2078,28 @@ public class WorldEditListener extends PluginListener {
} }
return buffer.toString(); return buffer.toString();
} }
/**
* @return the commands
*/
public HashMap<String, String> getCommands() {
return commands;
}
/**
* Gets the WorldEditLibrary session for a player. Used for the bridge.
*
* @param player
* @return
*/
public WorldEditSession getBridgeSession(WorldEditPlayer player) {
if (sessions.containsKey(player)) {
return sessions.get(player);
} else {
WorldEditSession session = new WorldEditSession();
session.setBlockChangeLimit(defaultChangeLimit);
sessions.put(player, session);
return session;
}
}
} }

Datei anzeigen

@ -1,4 +1,3 @@
package com.sk89q.worldedit;
// $Id$ // $Id$
/* /*
* WorldEdit * WorldEdit
@ -18,13 +17,13 @@ package com.sk89q.worldedit;
* 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;
import java.util.LinkedList;
import com.sk89q.worldedit.snapshots.Snapshot; import com.sk89q.worldedit.snapshots.Snapshot;
import com.sk89q.worldedit.bags.BlockBag; import com.sk89q.worldedit.bags.BlockBag;
import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.*;
import java.util.LinkedList;
/** /**
* *