mirror of
https://github.com/EngineHub/WorldEdit.git
synced 2024-12-15 04:41:37 +08:00
parent
fbb047a0c1
commit
0790e6e5d8
@ -9,6 +9,9 @@
|
|||||||
addJarManifest(WorldEditKind.Standalone("com.sk89q.worldedit.cli.CLIWorldEdit"))
|
addJarManifest(WorldEditKind.Standalone("com.sk89q.worldedit.cli.CLIWorldEdit"))
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
"compileOnly"(project(":worldedit-libs:core:ap"))
|
||||||
|
"annotationProcessor"(project(":worldedit-libs:core:ap"))
|
||||||
|
"annotationProcessor"("com.google.guava:guava:${Versions.GUAVA}")
|
||||||
"api"(project(":worldedit-core"))
|
"api"(project(":worldedit-core"))
|
||||||
"implementation"(platform("org.apache.logging.log4j:log4j-bom:2.14.1") {
|
"implementation"(platform("org.apache.logging.log4j:log4j-bom:2.14.1") {
|
||||||
because("We control Log4J on this platform")
|
because("We control Log4J on this platform")
|
||||||
|
@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* 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.cli;
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.LocalSession;
|
||||||
|
import com.sk89q.worldedit.WorldEdit;
|
||||||
|
import com.sk89q.worldedit.extension.platform.Actor;
|
||||||
|
import com.sk89q.worldedit.regions.selector.CuboidRegionSelector;
|
||||||
|
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||||
|
import com.sk89q.worldedit.util.task.Task;
|
||||||
|
import com.sk89q.worldedit.world.World;
|
||||||
|
import org.enginehub.piston.annotation.Command;
|
||||||
|
import org.enginehub.piston.annotation.CommandContainer;
|
||||||
|
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
|
@CommandContainer
|
||||||
|
public class CLIExtraCommands {
|
||||||
|
@Command(
|
||||||
|
name = "selectworld",
|
||||||
|
desc = "Select the entire world"
|
||||||
|
)
|
||||||
|
public void selectWorld(Actor actor, World world, LocalSession session) {
|
||||||
|
session.setRegionSelector(world, new CuboidRegionSelector(
|
||||||
|
world, world.getMinimumPoint(), world.getMaximumPoint()
|
||||||
|
));
|
||||||
|
actor.printInfo(TextComponent.of("Selected the entire world."));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Command(
|
||||||
|
name = "await",
|
||||||
|
desc = "Await all pending tasks"
|
||||||
|
)
|
||||||
|
public void await() {
|
||||||
|
for (Task<?> task : WorldEdit.getInstance().getSupervisor().getTasks()) {
|
||||||
|
try {
|
||||||
|
task.get();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
WorldEdit.logger.warn("Interrupted awaiting task", e);
|
||||||
|
} catch (ExecutionException e) {
|
||||||
|
WorldEdit.logger.warn("Error awaiting task", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -19,18 +19,23 @@
|
|||||||
|
|
||||||
package com.sk89q.worldedit.cli;
|
package com.sk89q.worldedit.cli;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.sk89q.worldedit.WorldEdit;
|
import com.sk89q.worldedit.WorldEdit;
|
||||||
import com.sk89q.worldedit.cli.data.FileRegistries;
|
import com.sk89q.worldedit.cli.data.FileRegistries;
|
||||||
import com.sk89q.worldedit.cli.schematic.ClipboardWorld;
|
import com.sk89q.worldedit.cli.schematic.ClipboardWorld;
|
||||||
import com.sk89q.worldedit.event.platform.CommandEvent;
|
import com.sk89q.worldedit.event.platform.CommandEvent;
|
||||||
import com.sk89q.worldedit.event.platform.PlatformReadyEvent;
|
import com.sk89q.worldedit.event.platform.PlatformReadyEvent;
|
||||||
|
import com.sk89q.worldedit.event.platform.PlatformsRegisteredEvent;
|
||||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||||
import com.sk89q.worldedit.extension.platform.Actor;
|
import com.sk89q.worldedit.extension.platform.Actor;
|
||||||
import com.sk89q.worldedit.extension.platform.Platform;
|
import com.sk89q.worldedit.extension.platform.Platform;
|
||||||
|
import com.sk89q.worldedit.extension.platform.PlatformCommandManager;
|
||||||
|
import com.sk89q.worldedit.extent.clipboard.io.BuiltInClipboardFormat;
|
||||||
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
|
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
|
||||||
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats;
|
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats;
|
||||||
import com.sk89q.worldedit.extent.clipboard.io.ClipboardReader;
|
import com.sk89q.worldedit.extent.clipboard.io.ClipboardReader;
|
||||||
|
import com.sk89q.worldedit.internal.Constants;
|
||||||
import com.sk89q.worldedit.internal.util.LogManagerCompat;
|
import com.sk89q.worldedit.internal.util.LogManagerCompat;
|
||||||
import com.sk89q.worldedit.registry.state.Property;
|
import com.sk89q.worldedit.registry.state.Property;
|
||||||
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
|
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
|
||||||
@ -87,10 +92,29 @@ public CLIWorldEdit() {
|
|||||||
private void setupPlatform() {
|
private void setupPlatform() {
|
||||||
WorldEdit.getInstance().getPlatformManager().register(platform);
|
WorldEdit.getInstance().getPlatformManager().register(platform);
|
||||||
|
|
||||||
|
registerCommands();
|
||||||
|
|
||||||
|
config = new CLIConfiguration(this);
|
||||||
|
|
||||||
|
// There's no other platforms, so fire this immediately
|
||||||
|
WorldEdit.getInstance().getEventBus().post(new PlatformsRegisteredEvent());
|
||||||
|
|
||||||
this.fileRegistries = new FileRegistries(this);
|
this.fileRegistries = new FileRegistries(this);
|
||||||
this.fileRegistries.loadDataFiles();
|
this.fileRegistries.loadDataFiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void registerCommands() {
|
||||||
|
PlatformCommandManager pcm = WorldEdit.getInstance().getPlatformManager()
|
||||||
|
.getPlatformCommandManager();
|
||||||
|
pcm.registerSubCommands(
|
||||||
|
"cli",
|
||||||
|
ImmutableList.of(),
|
||||||
|
"CLI-specific commands",
|
||||||
|
CLIExtraCommandsRegistration.builder(),
|
||||||
|
new CLIExtraCommands()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public void setupRegistries() {
|
public void setupRegistries() {
|
||||||
// Blocks
|
// Blocks
|
||||||
for (Map.Entry<String, FileRegistries.BlockManifest> manifestEntry : fileRegistries.getDataFile().blocks.entrySet()) {
|
for (Map.Entry<String, FileRegistries.BlockManifest> manifestEntry : fileRegistries.getDataFile().blocks.entrySet()) {
|
||||||
@ -172,7 +196,6 @@ public void onStarted() {
|
|||||||
setupRegistries();
|
setupRegistries();
|
||||||
WorldEdit.getInstance().loadMappings();
|
WorldEdit.getInstance().loadMappings();
|
||||||
|
|
||||||
config = new CLIConfiguration(this);
|
|
||||||
config.load();
|
config.load();
|
||||||
|
|
||||||
WorldEdit.getInstance().getEventBus().post(new PlatformReadyEvent(platform));
|
WorldEdit.getInstance().getEventBus().post(new PlatformReadyEvent(platform));
|
||||||
@ -235,8 +258,15 @@ public void saveAllWorlds(boolean force) {
|
|||||||
|
|
||||||
public void run(InputStream inputStream) {
|
public void run(InputStream inputStream) {
|
||||||
try (Scanner scanner = new Scanner(inputStream)) {
|
try (Scanner scanner = new Scanner(inputStream)) {
|
||||||
while (scanner.hasNextLine()) {
|
while (true) {
|
||||||
|
System.err.print("> ");
|
||||||
|
if (!scanner.hasNextLine()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
String line = scanner.nextLine();
|
String line = scanner.nextLine();
|
||||||
|
if (line.isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (line.equals("stop")) {
|
if (line.equals("stop")) {
|
||||||
commandSender.printInfo(TranslatableComponent.of("worldedit.cli.stopping"));
|
commandSender.printInfo(TranslatableComponent.of("worldedit.cli.stopping"));
|
||||||
break;
|
break;
|
||||||
@ -280,31 +310,40 @@ public static void main(String[] args) {
|
|||||||
if (file == null) {
|
if (file == null) {
|
||||||
throw new IllegalArgumentException("A file must be provided!");
|
throw new IllegalArgumentException("A file must be provided!");
|
||||||
}
|
}
|
||||||
|
LOGGER.info(() -> "Loading '" + file + "'...");
|
||||||
if (file.getName().endsWith("level.dat")) {
|
if (file.getName().endsWith("level.dat")) {
|
||||||
throw new IllegalArgumentException("level.dat file support is unfinished.");
|
throw new IllegalArgumentException("level.dat file support is unfinished.");
|
||||||
} else {
|
} else {
|
||||||
ClipboardFormat format = ClipboardFormats.findByFile(file);
|
ClipboardFormat format = ClipboardFormats.findByFile(file);
|
||||||
if (format != null) {
|
if (format != null) {
|
||||||
ClipboardReader dataVersionReader = format
|
int dataVersion;
|
||||||
.getReader(Files.newInputStream(file.toPath(), StandardOpenOption.READ));
|
if (format != BuiltInClipboardFormat.MCEDIT_SCHEMATIC) {
|
||||||
int dataVersion = dataVersionReader.getDataVersion()
|
try (ClipboardReader dataVersionReader = format.getReader(
|
||||||
.orElseThrow(() -> new IllegalArgumentException("Failed to obtain data version from schematic."));
|
Files.newInputStream(file.toPath(), StandardOpenOption.READ)
|
||||||
dataVersionReader.close();
|
)) {
|
||||||
|
dataVersion = dataVersionReader.getDataVersion()
|
||||||
|
.orElseThrow(() -> new IllegalArgumentException("Failed to obtain data version from schematic."));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
dataVersion = Constants.DATA_VERSION_MC_1_13_2;
|
||||||
|
}
|
||||||
app.platform.setDataVersion(dataVersion);
|
app.platform.setDataVersion(dataVersion);
|
||||||
app.onStarted();
|
app.onStarted();
|
||||||
|
ClipboardWorld world;
|
||||||
try (ClipboardReader clipboardReader = format.getReader(Files.newInputStream(file.toPath(), StandardOpenOption.READ))) {
|
try (ClipboardReader clipboardReader = format.getReader(Files.newInputStream(file.toPath(), StandardOpenOption.READ))) {
|
||||||
ClipboardWorld world = new ClipboardWorld(
|
world = new ClipboardWorld(
|
||||||
file,
|
file,
|
||||||
clipboardReader.read(),
|
clipboardReader.read(),
|
||||||
file.getName()
|
file.getName()
|
||||||
);
|
);
|
||||||
app.platform.addWorld(world);
|
|
||||||
WorldEdit.getInstance().getSessionManager().get(app.commandSender).setWorldOverride(world);
|
|
||||||
}
|
}
|
||||||
|
app.platform.addWorld(world);
|
||||||
|
WorldEdit.getInstance().getSessionManager().get(app.commandSender).setWorldOverride(world);
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException("Unknown file provided!");
|
throw new IllegalArgumentException("Unknown file provided!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
LOGGER.info(() -> "Loaded '" + file + "'");
|
||||||
|
|
||||||
String scriptFile = cmd.getOptionValue('s');
|
String scriptFile = cmd.getOptionValue('s');
|
||||||
if (scriptFile != null) {
|
if (scriptFile != null) {
|
||||||
|
@ -273,8 +273,11 @@ private void registerAlwaysInjectedValues() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private <CI> void registerSubCommands(String name, List<String> aliases, String desc,
|
/**
|
||||||
CommandRegistration<CI> registration, CI instance) {
|
* Internal use only.
|
||||||
|
*/
|
||||||
|
public <CI> void registerSubCommands(String name, List<String> aliases, String desc,
|
||||||
|
CommandRegistration<CI> registration, CI instance) {
|
||||||
registerSubCommands(name, aliases, desc, registration, instance, m -> {
|
registerSubCommands(name, aliases, desc, registration, instance, m -> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user