geforkt von Mirrors/FastAsyncWorldEdit
Implement suggestions for Bukkit + Sponge
Dieser Commit ist enthalten in:
Ursprung
1c54a04fd1
Commit
8a3e6a12b9
@ -80,36 +80,6 @@ public class WorldEditListener implements Listener {
|
|||||||
WorldEdit.getInstance().getSessionManager().get(plugin.wrapPlayer(event.getPlayer()));
|
WorldEdit.getInstance().getSessionManager().get(plugin.wrapPlayer(event.getPlayer()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when a player attempts to use a command
|
|
||||||
*
|
|
||||||
* @param event Relevant event details
|
|
||||||
*/
|
|
||||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
|
||||||
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
|
|
||||||
String[] split = event.getMessage().split(" ");
|
|
||||||
|
|
||||||
if (split.length > 0) {
|
|
||||||
split[0] = split[0].substring(1);
|
|
||||||
split = plugin.getWorldEdit().getPlatformManager().getPlatformCommandManager().commandDetection(split);
|
|
||||||
}
|
|
||||||
|
|
||||||
final String newMessage = "/" + StringUtil.joinString(split, " ");
|
|
||||||
|
|
||||||
if (!newMessage.equals(event.getMessage())) {
|
|
||||||
event.setMessage(newMessage);
|
|
||||||
plugin.getServer().getPluginManager().callEvent(event);
|
|
||||||
|
|
||||||
if (!event.isCancelled()) {
|
|
||||||
if (!event.getMessage().isEmpty()) {
|
|
||||||
plugin.getServer().dispatchCommand(event.getPlayer(), event.getMessage().substring(1));
|
|
||||||
}
|
|
||||||
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||||
public void onPlayerCommand(PlayerCommandSendEvent event) {
|
public void onPlayerCommand(PlayerCommandSendEvent event) {
|
||||||
InjectedValueStore store = MapBackedValueStore.create();
|
InjectedValueStore store = MapBackedValueStore.create();
|
||||||
|
@ -37,6 +37,7 @@ import com.sk89q.worldedit.extension.platform.Actor;
|
|||||||
import com.sk89q.worldedit.extension.platform.Capability;
|
import com.sk89q.worldedit.extension.platform.Capability;
|
||||||
import com.sk89q.worldedit.extension.platform.Platform;
|
import com.sk89q.worldedit.extension.platform.Platform;
|
||||||
import com.sk89q.worldedit.extent.inventory.BlockBag;
|
import com.sk89q.worldedit.extent.inventory.BlockBag;
|
||||||
|
import com.sk89q.worldedit.internal.command.CommandUtil;
|
||||||
import com.sk89q.worldedit.registry.state.Property;
|
import com.sk89q.worldedit.registry.state.Property;
|
||||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||||
import com.sk89q.worldedit.world.block.BlockCategory;
|
import com.sk89q.worldedit.world.block.BlockCategory;
|
||||||
@ -313,9 +314,10 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter {
|
|||||||
System.arraycopy(args, 0, split, 1, args.length);
|
System.arraycopy(args, 0, split, 1, args.length);
|
||||||
split[0] = "/" + cmd.getName();
|
split[0] = "/" + cmd.getName();
|
||||||
|
|
||||||
CommandSuggestionEvent event = new CommandSuggestionEvent(wrapCommandSender(sender), Joiner.on(" ").join(split));
|
String arguments = Joiner.on(" ").join(split);
|
||||||
|
CommandSuggestionEvent event = new CommandSuggestionEvent(wrapCommandSender(sender), arguments);
|
||||||
getWorldEdit().getEventBus().post(event);
|
getWorldEdit().getEventBus().post(event);
|
||||||
return event.getSuggestions();
|
return CommandUtil.fixSuggestions(arguments, event.getSuggestions());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -58,7 +58,6 @@ public abstract class LocalConfiguration {
|
|||||||
public String wandItem = "minecraft:wooden_axe";
|
public String wandItem = "minecraft:wooden_axe";
|
||||||
public boolean superPickaxeDrop = true;
|
public boolean superPickaxeDrop = true;
|
||||||
public boolean superPickaxeManyDrop = true;
|
public boolean superPickaxeManyDrop = true;
|
||||||
public boolean noDoubleSlash = false;
|
|
||||||
public boolean useInventory = false;
|
public boolean useInventory = false;
|
||||||
public boolean useInventoryOverride = false;
|
public boolean useInventoryOverride = false;
|
||||||
public boolean useInventoryCreativeOverride = false;
|
public boolean useInventoryCreativeOverride = false;
|
||||||
|
@ -19,14 +19,15 @@
|
|||||||
|
|
||||||
package com.sk89q.worldedit.event.platform;
|
package com.sk89q.worldedit.event.platform;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
|
||||||
|
|
||||||
import com.sk89q.worldedit.event.Event;
|
import com.sk89q.worldedit.event.Event;
|
||||||
import com.sk89q.worldedit.extension.platform.Actor;
|
import com.sk89q.worldedit.extension.platform.Actor;
|
||||||
|
import com.sk89q.worldedit.internal.util.Substring;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Posted when suggestions for auto-completion are requested for command input.
|
* Posted when suggestions for auto-completion are requested for command input.
|
||||||
*/
|
*/
|
||||||
@ -34,7 +35,7 @@ public class CommandSuggestionEvent extends Event {
|
|||||||
|
|
||||||
private final Actor actor;
|
private final Actor actor;
|
||||||
private final String arguments;
|
private final String arguments;
|
||||||
private List<String> suggestions = Collections.emptyList();
|
private List<Substring> suggestions = Collections.emptyList();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new instance.
|
* Create a new instance.
|
||||||
@ -71,9 +72,14 @@ public class CommandSuggestionEvent extends Event {
|
|||||||
/**
|
/**
|
||||||
* Get the list of suggestions that are to be presented.
|
* Get the list of suggestions that are to be presented.
|
||||||
*
|
*
|
||||||
|
* <p>
|
||||||
|
* Each Substring holds the replacement as the substring,
|
||||||
|
* and the replacement range as the original substring range.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
* @return the list of suggestions
|
* @return the list of suggestions
|
||||||
*/
|
*/
|
||||||
public List<String> getSuggestions() {
|
public List<Substring> getSuggestions() {
|
||||||
return suggestions;
|
return suggestions;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,7 +88,7 @@ public class CommandSuggestionEvent extends Event {
|
|||||||
*
|
*
|
||||||
* @param suggestions the list of suggestions
|
* @param suggestions the list of suggestions
|
||||||
*/
|
*/
|
||||||
public void setSuggestions(List<String> suggestions) {
|
public void setSuggestions(List<Substring> suggestions) {
|
||||||
checkNotNull(suggestions);
|
checkNotNull(suggestions);
|
||||||
this.suggestions = suggestions;
|
this.suggestions = suggestions;
|
||||||
}
|
}
|
||||||
|
@ -91,6 +91,7 @@ import com.sk89q.worldedit.internal.command.CommandLoggingHandler;
|
|||||||
import com.sk89q.worldedit.internal.command.CommandRegistrationHandler;
|
import com.sk89q.worldedit.internal.command.CommandRegistrationHandler;
|
||||||
import com.sk89q.worldedit.internal.command.exception.ExceptionConverter;
|
import com.sk89q.worldedit.internal.command.exception.ExceptionConverter;
|
||||||
import com.sk89q.worldedit.internal.command.exception.WorldEditExceptionConverter;
|
import com.sk89q.worldedit.internal.command.exception.WorldEditExceptionConverter;
|
||||||
|
import com.sk89q.worldedit.internal.util.Substring;
|
||||||
import com.sk89q.worldedit.regions.Region;
|
import com.sk89q.worldedit.regions.Region;
|
||||||
import com.sk89q.worldedit.session.request.Request;
|
import com.sk89q.worldedit.session.request.Request;
|
||||||
import com.sk89q.worldedit.util.eventbus.Subscribe;
|
import com.sk89q.worldedit.util.eventbus.Subscribe;
|
||||||
@ -125,15 +126,14 @@ import org.slf4j.LoggerFactory;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.logging.FileHandler;
|
import java.util.logging.FileHandler;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
@ -419,34 +419,8 @@ public final class PlatformCommandManager {
|
|||||||
dynamicHandler.setHandler(null);
|
dynamicHandler.setHandler(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String[] commandDetection(String[] split) {
|
private Stream<Substring> parseArgs(String input) {
|
||||||
// Quick script shortcut
|
return new CommandArgParser(CommandArgParser.spaceSplit(input.substring(1))).parseArgs();
|
||||||
if (split[0].matches("^[^/].*\\.js$")) {
|
|
||||||
String[] newSplit = new String[split.length + 1];
|
|
||||||
System.arraycopy(split, 0, newSplit, 1, split.length);
|
|
||||||
newSplit[0] = "cs";
|
|
||||||
newSplit[1] = newSplit[1];
|
|
||||||
split = newSplit;
|
|
||||||
}
|
|
||||||
|
|
||||||
String searchCmd = split[0].toLowerCase(Locale.ROOT);
|
|
||||||
|
|
||||||
// Try to detect the command
|
|
||||||
if (!commandManager.containsCommand(searchCmd)) {
|
|
||||||
if (worldEdit.getConfiguration().noDoubleSlash && commandManager.containsCommand("/" + searchCmd)) {
|
|
||||||
split[0] = "/" + split[0];
|
|
||||||
} else if (searchCmd.length() >= 2 && searchCmd.charAt(0) == '/' && commandManager.containsCommand(searchCmd.substring(1))) {
|
|
||||||
split[0] = split[0].substring(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return split;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String[] parseArgs(String input) {
|
|
||||||
return commandDetection(new CommandArgParser(input.substring(1))
|
|
||||||
.parseArgs()
|
|
||||||
.toArray(String[]::new));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
@ -454,7 +428,9 @@ public final class PlatformCommandManager {
|
|||||||
Request.reset();
|
Request.reset();
|
||||||
|
|
||||||
Actor actor = platformManager.createProxyActor(event.getActor());
|
Actor actor = platformManager.createProxyActor(event.getActor());
|
||||||
String[] split = parseArgs(event.getArguments());
|
String[] split = parseArgs(event.getArguments())
|
||||||
|
.map(Substring::getSubstring)
|
||||||
|
.toArray(String[]::new);
|
||||||
|
|
||||||
// No command found!
|
// No command found!
|
||||||
if (!commandManager.containsCommand(split[0])) {
|
if (!commandManager.containsCommand(split[0])) {
|
||||||
@ -581,13 +557,26 @@ public final class PlatformCommandManager {
|
|||||||
@Subscribe
|
@Subscribe
|
||||||
public void handleCommandSuggestion(CommandSuggestionEvent event) {
|
public void handleCommandSuggestion(CommandSuggestionEvent event) {
|
||||||
try {
|
try {
|
||||||
String[] split = parseArgs(event.getArguments());
|
String arguments = event.getArguments();
|
||||||
MemoizingValueAccess access = initializeInjectedValues(event::getArguments, event.getActor());
|
List<Substring> split = parseArgs(arguments).collect(Collectors.toList());
|
||||||
ImmutableSet<Suggestion> suggestions = commandManager.getSuggestions(access, Arrays.asList(split));
|
List<String> argStrings = split.stream()
|
||||||
|
.map(Substring::getSubstring)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
MemoizingValueAccess access = initializeInjectedValues(() -> arguments, event.getActor());
|
||||||
|
ImmutableSet<Suggestion> suggestions = commandManager.getSuggestions(access, argStrings);
|
||||||
|
|
||||||
log.debug("For input: {}", event.getArguments());
|
event.setSuggestions(suggestions.stream()
|
||||||
log.debug("I would suggest this: {}", suggestions);
|
.map(suggestion -> {
|
||||||
// TODO send back suggestions
|
Substring original = suggestion.getReplacedArgument() == split.size()
|
||||||
|
? Substring.from(arguments, arguments.length() - 1)
|
||||||
|
: split.get(suggestion.getReplacedArgument());
|
||||||
|
// increase original points by 1, for removed `/` in `parseArgs`
|
||||||
|
return Substring.wrap(
|
||||||
|
suggestion.getSuggestion(),
|
||||||
|
original.getStart() + 1,
|
||||||
|
original.getEnd() + 1
|
||||||
|
);
|
||||||
|
}).collect(Collectors.toList()));
|
||||||
} catch (CommandException e) {
|
} catch (CommandException e) {
|
||||||
event.getActor().printError(e.getMessage());
|
event.getActor().printError(e.getMessage());
|
||||||
}
|
}
|
||||||
|
@ -19,86 +19,94 @@
|
|||||||
|
|
||||||
package com.sk89q.worldedit.internal.command;
|
package com.sk89q.worldedit.internal.command;
|
||||||
|
|
||||||
|
import com.google.common.base.Splitter;
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
|
import com.sk89q.worldedit.internal.util.Substring;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public class CommandArgParser {
|
public class CommandArgParser {
|
||||||
|
|
||||||
|
public static ImmutableList<Substring> spaceSplit(String string) {
|
||||||
|
ImmutableList.Builder<Substring> result = ImmutableList.builder();
|
||||||
|
int index = 0;
|
||||||
|
for (String part : Splitter.on(' ').split(string)) {
|
||||||
|
result.add(Substring.from(string, index, index + part.length()));
|
||||||
|
index += part.length() + 1;
|
||||||
|
}
|
||||||
|
return result.build();
|
||||||
|
}
|
||||||
|
|
||||||
private enum State {
|
private enum State {
|
||||||
NORMAL,
|
NORMAL,
|
||||||
QUOTE
|
QUOTE
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Stream.Builder<String> args = Stream.builder();
|
private final Stream.Builder<Substring> args = Stream.builder();
|
||||||
private final StringBuilder currentArg = new StringBuilder();
|
private final List<Substring> input;
|
||||||
private final String input;
|
private final List<Substring> currentArg = new ArrayList<>();
|
||||||
private int index = 0;
|
private int index = 0;
|
||||||
private State state = State.NORMAL;
|
private State state = State.NORMAL;
|
||||||
|
|
||||||
public CommandArgParser(String input) {
|
public CommandArgParser(List<Substring> input) {
|
||||||
this.input = input;
|
this.input = input;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Stream<String> parseArgs() {
|
public Stream<Substring> parseArgs() {
|
||||||
for (; index < input.length(); index++) {
|
for (; index < input.size(); index++) {
|
||||||
char c = input.charAt(index);
|
Substring nextPart = input.get(index);
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case NORMAL:
|
case NORMAL:
|
||||||
handleNormal(c);
|
handleNormal(nextPart);
|
||||||
break;
|
break;
|
||||||
case QUOTE:
|
case QUOTE:
|
||||||
handleQuote(c);
|
handleQuote(nextPart);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finishArg(true);
|
|
||||||
return args.build();
|
return args.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleNormal(char c) {
|
private void handleNormal(Substring part) {
|
||||||
switch (c) {
|
if (part.getSubstring().startsWith("\"")) {
|
||||||
case '"':
|
state = State.QUOTE;
|
||||||
state = State.QUOTE;
|
currentArg.add(Substring.wrap(
|
||||||
break;
|
part.getSubstring().substring(1),
|
||||||
case ' ':
|
part.getStart(), part.getEnd()
|
||||||
finishArg(true);
|
));
|
||||||
break;
|
} else {
|
||||||
case '\\':
|
currentArg.add(part);
|
||||||
if (index + 1 < input.length()) {
|
finishArg();
|
||||||
index++;
|
|
||||||
}
|
|
||||||
appendChar(input.charAt(index));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
appendChar(c);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleQuote(char c) {
|
private void handleQuote(Substring part) {
|
||||||
switch (c) {
|
if (part.getSubstring().endsWith("\"")) {
|
||||||
case '"':
|
state = State.NORMAL;
|
||||||
state = State.NORMAL;
|
currentArg.add(Substring.wrap(
|
||||||
finishArg(false);
|
part.getSubstring().substring(0, part.getSubstring().length() - 1),
|
||||||
break;
|
part.getStart(), part.getEnd()
|
||||||
case '\\':
|
));
|
||||||
if (index + 1 < input.length()) {
|
finishArg();
|
||||||
index++;
|
} else {
|
||||||
}
|
currentArg.add(part);
|
||||||
appendChar(input.charAt(index));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
appendChar(c);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void finishArg(boolean requireText) {
|
private void finishArg() {
|
||||||
if (currentArg.length() == 0 && requireText) {
|
// Merge the arguments into a single, space-joined, string
|
||||||
return;
|
// Keep the original start + end points.
|
||||||
}
|
int start = currentArg.get(0).getStart();
|
||||||
args.add(currentArg.toString());
|
int end = Iterables.getLast(currentArg).getEnd();
|
||||||
currentArg.setLength(0);
|
args.add(Substring.wrap(currentArg.stream()
|
||||||
}
|
.map(Substring::getSubstring)
|
||||||
|
.collect(Collectors.joining(" ")),
|
||||||
private void appendChar(char c) {
|
start, end
|
||||||
currentArg.append(c);
|
));
|
||||||
|
currentArg.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -19,15 +19,22 @@
|
|||||||
|
|
||||||
package com.sk89q.worldedit.internal.command;
|
package com.sk89q.worldedit.internal.command;
|
||||||
|
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
import com.sk89q.worldedit.extension.platform.PlatformCommandManager;
|
import com.sk89q.worldedit.extension.platform.PlatformCommandManager;
|
||||||
|
import com.sk89q.worldedit.internal.util.Substring;
|
||||||
import org.enginehub.piston.Command;
|
import org.enginehub.piston.Command;
|
||||||
import org.enginehub.piston.part.SubCommandPart;
|
import org.enginehub.piston.part.SubCommandPart;
|
||||||
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
|
import static java.util.stream.Collectors.toList;
|
||||||
|
|
||||||
public class CommandUtil {
|
public class CommandUtil {
|
||||||
|
|
||||||
public static Map<String, Command> getSubCommands(Command currentCommand) {
|
public static Map<String, Command> getSubCommands(Command currentCommand) {
|
||||||
@ -48,6 +55,43 @@ public class CommandUtil {
|
|||||||
return BY_CLEAN_NAME;
|
return BY_CLEAN_NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fix {@code suggestions} to replace the last space-separated word in {@code arguments}.
|
||||||
|
*/
|
||||||
|
public static List<String> fixSuggestions(String arguments, List<Substring> suggestions) {
|
||||||
|
Substring lastArg = Iterables.getLast(CommandArgParser.spaceSplit(arguments));
|
||||||
|
return suggestions.stream()
|
||||||
|
.map(suggestion -> CommandUtil.suggestLast(lastArg, suggestion))
|
||||||
|
.filter(Optional::isPresent)
|
||||||
|
.map(Optional::get)
|
||||||
|
.collect(toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Given the last word of a command, mutate the suggestion to replace the last word, if
|
||||||
|
* possible.
|
||||||
|
*/
|
||||||
|
private static Optional<String> suggestLast(Substring last, Substring suggestion) {
|
||||||
|
if (suggestion.getStart() == last.getEnd()) {
|
||||||
|
// this suggestion is for the next argument.
|
||||||
|
if (last.getSubstring().isEmpty()) {
|
||||||
|
return Optional.of(suggestion.getSubstring());
|
||||||
|
}
|
||||||
|
return Optional.of(last.getSubstring() + " " + suggestion.getSubstring());
|
||||||
|
}
|
||||||
|
StringBuilder builder = new StringBuilder(last.getSubstring());
|
||||||
|
int start = suggestion.getStart() - last.getStart();
|
||||||
|
int end = suggestion.getEnd() - last.getStart();
|
||||||
|
if (start < 0) {
|
||||||
|
// Quoted suggestion, can't complete it here.
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
checkState(end <= builder.length(),
|
||||||
|
"Suggestion ends too late, last=%s, suggestion=", last, suggestion);
|
||||||
|
builder.replace(start, end, suggestion.getSubstring());
|
||||||
|
return Optional.of(builder.toString());
|
||||||
|
}
|
||||||
|
|
||||||
private CommandUtil() {
|
private CommandUtil() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,97 @@
|
|||||||
|
/*
|
||||||
|
* 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 Lesser 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 Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.sk89q.worldedit.internal.util;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An explicit substring. Provides the range from which it was taken.
|
||||||
|
*/
|
||||||
|
public final class Substring {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Take a substring from {@code original}, and {@link #wrap(String, int, int)} it into
|
||||||
|
* a Substring.
|
||||||
|
*/
|
||||||
|
public static Substring from(String original, int start) {
|
||||||
|
return wrap(original.substring(start), start, original.length());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Take a substring from {@code original}, and {@link #wrap(String, int, int)} it into
|
||||||
|
* a Substring.
|
||||||
|
*/
|
||||||
|
public static Substring from(String original, int start, int end) {
|
||||||
|
return wrap(original.substring(start, end), start, end);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrap the given parameters into a Substring instance.
|
||||||
|
*/
|
||||||
|
public static Substring wrap(String substring, int start, int end) {
|
||||||
|
return new Substring(substring, start, end);
|
||||||
|
}
|
||||||
|
|
||||||
|
private final String substring;
|
||||||
|
private final int start;
|
||||||
|
private final int end;
|
||||||
|
|
||||||
|
private Substring(String substring, int start, int end) {
|
||||||
|
this.substring = substring;
|
||||||
|
this.start = start;
|
||||||
|
this.end = end;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSubstring() {
|
||||||
|
return substring;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getStart() {
|
||||||
|
return start;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getEnd() {
|
||||||
|
return end;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
Substring substring1 = (Substring) o;
|
||||||
|
return start == substring1.start &&
|
||||||
|
end == substring1.end &&
|
||||||
|
substring.equals(substring1.substring);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(substring, start, end);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Substring{" +
|
||||||
|
"substring='" + substring + "'" +
|
||||||
|
",start=" + start +
|
||||||
|
",end=" + end +
|
||||||
|
"}";
|
||||||
|
}
|
||||||
|
}
|
@ -99,7 +99,6 @@ public class PropertiesConfiguration extends LocalConfiguration {
|
|||||||
}
|
}
|
||||||
superPickaxeDrop = getBool("super-pickaxe-drop-items", superPickaxeDrop);
|
superPickaxeDrop = getBool("super-pickaxe-drop-items", superPickaxeDrop);
|
||||||
superPickaxeManyDrop = getBool("super-pickaxe-many-drop-items", superPickaxeManyDrop);
|
superPickaxeManyDrop = getBool("super-pickaxe-many-drop-items", superPickaxeManyDrop);
|
||||||
noDoubleSlash = getBool("no-double-slash", noDoubleSlash);
|
|
||||||
useInventory = getBool("use-inventory", useInventory);
|
useInventory = getBool("use-inventory", useInventory);
|
||||||
useInventoryOverride = getBool("use-inventory-override", useInventoryOverride);
|
useInventoryOverride = getBool("use-inventory-override", useInventoryOverride);
|
||||||
useInventoryCreativeOverride = getBool("use-inventory-creative-override", useInventoryCreativeOverride);
|
useInventoryCreativeOverride = getBool("use-inventory-creative-override", useInventoryCreativeOverride);
|
||||||
|
@ -91,8 +91,6 @@ public class YAMLConfiguration extends LocalConfiguration {
|
|||||||
superPickaxeManyDrop = config.getBoolean(
|
superPickaxeManyDrop = config.getBoolean(
|
||||||
"super-pickaxe.many-drop-items", superPickaxeManyDrop);
|
"super-pickaxe.many-drop-items", superPickaxeManyDrop);
|
||||||
|
|
||||||
noDoubleSlash = config.getBoolean("no-double-slash", noDoubleSlash);
|
|
||||||
|
|
||||||
useInventory = config.getBoolean("use-inventory.enable", useInventory);
|
useInventory = config.getBoolean("use-inventory.enable", useInventory);
|
||||||
useInventoryOverride = config.getBoolean("use-inventory.allow-override",
|
useInventoryOverride = config.getBoolean("use-inventory.allow-override",
|
||||||
useInventoryOverride);
|
useInventoryOverride);
|
||||||
|
@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* 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 Lesser 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 Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.sk89q.worldedit.internal.command;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import com.sk89q.worldedit.internal.util.Substring;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static com.sk89q.worldedit.internal.command.CommandArgParser.spaceSplit;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
public class CommandArgParserTest {
|
||||||
|
@Test
|
||||||
|
public void testSpaceSplit() {
|
||||||
|
assertEquals(ImmutableList.of(
|
||||||
|
Substring.wrap("", 0, 0)
|
||||||
|
), spaceSplit(""));
|
||||||
|
assertEquals(ImmutableList.of(
|
||||||
|
Substring.wrap("ab", 0, 2)
|
||||||
|
), spaceSplit("ab"));
|
||||||
|
assertEquals(ImmutableList.of(
|
||||||
|
Substring.wrap("", 0, 0),
|
||||||
|
Substring.wrap("", 1, 1)
|
||||||
|
), spaceSplit(" "));
|
||||||
|
assertEquals(ImmutableList.of(
|
||||||
|
Substring.wrap("a", 0, 1),
|
||||||
|
Substring.wrap("", 2, 2)
|
||||||
|
), spaceSplit("a "));
|
||||||
|
assertEquals(ImmutableList.of(
|
||||||
|
Substring.wrap("a", 0, 1),
|
||||||
|
Substring.wrap("b", 2, 3)
|
||||||
|
), spaceSplit("a b"));
|
||||||
|
}
|
||||||
|
}
|
@ -24,7 +24,7 @@ configurations.all { Configuration it ->
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile project(':worldedit-core')
|
compile project(':worldedit-core')
|
||||||
compile 'org.apache.logging.log4j:log4j-slf4j-impl:2.8.1'
|
compile 'org.apache.logging.log4j:log4j-slf4j-impl:2.11.2'
|
||||||
|
|
||||||
minecraft "net.minecraftforge:forge:${minecraftVersion}-${forgeVersion}"
|
minecraft "net.minecraftforge:forge:${minecraftVersion}-${forgeVersion}"
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ configure(subprojects + project("core:ap")) {
|
|||||||
|
|
||||||
def textVersion = "3.0.0"
|
def textVersion = "3.0.0"
|
||||||
project("core") {
|
project("core") {
|
||||||
def pistonVersion = '0.2.0'
|
def pistonVersion = '0.2.1'
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
shade "net.kyori:text-api:$textVersion"
|
shade "net.kyori:text-api:$textVersion"
|
||||||
|
@ -29,6 +29,7 @@ import com.sk89q.worldedit.extension.platform.Actor;
|
|||||||
import com.sk89q.worldedit.extension.platform.Capability;
|
import com.sk89q.worldedit.extension.platform.Capability;
|
||||||
import com.sk89q.worldedit.extension.platform.MultiUserPlatform;
|
import com.sk89q.worldedit.extension.platform.MultiUserPlatform;
|
||||||
import com.sk89q.worldedit.extension.platform.Preference;
|
import com.sk89q.worldedit.extension.platform.Preference;
|
||||||
|
import com.sk89q.worldedit.internal.command.CommandUtil;
|
||||||
import com.sk89q.worldedit.sponge.config.SpongeConfiguration;
|
import com.sk89q.worldedit.sponge.config.SpongeConfiguration;
|
||||||
import com.sk89q.worldedit.world.World;
|
import com.sk89q.worldedit.world.World;
|
||||||
import com.sk89q.worldedit.world.registry.Registries;
|
import com.sk89q.worldedit.world.registry.Registries;
|
||||||
@ -144,7 +145,7 @@ class SpongePlatform extends AbstractPlatform implements MultiUserPlatform {
|
|||||||
public List<String> getSuggestions(CommandSource source, String arguments, @Nullable Location<org.spongepowered.api.world.World> targetPosition) throws CommandException {
|
public List<String> getSuggestions(CommandSource source, String arguments, @Nullable Location<org.spongepowered.api.world.World> targetPosition) throws CommandException {
|
||||||
CommandSuggestionEvent weEvent = new CommandSuggestionEvent(SpongeWorldEdit.inst().wrapCommandSource(source), command.getName() + " " + arguments);
|
CommandSuggestionEvent weEvent = new CommandSuggestionEvent(SpongeWorldEdit.inst().wrapCommandSource(source), command.getName() + " " + arguments);
|
||||||
WorldEdit.getInstance().getEventBus().post(weEvent);
|
WorldEdit.getInstance().getEventBus().post(weEvent);
|
||||||
return weEvent.getSuggestions();
|
return CommandUtil.fixSuggestions(arguments, weEvent.getSuggestions());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
ImmutableList.Builder<String> aliases = ImmutableList.builder();
|
ImmutableList.Builder<String> aliases = ImmutableList.builder();
|
||||||
|
@ -98,8 +98,6 @@ public class ConfigurateConfiguration extends LocalConfiguration {
|
|||||||
superPickaxeDrop = node.getNode("super-pickaxe", "drop-items").getBoolean(superPickaxeDrop);
|
superPickaxeDrop = node.getNode("super-pickaxe", "drop-items").getBoolean(superPickaxeDrop);
|
||||||
superPickaxeManyDrop = node.getNode("super-pickaxe", "many-drop-items").getBoolean(superPickaxeManyDrop);
|
superPickaxeManyDrop = node.getNode("super-pickaxe", "many-drop-items").getBoolean(superPickaxeManyDrop);
|
||||||
|
|
||||||
noDoubleSlash = node.getNode("no-double-slash").getBoolean(noDoubleSlash);
|
|
||||||
|
|
||||||
useInventory = node.getNode("use-inventory", "enable").getBoolean(useInventory);
|
useInventory = node.getNode("use-inventory", "enable").getBoolean(useInventory);
|
||||||
useInventoryOverride = node.getNode("use-inventory", "allow-override").getBoolean(useInventoryOverride);
|
useInventoryOverride = node.getNode("use-inventory", "allow-override").getBoolean(useInventoryOverride);
|
||||||
useInventoryCreativeOverride = node.getNode("use-inventory", "creative-mode-overrides").getBoolean(useInventoryCreativeOverride);
|
useInventoryCreativeOverride = node.getNode("use-inventory", "creative-mode-overrides").getBoolean(useInventoryCreativeOverride);
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren