Updated item/block lists, added Bukkit API for other plugins, moved some things around.

This commit is contained in:
sk89q
2011-01-16 09:39:11 -08:00
parent 3b9fe1b0c4
commit 80d7bbfa3c
19 changed files with 473 additions and 101 deletions

View File

@ -20,8 +20,9 @@
package com.sk89q.worldedit.bukkit;
import org.bukkit.*;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.bags.BlockBag;
public class BukkitPlayer extends LocalPlayer {
@ -47,7 +48,7 @@ public class BukkitPlayer extends LocalPlayer {
@Override
public int getItemInHand() {
ItemStack itemStack = player.getItemInHand();
return itemStack != null ? itemStack.getTypeID() : 0;
return itemStack != null ? itemStack.getTypeId() : 0;
}
@Override

View File

@ -21,7 +21,7 @@ package com.sk89q.worldedit.bukkit;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.ItemStack;
import org.bukkit.inventory.ItemStack;
import org.bukkit.Location;
import org.bukkit.World;
import com.sk89q.worldedit.EditSession;
@ -47,12 +47,12 @@ public class BukkitWorld extends LocalWorld {
@Override
public boolean setBlockType(Vector pt, int type) {
return world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).setTypeID(type);
return world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).setTypeId(type);
}
@Override
public int getBlockType(Vector pt) {
return world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).getTypeID();
return world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).getTypeId();
}
@Override

View File

@ -0,0 +1,41 @@
// $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.entity.Player;
import com.sk89q.worldedit.LocalSession;
public class WorldEditAPI {
private WorldEditPlugin plugin;
public WorldEditAPI(WorldEditPlugin plugin) {
this.plugin = plugin;
}
/**
* Get the session for a player.
*
* @param player
* @return
*/
public LocalSession getSession(Player player) {
return plugin.controller.getSession(new BukkitPlayer(plugin.server, player));
}
}

View File

@ -19,11 +19,10 @@
package com.sk89q.worldedit.bukkit;
import org.bukkit.Player;
import org.bukkit.entity.Player;
import org.bukkit.event.block.BlockDamageEvent;
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 org.bukkit.event.block.BlockRightClickEvent;
import com.sk89q.worldedit.*;
@ -41,19 +40,21 @@ public class WorldEditBlockListener extends BlockListener {
public WorldEditBlockListener(WorldEditPlugin plugin) {
this.plugin = plugin;
}
/**
* Called when a block is broken (or destroyed)
* Called when a block is damaged (or broken)
*
* @param event Relevant event details
*/
public void onBlockBroken(BlockBrokenEvent event) {
public void onBlockDamage(BlockDamageEvent event) {
LocalWorld world = new BukkitWorld(event.getBlock().getWorld());
WorldVector pos = new WorldVector(world, event.getBlock().getX(),
event.getBlock().getY(), event.getBlock().getZ());
LocalPlayer player = wrapPlayer(event.getPlayer());
plugin.controller.handleBlockLeftClick(player, pos);
if (plugin.controller.handleBlockLeftClick(player, pos)) {
event.setCancelled(true);
}
}
/**
@ -61,7 +62,7 @@ public class WorldEditBlockListener extends BlockListener {
*
* @param event Relevant event details
*/
public void onBlockRightClicked(BlockRightClickedEvent event) {
public void onBlockRightClick(BlockRightClickEvent event) {
LocalWorld world = new BukkitWorld(event.getBlock().getWorld());
WorldVector pos = new WorldVector(world, event.getBlock().getX(),
event.getBlock().getY(), event.getBlock().getZ());

View File

@ -20,6 +20,7 @@
package com.sk89q.worldedit.bukkit;
import org.bukkit.*;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.event.player.PlayerEvent;
import org.bukkit.event.player.PlayerListener;

View File

@ -37,6 +37,7 @@ import com.sk89q.worldedit.*;
public class WorldEditPlugin extends JavaPlugin {
public final ServerInterface server;
public final WorldEditController controller;
public final WorldEditAPI api;
private final WorldEditPlayerListener playerListener =
new WorldEditPlayerListener(this);
@ -44,8 +45,8 @@ public class WorldEditPlugin extends JavaPlugin {
new WorldEditBlockListener(this);
public WorldEditPlugin(PluginLoader pluginLoader, Server instance,
PluginDescriptionFile desc, File plugin, ClassLoader cLoader) {
super(pluginLoader, instance, desc, plugin, cLoader);
PluginDescriptionFile desc, File folder, File plugin, ClassLoader cLoader) {
super(pluginLoader, instance, desc, folder, plugin, cLoader);
LocalConfiguration config = new LocalConfiguration() {
@Override
@ -57,6 +58,8 @@ public class WorldEditPlugin extends JavaPlugin {
server = new BukkitServerInterface(getServer());
controller = new WorldEditController(server, config);
api = new WorldEditAPI(this);
registerEvents();
}
@ -79,4 +82,8 @@ public class WorldEditPlugin extends JavaPlugin {
getServer().getPluginManager().registerEvent(Event.Type.BLOCK_RIGHTCLICKED,
blockListener, Priority.Normal, this);
}
public WorldEditAPI getAPI() {
return api;
}
}

View File

@ -73,7 +73,7 @@ public class WorldSetBlockProxy extends World {
*/
@Override
public int a(int x, int y, int z) {
return editSession.getBlock(new Vector(x, y, z)).getID();
return editSession.getBlock(new Vector(x, y, z)).getType();
}
/**