This commit is contained in:
TomyLobo
2011-11-23 02:29:48 +01:00
parent 1a57f6e95d
commit 7e13b60a51
161 changed files with 1433 additions and 1412 deletions

View File

@ -36,9 +36,9 @@ public class BukkitConfiguration extends LocalConfiguration {
private YAMLProcessor config;
private Logger logger;
private FileHandler logFileHandler;
public boolean noOpPermissions = false;
public BukkitConfiguration(YAMLProcessor config, Logger logger) {
this.config = config;
this.logger = logger;
@ -53,7 +53,7 @@ public class BukkitConfiguration extends LocalConfiguration {
e.printStackTrace();
}
showFirstUseVersion = false;
profile = config.getBoolean("debug", profile);
wandItem = config.getInt("wand-item", wandItem);
defaultChangeLimit = Math.max(-1, config.getInt(
@ -74,7 +74,7 @@ public class BukkitConfiguration extends LocalConfiguration {
useInventoryOverride = config.getBoolean("use-inventory.allow-override",
useInventoryOverride);
maxBrushRadius = config.getInt("limits.max-brush-radius", maxBrushRadius);
navigationWand = config.getInt("navigation-wand.item", navigationWand);
navigationWandMaxDistance = config.getInt("navigation-wand.max-distance", navigationWandMaxDistance);
@ -82,18 +82,18 @@ public class BukkitConfiguration extends LocalConfiguration {
scriptsDir = config.getString("scripting.dir", scriptsDir);
saveDir = config.getString("saving.dir", saveDir);
disallowedBlocks = new HashSet<Integer>(config.getIntList("limits.disallowed-blocks", null));
allowedDataCycleBlocks = new HashSet<Integer>(config.getIntList("limits.allowed-data-cycle-blocks", null));
noOpPermissions = config.getBoolean("no-op-permissions", false);
LocalSession.MAX_HISTORY_SIZE = Math.max(0, config.getInt("history.size", 15));
LocalSession.EXPIRATION_GRACE = config.getInt("history.expiration", 10) * 60 * 1000;
String snapshotsDir = config.getString("snapshots.directory", "");
if (!snapshotsDir.isEmpty()){
if (!snapshotsDir.isEmpty()) {
snapshotRepo = new SnapshotRepository(snapshotsDir);
}
@ -116,11 +116,10 @@ public class BukkitConfiguration extends LocalConfiguration {
}
}
}
public void unload() {
if (logFileHandler != null) {
logFileHandler.close();
}
}
}
}

View File

@ -30,7 +30,7 @@ import com.sk89q.worldedit.cui.CUIEvent;
public class BukkitPlayer extends LocalPlayer {
private Player player;
private WorldEditPlugin plugin;
public BukkitPlayer(WorldEditPlugin plugin, ServerInterface server, Player player) {
super(server);
this.plugin = plugin;
@ -117,11 +117,11 @@ public class BukkitPlayer extends LocalPlayer {
public LocalWorld getWorld() {
return new BukkitWorld(player.getWorld());
}
@Override
public void dispatchCUIEvent(CUIEvent event) {
String[] params = event.getParameters();
if (params.length > 0) {
player.sendRawMessage("\u00A75\u00A76\u00A74\u00A75" + event.getTypeId()
+ "|" + StringUtil.joinString(params, "|"));
@ -129,7 +129,7 @@ public class BukkitPlayer extends LocalPlayer {
player.sendRawMessage("\u00A75\u00A76\u00A74\u00A75" + event.getTypeId());
}
}
@Override
public void dispatchCUIHandshake() {
player.sendRawMessage("\u00A75\u00A76\u00A74\u00A75");

View File

@ -37,7 +37,7 @@ public class BukkitPlayerBlockBag extends BlockBag {
* The player's inventory;
*/
private ItemStack[] items;
/**
* Construct the object.
*
@ -46,7 +46,7 @@ public class BukkitPlayerBlockBag extends BlockBag {
public BukkitPlayerBlockBag(Player player) {
this.player = player;
}
/**
* Loads inventory on first use.
*/
@ -55,7 +55,7 @@ public class BukkitPlayerBlockBag extends BlockBag {
items = player.getInventory().getContents();
}
}
/**
* Get the player.
*
@ -64,7 +64,7 @@ public class BukkitPlayerBlockBag extends BlockBag {
public Player getPlayer() {
return player;
}
/**
* Get a block.
*
@ -113,7 +113,7 @@ public class BukkitPlayerBlockBag extends BlockBag {
bukkitItem.setAmount(currentAmount - 1);
found = true;
} else {
items[slot] = null;
items[slot] = null;
found = true;
}
@ -196,7 +196,7 @@ public class BukkitPlayerBlockBag extends BlockBag {
throw new OutOfSpaceException(id);
}
/**
* Flush any changes. This is called at the end.
*/
@ -216,7 +216,7 @@ public class BukkitPlayerBlockBag extends BlockBag {
@Override
public void addSourcePosition(Vector pos) {
}
/**
* Adds a position to be used a source.
*

View File

@ -26,7 +26,7 @@ import com.sk89q.worldedit.ServerInterface;
public class BukkitServerInterface extends ServerInterface {
public Server server;
public WorldEditPlugin plugin;
public BukkitServerInterface(WorldEditPlugin plugin, Server server) {
this.plugin = plugin;
this.server = server;

View File

@ -30,10 +30,10 @@ import com.sk89q.worldedit.*;
import com.sk89q.worldedit.Vector;
public class BukkitUtil {
private BukkitUtil() {
private BukkitUtil() {
}
private static final Map<World,LocalWorld> wlw = new HashMap<World,LocalWorld>();
private static final Map<World, LocalWorld> wlw = new HashMap<World, LocalWorld>();
public static LocalWorld getLocalWorld(World w) {
LocalWorld lw = wlw.get(w);
@ -43,27 +43,27 @@ public class BukkitUtil {
}
return lw;
}
public static BlockVector toVector(Block block) {
return new BlockVector(block.getX(), block.getY(), block.getZ());
}
public static BlockVector toVector(BlockFace face) {
return new BlockVector(face.getModX(), face.getModY(), face.getModZ());
}
public static BlockWorldVector toWorldVector(Block block) {
return new BlockWorldVector(getLocalWorld(block.getWorld()), block.getX(), block.getY(), block.getZ());
}
public static Vector toVector(Location loc) {
return new Vector(loc.getX(), loc.getY(), loc.getZ());
}
public static Vector toVector(org.bukkit.util.Vector vector) {
return new Vector(vector.getX(), vector.getY(), vector.getZ());
}
public static Location toLocation(WorldVector pt) {
return new Location(toWorld(pt), pt.getX(), pt.getY(), pt.getZ());
}
@ -71,18 +71,18 @@ public class BukkitUtil {
public static Location toLocation(World world, Vector pt) {
return new Location(world, pt.getX(), pt.getY(), pt.getZ());
}
public static Location center(Location loc) {
return new Location(
loc.getWorld(),
loc.getBlockX()+0.5,
loc.getBlockY()+0.5,
loc.getBlockZ()+0.5,
loc.getBlockX() + 0.5,
loc.getBlockY() + 0.5,
loc.getBlockZ() + 0.5,
loc.getPitch(),
loc.getYaw()
);
}
public static Player matchSinglePlayer(Server server, String name) {
List<Player> players = server.matchPlayer(name);
if (players.size() == 0) {
@ -96,18 +96,19 @@ public class BukkitUtil {
}
public static World toWorld(WorldVector pt) {
return ((BukkitWorld)pt.getWorld()).getWorld();
return ((BukkitWorld) pt.getWorld()).getWorld();
}
/**
* Bukkit's Location class has serious problems with floating point
* precision.
*/
public static boolean equals(Location a, Location b) {
if (Math.abs(a.getX()-b.getX()) > EQUALS_PRECISION) return false;
if (Math.abs(a.getY()-b.getY()) > EQUALS_PRECISION) return false;
if (Math.abs(a.getZ()-b.getZ()) > EQUALS_PRECISION) return false;
if (Math.abs(a.getX() - b.getX()) > EQUALS_PRECISION) return false;
if (Math.abs(a.getY() - b.getY()) > EQUALS_PRECISION) return false;
if (Math.abs(a.getZ() - b.getZ()) > EQUALS_PRECISION) return false;
return true;
}
public static final double EQUALS_PRECISION = 0.0001;
}

View File

@ -61,7 +61,7 @@ import com.sk89q.worldedit.regions.Region;
public class BukkitWorld extends LocalWorld {
private World world;
/**
* Construct the object.
* @param world
@ -69,7 +69,7 @@ public class BukkitWorld extends LocalWorld {
public BukkitWorld(World world) {
this.world = world;
}
/**
* Get the world handle.
*
@ -78,7 +78,7 @@ public class BukkitWorld extends LocalWorld {
public World getWorld() {
return world;
}
/**
* Get the name of the world
*
@ -130,10 +130,10 @@ public class BukkitWorld extends LocalWorld {
* @return
*/
@Override
public boolean setTypeIdAndData(Vector pt, int type, int data){
public boolean setTypeIdAndData(Vector pt, int type, int data) {
return world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).setTypeIdAndData(type, (byte) data, true);
}
/**
* set block type & data
* @param pt
@ -142,7 +142,7 @@ public class BukkitWorld extends LocalWorld {
* @return
*/
@Override
public boolean setTypeIdAndDataFast(Vector pt, int type, int data){
public boolean setTypeIdAndDataFast(Vector pt, int type, int data) {
final Block block = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
if (fastLightingAvailable) {
type = type & 255;
@ -175,7 +175,7 @@ public class BukkitWorld extends LocalWorld {
*/
@Override
public void setBlockData(Vector pt, int data) {
world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).setData((byte)data);
world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).setData((byte) data);
}
/**
@ -186,7 +186,7 @@ public class BukkitWorld extends LocalWorld {
*/
@Override
public void setBlockDataFast(Vector pt, int data) {
world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).setData((byte)data, false);
world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).setData((byte) data, false);
}
/**
@ -221,10 +221,10 @@ public class BukkitWorld extends LocalWorld {
@Override
public boolean regenerate(Region region, EditSession editSession) {
BaseBlock[] history = new BaseBlock[16 * 16 * 128];
for (Vector2D chunk : region.getChunks()) {
Vector min = new Vector(chunk.getBlockX() * 16, 0, chunk.getBlockZ() * 16);
// First save all the blocks inside
for (int x = 0; x < 16; ++x) {
for (int y = 0; y < 128; ++y) {
@ -235,20 +235,20 @@ public class BukkitWorld extends LocalWorld {
}
}
}
try {
world.regenerateChunk(chunk.getBlockX(), chunk.getBlockZ());
} catch (Throwable t) {
t.printStackTrace();
}
// Then restore
for (int x = 0; x < 16; ++x) {
for (int y = 0; y < 128; ++y) {
for (int z = 0; z < 16; ++z) {
Vector pt = min.add(x, y, z);
int index = y * 16 * 16 + z * 16 + x;
// We have to restore the block if it was outside
if (!region.contains(pt)) {
editSession.smartSetBlock(pt, history[index]);
@ -260,7 +260,7 @@ public class BukkitWorld extends LocalWorld {
}
}
}
return true;
}
@ -273,51 +273,55 @@ public class BukkitWorld extends LocalWorld {
*/
@Override
public boolean copyToWorld(Vector pt, BaseBlock block) {
// Signs
if (block instanceof SignBlock) {
setSignText(pt, ((SignBlock)block).getText());
// Signs
setSignText(pt, ((SignBlock) block).getText());
return true;
// Furnaces
} else if (block instanceof FurnaceBlock) {
}
if (block instanceof FurnaceBlock) {
// Furnaces
Block bukkitBlock = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
if (bukkitBlock == null) return false;
BlockState state = bukkitBlock.getState();
if (!(state instanceof Furnace)) return false;
Furnace bukkit = (Furnace)state;
FurnaceBlock we = (FurnaceBlock)block;
Furnace bukkit = (Furnace) state;
FurnaceBlock we = (FurnaceBlock) block;
bukkit.setBurnTime(we.getBurnTime());
bukkit.setCookTime(we.getCookTime());
return setContainerBlockContents(pt, ((ContainerBlock)block).getItems());
// Chests/dispenser
} else if (block instanceof ContainerBlock) {
return setContainerBlockContents(pt, ((ContainerBlock)block).getItems());
// Mob spawners
} else if (block instanceof MobSpawnerBlock) {
return setContainerBlockContents(pt, ((ContainerBlock) block).getItems());
}
if (block instanceof ContainerBlock) {
// Chests/dispenser
return setContainerBlockContents(pt, ((ContainerBlock) block).getItems());
}
if (block instanceof MobSpawnerBlock) {
// Mob spawners
Block bukkitBlock = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
if (bukkitBlock == null) return false;
BlockState state = bukkitBlock.getState();
if (!(state instanceof CreatureSpawner)) return false;
CreatureSpawner bukkit = (CreatureSpawner)state;
MobSpawnerBlock we = (MobSpawnerBlock)block;
CreatureSpawner bukkit = (CreatureSpawner) state;
MobSpawnerBlock we = (MobSpawnerBlock) block;
bukkit.setCreatureTypeId(we.getMobType());
bukkit.setDelay(we.getDelay());
return true;
// Note block
} else if (block instanceof NoteBlock) {
}
if (block instanceof NoteBlock) {
// Note block
Block bukkitBlock = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
if (bukkitBlock == null) return false;
BlockState state = bukkitBlock.getState();
if (!(state instanceof org.bukkit.block.NoteBlock)) return false;
org.bukkit.block.NoteBlock bukkit = (org.bukkit.block.NoteBlock)state;
NoteBlock we = (NoteBlock)block;
org.bukkit.block.NoteBlock bukkit = (org.bukkit.block.NoteBlock) state;
NoteBlock we = (NoteBlock) block;
bukkit.setRawNote(we.getNote());
return true;
}
return false;
}
@ -330,13 +334,14 @@ public class BukkitWorld extends LocalWorld {
*/
@Override
public boolean copyFromWorld(Vector pt, BaseBlock block) {
// Signs
if (block instanceof SignBlock) {
// Signs
((SignBlock) block).setText(getSignText(pt));
return true;
// Furnaces
} else if (block instanceof FurnaceBlock) {
}
if (block instanceof FurnaceBlock) {
// Furnaces
Block bukkitBlock = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
if (bukkitBlock == null) return false;
BlockState state = bukkitBlock.getState();
@ -347,14 +352,16 @@ public class BukkitWorld extends LocalWorld {
we.setCookTime(bukkit.getCookTime());
((ContainerBlock) block).setItems(getContainerBlockContents(pt));
return true;
}
// Chests/dispenser
} else if (block instanceof ContainerBlock) {
if (block instanceof ContainerBlock) {
// Chests/dispenser
((ContainerBlock) block).setItems(getContainerBlockContents(pt));
return true;
// Mob spawners
} else if (block instanceof MobSpawnerBlock) {
}
if (block instanceof MobSpawnerBlock) {
// Mob spawners
Block bukkitBlock = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
if (bukkitBlock == null) return false;
BlockState state = bukkitBlock.getState();
@ -364,18 +371,19 @@ public class BukkitWorld extends LocalWorld {
we.setMobType(bukkit.getCreatureTypeId());
we.setDelay((short) bukkit.getDelay());
return true;
// Note block
} else if (block instanceof NoteBlock) {
}
if (block instanceof NoteBlock) {
// Note block
Block bukkitBlock = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
if (bukkitBlock == null) return false;
BlockState state = bukkitBlock.getState();
if (!(state instanceof org.bukkit.block.NoteBlock)) return false;
org.bukkit.block.NoteBlock bukkit = (org.bukkit.block.NoteBlock)state;
org.bukkit.block.NoteBlock bukkit = (org.bukkit.block.NoteBlock) state;
NoteBlock we = (NoteBlock) block;
we.setNote(bukkit.getRawNote());
}
return false;
}
@ -395,7 +403,7 @@ public class BukkitWorld extends LocalWorld {
return false;
}
org.bukkit.block.ContainerBlock chest = (org.bukkit.block.ContainerBlock)state;
org.bukkit.block.ContainerBlock chest = (org.bukkit.block.ContainerBlock) state;
Inventory inven = chest.getInventory();
inven.clear();
return true;
@ -472,7 +480,7 @@ public class BukkitWorld extends LocalWorld {
ItemStack bukkitItem = new ItemStack(item.getType(), item.getAmount(),
(byte) item.getDamage());
world.dropItemNaturally(toLocation(pt), bukkitItem);
}
/**
@ -499,7 +507,7 @@ public class BukkitWorld extends LocalWorld {
public int killMobs(Vector origin, int radius, boolean killPets) {
int num = 0;
double radiusSq = Math.pow(radius, 2);
for (LivingEntity ent : world.getLivingEntities()) {
if (!killPets && ent instanceof Tameable && ((Tameable) ent).isTamed()) {
continue; // tamed wolf
@ -512,10 +520,10 @@ public class BukkitWorld extends LocalWorld {
}
}
}
return num;
}
/**
* Remove entities in an area.
*
@ -527,54 +535,68 @@ public class BukkitWorld extends LocalWorld {
public int removeEntities(EntityType type, Vector origin, int radius) {
int num = 0;
double radiusSq = Math.pow(radius, 2);
for (Entity ent : world.getEntities()) {
if (radius != -1
&& origin.distanceSq(BukkitUtil.toVector(ent.getLocation())) > radiusSq) {
continue;
}
if (type == EntityType.ARROWS) {
switch (type) {
case ARROWS:
if (ent instanceof Arrow) {
ent.remove();
++num;
}
} else if (type == EntityType.BOATS) {
break;
case BOATS:
if (ent instanceof Boat) {
ent.remove();
++num;
}
} else if (type == EntityType.ITEMS) {
break;
case ITEMS:
if (ent instanceof Item) {
ent.remove();
++num;
}
} else if (type == EntityType.MINECARTS) {
break;
case MINECARTS:
if (ent instanceof Minecart) {
ent.remove();
++num;
}
} else if (type == EntityType.PAINTINGS) {
break;
case PAINTINGS:
if (ent instanceof Painting) {
ent.remove();
++num;
}
} else if (type == EntityType.TNT) {
break;
case TNT:
if (ent instanceof TNTPrimed) {
ent.remove();
++num;
}
} else if (type == EntityType.XP_ORBS) {
break;
case XP_ORBS:
if (ent instanceof ExperienceOrb) {
ent.remove();
++num;
}
break;
}
}
return num;
}
private Location toLocation(Vector pt) {
return new Location(world, pt.getX(), pt.getY(), pt.getZ());
}
@ -639,22 +661,22 @@ public class BukkitWorld extends LocalWorld {
if (!(state instanceof org.bukkit.block.ContainerBlock)) {
return new BaseItemStack[0];
}
org.bukkit.block.ContainerBlock container = (org.bukkit.block.ContainerBlock) state;
Inventory inven = container.getInventory();
int size = inven.getSize();
BaseItemStack[] contents = new BaseItemStack[size];
for (int i = 0; i < size; ++i) {
ItemStack bukkitStack = inven.getItem(i);
if (bukkitStack.getTypeId() > 0) {
contents[i] = new BaseItemStack(
bukkitStack.getTypeId(),
bukkitStack.getAmount(),
bukkitStack.getAmount(),
bukkitStack.getDurability());
}
}
return contents;
}
@ -674,11 +696,11 @@ public class BukkitWorld extends LocalWorld {
if (!(state instanceof org.bukkit.block.ContainerBlock)) {
return false;
}
org.bukkit.block.ContainerBlock chest = (org.bukkit.block.ContainerBlock)state;
org.bukkit.block.ContainerBlock chest = (org.bukkit.block.ContainerBlock) state;
Inventory inven = chest.getInventory();
int size = inven.getSize();
for (int i = 0; i < size; ++i) {
if (i >= contents.length) {
break;
@ -686,16 +708,16 @@ public class BukkitWorld extends LocalWorld {
if (contents[i] != null) {
inven.setItem(i, new ItemStack(contents[i].getType(),
contents[i].getAmount(),
contents[i].getAmount(),
(byte) contents[i].getDamage()));
} else {
inven.setItem(i, null);
}
}
return true;
}
/**
* Returns whether a block has a valid ID.
*
@ -719,7 +741,7 @@ public class BukkitWorld extends LocalWorld {
if (!(other instanceof BukkitWorld)) {
return false;
}
return ((BukkitWorld) other).world.equals(world);
}
@ -761,7 +783,7 @@ public class BukkitWorld extends LocalWorld {
final Object notchChunk = World_getChunkFromChunkCoords.invoke(notchWorld, chunkX, chunkZ);
// Fix skylight
final byte[] blocks = (byte[])Chunk_blocks.get(notchChunk);
final byte[] blocks = (byte[]) Chunk_blocks.get(notchChunk);
final int length = blocks.length;
Chunk_skylightMap.set(notchChunk, NibbleArray_ctor.newInstance(length, 7));
@ -781,7 +803,7 @@ public class BukkitWorld extends LocalWorld {
for (int y = 0; y < chunkSizeY; ++y) {
final int index = y + z * chunkSizeY + x * chunkSizeY * chunkSizeZ;
byte blockID = blocks[index];
if (!BlockType.emitsLight(blockID)) {
if (!BlockType.emitsLight(blockID)) {
if (xBorder || zBorder && BlockType.isTranslucent(blockID)) {
lightEmitters.add(chunk.getBlock(x, y, z).getState());
if (blockID == 20) {
@ -789,7 +811,7 @@ public class BukkitWorld extends LocalWorld {
} else {
blocks[index] = 20;
}
}
continue;
}

View File

@ -44,7 +44,7 @@ public class EditSessionBlockChangeDelegate implements BlockChangeDelegate {
return false;
}
}
public boolean setRawTypeIdAndData(int x, int y, int z, int typeId, int data) {
try {
return editSession.setBlock(new Vector(x, y, z), new BaseBlock(typeId, data));

View File

@ -30,10 +30,10 @@ import com.sk89q.worldedit.WorldEdit;
* @author sk89q
*/
public class SessionTimer implements Runnable {
private WorldEdit worldEdit;
private SessionCheck checker;
public SessionTimer(WorldEdit worldEdit, final Server server) {
this.worldEdit = worldEdit;
this.checker = new SessionCheck() {

View File

@ -22,13 +22,13 @@ package com.sk89q.worldedit.bukkit;
import org.bukkit.entity.Player;
import com.sk89q.worldedit.LocalSession;
public class WorldEditAPI {
public class WorldEditAPI {
private WorldEditPlugin plugin;
public WorldEditAPI(WorldEditPlugin plugin) {
this.plugin = plugin;
}
/**
* Get the session for a player.
*

View File

@ -32,7 +32,7 @@ public class WorldEditCriticalPlayerListener extends PlayerListener {
* Plugin.
*/
private WorldEditPlugin plugin;
/**
* Construct the object;
*

View File

@ -88,7 +88,7 @@ public class WorldEditPlayerListener extends PlayerListener {
}
private boolean ignoreLeftClickAir = false;
/**
* Called when a player interacts
*
@ -115,9 +115,11 @@ public class WorldEditPlayerListener extends PlayerListener {
}
if (!ignoreLeftClickAir) {
final int taskId = Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { public void run() {
ignoreLeftClickAir = false;
}}, 2);
final int taskId = Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
public void run() {
ignoreLeftClickAir = false;
}
}, 2);
if (taskId != -1) {
ignoreLeftClickAir = true;

View File

@ -53,7 +53,7 @@ public class WorldEditPlugin extends JavaPlugin {
* WorldEdit messages get sent here.
*/
private static final Logger logger = Logger.getLogger("Minecraft.WorldEdit");
/**
* The server interface that all server-related API goes through.
*/
@ -66,7 +66,7 @@ public class WorldEditPlugin extends JavaPlugin {
* Deprecated API.
*/
private WorldEditAPI api;
/**
* Holds the configuration for WorldEdit.
*/
@ -93,15 +93,15 @@ public class WorldEditPlugin extends JavaPlugin {
// Create the default configuration file
createDefaultConfiguration("config.yml");
// Set up configuration and such, including the permissions
// resolver
config = new BukkitConfiguration(new YAMLProcessor(new File(getDataFolder(), "config.yml"), true), logger);
perms = new PermissionsResolverManager(this, "WorldEdit", logger);
// Load the configuration
loadConfiguration();
// Setup interfaces
server = new BukkitServerInterface(this, getServer());
controller = new WorldEdit(server, config);
@ -109,8 +109,8 @@ public class WorldEditPlugin extends JavaPlugin {
// Now we can register events!
registerEvents();
getServer().getScheduler().scheduleAsyncRepeatingTask(this,
getServer().getScheduler().scheduleAsyncRepeatingTask(this,
new SessionTimer(controller, getServer()), 120, 120);
}
@ -128,7 +128,7 @@ public class WorldEditPlugin extends JavaPlugin {
config.unload();
this.getServer().getScheduler().cancelTasks(this);
}
/**
* Loads and reloads all configuration.
*/
@ -200,20 +200,22 @@ public class WorldEditPlugin extends JavaPlugin {
while ((length = input.read(buf)) > 0) {
output.write(buf, 0, length);
}
logger.info(getDescription().getName()
+ ": Default configuration file written: " + name);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (input != null)
if (input != null) {
input.close();
}
} catch (IOException e) {}
try {
if (output != null)
if (output != null) {
output.close();
}
} catch (IOException e) {}
}
}
@ -231,20 +233,20 @@ public class WorldEditPlugin extends JavaPlugin {
if (!(sender instanceof Player)) {
return true;
}
Player player = (Player)sender;
Player player = (Player) sender;
// Add the command to the array because the underlying command handling
// code of WorldEdit expects it
String[] split = new String[args.length + 1];
System.arraycopy(args, 0, split, 1, args.length);
split[0] = "/" + cmd.getName();
controller.handleCommand(wrapPlayer(player), split);
return true;
}
/**
* Gets the session for the player.
*
@ -254,7 +256,7 @@ public class WorldEditPlugin extends JavaPlugin {
public LocalSession getSession(Player player) {
return controller.getSession(wrapPlayer(player));
}
/**
* Gets the session for the player.
*
@ -265,15 +267,14 @@ public class WorldEditPlugin extends JavaPlugin {
LocalPlayer wePlayer = wrapPlayer(player);
LocalSession session = controller.getSession(wePlayer);
BlockBag blockBag = session.getBlockBag(wePlayer);
EditSession editSession =
new EditSession(wePlayer.getWorld(),
session.getBlockChangeLimit(), blockBag);
new EditSession(wePlayer.getWorld(), session.getBlockChangeLimit(), blockBag);
editSession.enableQueue();
return editSession;
}
/**
* Remember an edit session.
*
@ -283,13 +284,13 @@ public class WorldEditPlugin extends JavaPlugin {
public void remember(Player player, EditSession editSession) {
LocalPlayer wePlayer = wrapPlayer(player);
LocalSession session = controller.getSession(wePlayer);
session.remember(editSession);
editSession.flushQueue();
controller.flushBlockBag(wePlayer, editSession);
}
/**
* Wrap an operation into an EditSession.
*
@ -301,7 +302,7 @@ public class WorldEditPlugin extends JavaPlugin {
throws Throwable {
LocalPlayer wePlayer = wrapPlayer(player);
LocalSession session = controller.getSession(wePlayer);
EditSession editSession = createEditSession(player);
try {
op.run(session, wePlayer, editSession);
@ -309,7 +310,7 @@ public class WorldEditPlugin extends JavaPlugin {
remember(player, editSession);
}
}
/**
* Get the API.
*
@ -319,7 +320,7 @@ public class WorldEditPlugin extends JavaPlugin {
public WorldEditAPI getAPI() {
return api;
}
/**
* Returns the configuration used by WorldEdit.
*
@ -328,7 +329,7 @@ public class WorldEditPlugin extends JavaPlugin {
public BukkitConfiguration getLocalConfiguration() {
return config;
}
/**
* Get the permissions resolver in use.
*
@ -337,7 +338,7 @@ public class WorldEditPlugin extends JavaPlugin {
public PermissionsResolverManager getPermissionsResolver() {
return perms;
}
/**
* Used to wrap a Bukkit Player as a LocalPlayer.
*
@ -347,7 +348,7 @@ public class WorldEditPlugin extends JavaPlugin {
public BukkitPlayer wrapPlayer(Player player) {
return new BukkitPlayer(this, this.server, player);
}
/**
* Get the server interface.
*
@ -356,7 +357,7 @@ public class WorldEditPlugin extends JavaPlugin {
public ServerInterface getServerInterface() {
return server;
}
/**
* Get WorldEdit.
*
@ -365,7 +366,7 @@ public class WorldEditPlugin extends JavaPlugin {
public WorldEdit getWorldEdit() {
return controller;
}
/**
* Gets the region selection for the player.
*
@ -379,18 +380,18 @@ public class WorldEditPlugin extends JavaPlugin {
if (!player.isOnline()) {
throw new IllegalArgumentException("Offline player not allowed");
}
LocalSession session = controller.getSession(wrapPlayer(player));
RegionSelector selector = session.getRegionSelector();
try {
Region region = selector.getRegion();
World world = ((BukkitWorld) session.getSelectionWorld()).getWorld();
if (region instanceof CuboidRegion) {
return new CuboidSelection(world, selector, (CuboidRegion)region);
return new CuboidSelection(world, selector, (CuboidRegion) region);
} else if (region instanceof Polygonal2DRegion) {
return new Polygonal2DSelection(world, selector, (Polygonal2DRegion)region);
return new Polygonal2DSelection(world, selector, (Polygonal2DRegion) region);
} else {
return null;
}
@ -398,7 +399,7 @@ public class WorldEditPlugin extends JavaPlugin {
return null;
}
}
/**
* Sets the region selection for a player.
*
@ -415,8 +416,8 @@ public class WorldEditPlugin extends JavaPlugin {
if (selection == null) {
throw new IllegalArgumentException("Null selection not allowed");
}
LocalSession session = controller.getSession(wrapPlayer(player));
LocalSession session = controller.getSession(wrapPlayer(player));
RegionSelector sel = selection.getRegionSelector();
session.setRegionSelector(new BukkitWorld(player.getWorld()), sel);
session.dispatchCUISelection(wrapPlayer(player));

View File

@ -29,26 +29,26 @@ import com.sk89q.worldedit.regions.*;
public class CuboidSelection extends RegionSelection {
protected CuboidRegion cuboid;
public CuboidSelection(World world, Location pt1, Location pt2) {
public CuboidSelection(World world, Location pt1, Location pt2) {
this(world, BukkitUtil.toVector(pt1), BukkitUtil.toVector(pt2));
}
public CuboidSelection(World world, Vector pt1, Vector pt2) {
public CuboidSelection(World world, Vector pt1, Vector pt2) {
super(world);
if (pt1 == null) {
throw new IllegalArgumentException("Null point 1 not permitted");
}
if (pt2 == null) {
throw new IllegalArgumentException("Null point 2 not permitted");
}
CuboidRegionSelector sel = new CuboidRegionSelector();
sel.selectPrimary(pt1);
sel.selectSecondary(pt2);
try {
cuboid = sel.getRegion();
} catch (IncompleteRegionException e) {
@ -58,7 +58,7 @@ public class CuboidSelection extends RegionSelection {
setRegionSelector(sel);
setRegion(cuboid);
}
public CuboidSelection(World world, RegionSelector sel, CuboidRegion region) {
super(world, sel, region);
this.cuboid = region;

View File

@ -28,13 +28,13 @@ import com.sk89q.worldedit.regions.*;
public class Polygonal2DSelection extends RegionSelection {
protected Polygonal2DRegion poly2d;
public Polygonal2DSelection(World world, RegionSelector sel, Polygonal2DRegion region) {
super(world, sel, region);
this.poly2d = region;
}
public Polygonal2DSelection(World world, List<BlockVector2D> points, int minY, int maxY) {
public Polygonal2DSelection(World world, List<BlockVector2D> points, int minY, int maxY) {
super(world);
minY = Math.min(Math.max(0, minY), 127);
@ -48,7 +48,7 @@ public class Polygonal2DSelection extends RegionSelection {
setRegionSelector(sel);
setRegion(poly2d);
}
public List<BlockVector2D> getNativePoints() {
return Collections.unmodifiableList(poly2d.getPoints());
}

View File

@ -32,29 +32,29 @@ public abstract class RegionSelection implements Selection {
private World world;
private RegionSelector selector;
private Region region;
public RegionSelection(World world) {
this.world = world;
}
public RegionSelection(World world, RegionSelector selector, Region region) {
this.world = world;
this.region = region;
this.selector = selector;
}
protected Region getRegion() {
return region;
}
protected void setRegion(Region region) {
this.region = region;
}
public RegionSelector getRegionSelector() {
return selector;
}
protected void setRegionSelector(RegionSelector selector) {
this.selector = selector;
}
@ -99,7 +99,7 @@ public abstract class RegionSelection implements Selection {
if (!pt.getWorld().equals(world)) {
return false;
}
return region.contains(toVector(pt));
}

View File

@ -31,70 +31,70 @@ public interface Selection {
* @return min. point
*/
public Location getMinimumPoint();
/**
* Get the lower point of a region.
*
* @return min. point
*/
public Vector getNativeMinimumPoint();
/**
* Get the upper point of a region.
*
* @return max. point
*/
public Location getMaximumPoint();
/**
* Get the upper point of a region.
*
* @return max. point
*/
public Vector getNativeMaximumPoint();
/**
* Get the region selector. This is for internal use.
*
* @return
*/
public RegionSelector getRegionSelector();
/**
* Get the world.
*
* @return
*/
public World getWorld();
/**
* Get the number of blocks in the region.
*
* @return number of blocks
*/
public int getArea();
/**
* Get X-size.
*
* @return width
*/
public int getWidth();
/**
* Get Y-size.
*
* @return height
*/
public int getHeight();
/**
* Get Z-size.
*
* @return length
*/
public int getLength();
/**
* Returns true based on whether the region contains the point,
*