mirror of
https://github.com/EngineHub/WorldEdit.git
synced 2024-12-15 04:41:37 +08:00
Added region selection with a wooden axe (#271);
This commit is contained in:
parent
fc2a827c07
commit
bb06f9daed
@ -189,6 +189,60 @@ public void disable() {
|
||||
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
|
||||
|
@ -33,6 +33,9 @@ public class WorldEditSession {
|
||||
private LinkedList<EditSession> history = new LinkedList<EditSession>();
|
||||
private int historyPointer = 0;
|
||||
private RegionClipboard clipboard;
|
||||
private boolean toolControl = true;
|
||||
private int[] lastToolPos1 = new int[3];
|
||||
private long lastToolClick = 0;
|
||||
|
||||
/**
|
||||
* Clear history.
|
||||
@ -127,8 +130,8 @@ public int[] getPos1() throws IncompleteRegionException {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets postiion 1.
|
||||
*
|
||||
* Sets position 1.
|
||||
*
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
@ -138,6 +141,18 @@ public void setPos1(int x, int y, int 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.
|
||||
*
|
||||
@ -151,7 +166,7 @@ public int[] getPos2() throws IncompleteRegionException {
|
||||
|
||||
/**
|
||||
* Sets position 2.
|
||||
*
|
||||
*
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
@ -161,6 +176,18 @@ public void setPos2(int x, int y, int 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.
|
||||
*
|
||||
@ -262,4 +289,52 @@ public RegionClipboard getClipboard() {
|
||||
public void setClipboard(RegionClipboard 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();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user