3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-12-25 10:30:04 +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.
*/
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.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;
}

Datei anzeigen

@ -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 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.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
@ -60,6 +62,8 @@ public class WorldEdit extends Plugin {
PluginListener.Priority.MEDIUM);
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;
}
}

Datei anzeigen

@ -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;

Datei anzeigen

@ -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);
}

Datei-Diff unterdrückt, da er zu groß ist Diff laden

Datei anzeigen

@ -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;
/**
*