From 028df0a3402e2adbeea7050ea21b79999f5d65e1 Mon Sep 17 00:00:00 2001 From: Gabriel Tofvesson Date: Sat, 24 Jul 2021 21:37:20 +0200 Subject: [PATCH] Implement sign editor packets --- .../spigot/wizcompat/packet/Players.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/dev/w1zzrd/spigot/wizcompat/packet/Players.java b/src/dev/w1zzrd/spigot/wizcompat/packet/Players.java index c674d56..b4bcc8d 100644 --- a/src/dev/w1zzrd/spigot/wizcompat/packet/Players.java +++ b/src/dev/w1zzrd/spigot/wizcompat/packet/Players.java @@ -1,6 +1,9 @@ package dev.w1zzrd.spigot.wizcompat.packet; import org.bukkit.GameMode; +import org.bukkit.Location; +import org.bukkit.block.BlockState; +import org.bukkit.block.Sign; import org.bukkit.entity.Player; import java.lang.reflect.Array; @@ -75,4 +78,34 @@ public final class Players { return reflectGetField(player, "entity"); } + public static void openSignEditor(final Player target, final Location where) { + // Must edit a non-editable sign + final BlockState targetState = where.getBlock().getState(); + if (!(targetState instanceof Sign) || ((Sign)targetState).isEditable()) + return; + + final Object tileSign = reflectGetField(targetState, "tileEntity"); + + // Make editable by player + reflectInvoke(tileSign, new String[]{ "a" }, target.getUniqueId()); + reflectInvoke(tileSign, new String[]{ "a" }, true); + + final Class type_PacketPlayOutOpenSignEditor = loadClass( + getNativePacketPackage(target), + "PacketPlayOutOpenSignEditor", "game.PacketPlayOutOpenSignEditor" + ); + assert type_PacketPlayOutOpenSignEditor != null; + + Packets.sendPacket( + target, + reflectConstruct( + type_PacketPlayOutOpenSignEditor, + reflectConstruct( + type_PacketPlayOutOpenSignEditor.getDeclaredFields()[0].getType(), // Only declares one field + where.getBlockX(), + where.getBlockY(), + where.getBlockZ() + ))); + } + }