From b5878783ad27ea17421faee92bb9a43b3ef8ef37 Mon Sep 17 00:00:00 2001 From: md_5 Date: Sun, 6 Aug 2017 09:07:24 +1000 Subject: [PATCH] SPIGOT-3491: Add option to bypass permissions in advancements --- nms-patches/AdvancementRewards.patch | 46 ++++++++++++++++--- .../CommandBlockListenerAbstract.patch | 2 +- .../org/bukkit/craftbukkit/CraftServer.java | 6 +++ .../resources/configurations/commands.yml | 1 + 4 files changed, 47 insertions(+), 8 deletions(-) diff --git a/nms-patches/AdvancementRewards.patch b/nms-patches/AdvancementRewards.patch index 50852ea213..8f0ea2c330 100644 --- a/nms-patches/AdvancementRewards.patch +++ b/nms-patches/AdvancementRewards.patch @@ -1,15 +1,47 @@ --- a/net/minecraft/server/AdvancementRewards.java +++ b/net/minecraft/server/AdvancementRewards.java -@@ -98,7 +98,7 @@ - } +@@ -66,7 +66,24 @@ + CustomFunction customfunction = this.e.a(minecraftserver.aL()); - public boolean getSendCommandFeedback() { -- return minecraftserver.worldServer[0].getGameRules().getBoolean("commandBlockOutput"); -+ return minecraftserver.worlds.get(0).getGameRules().getBoolean("commandBlockOutput"); // CraftBukkit + if (customfunction != null) { +- ICommandListener icommandlistener = new ICommandListener() { ++ // CraftBukkit start ++ ICommandListener icommandlistener = new AdvancementCommandListener(entityplayer, minecraftserver); ++ ++ minecraftserver.aL().a(customfunction, icommandlistener); ++ } ++ ++ } ++ ++ public static class AdvancementCommandListener implements ICommandListener { ++ ++ private final EntityPlayer entityplayer; ++ private final MinecraftServer minecraftserver; ++ ++ public AdvancementCommandListener(EntityPlayer entityplayer, MinecraftServer minecraftserver) { ++ this.entityplayer = entityplayer; ++ this.minecraftserver = minecraftserver; ++ } ++ + public String getName() { + return entityplayer.getName(); } +@@ -108,12 +125,8 @@ + public MinecraftServer C_() { + return entityplayer.C_(); + } +- }; +- +- minecraftserver.aL().a(customfunction, icommandlistener); +- } +- +- } ++ } ++ // CraftBukkit end - public void a(CommandObjectiveExecutor.EnumCommandResult commandobjectiveexecutor_enumcommandresult, int i) { -@@ -156,7 +156,7 @@ + public String toString() { + return "AdvancementRewards{experience=" + this.b + ", loot=" + Arrays.toString(this.c) + ", recipes=" + Arrays.toString(this.d) + ", function=" + this.e + '}'; +@@ -156,7 +169,7 @@ return new AdvancementRewards(i, aminecraftkey, aminecraftkey1, customfunction_a); } diff --git a/nms-patches/CommandBlockListenerAbstract.patch b/nms-patches/CommandBlockListenerAbstract.patch index 5f6ef0419c..c0d98def1b 100644 --- a/nms-patches/CommandBlockListenerAbstract.patch +++ b/nms-patches/CommandBlockListenerAbstract.patch @@ -93,7 +93,7 @@ + } + String as[] = command.split(" "); + as = VanillaCommandWrapper.dropFirstArgument(as); -+ if (!((VanillaCommandWrapper) commandBlockCommand).testPermission(bSender)) { ++ if (!sender.getWorld().getServer().getPermissionOverride(sender) && !((VanillaCommandWrapper) commandBlockCommand).testPermission(bSender)) { + return 0; + } + return ((VanillaCommandWrapper) commandBlockCommand).dispatchVanillaCommand(bSender, sender, as); diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java index 0a5a11d838..1564dd717a 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -169,6 +169,7 @@ public final class CraftServer implements Server { private boolean printSaveWarning; private CraftIconCache icon; private boolean overrideAllCommandBlockCommands = false; + private boolean unrestrictedAdvancements; private final Pattern validUserPattern = Pattern.compile("^[a-zA-Z0-9_]{2,16}$"); private final UUID invalidUserUUID = UUID.nameUUIDFromBytes("InvalidUsername".getBytes(Charsets.UTF_8)); private final List playerView; @@ -247,6 +248,7 @@ public final class CraftServer implements Server { saveCommandsConfig(); overrideAllCommandBlockCommands = commandsConfiguration.getStringList("command-block-overrides").contains("*"); + unrestrictedAdvancements = commandsConfiguration.getBoolean("unrestricted-advancements"); pluginManager.useTimings(configuration.getBoolean("settings.plugin-profiling")); monsterSpawn = configuration.getInt("spawn-limits.monsters"); animalSpawn = configuration.getInt("spawn-limits.animals"); @@ -259,6 +261,10 @@ public final class CraftServer implements Server { loadIcon(); } + public boolean getPermissionOverride(ICommandListener listener) { + return unrestrictedAdvancements && listener instanceof AdvancementRewards.AdvancementCommandListener; + } + public boolean getCommandBlockOverride(String command) { return overrideAllCommandBlockCommands || commandsConfiguration.getStringList("command-block-overrides").contains(command); } diff --git a/src/main/resources/configurations/commands.yml b/src/main/resources/configurations/commands.yml index 733307c288..0491a8bbe5 100644 --- a/src/main/resources/configurations/commands.yml +++ b/src/main/resources/configurations/commands.yml @@ -11,6 +11,7 @@ # Bug tracker: http://www.spigotmc.org/go/bugs command-block-overrides: [] +unrestricted-advancements: false aliases: icanhasbukkit: - "version $1-"