mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-09 04:20:34 +01:00
Support sponge selector resolution - closes #275
This commit is contained in:
parent
cedc5108fc
commit
a5746dfa21
@ -35,13 +35,16 @@ import org.spongepowered.api.command.CommandCallable;
|
|||||||
import org.spongepowered.api.command.CommandException;
|
import org.spongepowered.api.command.CommandException;
|
||||||
import org.spongepowered.api.command.CommandResult;
|
import org.spongepowered.api.command.CommandResult;
|
||||||
import org.spongepowered.api.command.CommandSource;
|
import org.spongepowered.api.command.CommandSource;
|
||||||
|
import org.spongepowered.api.entity.living.player.Player;
|
||||||
import org.spongepowered.api.text.Text;
|
import org.spongepowered.api.text.Text;
|
||||||
|
import org.spongepowered.api.text.selector.Selector;
|
||||||
import org.spongepowered.api.world.Location;
|
import org.spongepowered.api.world.Location;
|
||||||
import org.spongepowered.api.world.World;
|
import org.spongepowered.api.world.World;
|
||||||
|
|
||||||
import co.aikar.timings.Timing;
|
import co.aikar.timings.Timing;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.ListIterator;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
@ -58,11 +61,29 @@ class SpongeCommand extends CommandManager implements CommandCallable {
|
|||||||
@Override
|
@Override
|
||||||
public CommandResult process(CommandSource source, String s) throws CommandException {
|
public CommandResult process(CommandSource source, String s) throws CommandException {
|
||||||
try (Timing ignored = plugin.getTimings().time(LPTiming.ON_COMMAND)) {
|
try (Timing ignored = plugin.getTimings().time(LPTiming.ON_COMMAND)) {
|
||||||
onCommand(
|
List<String> args = Util.stripQuotes(Splitter.on(COMMAND_SEPARATOR_PATTERN).omitEmptyStrings().splitToList(s));
|
||||||
plugin.getSenderFactory().wrap(source),
|
|
||||||
"lp",
|
// resolve selectors
|
||||||
Util.stripQuotes(Splitter.on(COMMAND_SEPARATOR_PATTERN).omitEmptyStrings().splitToList(s))
|
ListIterator<String> it = args.listIterator();
|
||||||
);
|
while (it.hasNext()) {
|
||||||
|
String element = it.next();
|
||||||
|
if (element.startsWith("@")) {
|
||||||
|
try {
|
||||||
|
Player ret = Selector.parse(element).resolve(source).stream()
|
||||||
|
.filter(e -> e instanceof Player)
|
||||||
|
.map(e -> ((Player) e))
|
||||||
|
.findFirst().orElse(null);
|
||||||
|
|
||||||
|
if (ret != null) {
|
||||||
|
it.set(ret.getUniqueId().toString());
|
||||||
|
}
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
// ignored
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onCommand(plugin.getSenderFactory().wrap(source), "lp", args);
|
||||||
return CommandResult.success();
|
return CommandResult.success();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user