From 63beba8cbae59d47287092ee60b66523c8d676f7 Mon Sep 17 00:00:00 2001 From: sk89q Date: Sun, 27 Mar 2011 11:12:35 -0700 Subject: [PATCH] Updated for latest Bukkit. --- .../PermissionsResolverServerListener.java | 4 +- .../sk89q/worldedit/bukkit/BukkitPlayer.java | 2 +- .../bukkit/WorldEditBlockListener.java | 79 ------------------- .../bukkit/WorldEditPlayerListener.java | 40 ++++++++-- .../worldedit/bukkit/WorldEditPlugin.java | 5 +- 5 files changed, 37 insertions(+), 93 deletions(-) delete mode 100644 src/com/sk89q/worldedit/bukkit/WorldEditBlockListener.java diff --git a/src/com/sk89q/bukkit/migration/PermissionsResolverServerListener.java b/src/com/sk89q/bukkit/migration/PermissionsResolverServerListener.java index 9bfa73809..ecb5dca24 100644 --- a/src/com/sk89q/bukkit/migration/PermissionsResolverServerListener.java +++ b/src/com/sk89q/bukkit/migration/PermissionsResolverServerListener.java @@ -38,7 +38,7 @@ public class PermissionsResolverServerListener extends ServerListener { * @param event Relevant event details */ @Override - public void onPluginEnabled(PluginEvent event) { + public void onPluginEnable(PluginEvent event) { Plugin plugin = event.getPlugin(); String name = plugin.getDescription().getName(); @@ -56,7 +56,7 @@ public class PermissionsResolverServerListener extends ServerListener { * @param event Relevant event details */ @Override - public void onPluginDisabled(PluginEvent event) { + public void onPluginDisable(PluginEvent event) { Plugin plugin = event.getPlugin(); String name = plugin.getDescription().getName(); diff --git a/src/com/sk89q/worldedit/bukkit/BukkitPlayer.java b/src/com/sk89q/worldedit/bukkit/BukkitPlayer.java index 3ffb3e0fa..c655bf7c0 100644 --- a/src/com/sk89q/worldedit/bukkit/BukkitPlayer.java +++ b/src/com/sk89q/worldedit/bukkit/BukkitPlayer.java @@ -92,7 +92,7 @@ public class BukkitPlayer extends LocalPlayer { @Override public void setPosition(Vector pos, float pitch, float yaw) { - player.teleportTo(new Location(player.getWorld(), pos.getX(), pos.getY(), + player.teleport(new Location(player.getWorld(), pos.getX(), pos.getY(), pos.getZ(), yaw, pitch)); } diff --git a/src/com/sk89q/worldedit/bukkit/WorldEditBlockListener.java b/src/com/sk89q/worldedit/bukkit/WorldEditBlockListener.java deleted file mode 100644 index 53d058c4e..000000000 --- a/src/com/sk89q/worldedit/bukkit/WorldEditBlockListener.java +++ /dev/null @@ -1,79 +0,0 @@ -// $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.entity.Player; -import org.bukkit.event.block.BlockDamageEvent; -import org.bukkit.event.block.BlockListener; -import org.bukkit.event.block.BlockRightClickEvent; - -import com.sk89q.worldedit.*; - -public class WorldEditBlockListener extends BlockListener { - /** - * Plugin. - */ - private WorldEditPlugin plugin; - - /** - * Construct the object; - * - * @param plugin - */ - public WorldEditBlockListener(WorldEditPlugin plugin) { - this.plugin = plugin; - } - - /** - * Called when a block is damaged (or broken) - * - * @param event Relevant event details - */ - @Override - 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()); - - if (plugin.controller.handleBlockLeftClick(player, pos)) { - event.setCancelled(true); - } - } - - /** - * Called when a player right clicks a block - * - * @param event Relevant event details - */ - @Override - 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()); - LocalPlayer player = wrapPlayer(event.getPlayer()); - - plugin.controller.handleBlockRightClick(player, pos); - } - - private BukkitPlayer wrapPlayer(Player player) { - return new BukkitPlayer(plugin, plugin.server, player); - } -} diff --git a/src/com/sk89q/worldedit/bukkit/WorldEditPlayerListener.java b/src/com/sk89q/worldedit/bukkit/WorldEditPlayerListener.java index 299d7f4cd..9d9457b24 100644 --- a/src/com/sk89q/worldedit/bukkit/WorldEditPlayerListener.java +++ b/src/com/sk89q/worldedit/bukkit/WorldEditPlayerListener.java @@ -20,13 +20,15 @@ package com.sk89q.worldedit.bukkit; import org.bukkit.entity.Player; +import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerAnimationEvent; import org.bukkit.event.player.PlayerAnimationType; import org.bukkit.event.player.PlayerChatEvent; import org.bukkit.event.player.PlayerEvent; -import org.bukkit.event.player.PlayerItemEvent; +import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerListener; import com.sk89q.worldedit.LocalPlayer; +import com.sk89q.worldedit.LocalWorld; import com.sk89q.worldedit.WorldVector; import com.sk89q.worldedit.blocks.BlockID; @@ -93,16 +95,40 @@ public class WorldEditPlayerListener extends PlayerListener { event.setCancelled(true); } } - + /** - * Called when a player uses an item - * + * Called when a player interacts + * * @param event Relevant event details */ @Override - public void onPlayerItem(PlayerItemEvent event) { - if (plugin.controller.handleRightClick(wrapPlayer(event.getPlayer()))) { - event.setCancelled(true); + public void onPlayerInteract(PlayerInteractEvent event) { + if (event.getAction() == Action.LEFT_CLICK_BLOCK) { + LocalWorld world = new BukkitWorld(event.getClickedBlock().getWorld()); + WorldVector pos = new WorldVector(world, event.getClickedBlock().getX(), + event.getClickedBlock().getY(), event.getClickedBlock().getZ()); + LocalPlayer player = wrapPlayer(event.getPlayer()); + + if (plugin.controller.handleBlockLeftClick(player, pos)) { + event.setCancelled(true); + } + } else if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { + LocalWorld world = new BukkitWorld(event.getClickedBlock().getWorld()); + WorldVector pos = new WorldVector(world, event.getClickedBlock().getX(), + event.getClickedBlock().getY(), event.getClickedBlock().getZ()); + LocalPlayer player = wrapPlayer(event.getPlayer()); + + if (plugin.controller.handleBlockRightClick(player, pos)) { + event.setCancelled(true); + } + + if (plugin.controller.handleRightClick(wrapPlayer(event.getPlayer()))) { + event.setCancelled(true); + } + } else if (event.getAction() == Action.RIGHT_CLICK_AIR) { + if (plugin.controller.handleRightClick(wrapPlayer(event.getPlayer()))) { + event.setCancelled(true); + } } } diff --git a/src/com/sk89q/worldedit/bukkit/WorldEditPlugin.java b/src/com/sk89q/worldedit/bukkit/WorldEditPlugin.java index b2c0c16ad..56260de20 100644 --- a/src/com/sk89q/worldedit/bukkit/WorldEditPlugin.java +++ b/src/com/sk89q/worldedit/bukkit/WorldEditPlugin.java @@ -126,14 +126,11 @@ public class WorldEditPlugin extends JavaPlugin { protected void registerEvents() { PlayerListener playerListener = new WorldEditPlayerListener(this); PlayerListener criticalPlayerListener = new WorldEditCriticalPlayerListener(this); - BlockListener blockListener = new WorldEditBlockListener(this); registerEvent(Event.Type.PLAYER_QUIT, playerListener); registerEvent(Event.Type.PLAYER_ANIMATION, playerListener); - registerEvent(Event.Type.PLAYER_ITEM, playerListener); + registerEvent(Event.Type.PLAYER_INTERACT, playerListener); registerEvent(Event.Type.PLAYER_COMMAND_PREPROCESS, playerListener); - registerEvent(Event.Type.BLOCK_DAMAGED, blockListener); - registerEvent(Event.Type.BLOCK_RIGHTCLICKED, blockListener); registerEvent(Event.Type.PLAYER_JOIN, criticalPlayerListener, Priority.Lowest); // The permissions resolver has some hooks of its own