Files
Purpur/patches/server/0181-Gamemode-extra-permissions.patch
Encode42 d5d756bc32 Updated Upstream (Paper & Airplane)
Upstream has released updates that appear to apply and compile correctly

Paper Changes:
PaperMC/Paper@c1b4899 Fix dupe uuid check on entity add (#6735)
PaperMC/Paper@3f043f7 Async catch modifications to critical entity state
PaperMC/Paper@bc43f40 Update jline and TCA (#6829)
PaperMC/Paper@d9e2817 Update paperweight to 1.1.13 (#6866)
PaperMC/Paper@3e310e0 Remove redundant and unneeded repos, reorder repos (#6867)
PaperMC/Paper@485d15f Update paperweight to 1.1.14 (#6868)
PaperMC/Paper@09d50a9 Added missing mappings (#6810)
PaperMC/Paper@0968cdd Move async catches back to where they were (#6869)
PaperMC/Paper@6f71b7c Deduplicate strings in ObfHelper (#6841)
PaperMC/Paper@ada930b Updated Upstream (Bukkit/CraftBukkit) (#6872)
PaperMC/Paper@06d82e0 Cache palette array (#6767)
PaperMC/Paper@70fe58d Expose the potential player cause of a lightning (#6782)
PaperMC/Paper@c20c9d3 Fix CraftNamespacedKey shenanigans (#6825)
PaperMC/Paper@29bb5a9 Add PlayerDeathEvent#getPlayer for clarity (#6859)
PaperMC/Paper@124d079 Fix issues with mob conversion (#6831)
PaperMC/Paper@22b0238 Add API for checking if a zombie has the option to break doors (#6855)
PaperMC/Paper@5af80b0 Add isCollidable methods to various places (#6870)
PaperMC/Paper@32ba088 Fix setPatternColor on tropical fish bucket meta (#6877)
PaperMC/Paper@87121ce Move `getTrackedPlayers` up from Player to Entity (#6569)
PaperMC/Paper@a923e33 Make despawn distance configs per-category, improve per category spawn limit config (#6717)
PaperMC/Paper@3f17694 Goat ram API (#6336)
PaperMC/Paper@cc2ecbc Add Raw Byte Entity Serialization (#6826)

Airplane Changes:
TECHNOVE/Airplane@e47949b Ty Penple <3
TECHNOVE/Airplane@86fee6b Update upstream
2021-11-11 02:03:29 -05:00

97 lines
6.7 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: William Blake Galbreath <Blake.Galbreath@GMail.com>
Date: Fri, 30 Apr 2021 13:39:39 -0500
Subject: [PATCH] Gamemode extra permissions
diff --git a/src/main/java/net/minecraft/commands/CommandSourceStack.java b/src/main/java/net/minecraft/commands/CommandSourceStack.java
index 224669ecaad37ac2f16900700eea40ef52d938a5..3c668bb739ee92b6d1130889cc42f73a129bf5a2 100644
--- a/src/main/java/net/minecraft/commands/CommandSourceStack.java
+++ b/src/main/java/net/minecraft/commands/CommandSourceStack.java
@@ -195,6 +195,21 @@ public class CommandSourceStack implements SharedSuggestionProvider, com.destroy
}
// CraftBukkit end
+ // Purpur start
+ public boolean testPermission(int i, String bukkitPermission) {
+ if (hasPermission(i, bukkitPermission)) {
+ return true;
+ }
+ String permissionMessage = getLevel().getServer().server.getPermissionMessage();
+ if (!permissionMessage.isBlank()) {
+ for (String line : permissionMessage.replace("<permission>", bukkitPermission).split("\n")) {
+ sendFailure(new TextComponent(line));
+ }
+ }
+ return false;
+ }
+ // Purpur end
+
public Vec3 getPosition() {
return this.worldPosition;
}
diff --git a/src/main/java/net/minecraft/server/commands/GameModeCommand.java b/src/main/java/net/minecraft/server/commands/GameModeCommand.java
index 79f6089b934124c3309c6bee2e48b36b937252e0..dff8ef0a1a2e52792070d93685c290023d31ce95 100644
--- a/src/main/java/net/minecraft/server/commands/GameModeCommand.java
+++ b/src/main/java/net/minecraft/server/commands/GameModeCommand.java
@@ -49,6 +49,18 @@ public class GameModeCommand {
}
private static int setMode(CommandContext<CommandSourceStack> context, Collection<ServerPlayer> targets, GameType gameMode) {
+ // Purpur start
+ if (net.pl3x.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/net/pl3x/purpur/PurpurConfig.java b/src/main/java/net/pl3x/purpur/PurpurConfig.java
index 62e741b78c70fd755c0e083bb510d621d0f3802e..7c108355943d71531ec7a9a997b10dc6959de09b 100644
--- a/src/main/java/net/pl3x/purpur/PurpurConfig.java
+++ b/src/main/java/net/pl3x/purpur/PurpurConfig.java
@@ -221,6 +221,7 @@ public class PurpurConfig {
public static String commandTPSBarTextColorMedium = "<gradient:#ffff55:#ffaa00><text></gradient>";
public static String commandTPSBarTextColorLow = "<gradient:#ff5555:#aa0000><text></gradient>";
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;
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 6cc517b394bafefce50d877761e5b2eee8e14c78..46ca899a7abddea108f6ff1b4ca14ca5cd3112ab 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 + "xp", "Allows the user to give themselves or others arbitrary values of experience", PermissionDefault.OP, commands);
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "toggledownfall", "Allows the user to toggle rain on/off for a given world", PermissionDefault.OP, commands);
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "defaultgamemode", "Allows the user to change the default gamemode of the server", PermissionDefault.OP, commands);