2010-09-30 06:41:05 +00:00
|
|
|
// $Id$
|
|
|
|
/*
|
|
|
|
* WorldEdit
|
|
|
|
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2010-10-20 23:15:20 +00:00
|
|
|
import com.sk89q.worldedit.snapshots.Snapshot;
|
2010-10-14 08:31:05 +00:00
|
|
|
import com.sk89q.worldedit.regions.Region;
|
|
|
|
import com.sk89q.worldedit.regions.CuboidRegion;
|
2010-10-02 20:46:33 +00:00
|
|
|
import com.sk89q.worldedit.*;
|
2010-10-02 21:52:42 +00:00
|
|
|
import java.util.LinkedList;
|
2010-10-02 20:46:33 +00:00
|
|
|
|
2010-09-30 06:41:05 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @author sk89q
|
|
|
|
*/
|
|
|
|
public class WorldEditSession {
|
2010-11-07 06:03:35 +00:00
|
|
|
/**
|
|
|
|
* List of super pick axe modes.
|
|
|
|
*/
|
2010-11-07 06:17:32 +00:00
|
|
|
public static enum SuperPickaxeMode {
|
2010-11-07 06:03:35 +00:00
|
|
|
SINGLE,
|
|
|
|
SAME_TYPE_RECURSIVE,
|
|
|
|
SAME_TYPE_AREA
|
|
|
|
};
|
2010-11-07 06:17:32 +00:00
|
|
|
/**
|
2010-11-27 03:33:28 +00:00
|
|
|
* List of tools.
|
2010-11-07 06:17:32 +00:00
|
|
|
*/
|
|
|
|
public static enum Tool {
|
|
|
|
NONE,
|
2010-11-27 03:33:28 +00:00
|
|
|
INFO,
|
2010-11-07 06:17:32 +00:00
|
|
|
TREE,
|
|
|
|
}
|
2010-11-07 06:03:35 +00:00
|
|
|
|
2010-10-02 21:52:42 +00:00
|
|
|
public static final int MAX_HISTORY_SIZE = 15;
|
2010-10-14 09:14:18 +00:00
|
|
|
private boolean placeAtPos1 = false;
|
2010-10-13 01:03:56 +00:00
|
|
|
private Vector pos1, pos2;
|
2010-10-13 04:41:06 +00:00
|
|
|
private Region region;
|
2010-10-02 21:52:42 +00:00
|
|
|
private LinkedList<EditSession> history = new LinkedList<EditSession>();
|
|
|
|
private int historyPointer = 0;
|
2010-10-11 08:22:47 +00:00
|
|
|
private CuboidClipboard clipboard;
|
2010-10-03 23:45:54 +00:00
|
|
|
private boolean toolControl = true;
|
2010-10-13 18:26:07 +00:00
|
|
|
private boolean superPickAxe = false;
|
2010-11-07 06:17:32 +00:00
|
|
|
private SuperPickaxeMode superPickaxeMode = SuperPickaxeMode.SINGLE;
|
|
|
|
private Tool tool = Tool.NONE;
|
2010-11-07 06:03:35 +00:00
|
|
|
private int superPickaxeRange = 3;
|
2010-10-04 23:39:35 +00:00
|
|
|
private int maxBlocksChanged = -1;
|
2010-10-20 23:15:20 +00:00
|
|
|
private Snapshot snapshot;
|
2010-10-02 21:52:42 +00:00
|
|
|
|
2010-10-02 23:13:52 +00:00
|
|
|
/**
|
|
|
|
* Clear history.
|
|
|
|
*/
|
|
|
|
public void clearHistory() {
|
|
|
|
history.clear();
|
|
|
|
historyPointer = 0;
|
|
|
|
}
|
|
|
|
|
2010-10-02 21:52:42 +00:00
|
|
|
/**
|
|
|
|
* Get the edit session.
|
|
|
|
*/
|
|
|
|
public void remember(EditSession editSession) {
|
|
|
|
// Don't store anything if no changes were made
|
|
|
|
if (editSession.size() == 0) { return; }
|
|
|
|
|
|
|
|
// Destroy any sessions after this undo point
|
|
|
|
while (historyPointer < history.size()) {
|
|
|
|
history.remove(historyPointer);
|
|
|
|
}
|
|
|
|
history.add(editSession);
|
|
|
|
while (history.size() > MAX_HISTORY_SIZE) {
|
|
|
|
history.remove(0);
|
|
|
|
}
|
|
|
|
historyPointer = history.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Undo.
|
|
|
|
*
|
2010-10-11 08:22:47 +00:00
|
|
|
* @return whether anything was undone
|
2010-10-02 21:52:42 +00:00
|
|
|
*/
|
|
|
|
public boolean undo() {
|
|
|
|
historyPointer--;
|
|
|
|
if (historyPointer >= 0) {
|
|
|
|
history.get(historyPointer).undo();
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
historyPointer = 0;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Redo.
|
|
|
|
*
|
2010-10-11 08:22:47 +00:00
|
|
|
* @return whether anything was redone
|
2010-10-02 21:52:42 +00:00
|
|
|
*/
|
|
|
|
public boolean redo() {
|
|
|
|
if (historyPointer < history.size()) {
|
|
|
|
history.get(historyPointer).redo();
|
|
|
|
historyPointer++;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2010-09-30 06:41:05 +00:00
|
|
|
|
2010-10-03 19:43:30 +00:00
|
|
|
/**
|
|
|
|
* Checks to make sure that position 1 is defined.
|
|
|
|
*
|
|
|
|
* @throws IncompleteRegionException
|
|
|
|
*/
|
2010-09-30 06:41:05 +00:00
|
|
|
private void checkPos1() throws IncompleteRegionException {
|
2010-10-11 08:22:47 +00:00
|
|
|
if (pos1 == null) {
|
2010-09-30 06:41:05 +00:00
|
|
|
throw new IncompleteRegionException();
|
|
|
|
}
|
|
|
|
}
|
2010-11-16 09:01:37 +00:00
|
|
|
|
2010-10-03 19:43:30 +00:00
|
|
|
/**
|
|
|
|
* Checks to make sure that position 2 is defined.
|
|
|
|
*
|
|
|
|
* @throws IncompleteRegionException
|
|
|
|
*/
|
2010-09-30 06:41:05 +00:00
|
|
|
private void checkPos2() throws IncompleteRegionException {
|
2010-10-11 08:22:47 +00:00
|
|
|
if (pos2 == null) {
|
2010-09-30 06:41:05 +00:00
|
|
|
throw new IncompleteRegionException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-16 09:01:37 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the region is fully defined.
|
|
|
|
*
|
|
|
|
* @throws IncompleteRegionException
|
|
|
|
*/
|
|
|
|
public boolean isRegionDefined() {
|
|
|
|
return pos1 != null && pos2 != null;
|
|
|
|
}
|
|
|
|
|
2010-10-03 19:43:30 +00:00
|
|
|
/**
|
|
|
|
* Gets defined position 1.
|
|
|
|
*
|
2010-10-11 15:56:19 +00:00
|
|
|
* @return position 1
|
2010-10-03 19:43:30 +00:00
|
|
|
* @throws IncompleteRegionException
|
|
|
|
*/
|
2010-10-13 01:03:56 +00:00
|
|
|
public Vector getPos1() throws IncompleteRegionException {
|
2010-09-30 06:41:05 +00:00
|
|
|
checkPos1();
|
|
|
|
return pos1;
|
|
|
|
}
|
|
|
|
|
2010-10-03 19:43:30 +00:00
|
|
|
/**
|
2010-10-03 23:45:54 +00:00
|
|
|
* Sets position 1.
|
|
|
|
*
|
2010-10-11 08:22:47 +00:00
|
|
|
* @param pt
|
2010-10-03 19:43:30 +00:00
|
|
|
*/
|
2010-10-13 01:03:56 +00:00
|
|
|
public void setPos1(Vector pt) {
|
2010-10-11 08:22:47 +00:00
|
|
|
pos1 = pt;
|
2010-10-13 04:41:06 +00:00
|
|
|
if (pos1 != null && pos2 != null) {
|
|
|
|
region = new CuboidRegion(pos1, pos2);
|
|
|
|
}
|
2010-10-03 23:45:54 +00:00
|
|
|
}
|
|
|
|
|
2010-10-03 19:43:30 +00:00
|
|
|
/**
|
|
|
|
* Gets position 2.
|
|
|
|
*
|
2010-10-11 15:56:19 +00:00
|
|
|
* @return position 2
|
2010-10-03 19:43:30 +00:00
|
|
|
* @throws IncompleteRegionException
|
|
|
|
*/
|
2010-10-13 01:03:56 +00:00
|
|
|
public Vector getPos2() throws IncompleteRegionException {
|
2010-09-30 06:41:05 +00:00
|
|
|
checkPos2();
|
|
|
|
return pos2;
|
|
|
|
}
|
|
|
|
|
2010-10-03 19:43:30 +00:00
|
|
|
/**
|
|
|
|
* Sets position 2.
|
2010-10-03 23:45:54 +00:00
|
|
|
*
|
2010-10-11 08:22:47 +00:00
|
|
|
* @param pt
|
2010-10-03 19:43:30 +00:00
|
|
|
*/
|
2010-10-13 01:03:56 +00:00
|
|
|
public void setPos2(Vector pt) {
|
2010-10-11 08:22:47 +00:00
|
|
|
pos2 = pt;
|
2010-10-13 04:41:06 +00:00
|
|
|
if (pos1 != null && pos2 != null) {
|
|
|
|
region = new CuboidRegion(pos1, pos2);
|
|
|
|
}
|
2010-09-30 06:41:05 +00:00
|
|
|
}
|
|
|
|
|
2010-10-03 23:45:54 +00:00
|
|
|
/**
|
2010-10-13 04:41:06 +00:00
|
|
|
* Update session position 1/2 based on the currently set region,
|
|
|
|
* provided that the region is of a cuboid.
|
|
|
|
*/
|
|
|
|
public void learnRegionChanges() {
|
|
|
|
if (region instanceof CuboidRegion) {
|
|
|
|
CuboidRegion cuboidRegion = (CuboidRegion)region;
|
|
|
|
pos1 = cuboidRegion.getPos1();
|
|
|
|
pos2 = cuboidRegion.getPos2();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-10-13 17:08:53 +00:00
|
|
|
* Get the region. If you change the region, you should
|
2010-10-13 04:41:06 +00:00
|
|
|
* call learnRegionChanges().
|
2010-10-03 19:43:30 +00:00
|
|
|
*
|
2010-10-11 15:56:19 +00:00
|
|
|
* @return region
|
2010-10-13 17:08:53 +00:00
|
|
|
* @throws IncompleteRegionException
|
2010-10-03 19:43:30 +00:00
|
|
|
*/
|
2010-10-13 17:08:53 +00:00
|
|
|
public Region getRegion() throws IncompleteRegionException {
|
|
|
|
if (region == null) {
|
|
|
|
throw new IncompleteRegionException();
|
|
|
|
}
|
2010-10-13 04:41:06 +00:00
|
|
|
return region;
|
2010-10-05 20:46:31 +00:00
|
|
|
}
|
|
|
|
|
2010-10-02 23:11:44 +00:00
|
|
|
/**
|
2010-10-03 19:43:30 +00:00
|
|
|
* Gets the clipboard.
|
|
|
|
*
|
2010-10-11 15:56:19 +00:00
|
|
|
* @return clipboard, may be null
|
2010-10-13 17:08:53 +00:00
|
|
|
* @throws EmptyClipboardException
|
2010-10-02 23:11:44 +00:00
|
|
|
*/
|
2010-10-13 17:08:53 +00:00
|
|
|
public CuboidClipboard getClipboard() throws EmptyClipboardException {
|
|
|
|
if (clipboard == null) {
|
|
|
|
throw new EmptyClipboardException();
|
|
|
|
}
|
2010-10-02 23:11:44 +00:00
|
|
|
return clipboard;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-10-03 19:43:30 +00:00
|
|
|
* Sets the clipboard.
|
|
|
|
*
|
2010-10-02 23:11:44 +00:00
|
|
|
* @param clipboard
|
|
|
|
*/
|
2010-10-11 08:22:47 +00:00
|
|
|
public void setClipboard(CuboidClipboard clipboard) {
|
2010-10-02 23:11:44 +00:00
|
|
|
this.clipboard = clipboard;
|
|
|
|
}
|
2010-10-03 23:45:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* See if tool control is enabled.
|
|
|
|
*
|
2010-10-11 15:56:19 +00:00
|
|
|
* @return true if enabled
|
2010-10-03 23:45:54 +00:00
|
|
|
*/
|
|
|
|
public boolean isToolControlEnabled() {
|
|
|
|
return toolControl;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Change tool control setting.
|
|
|
|
*
|
2010-10-11 15:56:19 +00:00
|
|
|
* @param toolControl
|
2010-10-03 23:45:54 +00:00
|
|
|
*/
|
|
|
|
public void setToolControl(boolean toolControl) {
|
|
|
|
this.toolControl = toolControl;
|
|
|
|
}
|
|
|
|
|
2010-10-04 23:39:35 +00:00
|
|
|
/**
|
|
|
|
* Get the maximum number of blocks that can be changed in an edit session.
|
2010-10-11 15:56:19 +00:00
|
|
|
*
|
|
|
|
* @return block change limit
|
2010-10-04 23:39:35 +00:00
|
|
|
*/
|
|
|
|
public int getBlockChangeLimit() {
|
|
|
|
return maxBlocksChanged;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the maximum number of blocks that can be changed.
|
|
|
|
*
|
|
|
|
* @param maxBlocksChanged
|
|
|
|
*/
|
|
|
|
public void setBlockChangeLimit(int maxBlocksChanged) {
|
|
|
|
this.maxBlocksChanged = maxBlocksChanged;
|
|
|
|
}
|
2010-10-13 18:26:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks whether the super pick axe is enabled.
|
|
|
|
*
|
|
|
|
* @return status
|
|
|
|
*/
|
|
|
|
public boolean hasSuperPickAxe() {
|
|
|
|
return superPickAxe;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enable super pick axe.
|
|
|
|
*
|
|
|
|
* @param superPickAxe
|
|
|
|
*/
|
|
|
|
public void enableSuperPickAxe() {
|
|
|
|
superPickAxe = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Disable super pick axe.
|
|
|
|
*
|
|
|
|
* @param superPickAxe
|
|
|
|
*/
|
|
|
|
public void disableSuperPickAxe() {
|
|
|
|
superPickAxe = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Toggle the super pick axe.
|
|
|
|
*
|
|
|
|
* @return status
|
|
|
|
*/
|
|
|
|
public boolean toggleSuperPickAxe() {
|
|
|
|
superPickAxe = !superPickAxe;
|
|
|
|
return superPickAxe;
|
|
|
|
}
|
2010-10-14 09:14:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return position
|
|
|
|
* @throws IncompleteRegionException
|
|
|
|
*/
|
|
|
|
public Vector getPlacementPosition(WorldEditPlayer player)
|
|
|
|
throws IncompleteRegionException {
|
|
|
|
if (!placeAtPos1) {
|
|
|
|
return player.getBlockIn();
|
|
|
|
}
|
|
|
|
|
|
|
|
checkPos1();
|
|
|
|
return pos1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Toggle placement position;
|
|
|
|
*/
|
|
|
|
public boolean togglePlacementPosition() {
|
|
|
|
placeAtPos1 = !placeAtPos1;
|
|
|
|
return placeAtPos1;
|
|
|
|
}
|
2010-10-20 23:15:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the snapshotName
|
|
|
|
*/
|
|
|
|
public Snapshot getSnapshot() {
|
|
|
|
return snapshot;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param snapshot
|
|
|
|
*/
|
|
|
|
public void setSnapshot(Snapshot snapshot) {
|
|
|
|
this.snapshot = snapshot;
|
|
|
|
}
|
2010-11-07 06:17:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the superPickaxeMode
|
|
|
|
*/
|
|
|
|
public SuperPickaxeMode getSuperPickaxeMode() {
|
|
|
|
return superPickaxeMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param superPickaxeMode the superPickaxeMode to set
|
|
|
|
*/
|
|
|
|
public void setSuperPickaxeMode(SuperPickaxeMode superPickaxeMode) {
|
|
|
|
this.superPickaxeMode = superPickaxeMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the superPickaxeRange
|
|
|
|
*/
|
|
|
|
public int getSuperPickaxeRange() {
|
|
|
|
return superPickaxeRange;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param superPickaxeRange the superPickaxeRange to set
|
|
|
|
*/
|
|
|
|
public void setSuperPickaxeRange(int superPickaxeRange) {
|
|
|
|
this.superPickaxeRange = superPickaxeRange;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the tool
|
|
|
|
*/
|
|
|
|
public Tool getTool() {
|
|
|
|
return tool;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param tool the tool to set
|
|
|
|
*/
|
|
|
|
public void setTool(Tool tool) {
|
|
|
|
this.tool = tool;
|
|
|
|
}
|
2010-09-30 06:41:05 +00:00
|
|
|
}
|