mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-23 01:37:37 +00:00
Finished abstraction.
This commit is contained in:
parent
ecce855db2
commit
16761dfb5c
@ -261,7 +261,7 @@ public class HMPlayer extends WorldEditPlayer {
|
||||
* Get this player's block bag.
|
||||
*/
|
||||
public BlockBag getInventoryBlockBag() {
|
||||
return new PlayerInventoryBlockBag(player);
|
||||
return new HMPlayerInventoryBlockBag(player);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -20,7 +20,7 @@
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.bags.*;
|
||||
|
||||
public class PlayerInventoryBlockBag extends BlockBag {
|
||||
public class HMPlayerInventoryBlockBag extends BlockBag {
|
||||
/**
|
||||
* Player instance.
|
||||
*/
|
||||
@ -35,7 +35,7 @@ public class PlayerInventoryBlockBag extends BlockBag {
|
||||
*
|
||||
* @param player
|
||||
*/
|
||||
public PlayerInventoryBlockBag(Player player) {
|
||||
public HMPlayerInventoryBlockBag(Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
@ -391,4 +391,36 @@ public class HMServerInterface extends ServerInterface {
|
||||
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
Executable file
227
src/HMWorldEditListener.java
Executable file
@ -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));
|
||||
}
|
||||
}
|
@ -20,6 +20,8 @@
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.sk89q.worldedit.ServerInterface;
|
||||
|
||||
/**
|
||||
* Entry point for the plugin for hey0's mod.
|
||||
*
|
||||
@ -33,7 +35,7 @@ public class WorldEdit extends Plugin {
|
||||
/**
|
||||
* 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
|
||||
@ -61,6 +63,8 @@ public class WorldEdit extends Plugin {
|
||||
loader.addListener(PluginLoader.Hook.ARM_SWING, listener, this,
|
||||
PluginListener.Priority.MEDIUM);
|
||||
|
||||
ServerInterface.setup(new HMServerInterface());
|
||||
|
||||
logger.log(Level.INFO, "WorldEdit version " + getVersion() + " loaded");
|
||||
}
|
||||
|
||||
@ -116,7 +120,7 @@ public class WorldEdit extends Plugin {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public WorldEditListener getListener() {
|
||||
public HMWorldEditListener getListener() {
|
||||
return listener;
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
package com.sk89q.worldedit;
|
||||
// $Id$
|
||||
/*
|
||||
* WorldEditLibrary
|
||||
@ -17,9 +18,6 @@
|
||||
* 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.filters.HeightMapFilter;
|
||||
import com.sk89q.worldedit.regions.Region;
|
@ -1,4 +1,3 @@
|
||||
package com.sk89q.worldedit;
|
||||
// $Id$
|
||||
/*
|
||||
* WorldEdit
|
||||
@ -18,7 +17,8 @@ package com.sk89q.worldedit;
|
||||
* 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;
|
||||
|
||||
/**
|
||||
@ -191,4 +191,21 @@ public abstract class ServerInterface {
|
||||
* @param 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);
|
||||
}
|
||||
|
363
src/WorldEditListener.java → src/com/sk89q/worldedit/WorldEditController.java
Executable file → Normal file
363
src/WorldEditListener.java → src/com/sk89q/worldedit/WorldEditController.java
Executable file → Normal file
@ -17,18 +17,16 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit;
|
||||
|
||||
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.*;
|
||||
@ -42,7 +40,7 @@ import com.sk89q.worldedit.patterns.*;
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class WorldEditListener extends PluginListener {
|
||||
public class WorldEditController {
|
||||
/**
|
||||
* Logger.
|
||||
*/
|
||||
@ -62,10 +60,6 @@ public class WorldEditListener extends PluginListener {
|
||||
*/
|
||||
private ServerInterface server;
|
||||
|
||||
/**
|
||||
* WorldEditLibrary's properties file.
|
||||
*/
|
||||
private PropertiesFile properties;
|
||||
/**
|
||||
* Stores a list of WorldEdit sessions, keyed by players' names. Sessions
|
||||
* 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 =
|
||||
new HashMap<WorldEditPlayer,WorldEditSession>();
|
||||
|
||||
/**
|
||||
* List of commands. These are checked when onCommand() is called, so
|
||||
* 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 boolean profile;
|
||||
private HashSet<Integer> allowedBlocks;
|
||||
private int defaultChangeLimit = -1;
|
||||
private int maxChangeLimit = -1;
|
||||
private String shellSaveType;
|
||||
private SnapshotRepository snapshotRepo;
|
||||
private int maxRadius = -1;
|
||||
private int maxSuperPickaxeSize = 5;
|
||||
private boolean logComands = false;
|
||||
private boolean registerHelp = true;
|
||||
private int wandItem = 271;
|
||||
private boolean superPickaxeDrop = true;
|
||||
private boolean superPickaxeManyDrop = true;
|
||||
private boolean noDoubleSlash = false;
|
||||
private boolean useInventory = false;
|
||||
private boolean useInventoryOverride = false;
|
||||
public boolean profile;
|
||||
public HashSet<Integer> allowedBlocks;
|
||||
public int defaultChangeLimit = -1;
|
||||
public int maxChangeLimit = -1;
|
||||
public String shellSaveType;
|
||||
public SnapshotRepository snapshotRepo;
|
||||
public int maxRadius = -1;
|
||||
public int maxSuperPickaxeSize = 5;
|
||||
public boolean logComands = false;
|
||||
public boolean registerHelp = true;
|
||||
public int wandItem = 271;
|
||||
public boolean superPickaxeDrop = true;
|
||||
public boolean superPickaxeManyDrop = true;
|
||||
public boolean noDoubleSlash = false;
|
||||
public boolean useInventory = false;
|
||||
public boolean useInventoryOverride = false;
|
||||
|
||||
/**
|
||||
* Construct an instance of the plugin.
|
||||
*/
|
||||
public WorldEditListener() {
|
||||
public WorldEditController() {
|
||||
server = ServerInterface.getInstance();
|
||||
|
||||
// Note: Commands should only have the phrase 'air' at the end
|
||||
@ -256,7 +251,7 @@ public class WorldEditListener extends PluginListener {
|
||||
} catch (NumberFormatException e) {
|
||||
blockType = BlockType.lookup(testID);
|
||||
if (blockType == null) {
|
||||
int t = etc.getDataSource().getItem(testID);
|
||||
int t = server.resolveItem(testID);
|
||||
if (t > 0 && t < 256) {
|
||||
blockType = BlockType.fromID(t);
|
||||
}
|
||||
@ -1328,17 +1323,7 @@ public class WorldEditListener extends PluginListener {
|
||||
Math.max(1, Integer.parseInt(split[1])) : -1;
|
||||
|
||||
Vector origin = session.getPlacementPosition(player);
|
||||
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++;
|
||||
}
|
||||
}
|
||||
|
||||
int killed = server.killMobs(origin, radius);
|
||||
player.print("Killed " + killed + " mobs.");
|
||||
|
||||
return true;
|
||||
@ -1697,13 +1682,13 @@ public class WorldEditListener extends PluginListener {
|
||||
}
|
||||
return b.substring(0, b.length() - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param player
|
||||
*/
|
||||
@Override
|
||||
public void onDisconnect(Player player) {
|
||||
removeSession(new HMPlayer(player));
|
||||
public void handleDisconnect(WorldEditPlayer player) {
|
||||
removeSession(player);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1711,55 +1696,21 @@ public class WorldEditListener extends PluginListener {
|
||||
*
|
||||
* @param player
|
||||
*/
|
||||
public void onArmSwing(Player modPlayer) {
|
||||
WorldEditPlayer player = new HMPlayer(modPlayer);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public void handleArmSwing(WorldEditPlayer player) {
|
||||
if (!canUseCommand(player, "//"))
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on right click.
|
||||
*
|
||||
* @param modPlayer
|
||||
* @param blockPlaced
|
||||
* @param blockClicked
|
||||
* @param itemInHand
|
||||
* @param player
|
||||
* @param clicked
|
||||
* @return false if you want the action to go through
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public boolean onBlockCreate(Player modPlayer, Block blockPlaced,
|
||||
Block blockClicked, int itemInHand) {
|
||||
WorldEditPlayer player = new HMPlayer(modPlayer);
|
||||
public boolean handleBlockRightClick(WorldEditPlayer player, Vector clicked) {
|
||||
int itemInHand = player.getItemInHand();
|
||||
|
||||
// This prevents needless sessions from being created
|
||||
if (!hasSession(player) && !(itemInHand == wandItem &&
|
||||
@ -1769,30 +1720,22 @@ public class WorldEditListener extends PluginListener {
|
||||
|
||||
if (itemInHand == wandItem && session.isToolControlEnabled()
|
||||
&& canUseCommand(player, "//pos2")) {
|
||||
Vector cur = Vector.toBlockPoint(blockClicked.getX(),
|
||||
blockClicked.getY(),
|
||||
blockClicked.getZ());
|
||||
|
||||
session.setPos2(cur);
|
||||
session.setPos2(clicked);
|
||||
try {
|
||||
player.print("Second position set to " + cur
|
||||
player.print("Second position set to " + clicked
|
||||
+ " (" + session.getRegion().getSize() + ").");
|
||||
} catch (IncompleteRegionException e) {
|
||||
player.print("Second position set to " + cur + ".");
|
||||
player.print("Second position set to " + clicked + ".");
|
||||
}
|
||||
|
||||
return true;
|
||||
} else if (player.isHoldingPickAxe()
|
||||
&& session.getTool() == WorldEditSession.Tool.TREE) {
|
||||
Vector pos = Vector.toBlockPoint(blockClicked.getX(),
|
||||
blockClicked.getY() + 1,
|
||||
blockClicked.getZ());
|
||||
|
||||
EditSession editSession =
|
||||
new EditSession(session.getBlockChangeLimit());
|
||||
|
||||
try {
|
||||
if (!server.generateTree(editSession, pos)) {
|
||||
if (!server.generateTree(editSession, clicked)) {
|
||||
player.printError("Notch won't let you put a tree there.");
|
||||
}
|
||||
} finally {
|
||||
@ -1802,20 +1745,17 @@ public class WorldEditListener extends PluginListener {
|
||||
return true;
|
||||
} else if (player.isHoldingPickAxe()
|
||||
&& session.getTool() == WorldEditSession.Tool.INFO) {
|
||||
Vector pos = Vector.toBlockPoint(blockClicked.getX(),
|
||||
blockClicked.getY(),
|
||||
blockClicked.getZ());
|
||||
BaseBlock block = (new EditSession(0)).rawGetBlock(clicked);
|
||||
|
||||
BaseBlock block = (new EditSession(0)).rawGetBlock(pos);
|
||||
|
||||
player.printRaw(Colors.LightPurple + "@" + pos + ": " + Colors.Yellow
|
||||
+ "Type: " + block.getID() + Colors.LightGray + " ("
|
||||
player.print("\u00A79@" + clicked + ": " + "\u00A7e"
|
||||
+ "Type: " + block.getID() + "\u00A77" + " ("
|
||||
+ BlockType.fromID(block.getID()).getName() + ") "
|
||||
+ Colors.White
|
||||
+ "\u00A7f"
|
||||
+ "[" + block.getData() + "]");
|
||||
|
||||
if (block instanceof MobSpawnerBlock) {
|
||||
player.printRaw(Colors.Yellow + "Mob Type: " + ((MobSpawnerBlock)block).getMobType());
|
||||
player.printRaw("\u00A7e" + "Mob Type: "
|
||||
+ ((MobSpawnerBlock)block).getMobType());
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -1827,15 +1767,11 @@ public class WorldEditListener extends PluginListener {
|
||||
/**
|
||||
* Called on left click.
|
||||
*
|
||||
* @param modPlayer
|
||||
* @param blockClicked
|
||||
* @param itemInHand
|
||||
* @param player
|
||||
* @param clicked
|
||||
* @return false if you want the action to go through
|
||||
*/
|
||||
@Override
|
||||
public boolean onBlockDestroy(Player modPlayer, Block blockClicked) {
|
||||
WorldEditPlayer player = new HMPlayer(modPlayer);
|
||||
|
||||
public boolean handleBlockLeftClick(WorldEditPlayer player, Vector clicked) {
|
||||
if (!canUseCommand(player, "//pos1")
|
||||
&& !canUseCommand(player, "//")) { return false; }
|
||||
|
||||
@ -1843,29 +1779,25 @@ public class WorldEditListener extends PluginListener {
|
||||
|
||||
if (player.getItemInHand() == wandItem) {
|
||||
if (session.isToolControlEnabled()) {
|
||||
Vector cur = Vector.toBlockPoint(blockClicked.getX(),
|
||||
blockClicked.getY(),
|
||||
blockClicked.getZ());
|
||||
|
||||
// Bug workaround
|
||||
if (cur.getBlockX() == 0 && cur.getBlockY() == 0
|
||||
&& cur.getBlockZ() == 0) {
|
||||
if (clicked.getBlockX() == 0 && clicked.getBlockY() == 0
|
||||
&& clicked.getBlockZ() == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
if (session.getPos1().equals(cur)) {
|
||||
if (session.getPos1().equals(clicked)) {
|
||||
return false;
|
||||
}
|
||||
} catch (IncompleteRegionException e) {
|
||||
}
|
||||
|
||||
session.setPos1(cur);
|
||||
session.setPos1(clicked);
|
||||
try {
|
||||
player.print("First position set to " + cur
|
||||
player.print("First position set to " + clicked
|
||||
+ " (" + session.getRegion().getSize() + ").");
|
||||
} catch (IncompleteRegionException e) {
|
||||
player.print("First position set to " + cur + ".");
|
||||
player.print("First position set to " + clicked + ".");
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -1877,30 +1809,26 @@ public class WorldEditListener extends PluginListener {
|
||||
// Single block super pickaxe
|
||||
if (session.getSuperPickaxeMode() ==
|
||||
WorldEditSession.SuperPickaxeMode.SINGLE) {
|
||||
Vector pos = new Vector(blockClicked.getX(),
|
||||
blockClicked.getY(), blockClicked.getZ());
|
||||
if (server.getBlockType(pos) == 7 && !canBedrock) {
|
||||
if (server.getBlockType(clicked) == 7 && !canBedrock) {
|
||||
return true;
|
||||
} else if (server.getBlockType(pos) == 46) {
|
||||
} else if (server.getBlockType(clicked) == 46) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (superPickaxeDrop) {
|
||||
server.simulateBlockMine(pos);
|
||||
server.simulateBlockMine(clicked);
|
||||
} else {
|
||||
server.setBlockType(pos, 0);
|
||||
server.setBlockType(clicked, 0);
|
||||
}
|
||||
|
||||
// Area super pickaxe
|
||||
} else if (session.getSuperPickaxeMode() ==
|
||||
WorldEditSession.SuperPickaxeMode.SAME_TYPE_AREA) {
|
||||
Vector origin = new Vector(blockClicked.getX(),
|
||||
blockClicked.getY(), blockClicked.getZ());
|
||||
int ox = blockClicked.getX();
|
||||
int oy = blockClicked.getY();
|
||||
int oz = blockClicked.getZ();
|
||||
int ox = clicked.getBlockX();
|
||||
int oy = clicked.getBlockY();
|
||||
int oz = clicked.getBlockZ();
|
||||
int size = session.getSuperPickaxeRange();
|
||||
int initialType = server.getBlockType(origin);
|
||||
int initialType = server.getBlockType(clicked);
|
||||
|
||||
if (initialType == 7 && !canBedrock) {
|
||||
return true;
|
||||
@ -1926,16 +1854,14 @@ public class WorldEditListener extends PluginListener {
|
||||
// Area super pickaxe
|
||||
} else if (session.getSuperPickaxeMode() ==
|
||||
WorldEditSession.SuperPickaxeMode.SAME_TYPE_RECURSIVE) {
|
||||
Vector origin = new Vector(blockClicked.getX(),
|
||||
blockClicked.getY(), blockClicked.getZ());
|
||||
int size = session.getSuperPickaxeRange();
|
||||
int initialType = server.getBlockType(origin);
|
||||
int initialType = server.getBlockType(clicked);
|
||||
|
||||
if (initialType == 7 && !canBedrock) {
|
||||
return true;
|
||||
}
|
||||
|
||||
recursiveSuperPickaxe(origin.toBlockVector(), origin, size,
|
||||
recursiveSuperPickaxe(clicked.toBlockVector(), clicked, size,
|
||||
initialType, new HashSet<BlockVector>());
|
||||
|
||||
return true;
|
||||
@ -1989,12 +1915,11 @@ public class WorldEditListener extends PluginListener {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param ply
|
||||
* @param player
|
||||
* @param split
|
||||
* @return whether the command was processed
|
||||
*/
|
||||
@Override
|
||||
public boolean onCommand(Player ply, String[] split) {
|
||||
public boolean handleCommand(WorldEditPlayer player, String[] split) {
|
||||
try {
|
||||
// Legacy /, command
|
||||
if (split[0].equals("/,")) {
|
||||
@ -2013,8 +1938,6 @@ public class WorldEditListener extends PluginListener {
|
||||
split[0] = split[0].substring(1);
|
||||
}
|
||||
|
||||
WorldEditPlayer player = new HMPlayer(ply);
|
||||
|
||||
if (canUseCommand(player, split[0])) {
|
||||
WorldEditSession session = getSession(player);
|
||||
BlockBag blockBag = session.getBlockBag(player);
|
||||
@ -2033,7 +1956,7 @@ public class WorldEditListener extends PluginListener {
|
||||
|
||||
if (profile) {
|
||||
long time = System.currentTimeMillis() - start;
|
||||
ply.sendMessage(Colors.Yellow + (time / 1000.0) + "s elapsed");
|
||||
player.print(( time / 1000.0) + "s elapsed");
|
||||
}
|
||||
|
||||
flushBlockBag(player, editSession);
|
||||
@ -2043,31 +1966,31 @@ public class WorldEditListener extends PluginListener {
|
||||
|
||||
return false;
|
||||
} catch (NumberFormatException e) {
|
||||
ply.sendMessage(Colors.Rose + "Number expected; string given.");
|
||||
player.printError("Number expected; string given.");
|
||||
} 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) {
|
||||
ply.sendMessage(Colors.Rose + "Block name '" + e3.getID() + "' was not recognized.");
|
||||
player.printError("Block name '" + e3.getID() + "' was not recognized.");
|
||||
} catch (InvalidItemException e4) {
|
||||
ply.sendMessage(Colors.Rose + e4.getMessage());
|
||||
player.printError(e4.getMessage());
|
||||
} 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) {
|
||||
ply.sendMessage(Colors.Rose + "Max blocks changed in an operation reached ("
|
||||
player.printError("Max blocks changed in an operation reached ("
|
||||
+ e5.getBlockLimit() + ").");
|
||||
} catch (MaxRadiusException e) {
|
||||
ply.sendMessage(Colors.Rose + "Maximum radius: " + maxRadius);
|
||||
player.printError("Maximum radius: " + maxRadius);
|
||||
} catch (UnknownDirectionException ue) {
|
||||
ply.sendMessage(Colors.Rose + "Unknown direction: " + ue.getDirection());
|
||||
player.printError("Unknown direction: " + ue.getDirection());
|
||||
} catch (InsufficientArgumentsException e6) {
|
||||
ply.sendMessage(Colors.Rose + e6.getMessage());
|
||||
player.printError(e6.getMessage());
|
||||
} catch (EmptyClipboardException ec) {
|
||||
ply.sendMessage(Colors.Rose + "Your clipboard is empty.");
|
||||
player.printError("Your clipboard is empty.");
|
||||
} catch (WorldEditException e7) {
|
||||
ply.sendMessage(Colors.Rose + e7.getMessage());
|
||||
player.printError(e7.getMessage());
|
||||
} catch (Throwable excp) {
|
||||
ply.sendMessage(Colors.Rose + "Please report this error: [See console]");
|
||||
ply.sendMessage(excp.getClass().getName() + ": " + excp.getMessage());
|
||||
player.printError("Please report this error: [See console]");
|
||||
player.printRaw(excp.getClass().getName() + ": " + excp.getMessage());
|
||||
excp.printStackTrace();
|
||||
}
|
||||
|
||||
@ -2138,112 +2061,6 @@ public class WorldEditListener extends PluginListener {
|
||||
|| 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.
|
||||
*
|
||||
@ -2261,4 +2078,28 @@ public class WorldEditListener extends PluginListener {
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,3 @@
|
||||
package com.sk89q.worldedit;
|
||||
// $Id$
|
||||
/*
|
||||
* WorldEdit
|
||||
@ -18,13 +17,13 @@ package com.sk89q.worldedit;
|
||||
* 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.bags.BlockBag;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.*;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
/**
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user