Skip to content

Commit

Permalink
Fixed a lot of PR requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
me4502 committed Aug 12, 2019
1 parent d7bf88c commit a59f325
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 62 deletions.
6 changes: 2 additions & 4 deletions worldedit-cli/build.gradle.kts
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ applyShadowConfiguration()
dependencies { dependencies {
"compile"(project(":worldedit-core")) "compile"(project(":worldedit-core"))
"compile"("org.apache.logging.log4j:log4j-core:2.8.1") "compile"("org.apache.logging.log4j:log4j-core:2.8.1")
"compile"( "org.apache.logging.log4j:log4j-slf4j-impl:2.8.1") "compile"("org.apache.logging.log4j:log4j-slf4j-impl:2.8.1")
"compile"( "commons-cli:commons-cli:1.4") "compile"("commons-cli:commons-cli:1.4")

"testCompile"("org.mockito:mockito-core:1.9.0-rc1")
} }


tasks.named<Jar>("jar") { tasks.named<Jar>("jar") {
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@
import com.sk89q.worldedit.world.registry.BlockCategoryRegistry; import com.sk89q.worldedit.world.registry.BlockCategoryRegistry;


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


public class CLIBlockCategoryRegistry implements BlockCategoryRegistry { public class CLIBlockCategoryRegistry implements BlockCategoryRegistry {


@Override @Override
public Set<BlockType> getCategorisedByName(String category) { 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) .map(BlockType.REGISTRY::get)
.collect(Collectors.toSet()); .collect(Collectors.toSet());
} }
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@


package com.sk89q.worldedit.cli; 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.cli.data.FileRegistries;
import com.sk89q.worldedit.registry.state.BooleanProperty; import com.sk89q.worldedit.registry.state.BooleanProperty;
import com.sk89q.worldedit.registry.state.DirectionalProperty; import com.sk89q.worldedit.registry.state.DirectionalProperty;
Expand All @@ -29,7 +31,6 @@
import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.registry.BundledBlockRegistry; import com.sk89q.worldedit.world.registry.BundledBlockRegistry;


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

return ImmutableMap.copyOf(Maps.transformEntries(properties,
properties.forEach((name, prop) -> worldEditProperties.put(name, createProperty(prop.type, name, prop.values))); (Maps.EntryTransformer<String, FileRegistries.BlockProperty, Property<?>>)

(key, value) -> createProperty(value.type, key, value.values)));
return worldEditProperties;
} }
} }
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import com.sk89q.worldedit.util.auth.AuthorizationException; import com.sk89q.worldedit.util.auth.AuthorizationException;
import com.sk89q.worldedit.util.formatting.text.Component; import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.serializer.plain.PlainComponentSerializer; 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.io.File;
import java.util.UUID; import java.util.UUID;
Expand All @@ -39,14 +39,14 @@ public class CLICommandSender implements Actor {
*/ */
private static final UUID DEFAULT_ID = UUID.fromString("a233eb4b-4cab-42cd-9fd9-7e7b9a3f74be"); private static final UUID DEFAULT_ID = UUID.fromString("a233eb4b-4cab-42cd-9fd9-7e7b9a3f74be");


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


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


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


Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@


public class CLIConfiguration extends PropertiesConfiguration { public class CLIConfiguration extends PropertiesConfiguration {


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


@Override @Override
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@


class CLIPlatform extends AbstractPlatform { class CLIPlatform extends AbstractPlatform {


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


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


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


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


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


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


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


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


@Override @Override
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class CLIRegistries extends BundledRegistries {
/** /**
* Create a new instance. * Create a new instance.
*/ */
CLIRegistries() { private CLIRegistries() {
} }


@Override @Override
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
import org.apache.commons.cli.CommandLineParser; import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser; import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.Options; import org.apache.commons.cli.Options;
import org.apache.logging.log4j.LogManager; import org.slf4j.Logger;
import org.apache.logging.log4j.Logger; import org.slf4j.LoggerFactory;


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


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


public static CLIWorldEdit inst; public static CLIWorldEdit inst;


Expand Down Expand Up @@ -106,8 +106,9 @@ public void setupRegistries() {
).toImmutableState(); ).toImmutableState();
BlockState defaultState = input.getBlockType().getAllStates().get(0); BlockState defaultState = input.getBlockType().getAllStates().get(0);
for (Map.Entry<Property<?>, Object> propertyObjectEntry : state.getStates().entrySet()) { for (Map.Entry<Property<?>, Object> propertyObjectEntry : state.getStates().entrySet()) {
//noinspection unchecked @SuppressWarnings("unchecked")
defaultState = defaultState.with((Property<Object>) propertyObjectEntry.getKey(), propertyObjectEntry.getValue()); Property<Object> prop = (Property<Object>) propertyObjectEntry.getKey();
defaultState = defaultState.with(prop, propertyObjectEntry.getValue());
} }
return defaultState; return defaultState;
} catch (InputParseException e) { } catch (InputParseException e) {
Expand Down Expand Up @@ -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 * @return a version string
*/ */
Expand All @@ -224,7 +225,7 @@ String getInternalVersion() {


public void run() { public void run() {
Scanner scanner = new Scanner(System.in); Scanner scanner = new Scanner(System.in);
while (scanner.hasNext()) { while (scanner.hasNextLine()) {
String line = scanner.nextLine(); String line = scanner.nextLine();
if (line.equalsIgnoreCase("stop")) { if (line.equalsIgnoreCase("stop")) {
commandSender.print("Stopping!"); commandSender.print("Stopping!");
Expand Down Expand Up @@ -269,9 +270,10 @@ public static void main(String[] args) {
Options options = new Options(); 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."); 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(); CommandLineParser parser = new DefaultParser();
int exitCode = 0;


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


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


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

if (exitCode != 0) {
System.exit(exitCode);
} }
} }
} }
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@


public class FileRegistries { public class FileRegistries {


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


private DataFile dataFile; private DataFile dataFile;


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


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

0 comments on commit a59f325

Please sign in to comment.