Cleaned up WorldEditPlayerListener.onPlayerInteract.

Dieser Commit ist enthalten in:
TomyLobo 2011-11-13 15:13:59 +01:00
Ursprung a3946dc8c4
Commit 86dfa3dce8

Datei anzeigen

@ -19,14 +19,15 @@
package com.sk89q.worldedit.bukkit; package com.sk89q.worldedit.bukkit;
import org.bukkit.block.Block;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerListener; import org.bukkit.event.player.PlayerListener;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import com.sk89q.worldedit.LocalPlayer; import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalWorld; import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldVector; import com.sk89q.worldedit.WorldVector;
/** /**
@ -37,13 +38,13 @@ public class WorldEditPlayerListener extends PlayerListener {
* Plugin. * Plugin.
*/ */
private WorldEditPlugin plugin; private WorldEditPlugin plugin;
/** /**
* Called when a player plays an animation, such as an arm swing * Called when a player plays an animation, such as an arm swing
* *
* @param event Relevant event details * @param event Relevant event details
*/ */
/** /**
* Construct the object; * Construct the object;
* *
@ -56,7 +57,7 @@ public class WorldEditPlayerListener extends PlayerListener {
plugin.registerEvent("PLAYER_INTERACT", this); plugin.registerEvent("PLAYER_INTERACT", this);
plugin.registerEvent("PLAYER_COMMAND_PREPROCESS", this); plugin.registerEvent("PLAYER_COMMAND_PREPROCESS", this);
} }
/** /**
* Called when a player leaves a server * Called when a player leaves a server
* *
@ -79,7 +80,7 @@ public class WorldEditPlayerListener extends PlayerListener {
} }
String[] split = event.getMessage().split(" "); String[] split = event.getMessage().split(" ");
if (plugin.getWorldEdit().handleCommand(wrapPlayer(event.getPlayer()), split)) { if (plugin.getWorldEdit().handleCommand(wrapPlayer(event.getPlayer()), split)) {
event.setCancelled(true); event.setCancelled(true);
} }
@ -92,43 +93,55 @@ public class WorldEditPlayerListener extends PlayerListener {
*/ */
@Override @Override
public void onPlayerInteract(PlayerInteractEvent event) { public void onPlayerInteract(PlayerInteractEvent event) {
if (event.getAction() == Action.LEFT_CLICK_BLOCK) { final LocalPlayer player = wrapPlayer(event.getPlayer());
LocalWorld world = new BukkitWorld(event.getClickedBlock().getWorld()); final LocalWorld world = player.getWorld();
WorldVector pos = new WorldVector(world, event.getClickedBlock().getX(), final WorldEdit we = plugin.getWorldEdit();
event.getClickedBlock().getY(), event.getClickedBlock().getZ());
LocalPlayer player = wrapPlayer(event.getPlayer());
if (plugin.getWorldEdit().handleBlockLeftClick(player, pos)) { switch (event.getAction()) {
case LEFT_CLICK_BLOCK: {
final Block clickedBlock = event.getClickedBlock();
final WorldVector pos = new WorldVector(world, clickedBlock.getX(),
clickedBlock.getY(), clickedBlock.getZ());
if (we.handleBlockLeftClick(player, pos)) {
event.setCancelled(true); event.setCancelled(true);
} }
if (plugin.getWorldEdit().handleArmSwing(wrapPlayer(event.getPlayer()))) { if (we.handleArmSwing(player)) {
event.setCancelled(true); event.setCancelled(true);
} }
} else if (event.getAction() == Action.LEFT_CLICK_AIR) { break;
if (plugin.getWorldEdit().handleArmSwing(wrapPlayer(event.getPlayer()))) { }
case LEFT_CLICK_AIR:
if (we.handleArmSwing(player)) {
event.setCancelled(true); event.setCancelled(true);
} }
} else if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { break;
LocalWorld world = new BukkitWorld(event.getClickedBlock().getWorld());
WorldVector pos = new WorldVector(world, event.getClickedBlock().getX(), case RIGHT_CLICK_BLOCK: {
event.getClickedBlock().getY(), event.getClickedBlock().getZ()); final Block clickedBlock = event.getClickedBlock();
LocalPlayer player = wrapPlayer(event.getPlayer()); final WorldVector pos = new WorldVector(world, clickedBlock.getX(),
clickedBlock.getY(), clickedBlock.getZ());
if (plugin.getWorldEdit().handleBlockRightClick(player, pos)) {
if (we.handleBlockRightClick(player, pos)) {
event.setCancelled(true); event.setCancelled(true);
} }
if (plugin.getWorldEdit().handleRightClick(wrapPlayer(event.getPlayer()))) { if (we.handleRightClick(player)) {
event.setCancelled(true); event.setCancelled(true);
} }
} else if (event.getAction() == Action.RIGHT_CLICK_AIR) { break;
if (plugin.getWorldEdit().handleRightClick(wrapPlayer(event.getPlayer()))) { }
case RIGHT_CLICK_AIR:
if (we.handleRightClick(player)) {
event.setCancelled(true); event.setCancelled(true);
} }
break;
} }
} }
private BukkitPlayer wrapPlayer(Player player) { private BukkitPlayer wrapPlayer(Player player) {
return new BukkitPlayer(plugin, plugin.getServerInterface(), player); return new BukkitPlayer(plugin, plugin.getServerInterface(), player);
} }