From e13a2f1ff670aa1ea9faf088cc37515d83ad9c9b Mon Sep 17 00:00:00 2001 From: William Blake Galbreath Date: Sat, 11 Jan 2025 18:22:32 -0800 Subject: [PATCH] Gamemode extra permissions --- .../0152-Gamemode-extra-permissions.patch | 94 ------------------- .../commands/CommandSourceStack.java.patch | 28 +++++- .../commands/GameModeCommand.java.patch | 21 +++++ .../permissions/CommandPermissions.java.patch | 19 ++++ .../org/purpurmc/purpur/PurpurConfig.java | 2 + 5 files changed, 66 insertions(+), 98 deletions(-) delete mode 100644 patches/server/0152-Gamemode-extra-permissions.patch create mode 100644 purpur-server/minecraft-patches/sources/net/minecraft/server/commands/GameModeCommand.java.patch create mode 100644 purpur-server/paper-patches/files/src/main/java/org/bukkit/craftbukkit/util/permissions/CommandPermissions.java.patch diff --git a/patches/server/0152-Gamemode-extra-permissions.patch b/patches/server/0152-Gamemode-extra-permissions.patch deleted file mode 100644 index 92036a5c0..000000000 --- a/patches/server/0152-Gamemode-extra-permissions.patch +++ /dev/null @@ -1,94 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: William Blake Galbreath -Date: Fri, 30 Apr 2021 13:39:39 -0500 -Subject: [PATCH] Gamemode extra permissions - - -diff --git a/net/minecraft/commands/CommandSourceStack.java b/net/minecraft/commands/CommandSourceStack.java -index 7b2daf47e411362a462019a1612a99c952170200..8ed5e9293e80f53d741c145fa415fab6311036d7 100644 ---- a/net/minecraft/commands/CommandSourceStack.java -+++ b/net/minecraft/commands/CommandSourceStack.java -@@ -211,6 +211,19 @@ public class CommandSourceStack implements ExecutionCommandSource").replacement(bukkitPermission).build()))); -+ } -+ return false; -+ } -+ // Purpur end -+ - public Vec3 getPosition() { - return this.worldPosition; - } -diff --git a/net/minecraft/server/commands/GameModeCommand.java b/net/minecraft/server/commands/GameModeCommand.java -index d1da3600dc07107309b20ebe6e7c0c4da0e8de76..244b4719c689f153fa36381a60acc280bb0bd9b3 100644 ---- a/net/minecraft/server/commands/GameModeCommand.java -+++ b/net/minecraft/server/commands/GameModeCommand.java -@@ -57,6 +57,18 @@ public class GameModeCommand { - } - - private static int setMode(CommandContext context, Collection targets, GameType gameMode) { -+ // Purpur start -+ if (org.purpurmc.purpur.PurpurConfig.commandGamemodeRequiresPermission) { -+ String gamemode = gameMode.getName(); -+ CommandSourceStack sender = context.getSource(); -+ if (!sender.testPermission(2, "minecraft.command.gamemode." + gamemode)) { -+ return 0; -+ } -+ if (sender.getEntity() instanceof ServerPlayer player && (targets.size() > 1 || !targets.contains(player)) && !sender.testPermission(2, "minecraft.command.gamemode." + gamemode + ".other")) { -+ return 0; -+ } -+ } -+ // Purpur end - int i = 0; - - for (ServerPlayer serverPlayer : targets) { -diff --git a/src/main/java/org/bukkit/craftbukkit/util/permissions/CommandPermissions.java b/src/main/java/org/bukkit/craftbukkit/util/permissions/CommandPermissions.java -index b3169c551b8410f5861f9db0543c785439ecba7c..916ca3f1f39e10158fc7c10141785fff49ed1501 100644 ---- a/src/main/java/org/bukkit/craftbukkit/util/permissions/CommandPermissions.java -+++ b/src/main/java/org/bukkit/craftbukkit/util/permissions/CommandPermissions.java -@@ -23,7 +23,15 @@ public final class CommandPermissions { - DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "kick", "Allows the user to kick players", PermissionDefault.OP, commands); - DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "stop", "Allows the user to stop the server", PermissionDefault.OP, commands); - DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "list", "Allows the user to list all online players", PermissionDefault.OP, commands); -- DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "gamemode", "Allows the user to change the gamemode of another player", PermissionDefault.OP, commands); -+ // Purpur start -+ Permission gamemodeVanilla = DefaultPermissions.registerPermission(PREFIX + "gamemode", "Allows the user to change the gamemode", PermissionDefault.OP, commands); -+ for (net.minecraft.world.level.GameType gametype : net.minecraft.world.level.GameType.values()) { -+ Permission gamemodeSelf = DefaultPermissions.registerPermission(PREFIX + "gamemode." + gametype.getName(), "Allows the user to set " + gametype.getName() + " gamemode for self", PermissionDefault.OP); -+ Permission gamemodeOther = DefaultPermissions.registerPermission(PREFIX + "gamemode." + gametype.getName() + ".other", "Allows the user to set " + gametype.getName() + " gamemode for other players", PermissionDefault.OP); -+ gamemodeSelf.addParent(gamemodeOther, true); -+ gamemodeVanilla.addParent(gamemodeSelf, true); -+ } -+ // Purpur end - DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "experience", "Allows the user to give themselves or others arbitrary values of experience", PermissionDefault.OP, commands); // Paper - wrong permission; redirects are de-redirected and the root literal name is used, so xp -> experience - DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "defaultgamemode", "Allows the user to change the default gamemode of the server", PermissionDefault.OP, commands); - DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "seed", "Allows the user to view the seed of the world", PermissionDefault.OP, commands); -diff --git a/src/main/java/org/purpurmc/purpur/PurpurConfig.java b/src/main/java/org/purpurmc/purpur/PurpurConfig.java -index 3310fb33efdf129c424503eb07055ddb4c3a200b..7fda69055383d8b8740752999f0d1f9993c454e4 100644 ---- a/src/main/java/org/purpurmc/purpur/PurpurConfig.java -+++ b/src/main/java/org/purpurmc/purpur/PurpurConfig.java -@@ -236,6 +236,7 @@ public class PurpurConfig { - public static String commandTPSBarTextColorMedium = ""; - public static String commandTPSBarTextColorLow = ""; - public static int commandTPSBarTickInterval = 20; -+ public static boolean commandGamemodeRequiresPermission = false; - private static void commandSettings() { - commandTPSBarTitle = getString("settings.command.tpsbar.title", commandTPSBarTitle); - commandTPSBarProgressOverlay = BossBar.Overlay.valueOf(getString("settings.command.tpsbar.overlay", commandTPSBarProgressOverlay.name())); -@@ -247,6 +248,7 @@ public class PurpurConfig { - commandTPSBarTextColorMedium = getString("settings.command.tpsbar.text-color.medium", commandTPSBarTextColorMedium); - commandTPSBarTextColorLow = getString("settings.command.tpsbar.text-color.low", commandTPSBarTextColorLow); - commandTPSBarTickInterval = getInt("settings.command.tpsbar.tick-interval", commandTPSBarTickInterval); -+ commandGamemodeRequiresPermission = getBoolean("settings.command.gamemode.requires-specific-permission", commandGamemodeRequiresPermission); - } - - public static int barrelRows = 3; diff --git a/purpur-server/minecraft-patches/sources/net/minecraft/commands/CommandSourceStack.java.patch b/purpur-server/minecraft-patches/sources/net/minecraft/commands/CommandSourceStack.java.patch index 60b6380dc..86f83273f 100644 --- a/purpur-server/minecraft-patches/sources/net/minecraft/commands/CommandSourceStack.java.patch +++ b/purpur-server/minecraft-patches/sources/net/minecraft/commands/CommandSourceStack.java.patch @@ -1,9 +1,30 @@ --- a/net/minecraft/commands/CommandSourceStack.java +++ b/net/minecraft/commands/CommandSourceStack.java -@@ -517,6 +_,30 @@ +@@ -431,6 +_,19 @@ + } + // CraftBukkit end + ++ // Purpur start - Gamemode extra permissions ++ public boolean testPermission(int i, String bukkitPermission) { ++ if (hasPermission(i, bukkitPermission)) { ++ return true; ++ } ++ net.kyori.adventure.text.Component permissionMessage = getLevel().getServer().server.permissionMessage(); ++ if (!permissionMessage.equals(net.kyori.adventure.text.Component.empty())) { ++ sendFailure(io.papermc.paper.adventure.PaperAdventure.asVanilla(permissionMessage.replaceText(net.kyori.adventure.text.TextReplacementConfig.builder().matchLiteral("").replacement(bukkitPermission).build()))); ++ } ++ return false; ++ } ++ // Purpur end - Gamemode extra permissions ++ + public Vec3 getPosition() { + return this.worldPosition; + } +@@ -516,6 +_,30 @@ + } } } - ++ + // Purpur start - Purpur config files + public void sendSuccess(@Nullable String message) { + sendSuccess(message, false); @@ -27,7 +48,6 @@ + sendSuccess(() -> io.papermc.paper.adventure.PaperAdventure.asVanilla(message), broadcastToOps); + } + // Purpur end - Purpur config files -+ + public void sendSuccess(Supplier messageSupplier, boolean allowLogging) { boolean flag = this.source.acceptsSuccess() && !this.silent; - boolean flag1 = allowLogging && this.source.shouldInformAdmins() && !this.silent; diff --git a/purpur-server/minecraft-patches/sources/net/minecraft/server/commands/GameModeCommand.java.patch b/purpur-server/minecraft-patches/sources/net/minecraft/server/commands/GameModeCommand.java.patch new file mode 100644 index 000000000..b1ef32c8b --- /dev/null +++ b/purpur-server/minecraft-patches/sources/net/minecraft/server/commands/GameModeCommand.java.patch @@ -0,0 +1,21 @@ +--- a/net/minecraft/server/commands/GameModeCommand.java ++++ b/net/minecraft/server/commands/GameModeCommand.java +@@ -51,6 +_,18 @@ + } + + private static int setMode(CommandContext source, Collection players, GameType gameType) { ++ // Purpur start - Gamemode extra permissions ++ if (org.purpurmc.purpur.PurpurConfig.commandGamemodeRequiresPermission) { ++ String gamemode = gameType.getName(); ++ CommandSourceStack sender = source.getSource(); ++ if (!sender.testPermission(2, "minecraft.command.gamemode." + gamemode)) { ++ return 0; ++ } ++ if (sender.getEntity() instanceof ServerPlayer player && (players.size() > 1 || !players.contains(player)) && !sender.testPermission(2, "minecraft.command.gamemode." + gamemode + ".other")) { ++ return 0; ++ } ++ } ++ // Purpur end - Gamemode extra permissions + int i = 0; + + for (ServerPlayer serverPlayer : players) { diff --git a/purpur-server/paper-patches/files/src/main/java/org/bukkit/craftbukkit/util/permissions/CommandPermissions.java.patch b/purpur-server/paper-patches/files/src/main/java/org/bukkit/craftbukkit/util/permissions/CommandPermissions.java.patch new file mode 100644 index 000000000..6106785b3 --- /dev/null +++ b/purpur-server/paper-patches/files/src/main/java/org/bukkit/craftbukkit/util/permissions/CommandPermissions.java.patch @@ -0,0 +1,19 @@ +--- a/src/main/java/org/bukkit/craftbukkit/util/permissions/CommandPermissions.java ++++ b/src/main/java/org/bukkit/craftbukkit/util/permissions/CommandPermissions.java +@@ -23,7 +_,15 @@ + DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "kick", "Allows the user to kick players", PermissionDefault.OP, commands); + DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "stop", "Allows the user to stop the server", PermissionDefault.OP, commands); + DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "list", "Allows the user to list all online players", PermissionDefault.OP, commands); +- DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "gamemode", "Allows the user to change the gamemode of another player", PermissionDefault.OP, commands); ++ // Purpur start - Gamemode extra permissions ++ Permission gamemodeVanilla = DefaultPermissions.registerPermission(PREFIX + "gamemode", "Allows the user to change the gamemode", PermissionDefault.OP, commands); ++ for (net.minecraft.world.level.GameType gametype : net.minecraft.world.level.GameType.values()) { ++ Permission gamemodeSelf = DefaultPermissions.registerPermission(PREFIX + "gamemode." + gametype.getName(), "Allows the user to set " + gametype.getName() + " gamemode for self", PermissionDefault.OP); ++ Permission gamemodeOther = DefaultPermissions.registerPermission(PREFIX + "gamemode." + gametype.getName() + ".other", "Allows the user to set " + gametype.getName() + " gamemode for other players", PermissionDefault.OP); ++ gamemodeSelf.addParent(gamemodeOther, true); ++ gamemodeVanilla.addParent(gamemodeSelf, true); ++ } ++ // Purpur end - Gamemode extra permissions + DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "experience", "Allows the user to give themselves or others arbitrary values of experience", PermissionDefault.OP, commands); // Paper - wrong permission; redirects are de-redirected and the root literal name is used, so xp -> experience + DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "defaultgamemode", "Allows the user to change the default gamemode of the server", PermissionDefault.OP, commands); + DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "seed", "Allows the user to view the seed of the world", PermissionDefault.OP, commands); diff --git a/purpur-server/src/main/java/org/purpurmc/purpur/PurpurConfig.java b/purpur-server/src/main/java/org/purpurmc/purpur/PurpurConfig.java index 980b3a7d4..cdc13dfea 100644 --- a/purpur-server/src/main/java/org/purpurmc/purpur/PurpurConfig.java +++ b/purpur-server/src/main/java/org/purpurmc/purpur/PurpurConfig.java @@ -221,6 +221,7 @@ public class PurpurConfig { public static String commandTPSBarTextColorMedium = ""; public static String commandTPSBarTextColorLow = ""; public static int commandTPSBarTickInterval = 20; + public static boolean commandGamemodeRequiresPermission = false; private static void commandSettings() { commandTPSBarTitle = getString("settings.command.tpsbar.title", commandTPSBarTitle); commandTPSBarProgressOverlay = BossBar.Overlay.valueOf(getString("settings.command.tpsbar.overlay", commandTPSBarProgressOverlay.name())); @@ -232,6 +233,7 @@ public class PurpurConfig { commandTPSBarTextColorMedium = getString("settings.command.tpsbar.text-color.medium", commandTPSBarTextColorMedium); commandTPSBarTextColorLow = getString("settings.command.tpsbar.text-color.low", commandTPSBarTextColorLow); commandTPSBarTickInterval = getInt("settings.command.tpsbar.tick-interval", commandTPSBarTickInterval); + commandGamemodeRequiresPermission = getBoolean("settings.command.gamemode.requires-specific-permission", commandGamemodeRequiresPermission); } public static int barrelRows = 3;