mirror of
https://github.com/aikar/commands.git
synced 2026-05-31 06:11:55 +00:00
Merge pull request #437 from Intybyte/fix/sponge10-broken-contexts
Sponge8 fix broken SpongeCommandSource
This commit is contained in:
@@ -27,6 +27,7 @@ import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.api.entity.living.player.Player;
|
||||
import org.spongepowered.api.entity.living.player.server.ServerPlayer;
|
||||
import org.spongepowered.api.service.permission.Subject;
|
||||
import org.spongepowered.api.util.Identifiable;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@@ -45,11 +46,11 @@ public class SpongeCommandIssuer implements CommandIssuer {
|
||||
|
||||
@Override
|
||||
public boolean isPlayer() {
|
||||
return this.source instanceof Player;
|
||||
return getSubject() instanceof Player;
|
||||
}
|
||||
|
||||
public boolean isServerPlayer() {
|
||||
return this.source instanceof ServerPlayer;
|
||||
return getSubject() instanceof ServerPlayer;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -57,22 +58,26 @@ public class SpongeCommandIssuer implements CommandIssuer {
|
||||
return this.source;
|
||||
}
|
||||
|
||||
public Subject getSubject() {
|
||||
return source.commandCause().subject();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull UUID getUniqueId() {
|
||||
if (this.source instanceof Identifiable) {
|
||||
return ((Identifiable) source).uniqueId();
|
||||
if (getSubject() instanceof Identifiable) {
|
||||
return ((Identifiable) getSubject()).uniqueId();
|
||||
}
|
||||
|
||||
//generate a unique id based of the name (like for the console command sender)
|
||||
return UUID.nameUUIDFromBytes(source.commandCause().identifier().getBytes(StandardCharsets.UTF_8));
|
||||
return UUID.nameUUIDFromBytes(getSubject().identifier().getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return isPlayer() ? (Player) source : null;
|
||||
return isPlayer() ? (Player) getSubject() : null;
|
||||
}
|
||||
|
||||
public ServerPlayer getServerPlayer() {
|
||||
return isServerPlayer() ? (ServerPlayer) source : null;
|
||||
return isServerPlayer() ? (ServerPlayer) getSubject() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -89,7 +94,7 @@ public class SpongeCommandIssuer implements CommandIssuer {
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(final String permission) {
|
||||
return this.source.commandCause().hasPermission(permission);
|
||||
return getSubject().hasPermission(permission);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -34,12 +34,8 @@ import org.spongepowered.api.command.exception.CommandException;
|
||||
import org.spongepowered.api.command.parameter.ArgumentReader;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
@@ -105,33 +101,9 @@ public class SpongeRootCommand implements Command.Raw, RootCommand {
|
||||
@Override
|
||||
public List<CommandCompletion> complete(CommandCause cause, ArgumentReader.Mutable arguments) throws CommandException {
|
||||
String[] args = argToStrlist(arguments);
|
||||
return getTabCompletions(manager.getCommandIssuer(cause), this.name, args).stream().map(it -> new CommandCompletion() {
|
||||
@Override
|
||||
public String completion() {
|
||||
return it;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Component> tooltip() {
|
||||
return Optional.empty();
|
||||
}
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompletions(CommandIssuer sender, String alias, String[] args, boolean commandsOnly, boolean isAsync) {
|
||||
Set<String> completions = new HashSet<>();
|
||||
getChildren().forEach(child -> {
|
||||
if (!commandsOnly) {
|
||||
completions.addAll(child.tabComplete(sender, this, args, isAsync));
|
||||
}
|
||||
completions.addAll(child.getCommandsForCompletion(sender, args));
|
||||
});
|
||||
|
||||
return completions.stream()
|
||||
.filter(it -> Arrays
|
||||
.stream(args)
|
||||
.noneMatch(it::equals))
|
||||
return getTabCompletions(manager.getCommandIssuer(cause), this.name, args)
|
||||
.stream()
|
||||
.map(CommandCompletion::of)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@@ -158,8 +130,7 @@ public class SpongeRootCommand implements Command.Raw, RootCommand {
|
||||
}
|
||||
|
||||
private String[] argToStrlist(ArgumentReader.Mutable arguments) {
|
||||
return Arrays.stream(arguments.input().split(" "))
|
||||
.filter(string -> (!string.isEmpty()))
|
||||
.toArray(String[]::new);
|
||||
String input = arguments.input();
|
||||
return input.split(" ", - 1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user