mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-23 09:47:38 +00:00
parent
614f5e1c16
commit
5feac07bf0
@ -466,17 +466,13 @@ public class WorldEditPlugin extends JavaPlugin { //implements TabCompleter
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||
int plSep = commandLabel.indexOf(":");
|
||||
if (plSep >= 0 && plSep < commandLabel.length() + 1) {
|
||||
commandLabel = commandLabel.substring(plSep + 1);
|
||||
}
|
||||
// Add the command to the array because the underlying command handling
|
||||
// code of WorldEdit expects it
|
||||
String[] split = new String[args.length + 1];
|
||||
System.arraycopy(args, 0, split, 1, args.length);
|
||||
split[0] = commandLabel;
|
||||
|
||||
StringBuilder sb = new StringBuilder("/").append(commandLabel);
|
||||
if (args.length > 0) {
|
||||
sb.append(" ");
|
||||
}
|
||||
String arguments = Joiner.on(" ").appendTo(sb, args).toString();
|
||||
CommandEvent event = new CommandEvent(wrapCommandSender(sender), arguments);
|
||||
CommandEvent event = new CommandEvent(wrapCommandSender(sender), Joiner.on(" ").join(split));
|
||||
getWorldEdit().getEventBus().post(event);
|
||||
|
||||
return true;
|
||||
@ -657,24 +653,15 @@ public class WorldEditPlugin extends JavaPlugin { //implements TabCompleter
|
||||
String buffer = event.getBuffer();
|
||||
int firstSpace = buffer.indexOf(' ');
|
||||
if (firstSpace < 0) return;
|
||||
String label = buffer.substring(1, 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);
|
||||
}
|
||||
String label = buffer.substring(0, firstSpace);
|
||||
final Optional<org.enginehub.piston.Command> command
|
||||
= WorldEdit.getInstance().getPlatformManager().getPlatformCommandManager().getCommandManager().getCommand(label);
|
||||
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);
|
||||
|
||||
event.setCompletions(CommandUtil.fixSuggestions(buffer, suggestEvent.getSuggestions()));
|
||||
event.setCompletions(CommandUtil.fixSuggestions(event.getBuffer(), suggestEvent.getSuggestions()));
|
||||
event.setHandled(true);
|
||||
}
|
||||
}
|
||||
|
@ -600,6 +600,16 @@ public final class PlatformCommandManager {
|
||||
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) {
|
||||
ArgumentConverter<T> converter = commandManager.getConverter(Key.of(clazz)).orElse(null);
|
||||
if (converter != null) {
|
||||
@ -612,16 +622,19 @@ public final class PlatformCommandManager {
|
||||
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
|
||||
public void handleCommand(CommandEvent event) {
|
||||
Request.reset();
|
||||
Actor actor = event.getActor();
|
||||
String args;
|
||||
if (event.getArguments().length() > 1) {
|
||||
args = event.getArguments().substring(1);
|
||||
} else {
|
||||
args = event.getArguments();
|
||||
}
|
||||
String args = event.getArguments();
|
||||
TaskManager.IMP.taskNow(() -> {
|
||||
int space0 = args.indexOf(' ');
|
||||
String arg0 = space0 == -1 ? args : args.substring(0, space0);
|
||||
@ -694,12 +707,11 @@ public final class PlatformCommandManager {
|
||||
exceptionConverter.convert(next);
|
||||
next = next.getCause();
|
||||
} while (next != null);
|
||||
|
||||
throw t;
|
||||
}
|
||||
} catch (ConditionFailedException e) {
|
||||
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 {
|
||||
actor.print(e.getRichMessage());
|
||||
}
|
||||
@ -825,7 +837,6 @@ public final class PlatformCommandManager {
|
||||
}
|
||||
throw t;
|
||||
}
|
||||
|
||||
event.setSuggestions(suggestions.stream()
|
||||
.map(suggestion -> {
|
||||
int noSlashLength = arguments.length() - 1;
|
||||
|
Loading…
Reference in New Issue
Block a user