You may now select pos1/pos2 from a distance!

This commit is contained in:
mrapple 2011-07-23 11:34:28 -05:00
parent 40772cbc67
commit 894ebec740
2 changed files with 59 additions and 38 deletions

View File

@ -879,16 +879,19 @@ public class WorldEdit {
} }
/** /**
* Called on arm swing. * Called on left click (not on a block).
* *
* @param player * @param player
* @return * @return
*/ */
public boolean handleArmSwing(LocalPlayer player) { public boolean handleLeftClick(LocalPlayer player) {
if (player.getItemInHand() == config.navigationWand LocalSession session = getSession(player);
WorldVector pos = player.getSolidBlockTrace(config.navigationWandMaxDistance);
if (player.getItemInHand() == config.wandItem) {
return selectFirstPoint(player, session, pos);
} else if (player.getItemInHand() == config.navigationWand
&& config.navigationWandMaxDistance > 0 && config.navigationWandMaxDistance > 0
&& player.hasPermission("worldedit.navigation.jumpto")) { && player.hasPermission("worldedit.navigation.jumpto")) {
WorldVector pos = player.getSolidBlockTrace(config.navigationWandMaxDistance);
if (pos != null) { if (pos != null) {
player.findFreePosition(pos); player.findFreePosition(pos);
} else { } else {
@ -915,6 +918,9 @@ public class WorldEdit {
if (!player.passThroughForwardWall(40)) { if (!player.passThroughForwardWall(40)) {
player.printError("Nothing to pass through!"); player.printError("Nothing to pass through!");
} }
} else if (player.getItemInHand() == config.wandItem) {
WorldVector pos = player.getSolidBlockTrace(config.navigationWandMaxDistance);
return selectSecondPoint(player, session, pos);
} }
Tool tool = session.getTool(player.getItemInHand()); Tool tool = session.getTool(player.getItemInHand());
@ -937,18 +943,10 @@ public class WorldEdit {
* @return false if you want the action to go through * @return false if you want the action to go through
*/ */
public boolean handleBlockRightClick(LocalPlayer player, WorldVector clicked) { public boolean handleBlockRightClick(LocalPlayer player, WorldVector clicked) {
int itemInHand = player.getItemInHand();
LocalSession session = getSession(player); LocalSession session = getSession(player);
if (itemInHand == config.wandItem && session.isToolControlEnabled() if (player.getItemInHand() == config.wandItem) {
&& player.hasPermission("worldedit.selection.pos")) { return selectSecondPoint(player, session, clicked);
RegionSelector selector = session.getRegionSelector(player.getWorld());
if (selector.selectSecondary(clicked)) {
selector.explainSecondarySelection(player, session, clicked);
}
return true;
} }
Tool tool = session.getTool(player.getItemInHand()); Tool tool = session.getTool(player.getItemInHand());
@ -973,22 +971,8 @@ public class WorldEdit {
public boolean handleBlockLeftClick(LocalPlayer player, WorldVector clicked) { public boolean handleBlockLeftClick(LocalPlayer player, WorldVector clicked) {
LocalSession session = getSession(player); LocalSession session = getSession(player);
if (player.getItemInHand() == config.wandItem) { if (player.getItemInHand() == config.wandItem) {
if (session.isToolControlEnabled() return selectFirstPoint(player, session, clicked);
&& player.hasPermission("worldedit.selection.pos")) {
// Bug workaround
if (clicked.getBlockX() == 0 && clicked.getBlockY() == 0
&& clicked.getBlockZ() == 0) {
return false;
}
RegionSelector selector = session.getRegionSelector(player.getWorld());
if (selector.selectPrimary(clicked)) {
selector.explainPrimarySelection(player, session, clicked);
}
return true;
}
} else if (player.isHoldingPickAxe() && session.hasSuperPickAxe()) { } else if (player.isHoldingPickAxe() && session.hasSuperPickAxe()) {
if (session.getSuperPickaxe() != null) { if (session.getSuperPickaxe() != null) {
if (session.getSuperPickaxe().canUse(player)) { if (session.getSuperPickaxe().canUse(player)) {
@ -1007,6 +991,40 @@ public class WorldEdit {
} }
} }
return false;
}
private boolean selectFirstPoint(LocalPlayer player, LocalSession session, WorldVector clicked)
{
if (session.isToolControlEnabled()
&& player.hasPermission("worldedit.selection.pos")) {
// Bug workaround
if (clicked.getBlockX() == 0 && clicked.getBlockY() == 0
&& clicked.getBlockZ() == 0) {
return false;
}
RegionSelector selector = session.getRegionSelector(player.getWorld());
if (selector.selectPrimary(clicked)) {
selector.explainPrimarySelection(player, session, clicked);
}
return true;
}
return false;
}
private boolean selectSecondPoint(LocalPlayer player, LocalSession session, WorldVector clicked)
{
if (session.isToolControlEnabled()
&& player.hasPermission("worldedit.selection.pos")) {
RegionSelector selector = session.getRegionSelector(player.getWorld());
if (selector.selectSecondary(clicked)) {
selector.explainSecondarySelection(player, session, clicked);
}
return true;
}
return false; return false;
} }

View File

@ -87,16 +87,17 @@ public class WorldEditPlayerListener extends PlayerListener {
*/ */
@Override @Override
public void onPlayerInteract(PlayerInteractEvent event) { public void onPlayerInteract(PlayerInteractEvent event) {
if (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.LEFT_CLICK_AIR) { if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
LocalWorld world = new BukkitWorld(event.getClickedBlock().getWorld()); LocalWorld world = new BukkitWorld(event.getClickedBlock().getWorld());
WorldVector pos = new WorldVector(world, event.getClickedBlock().getX(), WorldVector pos = new WorldVector(world, event.getClickedBlock().getX(),
event.getClickedBlock().getY(), event.getClickedBlock().getZ()); event.getClickedBlock().getY(), event.getClickedBlock().getZ());
LocalPlayer player = wrapPlayer(event.getPlayer()); LocalPlayer player = wrapPlayer(event.getPlayer());
if (!(event.getAction() == Action.LEFT_CLICK_BLOCK && plugin.getWorldEdit().handleBlockLeftClick(player, pos))) { if (plugin.getWorldEdit().handleBlockLeftClick(player, pos)) {
plugin.getWorldEdit().handleArmSwing(player); event.setCancelled(true);
} } else if (plugin.getWorldEdit().handleLeftClick(wrapPlayer(event.getPlayer()))) {
event.setCancelled(true); event.setCancelled(true);
}
} else if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { } else if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
LocalWorld world = new BukkitWorld(event.getClickedBlock().getWorld()); LocalWorld world = new BukkitWorld(event.getClickedBlock().getWorld());
WorldVector pos = new WorldVector(world, event.getClickedBlock().getX(), WorldVector pos = new WorldVector(world, event.getClickedBlock().getX(),
@ -105,15 +106,17 @@ public class WorldEditPlayerListener extends PlayerListener {
if (plugin.getWorldEdit().handleBlockRightClick(player, pos)) { if (plugin.getWorldEdit().handleBlockRightClick(player, pos)) {
event.setCancelled(true); event.setCancelled(true);
} } else if (plugin.getWorldEdit().handleRightClick(wrapPlayer(event.getPlayer()))) {
if (plugin.getWorldEdit().handleRightClick(wrapPlayer(event.getPlayer()))) {
event.setCancelled(true); event.setCancelled(true);
} }
} else if (event.getAction() == Action.RIGHT_CLICK_AIR) { } else if (event.getAction() == Action.RIGHT_CLICK_AIR) {
if (plugin.getWorldEdit().handleRightClick(wrapPlayer(event.getPlayer()))) { if (plugin.getWorldEdit().handleRightClick(wrapPlayer(event.getPlayer()))) {
event.setCancelled(true); event.setCancelled(true);
} }
} else if (event.getAction() == Action.LEFT_CLICK_AIR) {
if (plugin.getWorldEdit().handleLeftClick(wrapPlayer(event.getPlayer()))) {
event.setCancelled(true);
}
} }
} }