From 88857e015d3be6f894592204d76d8580eae0ac9b Mon Sep 17 00:00:00 2001 From: Luck Date: Wed, 17 Apr 2019 10:06:47 +0100 Subject: Fix permission checking --- .../src/main/java/me/lucko/spark/bukkit/SparkBukkitPlugin.java | 3 ++- .../src/main/java/me/lucko/spark/bungeecord/SparkBungeeCordPlugin.java | 3 ++- spark-common/src/main/java/me/lucko/spark/common/SparkPlugin.java | 2 +- .../java/me/lucko/spark/common/command/CommandResponseHandler.java | 2 +- .../src/main/java/me/lucko/spark/forge/ForgeClientSparkPlugin.java | 2 +- .../src/main/java/me/lucko/spark/forge/ForgeServerSparkPlugin.java | 3 ++- .../src/main/java/me/lucko/spark/sponge/SparkSpongePlugin.java | 3 ++- .../src/main/java/me/lucko/spark/velocity/SparkVelocityPlugin.java | 3 ++- 8 files changed, 13 insertions(+), 8 deletions(-) diff --git a/spark-bukkit/src/main/java/me/lucko/spark/bukkit/SparkBukkitPlugin.java b/spark-bukkit/src/main/java/me/lucko/spark/bukkit/SparkBukkitPlugin.java index 1fcb571..c713a2c 100644 --- a/spark-bukkit/src/main/java/me/lucko/spark/bukkit/SparkBukkitPlugin.java +++ b/spark-bukkit/src/main/java/me/lucko/spark/bukkit/SparkBukkitPlugin.java @@ -102,8 +102,9 @@ public class SparkBukkitPlugin extends JavaPlugin implements SparkPlugin getSenders() { + public Set getSendersWithPermission(String permission) { Set senders = new HashSet<>(getServer().getOnlinePlayers()); + senders.removeIf(sender -> !sender.hasPermission(permission)); senders.add(getServer().getConsoleSender()); return senders; } diff --git a/spark-bungeecord/src/main/java/me/lucko/spark/bungeecord/SparkBungeeCordPlugin.java b/spark-bungeecord/src/main/java/me/lucko/spark/bungeecord/SparkBungeeCordPlugin.java index 5c39d34..0bc118a 100644 --- a/spark-bungeecord/src/main/java/me/lucko/spark/bungeecord/SparkBungeeCordPlugin.java +++ b/spark-bungeecord/src/main/java/me/lucko/spark/bungeecord/SparkBungeeCordPlugin.java @@ -68,8 +68,9 @@ public class SparkBungeeCordPlugin extends Plugin implements SparkPlugin getSenders() { + public Set getSendersWithPermission(String permission) { Set senders = new HashSet<>(getProxy().getPlayers()); + senders.removeIf(sender -> !sender.hasPermission(permission)); senders.add(getProxy().getConsole()); return senders; } diff --git a/spark-common/src/main/java/me/lucko/spark/common/SparkPlugin.java b/spark-common/src/main/java/me/lucko/spark/common/SparkPlugin.java index 7a3a353..481a615 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/SparkPlugin.java +++ b/spark-common/src/main/java/me/lucko/spark/common/SparkPlugin.java @@ -34,7 +34,7 @@ public interface SparkPlugin { String getLabel(); - Set getSenders(); + Set getSendersWithPermission(String permission); void sendMessage(S sender, String message); diff --git a/spark-common/src/main/java/me/lucko/spark/common/command/CommandResponseHandler.java b/spark-common/src/main/java/me/lucko/spark/common/command/CommandResponseHandler.java index 0df2950..9d604bd 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/command/CommandResponseHandler.java +++ b/spark-common/src/main/java/me/lucko/spark/common/command/CommandResponseHandler.java @@ -43,7 +43,7 @@ public class CommandResponseHandler { } public void allSenders(Consumer action) { - Set senders = this.platform.getPlugin().getSenders(); + Set senders = this.platform.getPlugin().getSendersWithPermission("spark"); senders.add(this.sender); senders.forEach(action); } diff --git a/spark-forge/src/main/java/me/lucko/spark/forge/ForgeClientSparkPlugin.java b/spark-forge/src/main/java/me/lucko/spark/forge/ForgeClientSparkPlugin.java index 2c6c2fb..b214308 100644 --- a/spark-forge/src/main/java/me/lucko/spark/forge/ForgeClientSparkPlugin.java +++ b/spark-forge/src/main/java/me/lucko/spark/forge/ForgeClientSparkPlugin.java @@ -43,7 +43,7 @@ public class ForgeClientSparkPlugin extends ForgeSparkPlugin { } @Override - public Set getSenders() { + public Set getSendersWithPermission(String permission) { return new HashSet<>(Collections.singleton(Minecraft.getMinecraft().player)); } diff --git a/spark-forge/src/main/java/me/lucko/spark/forge/ForgeServerSparkPlugin.java b/spark-forge/src/main/java/me/lucko/spark/forge/ForgeServerSparkPlugin.java index 98740c0..167aa94 100644 --- a/spark-forge/src/main/java/me/lucko/spark/forge/ForgeServerSparkPlugin.java +++ b/spark-forge/src/main/java/me/lucko/spark/forge/ForgeServerSparkPlugin.java @@ -37,9 +37,10 @@ public class ForgeServerSparkPlugin extends ForgeSparkPlugin { } @Override - public Set getSenders() { + public Set getSendersWithPermission(String permission) { MinecraftServer mcServer = FMLCommonHandler.instance().getMinecraftServerInstance(); Set senders = new HashSet<>(mcServer.getPlayerList().getPlayers()); + senders.removeIf(sender -> !sender.canUseCommand(4, permission)); senders.add(mcServer); return senders; } diff --git a/spark-sponge/src/main/java/me/lucko/spark/sponge/SparkSpongePlugin.java b/spark-sponge/src/main/java/me/lucko/spark/sponge/SparkSpongePlugin.java index 6d0c56a..159cbc7 100644 --- a/spark-sponge/src/main/java/me/lucko/spark/sponge/SparkSpongePlugin.java +++ b/spark-sponge/src/main/java/me/lucko/spark/sponge/SparkSpongePlugin.java @@ -107,8 +107,9 @@ public class SparkSpongePlugin implements SparkPlugin { } @Override - public Set getSenders() { + public Set getSendersWithPermission(String permission) { Set senders = new HashSet<>(this.game.getServer().getOnlinePlayers()); + senders.removeIf(sender -> !sender.hasPermission(permission)); senders.add(this.game.getServer().getConsole()); return senders; } diff --git a/spark-velocity/src/main/java/me/lucko/spark/velocity/SparkVelocityPlugin.java b/spark-velocity/src/main/java/me/lucko/spark/velocity/SparkVelocityPlugin.java index fef48e7..749319d 100644 --- a/spark-velocity/src/main/java/me/lucko/spark/velocity/SparkVelocityPlugin.java +++ b/spark-velocity/src/main/java/me/lucko/spark/velocity/SparkVelocityPlugin.java @@ -103,8 +103,9 @@ public class SparkVelocityPlugin implements SparkPlugin, Command } @Override - public Set getSenders() { + public Set getSendersWithPermission(String permission) { Set senders = new HashSet<>(this.proxy.getAllPlayers()); + senders.removeIf(sender -> !sender.hasPermission(permission)); senders.add(this.proxy.getConsoleCommandSource()); return senders; } -- cgit