From 72a4bb355263139c6263f088fa81161496fd545c Mon Sep 17 00:00:00 2001 From: MattBDev <4009945+MattBDev@users.noreply.github.com> Date: Tue, 18 Aug 2020 13:43:18 -0400 Subject: [PATCH] Upstream merge of the scripting package --- .../InsufficientArgumentsException.java | 24 ++++--- .../scripting/CraftScriptContext.java | 62 +++++++++++-------- .../scripting/CraftScriptEngine.java | 18 +++--- .../scripting/CraftScriptEnvironment.java | 18 +++--- .../MinecraftHidingClassShutter.java | 18 +++--- .../scripting/RhinoContextFactory.java | 18 +++--- .../scripting/RhinoCraftScriptEngine.java | 18 +++--- 7 files changed, 97 insertions(+), 79 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/InsufficientArgumentsException.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/InsufficientArgumentsException.java index 796b8e645..666d582fb 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/InsufficientArgumentsException.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/InsufficientArgumentsException.java @@ -3,28 +3,34 @@ * Copyright (C) sk89q * 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 Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or + * 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 Lesser General Public License - * for more details. + * 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 Lesser General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package com.sk89q.worldedit.command; import com.sk89q.worldedit.WorldEditException; +import com.sk89q.worldedit.util.formatting.text.Component; public class InsufficientArgumentsException extends WorldEditException { + @Deprecated public InsufficientArgumentsException(String error) { super(error); } + public InsufficientArgumentsException(Component error) { + super(error); + } + } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/scripting/CraftScriptContext.java b/worldedit-core/src/main/java/com/sk89q/worldedit/scripting/CraftScriptContext.java index 9184e805f..c53401c25 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/scripting/CraftScriptContext.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/scripting/CraftScriptContext.java @@ -3,36 +3,38 @@ * Copyright (C) sk89q * 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 Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or + * 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 Lesser General Public License - * for more details. + * 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 Lesser General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package com.sk89q.worldedit.scripting; -import com.sk89q.worldedit.DisallowedItemException; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.LocalSession; -import com.sk89q.worldedit.UnknownItemException; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.command.InsufficientArgumentsException; import com.sk89q.worldedit.entity.Player; +import com.sk89q.worldedit.extension.input.DisallowedUsageException; +import com.sk89q.worldedit.extension.input.NoMatchException; import com.sk89q.worldedit.extension.input.ParserContext; import com.sk89q.worldedit.extension.platform.Platform; import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.internal.expression.invoke.ReturnException; import com.sk89q.worldedit.session.request.Request; import com.sk89q.worldedit.util.formatting.text.TextComponent; +import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; import com.sk89q.worldedit.util.io.file.FilenameException; import com.sk89q.worldedit.world.block.BaseBlock; @@ -47,8 +49,8 @@ import java.util.Set; */ public class CraftScriptContext extends CraftScriptEnvironment { - private List editSessions = new ArrayList<>(); - private String[] args; + private final List editSessions = new ArrayList<>(); + private final String[] args; public CraftScriptContext(WorldEdit controller, Platform server, LocalConfiguration config, @@ -142,23 +144,33 @@ public class CraftScriptContext extends CraftScriptEnvironment { * @param min a number of arguments * @param max -1 for no maximum * @param usage usage string - * @throws InsufficientArgumentsException + * @throws InsufficientArgumentsException if the arguments are not "sufficiently" good */ public void checkArgs(int min, int max, String usage) throws InsufficientArgumentsException { if (args.length <= min || (max != -1 && args.length - 1 > max)) { - throw new InsufficientArgumentsException("Usage: " + usage); + throw new InsufficientArgumentsException(TranslatableComponent.of("worldedit.error.incorrect-usage", TextComponent.of(usage))); } } + /** + * Immediately terminate execution of the script, but without a failure message. + * + * @implNote This exits by throwing an exception, which if caught will prevent + * the script from exiting + */ + public void exit() { + throw new ReturnException(null); + } + /** * Get an item from an item name or an item ID number. * * @param input input to parse * @param allAllowed true to ignore blacklists * @return a block - * @throws UnknownItemException - * @throws DisallowedItemException + * @throws NoMatchException if no block was found + * @throws DisallowedUsageException if the block is disallowed */ public BaseBlock getBlock(String input, boolean allAllowed) throws WorldEditException { ParserContext context = new ParserContext(); @@ -176,8 +188,8 @@ public class CraftScriptContext extends CraftScriptEnvironment { * * @param id the type Id * @return a block - * @throws UnknownItemException - * @throws DisallowedItemException + * @throws NoMatchException if no block was found + * @throws DisallowedUsageException if the block is disallowed */ public BaseBlock getBlock(String id) throws WorldEditException { return getBlock(id, false); @@ -188,8 +200,8 @@ public class CraftScriptContext extends CraftScriptEnvironment { * * @param list the input * @return pattern - * @throws UnknownItemException - * @throws DisallowedItemException + * @throws NoMatchException if the pattern was invalid + * @throws DisallowedUsageException if the block is disallowed */ public Pattern getBlockPattern(String list) throws WorldEditException { ParserContext context = new ParserContext(); @@ -205,8 +217,8 @@ public class CraftScriptContext extends CraftScriptEnvironment { * @param list a list * @param allBlocksAllowed true if all blocks are allowed * @return set - * @throws UnknownItemException - * @throws DisallowedItemException + * @throws NoMatchException if the blocks couldn't be found + * @throws DisallowedUsageException if the block is disallowed */ public Set getBlocks(String list, boolean allBlocksAllowed) throws WorldEditException { ParserContext context = new ParserContext(); @@ -231,7 +243,7 @@ public class CraftScriptContext extends CraftScriptEnvironment { * @param defaultExt default extension to append if there is none * @param exts list of extensions for file open dialog, null for no filter * @return a file - * @throws FilenameException + * @throws FilenameException if there is a problem with the name of the file */ public File getSafeOpenFile(String folder, String filename, String defaultExt, String... exts) throws FilenameException { File dir = controller.getWorkingDirectoryFile(folder); @@ -252,7 +264,7 @@ public class CraftScriptContext extends CraftScriptEnvironment { * @param defaultExt default extension to append if there is none * @param exts list of extensions for file save dialog, null for no filter * @return a file - * @throws FilenameException + * @throws FilenameException if there is a problem with the name of the file */ public File getSafeSaveFile(String folder, String filename, String defaultExt, String... exts) throws FilenameException { File dir = controller.getWorkingDirectoryFile(folder); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/scripting/CraftScriptEngine.java b/worldedit-core/src/main/java/com/sk89q/worldedit/scripting/CraftScriptEngine.java index c5423aa88..54477cc72 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/scripting/CraftScriptEngine.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/scripting/CraftScriptEngine.java @@ -3,18 +3,18 @@ * Copyright (C) sk89q * 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 Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or + * 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 Lesser General Public License - * for more details. + * 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 Lesser General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package com.sk89q.worldedit.scripting; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/scripting/CraftScriptEnvironment.java b/worldedit-core/src/main/java/com/sk89q/worldedit/scripting/CraftScriptEnvironment.java index 68c145b4c..f5265fe08 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/scripting/CraftScriptEnvironment.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/scripting/CraftScriptEnvironment.java @@ -3,18 +3,18 @@ * Copyright (C) sk89q * 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 Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or + * 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 Lesser General Public License - * for more details. + * 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 Lesser General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package com.sk89q.worldedit.scripting; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/scripting/MinecraftHidingClassShutter.java b/worldedit-core/src/main/java/com/sk89q/worldedit/scripting/MinecraftHidingClassShutter.java index 20324ed59..e9c6c5a69 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/scripting/MinecraftHidingClassShutter.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/scripting/MinecraftHidingClassShutter.java @@ -3,18 +3,18 @@ * Copyright (C) sk89q * 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 Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or + * 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 Lesser General Public License - * for more details. + * 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 Lesser General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package com.sk89q.worldedit.scripting; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/scripting/RhinoContextFactory.java b/worldedit-core/src/main/java/com/sk89q/worldedit/scripting/RhinoContextFactory.java index 04f7cb399..947785cee 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/scripting/RhinoContextFactory.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/scripting/RhinoContextFactory.java @@ -3,18 +3,18 @@ * Copyright (C) sk89q * 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 Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or + * 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 Lesser General Public License - * for more details. + * 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 Lesser General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package com.sk89q.worldedit.scripting; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/scripting/RhinoCraftScriptEngine.java b/worldedit-core/src/main/java/com/sk89q/worldedit/scripting/RhinoCraftScriptEngine.java index d48b6461c..c6ba5ef7c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/scripting/RhinoCraftScriptEngine.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/scripting/RhinoCraftScriptEngine.java @@ -3,18 +3,18 @@ * Copyright (C) sk89q * 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 Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or + * 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 Lesser General Public License - * for more details. + * 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 Lesser General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package com.sk89q.worldedit.scripting;