Scissors/patches/removed/0037-Fix-ClickEvents-on-Sig...

94 lines
4.5 KiB
Diff

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 1aa418ef5e400aabdf17dbe81da6cee6a1f63d96..9cd5ffca69df27f794f5a72e687fc6b3ae0f1656 100644
--- a/src/main/java/me/totalfreedom/scissors/ScissorsConfig.java
+++ b/src/main/java/me/totalfreedom/scissors/ScissorsConfig.java
@@ -87,8 +87,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);
}
@@ -156,6 +156,13 @@ public class ScissorsConfig
runCommandsInBooks = getBoolean("runCommandsInBooks", false);
}
+ // people still may want them to bypass permissions for warps
+ public static boolean commandSignsBypassPermissions = false;
+ private 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 58599ead28c25a76d9f41d2d29ee8024c9afdccd..a4ea00cbe0cae3664391d3b84a0e6956a3253491 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
}
}