Plex-FAWE/worldedit-core/src/main/java/com/sk89q/worldedit/WorldEdit.java

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

901 lines
31 KiB
Java
Raw Normal View History

/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* 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 <https://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit;
Feature/1.17 (#1120) * start v6 * Update classes to v6 method signatures * change rootVersion to signify p2v6 compat * Use 16 as toolchain version but target 11 for build output * add minimessage as api * Require v6 and don't attempt to "setup" hook from FAWE * Address comments * *address /all/ comments * FAWE classes should only act as a delegate * Uppercase logger * Settings for v6-hook have moved to P2-v6, remove unneeded if statements * Rename classes to Delegate * add whenDone task to setCuboids * Remove bad spaces * Fix plot swap * Initial work on 1.17 support * Remove data versions from the Bukkit adapters (#1507) * Remove data versions from the Bukkit adapters * Don't allow saving schematics without an adapter in place on Bukkit. * Removed confusing line (cherry picked from commit 2056218b4a8644836b1d127105dfa289e9cdbc1c) * More progress * Fix chunk sending * Repackage from com.boydti to com.fastasyncworldedit.<module> (#1119) * Preliminary work on repackaging * Rename build artifacts matching our pattern * Finish up repackaging * Fix a few field accesses and old imports * Dirty fix for chunks container ChunkSections outside of 0-15 * Correctly read from NibbleArrays for lighting * Fix getSections and BlockMaterial for 1.17 * Fix writing blocks to the world. - The issue isn't the presence of a "-1" chunk, it's the constructor for ChunkSection requiring the layer (0 to 15) rather than the y chord * Fix more field accesses * More work towards 1.17 * Update Upstream a57f66f Fix watchdog, add negative y support. (1782) * Add azalea tree to `/tool tree` * Don't define toolchain twice * Repackage GriefDefender * Relocate under new namespace * Bye bye ecma left overs * Add 1.17 to issue templates and instructions * Move to adventure-nbt (#918) * Initial work for adventure-nbt * Some more FAWE specific stuff * Fix erroneous deprecation check * Workflow change * Continued merging all adventure NBT related changes * Continued merging all adventure NBT related changes * Made a constructor public again This needs to be public for BlockTransformExtent.java * Finished converting all NBT data to adventure. * Make this compile * Fix conflicts Co-authored-by: Matt <4009945+MattBDev@users.noreply.github.com> * Update adapters to 1.17 * Change build prefix to 1.17 * Move more nms classes to adapters * Move left over nms classes * Move Spigot 1.17 class * Remove unneeded adapter loader code The loader will find the appropriate class now itself * Update adapters * Update adapters * Lazy fix tests * Update adapters * Update Upstream 43da91a Remove method reflection for getMinHeight in BukkitWorld. (1796) * Relocate adventure-nbt under proper namespace * Add LazyCompoundTag as a non-version-specific class to be used by adapters * Better integration between old NBT and Adventure NBT - begin fixing the issues seen recently * Correctly NBT conversion method * LazyCompoundTags should actually be overriding and correctly returning a CompoundBinaryTag. * Update worldedit-adapters Fixes #1141 * Remove unnecessary massive lag machine * Refactor apply to applyBlock in subclasses * applyBlock should be overriden by all subclasses. Default apply to applyBlock * Closes #1130 Closes #1132 * Squashed commit of the following: commit a9bfa1a07c77083c844a0c3ba62f4bd94bed107c Author: NotMyFault <mc.cache@web.de> Date: Sun Jun 27 21:53:21 2021 +0200 [ci skip] Update gradle wrapper validation commit aa7471f95317d28a16f62e4b200de8d0fea2fa95 Author: Matthew Miller <mnmiller1@me.com> Date: Sat Oct 10 15:49:13 2020 +1000 Add ^x,y,z relative offset support to the offset parser (#1545) * Add ^x,y,z relative offset support to the offset parser * Wrap in a try-catch (cherry picked from commit 28bdf7ff9254bbc85bb4f5f792b303943a3930a8) * Add `fawe.error.schematic.not.found` translation key * Update Upstream 728a152 Skip notify if chunk section doesn't exist (1794) * Fixed #1157 * Add a null check to prevent NPE in nbt code * Update adapters * Update Upstream fbb047a Optimize legacy schematic loading (1808) * Hurr durr I don't want to update Java * Update Upstream 0790e6e Fix CLI Mess (1811) * Fixes #1160 * Expose minimessage transitively thru PlotSquared Touches #32 * [ci skip] Remove unneeded maven repository * Steal tab completion from PlotSquared for P2 related commands * Don't error on startup when building locally Co-Authored-By: goldfishapp <8278196+goldfishapp@users.noreply.github.com> * [ci skip] Update gh actions to Java 16 * Update textures to grab 1.17 jar Co-authored-by: NotMyFault <mc.cache@web.de> Co-authored-by: SirYwell <hannesgreule@outlook.de> Co-authored-by: Matthew Miller <mnmiller1@me.com> Co-authored-by: Matt <4009945+MattBDev@users.noreply.github.com> Co-authored-by: goldfishapp <8278196+goldfishapp@users.noreply.github.com>
2021-07-01 20:16:25 +00:00
import com.fastasyncworldedit.core.configuration.Caption;
2021-09-08 15:39:43 +00:00
import com.fastasyncworldedit.core.extension.factory.TransformFactory;
import com.fastasyncworldedit.core.extent.ResettableExtent;
2020-07-14 02:50:59 +00:00
import com.google.common.base.Throwables;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.ImmutableList;
2020-07-14 02:50:59 +00:00
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
2020-07-14 02:50:59 +00:00
import com.google.common.collect.SetMultimap;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
import com.sk89q.worldedit.blocks.BaseItem;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.event.platform.BlockInteractEvent;
import com.sk89q.worldedit.event.platform.InputType;
import com.sk89q.worldedit.event.platform.PlayerInputEvent;
import com.sk89q.worldedit.extension.factory.BlockFactory;
import com.sk89q.worldedit.extension.factory.ItemFactory;
import com.sk89q.worldedit.extension.factory.MaskFactory;
import com.sk89q.worldedit.extension.factory.PatternFactory;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.extension.platform.Locatable;
import com.sk89q.worldedit.extension.platform.Platform;
import com.sk89q.worldedit.extension.platform.PlatformManager;
import com.sk89q.worldedit.extent.inventory.BlockBag;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.internal.SchematicsEventListener;
2019-04-03 13:25:16 +00:00
import com.sk89q.worldedit.internal.expression.Expression;
2020-07-14 02:50:59 +00:00
import com.sk89q.worldedit.internal.expression.invoke.ReturnException;
import com.sk89q.worldedit.internal.util.LogManagerCompat;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.scripting.CraftScriptContext;
import com.sk89q.worldedit.scripting.CraftScriptEngine;
import com.sk89q.worldedit.scripting.RhinoCraftScriptEngine;
import com.sk89q.worldedit.session.SessionManager;
import com.sk89q.worldedit.util.Direction;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.util.concurrency.EvenMoreExecutors;
import com.sk89q.worldedit.util.concurrency.LazyReference;
import com.sk89q.worldedit.util.eventbus.EventBus;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.util.io.file.FileSelectionAbortedException;
import com.sk89q.worldedit.util.io.file.FilenameException;
import com.sk89q.worldedit.util.io.file.FilenameResolutionException;
import com.sk89q.worldedit.util.io.file.InvalidFilenameException;
import com.sk89q.worldedit.util.task.SimpleSupervisor;
import com.sk89q.worldedit.util.task.Supervisor;
import com.sk89q.worldedit.util.translation.TranslationManager;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.registry.BundledBlockData;
import com.sk89q.worldedit.world.registry.BundledItemData;
import com.sk89q.worldedit.world.registry.LegacyMapper;
import org.apache.logging.log4j.Logger;
2020-07-14 02:50:59 +00:00
import javax.annotation.Nullable;
import javax.script.ScriptException;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.InvalidPathException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
2019-07-22 06:02:51 +00:00
2020-07-14 02:50:59 +00:00
import static com.google.common.base.Preconditions.checkArgument;
import static com.sk89q.worldedit.event.platform.Interaction.HIT;
import static com.sk89q.worldedit.event.platform.Interaction.OPEN;
/**
* The entry point and container for a working implementation of WorldEdit.
*
* <p>An instance handles event handling; block, mask, pattern, etc. registration;
* the management of sessions; the creation of {@link EditSession}s; and more.
* In order to use WorldEdit, at least one {@link Platform} must be registered
* with WorldEdit using {@link PlatformManager#register(Platform)} on the
* manager retrieved using {@link WorldEdit#getPlatformManager()}.</p>
*
* <p>An instance of WorldEdit can be retrieved using the static
* method {@link WorldEdit#getInstance()}, which is shared among all
* platforms within the same classloader hierarchy.</p>
*/
public final class WorldEdit {
/**
* This is for internal use only.
*/
public static final Logger logger = LogManagerCompat.getLogger();
private static final WorldEdit instance = new WorldEdit();
private static String version;
private final EventBus eventBus = new EventBus();
private final PlatformManager platformManager = new PlatformManager(this);
@Deprecated
private final EditSessionFactory editSessionFactory = new EditSessionFactory.EditSessionFactoryImpl();
private final SessionManager sessions = new SessionManager(this);
private final ListeningExecutorService executorService = MoreExecutors.listeningDecorator(EvenMoreExecutors.newBoundedCachedThreadPool(
0,
1,
20,
"WorldEdit Task Executor - %s"
));
private final Supervisor supervisor = new SimpleSupervisor();
Feature/propagate diff and object cleanup (#1190) * Feature/main/propagate diff annotations (#1187) * 25% done * More work * More work * 50% * More work * 75% * 100% & cleanup * Update adapters * Squish squash, applesauce commit 275ba9bd8424270b513009e24123df5d158b1990 Author: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Date: Sat Jul 17 01:10:20 2021 +0200 Update dependency com.comphenix.protocol:ProtocolLib to v4.7.0 (#1173) Co-authored-by: Renovate Bot <bot@renovateapp.com> commit 9fd898480419ebe7c57e59caf56b8cf34fef0aae Author: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Date: Sat Jul 17 01:09:29 2021 +0200 Update dependency org.checkerframework:checker-qual to v3.16.0 (#1184) Co-authored-by: Renovate Bot <bot@renovateapp.com> commit 861fb45e5c8d3c82a0d9fdb270f8ebe3ebbafac4 Author: dordsor21 <dordsor21@gmail.com> Date: Fri Jul 16 19:07:02 2021 +0100 Fix #1075 commit 420c45a29ac8a2cdd0110e9a9b225abf9e726a26 Author: dordsor21 <dordsor21@gmail.com> Date: Fri Jul 16 18:48:21 2021 +0100 Entity removal should be on the main thread as we're just passing through rather than doing chunk operations - Fixes #1164 - Not working: butcher/remove history commit 4d4db7dcd0c2ce99d59c32072247f0fc61fd27f6 Author: SirYwell <hannesgreule@outlook.de> Date: Fri Jul 16 17:52:44 2021 +0200 Make sure leaves category is loaded for heightmaps (fixes #1176) commit c98f6e4f37e256133bdee5179cb1c319d8c2c203 Author: dordsor21 <dordsor21@gmail.com> Date: Fri Jul 16 10:44:52 2021 +0100 Do not allow generation commands to generate outside selection commit 2485f5eccc875faff9730b5107e2559612042bad Author: dordsor21 <dordsor21@gmail.com> Date: Fri Jul 16 10:43:15 2021 +0100 EditSession needs to override some Extent methods to ensure block changes are correctly set through the various extents Fixes #1152 commit d9418ec8aefaa3f843f61babf87c40e01502a9e1 Author: dordsor21 <dordsor21@gmail.com> Date: Fri Jul 16 09:52:44 2021 +0100 Undo part of 41073bb1a0f73c58308cad13c9206ca16ed67831 Fixes #1178 * Update Upstream fb1fb84 Fixed typo and grammar * We don't support custom heights yet * Casing inconsistency * Address a few comments * Address comments * Don't refactor to AP classpath * Document annotation style * Refactoring & shade cleanup * Address a few comments * More work * Resolve comments not being resolved yet * Feature/main/propagate diff annotations (#1187) (#1194) * Remove beta package, fix history packages, move classes out of object package * Resolve comments not being resolved yet * Remove beta package, fix history packages, move classes out of object package Co-authored-by: NotMyFault <mc.cache@web.de> * brushes should be under brush * More refactoring - Filters/processors should be in the same place and are related to extents - Transforms are in `extent.transform` in upstream * Move history classes under history * Update adapters Co-authored-by: dordsor21 <dordsor21@gmail.com>
2021-07-23 15:48:51 +00:00
//FAWE start
private final LazyReference<TranslationManager> translationManager =
LazyReference.from(() -> new TranslationManager(
WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.CONFIGURATION).getResourceLoader()
));
Feature/propagate diff and object cleanup (#1190) * Feature/main/propagate diff annotations (#1187) * 25% done * More work * More work * 50% * More work * 75% * 100% & cleanup * Update adapters * Squish squash, applesauce commit 275ba9bd8424270b513009e24123df5d158b1990 Author: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Date: Sat Jul 17 01:10:20 2021 +0200 Update dependency com.comphenix.protocol:ProtocolLib to v4.7.0 (#1173) Co-authored-by: Renovate Bot <bot@renovateapp.com> commit 9fd898480419ebe7c57e59caf56b8cf34fef0aae Author: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Date: Sat Jul 17 01:09:29 2021 +0200 Update dependency org.checkerframework:checker-qual to v3.16.0 (#1184) Co-authored-by: Renovate Bot <bot@renovateapp.com> commit 861fb45e5c8d3c82a0d9fdb270f8ebe3ebbafac4 Author: dordsor21 <dordsor21@gmail.com> Date: Fri Jul 16 19:07:02 2021 +0100 Fix #1075 commit 420c45a29ac8a2cdd0110e9a9b225abf9e726a26 Author: dordsor21 <dordsor21@gmail.com> Date: Fri Jul 16 18:48:21 2021 +0100 Entity removal should be on the main thread as we're just passing through rather than doing chunk operations - Fixes #1164 - Not working: butcher/remove history commit 4d4db7dcd0c2ce99d59c32072247f0fc61fd27f6 Author: SirYwell <hannesgreule@outlook.de> Date: Fri Jul 16 17:52:44 2021 +0200 Make sure leaves category is loaded for heightmaps (fixes #1176) commit c98f6e4f37e256133bdee5179cb1c319d8c2c203 Author: dordsor21 <dordsor21@gmail.com> Date: Fri Jul 16 10:44:52 2021 +0100 Do not allow generation commands to generate outside selection commit 2485f5eccc875faff9730b5107e2559612042bad Author: dordsor21 <dordsor21@gmail.com> Date: Fri Jul 16 10:43:15 2021 +0100 EditSession needs to override some Extent methods to ensure block changes are correctly set through the various extents Fixes #1152 commit d9418ec8aefaa3f843f61babf87c40e01502a9e1 Author: dordsor21 <dordsor21@gmail.com> Date: Fri Jul 16 09:52:44 2021 +0100 Undo part of 41073bb1a0f73c58308cad13c9206ca16ed67831 Fixes #1178 * Update Upstream fb1fb84 Fixed typo and grammar * We don't support custom heights yet * Casing inconsistency * Address a few comments * Address comments * Don't refactor to AP classpath * Document annotation style * Refactoring & shade cleanup * Address a few comments * More work * Resolve comments not being resolved yet * Feature/main/propagate diff annotations (#1187) (#1194) * Remove beta package, fix history packages, move classes out of object package * Resolve comments not being resolved yet * Remove beta package, fix history packages, move classes out of object package Co-authored-by: NotMyFault <mc.cache@web.de> * brushes should be under brush * More refactoring - Filters/processors should be in the same place and are related to extents - Transforms are in `extent.transform` in upstream * Move history classes under history * Update adapters Co-authored-by: dordsor21 <dordsor21@gmail.com>
2021-07-23 15:48:51 +00:00
//FAWE end
private final BlockFactory blockFactory = new BlockFactory(this);
private final ItemFactory itemFactory = new ItemFactory(this);
private final MaskFactory maskFactory = new MaskFactory(this);
private final PatternFactory patternFactory = new PatternFactory(this);
private final TransformFactory transformFactory = new TransformFactory(this);
static {
getVersion();
}
private WorldEdit() {
eventBus.register(new SchematicsEventListener());
}
/**
* Gets the current instance of this class.
*
* <p>An instance will always be available, but no platform may yet be
* registered with WorldEdit, meaning that a number of operations
* may fail. However, event handlers can be registered.</p>
*
* @return an instance of WorldEdit.
*/
public static WorldEdit getInstance() {
return instance;
}
/**
* Get the platform manager, where platforms (that implement WorldEdit)
* can be registered and information about registered platforms can
* be queried.
*
* @return the platform manager
*/
public PlatformManager getPlatformManager() {
return platformManager;
}
/**
* Get the event bus for WorldEdit.
*
* <p>Event handlers can be registered on the event bus.</p>
*
* @return the event bus
*/
public EventBus getEventBus() {
return eventBus;
}
/**
* Get the supervisor. Internal, not for API use.
*
* @return the supervisor
*/
public Supervisor getSupervisor() {
return supervisor;
}
/**
* Get the executor service. Internal, not for API use.
*
* @return the executor service
*/
public ListeningExecutorService getExecutorService() {
return executorService;
}
/**
* Get the block factory from which new {@link BlockStateHolder}s can be
* constructed.
*
* @return the block factory
*/
public BlockFactory getBlockFactory() {
return blockFactory;
}
/**
* Get the item factory from which new {@link BaseItem}s can be
* constructed.
*
* @return the item factory
*/
public ItemFactory getItemFactory() {
return itemFactory;
}
/**
* Get the mask factory from which new {@link Mask}s
* can be constructed.
*
* @return the mask factory
*/
public MaskFactory getMaskFactory() {
return maskFactory;
}
/**
* Get the pattern factory from which new {@link Pattern}s
* can be constructed.
*
* @return the pattern factory
*/
public PatternFactory getPatternFactory() {
return patternFactory;
}
/**
* Get the transform factory from which new {@link ResettableExtent}s
* can be constructed.
*
* @return the transform factory
*/
public TransformFactory getTransformFactory() {
return transformFactory;
}
/**
* Return the session manager.
*
* @return the session manager
*/
public SessionManager getSessionManager() {
return sessions;
}
/**
* Return the translation manager.
*
* @return the translation manager
*/
public TranslationManager getTranslationManager() {
return translationManager.getValue();
}
/**
* Gets the path to a file. This method will check to see if the filename
* has valid characters and has an extension. It also prevents directory
* traversal exploits by checking the root directory and the file directory.
* On success, a {@code java.io.File} object will be returned.
*
* @param actor the actor
* @param dir sub-directory to look in
* @param filename filename (user-submitted)
* @param defaultExt append an extension if missing one, null to not use
* @param extensions list of extensions, null for any
* @return a file
* @throws FilenameException thrown if the filename is invalid
*/
public File getSafeSaveFile(Actor actor, File dir, String filename, String defaultExt, String... extensions) throws
FilenameException {
2019-08-06 15:29:09 +00:00
return getSafeFile(actor, dir, filename, defaultExt, extensions, true);
}
/**
* Gets the path to a file. This method will check to see if the filename
* has valid characters and has an extension. It also prevents directory
* traversal exploits by checking the root directory and the file directory.
* On success, a {@code java.io.File} object will be returned.
*
* @param actor the actor
* @param dir sub-directory to look in
* @param filename filename (user-submitted)
* @param defaultExt append an extension if missing one, null to not use
* @param extensions list of extensions, null for any
* @return a file
* @throws FilenameException thrown if the filename is invalid
*/
public File getSafeOpenFile(Actor actor, File dir, String filename, String defaultExt, String... extensions) throws
FilenameException {
2019-08-06 15:29:09 +00:00
return getSafeFile(actor, dir, filename, defaultExt, extensions, false);
}
/**
* Get a safe path to a file.
*
* @param actor the actor
* @param dir sub-directory to look in
* @param filename filename (user-submitted)
* @param defaultExt append an extension if missing one, null to not use
* @param extensions list of extensions, null for any
* @param isSave true if the purpose is for saving
* @return a file
* @throws FilenameException thrown if the filename is invalid
*/
private File getSafeFile(
@Nullable Actor actor,
File dir,
String filename,
String defaultExt,
String[] extensions,
boolean isSave
) throws FilenameException {
2020-07-14 02:50:59 +00:00
if (extensions != null && (extensions.length == 1 && extensions[0] == null)) {
extensions = null;
}
File f;
2019-08-06 15:29:09 +00:00
if (filename.equals("#") && actor != null) {
if (isSave) {
2019-08-06 15:29:09 +00:00
f = actor.openFileSaveDialog(extensions);
} else {
2019-08-06 15:29:09 +00:00
f = actor.openFileOpenDialog(extensions);
}
if (f == null) {
throw new FileSelectionAbortedException(Caption.of("worldedit.error.no-file-selected"));
}
} else {
List<String> exts = extensions == null ? ImmutableList.of(defaultExt) : Lists.asList(defaultExt, extensions);
f = getSafeFileWithExtensions(dir, filename, exts, isSave);
}
try {
Path filePath = Paths.get(f.toURI()).normalize();
Path dirPath = Paths.get(dir.toURI()).normalize();
boolean inDir = filePath.startsWith(dirPath);
Path existingParent = filePath;
do {
existingParent = existingParent.getParent();
} while (existingParent != null && !existingParent.toFile().exists());
boolean isSym = existingParent != null && !existingParent.toRealPath().equals(existingParent);
if (!inDir || (!getConfiguration().allowSymlinks && isSym)) {
throw new FilenameResolutionException(filename, Caption.of("worldedit.error.file-resolution.outside-root"));
}
return filePath.toFile();
} catch (IOException | InvalidPathException e) {
throw new FilenameResolutionException(filename, Caption.of("worldedit.error.file-resolution.resolve-failed"));
}
}
private File getSafeFileWithExtensions(File dir, String filename, List<String> exts, boolean isSave) throws
InvalidFilenameException {
if (isSave) {
// First is default, only use that.
if (exts.size() != 1) {
exts = exts.subList(0, 1);
}
} else {
int dot = filename.lastIndexOf('.');
if (dot < 0 || dot == filename.length() - 1) {
String currentExt = filename.substring(dot + 1);
if (exts.contains(currentExt) && checkFilename(filename)) {
File f = new File(dir, filename);
if (f.exists()) {
return f;
}
}
}
}
File result = null;
for (Iterator<String> iter = exts.iterator(); iter.hasNext() && (result == null || (!isSave && !result.exists())); ) {
result = getSafeFileWithExtension(dir, filename, iter.next());
}
if (result == null) {
throw new InvalidFilenameException(filename, Caption.of("worldedit.error.invalid-filename.invalid-characters"));
}
return result;
}
private File getSafeFileWithExtension(File dir, String filename, String extension) {
if (extension != null) {
int dot = filename.lastIndexOf('.');
if (dot < 0 || dot == filename.length() - 1 || !filename.substring(dot + 1).equalsIgnoreCase(extension)) {
filename += "." + extension;
}
}
if (!checkFilename(filename)) {
return null;
}
return new File(dir, filename);
}
private boolean checkFilename(String filename) {
return filename.matches("^[A-Za-z0-9_\\-./'$@~!%()\\[\\]+{},]+\\.[A-Za-z0-9]+$");
}
/**
* Load the bundled mappings.
*/
public void loadMappings() {
BundledBlockData.getInstance(); // Load block registry
BundledItemData.getInstance(); // Load item registry
LegacyMapper.getInstance(); // Load item registry
}
/**
* Checks to see if the specified radius is within bounds.
*
* @param radius the radius
2020-07-14 02:50:59 +00:00
* @throws MaxRadiusException if the radius is bigger than the configured radius
*/
public void checkMaxRadius(double radius) throws MaxRadiusException {
if (getConfiguration().maxRadius > 0 && radius > getConfiguration().maxRadius) {
throw new MaxRadiusException();
}
}
/**
* Checks to see if the specified brush radius is within bounds.
*
* @param radius the radius
2020-07-14 02:50:59 +00:00
* @throws MaxBrushRadiusException if the radius is bigger than the configured radius
*/
public void checkMaxBrushRadius(double radius) throws MaxBrushRadiusException {
if (getConfiguration().maxBrushRadius > 0 && radius > getConfiguration().maxBrushRadius) {
throw new MaxBrushRadiusException();
}
}
Feature/propagate diff and object cleanup (#1190) * Feature/main/propagate diff annotations (#1187) * 25% done * More work * More work * 50% * More work * 75% * 100% & cleanup * Update adapters * Squish squash, applesauce commit 275ba9bd8424270b513009e24123df5d158b1990 Author: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Date: Sat Jul 17 01:10:20 2021 +0200 Update dependency com.comphenix.protocol:ProtocolLib to v4.7.0 (#1173) Co-authored-by: Renovate Bot <bot@renovateapp.com> commit 9fd898480419ebe7c57e59caf56b8cf34fef0aae Author: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Date: Sat Jul 17 01:09:29 2021 +0200 Update dependency org.checkerframework:checker-qual to v3.16.0 (#1184) Co-authored-by: Renovate Bot <bot@renovateapp.com> commit 861fb45e5c8d3c82a0d9fdb270f8ebe3ebbafac4 Author: dordsor21 <dordsor21@gmail.com> Date: Fri Jul 16 19:07:02 2021 +0100 Fix #1075 commit 420c45a29ac8a2cdd0110e9a9b225abf9e726a26 Author: dordsor21 <dordsor21@gmail.com> Date: Fri Jul 16 18:48:21 2021 +0100 Entity removal should be on the main thread as we're just passing through rather than doing chunk operations - Fixes #1164 - Not working: butcher/remove history commit 4d4db7dcd0c2ce99d59c32072247f0fc61fd27f6 Author: SirYwell <hannesgreule@outlook.de> Date: Fri Jul 16 17:52:44 2021 +0200 Make sure leaves category is loaded for heightmaps (fixes #1176) commit c98f6e4f37e256133bdee5179cb1c319d8c2c203 Author: dordsor21 <dordsor21@gmail.com> Date: Fri Jul 16 10:44:52 2021 +0100 Do not allow generation commands to generate outside selection commit 2485f5eccc875faff9730b5107e2559612042bad Author: dordsor21 <dordsor21@gmail.com> Date: Fri Jul 16 10:43:15 2021 +0100 EditSession needs to override some Extent methods to ensure block changes are correctly set through the various extents Fixes #1152 commit d9418ec8aefaa3f843f61babf87c40e01502a9e1 Author: dordsor21 <dordsor21@gmail.com> Date: Fri Jul 16 09:52:44 2021 +0100 Undo part of 41073bb1a0f73c58308cad13c9206ca16ed67831 Fixes #1178 * Update Upstream fb1fb84 Fixed typo and grammar * We don't support custom heights yet * Casing inconsistency * Address a few comments * Address comments * Don't refactor to AP classpath * Document annotation style * Refactoring & shade cleanup * Address a few comments * More work * Resolve comments not being resolved yet * Feature/main/propagate diff annotations (#1187) (#1194) * Remove beta package, fix history packages, move classes out of object package * Resolve comments not being resolved yet * Remove beta package, fix history packages, move classes out of object package Co-authored-by: NotMyFault <mc.cache@web.de> * brushes should be under brush * More refactoring - Filters/processors should be in the same place and are related to extents - Transforms are in `extent.transform` in upstream * Move history classes under history * Update adapters Co-authored-by: dordsor21 <dordsor21@gmail.com>
2021-07-23 15:48:51 +00:00
//FAWE start
public void checkMaxBrushRadius(Expression radius) throws MaxBrushRadiusException {
double val = radius.evaluate();
2021-05-22 15:33:42 +00:00
checkArgument(val >= 0, "Radius must be a positive number.");
if (getConfiguration().maxBrushRadius > 0) {
2019-11-20 00:11:54 +00:00
if (val > getConfiguration().maxBrushRadius) {
throw new MaxBrushRadiusException();
}
}
}
Feature/propagate diff and object cleanup (#1190) * Feature/main/propagate diff annotations (#1187) * 25% done * More work * More work * 50% * More work * 75% * 100% & cleanup * Update adapters * Squish squash, applesauce commit 275ba9bd8424270b513009e24123df5d158b1990 Author: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Date: Sat Jul 17 01:10:20 2021 +0200 Update dependency com.comphenix.protocol:ProtocolLib to v4.7.0 (#1173) Co-authored-by: Renovate Bot <bot@renovateapp.com> commit 9fd898480419ebe7c57e59caf56b8cf34fef0aae Author: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Date: Sat Jul 17 01:09:29 2021 +0200 Update dependency org.checkerframework:checker-qual to v3.16.0 (#1184) Co-authored-by: Renovate Bot <bot@renovateapp.com> commit 861fb45e5c8d3c82a0d9fdb270f8ebe3ebbafac4 Author: dordsor21 <dordsor21@gmail.com> Date: Fri Jul 16 19:07:02 2021 +0100 Fix #1075 commit 420c45a29ac8a2cdd0110e9a9b225abf9e726a26 Author: dordsor21 <dordsor21@gmail.com> Date: Fri Jul 16 18:48:21 2021 +0100 Entity removal should be on the main thread as we're just passing through rather than doing chunk operations - Fixes #1164 - Not working: butcher/remove history commit 4d4db7dcd0c2ce99d59c32072247f0fc61fd27f6 Author: SirYwell <hannesgreule@outlook.de> Date: Fri Jul 16 17:52:44 2021 +0200 Make sure leaves category is loaded for heightmaps (fixes #1176) commit c98f6e4f37e256133bdee5179cb1c319d8c2c203 Author: dordsor21 <dordsor21@gmail.com> Date: Fri Jul 16 10:44:52 2021 +0100 Do not allow generation commands to generate outside selection commit 2485f5eccc875faff9730b5107e2559612042bad Author: dordsor21 <dordsor21@gmail.com> Date: Fri Jul 16 10:43:15 2021 +0100 EditSession needs to override some Extent methods to ensure block changes are correctly set through the various extents Fixes #1152 commit d9418ec8aefaa3f843f61babf87c40e01502a9e1 Author: dordsor21 <dordsor21@gmail.com> Date: Fri Jul 16 09:52:44 2021 +0100 Undo part of 41073bb1a0f73c58308cad13c9206ca16ed67831 Fixes #1178 * Update Upstream fb1fb84 Fixed typo and grammar * We don't support custom heights yet * Casing inconsistency * Address a few comments * Address comments * Don't refactor to AP classpath * Document annotation style * Refactoring & shade cleanup * Address a few comments * More work * Resolve comments not being resolved yet * Feature/main/propagate diff annotations (#1187) (#1194) * Remove beta package, fix history packages, move classes out of object package * Resolve comments not being resolved yet * Remove beta package, fix history packages, move classes out of object package Co-authored-by: NotMyFault <mc.cache@web.de> * brushes should be under brush * More refactoring - Filters/processors should be in the same place and are related to extents - Transforms are in `extent.transform` in upstream * Move history classes under history * Update adapters Co-authored-by: dordsor21 <dordsor21@gmail.com>
2021-07-23 15:48:51 +00:00
//FAWE end
/**
* Get a file relative to the defined working directory. If the specified
* path is absolute, then the working directory is not used.
*
* @param path the subpath under the working directory
* @return a working directory
* @deprecated Use {@link WorldEdit#getWorkingDirectoryPath(String)} instead
*/
@Deprecated
public File getWorkingDirectoryFile(String path) {
return getWorkingDirectoryPath(path).toFile();
}
/**
* Get a file relative to the defined working directory. If the specified
* path is absolute, then the working directory is not used.
*
* @param path the subpath under the working directory
* @return a working directory
*/
public Path getWorkingDirectoryPath(String path) {
Path p = Paths.get(path);
if (p.isAbsolute()) {
return p;
}
return getConfiguration().getWorkingDirectoryPath().resolve(path);
}
Feature/propagate diff and object cleanup (#1190) * Feature/main/propagate diff annotations (#1187) * 25% done * More work * More work * 50% * More work * 75% * 100% & cleanup * Update adapters * Squish squash, applesauce commit 275ba9bd8424270b513009e24123df5d158b1990 Author: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Date: Sat Jul 17 01:10:20 2021 +0200 Update dependency com.comphenix.protocol:ProtocolLib to v4.7.0 (#1173) Co-authored-by: Renovate Bot <bot@renovateapp.com> commit 9fd898480419ebe7c57e59caf56b8cf34fef0aae Author: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Date: Sat Jul 17 01:09:29 2021 +0200 Update dependency org.checkerframework:checker-qual to v3.16.0 (#1184) Co-authored-by: Renovate Bot <bot@renovateapp.com> commit 861fb45e5c8d3c82a0d9fdb270f8ebe3ebbafac4 Author: dordsor21 <dordsor21@gmail.com> Date: Fri Jul 16 19:07:02 2021 +0100 Fix #1075 commit 420c45a29ac8a2cdd0110e9a9b225abf9e726a26 Author: dordsor21 <dordsor21@gmail.com> Date: Fri Jul 16 18:48:21 2021 +0100 Entity removal should be on the main thread as we're just passing through rather than doing chunk operations - Fixes #1164 - Not working: butcher/remove history commit 4d4db7dcd0c2ce99d59c32072247f0fc61fd27f6 Author: SirYwell <hannesgreule@outlook.de> Date: Fri Jul 16 17:52:44 2021 +0200 Make sure leaves category is loaded for heightmaps (fixes #1176) commit c98f6e4f37e256133bdee5179cb1c319d8c2c203 Author: dordsor21 <dordsor21@gmail.com> Date: Fri Jul 16 10:44:52 2021 +0100 Do not allow generation commands to generate outside selection commit 2485f5eccc875faff9730b5107e2559612042bad Author: dordsor21 <dordsor21@gmail.com> Date: Fri Jul 16 10:43:15 2021 +0100 EditSession needs to override some Extent methods to ensure block changes are correctly set through the various extents Fixes #1152 commit d9418ec8aefaa3f843f61babf87c40e01502a9e1 Author: dordsor21 <dordsor21@gmail.com> Date: Fri Jul 16 09:52:44 2021 +0100 Undo part of 41073bb1a0f73c58308cad13c9206ca16ed67831 Fixes #1178 * Update Upstream fb1fb84 Fixed typo and grammar * We don't support custom heights yet * Casing inconsistency * Address a few comments * Address comments * Don't refactor to AP classpath * Document annotation style * Refactoring & shade cleanup * Address a few comments * More work * Resolve comments not being resolved yet * Feature/main/propagate diff annotations (#1187) (#1194) * Remove beta package, fix history packages, move classes out of object package * Resolve comments not being resolved yet * Remove beta package, fix history packages, move classes out of object package Co-authored-by: NotMyFault <mc.cache@web.de> * brushes should be under brush * More refactoring - Filters/processors should be in the same place and are related to extents - Transforms are in `extent.transform` in upstream * Move history classes under history * Update adapters Co-authored-by: dordsor21 <dordsor21@gmail.com>
2021-07-23 15:48:51 +00:00
//FAWE start
/**
* Gets the path to the folder in which schematics are saved by default
*
* @return Path to the schematic folder
*/
public Path getSchematicsFolderPath() {
return getWorkingDirectoryPath(getConfiguration().saveDir);
}
Feature/propagate diff and object cleanup (#1190) * Feature/main/propagate diff annotations (#1187) * 25% done * More work * More work * 50% * More work * 75% * 100% & cleanup * Update adapters * Squish squash, applesauce commit 275ba9bd8424270b513009e24123df5d158b1990 Author: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Date: Sat Jul 17 01:10:20 2021 +0200 Update dependency com.comphenix.protocol:ProtocolLib to v4.7.0 (#1173) Co-authored-by: Renovate Bot <bot@renovateapp.com> commit 9fd898480419ebe7c57e59caf56b8cf34fef0aae Author: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Date: Sat Jul 17 01:09:29 2021 +0200 Update dependency org.checkerframework:checker-qual to v3.16.0 (#1184) Co-authored-by: Renovate Bot <bot@renovateapp.com> commit 861fb45e5c8d3c82a0d9fdb270f8ebe3ebbafac4 Author: dordsor21 <dordsor21@gmail.com> Date: Fri Jul 16 19:07:02 2021 +0100 Fix #1075 commit 420c45a29ac8a2cdd0110e9a9b225abf9e726a26 Author: dordsor21 <dordsor21@gmail.com> Date: Fri Jul 16 18:48:21 2021 +0100 Entity removal should be on the main thread as we're just passing through rather than doing chunk operations - Fixes #1164 - Not working: butcher/remove history commit 4d4db7dcd0c2ce99d59c32072247f0fc61fd27f6 Author: SirYwell <hannesgreule@outlook.de> Date: Fri Jul 16 17:52:44 2021 +0200 Make sure leaves category is loaded for heightmaps (fixes #1176) commit c98f6e4f37e256133bdee5179cb1c319d8c2c203 Author: dordsor21 <dordsor21@gmail.com> Date: Fri Jul 16 10:44:52 2021 +0100 Do not allow generation commands to generate outside selection commit 2485f5eccc875faff9730b5107e2559612042bad Author: dordsor21 <dordsor21@gmail.com> Date: Fri Jul 16 10:43:15 2021 +0100 EditSession needs to override some Extent methods to ensure block changes are correctly set through the various extents Fixes #1152 commit d9418ec8aefaa3f843f61babf87c40e01502a9e1 Author: dordsor21 <dordsor21@gmail.com> Date: Fri Jul 16 09:52:44 2021 +0100 Undo part of 41073bb1a0f73c58308cad13c9206ca16ed67831 Fixes #1178 * Update Upstream fb1fb84 Fixed typo and grammar * We don't support custom heights yet * Casing inconsistency * Address a few comments * Address comments * Don't refactor to AP classpath * Document annotation style * Refactoring & shade cleanup * Address a few comments * More work * Resolve comments not being resolved yet * Feature/main/propagate diff annotations (#1187) (#1194) * Remove beta package, fix history packages, move classes out of object package * Resolve comments not being resolved yet * Remove beta package, fix history packages, move classes out of object package Co-authored-by: NotMyFault <mc.cache@web.de> * brushes should be under brush * More refactoring - Filters/processors should be in the same place and are related to extents - Transforms are in `extent.transform` in upstream * Move history classes under history * Update adapters Co-authored-by: dordsor21 <dordsor21@gmail.com>
2021-07-23 15:48:51 +00:00
//FAWE end
/**
* Get the direction vector for a player's direction.
*
* @param player the player
* @param dirStr the direction string
* @return a direction vector
* @throws UnknownDirectionException thrown if the direction is not known, or a relative direction is used with null player
*/
public BlockVector3 getDirection(@Nullable Player player, String dirStr) throws UnknownDirectionException {
dirStr = dirStr.toLowerCase(Locale.ROOT);
final Direction dir = getPlayerDirection(player, dirStr);
if (dir.isUpright() || dir.isCardinal()) {
return dir.toBlockVector();
} else {
throw new UnknownDirectionException(dir.name());
}
}
/**
* Get the direction vector for a player's direction.
*
* @param player the player
* @param dirStr the direction string
* @return a direction vector
* @throws UnknownDirectionException thrown if the direction is not known, or a relative direction is used with null player
*/
public BlockVector3 getDiagonalDirection(@Nullable Player player, String dirStr) throws UnknownDirectionException {
dirStr = dirStr.toLowerCase(Locale.ROOT);
final Direction dir = getPlayerDirection(player, dirStr);
if (dir.isCardinal() || dir.isOrdinal() || dir.isUpright()) {
return dir.toBlockVector();
}
throw new UnknownDirectionException(dir.name());
}
2020-07-14 02:50:59 +00:00
private static final Map<String, Direction> NAME_TO_DIRECTION_MAP;
static {
SetMultimap<Direction, String> directionNames = HashMultimap.create();
for (Direction direction : Direction.valuesOf(
Direction.Flag.CARDINAL | Direction.Flag.UPRIGHT
2020-07-14 02:50:59 +00:00
)) {
String name = direction.name().toLowerCase(Locale.ROOT);
for (int i = 1; i <= name.length(); i++) {
directionNames.put(direction, name.substring(0, i));
}
}
ImmutableMap.Builder<String, Direction> nameToDirectionMap = ImmutableMap.builder();
for (Direction direction : directionNames.keySet()) {
directionNames.get(direction).forEach(name ->
nameToDirectionMap.put(name, direction)
2020-07-14 02:50:59 +00:00
);
}
for (Direction direction : ImmutableList.of(Direction.NORTH, Direction.SOUTH)) {
for (Direction diagonal : ImmutableList.of(Direction.WEST, Direction.EAST)) {
for (String dirName : directionNames.get(direction)) {
for (String diagName : directionNames.get(diagonal)) {
nameToDirectionMap.put(dirName + diagName, Direction.valueOf(
direction.name() + diagonal.name()
2020-07-14 02:50:59 +00:00
));
}
}
}
}
NAME_TO_DIRECTION_MAP = nameToDirectionMap.build();
}
/**
* Get the direction vector for a player's direction.
*
* @param player the player
* @param dirStr the direction string
* @return a direction enum value
* @throws UnknownDirectionException thrown if the direction is not known, or a relative direction is used with null player
*/
private Direction getPlayerDirection(@Nullable Player player, String dirStr) throws UnknownDirectionException {
2020-07-14 02:50:59 +00:00
Direction byName = NAME_TO_DIRECTION_MAP.get(dirStr);
if (byName != null) {
return byName;
}
switch (dirStr) {
case "m":
case "me":
case "f":
case "forward":
return getDirectionRelative(player, 0);
case "b":
case "back":
Direction dir = getDirectionRelative(player, 180);
if (dir.isUpright()) {
// If this is an upright direction, flip it.
dir = dir == Direction.UP ? Direction.DOWN : Direction.UP;
}
return dir;
2020-07-14 02:50:59 +00:00
case "l":
case "left":
return getDirectionRelative(player, -90);
case "r":
case "right":
return getDirectionRelative(player, 90);
default:
throw new UnknownDirectionException(dirStr);
}
}
private Direction getDirectionRelative(Player player, int yawOffset) throws UnknownDirectionException {
if (player != null) {
return player.getCardinalDirection(yawOffset);
}
throw new UnknownDirectionException("Only a player can use relative directions");
}
/**
* Flush a block bag's changes to a player.
*
* @param actor the actor
* @param editSession the edit session
*/
public void flushBlockBag(Actor actor, EditSession editSession) {
BlockBag blockBag = editSession.getBlockBag();
if (blockBag != null) {
blockBag.flushChanges();
}
Map<BlockType, Integer> missingBlocks = editSession.popMissingBlocks();
if (!missingBlocks.isEmpty()) {
TextComponent.Builder str = TextComponent.builder();
str.append("Missing these blocks: ");
int size = missingBlocks.size();
int i = 0;
for (Map.Entry<BlockType, Integer> blockTypeIntegerEntry : missingBlocks.entrySet()) {
str.append((blockTypeIntegerEntry.getKey()).getRichName());
str.append(" [Amt: ")
.append(String.valueOf(blockTypeIntegerEntry.getValue()))
.append("]");
++i;
if (i != size) {
str.append(", ");
}
}
actor.printError(str.build());
}
}
/**
* Called on arm swing.
*
* @param player the player
* @return true if the swing was handled
*/
public boolean handleArmSwing(Player player) {
PlayerInputEvent event = new PlayerInputEvent(player, InputType.PRIMARY);
getEventBus().post(event);
return event.isCancelled();
}
/**
* Called on right click (not on a block).
*
* @param player the player
* @return true if the right click was handled
*/
public boolean handleRightClick(Player player) {
PlayerInputEvent event = new PlayerInputEvent(player, InputType.SECONDARY);
getEventBus().post(event);
return event.isCancelled();
}
/**
* Called on right click.
*
* @param player the player
* @param clicked the clicked block
* @return false if you want the action to go through
*/
2020-07-14 02:50:59 +00:00
@Deprecated
public boolean handleBlockRightClick(Player player, Location clicked) {
2020-07-14 02:50:59 +00:00
return handleBlockRightClick(player, clicked, null);
}
/**
* Called on right click.
*
* @param player the player
2020-07-14 02:50:59 +00:00
* @param clicked the clicked block
* @param face The clicked face
2020-07-14 02:50:59 +00:00
* @return false if you want the action to go through
*/
public boolean handleBlockRightClick(Player player, Location clicked, @Nullable Direction face) {
BlockInteractEvent event = new BlockInteractEvent(player, clicked, face, OPEN);
getEventBus().post(event);
return event.isCancelled();
}
/**
* Called on left click.
*
* @param player the player
* @param clicked the clicked block
* @return false if you want the action to go through
*/
2020-07-14 02:50:59 +00:00
@Deprecated
public boolean handleBlockLeftClick(Player player, Location clicked) {
2020-07-14 02:50:59 +00:00
return handleBlockLeftClick(player, clicked, null);
}
/**
* Called on left click.
*
* @param player the player
2020-07-14 02:50:59 +00:00
* @param clicked the clicked block
* @param face The clicked face
2020-07-14 02:50:59 +00:00
* @return false if you want the action to go through
*/
public boolean handleBlockLeftClick(Player player, Location clicked, @Nullable Direction face) {
BlockInteractEvent event = new BlockInteractEvent(player, clicked, face, HIT);
getEventBus().post(event);
return event.isCancelled();
}
/**
* Executes a WorldEdit script.
*
* @param player the player
* @param f the script file to execute
* @param args arguments for the script
2019-11-01 12:33:31 +00:00
* @throws WorldEditException if something goes wrong
*/
2019-08-26 04:45:03 +00:00
public void runScript(Player player, File f, String[] args) throws WorldEditException {
String filename = f.getPath();
int index = filename.lastIndexOf('.');
String ext = filename.substring(index + 1);
if (!ext.equalsIgnoreCase("js")) {
player.print(Caption.of("worldedit.script.unsupported"));
2019-08-26 04:45:03 +00:00
return;
}
String script;
try {
InputStream file;
if (!f.exists()) {
file = WorldEdit.class.getResourceAsStream("craftscripts/" + filename);
if (file == null) {
player.print(Caption.of("worldedit.script.file-not-found", TextComponent.of(filename)));
2019-08-26 04:45:03 +00:00
return;
}
} else {
file = new FileInputStream(f);
}
DataInputStream in = new DataInputStream(file);
byte[] data = new byte[in.available()];
in.readFully(data);
in.close();
script = new String(data, 0, data.length, StandardCharsets.UTF_8);
} catch (IOException e) {
player.print(Caption.of("worldedit.script.read-error", TextComponent.of(e.getMessage())));
2019-08-26 04:45:03 +00:00
return;
}
LocalSession session = getSessionManager().get(player);
CraftScriptContext scriptContext = new CraftScriptContext(
this,
getPlatformManager().queryCapability(Capability.USER_COMMANDS),
getConfiguration(),
session,
player,
args
);
CraftScriptEngine engine;
try {
engine = new RhinoCraftScriptEngine();
} catch (NoClassDefFoundError ignored) {
player.print(Caption.of("worldedit.script.no-script-engine"));
2019-08-26 04:45:03 +00:00
return;
}
engine.setTimeLimit(getConfiguration().scriptTimeout);
Map<String, Object> vars = new HashMap<>();
vars.put("argv", args);
vars.put("context", scriptContext);
vars.put("player", player);
try {
2019-08-26 04:45:03 +00:00
engine.evaluate(script, filename, vars);
} catch (ScriptException e) {
2020-07-14 02:50:59 +00:00
// non-exceptional return check
if (!(Throwables.getRootCause(e) instanceof ReturnException)) {
player.print(Caption.of("worldedit.script.failed", TextComponent.of(e.getMessage())));
2020-07-14 02:50:59 +00:00
logger.warn("Failed to execute script", e);
}
} catch (NumberFormatException | WorldEditException e) {
throw e;
} catch (Throwable e) {
player.print(Caption.of("worldedit.script.failed-console", TextComponent.of(e.getClass().getCanonicalName())));
logger.warn("Failed to execute script", e);
} finally {
for (EditSession editSession : scriptContext.getEditSessions()) {
Feature/propagate diff and object cleanup (#1190) * Feature/main/propagate diff annotations (#1187) * 25% done * More work * More work * 50% * More work * 75% * 100% & cleanup * Update adapters * Squish squash, applesauce commit 275ba9bd8424270b513009e24123df5d158b1990 Author: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Date: Sat Jul 17 01:10:20 2021 +0200 Update dependency com.comphenix.protocol:ProtocolLib to v4.7.0 (#1173) Co-authored-by: Renovate Bot <bot@renovateapp.com> commit 9fd898480419ebe7c57e59caf56b8cf34fef0aae Author: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Date: Sat Jul 17 01:09:29 2021 +0200 Update dependency org.checkerframework:checker-qual to v3.16.0 (#1184) Co-authored-by: Renovate Bot <bot@renovateapp.com> commit 861fb45e5c8d3c82a0d9fdb270f8ebe3ebbafac4 Author: dordsor21 <dordsor21@gmail.com> Date: Fri Jul 16 19:07:02 2021 +0100 Fix #1075 commit 420c45a29ac8a2cdd0110e9a9b225abf9e726a26 Author: dordsor21 <dordsor21@gmail.com> Date: Fri Jul 16 18:48:21 2021 +0100 Entity removal should be on the main thread as we're just passing through rather than doing chunk operations - Fixes #1164 - Not working: butcher/remove history commit 4d4db7dcd0c2ce99d59c32072247f0fc61fd27f6 Author: SirYwell <hannesgreule@outlook.de> Date: Fri Jul 16 17:52:44 2021 +0200 Make sure leaves category is loaded for heightmaps (fixes #1176) commit c98f6e4f37e256133bdee5179cb1c319d8c2c203 Author: dordsor21 <dordsor21@gmail.com> Date: Fri Jul 16 10:44:52 2021 +0100 Do not allow generation commands to generate outside selection commit 2485f5eccc875faff9730b5107e2559612042bad Author: dordsor21 <dordsor21@gmail.com> Date: Fri Jul 16 10:43:15 2021 +0100 EditSession needs to override some Extent methods to ensure block changes are correctly set through the various extents Fixes #1152 commit d9418ec8aefaa3f843f61babf87c40e01502a9e1 Author: dordsor21 <dordsor21@gmail.com> Date: Fri Jul 16 09:52:44 2021 +0100 Undo part of 41073bb1a0f73c58308cad13c9206ca16ed67831 Fixes #1178 * Update Upstream fb1fb84 Fixed typo and grammar * We don't support custom heights yet * Casing inconsistency * Address a few comments * Address comments * Don't refactor to AP classpath * Document annotation style * Refactoring & shade cleanup * Address a few comments * More work * Resolve comments not being resolved yet * Feature/main/propagate diff annotations (#1187) (#1194) * Remove beta package, fix history packages, move classes out of object package * Resolve comments not being resolved yet * Remove beta package, fix history packages, move classes out of object package Co-authored-by: NotMyFault <mc.cache@web.de> * brushes should be under brush * More refactoring - Filters/processors should be in the same place and are related to extents - Transforms are in `extent.transform` in upstream * Move history classes under history * Update adapters Co-authored-by: dordsor21 <dordsor21@gmail.com>
2021-07-23 15:48:51 +00:00
editSession.close();
session.remember(editSession);
}
}
}
/**
* Get Worldedit's configuration.
*
* @return a configuration
*/
public LocalConfiguration getConfiguration() {
return getPlatformManager().getConfiguration();
}
/**
* Get a factory for {@link EditSession}s.
*
* @deprecated Use {@link #newEditSessionBuilder()} instead. See {@link EditSessionFactory} for details.
*/
@Deprecated
public EditSessionFactory getEditSessionFactory() {
return editSessionFactory;
}
/**
* Create a builder for {@link EditSession}s.
*/
public EditSessionBuilder newEditSessionBuilder() {
return new EditSessionBuilder(eventBus);
}
/**
* Shorthand for {@code newEditSessionBuilder().world(world).build()}.
*
* @param world the world
* @return the new {@link EditSession}
*/
public EditSession newEditSession(@Nullable World world) {
return newEditSessionBuilder().world(world).build();
}
/**
* Shorthand for {@code newEditSessionBuilder().locatableActor(locatableActor).build()}.
*
* @param locatableActor the actor
* @return the new {@link EditSession}
*/
public <A extends Actor & Locatable> EditSession newEditSession(A locatableActor) {
return newEditSessionBuilder().locatableActor(locatableActor).build();
}
/**
* Get the version.
*
* @return the version of WorldEdit
*/
public static String getVersion() {
if (version != null) {
return version;
}
WorldEditManifest manifest = WorldEditManifest.load();
return version = manifest.getWorldEditVersion();
}
}