Updated Bukkit plugin.

This commit is contained in:
sk89q 2011-01-03 12:05:41 -08:00
parent 0dfb88c41d
commit e1939e0d4c
6 changed files with 147 additions and 69 deletions

View File

@ -21,23 +21,25 @@
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 String getName() {
}
@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 boolean hasPermission(String perm) {
return true;
}
@Override
public LocalWorld getWorld() {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -21,6 +21,7 @@
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 BukkitServerInterface(Server server) {
}
@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 boolean isValidMobType(String type) {
}
@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 int resolveItem(String name) {
}
@Override
public int killMobs(Vector origin, int radius) {
public int killMobs(LocalWorld world, Vector origin, int radius) {
// TODO Auto-generated method stub
return 0;
}

View File

@ -0,0 +1,51 @@
// $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/>.
*/
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();
}
}

View File

@ -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 void onBlockBroken(BlockBrokenEvent event) {
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);
}
}

View File

@ -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 WorldEditPlayerListener(WorldEditPlugin plugin) {
* @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 void onPlayerQuit(PlayerEvent event) {
* @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);
}
}

View File

@ -30,8 +30,8 @@
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<Integer>();
}
};
ServerInterface.setup(new BukkitServerInterface(getServer()));
controller.profile = true;
controller.allowedBlocks = new HashSet<Integer>();
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 @@ private void registerEvents() {
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);
}
}