Upstream merge of the scripting package

Dieser Commit ist enthalten in:
MattBDev 2020-08-18 13:43:18 -04:00
Ursprung 4041b2aa1d
Commit 72a4bb3552
7 geänderte Dateien mit 97 neuen und 79 gelöschten Zeilen

Datei anzeigen

@ -3,28 +3,34 @@
* Copyright (C) sk89q <http://www.sk89q.com> * Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors * Copyright (C) WorldEdit team and contributors
* *
* This program is free software: you can redistribute it and/or modify it * This program is free software: you can redistribute it and/or modify
* under the terms of the GNU Lesser General Public License as published by the * it under the terms of the GNU General Public License as published by
* Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful,
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * but WITHOUT ANY WARRANTY; without even the implied warranty of
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package com.sk89q.worldedit.command; package com.sk89q.worldedit.command;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.util.formatting.text.Component;
public class InsufficientArgumentsException extends WorldEditException { public class InsufficientArgumentsException extends WorldEditException {
@Deprecated
public InsufficientArgumentsException(String error) { public InsufficientArgumentsException(String error) {
super(error); super(error);
} }
public InsufficientArgumentsException(Component error) {
super(error);
}
} }

Datei anzeigen

@ -3,36 +3,38 @@
* Copyright (C) sk89q <http://www.sk89q.com> * Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors * Copyright (C) WorldEdit team and contributors
* *
* This program is free software: you can redistribute it and/or modify it * This program is free software: you can redistribute it and/or modify
* under the terms of the GNU Lesser General Public License as published by the * it under the terms of the GNU General Public License as published by
* Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful,
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * but WITHOUT ANY WARRANTY; without even the implied warranty of
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package com.sk89q.worldedit.scripting; package com.sk89q.worldedit.scripting;
import com.sk89q.worldedit.DisallowedItemException;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.UnknownItemException;
import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.command.InsufficientArgumentsException; import com.sk89q.worldedit.command.InsufficientArgumentsException;
import com.sk89q.worldedit.entity.Player; 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.input.ParserContext;
import com.sk89q.worldedit.extension.platform.Platform; import com.sk89q.worldedit.extension.platform.Platform;
import com.sk89q.worldedit.function.pattern.Pattern; 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.session.request.Request;
import com.sk89q.worldedit.util.formatting.text.TextComponent; 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.util.io.file.FilenameException;
import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BaseBlock;
@ -47,8 +49,8 @@ import java.util.Set;
*/ */
public class CraftScriptContext extends CraftScriptEnvironment { public class CraftScriptContext extends CraftScriptEnvironment {
private List<EditSession> editSessions = new ArrayList<>(); private final List<EditSession> editSessions = new ArrayList<>();
private String[] args; private final String[] args;
public CraftScriptContext(WorldEdit controller, public CraftScriptContext(WorldEdit controller,
Platform server, LocalConfiguration config, Platform server, LocalConfiguration config,
@ -142,23 +144,33 @@ public class CraftScriptContext extends CraftScriptEnvironment {
* @param min a number of arguments * @param min a number of arguments
* @param max -1 for no maximum * @param max -1 for no maximum
* @param usage usage string * @param usage usage string
* @throws InsufficientArgumentsException * @throws InsufficientArgumentsException if the arguments are not "sufficiently" good
*/ */
public void checkArgs(int min, int max, String usage) public void checkArgs(int min, int max, String usage)
throws InsufficientArgumentsException { throws InsufficientArgumentsException {
if (args.length <= min || (max != -1 && args.length - 1 > max)) { 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. * Get an item from an item name or an item ID number.
* *
* @param input input to parse * @param input input to parse
* @param allAllowed true to ignore blacklists * @param allAllowed true to ignore blacklists
* @return a block * @return a block
* @throws UnknownItemException * @throws NoMatchException if no block was found
* @throws DisallowedItemException * @throws DisallowedUsageException if the block is disallowed
*/ */
public BaseBlock getBlock(String input, boolean allAllowed) throws WorldEditException { public BaseBlock getBlock(String input, boolean allAllowed) throws WorldEditException {
ParserContext context = new ParserContext(); ParserContext context = new ParserContext();
@ -176,8 +188,8 @@ public class CraftScriptContext extends CraftScriptEnvironment {
* *
* @param id the type Id * @param id the type Id
* @return a block * @return a block
* @throws UnknownItemException * @throws NoMatchException if no block was found
* @throws DisallowedItemException * @throws DisallowedUsageException if the block is disallowed
*/ */
public BaseBlock getBlock(String id) throws WorldEditException { public BaseBlock getBlock(String id) throws WorldEditException {
return getBlock(id, false); return getBlock(id, false);
@ -188,8 +200,8 @@ public class CraftScriptContext extends CraftScriptEnvironment {
* *
* @param list the input * @param list the input
* @return pattern * @return pattern
* @throws UnknownItemException * @throws NoMatchException if the pattern was invalid
* @throws DisallowedItemException * @throws DisallowedUsageException if the block is disallowed
*/ */
public Pattern getBlockPattern(String list) throws WorldEditException { public Pattern getBlockPattern(String list) throws WorldEditException {
ParserContext context = new ParserContext(); ParserContext context = new ParserContext();
@ -205,8 +217,8 @@ public class CraftScriptContext extends CraftScriptEnvironment {
* @param list a list * @param list a list
* @param allBlocksAllowed true if all blocks are allowed * @param allBlocksAllowed true if all blocks are allowed
* @return set * @return set
* @throws UnknownItemException * @throws NoMatchException if the blocks couldn't be found
* @throws DisallowedItemException * @throws DisallowedUsageException if the block is disallowed
*/ */
public Set<BaseBlock> getBlocks(String list, boolean allBlocksAllowed) throws WorldEditException { public Set<BaseBlock> getBlocks(String list, boolean allBlocksAllowed) throws WorldEditException {
ParserContext context = new ParserContext(); ParserContext context = new ParserContext();
@ -231,7 +243,7 @@ public class CraftScriptContext extends CraftScriptEnvironment {
* @param defaultExt default extension to append if there is none * @param defaultExt default extension to append if there is none
* @param exts list of extensions for file open dialog, null for no filter * @param exts list of extensions for file open dialog, null for no filter
* @return a file * @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 { public File getSafeOpenFile(String folder, String filename, String defaultExt, String... exts) throws FilenameException {
File dir = controller.getWorkingDirectoryFile(folder); 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 defaultExt default extension to append if there is none
* @param exts list of extensions for file save dialog, null for no filter * @param exts list of extensions for file save dialog, null for no filter
* @return a file * @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 { public File getSafeSaveFile(String folder, String filename, String defaultExt, String... exts) throws FilenameException {
File dir = controller.getWorkingDirectoryFile(folder); File dir = controller.getWorkingDirectoryFile(folder);

Datei anzeigen

@ -3,18 +3,18 @@
* Copyright (C) sk89q <http://www.sk89q.com> * Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors * Copyright (C) WorldEdit team and contributors
* *
* This program is free software: you can redistribute it and/or modify it * This program is free software: you can redistribute it and/or modify
* under the terms of the GNU Lesser General Public License as published by the * it under the terms of the GNU General Public License as published by
* Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful,
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * but WITHOUT ANY WARRANTY; without even the implied warranty of
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package com.sk89q.worldedit.scripting; package com.sk89q.worldedit.scripting;

Datei anzeigen

@ -3,18 +3,18 @@
* Copyright (C) sk89q <http://www.sk89q.com> * Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors * Copyright (C) WorldEdit team and contributors
* *
* This program is free software: you can redistribute it and/or modify it * This program is free software: you can redistribute it and/or modify
* under the terms of the GNU Lesser General Public License as published by the * it under the terms of the GNU General Public License as published by
* Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful,
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * but WITHOUT ANY WARRANTY; without even the implied warranty of
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package com.sk89q.worldedit.scripting; package com.sk89q.worldedit.scripting;

Datei anzeigen

@ -3,18 +3,18 @@
* Copyright (C) sk89q <http://www.sk89q.com> * Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors * Copyright (C) WorldEdit team and contributors
* *
* This program is free software: you can redistribute it and/or modify it * This program is free software: you can redistribute it and/or modify
* under the terms of the GNU Lesser General Public License as published by the * it under the terms of the GNU General Public License as published by
* Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful,
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * but WITHOUT ANY WARRANTY; without even the implied warranty of
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package com.sk89q.worldedit.scripting; package com.sk89q.worldedit.scripting;

Datei anzeigen

@ -3,18 +3,18 @@
* Copyright (C) sk89q <http://www.sk89q.com> * Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors * Copyright (C) WorldEdit team and contributors
* *
* This program is free software: you can redistribute it and/or modify it * This program is free software: you can redistribute it and/or modify
* under the terms of the GNU Lesser General Public License as published by the * it under the terms of the GNU General Public License as published by
* Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful,
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * but WITHOUT ANY WARRANTY; without even the implied warranty of
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package com.sk89q.worldedit.scripting; package com.sk89q.worldedit.scripting;

Datei anzeigen

@ -3,18 +3,18 @@
* Copyright (C) sk89q <http://www.sk89q.com> * Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors * Copyright (C) WorldEdit team and contributors
* *
* This program is free software: you can redistribute it and/or modify it * This program is free software: you can redistribute it and/or modify
* under the terms of the GNU Lesser General Public License as published by the * it under the terms of the GNU General Public License as published by
* Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful,
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * but WITHOUT ANY WARRANTY; without even the implied warranty of
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package com.sk89q.worldedit.scripting; package com.sk89q.worldedit.scripting;