Changed arm swing event to use arm swing; now compass right click toggles the compass mode between /jumpto and /thru.

This commit is contained in:
sk89q 2011-01-26 10:52:53 -08:00
parent c49631de1e
commit fdb7c31aae
4 changed files with 85 additions and 8 deletions

View File

@ -32,6 +32,11 @@ import com.sk89q.worldedit.regions.CuboidRegion;
* @author sk89q
*/
public class LocalSession {
public enum CompassMode {
JUMPTO,
THRU
}
public static final int MAX_HISTORY_SIZE = 15;
private boolean placeAtPos1 = false;
@ -49,6 +54,7 @@ public class LocalSession {
private boolean useInventory;
private Snapshot snapshot;
private String lastScript;
private CompassMode compassMode = CompassMode.JUMPTO;
/**
* Clear history.
@ -427,4 +433,18 @@ public class LocalSession {
public void setLastScript(String lastScript) {
this.lastScript = lastScript;
}
/**
* @return the compassMode
*/
public CompassMode getCompassMode() {
return compassMode;
}
/**
* @param compassMode the compassMode to set
*/
public void setCompassMode(CompassMode compassMode) {
this.compassMode = compassMode;
}
}

View File

@ -30,6 +30,7 @@ import java.util.logging.Logger;
import java.io.*;
import javax.script.ScriptException;
import com.sk89q.util.StringUtil;
import com.sk89q.worldedit.LocalSession.CompassMode;
import com.sk89q.worldedit.bags.BlockBag;
import com.sk89q.worldedit.blocks.*;
import com.sk89q.worldedit.data.*;
@ -1952,14 +1953,55 @@ public class WorldEditController {
return true;
}
} else if (player.getItemInHand() == config.navigationWand
&& config.navigationWandMaxDistance > 0
&& player.hasPermission("jumpto")) {
&& config.navigationWandMaxDistance > 0) {
CompassMode mode = session.getCompassMode();
if (player.hasPermission("jumpto") && mode == CompassMode.JUMPTO) {
WorldVector pos = player.getSolidBlockTrace(config.navigationWandMaxDistance);
if (pos != null) {
player.findFreePosition(pos);
} else {
player.printError("No block in sight (or too far)!");
}
} else if (mode == CompassMode.THRU) { // Permission is implied
if (!player.passThroughForwardWall(40)) {
player.printError("Nothing to pass through!");
}
}
}
return false;
}
/**
* Called on right click (not on a block).
*
* @param player
* @return
*/
public boolean handleRightClick(LocalPlayer player) {
LocalSession session = getSession(player);
if (player.getItemInHand() == config.navigationWand) {
CompassMode mode = session.getCompassMode();
if (mode == CompassMode.JUMPTO) {
if (player.hasPermission("thru")) {
session.setCompassMode(CompassMode.THRU);
player.print("Switched to /thru mode.");
} else {
player.printError("You don't have permission for /thru.");
}
} else {
if (player.hasPermission("jumpto")) {
session.setCompassMode(CompassMode.JUMPTO);
player.print("Switched to /jumpto mode.");
} else {
player.printError("You don't have permission for /jumpto.");
}
}
return true;
}
return false;

View File

@ -20,6 +20,8 @@
package com.sk89q.worldedit.bukkit;
import org.bukkit.entity.Player;
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;
@ -34,6 +36,17 @@ public class WorldEditPlayerListener extends PlayerListener {
*/
private WorldEditPlugin plugin;
/**
* Called when a player plays an animation, such as an arm swing
*
* @param event Relevant event details
*/
public void onPlayerAnimation(PlayerAnimationEvent event) {
if (event.getAnimationType() == PlayerAnimationType.ARM_SWING) {
plugin.controller.handleArmSwing(wrapPlayer(event.getPlayer()));
}
}
/**
* Construct the object;
*
@ -71,7 +84,7 @@ public class WorldEditPlayerListener extends PlayerListener {
* @param event Relevant event details
*/
public void onPlayerItem(PlayerItemEvent event) {
if (plugin.controller.handleArmSwing(wrapPlayer(event.getPlayer()))) {
if (plugin.controller.handleRightClick(wrapPlayer(event.getPlayer()))) {
event.setCancelled(true);
}
}

View File

@ -90,6 +90,8 @@ public class WorldEditPlugin extends JavaPlugin {
private void registerEvents() {
getServer().getPluginManager().registerEvent(Event.Type.PLAYER_QUIT,
playerListener, Priority.Normal, this);
getServer().getPluginManager().registerEvent(Event.Type.PLAYER_ANIMATION,
playerListener, Priority.Normal, this);
getServer().getPluginManager().registerEvent(Event.Type.PLAYER_ITEM,
playerListener, Priority.Normal, this);
getServer().getPluginManager().registerEvent(Event.Type.PLAYER_COMMAND,