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/>.
|
|
|
|
*/
|
|
|
|
|
2011-01-01 01:40:07 +00:00
|
|
|
package com.sk89q.worldedit;
|
|
|
|
|
2011-03-14 03:23:55 +00:00
|
|
|
import java.util.Calendar;
|
2011-02-18 23:14:43 +00:00
|
|
|
import java.util.HashMap;
|
2011-01-01 01:40:07 +00:00
|
|
|
import java.util.LinkedList;
|
2011-02-18 23:14:43 +00:00
|
|
|
import java.util.Map;
|
2011-03-14 03:23:55 +00:00
|
|
|
import java.util.TimeZone;
|
|
|
|
import com.sk89q.jchronic.Chronic;
|
|
|
|
import com.sk89q.jchronic.Options;
|
|
|
|
import com.sk89q.jchronic.utils.Span;
|
|
|
|
import com.sk89q.jchronic.utils.Time;
|
2010-10-20 23:15:20 +00:00
|
|
|
import com.sk89q.worldedit.snapshots.Snapshot;
|
2011-02-19 07:36:08 +00:00
|
|
|
import com.sk89q.worldedit.tools.BrushTool;
|
2011-02-18 23:14:43 +00:00
|
|
|
import com.sk89q.worldedit.tools.SinglePickaxe;
|
|
|
|
import com.sk89q.worldedit.tools.BlockTool;
|
|
|
|
import com.sk89q.worldedit.tools.Tool;
|
2010-12-31 22:31:49 +00:00
|
|
|
import com.sk89q.worldedit.bags.BlockBag;
|
2011-03-12 06:43:02 +00:00
|
|
|
import com.sk89q.worldedit.cui.CUIPointBasedRegion;
|
|
|
|
import com.sk89q.worldedit.cui.CUIEvent;
|
|
|
|
import com.sk89q.worldedit.cui.SelectionShapeEvent;
|
2011-06-04 19:16:10 +00:00
|
|
|
import com.sk89q.worldedit.masks.Mask;
|
2011-02-20 01:44:39 +00:00
|
|
|
import com.sk89q.worldedit.regions.CuboidRegionSelector;
|
2010-10-14 08:31:05 +00:00
|
|
|
import com.sk89q.worldedit.regions.Region;
|
2011-02-20 01:44:39 +00:00
|
|
|
import com.sk89q.worldedit.regions.RegionSelector;
|
2010-10-02 20:46:33 +00:00
|
|
|
|
2010-09-30 06:41:05 +00:00
|
|
|
/**
|
2011-02-18 23:14:43 +00:00
|
|
|
* An instance of this represents the WorldEdit session of a user. A session
|
|
|
|
* stores history and settings. Sessions are not tied particularly to any
|
|
|
|
* player and can be shuffled between players, saved, and loaded.
|
2010-09-30 06:41:05 +00:00
|
|
|
*
|
|
|
|
* @author sk89q
|
|
|
|
*/
|
2011-01-01 18:34:36 +00:00
|
|
|
public class LocalSession {
|
2011-02-19 05:57:43 +00:00
|
|
|
public static int MAX_HISTORY_SIZE = 15;
|
2011-05-02 00:37:05 +00:00
|
|
|
public static int EXPIRATION_GRACE = 600000;
|
2011-09-24 19:32:03 +00:00
|
|
|
|
2011-01-31 08:58:29 +00:00
|
|
|
private LocalConfiguration config;
|
2011-09-24 19:32:03 +00:00
|
|
|
|
2011-05-02 00:37:05 +00:00
|
|
|
private long expirationTime = 0;
|
2011-02-20 01:44:39 +00:00
|
|
|
private LocalWorld selectionWorld;
|
2011-03-12 06:43:02 +00:00
|
|
|
private RegionSelector selector = new CuboidRegionSelector();
|
2010-10-14 09:14:18 +00:00
|
|
|
private boolean placeAtPos1 = false;
|
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;
|
2011-01-02 05:50:31 +00:00
|
|
|
private boolean superPickaxe = false;
|
2011-02-18 23:14:43 +00:00
|
|
|
private BlockTool pickaxeMode = new SinglePickaxe();
|
2011-09-24 19:24:10 +00:00
|
|
|
private Map<Integer, Tool> tools = new HashMap<Integer, Tool>();
|
2010-10-04 23:39:35 +00:00
|
|
|
private int maxBlocksChanged = -1;
|
2010-12-31 22:31:49 +00:00
|
|
|
private boolean useInventory;
|
2010-10-20 23:15:20 +00:00
|
|
|
private Snapshot snapshot;
|
2011-01-23 10:09:51 +00:00
|
|
|
private String lastScript;
|
2011-01-31 08:58:29 +00:00
|
|
|
private boolean beenToldVersion = false;
|
2011-03-12 06:43:02 +00:00
|
|
|
private boolean hasCUISupport = false;
|
2011-06-04 17:30:45 +00:00
|
|
|
private boolean fastMode = false;
|
2011-06-04 19:16:10 +00:00
|
|
|
private Mask mask;
|
2011-03-14 03:23:55 +00:00
|
|
|
private TimeZone timezone = TimeZone.getDefault();
|
|
|
|
|
2011-01-31 08:58:29 +00:00
|
|
|
/**
|
|
|
|
* Construct the object.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2011-01-31 08:58:29 +00:00
|
|
|
* @param config
|
|
|
|
*/
|
|
|
|
public LocalSession(LocalConfiguration config) {
|
|
|
|
this.config = config;
|
|
|
|
}
|
2011-09-24 19:32:03 +00:00
|
|
|
|
2011-03-14 03:23:55 +00:00
|
|
|
/**
|
|
|
|
* Get the session's timezone.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2011-03-14 03:23:55 +00:00
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public TimeZone getTimeZone() {
|
|
|
|
return timezone;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the session's timezone.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
|
|
|
* @param timezone
|
2011-03-14 03:23:55 +00:00
|
|
|
*/
|
|
|
|
public void setTimezone(TimeZone timezone) {
|
|
|
|
this.timezone = timezone;
|
|
|
|
}
|
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
|
|
|
/**
|
2011-02-18 23:14:43 +00:00
|
|
|
* Remember an edit session for the undo history. If the history maximum
|
|
|
|
* size is reached, old edit sessions will be discarded.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2011-02-18 23:14:43 +00:00
|
|
|
* @param editSession
|
2010-10-02 21:52:42 +00:00
|
|
|
*/
|
|
|
|
public void remember(EditSession editSession) {
|
|
|
|
// Don't store anything if no changes were made
|
2011-09-24 19:24:10 +00:00
|
|
|
if (editSession.size() == 0) return;
|
2010-10-02 21:52:42 +00:00
|
|
|
|
|
|
|
// 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();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-02-18 23:14:43 +00:00
|
|
|
* Performs an undo.
|
2010-10-02 21:52:42 +00:00
|
|
|
*
|
2011-02-18 23:14:43 +00:00
|
|
|
* @param newBlockBag
|
2010-10-11 08:22:47 +00:00
|
|
|
* @return whether anything was undone
|
2010-10-02 21:52:42 +00:00
|
|
|
*/
|
2010-12-31 22:31:49 +00:00
|
|
|
public EditSession undo(BlockBag newBlockBag) {
|
2011-07-15 07:00:48 +00:00
|
|
|
--historyPointer;
|
2010-10-02 21:52:42 +00:00
|
|
|
if (historyPointer >= 0) {
|
2010-12-31 22:31:49 +00:00
|
|
|
EditSession editSession = history.get(historyPointer);
|
2011-02-18 23:14:43 +00:00
|
|
|
EditSession newEditSession =
|
|
|
|
new EditSession(editSession.getWorld(), -1, newBlockBag);
|
2011-03-13 00:42:50 +00:00
|
|
|
newEditSession.enableQueue();
|
2011-06-04 17:30:45 +00:00
|
|
|
newEditSession.setFastMode(fastMode);
|
2011-02-18 23:14:43 +00:00
|
|
|
editSession.undo(newEditSession);
|
2010-12-31 22:31:49 +00:00
|
|
|
return editSession;
|
2010-10-02 21:52:42 +00:00
|
|
|
} else {
|
|
|
|
historyPointer = 0;
|
2010-12-31 22:31:49 +00:00
|
|
|
return null;
|
2010-10-02 21:52:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-02-18 23:14:43 +00:00
|
|
|
* Performs a redo
|
2010-10-02 21:52:42 +00:00
|
|
|
*
|
2011-02-18 23:14:43 +00:00
|
|
|
* @param newBlockBag
|
2010-10-11 08:22:47 +00:00
|
|
|
* @return whether anything was redone
|
2010-10-02 21:52:42 +00:00
|
|
|
*/
|
2010-12-31 22:31:49 +00:00
|
|
|
public EditSession redo(BlockBag newBlockBag) {
|
2010-10-02 21:52:42 +00:00
|
|
|
if (historyPointer < history.size()) {
|
2010-12-31 22:31:49 +00:00
|
|
|
EditSession editSession = history.get(historyPointer);
|
2011-02-18 23:14:43 +00:00
|
|
|
EditSession newEditSession =
|
2011-11-23 01:29:48 +00:00
|
|
|
new EditSession(editSession.getWorld(), -1, newBlockBag);
|
2011-03-13 00:42:50 +00:00
|
|
|
newEditSession.enableQueue();
|
2011-06-04 17:30:45 +00:00
|
|
|
newEditSession.setFastMode(fastMode);
|
2011-02-18 23:14:43 +00:00
|
|
|
editSession.redo(newEditSession);
|
2011-07-15 07:00:48 +00:00
|
|
|
++historyPointer;
|
2010-12-31 22:31:49 +00:00
|
|
|
return editSession;
|
2010-10-02 21:52:42 +00:00
|
|
|
}
|
|
|
|
|
2010-12-31 22:31:49 +00:00
|
|
|
return null;
|
2010-10-02 21:52:42 +00:00
|
|
|
}
|
2010-09-30 06:41:05 +00:00
|
|
|
|
2010-10-03 19:43:30 +00:00
|
|
|
/**
|
2011-02-20 01:44:39 +00:00
|
|
|
* Get the region selector for defining the selection. If the selection
|
|
|
|
* was defined for a different world, the old selection will be discarded.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
|
|
|
* @param world
|
2011-02-20 01:44:39 +00:00
|
|
|
* @return position
|
2010-10-03 19:43:30 +00:00
|
|
|
*/
|
2011-02-20 01:44:39 +00:00
|
|
|
public RegionSelector getRegionSelector(LocalWorld world) {
|
|
|
|
if (selectionWorld == null) {
|
|
|
|
selectionWorld = world;
|
|
|
|
} else if (!selectionWorld.equals(world)) {
|
|
|
|
selectionWorld = world;
|
2011-03-12 06:43:02 +00:00
|
|
|
selector.clear();
|
2010-09-30 06:41:05 +00:00
|
|
|
}
|
2011-03-12 06:43:02 +00:00
|
|
|
return selector;
|
2010-09-30 06:41:05 +00:00
|
|
|
}
|
2010-11-16 09:01:37 +00:00
|
|
|
|
2010-10-03 19:43:30 +00:00
|
|
|
/**
|
2011-02-20 01:44:39 +00:00
|
|
|
* Get the region selector. This won't check worlds so make sure that
|
|
|
|
* this region selector isn't used blindly.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2011-02-20 01:44:39 +00:00
|
|
|
* @return position
|
2010-10-03 19:43:30 +00:00
|
|
|
*/
|
2011-02-20 01:44:39 +00:00
|
|
|
public RegionSelector getRegionSelector() {
|
2011-03-12 06:43:02 +00:00
|
|
|
return selector;
|
2010-09-30 06:41:05 +00:00
|
|
|
}
|
|
|
|
|
2010-11-16 09:01:37 +00:00
|
|
|
/**
|
2011-02-20 01:44:39 +00:00
|
|
|
* Set the region selector.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2011-02-20 01:44:39 +00:00
|
|
|
* @param world
|
|
|
|
* @param selector
|
2010-11-16 09:01:37 +00:00
|
|
|
*/
|
2011-02-20 01:44:39 +00:00
|
|
|
public void setRegionSelector(LocalWorld world, RegionSelector selector) {
|
|
|
|
selectionWorld = world;
|
2011-03-12 06:43:02 +00:00
|
|
|
this.selector = selector;
|
2010-11-16 09:01:37 +00:00
|
|
|
}
|
|
|
|
|
2010-10-03 19:43:30 +00:00
|
|
|
/**
|
2011-02-20 01:44:39 +00:00
|
|
|
* Returns true if the region is fully defined.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
|
|
|
* @return
|
2010-10-03 19:43:30 +00:00
|
|
|
*/
|
2011-02-20 01:44:39 +00:00
|
|
|
@Deprecated
|
|
|
|
public boolean isRegionDefined() {
|
2011-03-12 06:43:02 +00:00
|
|
|
return selector.isDefined();
|
2010-09-30 06:41:05 +00:00
|
|
|
}
|
|
|
|
|
2010-10-03 19:43:30 +00:00
|
|
|
/**
|
2011-02-20 01:44:39 +00:00
|
|
|
* Returns true if the region is fully defined for the specified world.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
|
|
|
* @param world
|
|
|
|
* @return
|
2010-10-03 19:43:30 +00:00
|
|
|
*/
|
2011-02-20 01:44:39 +00:00
|
|
|
public boolean isSelectionDefined(LocalWorld world) {
|
|
|
|
if (selectionWorld == null || !selectionWorld.equals(world)) {
|
|
|
|
return false;
|
2010-10-13 04:41:06 +00:00
|
|
|
}
|
2011-03-12 06:43:02 +00:00
|
|
|
return selector.isDefined();
|
2010-10-03 23:45:54 +00:00
|
|
|
}
|
|
|
|
|
2010-10-03 19:43:30 +00:00
|
|
|
/**
|
2011-02-20 01:44:39 +00:00
|
|
|
* Use <code>getSelection()</code>.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2011-02-20 01:44:39 +00:00
|
|
|
* @return region
|
2010-10-03 19:43:30 +00:00
|
|
|
* @throws IncompleteRegionException
|
|
|
|
*/
|
2011-02-20 01:44:39 +00:00
|
|
|
@Deprecated
|
|
|
|
public Region getRegion() throws IncompleteRegionException {
|
2011-03-12 06:43:02 +00:00
|
|
|
return selector.getRegion();
|
2010-10-13 04:41:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-02-20 01:44:39 +00:00
|
|
|
* Get the selection region. If you change the region, you should
|
|
|
|
* call learnRegionChanges(). If the selection is defined in
|
|
|
|
* a different world, the <code>IncompleteRegionException</code>
|
|
|
|
* exception will be thrown.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
|
|
|
* @param world
|
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
|
|
|
*/
|
2011-02-20 01:44:39 +00:00
|
|
|
public Region getSelection(LocalWorld world) throws IncompleteRegionException {
|
|
|
|
if (selectionWorld == null || !selectionWorld.equals(world)) {
|
2010-10-13 17:08:53 +00:00
|
|
|
throw new IncompleteRegionException();
|
|
|
|
}
|
2011-03-12 06:43:02 +00:00
|
|
|
return selector.getRegion();
|
2010-10-05 20:46:31 +00:00
|
|
|
}
|
2011-09-24 19:32:03 +00:00
|
|
|
|
2011-03-12 08:28:19 +00:00
|
|
|
/**
|
|
|
|
* Get the selection world.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2011-03-12 08:28:19 +00:00
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public LocalWorld getSelectionWorld() {
|
|
|
|
return selectionWorld;
|
|
|
|
}
|
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.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
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.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
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.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
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.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
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.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2010-10-04 23:39:35 +00:00
|
|
|
* @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.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2010-10-13 18:26:07 +00:00
|
|
|
* @return status
|
|
|
|
*/
|
|
|
|
public boolean hasSuperPickAxe() {
|
2011-01-02 05:50:31 +00:00
|
|
|
return superPickaxe;
|
2010-10-13 18:26:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enable super pick axe.
|
|
|
|
*/
|
|
|
|
public void enableSuperPickAxe() {
|
2011-01-02 05:50:31 +00:00
|
|
|
superPickaxe = true;
|
2010-10-13 18:26:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Disable super pick axe.
|
|
|
|
*/
|
|
|
|
public void disableSuperPickAxe() {
|
2011-01-02 05:50:31 +00:00
|
|
|
superPickaxe = false;
|
2010-10-13 18:26:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Toggle the super pick axe.
|
|
|
|
*
|
|
|
|
* @return status
|
|
|
|
*/
|
|
|
|
public boolean toggleSuperPickAxe() {
|
2011-01-02 05:50:31 +00:00
|
|
|
superPickaxe = !superPickaxe;
|
|
|
|
return superPickaxe;
|
2010-10-13 18:26:07 +00:00
|
|
|
}
|
2010-10-14 09:14:18 +00:00
|
|
|
|
|
|
|
/**
|
2011-02-18 23:14:43 +00:00
|
|
|
* Get the placement position.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
|
|
|
* @param player
|
2010-10-14 09:14:18 +00:00
|
|
|
* @return position
|
|
|
|
* @throws IncompleteRegionException
|
|
|
|
*/
|
2011-01-01 18:34:36 +00:00
|
|
|
public Vector getPlacementPosition(LocalPlayer player)
|
2010-10-14 09:14:18 +00:00
|
|
|
throws IncompleteRegionException {
|
|
|
|
if (!placeAtPos1) {
|
|
|
|
return player.getBlockIn();
|
|
|
|
}
|
|
|
|
|
2011-03-12 06:43:02 +00:00
|
|
|
return selector.getPrimaryPosition();
|
2010-10-14 09:14:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-02-18 23:14:43 +00:00
|
|
|
* Toggle placement position.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
|
|
|
* @return
|
2010-10-14 09:14:18 +00:00
|
|
|
*/
|
|
|
|
public boolean togglePlacementPosition() {
|
|
|
|
placeAtPos1 = !placeAtPos1;
|
|
|
|
return placeAtPos1;
|
|
|
|
}
|
2011-09-24 19:32:03 +00:00
|
|
|
|
2010-12-31 22:31:49 +00:00
|
|
|
/**
|
|
|
|
* Get a block bag for a player.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2010-12-31 22:31:49 +00:00
|
|
|
* @param player
|
|
|
|
* @return
|
|
|
|
*/
|
2011-01-01 18:34:36 +00:00
|
|
|
public BlockBag getBlockBag(LocalPlayer player) {
|
2010-12-31 22:31:49 +00:00
|
|
|
if (!useInventory) {
|
|
|
|
return null;
|
|
|
|
}
|
2011-01-01 01:06:42 +00:00
|
|
|
return player.getInventoryBlockBag();
|
2010-12-31 22:31:49 +00:00
|
|
|
}
|
2010-10-20 23:15:20 +00:00
|
|
|
|
|
|
|
/**
|
2011-02-18 23:14:43 +00:00
|
|
|
* Get the snapshot that has been selected.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2011-02-18 23:14:43 +00:00
|
|
|
* @return the snapshot
|
2010-10-20 23:15:20 +00:00
|
|
|
*/
|
|
|
|
public Snapshot getSnapshot() {
|
|
|
|
return snapshot;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-02-18 23:14:43 +00:00
|
|
|
* Select a snapshot.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2010-10-20 23:15:20 +00:00
|
|
|
* @param snapshot
|
|
|
|
*/
|
|
|
|
public void setSnapshot(Snapshot snapshot) {
|
|
|
|
this.snapshot = snapshot;
|
|
|
|
}
|
2010-11-07 06:17:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the superPickaxeMode
|
|
|
|
*/
|
2011-02-18 23:14:43 +00:00
|
|
|
public BlockTool getSuperPickaxe() {
|
|
|
|
return pickaxeMode;
|
2010-11-07 06:17:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-02-18 23:14:43 +00:00
|
|
|
* Set the super pickaxe tool.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2011-02-18 23:14:43 +00:00
|
|
|
* @param tool
|
2010-11-07 06:17:32 +00:00
|
|
|
*/
|
2011-02-18 23:14:43 +00:00
|
|
|
public void setSuperPickaxe(BlockTool tool) {
|
|
|
|
this.pickaxeMode = tool;
|
2010-11-07 06:17:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-02-18 23:14:43 +00:00
|
|
|
* Get the tool assigned to the item.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
|
|
|
* @param item
|
2010-11-07 06:17:32 +00:00
|
|
|
* @return the tool
|
|
|
|
*/
|
2011-02-18 23:14:43 +00:00
|
|
|
public Tool getTool(int item) {
|
|
|
|
return tools.get(item);
|
2011-01-09 19:14:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-02-18 23:14:43 +00:00
|
|
|
* Get the brush tool assigned to the item. If there is no tool assigned
|
|
|
|
* or the tool is not assigned, the slot will be replaced with the
|
|
|
|
* brush tool.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
|
|
|
* @param item
|
2011-02-18 23:14:43 +00:00
|
|
|
* @return the tool
|
2011-09-24 19:32:03 +00:00
|
|
|
* @throws InvalidToolBindException
|
2011-01-09 19:14:55 +00:00
|
|
|
*/
|
2011-02-19 07:36:08 +00:00
|
|
|
public BrushTool getBrushTool(int item) throws InvalidToolBindException {
|
2011-02-18 23:14:43 +00:00
|
|
|
Tool tool = getTool(item);
|
2011-09-24 19:32:03 +00:00
|
|
|
|
2011-02-19 07:36:08 +00:00
|
|
|
if (tool == null || !(tool instanceof BrushTool)) {
|
2011-05-02 00:06:40 +00:00
|
|
|
tool = new BrushTool("worldedit.brush.sphere");
|
2011-02-18 23:14:43 +00:00
|
|
|
setTool(item, tool);
|
|
|
|
}
|
2011-09-24 19:32:03 +00:00
|
|
|
|
2011-11-23 01:29:48 +00:00
|
|
|
return (BrushTool) tool;
|
2011-01-09 19:14:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-02-18 23:14:43 +00:00
|
|
|
* Set the tool.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
|
|
|
* @param item
|
2011-02-18 23:14:43 +00:00
|
|
|
* @param tool the tool to set
|
2011-09-24 19:32:03 +00:00
|
|
|
* @throws InvalidToolBindException
|
2011-02-19 04:50:40 +00:00
|
|
|
*/
|
|
|
|
public void setTool(int item, Tool tool) throws InvalidToolBindException {
|
|
|
|
if (item > 0 && item < 255) {
|
|
|
|
throw new InvalidToolBindException(item, "Blocks can't be used");
|
|
|
|
} else if (item == config.wandItem) {
|
|
|
|
throw new InvalidToolBindException(item, "Already used for the wand");
|
2011-02-19 04:59:39 +00:00
|
|
|
} else if (item == config.navigationWand) {
|
|
|
|
throw new InvalidToolBindException(item, "Already used for the navigation wand");
|
2011-02-19 04:50:40 +00:00
|
|
|
}
|
2011-09-24 19:32:03 +00:00
|
|
|
|
2011-02-18 23:14:43 +00:00
|
|
|
this.tools.put(item, tool);
|
2010-11-07 06:17:32 +00:00
|
|
|
}
|
2010-12-31 22:31:49 +00:00
|
|
|
|
|
|
|
/**
|
2011-02-18 23:14:43 +00:00
|
|
|
* Returns whether inventory usage is enabled for this session.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2010-12-31 22:31:49 +00:00
|
|
|
* @return the useInventory
|
|
|
|
*/
|
|
|
|
public boolean isUsingInventory() {
|
|
|
|
return useInventory;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-02-18 23:14:43 +00:00
|
|
|
* Set the state of inventory usage.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2010-12-31 22:31:49 +00:00
|
|
|
* @param useInventory the useInventory to set
|
|
|
|
*/
|
|
|
|
public void setUseInventory(boolean useInventory) {
|
|
|
|
this.useInventory = useInventory;
|
|
|
|
}
|
2011-01-23 10:09:51 +00:00
|
|
|
|
|
|
|
/**
|
2011-02-18 23:14:43 +00:00
|
|
|
* Get the last script used.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2011-01-23 10:09:51 +00:00
|
|
|
* @return the lastScript
|
|
|
|
*/
|
|
|
|
public String getLastScript() {
|
|
|
|
return lastScript;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-02-18 23:14:43 +00:00
|
|
|
* Set the last script used.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2011-01-23 10:09:51 +00:00
|
|
|
* @param lastScript the lastScript to set
|
|
|
|
*/
|
|
|
|
public void setLastScript(String lastScript) {
|
|
|
|
this.lastScript = lastScript;
|
|
|
|
}
|
2011-09-24 19:32:03 +00:00
|
|
|
|
2011-01-31 08:58:29 +00:00
|
|
|
/**
|
|
|
|
* Tell the player the WorldEdit version.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
|
|
|
* @param player
|
2011-01-31 08:58:29 +00:00
|
|
|
*/
|
|
|
|
public void tellVersion(LocalPlayer player) {
|
|
|
|
if (config.showFirstUseVersion) {
|
|
|
|
if (!beenToldVersion) {
|
|
|
|
player.printRaw("\u00A78WorldEdit ver. " + WorldEdit.getVersion()
|
|
|
|
+ " (http://sk89q.com/projects/worldedit/)");
|
|
|
|
beenToldVersion = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-09-24 19:32:03 +00:00
|
|
|
|
2011-03-12 06:43:02 +00:00
|
|
|
/**
|
|
|
|
* Dispatch a CUI event but only if the player has CUI support.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2011-03-12 06:43:02 +00:00
|
|
|
* @param player
|
|
|
|
* @param event
|
|
|
|
*/
|
|
|
|
public void dispatchCUIEvent(LocalPlayer player, CUIEvent event) {
|
|
|
|
if (hasCUISupport) {
|
|
|
|
player.dispatchCUIEvent(event);
|
|
|
|
}
|
|
|
|
}
|
2011-09-24 19:32:03 +00:00
|
|
|
|
2011-03-12 06:43:02 +00:00
|
|
|
/**
|
|
|
|
* Dispatch the initial setup CUI messages.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2011-03-12 06:43:02 +00:00
|
|
|
* @param player
|
|
|
|
*/
|
|
|
|
public void dispatchCUISetup(LocalPlayer player) {
|
|
|
|
if (selector != null) {
|
2011-03-12 10:27:43 +00:00
|
|
|
dispatchCUISelection(player);
|
|
|
|
}
|
|
|
|
}
|
2011-09-24 19:32:03 +00:00
|
|
|
|
2011-03-12 10:27:43 +00:00
|
|
|
/**
|
|
|
|
* Send the selection information.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2011-03-12 10:27:43 +00:00
|
|
|
* @param player
|
|
|
|
*/
|
|
|
|
public void dispatchCUISelection(LocalPlayer player) {
|
|
|
|
if (!hasCUISupport) {
|
|
|
|
return;
|
|
|
|
}
|
2011-09-24 19:32:03 +00:00
|
|
|
|
2011-09-24 19:24:10 +00:00
|
|
|
player.dispatchCUIEvent(new SelectionShapeEvent(selector.getTypeId()));
|
2011-09-24 19:32:03 +00:00
|
|
|
|
2011-03-12 10:27:43 +00:00
|
|
|
if (selector instanceof CUIPointBasedRegion) {
|
2011-09-24 17:45:03 +00:00
|
|
|
((CUIPointBasedRegion) selector).describeCUI(player);
|
2011-03-12 06:43:02 +00:00
|
|
|
}
|
|
|
|
}
|
2011-09-24 19:32:03 +00:00
|
|
|
|
2011-05-31 03:58:32 +00:00
|
|
|
/**
|
|
|
|
* Gets the status of CUI support.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2011-05-31 03:58:32 +00:00
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public boolean hasCUISupport() {
|
|
|
|
return hasCUISupport;
|
|
|
|
}
|
2011-09-24 19:32:03 +00:00
|
|
|
|
2011-03-12 06:43:02 +00:00
|
|
|
/**
|
|
|
|
* Sets the status of CUI support.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2011-03-12 06:43:02 +00:00
|
|
|
* @param support
|
|
|
|
*/
|
|
|
|
public void setCUISupport(boolean support) {
|
|
|
|
hasCUISupport = true;
|
|
|
|
}
|
2011-09-24 19:32:03 +00:00
|
|
|
|
2011-03-14 03:23:55 +00:00
|
|
|
/**
|
|
|
|
* Detect date from a user's input.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2011-03-14 03:23:55 +00:00
|
|
|
* @param input
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public Calendar detectDate(String input) {
|
|
|
|
Time.setTimeZone(getTimeZone());
|
|
|
|
Options opt = new com.sk89q.jchronic.Options();
|
|
|
|
opt.setNow(Calendar.getInstance(getTimeZone()));
|
|
|
|
Span date = Chronic.parse(input, opt);
|
|
|
|
if (date == null) {
|
|
|
|
return null;
|
|
|
|
} else {
|
|
|
|
return date.getBeginCalendar();
|
|
|
|
}
|
|
|
|
}
|
2011-09-24 19:32:03 +00:00
|
|
|
|
2011-05-02 00:37:05 +00:00
|
|
|
/**
|
|
|
|
* Update the last update time for calculating expiration.
|
|
|
|
*/
|
|
|
|
public void update() {
|
|
|
|
expirationTime = System.currentTimeMillis();
|
|
|
|
}
|
2011-09-24 19:32:03 +00:00
|
|
|
|
2011-05-02 00:37:05 +00:00
|
|
|
/**
|
|
|
|
* Returns whether this session has expired.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2011-05-02 00:37:05 +00:00
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public boolean hasExpired() {
|
|
|
|
return System.currentTimeMillis() - expirationTime > EXPIRATION_GRACE;
|
|
|
|
}
|
2011-09-24 19:32:03 +00:00
|
|
|
|
2011-06-04 17:30:45 +00:00
|
|
|
/**
|
|
|
|
* Construct a new edit session.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2011-06-04 17:30:45 +00:00
|
|
|
* @param player
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public EditSession createEditSession(LocalPlayer player) {
|
|
|
|
BlockBag blockBag = getBlockBag(player);
|
2011-09-24 19:32:03 +00:00
|
|
|
|
2011-06-04 17:30:45 +00:00
|
|
|
// Create an edit session
|
|
|
|
EditSession editSession =
|
|
|
|
new EditSession(player.getWorld(),
|
|
|
|
getBlockChangeLimit(), blockBag);
|
|
|
|
editSession.setFastMode(fastMode);
|
2011-06-04 19:16:10 +00:00
|
|
|
editSession.setMask(mask);
|
2011-09-24 19:32:03 +00:00
|
|
|
|
2011-06-04 17:30:45 +00:00
|
|
|
return editSession;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the session has fast mode enabled.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2011-06-04 17:30:45 +00:00
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public boolean hasFastMode() {
|
|
|
|
return fastMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set fast mode.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2011-06-04 17:30:45 +00:00
|
|
|
* @param fastMode
|
|
|
|
*/
|
|
|
|
public void setFastMode(boolean fastMode) {
|
|
|
|
this.fastMode = fastMode;
|
|
|
|
}
|
2011-06-04 19:16:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the mask.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2011-06-04 19:16:10 +00:00
|
|
|
* @return mask, may be null
|
|
|
|
*/
|
|
|
|
public Mask getMask() {
|
|
|
|
return mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a mask.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2011-06-04 19:16:10 +00:00
|
|
|
* @param mask mask or null
|
|
|
|
*/
|
|
|
|
public void setMask(Mask mask) {
|
|
|
|
this.mask = mask;
|
|
|
|
}
|
2010-09-30 06:41:05 +00:00
|
|
|
}
|