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;
/** /**
@ -92,40 +93,52 @@ 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()))) {
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.getWorldEdit().handleBlockRightClick(player, pos)) { case LEFT_CLICK_AIR:
if (we.handleArmSwing(player)) {
event.setCancelled(true);
}
break;
case RIGHT_CLICK_BLOCK: {
final Block clickedBlock = event.getClickedBlock();
final WorldVector pos = new WorldVector(world, clickedBlock.getX(),
clickedBlock.getY(), clickedBlock.getZ());
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;
} }
} }