mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2026-11-18 13:49:18 +00:00
Move stuff into commons, rename PermissionObject, add more javadocs to api
This commit is contained in:
38 files changed
+516
-388
No files matched your search
@@ -1,7 +1,7 @@
|
||||
package me.lucko.luckperms;
|
||||
|
||||
import me.lucko.luckperms.commands.CommandManager;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SenderFactory;
|
||||
import me.lucko.luckperms.utils.Patterns;
|
||||
import org.spongepowered.api.command.CommandCallable;
|
||||
import org.spongepowered.api.command.CommandException;
|
||||
@@ -10,65 +10,59 @@ import org.spongepowered.api.command.CommandSource;
|
||||
import org.spongepowered.api.text.Text;
|
||||
import org.spongepowered.api.text.serializer.TextSerializers;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class SpongeCommand extends CommandManager implements CommandCallable {
|
||||
public SpongeCommand(LuckPermsPlugin plugin) {
|
||||
class SpongeCommand extends CommandManager implements CommandCallable {
|
||||
private static final Factory FACTORY = new Factory();
|
||||
|
||||
SpongeCommand(LuckPermsPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult process(CommandSource source, String s) throws CommandException {
|
||||
onCommand(makeSender(source), "perms", Arrays.asList(Patterns.SPACE_SPLIT.split(s)));
|
||||
onCommand(FACTORY.wrap(source), "perms", Arrays.asList(Patterns.SPACE.split(s)));
|
||||
return CommandResult.success();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getSuggestions(CommandSource source, String s) throws CommandException {
|
||||
return onTabComplete(makeSender(source), Arrays.asList(Patterns.SPACE_SPLIT.split(s)));
|
||||
return onTabComplete(FACTORY.wrap(source), Arrays.asList(Patterns.SPACE.split(s)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean testPermission(CommandSource commandSource) {
|
||||
public boolean testPermission(CommandSource source) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<? extends Text> getShortDescription(CommandSource commandSource) {
|
||||
public Optional<? extends Text> getShortDescription(CommandSource source) {
|
||||
return Optional.of(Text.of("LuckPerms main command."));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<? extends Text> getHelp(CommandSource commandSource) {
|
||||
public Optional<? extends Text> getHelp(CommandSource source) {
|
||||
return Optional.of(Text.of("Type /perms for help."));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Text getUsage(CommandSource commandSource) {
|
||||
public Text getUsage(CommandSource source) {
|
||||
return Text.of("/perms");
|
||||
}
|
||||
|
||||
private static Sender makeSender(CommandSource source) {
|
||||
return new Sender() {
|
||||
final WeakReference<CommandSource> cs = new WeakReference<>(source);
|
||||
private static class Factory extends SenderFactory<CommandSource> {
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void sendMessage(String s) {
|
||||
final CommandSource c = cs.get();
|
||||
if (c != null) {
|
||||
c.sendMessage(TextSerializers.LEGACY_FORMATTING_CODE.deserialize(s));
|
||||
}
|
||||
}
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
protected void sendMessage(CommandSource source, String s) {
|
||||
source.sendMessage(TextSerializers.LEGACY_FORMATTING_CODE.deserialize(s));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(String node) {
|
||||
final CommandSource c = cs.get();
|
||||
return c != null && c.hasPermission(node);
|
||||
}
|
||||
};
|
||||
@Override
|
||||
protected boolean hasPermission(CommandSource source, String node) {
|
||||
return source.hasPermission(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user