Added region selection with a wooden axe (#271);

This commit is contained in:
sk89q 2010-10-03 16:45:54 -07:00
parent fc2a827c07
commit bb06f9daed
2 changed files with 132 additions and 3 deletions

View File

@ -189,6 +189,60 @@ public class WorldEdit extends Plugin {
sessions.clear(); sessions.clear();
} }
/**
* Called on right click.
*
* @param player
* @param blockPlaced
* @param blockClicked
* @param itemInHand
* @return false if you want the action to go through
*/
@Override
public boolean onBlockCreate(Player player, Block blockPlaced,
Block blockClicked, int itemInHand) {
if (itemInHand == 271) { // Wooden axe
if (!etc.getInstance().canUseCommand(player.getName(), "/editpos1")
|| !etc.getInstance().canUseCommand(player.getName(), "/editpos2")) {
return false;
}
WorldEditSession session = getSession(player);
int x = (int)Math.floor(blockClicked.getX());
int y = (int)Math.floor(blockClicked.getY());
int z = (int)Math.floor(blockClicked.getZ());
if (session.isToolControlEnabled()) {
try {
if (session.hasToolBeenDoubleClicked()
&& x == session.getPos1()[0]
&& y == session.getPos1()[1]
&& z == session.getPos1()[2]) { // Pos 2
session.setPos2(x, y, z);
session.setPos1(session.getLastToolPos1());
player.sendMessage(Colors.LightPurple + "Second edit position set; first one restored.");
} else {
// Have to remember the original position because on
// double click, we are going to restore it
try {
session.setLastToolPos1(session.getPos1());
} catch (IncompleteRegionException e) {}
session.setPos1(x, y, z);
player.sendMessage(Colors.LightPurple + "First edit position set.");
}
} catch (IncompleteRegionException e) {}
session.triggerToolClick();
return true;
}
}
return false;
}
/** /**
* *
* @param player * @param player

View File

@ -33,6 +33,9 @@ public class WorldEditSession {
private LinkedList<EditSession> history = new LinkedList<EditSession>(); private LinkedList<EditSession> history = new LinkedList<EditSession>();
private int historyPointer = 0; private int historyPointer = 0;
private RegionClipboard clipboard; private RegionClipboard clipboard;
private boolean toolControl = true;
private int[] lastToolPos1 = new int[3];
private long lastToolClick = 0;
/** /**
* Clear history. * Clear history.
@ -127,7 +130,7 @@ public class WorldEditSession {
} }
/** /**
* Sets postiion 1. * Sets position 1.
* *
* @param x * @param x
* @param y * @param y
@ -138,6 +141,18 @@ public class WorldEditSession {
pos1 = new int[]{x, y, z}; pos1 = new int[]{x, y, z};
} }
/**
* Sets position 1.
*
* @param x
* @param y
* @param z
*/
public void setPos1(int[] pos) {
hasSetPos1 = true;
pos1 = pos;
}
/** /**
* Gets position 2. * Gets position 2.
* *
@ -161,6 +176,18 @@ public class WorldEditSession {
pos2 = new int[]{x, y, z}; pos2 = new int[]{x, y, z};
} }
/**
* Sets position 2.
*
* @param x
* @param y
* @param z
*/
public void setPos2(int[] pos) {
hasSetPos2 = true;
pos2 = pos;
}
/** /**
* Get lower X bound. * Get lower X bound.
* *
@ -262,4 +289,52 @@ public class WorldEditSession {
public void setClipboard(RegionClipboard clipboard) { public void setClipboard(RegionClipboard clipboard) {
this.clipboard = clipboard; this.clipboard = clipboard;
} }
/**
* See if tool control is enabled.
*
* @return
*/
public boolean isToolControlEnabled() {
return toolControl;
}
/**
* Change tool control setting.
*
* @param
*/
public void setToolControl(boolean toolControl) {
this.toolControl = toolControl;
}
/**
* @return the lastToolPos1
*/
public int[] getLastToolPos1() {
return lastToolPos1;
}
/**
* @param lastToolPos1 the lastToolPos1 to set
*/
public void setLastToolPos1(int[] lastToolPos1) {
this.lastToolPos1 = lastToolPos1;
}
/**
* Returns true if the tool has been double clicked.
*
* @return
*/
public boolean hasToolBeenDoubleClicked() {
return System.currentTimeMillis() - lastToolClick < 500;
}
/**
* Triggers a click of the tool.
*/
public void triggerToolClick() {
lastToolClick = System.currentTimeMillis();
}
} }