From e1939e0d4c8924d57865aeae656af3baac076a94 Mon Sep 17 00:00:00 2001 From: sk89q Date: Mon, 3 Jan 2011 12:05:41 -0800 Subject: [PATCH] Updated Bukkit plugin. --- .../sk89q/worldedit/bukkit/BukkitPlayer.java | 21 ++++-- .../bukkit/BukkitServerInterface.java | 73 +++++++++++-------- .../sk89q/worldedit/bukkit/BukkitWorld.java | 51 +++++++++++++ .../bukkit/WorldEditBlockListener.java | 22 ++++-- .../bukkit/WorldEditPlayerListener.java | 15 ++-- .../worldedit/bukkit/WorldEditPlugin.java | 34 ++++----- 6 files changed, 147 insertions(+), 69 deletions(-) create mode 100644 src/com/sk89q/worldedit/bukkit/BukkitWorld.java diff --git a/src/com/sk89q/worldedit/bukkit/BukkitPlayer.java b/src/com/sk89q/worldedit/bukkit/BukkitPlayer.java index 58d900039..24dc9489c 100644 --- a/src/com/sk89q/worldedit/bukkit/BukkitPlayer.java +++ b/src/com/sk89q/worldedit/bukkit/BukkitPlayer.java @@ -21,23 +21,25 @@ package com.sk89q.worldedit.bukkit; import org.bukkit.*; import com.sk89q.worldedit.*; +import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.bags.BlockBag; -public class BukkitPlayer extends WorldEditPlayer { +public class BukkitPlayer extends LocalPlayer { private Player player; - public BukkitPlayer(Player player) { + public BukkitPlayer(ServerInterface server, Player player) { + super(server); this.player = player; } @Override - public Vector getBlockTrace(int range) { + public WorldVector getBlockTrace(int range) { // TODO Auto-generated method stub return null; } @Override - public Vector getSolidBlockTrace(int range) { + public WorldVector getSolidBlockTrace(int range) { // TODO Auto-generated method stub return null; } @@ -54,9 +56,10 @@ public class BukkitPlayer extends WorldEditPlayer { } @Override - public Vector getPosition() { + public WorldVector getPosition() { Location loc = player.getLocation(); - return new Vector(loc.getX(), loc.getY(), loc.getZ()); + return new WorldVector(new BukkitWorld(loc.getWorld()), + loc.getX(), loc.getY(), loc.getZ()); } @Override @@ -119,4 +122,10 @@ public class BukkitPlayer extends WorldEditPlayer { return true; } + @Override + public LocalWorld getWorld() { + // TODO Auto-generated method stub + return null; + } + } diff --git a/src/com/sk89q/worldedit/bukkit/BukkitServerInterface.java b/src/com/sk89q/worldedit/bukkit/BukkitServerInterface.java index c997c620d..3755be932 100644 --- a/src/com/sk89q/worldedit/bukkit/BukkitServerInterface.java +++ b/src/com/sk89q/worldedit/bukkit/BukkitServerInterface.java @@ -21,6 +21,7 @@ package com.sk89q.worldedit.bukkit; import org.bukkit.*; import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.LocalWorld; import com.sk89q.worldedit.ServerInterface; import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.blocks.BaseItemStack; @@ -33,53 +34,66 @@ public class BukkitServerInterface extends ServerInterface { } @Override - public boolean setBlockType(Vector pt, int type) { - // TODO Auto-generated method stub - return false; + public boolean setBlockType(LocalWorld world, Vector pt, int type) { + ((BukkitWorld)world).getWorld().getBlockAt( + pt.getBlockX(), + pt.getBlockY(), + pt.getBlockZ()).setTypeID(type); + + return true; } @Override - public int getBlockType(Vector pt) { - return server.getWorlds()[0].getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).getType(); + public int getBlockType(LocalWorld world, Vector pt) { + return ((BukkitWorld)world).getWorld().getBlockAt( + pt.getBlockX(), + pt.getBlockY(), + pt.getBlockZ()).getTypeID(); } @Override - public void setBlockData(Vector pt, int data) { + public void setBlockData(LocalWorld world, Vector pt, int data) { + ((BukkitWorld)world).getWorld().getBlockAt( + pt.getBlockX(), + pt.getBlockY(), + pt.getBlockZ()).setData((byte)data); + + } + + @Override + public int getBlockData(LocalWorld world, Vector pt) { + return ((BukkitWorld)world).getWorld().getBlockAt( + pt.getBlockX(), + pt.getBlockY(), + pt.getBlockZ()).getData(); + } + + @Override + public void setSignText(LocalWorld world, Vector pt, String[] text) { // TODO Auto-generated method stub } @Override - public int getBlockData(Vector pt) { - return server.getWorlds()[0].getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).getData(); - } - - @Override - public void setSignText(Vector pt, String[] text) { - // TODO Auto-generated method stub - - } - - @Override - public String[] getSignText(Vector pt) { + public String[] getSignText(LocalWorld world, Vector pt) { // TODO Auto-generated method stub return null; } @Override - public BaseItemStack[] getChestContents(Vector pt) { + public BaseItemStack[] getChestContents(LocalWorld world, Vector pt) { // TODO Auto-generated method stub return null; } @Override - public boolean setChestContents(Vector pt, BaseItemStack[] contents) { + public boolean setChestContents(LocalWorld world, Vector pt, BaseItemStack[] contents) { // TODO Auto-generated method stub return false; } @Override - public boolean clearChest(Vector pt) { + public boolean clearChest(LocalWorld world, Vector pt) { // TODO Auto-generated method stub return false; } @@ -91,43 +105,44 @@ public class BukkitServerInterface extends ServerInterface { } @Override - public void setMobSpawnerType(Vector pt, String mobType) { + public void setMobSpawnerType(LocalWorld world, Vector pt, String mobType) { // TODO Auto-generated method stub } @Override - public String getMobSpawnerType(Vector pt) { + public String getMobSpawnerType(LocalWorld world, Vector pt) { // TODO Auto-generated method stub return null; } @Override - public boolean generateTree(EditSession editSession, Vector pt) { + public boolean generateTree(EditSession editSession, LocalWorld world, + Vector pt) { // TODO Auto-generated method stub return false; } @Override - public void dropItem(Vector pt, int type, int count, int times) { + public void dropItem(LocalWorld world, Vector pt, int type, int count, int times) { // TODO Auto-generated method stub } @Override - public void dropItem(Vector pt, int type, int count) { + public void dropItem(LocalWorld world, Vector pt, int type, int count) { // TODO Auto-generated method stub } @Override - public void dropItem(Vector pt, int type) { + public void dropItem(LocalWorld world, Vector pt, int type) { // TODO Auto-generated method stub } @Override - public void simulateBlockMine(Vector pt) { + public void simulateBlockMine(LocalWorld world, Vector pt) { // TODO Auto-generated method stub } @@ -139,7 +154,7 @@ public class BukkitServerInterface extends ServerInterface { } @Override - public int killMobs(Vector origin, int radius) { + public int killMobs(LocalWorld world, Vector origin, int radius) { // TODO Auto-generated method stub return 0; } diff --git a/src/com/sk89q/worldedit/bukkit/BukkitWorld.java b/src/com/sk89q/worldedit/bukkit/BukkitWorld.java new file mode 100644 index 000000000..039e88300 --- /dev/null +++ b/src/com/sk89q/worldedit/bukkit/BukkitWorld.java @@ -0,0 +1,51 @@ +// $Id$ +/* + * WorldEdit + * Copyright (C) 2010 sk89q + * + * 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 . +*/ + +package com.sk89q.worldedit.bukkit; + +import org.bukkit.World; + +import com.sk89q.worldedit.LocalWorld; + +public class BukkitWorld extends LocalWorld { + private World world; + + public BukkitWorld(World world) { + this.world = world; + } + + public World getWorld() { + return world; + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof BukkitWorld)) { + return false; + } + + return ((BukkitWorld)other).world.equals(world); + } + + @Override + public int hashCode() { + return world.hashCode(); + } + +} diff --git a/src/com/sk89q/worldedit/bukkit/WorldEditBlockListener.java b/src/com/sk89q/worldedit/bukkit/WorldEditBlockListener.java index d77f68a5c..c27267455 100644 --- a/src/com/sk89q/worldedit/bukkit/WorldEditBlockListener.java +++ b/src/com/sk89q/worldedit/bukkit/WorldEditBlockListener.java @@ -19,8 +19,10 @@ package com.sk89q.worldedit.bukkit; +import org.bukkit.Player; import org.bukkit.event.block.BlockListener; import org.bukkit.event.block.BlockBrokenEvent; +import org.bukkit.event.block.BlockPlacedEvent; import org.bukkit.event.block.BlockRightClickedEvent; import com.sk89q.worldedit.*; @@ -48,20 +50,26 @@ public class WorldEditBlockListener extends BlockListener { Vector pos = new Vector(event.getBlock().getX(), event.getBlock().getY(), event.getBlock().getZ()); - WorldEditPlayer player = new BukkitPlayer(plugin.getServer().getOnlinePlayers()[0]); - plugin.controller.handleBlockLeftClick(player, pos); + LocalWorld world = new BukkitWorld(event.getBlock().getWorld()); + LocalPlayer player = wrapPlayer(event.getPlayer()); + plugin.controller.handleBlockLeftClick(player, world, pos); } - + /** - * Called when a player right clicks a block + * Called when a player places a block * * @param event Relevant event details */ - public void onBlockRightClicked(BlockRightClickedEvent event) { + public void onBlockPlaced(BlockPlacedEvent event) { Vector pos = new Vector(event.getBlock().getX(), event.getBlock().getY(), event.getBlock().getZ()); - WorldEditPlayer player = new BukkitPlayer(plugin.getServer().getOnlinePlayers()[0]); - plugin.controller.handleBlockRightClick(player, pos); + LocalWorld world = new BukkitWorld(event.getBlock().getWorld()); + LocalPlayer player = wrapPlayer(event.getPlayer()); + plugin.controller.handleBlockRightClick(player, world, pos); + } + + private BukkitPlayer wrapPlayer(Player player) { + return new BukkitPlayer(plugin.server, player); } } diff --git a/src/com/sk89q/worldedit/bukkit/WorldEditPlayerListener.java b/src/com/sk89q/worldedit/bukkit/WorldEditPlayerListener.java index e62c2c5b0..a7fee149c 100644 --- a/src/com/sk89q/worldedit/bukkit/WorldEditPlayerListener.java +++ b/src/com/sk89q/worldedit/bukkit/WorldEditPlayerListener.java @@ -19,11 +19,11 @@ package com.sk89q.worldedit.bukkit; +import org.bukkit.*; import org.bukkit.event.player.PlayerChatEvent; import org.bukkit.event.player.PlayerEvent; import org.bukkit.event.player.PlayerListener; - -import com.sk89q.worldedit.WorldEditPlayer; +import com.sk89q.worldedit.*; /** * Handles all events thrown in relation to a Player @@ -49,8 +49,7 @@ public class WorldEditPlayerListener extends PlayerListener { * @param event Relevant event details */ public void onPlayerQuit(PlayerEvent event) { - WorldEditPlayer player = new BukkitPlayer(plugin.getServer().getOnlinePlayers()[0]); - plugin.controller.handleDisconnect(player); + plugin.controller.handleDisconnect(wrapPlayer(event.getPlayer())); } /** @@ -59,7 +58,11 @@ public class WorldEditPlayerListener extends PlayerListener { * @param event Relevant event details */ public void onPlayerCommand(PlayerChatEvent event) { - WorldEditPlayer player = new BukkitPlayer(plugin.getServer().getOnlinePlayers()[0]); - plugin.controller.handleCommand(player, event.getMessage().split(" ")); + plugin.controller.handleCommand(wrapPlayer(event.getPlayer()), + event.getMessage().split(" ")); + } + + private BukkitPlayer wrapPlayer(Player player) { + return new BukkitPlayer(plugin.server, player); } } diff --git a/src/com/sk89q/worldedit/bukkit/WorldEditPlugin.java b/src/com/sk89q/worldedit/bukkit/WorldEditPlugin.java index a4fc11fe1..d386e6804 100644 --- a/src/com/sk89q/worldedit/bukkit/WorldEditPlugin.java +++ b/src/com/sk89q/worldedit/bukkit/WorldEditPlugin.java @@ -30,8 +30,8 @@ import org.bukkit.plugin.java.JavaPlugin; import com.sk89q.worldedit.*; public class WorldEditPlugin extends JavaPlugin { - public final WorldEditController controller = - new WorldEditController(); + public final ServerInterface server; + public final WorldEditController controller; private final WorldEditPlayerListener playerListener = new WorldEditPlayerListener(this); @@ -41,25 +41,17 @@ public class WorldEditPlugin extends JavaPlugin { public WorldEditPlugin(PluginLoader pluginLoader, Server instance, PluginDescriptionFile desc, File plugin, ClassLoader cLoader) { super(pluginLoader, instance, desc, plugin, cLoader); + + LocalConfiguration config = new LocalConfiguration() { + @Override + public void load() { + // TODO Auto-generated method stub + disallowedBlocks = new HashSet(); + } + }; - ServerInterface.setup(new BukkitServerInterface(getServer())); - - controller.profile = true; - controller.allowedBlocks = new HashSet(); - controller.defaultChangeLimit = -1; - controller.maxChangeLimit = -1; - controller.shellSaveType = "sh"; - controller.snapshotRepo = null; - controller.maxRadius = -1; - controller.maxSuperPickaxeSize = 5; - controller.logComands = false; - controller.registerHelp = true; - controller.wandItem = 271; - controller.superPickaxeDrop = true; - controller.superPickaxeManyDrop = true; - controller.noDoubleSlash = true; - controller.useInventory = false; - controller.useInventoryOverride = false; + server = new BukkitServerInterface(getServer()); + controller = new WorldEditController(server, config); registerEvents(); } @@ -79,7 +71,7 @@ public class WorldEditPlugin extends JavaPlugin { playerListener, Priority.Normal, this); getServer().getPluginManager().registerEvent(Event.Type.BLOCK_DAMAGED, blockListener, Priority.Normal, this); - getServer().getPluginManager().registerEvent(Event.Type.BLOCK_RIGHTCLICKED, + getServer().getPluginManager().registerEvent(Event.Type.BLOCK_PLACED, blockListener, Priority.Normal, this); } }