Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-12-25 18:40:05 +01:00
Update Piston for suggestions, add hacky-pseudo-suggestions
Dieser Commit ist enthalten in:
Ursprung
acc0e7d09c
Commit
4355f8cbf7
@ -20,6 +20,7 @@
|
|||||||
package com.sk89q.worldedit.extension.platform;
|
package com.sk89q.worldedit.extension.platform;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.reflect.TypeToken;
|
import com.google.common.reflect.TypeToken;
|
||||||
import com.sk89q.worldedit.EditSession;
|
import com.sk89q.worldedit.EditSession;
|
||||||
import com.sk89q.worldedit.IncompleteRegionException;
|
import com.sk89q.worldedit.IncompleteRegionException;
|
||||||
@ -85,13 +86,13 @@ import com.sk89q.worldedit.event.platform.CommandEvent;
|
|||||||
import com.sk89q.worldedit.event.platform.CommandSuggestionEvent;
|
import com.sk89q.worldedit.event.platform.CommandSuggestionEvent;
|
||||||
import com.sk89q.worldedit.extent.Extent;
|
import com.sk89q.worldedit.extent.Extent;
|
||||||
import com.sk89q.worldedit.internal.annotation.Selection;
|
import com.sk89q.worldedit.internal.annotation.Selection;
|
||||||
|
import com.sk89q.worldedit.internal.command.CommandArgParser;
|
||||||
import com.sk89q.worldedit.internal.command.CommandLoggingHandler;
|
import com.sk89q.worldedit.internal.command.CommandLoggingHandler;
|
||||||
|
import com.sk89q.worldedit.internal.command.CommandRegistrationHandler;
|
||||||
|
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.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.internal.command.CommandArgParser;
|
|
||||||
import com.sk89q.worldedit.internal.command.CommandRegistrationHandler;
|
|
||||||
import com.sk89q.worldedit.internal.command.exception.ExceptionConverter;
|
|
||||||
import com.sk89q.worldedit.util.eventbus.Subscribe;
|
import com.sk89q.worldedit.util.eventbus.Subscribe;
|
||||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||||
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
|
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
|
||||||
@ -116,6 +117,7 @@ import org.enginehub.piston.inject.MapBackedValueStore;
|
|||||||
import org.enginehub.piston.inject.MemoizingValueAccess;
|
import org.enginehub.piston.inject.MemoizingValueAccess;
|
||||||
import org.enginehub.piston.inject.MergedValueAccess;
|
import org.enginehub.piston.inject.MergedValueAccess;
|
||||||
import org.enginehub.piston.part.SubCommandPart;
|
import org.enginehub.piston.part.SubCommandPart;
|
||||||
|
import org.enginehub.piston.suggestion.Suggestion;
|
||||||
import org.enginehub.piston.util.HelpGenerator;
|
import org.enginehub.piston.util.HelpGenerator;
|
||||||
import org.enginehub.piston.util.ValueProvider;
|
import org.enginehub.piston.util.ValueProvider;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@ -123,6 +125,7 @@ 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.Locale;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@ -441,7 +444,9 @@ public final class PlatformCommandManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String[] parseArgs(String input) {
|
private String[] parseArgs(String input) {
|
||||||
return new CommandArgParser(input).parseArgs().toArray(String[]::new);
|
return commandDetection(new CommandArgParser(input.substring(1))
|
||||||
|
.parseArgs()
|
||||||
|
.toArray(String[]::new));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
@ -449,7 +454,7 @@ public final class PlatformCommandManager {
|
|||||||
Request.reset();
|
Request.reset();
|
||||||
|
|
||||||
Actor actor = platformManager.createProxyActor(event.getActor());
|
Actor actor = platformManager.createProxyActor(event.getActor());
|
||||||
String[] split = commandDetection(parseArgs(event.getArguments().substring(1)));
|
String[] split = parseArgs(event.getArguments());
|
||||||
|
|
||||||
// No command found!
|
// No command found!
|
||||||
if (!commandManager.containsCommand(split[0])) {
|
if (!commandManager.containsCommand(split[0])) {
|
||||||
@ -466,26 +471,7 @@ public final class PlatformCommandManager {
|
|||||||
}
|
}
|
||||||
LocalConfiguration config = worldEdit.getConfiguration();
|
LocalConfiguration config = worldEdit.getConfiguration();
|
||||||
|
|
||||||
InjectedValueStore store = MapBackedValueStore.create();
|
MemoizingValueAccess context = initializeInjectedValues(event::getArguments, actor);
|
||||||
store.injectValue(Key.of(Actor.class), ValueProvider.constant(actor));
|
|
||||||
if (actor instanceof Player) {
|
|
||||||
store.injectValue(Key.of(Player.class), ValueProvider.constant((Player) actor));
|
|
||||||
} else {
|
|
||||||
store.injectValue(Key.of(Player.class), context -> {
|
|
||||||
throw new CommandException(TextComponent.of("This command must be used with a player."), ImmutableList.of());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
store.injectValue(Key.of(Arguments.class), ValueProvider.constant(event::getArguments));
|
|
||||||
store.injectValue(Key.of(LocalSession.class),
|
|
||||||
context -> {
|
|
||||||
LocalSession localSession = worldEdit.getSessionManager().get(actor);
|
|
||||||
localSession.tellVersion(actor);
|
|
||||||
return Optional.of(localSession);
|
|
||||||
});
|
|
||||||
|
|
||||||
MemoizingValueAccess context = MemoizingValueAccess.wrap(
|
|
||||||
MergedValueAccess.of(store, globalInjectedValues)
|
|
||||||
);
|
|
||||||
|
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
|
|
||||||
@ -563,6 +549,29 @@ public final class PlatformCommandManager {
|
|||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private MemoizingValueAccess initializeInjectedValues(Arguments arguments, Actor actor) {
|
||||||
|
InjectedValueStore store = MapBackedValueStore.create();
|
||||||
|
store.injectValue(Key.of(Actor.class), ValueProvider.constant(actor));
|
||||||
|
if (actor instanceof Player) {
|
||||||
|
store.injectValue(Key.of(Player.class), ValueProvider.constant((Player) actor));
|
||||||
|
} else {
|
||||||
|
store.injectValue(Key.of(Player.class), context -> {
|
||||||
|
throw new CommandException(TextComponent.of("This command must be used with a player."), ImmutableList.of());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
store.injectValue(Key.of(Arguments.class), ValueProvider.constant(arguments));
|
||||||
|
store.injectValue(Key.of(LocalSession.class),
|
||||||
|
context -> {
|
||||||
|
LocalSession localSession = worldEdit.getSessionManager().get(actor);
|
||||||
|
localSession.tellVersion(actor);
|
||||||
|
return Optional.of(localSession);
|
||||||
|
});
|
||||||
|
|
||||||
|
return MemoizingValueAccess.wrap(
|
||||||
|
MergedValueAccess.of(store, globalInjectedValues)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
private void handleUnknownException(Actor actor, Throwable t) {
|
private void handleUnknownException(Actor actor, Throwable t) {
|
||||||
actor.printError("Please report this error: [See console]");
|
actor.printError("Please report this error: [See console]");
|
||||||
actor.printRaw(t.getClass().getName() + ": " + t.getMessage());
|
actor.printRaw(t.getClass().getName() + ": " + t.getMessage());
|
||||||
@ -572,9 +581,13 @@ public final class PlatformCommandManager {
|
|||||||
@Subscribe
|
@Subscribe
|
||||||
public void handleCommandSuggestion(CommandSuggestionEvent event) {
|
public void handleCommandSuggestion(CommandSuggestionEvent event) {
|
||||||
try {
|
try {
|
||||||
globalInjectedValues.injectValue(Key.of(Actor.class), ValueProvider.constant(event.getActor()));
|
String[] split = parseArgs(event.getArguments());
|
||||||
globalInjectedValues.injectValue(Key.of(Arguments.class), ValueProvider.constant(event::getArguments));
|
MemoizingValueAccess access = initializeInjectedValues(event::getArguments, event.getActor());
|
||||||
// TODO suggestions
|
ImmutableSet<Suggestion> suggestions = commandManager.getSuggestions(access, Arrays.asList(split));
|
||||||
|
|
||||||
|
log.debug("For input: {}", event.getArguments());
|
||||||
|
log.debug("I would suggest this: {}", suggestions);
|
||||||
|
// TODO send back suggestions
|
||||||
} catch (CommandException e) {
|
} catch (CommandException e) {
|
||||||
event.getActor().printError(e.getMessage());
|
event.getActor().printError(e.getMessage());
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,7 @@ configure(subprojects + project("core:ap")) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
project("core") {
|
project("core") {
|
||||||
def pistonVersion = '0.1.1'
|
def pistonVersion = '0.1.2'
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
shade 'net.kyori:text-api:2.0.0'
|
shade 'net.kyori:text-api:2.0.0'
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren