2010-09-30 06:41:05 +00:00
|
|
|
/*
|
2014-04-04 22:03:18 +00:00
|
|
|
* WorldEdit, a Minecraft world manipulation toolkit
|
|
|
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
|
|
|
* Copyright (C) WorldEdit team and contributors
|
2010-09-30 06:41:05 +00:00
|
|
|
*
|
2014-04-04 22:03:18 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU Lesser General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or
|
2010-09-30 06:41:05 +00:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
2014-04-04 22:03:18 +00:00
|
|
|
* 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 Lesser General Public License
|
|
|
|
* for more details.
|
2010-09-30 06:41:05 +00:00
|
|
|
*
|
2014-04-04 22:03:18 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
2010-09-30 06:41:05 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2014-04-04 22:03:18 +00:00
|
|
|
*/
|
2010-09-30 06:41:05 +00:00
|
|
|
|
2011-01-01 01:40:07 +00:00
|
|
|
package com.sk89q.worldedit;
|
|
|
|
|
2018-06-16 05:29:48 +00:00
|
|
|
import static com.google.common.base.Preconditions.checkNotNull;
|
|
|
|
|
2011-03-14 03:23:55 +00:00
|
|
|
import com.sk89q.jchronic.Chronic;
|
|
|
|
import com.sk89q.jchronic.Options;
|
|
|
|
import com.sk89q.jchronic.utils.Span;
|
|
|
|
import com.sk89q.jchronic.utils.Time;
|
2018-08-18 04:22:08 +00:00
|
|
|
import com.sk89q.jnbt.IntTag;
|
|
|
|
import com.sk89q.jnbt.Tag;
|
2014-04-04 00:52:53 +00:00
|
|
|
import com.sk89q.worldedit.command.tool.BlockTool;
|
2014-04-03 02:08:50 +00:00
|
|
|
import com.sk89q.worldedit.command.tool.BrushTool;
|
2014-07-29 14:57:45 +00:00
|
|
|
import com.sk89q.worldedit.command.tool.InvalidToolBindException;
|
2014-04-03 02:08:50 +00:00
|
|
|
import com.sk89q.worldedit.command.tool.SinglePickaxe;
|
|
|
|
import com.sk89q.worldedit.command.tool.Tool;
|
2014-06-27 23:03:29 +00:00
|
|
|
import com.sk89q.worldedit.entity.Player;
|
2014-04-05 09:59:38 +00:00
|
|
|
import com.sk89q.worldedit.extension.platform.Actor;
|
2014-04-03 02:08:50 +00:00
|
|
|
import com.sk89q.worldedit.extent.inventory.BlockBag;
|
2014-06-28 08:01:49 +00:00
|
|
|
import com.sk89q.worldedit.function.mask.Mask;
|
2014-04-03 02:08:50 +00:00
|
|
|
import com.sk89q.worldedit.internal.cui.CUIEvent;
|
2014-04-04 00:52:53 +00:00
|
|
|
import com.sk89q.worldedit.internal.cui.CUIRegion;
|
2014-04-03 02:08:50 +00:00
|
|
|
import com.sk89q.worldedit.internal.cui.SelectionShapeEvent;
|
2018-08-18 04:22:08 +00:00
|
|
|
import com.sk89q.worldedit.internal.cui.ServerCUIHandler;
|
2010-10-14 08:31:05 +00:00
|
|
|
import com.sk89q.worldedit.regions.Region;
|
2014-04-04 02:50:05 +00:00
|
|
|
import com.sk89q.worldedit.regions.RegionSelector;
|
2014-06-28 08:01:49 +00:00
|
|
|
import com.sk89q.worldedit.regions.selector.CuboidRegionSelector;
|
2014-07-29 03:53:17 +00:00
|
|
|
import com.sk89q.worldedit.regions.selector.RegionSelectorType;
|
2014-07-02 09:56:21 +00:00
|
|
|
import com.sk89q.worldedit.session.ClipboardHolder;
|
2014-04-04 00:52:53 +00:00
|
|
|
import com.sk89q.worldedit.session.request.Request;
|
2014-04-05 09:59:38 +00:00
|
|
|
import com.sk89q.worldedit.world.World;
|
2018-08-18 04:22:08 +00:00
|
|
|
import com.sk89q.worldedit.world.block.BaseBlock;
|
2018-07-30 13:26:06 +00:00
|
|
|
import com.sk89q.worldedit.world.item.ItemType;
|
|
|
|
import com.sk89q.worldedit.world.item.ItemTypes;
|
2014-04-04 00:52:53 +00:00
|
|
|
import com.sk89q.worldedit.world.snapshot.Snapshot;
|
|
|
|
|
2014-07-09 21:14:17 +00:00
|
|
|
import java.util.Calendar;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.TimeZone;
|
2014-07-28 03:44:05 +00:00
|
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
|
|
2018-06-16 05:29:48 +00:00
|
|
|
import javax.annotation.Nullable;
|
2010-10-02 20:46:33 +00:00
|
|
|
|
2010-09-30 06:41:05 +00:00
|
|
|
/**
|
2014-07-28 03:44:05 +00:00
|
|
|
* Stores session information.
|
2010-09-30 06:41:05 +00:00
|
|
|
*/
|
2011-01-01 18:34:36 +00:00
|
|
|
public class LocalSession {
|
2014-07-19 22:40:44 +00:00
|
|
|
|
2014-07-28 03:44:05 +00:00
|
|
|
public transient static int MAX_HISTORY_SIZE = 15;
|
|
|
|
|
|
|
|
// Non-session related fields
|
|
|
|
private transient LocalConfiguration config;
|
|
|
|
private transient final AtomicBoolean dirty = new AtomicBoolean();
|
2018-02-28 00:59:00 +00:00
|
|
|
private transient int failedCuiAttempts = 0;
|
2014-07-28 03:44:05 +00:00
|
|
|
|
|
|
|
// Session related
|
|
|
|
private transient RegionSelector selector = new CuboidRegionSelector();
|
|
|
|
private transient boolean placeAtPos1 = false;
|
2018-06-16 05:29:48 +00:00
|
|
|
private transient LinkedList<EditSession> history = new LinkedList<>();
|
2014-07-28 03:44:05 +00:00
|
|
|
private transient int historyPointer = 0;
|
|
|
|
private transient ClipboardHolder clipboard;
|
|
|
|
private transient boolean toolControl = true;
|
|
|
|
private transient boolean superPickaxe = false;
|
|
|
|
private transient BlockTool pickaxeMode = new SinglePickaxe();
|
2018-06-17 07:50:04 +00:00
|
|
|
private transient Map<ItemType, Tool> tools = new HashMap<>();
|
2014-07-28 03:44:05 +00:00
|
|
|
private transient int maxBlocksChanged = -1;
|
|
|
|
private transient boolean useInventory;
|
|
|
|
private transient Snapshot snapshot;
|
|
|
|
private transient boolean hasCUISupport = false;
|
|
|
|
private transient int cuiVersion = -1;
|
|
|
|
private transient boolean fastMode = false;
|
|
|
|
private transient Mask mask;
|
|
|
|
private transient TimeZone timezone = TimeZone.getDefault();
|
2018-08-18 04:22:08 +00:00
|
|
|
private transient Vector cuiTemporaryBlock;
|
2014-07-28 03:44:05 +00:00
|
|
|
|
|
|
|
// Saved properties
|
2011-01-23 10:09:51 +00:00
|
|
|
private String lastScript;
|
2014-07-29 03:53:17 +00:00
|
|
|
private RegionSelectorType defaultSelector;
|
2018-08-18 04:22:08 +00:00
|
|
|
private boolean useServerCUI = true; // Save this to not annoy players.
|
2011-03-14 03:23:55 +00:00
|
|
|
|
2011-01-31 08:58:29 +00:00
|
|
|
/**
|
|
|
|
* Construct the object.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2014-07-28 03:44:05 +00:00
|
|
|
* <p>{@link #setConfiguration(LocalConfiguration)} should be called
|
|
|
|
* later with configuration.</p>
|
|
|
|
*/
|
|
|
|
public LocalSession() {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct the object.
|
|
|
|
*
|
|
|
|
* @param config the configuration
|
|
|
|
*/
|
|
|
|
public LocalSession(@Nullable LocalConfiguration config) {
|
|
|
|
this.config = config;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the configuration.
|
|
|
|
*
|
|
|
|
* @param config the configuration
|
2011-01-31 08:58:29 +00:00
|
|
|
*/
|
2014-07-28 03:44:05 +00:00
|
|
|
public void setConfiguration(LocalConfiguration config) {
|
|
|
|
checkNotNull(config);
|
2011-01-31 08:58:29 +00:00
|
|
|
this.config = config;
|
|
|
|
}
|
2011-09-24 19:32:03 +00:00
|
|
|
|
2014-07-29 03:53:17 +00:00
|
|
|
/**
|
|
|
|
* Called on post load of the session from persistent storage.
|
|
|
|
*/
|
|
|
|
public void postLoad() {
|
|
|
|
if (defaultSelector != null) {
|
|
|
|
this.selector = defaultSelector.createSelector();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-28 03:44:05 +00:00
|
|
|
/**
|
|
|
|
* Get whether this session is "dirty" and has changes that needs to
|
|
|
|
* be committed.
|
|
|
|
*
|
|
|
|
* @return true if dirty
|
|
|
|
*/
|
|
|
|
public boolean isDirty() {
|
|
|
|
return dirty.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set this session as dirty.
|
|
|
|
*/
|
|
|
|
private void setDirty() {
|
|
|
|
dirty.set(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get whether this session is "dirty" and has changes that needs to
|
|
|
|
* be committed, and reset it to {@code false}.
|
|
|
|
*
|
|
|
|
* @return true if the dirty value was {@code true}
|
|
|
|
*/
|
|
|
|
public boolean compareAndResetDirty() {
|
|
|
|
return dirty.compareAndSet(true, false);
|
|
|
|
}
|
|
|
|
|
2011-03-14 03:23:55 +00:00
|
|
|
/**
|
|
|
|
* Get the session's timezone.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2014-07-28 03:44:05 +00:00
|
|
|
* @return the timezone
|
2011-03-14 03:23:55 +00:00
|
|
|
*/
|
|
|
|
public TimeZone getTimeZone() {
|
|
|
|
return timezone;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the session's timezone.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2014-07-28 03:44:05 +00:00
|
|
|
* @param timezone the user's timezone
|
2011-03-14 03:23:55 +00:00
|
|
|
*/
|
|
|
|
public void setTimezone(TimeZone timezone) {
|
2014-07-28 03:44:05 +00:00
|
|
|
checkNotNull(timezone);
|
2011-03-14 03:23:55 +00:00
|
|
|
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
|
|
|
*
|
2014-07-28 03:44:05 +00:00
|
|
|
* @param editSession the edit session
|
2010-10-02 21:52:42 +00:00
|
|
|
*/
|
|
|
|
public void remember(EditSession editSession) {
|
2014-07-28 03:44:05 +00:00
|
|
|
checkNotNull(editSession);
|
|
|
|
|
2010-10-02 21:52:42 +00:00
|
|
|
// 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();
|
|
|
|
}
|
|
|
|
|
2014-06-28 08:01:49 +00:00
|
|
|
/**
|
|
|
|
* Performs an undo.
|
|
|
|
*
|
2014-07-28 03:44:05 +00:00
|
|
|
* @param newBlockBag a new block bag
|
|
|
|
* @param player the player
|
2014-06-28 08:01:49 +00:00
|
|
|
* @return whether anything was undone
|
|
|
|
*/
|
2014-07-28 05:04:28 +00:00
|
|
|
public EditSession undo(@Nullable BlockBag newBlockBag, Player player) {
|
2014-07-28 03:44:05 +00:00
|
|
|
checkNotNull(player);
|
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);
|
2012-10-18 10:34:09 +00:00
|
|
|
EditSession newEditSession = WorldEdit.getInstance().getEditSessionFactory()
|
2012-11-13 10:07:08 +00:00
|
|
|
.getEditSession(editSession.getWorld(), -1, newBlockBag, player);
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-28 08:01:49 +00:00
|
|
|
/**
|
|
|
|
* Performs a redo
|
|
|
|
*
|
2014-07-28 03:44:05 +00:00
|
|
|
* @param newBlockBag a new block bag
|
|
|
|
* @param player the player
|
2014-06-28 08:01:49 +00:00
|
|
|
* @return whether anything was redone
|
|
|
|
*/
|
2014-07-28 05:04:28 +00:00
|
|
|
public EditSession redo(@Nullable BlockBag newBlockBag, Player player) {
|
2014-07-28 03:44:05 +00:00
|
|
|
checkNotNull(player);
|
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);
|
2012-10-18 10:34:09 +00:00
|
|
|
EditSession newEditSession = WorldEdit.getInstance().getEditSessionFactory()
|
2012-11-13 10:07:08 +00:00
|
|
|
.getEditSession(editSession.getWorld(), -1, newBlockBag, player);
|
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
|
|
|
|
2014-07-29 03:53:17 +00:00
|
|
|
/**
|
|
|
|
* Get the default region selector.
|
|
|
|
*
|
|
|
|
* @return the default region selector
|
|
|
|
*/
|
|
|
|
public RegionSelectorType getDefaultRegionSelector() {
|
|
|
|
return defaultSelector;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the default region selector.
|
|
|
|
*
|
|
|
|
* @param defaultSelector the default region selector
|
|
|
|
*/
|
|
|
|
public void setDefaultRegionSelector(RegionSelectorType defaultSelector) {
|
|
|
|
checkNotNull(defaultSelector);
|
|
|
|
this.defaultSelector = defaultSelector;
|
|
|
|
setDirty();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
*
|
2014-07-28 03:44:05 +00:00
|
|
|
* @param world the world
|
|
|
|
* @return position the position
|
2010-10-03 19:43:30 +00:00
|
|
|
*/
|
2014-04-05 09:59:38 +00:00
|
|
|
public RegionSelector getRegionSelector(World world) {
|
2014-07-28 03:44:05 +00:00
|
|
|
checkNotNull(world);
|
2014-07-29 03:53:17 +00:00
|
|
|
if (selector.getWorld() == null || !selector.getWorld().equals(world)) {
|
|
|
|
selector.setWorld(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
|
|
|
|
|
|
|
/**
|
2011-02-20 01:44:39 +00:00
|
|
|
* Set the region selector.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2014-07-28 03:44:05 +00:00
|
|
|
* @param world the world
|
|
|
|
* @param selector the selector
|
2010-11-16 09:01:37 +00:00
|
|
|
*/
|
2014-04-05 09:59:38 +00:00
|
|
|
public void setRegionSelector(World world, RegionSelector selector) {
|
2014-07-28 03:44:05 +00:00
|
|
|
checkNotNull(world);
|
|
|
|
checkNotNull(selector);
|
2014-07-29 03:53:17 +00:00
|
|
|
selector.setWorld(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 for the specified world.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2014-07-28 03:44:05 +00:00
|
|
|
* @param world the world
|
|
|
|
* @return true if a region selection is defined
|
2010-10-03 19:43:30 +00:00
|
|
|
*/
|
2014-04-05 09:59:38 +00:00
|
|
|
public boolean isSelectionDefined(World world) {
|
2014-07-28 03:44:05 +00:00
|
|
|
checkNotNull(world);
|
2011-12-13 03:20:31 +00:00
|
|
|
if (selector.getIncompleteRegion().getWorld() == null || !selector.getIncompleteRegion().getWorld().equals(world)) {
|
2011-02-20 01:44:39 +00:00
|
|
|
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-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
|
2014-07-28 03:44:05 +00:00
|
|
|
* a different world, the {@code IncompleteRegionException}
|
2011-02-20 01:44:39 +00:00
|
|
|
* exception will be thrown.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2014-07-28 03:44:05 +00:00
|
|
|
* @param world the world
|
|
|
|
* @return a region
|
|
|
|
* @throws IncompleteRegionException if no region is selected
|
2010-10-03 19:43:30 +00:00
|
|
|
*/
|
2014-04-05 09:59:38 +00:00
|
|
|
public Region getSelection(World world) throws IncompleteRegionException {
|
2014-07-28 03:44:05 +00:00
|
|
|
checkNotNull(world);
|
2011-12-13 03:20:31 +00:00
|
|
|
if (selector.getIncompleteRegion().getWorld() == null || !selector.getIncompleteRegion().getWorld().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
|
|
|
*
|
2014-07-28 03:44:05 +00:00
|
|
|
* @return the the world of the selection
|
2011-03-12 08:28:19 +00:00
|
|
|
*/
|
2014-04-05 09:59:38 +00:00
|
|
|
public World getSelectionWorld() {
|
2011-12-13 03:20:31 +00:00
|
|
|
return selector.getIncompleteRegion().getWorld();
|
2011-03-12 08:28:19 +00:00
|
|
|
}
|
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
|
|
|
*
|
2014-07-28 03:44:05 +00:00
|
|
|
* @return clipboard
|
2014-07-09 21:14:17 +00:00
|
|
|
* @throws EmptyClipboardException thrown if no clipboard is set
|
2010-10-02 23:11:44 +00:00
|
|
|
*/
|
2014-07-02 09:56:21 +00:00
|
|
|
public ClipboardHolder getClipboard() throws EmptyClipboardException {
|
2010-10-13 17:08:53 +00:00
|
|
|
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
|
|
|
*
|
2014-07-09 21:14:17 +00:00
|
|
|
* <p>Pass {@code null} to clear the clipboard.</p>
|
|
|
|
*
|
|
|
|
* @param clipboard the clipboard, or null if the clipboard is to be cleared
|
2010-10-02 23:11:44 +00:00
|
|
|
*/
|
2014-07-09 21:14:17 +00:00
|
|
|
public void setClipboard(@Nullable ClipboardHolder clipboard) {
|
|
|
|
this.clipboard = clipboard;
|
2010-10-02 23:11:44 +00:00
|
|
|
}
|
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
|
|
|
*
|
2014-07-28 03:44:05 +00:00
|
|
|
* @param toolControl true to enable tool control
|
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
|
|
|
*
|
2014-07-28 03:44:05 +00:00
|
|
|
* @param maxBlocksChanged the maximum number of blocks changed
|
2010-10-04 23:39:35 +00:00
|
|
|
*/
|
|
|
|
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.
|
|
|
|
*
|
2014-07-28 03:44:05 +00:00
|
|
|
* @return whether the super pick axe is now enabled
|
2010-10-13 18:26:07 +00:00
|
|
|
*/
|
|
|
|
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
|
|
|
|
|
|
|
/**
|
2014-07-28 03:44:05 +00:00
|
|
|
* Get the position use for commands that take a center point
|
|
|
|
* (i.e. //forestgen, etc.).
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2014-07-28 03:44:05 +00:00
|
|
|
* @param player the player
|
|
|
|
* @return the position to use
|
|
|
|
* @throws IncompleteRegionException thrown if a region is not fully selected
|
2010-10-14 09:14:18 +00:00
|
|
|
*/
|
2014-06-28 00:55:39 +00:00
|
|
|
public Vector getPlacementPosition(Player player) throws IncompleteRegionException {
|
2014-07-28 03:44:05 +00:00
|
|
|
checkNotNull(player);
|
2010-10-14 09:14:18 +00:00
|
|
|
if (!placeAtPos1) {
|
2018-06-16 05:29:48 +00:00
|
|
|
return player.getBlockIn().toVector();
|
2010-10-14 09:14:18 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
*
|
2014-07-28 03:44:05 +00:00
|
|
|
* @return whether "place at position 1" is now enabled
|
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
|
|
|
*
|
2014-07-28 03:44:05 +00:00
|
|
|
* @param player the player to get the block bag for
|
|
|
|
* @return a block bag
|
2010-12-31 22:31:49 +00:00
|
|
|
*/
|
2014-07-28 03:44:05 +00:00
|
|
|
@Nullable
|
2014-06-27 23:03:29 +00:00
|
|
|
public BlockBag getBlockBag(Player player) {
|
2014-07-28 03:44:05 +00:00
|
|
|
checkNotNull(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
|
|
|
*/
|
2014-07-28 03:44:05 +00:00
|
|
|
@Nullable
|
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
|
|
|
*
|
2014-07-28 03:44:05 +00:00
|
|
|
* @param snapshot a snapshot
|
2010-10-20 23:15:20 +00:00
|
|
|
*/
|
2014-07-28 03:44:05 +00:00
|
|
|
public void setSnapshot(@Nullable Snapshot snapshot) {
|
2010-10-20 23:15:20 +00:00
|
|
|
this.snapshot = snapshot;
|
|
|
|
}
|
2010-11-07 06:17:32 +00:00
|
|
|
|
|
|
|
/**
|
2014-07-28 03:44:05 +00:00
|
|
|
* Get the assigned block tool.
|
|
|
|
*
|
|
|
|
* @return the super pickaxe tool mode
|
2010-11-07 06:17:32 +00:00
|
|
|
*/
|
2011-02-18 23:14:43 +00:00
|
|
|
public BlockTool getSuperPickaxe() {
|
|
|
|
return pickaxeMode;
|
2010-11-07 06:17:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-07-28 03:44:05 +00:00
|
|
|
* Set the super pick axe tool.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2014-07-28 03:44:05 +00:00
|
|
|
* @param tool the tool to set
|
2010-11-07 06:17:32 +00:00
|
|
|
*/
|
2011-02-18 23:14:43 +00:00
|
|
|
public void setSuperPickaxe(BlockTool tool) {
|
2014-07-28 03:44:05 +00:00
|
|
|
checkNotNull(tool);
|
2011-02-18 23:14:43 +00:00
|
|
|
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
|
|
|
*
|
2018-06-17 07:50:04 +00:00
|
|
|
* @param item the item type
|
2014-07-28 03:44:05 +00:00
|
|
|
* @return the tool, which may be {@link null}
|
2010-11-07 06:17:32 +00:00
|
|
|
*/
|
2014-07-28 03:44:05 +00:00
|
|
|
@Nullable
|
2018-06-17 07:50:04 +00:00
|
|
|
public Tool getTool(ItemType item) {
|
2011-02-18 23:14:43 +00:00
|
|
|
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
|
|
|
*
|
2018-06-17 07:50:04 +00:00
|
|
|
* @param item the item type
|
2014-07-28 03:44:05 +00:00
|
|
|
* @return the tool, or {@code null}
|
|
|
|
* @throws InvalidToolBindException if the item can't be bound to that item
|
2011-01-09 19:14:55 +00:00
|
|
|
*/
|
2018-06-17 07:50:04 +00:00
|
|
|
public BrushTool getBrushTool(ItemType item) throws InvalidToolBindException {
|
2011-02-18 23:14:43 +00:00
|
|
|
Tool tool = getTool(item);
|
2011-09-24 19:32:03 +00:00
|
|
|
|
2018-06-17 07:50:04 +00:00
|
|
|
if (!(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
|
|
|
*
|
2018-06-17 07:50:04 +00:00
|
|
|
* @param item the item type
|
2014-07-28 03:44:05 +00:00
|
|
|
* @param tool the tool to set, which can be {@code null}
|
|
|
|
* @throws InvalidToolBindException if the item can't be bound to that item
|
2011-02-19 04:50:40 +00:00
|
|
|
*/
|
2018-06-17 07:50:04 +00:00
|
|
|
public void setTool(ItemType item, @Nullable Tool tool) throws InvalidToolBindException {
|
2018-07-01 13:20:07 +00:00
|
|
|
if (item.hasBlockType()) {
|
2011-02-19 04:50:40 +00:00
|
|
|
throw new InvalidToolBindException(item, "Blocks can't be used");
|
2018-07-05 08:48:37 +00:00
|
|
|
} else if (item == ItemTypes.get(config.wandItem)) {
|
2011-02-19 04:50:40 +00:00
|
|
|
throw new InvalidToolBindException(item, "Already used for the wand");
|
2018-07-05 08:48:37 +00:00
|
|
|
} else if (item == ItemTypes.get(config.navigationWand)) {
|
2011-02-19 04:59:39 +00:00
|
|
|
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
|
|
|
*
|
2014-07-28 03:44:05 +00:00
|
|
|
* @return if inventory is being used
|
2010-12-31 22:31:49 +00:00
|
|
|
*/
|
|
|
|
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
|
|
|
*
|
2014-07-28 03:44:05 +00:00
|
|
|
* @param useInventory if inventory is to be used
|
2010-12-31 22:31:49 +00:00
|
|
|
*/
|
|
|
|
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
|
|
|
*
|
2014-07-28 03:44:05 +00:00
|
|
|
* @return the last script's name
|
2011-01-23 10:09:51 +00:00
|
|
|
*/
|
2014-07-28 03:44:05 +00:00
|
|
|
@Nullable
|
2011-01-23 10:09:51 +00:00
|
|
|
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
|
|
|
*
|
2014-07-28 03:44:05 +00:00
|
|
|
* @param lastScript the last script's name
|
2011-01-23 10:09:51 +00:00
|
|
|
*/
|
2014-07-28 03:44:05 +00:00
|
|
|
public void setLastScript(@Nullable String lastScript) {
|
2011-01-23 10:09:51 +00:00
|
|
|
this.lastScript = lastScript;
|
2014-07-28 03:44:05 +00:00
|
|
|
setDirty();
|
2011-01-23 10:09:51 +00:00
|
|
|
}
|
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
|
|
|
*
|
2014-07-28 03:44:05 +00:00
|
|
|
* @param player the player
|
2011-01-31 08:58:29 +00:00
|
|
|
*/
|
2014-06-27 23:03:29 +00:00
|
|
|
public void tellVersion(Actor player) {
|
2011-01-31 08:58:29 +00:00
|
|
|
}
|
2011-09-24 19:32:03 +00:00
|
|
|
|
2018-08-18 06:34:32 +00:00
|
|
|
public boolean shouldUseServerCUI() {
|
|
|
|
return this.useServerCUI;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setUseServerCUI(boolean useServerCUI) {
|
|
|
|
this.useServerCUI = useServerCUI;
|
2018-08-19 00:46:46 +00:00
|
|
|
setDirty();
|
2018-08-18 06:34:32 +00:00
|
|
|
}
|
|
|
|
|
2018-08-18 04:22:08 +00:00
|
|
|
/**
|
|
|
|
* Update server-side WorldEdit CUI.
|
|
|
|
*
|
|
|
|
* @param actor The player
|
|
|
|
*/
|
|
|
|
public void updateServerCUI(Actor actor) {
|
|
|
|
if (!actor.isPlayer()) {
|
|
|
|
return; // This is for players only.
|
|
|
|
}
|
|
|
|
|
2018-08-18 09:42:45 +00:00
|
|
|
if (!config.serverSideCUI) {
|
|
|
|
return; // Disabled in config.
|
|
|
|
}
|
|
|
|
|
2018-08-18 06:34:32 +00:00
|
|
|
Player player = (Player) actor;
|
|
|
|
|
2018-08-18 04:22:08 +00:00
|
|
|
if (!useServerCUI || hasCUISupport) {
|
2018-08-18 06:34:32 +00:00
|
|
|
if (cuiTemporaryBlock != null) {
|
|
|
|
player.sendFakeBlock(cuiTemporaryBlock, null);
|
|
|
|
cuiTemporaryBlock = null;
|
|
|
|
}
|
2018-08-18 04:22:08 +00:00
|
|
|
return; // If it's not enabled, ignore this.
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove the old block.
|
|
|
|
if (cuiTemporaryBlock != null) {
|
2018-08-18 05:22:49 +00:00
|
|
|
player.sendFakeBlock(cuiTemporaryBlock, null);
|
2018-08-18 04:22:08 +00:00
|
|
|
cuiTemporaryBlock = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
BaseBlock block = ServerCUIHandler.createStructureBlock(player);
|
|
|
|
if (block != null) {
|
|
|
|
// If it's null, we don't need to do anything. The old was already removed.
|
|
|
|
Map<String, Tag> tags = block.getNbtData().getValue();
|
|
|
|
cuiTemporaryBlock = new Vector(
|
|
|
|
((IntTag) tags.get("x")).getValue(),
|
|
|
|
((IntTag) tags.get("y")).getValue(),
|
|
|
|
((IntTag) tags.get("z")).getValue()
|
|
|
|
);
|
|
|
|
|
2018-08-18 05:22:49 +00:00
|
|
|
player.sendFakeBlock(cuiTemporaryBlock, block);
|
2018-08-18 04:22:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-12 06:43:02 +00:00
|
|
|
/**
|
2014-07-28 03:44:05 +00:00
|
|
|
* Dispatch a CUI event but only if the actor has CUI support.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2014-07-28 03:44:05 +00:00
|
|
|
* @param actor the actor
|
|
|
|
* @param event the event
|
2011-03-12 06:43:02 +00:00
|
|
|
*/
|
2014-07-28 03:44:05 +00:00
|
|
|
public void dispatchCUIEvent(Actor actor, CUIEvent event) {
|
|
|
|
checkNotNull(actor);
|
|
|
|
checkNotNull(event);
|
|
|
|
|
2011-03-12 06:43:02 +00:00
|
|
|
if (hasCUISupport) {
|
2014-07-28 03:44:05 +00:00
|
|
|
actor.dispatchCUIEvent(event);
|
2018-08-18 04:22:08 +00:00
|
|
|
} else if (useServerCUI) {
|
|
|
|
updateServerCUI(actor);
|
2011-03-12 06:43:02 +00:00
|
|
|
}
|
|
|
|
}
|
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
|
|
|
*
|
2014-07-28 03:44:05 +00:00
|
|
|
* @param actor the actor
|
2011-03-12 06:43:02 +00:00
|
|
|
*/
|
2014-07-28 03:44:05 +00:00
|
|
|
public void dispatchCUISetup(Actor actor) {
|
2011-03-12 06:43:02 +00:00
|
|
|
if (selector != null) {
|
2014-07-28 03:44:05 +00:00
|
|
|
dispatchCUISelection(actor);
|
2011-03-12 10:27:43 +00:00
|
|
|
}
|
|
|
|
}
|
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
|
|
|
*
|
2014-07-28 03:44:05 +00:00
|
|
|
* @param actor the actor
|
2011-03-12 10:27:43 +00:00
|
|
|
*/
|
2014-07-28 03:44:05 +00:00
|
|
|
public void dispatchCUISelection(Actor actor) {
|
|
|
|
checkNotNull(actor);
|
|
|
|
|
2011-03-12 10:27:43 +00:00
|
|
|
if (!hasCUISupport) {
|
2018-08-18 04:22:08 +00:00
|
|
|
if (useServerCUI) {
|
|
|
|
updateServerCUI(actor);
|
|
|
|
}
|
2011-03-12 10:27:43 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-09-24 19:32:03 +00:00
|
|
|
|
2012-01-01 04:16:39 +00:00
|
|
|
if (selector instanceof CUIRegion) {
|
|
|
|
CUIRegion tempSel = (CUIRegion) selector;
|
|
|
|
|
|
|
|
if (tempSel.getProtocolVersion() > cuiVersion) {
|
2014-07-28 03:44:05 +00:00
|
|
|
actor.dispatchCUIEvent(new SelectionShapeEvent(tempSel.getLegacyTypeID()));
|
|
|
|
tempSel.describeLegacyCUI(this, actor);
|
2012-01-01 04:16:39 +00:00
|
|
|
} else {
|
2014-07-28 03:44:05 +00:00
|
|
|
actor.dispatchCUIEvent(new SelectionShapeEvent(tempSel.getTypeID()));
|
|
|
|
tempSel.describeCUI(this, actor);
|
2012-01-01 04:16:39 +00:00
|
|
|
}
|
|
|
|
|
2011-12-30 10:59:33 +00:00
|
|
|
}
|
2012-01-01 04:16:39 +00:00
|
|
|
}
|
2012-04-20 04:46:18 +00:00
|
|
|
|
2014-07-28 03:44:05 +00:00
|
|
|
/**
|
|
|
|
* Describe the selection to the CUI actor.
|
|
|
|
*
|
|
|
|
* @param actor the actor
|
|
|
|
*/
|
|
|
|
public void describeCUI(Actor actor) {
|
|
|
|
checkNotNull(actor);
|
|
|
|
|
2012-01-01 04:16:39 +00:00
|
|
|
if (!hasCUISupport) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (selector instanceof CUIRegion) {
|
|
|
|
CUIRegion tempSel = (CUIRegion) selector;
|
|
|
|
|
|
|
|
if (tempSel.getProtocolVersion() > cuiVersion) {
|
2014-07-28 03:44:05 +00:00
|
|
|
tempSel.describeLegacyCUI(this, actor);
|
2012-01-01 04:16:39 +00:00
|
|
|
} else {
|
2014-07-28 03:44:05 +00:00
|
|
|
tempSel.describeCUI(this, actor);
|
2012-01-01 04:16:39 +00:00
|
|
|
}
|
2011-09-24 19:32:03 +00:00
|
|
|
|
2011-03-12 06:43:02 +00:00
|
|
|
}
|
|
|
|
}
|
2011-09-24 19:32:03 +00:00
|
|
|
|
2014-07-28 03:44:05 +00:00
|
|
|
/**
|
|
|
|
* Handle a CUI initialization message.
|
|
|
|
*
|
|
|
|
* @param text the message
|
|
|
|
*/
|
2012-08-05 03:22:55 +00:00
|
|
|
public void handleCUIInitializationMessage(String text) {
|
2014-07-28 03:44:05 +00:00
|
|
|
checkNotNull(text);
|
2018-02-28 00:59:00 +00:00
|
|
|
if (this.failedCuiAttempts > 3) {
|
|
|
|
return;
|
|
|
|
}
|
2014-07-28 03:44:05 +00:00
|
|
|
|
2018-02-28 00:59:00 +00:00
|
|
|
String[] split = text.split("\\|", 2);
|
2012-08-05 03:22:55 +00:00
|
|
|
if (split.length > 1 && split[0].equalsIgnoreCase("v")) { // enough fields and right message
|
2018-02-28 00:59:00 +00:00
|
|
|
if (split[1].length() > 4) {
|
|
|
|
this.failedCuiAttempts ++;
|
|
|
|
return;
|
|
|
|
}
|
2012-08-05 03:22:55 +00:00
|
|
|
setCUISupport(true);
|
|
|
|
try {
|
|
|
|
setCUIVersion(Integer.parseInt(split[1]));
|
|
|
|
} catch (NumberFormatException e) {
|
|
|
|
WorldEdit.logger.warning("Error while reading CUI init message: " + e.getMessage());
|
2018-02-28 00:59:00 +00:00
|
|
|
this.failedCuiAttempts ++;
|
2012-08-05 03:22:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-31 03:58:32 +00:00
|
|
|
/**
|
|
|
|
* Gets the status of CUI support.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2014-07-28 03:44:05 +00:00
|
|
|
* @return true if CUI is enabled
|
2011-05-31 03:58:32 +00:00
|
|
|
*/
|
|
|
|
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
|
|
|
*
|
2014-07-28 03:44:05 +00:00
|
|
|
* @param support true if CUI is enabled
|
2011-03-12 06:43:02 +00:00
|
|
|
*/
|
|
|
|
public void setCUISupport(boolean support) {
|
2012-08-05 03:22:55 +00:00
|
|
|
hasCUISupport = support;
|
2011-03-12 06:43:02 +00:00
|
|
|
}
|
2011-09-24 19:32:03 +00:00
|
|
|
|
2012-01-01 04:16:39 +00:00
|
|
|
/**
|
|
|
|
* Gets the client's CUI protocol version
|
2012-04-20 04:46:18 +00:00
|
|
|
*
|
2014-07-28 03:44:05 +00:00
|
|
|
* @return the CUI version
|
2012-01-01 04:16:39 +00:00
|
|
|
*/
|
|
|
|
public int getCUIVersion() {
|
|
|
|
return cuiVersion;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the client's CUI protocol version
|
2012-04-20 04:46:18 +00:00
|
|
|
*
|
2014-07-28 03:44:05 +00:00
|
|
|
* @param cuiVersion the CUI version
|
2012-01-01 04:16:39 +00:00
|
|
|
*/
|
2014-04-04 23:09:05 +00:00
|
|
|
public void setCUIVersion(int cuiVersion) {
|
|
|
|
this.cuiVersion = cuiVersion;
|
2012-01-01 04:16:39 +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
|
|
|
*
|
2014-07-28 03:44:05 +00:00
|
|
|
* @param input the input to parse
|
|
|
|
* @return a date
|
2011-03-14 03:23:55 +00:00
|
|
|
*/
|
2014-07-28 03:44:05 +00:00
|
|
|
@Nullable
|
2011-03-14 03:23:55 +00:00
|
|
|
public Calendar detectDate(String input) {
|
2014-07-28 03:44:05 +00:00
|
|
|
checkNotNull(input);
|
|
|
|
|
2011-03-14 03:23:55 +00:00
|
|
|
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
|
|
|
|
2014-06-27 23:03:29 +00:00
|
|
|
/**
|
|
|
|
* Construct a new edit session.
|
|
|
|
*
|
2014-07-28 03:44:05 +00:00
|
|
|
* @param player the player
|
|
|
|
* @return an edit session
|
2014-06-27 23:03:29 +00:00
|
|
|
*/
|
|
|
|
public EditSession createEditSession(Player player) {
|
2014-07-28 03:44:05 +00:00
|
|
|
checkNotNull(player);
|
|
|
|
|
2011-06-04 17:30:45 +00:00
|
|
|
BlockBag blockBag = getBlockBag(player);
|
2011-09-24 19:32:03 +00:00
|
|
|
|
2011-06-04 17:30:45 +00:00
|
|
|
// Create an edit session
|
2012-10-18 10:34:09 +00:00
|
|
|
EditSession editSession = WorldEdit.getInstance().getEditSessionFactory()
|
|
|
|
.getEditSession(player.isPlayer() ? player.getWorld() : null,
|
2012-11-13 10:07:08 +00:00
|
|
|
getBlockChangeLimit(), blockBag, player);
|
2011-06-04 17:30:45 +00:00
|
|
|
editSession.setFastMode(fastMode);
|
2014-04-04 00:52:53 +00:00
|
|
|
Request.request().setEditSession(editSession);
|
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
|
|
|
*
|
2014-07-28 03:44:05 +00:00
|
|
|
* @return true if fast mode is enabled
|
2011-06-04 17:30:45 +00:00
|
|
|
*/
|
|
|
|
public boolean hasFastMode() {
|
|
|
|
return fastMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set fast mode.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2014-07-28 03:44:05 +00:00
|
|
|
* @param fastMode true if fast mode is enabled
|
2011-06-04 17:30:45 +00:00
|
|
|
*/
|
|
|
|
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;
|
|
|
|
}
|
2014-06-28 08:01:49 +00:00
|
|
|
|
2010-09-30 06:41:05 +00:00
|
|
|
}
|