Revert "Fixed commands not working"

This reverts commit 0b5eb903
Dieser Commit ist enthalten in:
MattBDev 2020-02-06 20:26:04 -05:00
Ursprung 614f5e1c16
Commit 5feac07bf0
2 geänderte Dateien mit 29 neuen und 31 gelöschten Zeilen

Datei anzeigen

@ -466,17 +466,13 @@ public class WorldEditPlugin extends JavaPlugin { //implements TabCompleter
@Override @Override
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
int plSep = commandLabel.indexOf(":"); // Add the command to the array because the underlying command handling
if (plSep >= 0 && plSep < commandLabel.length() + 1) { // code of WorldEdit expects it
commandLabel = commandLabel.substring(plSep + 1); String[] split = new String[args.length + 1];
} System.arraycopy(args, 0, split, 1, args.length);
split[0] = commandLabel;
StringBuilder sb = new StringBuilder("/").append(commandLabel); CommandEvent event = new CommandEvent(wrapCommandSender(sender), Joiner.on(" ").join(split));
if (args.length > 0) {
sb.append(" ");
}
String arguments = Joiner.on(" ").appendTo(sb, args).toString();
CommandEvent event = new CommandEvent(wrapCommandSender(sender), arguments);
getWorldEdit().getEventBus().post(event); getWorldEdit().getEventBus().post(event);
return true; return true;
@ -657,24 +653,15 @@ public class WorldEditPlugin extends JavaPlugin { //implements TabCompleter
String buffer = event.getBuffer(); String buffer = event.getBuffer();
int firstSpace = buffer.indexOf(' '); int firstSpace = buffer.indexOf(' ');
if (firstSpace < 0) return; if (firstSpace < 0) return;
String label = buffer.substring(1, firstSpace); String label = buffer.substring(0, firstSpace);
Plugin owner = server.getDynamicCommands().getCommandOwner(label);
if (owner != WorldEditPlugin.this) {
return;
}
int plSep = label.indexOf(":");
if (plSep >= 0 && plSep < label.length() + 1) {
label = label.substring(plSep + 1);
buffer = "/" + buffer.substring(plSep + 2);
}
final Optional<org.enginehub.piston.Command> command final Optional<org.enginehub.piston.Command> command
= WorldEdit.getInstance().getPlatformManager().getPlatformCommandManager().getCommandManager().getCommand(label); = WorldEdit.getInstance().getPlatformManager().getPlatformCommandManager().getCommandManager().getCommand(label);
if (!command.isPresent()) return; if (!command.isPresent()) return;
CommandSuggestionEvent suggestEvent = new CommandSuggestionEvent(wrapCommandSender(event.getSender()), buffer); CommandSuggestionEvent suggestEvent = new CommandSuggestionEvent(wrapCommandSender(event.getSender()), event.getBuffer());
getWorldEdit().getEventBus().post(suggestEvent); getWorldEdit().getEventBus().post(suggestEvent);
event.setCompletions(CommandUtil.fixSuggestions(buffer, suggestEvent.getSuggestions())); event.setCompletions(CommandUtil.fixSuggestions(event.getBuffer(), suggestEvent.getSuggestions()));
event.setHandled(true); event.setHandled(true);
} }
} }

Datei anzeigen

@ -600,6 +600,16 @@ public final class PlatformCommandManager {
return CommandArgParser.forArgString(input).parseArgs(); return CommandArgParser.forArgString(input).parseArgs();
} }
public int parseCommand(String args, Actor actor) {
InjectedValueAccess context;
if (actor == null) {
context = globalInjectedValues;
} else {
context = initializeInjectedValues(args::toString, actor, null);
}
return parseCommand(args, context);
}
public <T> T parseConverter(String args, InjectedValueAccess access, Class<T> clazz) { public <T> T parseConverter(String args, InjectedValueAccess access, Class<T> clazz) {
ArgumentConverter<T> converter = commandManager.getConverter(Key.of(clazz)).orElse(null); ArgumentConverter<T> converter = commandManager.getConverter(Key.of(clazz)).orElse(null);
if (converter != null) { if (converter != null) {
@ -612,16 +622,19 @@ public final class PlatformCommandManager {
return null; return null;
} }
public int parseCommand(String args, InjectedValueAccess access) {
if (args.isEmpty()) return 0;
String[] split = parseArgs(args)
.map(Substring::getSubstring)
.toArray(String[]::new);
return commandManager.execute(access, ImmutableList.copyOf(split));
}
@Subscribe @Subscribe
public void handleCommand(CommandEvent event) { public void handleCommand(CommandEvent event) {
Request.reset(); Request.reset();
Actor actor = event.getActor(); Actor actor = event.getActor();
String args; String args = event.getArguments();
if (event.getArguments().length() > 1) {
args = event.getArguments().substring(1);
} else {
args = event.getArguments();
}
TaskManager.IMP.taskNow(() -> { TaskManager.IMP.taskNow(() -> {
int space0 = args.indexOf(' '); int space0 = args.indexOf(' ');
String arg0 = space0 == -1 ? args : args.substring(0, space0); String arg0 = space0 == -1 ? args : args.substring(0, space0);
@ -694,12 +707,11 @@ public final class PlatformCommandManager {
exceptionConverter.convert(next); exceptionConverter.convert(next);
next = next.getCause(); next = next.getCause();
} while (next != null); } while (next != null);
throw t; throw t;
} }
} catch (ConditionFailedException e) { } catch (ConditionFailedException e) {
if (e.getCondition() instanceof PermissionCondition) { if (e.getCondition() instanceof PermissionCondition) {
actor.printError(TranslatableComponent.of("worldedit.command.permissions")); actor.printError(Caption.of("fawe.error.no.perm", StringMan.getString(((PermissionCondition) e.getCondition()).getPermissions())));
} else { } else {
actor.print(e.getRichMessage()); actor.print(e.getRichMessage());
} }
@ -825,7 +837,6 @@ public final class PlatformCommandManager {
} }
throw t; throw t;
} }
event.setSuggestions(suggestions.stream() event.setSuggestions(suggestions.stream()
.map(suggestion -> { .map(suggestion -> {
int noSlashLength = arguments.length() - 1; int noSlashLength = arguments.length() - 1;