Skip to content
Permalink
Browse files

Minor cleanup and implementing a few of the final functions

  • Loading branch information...
me4502 committed Aug 2, 2019
1 parent afa1908 commit a8e3cf984b27fe48dbb14615f92c570b56ab5671
@@ -22,7 +22,6 @@
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.registry.BlockCategoryRegistry;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Set;
import java.util.stream.Collectors;
@@ -24,6 +24,7 @@
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.internal.cui.CUIEvent;
import com.sk89q.worldedit.session.SessionKey;
import com.sk89q.worldedit.util.FileDialogUtil;
import com.sk89q.worldedit.util.auth.AuthorizationException;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.serializer.plain.PlainComponentSerializer;
@@ -124,12 +125,12 @@ public boolean isPlayer() {

@Override
public File openFileOpenDialog(String[] extensions) {
return null;
return FileDialogUtil.showOpenDialog(extensions);
}

@Override
public File openFileSaveDialog(String[] extensions) {
return null;
return FileDialogUtil.showSaveDialog(extensions);
}

@Override
@@ -33,6 +33,8 @@
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;

import javax.annotation.Nullable;

@@ -42,6 +44,8 @@
private int dataVersion = -1;

private final List<World> worlds = new ArrayList<>();
private final Timer timer = new Timer();
private int lastTimerId = 0;

CLIPlatform(CLIWorldEdit app) {
this.app = app;
@@ -54,7 +58,7 @@ public Registries getRegistries() {

@Override
public int getDataVersion() {
return dataVersion;
return this.dataVersion;
}

public void setDataVersion(int dataVersion) {
@@ -78,12 +82,21 @@ public void reload() {

@Override
public int schedule(long delay, long period, Runnable task) {
return -1;
this.timer.schedule(new TimerTask() {
@Override
public void run() {
task.run();
if (period >= 0) {
timer.schedule(this, period);
}
}
}, delay);
return this.lastTimerId++;
}

@Override
public List<? extends World> getWorlds() {
return worlds;
return this.worlds;
}

@Nullable
@@ -95,7 +108,10 @@ public Player matchPlayer(Player player) {
@Nullable
@Override
public World matchWorld(World world) {
return null;
return this.worlds.stream()
.filter(w -> w.getId().equals(world.getId()))
.findAny()
.orElse(null);
}

@Override
@@ -34,7 +34,6 @@
import com.sk89q.worldedit.extent.clipboard.io.ClipboardReader;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardWriter;
import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.util.FileDialogUtil;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BlockCategory;
@@ -50,20 +49,19 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.SequenceInputStream;
import java.io.UncheckedIOException;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.util.Map;
import java.util.Scanner;
import java.util.jar.Manifest;

/**
* The CLI implementation of WorldEdit.
@@ -250,7 +248,7 @@ public void run(InputStream inputStream) {
if (bits.length >= 2) {
file = new File(bits[1]);
} else {
file = FileDialogUtil.showSaveDialog(new String[]{"schem"});
file = commandSender.openFileSaveDialog(new String[]{"schem"});
}
if (file == null) {
commandSender.printError("Please choose a file.");
@@ -291,7 +289,7 @@ public static void main(String[] args) {
String fileArg = cmd.getOptionValue('f');
File file;
if (fileArg == null) {
file = FileDialogUtil.showOpenDialog(new String[]{"schem", "dat"});
file = app.commandSender.openFileOpenDialog(new String[]{"schem", "dat"});
} else {
file = new File(fileArg);
}
@@ -327,7 +325,10 @@ public static void main(String[] args) {
if (!scriptFileHandle.exists()) {
throw new IllegalArgumentException("Could not find given script file.");
}
inputStream = new SequenceInputStream(Files.newInputStream(scriptFileHandle.toPath(), StandardOpenOption.READ), inputStream);
InputStream scriptStream = Files.newInputStream(scriptFileHandle.toPath(), StandardOpenOption.READ);
InputStream newLineStream = new ByteArrayInputStream("\n".getBytes(StandardCharsets.UTF_8));
// Cleaner to do this than make an Enumeration :(
inputStream = new SequenceInputStream(new SequenceInputStream(scriptStream, newLineStream), inputStream);
}

app.run(inputStream);

0 comments on commit a8e3cf9

Please sign in to comment.
You can’t perform that action at this time.