From 38d5ee334d1e142c3f894a4937024b0dfc021956 Mon Sep 17 00:00:00 2001 From: Rubenicos <44579213+Rubenicos@users.noreply.github.com> Date: Sat, 11 May 2024 14:44:48 -0600 Subject: [PATCH] Add individual permissions --- .../java/com/moulberry/axiom/AxiomPaper.java | 17 +++++- .../BlueprintRequestPacketListener.java | 2 +- .../packet/DeleteEntityPacketListener.java | 6 +- .../ManipulateEntityPacketListener.java | 6 +- .../MarkerNbtRequestPacketListener.java | 6 +- .../RequestChunkDataPacketListener.java | 2 +- .../packet/SetBlockBufferPacketListener.java | 4 +- .../axiom/packet/SetBlockPacketListener.java | 2 +- .../packet/SetEditorViewsPacketListener.java | 2 +- .../packet/SetFlySpeedPacketListener.java | 2 +- .../packet/SetGamemodePacketListener.java | 2 +- .../packet/SetHotbarSlotPacketListener.java | 2 +- .../axiom/packet/SetTimePacketListener.java | 2 +- .../packet/SetWorldPropertyListener.java | 2 +- .../packet/SpawnEntityPacketListener.java | 6 +- .../SwitchActiveHotbarPacketListener.java | 2 +- .../axiom/packet/TeleportPacketListener.java | 2 +- .../packet/UploadBlueprintPacketListener.java | 2 +- src/main/resources/plugin.yml | 55 ++++++++++++++++--- 19 files changed, 81 insertions(+), 43 deletions(-) diff --git a/src/main/java/com/moulberry/axiom/AxiomPaper.java b/src/main/java/com/moulberry/axiom/AxiomPaper.java index 8da16c2..82b22cd 100644 --- a/src/main/java/com/moulberry/axiom/AxiomPaper.java +++ b/src/main/java/com/moulberry/axiom/AxiomPaper.java @@ -304,11 +304,24 @@ public class AxiomPaper extends JavaPlugin implements Listener { } public boolean hasAxiomPermission(Player player) { - return player.hasPermission("axiom.*") || player.isOp(); + return hasAxiomPermission(player, null); + } + + public boolean hasAxiomPermission(Player player, String permission) { + if (player.hasPermission("axiom.*") || player.isOp()) { + return true; + } else if (permission != null && !player.hasPermission(permission)) { + return false; + } + return player.hasPermission("axiom.use"); } public boolean canUseAxiom(Player player) { - return hasAxiomPermission(player) && activeAxiomPlayers.contains(player.getUniqueId()); + return canUseAxiom(player, null); + } + + public boolean canUseAxiom(Player player, String permission) { + return activeAxiomPlayers.contains(player.getUniqueId()) && hasAxiomPermission(player, permission); } public @Nullable RateLimiter getBlockBufferRateLimiter(UUID uuid) { diff --git a/src/main/java/com/moulberry/axiom/packet/BlueprintRequestPacketListener.java b/src/main/java/com/moulberry/axiom/packet/BlueprintRequestPacketListener.java index 6d3741e..8b920e0 100644 --- a/src/main/java/com/moulberry/axiom/packet/BlueprintRequestPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/BlueprintRequestPacketListener.java @@ -36,7 +36,7 @@ public class BlueprintRequestPacketListener implements PluginMessageListener { } private void process(Player player, byte[] message) { - if (!this.plugin.canUseAxiom(player)) { + if (!this.plugin.canUseAxiom(player, "axiom.blueprint.request")) { return; } diff --git a/src/main/java/com/moulberry/axiom/packet/DeleteEntityPacketListener.java b/src/main/java/com/moulberry/axiom/packet/DeleteEntityPacketListener.java index bfddcb0..3e4d413 100644 --- a/src/main/java/com/moulberry/axiom/packet/DeleteEntityPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/DeleteEntityPacketListener.java @@ -35,11 +35,7 @@ public class DeleteEntityPacketListener implements PluginMessageListener { } private void process(Player player, byte[] message) { - if (!this.plugin.canUseAxiom(player)) { - return; - } - - if (!player.hasPermission("axiom.entity.*") && !player.hasPermission("axiom.entity.delete")) { + if (!this.plugin.canUseAxiom(player, "axiom.entity.delete")) { return; } diff --git a/src/main/java/com/moulberry/axiom/packet/ManipulateEntityPacketListener.java b/src/main/java/com/moulberry/axiom/packet/ManipulateEntityPacketListener.java index af926a5..2323a7e 100644 --- a/src/main/java/com/moulberry/axiom/packet/ManipulateEntityPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/ManipulateEntityPacketListener.java @@ -90,11 +90,7 @@ public class ManipulateEntityPacketListener implements PluginMessageListener { } private void process(Player player, byte[] message) { - if (!this.plugin.canUseAxiom(player)) { - return; - } - - if (!player.hasPermission("axiom.entity.*") && !player.hasPermission("axiom.entity.manipulate")) { + if (!this.plugin.canUseAxiom(player, "axiom.entity.manipulate")) { return; } diff --git a/src/main/java/com/moulberry/axiom/packet/MarkerNbtRequestPacketListener.java b/src/main/java/com/moulberry/axiom/packet/MarkerNbtRequestPacketListener.java index 1856c13..516dfa5 100644 --- a/src/main/java/com/moulberry/axiom/packet/MarkerNbtRequestPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/MarkerNbtRequestPacketListener.java @@ -33,11 +33,7 @@ public class MarkerNbtRequestPacketListener implements PluginMessageListener { } private void process(Player player, byte[] message) { - if (!this.plugin.canUseAxiom(player)) { - return; - } - - if (!player.hasPermission("axiom.entity.*") && !player.hasPermission("axiom.entity.manipulate")) { + if (!this.plugin.canUseAxiom(player, "axiom.entity.manipulate")) { return; } diff --git a/src/main/java/com/moulberry/axiom/packet/RequestChunkDataPacketListener.java b/src/main/java/com/moulberry/axiom/packet/RequestChunkDataPacketListener.java index 0aae6cd..b538c44 100644 --- a/src/main/java/com/moulberry/axiom/packet/RequestChunkDataPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/RequestChunkDataPacketListener.java @@ -56,7 +56,7 @@ public class RequestChunkDataPacketListener implements PluginMessageListener { FriendlyByteBuf friendlyByteBuf = new FriendlyByteBuf(Unpooled.wrappedBuffer(message)); long id = friendlyByteBuf.readLong(); - if (!this.plugin.canUseAxiom(bukkitPlayer) || this.plugin.isMismatchedDataVersion(bukkitPlayer.getUniqueId())) { + if (!this.plugin.canUseAxiom(bukkitPlayer, "axiom.chunk.request") || this.plugin.isMismatchedDataVersion(bukkitPlayer.getUniqueId())) { // We always send an 'empty' response in order to make the client happy sendEmptyResponse(player, id); return; diff --git a/src/main/java/com/moulberry/axiom/packet/SetBlockBufferPacketListener.java b/src/main/java/com/moulberry/axiom/packet/SetBlockBufferPacketListener.java index e2c8d27..5c54b10 100644 --- a/src/main/java/com/moulberry/axiom/packet/SetBlockBufferPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/SetBlockBufferPacketListener.java @@ -125,7 +125,7 @@ public class SetBlockBufferPacketListener { ServerLevel world = player.serverLevel(); if (!world.dimension().equals(worldKey)) return; - if (!this.plugin.canUseAxiom(player.getBukkitEntity())) { + if (!this.plugin.canUseAxiom(player.getBukkitEntity(), "axiom.build.section")) { return; } @@ -325,7 +325,7 @@ public class SetBlockBufferPacketListener { ServerLevel world = player.serverLevel(); if (!world.dimension().equals(worldKey)) return; - if (!this.plugin.canUseAxiom(player.getBukkitEntity())) { + if (!this.plugin.canUseAxiom(player.getBukkitEntity(), "axiom.build.section")) { return; } diff --git a/src/main/java/com/moulberry/axiom/packet/SetBlockPacketListener.java b/src/main/java/com/moulberry/axiom/packet/SetBlockPacketListener.java index 860cb65..0bf6d59 100644 --- a/src/main/java/com/moulberry/axiom/packet/SetBlockPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/SetBlockPacketListener.java @@ -79,7 +79,7 @@ public class SetBlockPacketListener implements PluginMessageListener { } private void process(Player bukkitPlayer, byte[] message) { - if (!this.plugin.canUseAxiom(bukkitPlayer)) { + if (!this.plugin.canUseAxiom(bukkitPlayer, "axiom.build.place")) { return; } diff --git a/src/main/java/com/moulberry/axiom/packet/SetEditorViewsPacketListener.java b/src/main/java/com/moulberry/axiom/packet/SetEditorViewsPacketListener.java index 4bfc76f..e718080 100644 --- a/src/main/java/com/moulberry/axiom/packet/SetEditorViewsPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/SetEditorViewsPacketListener.java @@ -35,7 +35,7 @@ public class SetEditorViewsPacketListener implements PluginMessageListener { } private void process(Player player, byte[] message) { - if (!this.plugin.canUseAxiom(player)) { + if (!this.plugin.canUseAxiom(player, "axiom.editor.views")) { return; } diff --git a/src/main/java/com/moulberry/axiom/packet/SetFlySpeedPacketListener.java b/src/main/java/com/moulberry/axiom/packet/SetFlySpeedPacketListener.java index e488f3b..421e745 100644 --- a/src/main/java/com/moulberry/axiom/packet/SetFlySpeedPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/SetFlySpeedPacketListener.java @@ -28,7 +28,7 @@ public class SetFlySpeedPacketListener implements PluginMessageListener { } private void process(Player player, byte[] message) { - if (!this.plugin.canUseAxiom(player)) { + if (!this.plugin.canUseAxiom(player, "axiom.player.speed")) { return; } diff --git a/src/main/java/com/moulberry/axiom/packet/SetGamemodePacketListener.java b/src/main/java/com/moulberry/axiom/packet/SetGamemodePacketListener.java index be24422..de1c535 100644 --- a/src/main/java/com/moulberry/axiom/packet/SetGamemodePacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/SetGamemodePacketListener.java @@ -30,7 +30,7 @@ public class SetGamemodePacketListener implements PluginMessageListener { } private void process(Player player, byte[] message) { - if (!this.plugin.canUseAxiom(player)) { + if (!this.plugin.canUseAxiom(player, "axiom.player.gamemode")) { return; } diff --git a/src/main/java/com/moulberry/axiom/packet/SetHotbarSlotPacketListener.java b/src/main/java/com/moulberry/axiom/packet/SetHotbarSlotPacketListener.java index 685a7f0..f8a1a67 100644 --- a/src/main/java/com/moulberry/axiom/packet/SetHotbarSlotPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/SetHotbarSlotPacketListener.java @@ -35,7 +35,7 @@ public class SetHotbarSlotPacketListener implements PluginMessageListener { } private void process(Player player, byte[] message) { - if (!this.plugin.canUseAxiom(player) || this.plugin.isMismatchedDataVersion(player.getUniqueId())) { + if (!this.plugin.canUseAxiom(player, "axiom.player.hotbar") || this.plugin.isMismatchedDataVersion(player.getUniqueId())) { return; } diff --git a/src/main/java/com/moulberry/axiom/packet/SetTimePacketListener.java b/src/main/java/com/moulberry/axiom/packet/SetTimePacketListener.java index a3b0c7b..f1bca47 100644 --- a/src/main/java/com/moulberry/axiom/packet/SetTimePacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/SetTimePacketListener.java @@ -34,7 +34,7 @@ public class SetTimePacketListener implements PluginMessageListener { } private void process(Player player, byte[] message) { - if (!this.plugin.canUseAxiom(player)) { + if (!this.plugin.canUseAxiom(player, "axiom.world.time")) { return; } diff --git a/src/main/java/com/moulberry/axiom/packet/SetWorldPropertyListener.java b/src/main/java/com/moulberry/axiom/packet/SetWorldPropertyListener.java index 5b23f3d..73bd459 100644 --- a/src/main/java/com/moulberry/axiom/packet/SetWorldPropertyListener.java +++ b/src/main/java/com/moulberry/axiom/packet/SetWorldPropertyListener.java @@ -29,7 +29,7 @@ public class SetWorldPropertyListener implements PluginMessageListener { } private void process(Player player, byte[] message) { - if (!this.plugin.canUseAxiom(player)) { + if (!this.plugin.canUseAxiom(player, "axiom.world.property")) { return; } diff --git a/src/main/java/com/moulberry/axiom/packet/SpawnEntityPacketListener.java b/src/main/java/com/moulberry/axiom/packet/SpawnEntityPacketListener.java index b643781..3714440 100644 --- a/src/main/java/com/moulberry/axiom/packet/SpawnEntityPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/SpawnEntityPacketListener.java @@ -55,11 +55,7 @@ public class SpawnEntityPacketListener implements PluginMessageListener { } private void process(Player player, byte[] message) { - if (!this.plugin.canUseAxiom(player)) { - return; - } - - if (!player.hasPermission("axiom.entity.*") && !player.hasPermission("axiom.entity.spawn")) { + if (!this.plugin.canUseAxiom(player, "axiom.entity.spawn")) { return; } diff --git a/src/main/java/com/moulberry/axiom/packet/SwitchActiveHotbarPacketListener.java b/src/main/java/com/moulberry/axiom/packet/SwitchActiveHotbarPacketListener.java index 90a7338..f1056ef 100644 --- a/src/main/java/com/moulberry/axiom/packet/SwitchActiveHotbarPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/SwitchActiveHotbarPacketListener.java @@ -36,7 +36,7 @@ public class SwitchActiveHotbarPacketListener implements PluginMessageListener { } private void process(Player player, byte[] message) { - if (!this.plugin.canUseAxiom(player) || this.plugin.isMismatchedDataVersion(player.getUniqueId())) { + if (!this.plugin.canUseAxiom(player, "axiom.player.hotbar") || this.plugin.isMismatchedDataVersion(player.getUniqueId())) { return; } diff --git a/src/main/java/com/moulberry/axiom/packet/TeleportPacketListener.java b/src/main/java/com/moulberry/axiom/packet/TeleportPacketListener.java index cdb93b5..dfbeb82 100644 --- a/src/main/java/com/moulberry/axiom/packet/TeleportPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/TeleportPacketListener.java @@ -33,7 +33,7 @@ public class TeleportPacketListener implements PluginMessageListener { } private void process(Player player, byte[] message) { - if (!this.plugin.canUseAxiom(player)) { + if (!this.plugin.canUseAxiom(player, "axiom.world.teleport")) { return; } diff --git a/src/main/java/com/moulberry/axiom/packet/UploadBlueprintPacketListener.java b/src/main/java/com/moulberry/axiom/packet/UploadBlueprintPacketListener.java index 96b63b9..0a6d2eb 100644 --- a/src/main/java/com/moulberry/axiom/packet/UploadBlueprintPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/UploadBlueprintPacketListener.java @@ -24,7 +24,7 @@ public class UploadBlueprintPacketListener { } public void onReceive(ServerPlayer serverPlayer, FriendlyByteBuf friendlyByteBuf) { - if (!this.plugin.canUseAxiom(serverPlayer.getBukkitEntity())) { + if (!this.plugin.canUseAxiom(serverPlayer.getBukkitEntity(), "axiom.blueprint.upload")) { return; } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 8e00fc0..0adda57 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -5,23 +5,64 @@ description: $description authors: - Moulberry api-version: "$apiVersion" -softdepend: ["CoreProtect"] +softdepend: + - ViaVersion + - WorldGuard + - PlotSquared permissions: axiom.*: description: Allows use of all default Axiom features default: op + axiom.use: + description: Allows basic use of axiom + default: op axiom.debug: description: Allows use of the /axiompaperdebug command default: op axiom.entity.*: description: Allows use of all entity-related features (spawning, manipulating, deleting) default: op - axiom.entity.spawn: - description: Allows entity spawning - axiom.entity.manipulate: - description: Allows entity manipulation - axiom.entity.delete: - description: Allows entity deletion + children: + axiom.entity.spawn: true + axiom.entity.manipulate: true + axiom.entity.delete: true + axiom.blueprint.*: + description: Allows use of all blueprint-related features + default: op + children: + axiom.blueprint.upload: true + axiom.blueprint.request: true + axiom.blueprint.manifest: true + axiom.chunk.*: + description: Allows use of all chunk-related features + default: op + children: + axiom.chunk.request: true + axiom.build.*: + description: Allows use of all build-related features + default: op + children: + axiom.build.place: true + axiom.build.section: true + axiom.editor.*: + description: Allows use of all editor-related features + default: op + children: + axiom.editor.views: true + axiom.player.*: + description: Allows use of all player-related features + default: op + children: + axiom.player.speed: true + axiom.player.gamemode: true + axiom.player.hotbar: true + axiom.world.*: + description: Allows use of all world-related features + default: op + children: + axiom.world.time: true + axiom.world.property: true + axiom.world.teleport: true axiom.allow_copying_other_plots: description: This permission allows users to copy other user's plots