diff --git a/spark-common/src/main/java/me/lucko/spark/common/SparkPlatform.java b/spark-common/src/main/java/me/lucko/spark/common/SparkPlatform.java index 919fb952..bedc605f 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/SparkPlatform.java +++ b/spark-common/src/main/java/me/lucko/spark/common/SparkPlatform.java @@ -74,12 +74,14 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.concurrent.CompletableFuture; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.locks.ReentrantLock; import java.util.logging.Level; import java.util.stream.Collectors; +import java.util.stream.Stream; import static net.kyori.adventure.text.Component.space; import static net.kyori.adventure.text.Component.text; @@ -341,6 +343,15 @@ private List getAvailableCommands(CommandSender sender) { .collect(Collectors.toList()); } + public Set getAllSparkPermissions() { + return Stream.concat( + Stream.of("spark"), + this.commands.stream() + .map(Command::primaryAlias) + .map(alias -> "spark." + alias) + ).collect(Collectors.toSet()); + } + public boolean hasPermissionForAnyCommand(CommandSender sender) { return !getAvailableCommands(sender).isEmpty(); } diff --git a/spark-paper/src/main/java/me/lucko/spark/paper/PaperSparkPlugin.java b/spark-paper/src/main/java/me/lucko/spark/paper/PaperSparkPlugin.java index eb82f8e6..d70d5dbc 100644 --- a/spark-paper/src/main/java/me/lucko/spark/paper/PaperSparkPlugin.java +++ b/spark-paper/src/main/java/me/lucko/spark/paper/PaperSparkPlugin.java @@ -90,6 +90,16 @@ public List tabComplete(CommandSender sender, String[] args) { return this.platform.tabCompleteCommand(new PaperCommandSender(sender), args); } + @Override + public boolean hasPermission(CommandSender sender) { + return this.platform.hasPermissionForAnyCommand(new PaperCommandSender(sender)); + } + + @Override + public Collection getPermissions() { + return this.platform.getAllSparkPermissions(); + } + @Override public void onServerTickStart() { this.tickHook.onTick(); diff --git a/spark-paper/src/main/java/me/lucko/spark/paper/api/PaperSparkModule.java b/spark-paper/src/main/java/me/lucko/spark/paper/api/PaperSparkModule.java index 011841d2..e7964382 100644 --- a/spark-paper/src/main/java/me/lucko/spark/paper/api/PaperSparkModule.java +++ b/spark-paper/src/main/java/me/lucko/spark/paper/api/PaperSparkModule.java @@ -24,7 +24,9 @@ import org.bukkit.Server; import org.bukkit.command.CommandSender; +import java.util.Collection; import java.util.List; +import java.util.Set; import java.util.logging.Logger; /** @@ -94,6 +96,21 @@ static PaperSparkModule create(Compatibility compatibility, Server server, Logge */ List tabComplete(CommandSender sender, String[] args); + /** + * Gets if the sender has permission to execute any spark commands. + * + * @param sender the sender + * @return if the sender has permission + */ + boolean hasPermission(CommandSender sender); + + /** + * Gets a collection of all known spark permissions. + * + * @return a set of permissions + */ + Collection getPermissions(); + /** * Called by Paper at the start of each server tick. */