Fix ClickEvents on Signs bypassing permissions (#51)

This commit is contained in:
Allink 2022-07-13 20:41:17 +01:00 committed by GitHub
parent 97cdd47afa
commit 253787181e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -0,0 +1,93 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Allink <arclicious@vivaldi.net>
Date: Wed, 13 Jul 2022 12:13:22 +0100
Subject: [PATCH] Fix ClickEvents on Signs bypassing permissions
diff --git a/src/main/java/me/totalfreedom/scissors/ScissorsConfig.java b/src/main/java/me/totalfreedom/scissors/ScissorsConfig.java
index 7cffc17d6527dc8788453c6040cc7a5e0cbebd2c..c908eda285f478def54506cf65ed1055b3a94371 100644
--- a/src/main/java/me/totalfreedom/scissors/ScissorsConfig.java
+++ b/src/main/java/me/totalfreedom/scissors/ScissorsConfig.java
@@ -67,8 +67,8 @@ public class ScissorsConfig
config.options().header(HEADER);
config.options().copyDefaults(true);
- version = getInt("config-version", 1);
- set("config-version", 1);
+ version = getInt("config-version", 2);
+ set("config-version", 2);
readConfig(ScissorsConfig.class, null);
}
@@ -135,6 +135,13 @@ public class ScissorsConfig
runCommandsInBooks = getBoolean("runCommandsInBooks", false);
}
+ // people still may want them to bypass permissions for warps
+ public static boolean commandSignsBypassPermissions = false;
+ public static void commandSignsBypassPermissions()
+ {
+ commandSignsBypassPermissions = getBoolean("commandSignsBypassPermissions", false);
+ }
+
private static void set(String path, Object val)
{
config.set(path, val);
diff --git a/src/main/java/net/minecraft/world/level/block/entity/SignBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/SignBlockEntity.java
index def4fdd2c7e4f925fa128692a744e5d10ae0203a..6ea38c4cb62c71e208b64629f8a427a40c062f3c 100644
--- a/src/main/java/net/minecraft/world/level/block/entity/SignBlockEntity.java
+++ b/src/main/java/net/minecraft/world/level/block/entity/SignBlockEntity.java
@@ -1,11 +1,13 @@
package net.minecraft.world.level.block.entity;
+import me.totalfreedom.scissors.ScissorsConfig;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import java.util.UUID;
import java.util.function.Function;
import javax.annotation.Nullable;
import net.minecraft.commands.CommandSource;
import net.minecraft.commands.CommandSourceStack;
+import net.minecraft.commands.Commands;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.ClickEvent;
@@ -15,6 +17,7 @@ import net.minecraft.network.chat.ComponentUtils;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.chat.Style;
import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
+import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.util.FormattedCharSequence;
@@ -23,6 +26,8 @@ import net.minecraft.world.item.DyeColor;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.Vec2;
import net.minecraft.world.phys.Vec3;
+import org.bukkit.craftbukkit.CraftServer;
+import org.bukkit.craftbukkit.entity.CraftPlayer;
public class SignBlockEntity extends BlockEntity implements CommandSource { // CraftBukkit - implements
private static final boolean CONVERT_LEGACY_SIGNS = Boolean.getBoolean("convertLegacySigns"); // Paper
@@ -234,7 +239,21 @@ public class SignBlockEntity extends BlockEntity implements CommandSource { // C
if (!event.callEvent()) {
return false;
}
- player.getServer().getCommands().performPrefixedCommand(this.createCommandSourceStack(((org.bukkit.craftbukkit.entity.CraftPlayer) event.getPlayer()).getHandle()), event.getMessage());
+
+ // Scissors start - Add optional permissions to command signs
+ final MinecraftServer vanillaServer = player.getServer();
+ final CraftServer craftServer = vanillaServer.server;
+ final CraftPlayer craftPlayer = player.getBukkitEntity();
+ final Commands commands = vanillaServer.getCommands();
+
+ if (ScissorsConfig.commandSignsBypassPermissions)
+ {
+ commands.performPrefixedCommand(this.createCommandSourceStack(((org.bukkit.craftbukkit.entity.CraftPlayer) event.getPlayer()).getHandle()), event.getMessage());
+ } else
+ {
+ craftServer.dispatchCommand(craftPlayer, command.substring(1));
+ }
+ // Scissors end
// Paper end
}
}