Skip to content
Permalink
Browse files

Fixed a lot of PR requested changes

  • Loading branch information...
me4502 committed Jul 23, 2019
1 parent 293004f commit 5b56661261b01cbb01aa787ac12ff31abba908b0
@@ -6,10 +6,8 @@ applyShadowConfiguration()
dependencies {
"compile"(project(":worldedit-core"))
"compile"("org.apache.logging.log4j:log4j-core:2.8.1")
"compile"( "org.apache.logging.log4j:log4j-slf4j-impl:2.8.1")
"compile"( "commons-cli:commons-cli:1.4")

"testCompile"("org.mockito:mockito-core:1.9.0-rc1")
"compile"("org.apache.logging.log4j:log4j-slf4j-impl:2.8.1")
"compile"("commons-cli:commons-cli:1.4")
}

tasks.named<Jar>("jar") {
@@ -23,14 +23,15 @@
import com.sk89q.worldedit.world.registry.BlockCategoryRegistry;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Set;
import java.util.stream.Collectors;

public class CLIBlockCategoryRegistry implements BlockCategoryRegistry {

@Override
public Set<BlockType> getCategorisedByName(String category) {
return CLIWorldEdit.inst.getFileRegistries().getDataFile().blocktags.getOrDefault(category, new ArrayList<>()).stream()
return CLIWorldEdit.inst.getFileRegistries().getDataFile().blocktags.getOrDefault(category, Collections.emptyList()).stream()
.map(BlockType.REGISTRY::get)
.collect(Collectors.toSet());
}
@@ -19,6 +19,8 @@

package com.sk89q.worldedit.cli;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import com.sk89q.worldedit.cli.data.FileRegistries;
import com.sk89q.worldedit.registry.state.BooleanProperty;
import com.sk89q.worldedit.registry.state.DirectionalProperty;
@@ -29,7 +31,6 @@
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.registry.BundledBlockRegistry;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@@ -63,11 +64,10 @@
@Nullable
@Override
public Map<String, ? extends Property<?>> getProperties(BlockType blockType) {
Map<String, FileRegistries.BlockProperty> properties = CLIWorldEdit.inst.getFileRegistries().getDataFile().blocks.get(blockType.getId()).properties;
Map<String, Property<?>> worldEditProperties = new HashMap<>();

properties.forEach((name, prop) -> worldEditProperties.put(name, createProperty(prop.type, name, prop.values)));

return worldEditProperties;
Map<String, FileRegistries.BlockProperty> properties =
CLIWorldEdit.inst.getFileRegistries().getDataFile().blocks.get(blockType.getId()).properties;
return ImmutableMap.copyOf(Maps.transformEntries(properties,
(Maps.EntryTransformer<String, FileRegistries.BlockProperty, Property<?>>)
(key, value) -> createProperty(value.type, key, value.values)));
}
}
@@ -27,7 +27,7 @@
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;
import org.apache.logging.log4j.Logger;
import org.slf4j.Logger;

import java.io.File;
import java.util.UUID;
@@ -39,14 +39,14 @@
*/
private static final UUID DEFAULT_ID = UUID.fromString("a233eb4b-4cab-42cd-9fd9-7e7b9a3f74be");

private CLIWorldEdit plugin;
private Logger sender;
private final CLIWorldEdit app;
private final Logger sender;

public CLICommandSender(CLIWorldEdit plugin, Logger sender) {
checkNotNull(plugin);
public CLICommandSender(CLIWorldEdit app, Logger sender) {
checkNotNull(app);
checkNotNull(sender);

this.plugin = plugin;
this.app = app;
this.sender = sender;
}

@@ -25,8 +25,8 @@

public class CLIConfiguration extends PropertiesConfiguration {

public CLIConfiguration(CLIWorldEdit mod) {
super(new File(mod.getWorkingDir() + File.separator + "worldedit.properties"));
public CLIConfiguration(CLIWorldEdit app) {
super(new File(app.getWorkingDir(), "worldedit.properties"));
}

@Override
@@ -38,13 +38,13 @@

class CLIPlatform extends AbstractPlatform {

private final CLIWorldEdit mod;
private final CLIWorldEdit app;
private int dataVersion = -1;

private List<World> worlds = new ArrayList<>();
private final List<World> worlds = new ArrayList<>();

CLIPlatform(CLIWorldEdit mod) {
this.mod = mod;
CLIPlatform(CLIWorldEdit app) {
this.app = app;
}

@Override
@@ -108,12 +108,12 @@ public void registerGameHooks() {

@Override
public CLIConfiguration getConfiguration() {
return mod.getConfig();
return app.getConfig();
}

@Override
public String getVersion() {
return mod.getInternalVersion();
return app.getInternalVersion();
}

@Override
@@ -123,7 +123,7 @@ public String getPlatformName() {

@Override
public String getPlatformVersion() {
return mod.getInternalVersion();
return app.getInternalVersion();
}

@Override
@@ -34,7 +34,7 @@
/**
* Create a new instance.
*/
CLIRegistries() {
private CLIRegistries() {
}

@Override
@@ -49,8 +49,8 @@
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.Options;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.FileOutputStream;
@@ -67,7 +67,7 @@
*/
public class CLIWorldEdit {

private static final Logger LOGGER = LogManager.getLogger();
private static final Logger LOGGER = LoggerFactory.getLogger(CLIWorldEdit.class);

public static CLIWorldEdit inst;

@@ -106,8 +106,9 @@ public void setupRegistries() {
).toImmutableState();
BlockState defaultState = input.getBlockType().getAllStates().get(0);
for (Map.Entry<Property<?>, Object> propertyObjectEntry : state.getStates().entrySet()) {
//noinspection unchecked
defaultState = defaultState.with((Property<Object>) propertyObjectEntry.getKey(), propertyObjectEntry.getValue());
@SuppressWarnings("unchecked")
Property<Object> prop = (Property<Object>) propertyObjectEntry.getKey();
defaultState = defaultState.with(prop, propertyObjectEntry.getValue());
}
return defaultState;
} catch (InputParseException e) {
@@ -214,7 +215,7 @@ public File getWorkingDir() {
}

/**
* Get the version of the WorldEdit-for-Forge implementation.
* Get the version of the WorldEdit-CLI implementation.
*
* @return a version string
*/
@@ -224,7 +225,7 @@ String getInternalVersion() {

public void run() {
Scanner scanner = new Scanner(System.in);
while (scanner.hasNext()) {
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
if (line.equalsIgnoreCase("stop")) {
commandSender.print("Stopping!");
@@ -269,9 +270,10 @@ public static void main(String[] args) {
Options options = new Options();
options.addRequiredOption("f", "file", false, "The file to load in. Either a schematic, or a level.dat in a world folder.");
CommandLineParser parser = new DefaultParser();
int exitCode = 0;

CLIWorldEdit worldEdit = new CLIWorldEdit();
worldEdit.onInitialized();
CLIWorldEdit app = new CLIWorldEdit();
app.onInitialized();

try {
CommandLine cmd = parser.parse(options, args);
@@ -296,23 +298,28 @@ public static void main(String[] args) {
.getReader(Files.newInputStream(file.toPath(), StandardOpenOption.READ));
int dataVersion = clipboardReader.getDataVersion()
.orElseThrow(() -> new IllegalArgumentException("Failed to obtain data version from schematic."));
worldEdit.platform.setDataVersion(dataVersion);
worldEdit.onStarted();
app.platform.setDataVersion(dataVersion);
app.onStarted();
ClipboardWorld world = new ClipboardWorld(
format.getReader(Files.newInputStream(file.toPath(), StandardOpenOption.READ)).read(),
file.getName()
);
worldEdit.platform.addWorld(world);
WorldEdit.getInstance().getSessionManager().get(worldEdit.commandSender).setWorldOverride(world);
app.platform.addWorld(world);
WorldEdit.getInstance().getSessionManager().get(app.commandSender).setWorldOverride(world);
} else {
throw new IllegalArgumentException("Unknown file provided!");
}

worldEdit.run();
app.run();
} catch (Exception e) {
e.printStackTrace();
exitCode = 1;
} finally {
worldEdit.onStopped();
app.onStopped();
}

if (exitCode != 0) {
System.exit(exitCode);
}
}
}
@@ -33,18 +33,18 @@

public class FileRegistries {

private CLIWorldEdit program;
private CLIWorldEdit app;
private Gson gson = new GsonBuilder().create();

private DataFile dataFile;

public FileRegistries(CLIWorldEdit program) {
this.program = program;
public FileRegistries(CLIWorldEdit app) {
this.app = app;
}

public void loadDataFiles() {
try {
URL url = ResourceLoader.getResource(FileRegistries.class, program.getPlatform().getDataVersion() + ".json");
URL url = ResourceLoader.getResource(FileRegistries.class, app.getPlatform().getDataVersion() + ".json");
this.dataFile = gson.fromJson(Resources.toString(url, StandardCharsets.UTF_8), DataFile.class);
} catch (IOException e) {
throw new RuntimeException("The provided file is not compatible with this version of WorldEdit-CLI. Please update or report this.");
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN" packages="net.minecraft,com.mojang">
<Configuration status="WARN" packages="com.sk89q,org.enginehub">
<Appenders>
<Console name="SysOut" target="SYSTEM_OUT">
<PatternLayout pattern="[%d{HH:mm:ss}] [%t/%level]: %msg%n" />
@@ -504,7 +504,7 @@ public boolean toggleSuperPickAxe() {
public BlockVector3 getPlacementPosition(Actor actor) throws IncompleteRegionException {
checkNotNull(actor);
if (!placeAtPos1) {
if (actor.isPlayer() && actor instanceof Player) {
if (actor instanceof Player) {
return ((Player) actor).getBlockIn().toVector().toBlockPoint();
} else {
throw new IncompleteRegionException();
@@ -226,21 +226,13 @@ private void registerAlwaysInjectedValues() {
context -> {
LocalSession localSession = context.injectedValue(Key.of(LocalSession.class))
.orElseThrow(() -> new IllegalStateException("No LocalSession"));
return context.injectedValue(Key.of(Actor.class))
.map(actor -> {
return context.injectedValue(Key.of(World.class))
.map(world -> {
try {
World world;
if (localSession.hasWorldOverride()) {
world = localSession.getWorldOverride();
} else if (actor.isPlayer() && actor instanceof Player) {
world = ((Player) actor).getWorld();
} else {
throw new MissingWorldException();
}
return localSession.getSelection(world);
} catch (MissingWorldException | IncompleteRegionException e) {
} catch (IncompleteRegionException e) {
exceptionConverter.convert(e);
throw new AssertionError("Should have thrown a new exception.");
throw new AssertionError("Should have thrown a new exception.", e);
}
});
});
@@ -271,7 +263,7 @@ private void registerAlwaysInjectedValues() {
}
} catch (MissingWorldException e) {
exceptionConverter.convert(e);
throw new AssertionError("Should have thrown a new exception.");
throw new AssertionError("Should have thrown a new exception.", e);
}
});
});

0 comments on commit 5b56661

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