Skip to content

Commit

Permalink
Minor cleanup and implementing a few of the final functions
Browse files Browse the repository at this point in the history
  • Loading branch information
me4502 committed Aug 2, 2019
1 parent afa1908 commit a8e3cf9
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 14 deletions.
Expand Up @@ -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;
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Expand Up @@ -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;

Expand All @@ -42,6 +44,8 @@ class CLIPlatform extends AbstractPlatform {
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;
Expand All @@ -54,7 +58,7 @@ public Registries getRegistries() {

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

public void setDataVersion(int dataVersion) {
Expand All @@ -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
Expand All @@ -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
Expand Down
Expand Up @@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -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.");
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit a8e3cf9

Please sign in to comment.