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/src/main/java/net/minecraft/commands/CommandSourceStack.java b/src/main/java/net/minecraft/commands/CommandSourceStack.java index a01d283ffcef2d4a608c42e230fa557563fe8179..889756a54d1d244438a8c14d3f93f690b499e674 100644 --- a/src/main/java/net/minecraft/commands/CommandSourceStack.java +++ b/src/main/java/net/minecraft/commands/CommandSourceStack.java @@ -204,6 +204,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("", bukkitPermission).split("\n")) { + sendFailure(Component.literal(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 7882ee2b7813d437d3b7580f046f38e79fc9e7b6..afdf86826efc1c8c73a722d7709641b3fa16d542 100644 --- a/src/main/java/net/minecraft/server/commands/GameModeCommand.java +++ b/src/main/java/net/minecraft/server/commands/GameModeCommand.java @@ -47,6 +47,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 0467419fc8a06c241a46216c8f8c32abeb9fbc26..bc178d7305f38b77393b827d7b71412d92ea1acb 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 + "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 32da21aa0b00eab4a5bbfb1c42bcfb2c8e97b43d..94a1c3035462f9934a425ff996510d7d7a236f19 100644 --- a/src/main/java/org/purpurmc/purpur/PurpurConfig.java +++ b/src/main/java/org/purpurmc/purpur/PurpurConfig.java @@ -226,6 +226,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())); @@ -237,6 +238,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;