Scissors/patches/server/0032-Fix-ClickEvents-on-Sig...

61 lines
3.3 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/net/minecraft/world/level/block/entity/SignBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/SignBlockEntity.java
index 4da4edae517a0efec6e03a719ec47b700509dab1..96e330e024384503496f834a9767122f6b4d86d6 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
@@ -4,8 +4,10 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
import java.util.UUID;
import java.util.function.Function;
import javax.annotation.Nullable;
+import me.totalfreedom.scissors.ScissorsConfig; // Scissors
import net.minecraft.commands.CommandSource;
import net.minecraft.commands.CommandSourceStack;
+import net.minecraft.commands.Commands; // Scissors
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; // Scissors
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.util.FormattedCharSequence;
@@ -24,6 +27,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; // Scissors
+import org.bukkit.craftbukkit.entity.CraftPlayer; // Scissors
public class SignBlockEntity extends BlockEntity implements CommandSource { // CraftBukkit - implements
private static final boolean CONVERT_LEGACY_SIGNS = Boolean.getBoolean("convertLegacySigns"); // Paper
@@ -272,6 +277,21 @@ public class SignBlockEntity extends BlockEntity implements CommandSource { // C
}
player.getServer().getCommands().performPrefixedCommand(this.createCommandSourceStack(((org.bukkit.craftbukkit.entity.CraftPlayer) event.getPlayer()).getHandle()), event.getMessage());
// Paper end
+ // 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
}
}