Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
Ursprung
e71931e757
Commit
81d1b4a914
@ -19,17 +19,15 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.features.world;
|
package de.steamwar.bausystem.features.world;
|
||||||
|
|
||||||
import com.comphenix.protocol.PacketType;
|
import com.comphenix.tinyprotocol.Reflection;
|
||||||
import com.comphenix.protocol.ProtocolLibrary;
|
|
||||||
import com.comphenix.protocol.events.PacketAdapter;
|
|
||||||
import com.comphenix.protocol.events.PacketContainer;
|
|
||||||
import com.comphenix.protocol.events.PacketEvent;
|
|
||||||
import com.comphenix.protocol.wrappers.BlockPosition;
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.bausystem.linkage.LinkageType;
|
import de.steamwar.bausystem.linkage.LinkageType;
|
||||||
import de.steamwar.bausystem.linkage.Linked;
|
import de.steamwar.bausystem.linkage.Linked;
|
||||||
|
import de.steamwar.bausystem.utils.ProtocolAPI;
|
||||||
|
import net.minecraft.server.v1_15_R1.BlockPosition;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.Sign;
|
import org.bukkit.block.Sign;
|
||||||
@ -38,13 +36,18 @@ import org.bukkit.event.EventHandler;
|
|||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.block.Action;
|
import org.bukkit.event.block.Action;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
@Linked(LinkageType.LISTENER)
|
@Linked(LinkageType.LISTENER)
|
||||||
public class SignEdit implements Listener {
|
public class SignEdit implements Listener {
|
||||||
|
|
||||||
|
public static final Class<?> openSign = Reflection.getClass("{nms}.PacketPlayOutOpenSignEditor");
|
||||||
|
private static final Reflection.FieldAccessor<net.minecraft.server.v1_15_R1.BlockPosition> blockPositionFieldAccessor = Reflection.getField(openSign, net.minecraft.server.v1_15_R1.BlockPosition.class, 0);
|
||||||
|
|
||||||
|
public static final Class<?> updateSign = Reflection.getClass("{nms}.PacketPlayInUpdateSign");
|
||||||
|
private static final Reflection.FieldAccessor<BlockPosition> getBlockPositionFieldAccessor = Reflection.getField(updateSign, BlockPosition.class, 0);
|
||||||
|
private static final Reflection.FieldAccessor<String[]> stringFieldAccessor = Reflection.getField(updateSign, String[].class, 0);
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void editSign(PlayerInteractEvent event) {
|
public void editSign(PlayerInteractEvent event) {
|
||||||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK ||
|
if (event.getAction() != Action.RIGHT_CLICK_BLOCK ||
|
||||||
@ -62,26 +65,19 @@ public class SignEdit implements Listener {
|
|||||||
}
|
}
|
||||||
sign.update();
|
sign.update();
|
||||||
|
|
||||||
PacketContainer signOpen = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.OPEN_SIGN_EDITOR);
|
Object openSignObject = Reflection.newInstance(openSign);
|
||||||
signOpen.getBlockPositionModifier().write(0, new BlockPosition(event.getClickedBlock().getLocation().toVector()));
|
Vector vector = event.getClickedBlock().getLocation().toVector();
|
||||||
try {
|
blockPositionFieldAccessor.set(openSignObject, new BlockPosition(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ()));
|
||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, signOpen);
|
ProtocolAPI.tinyProtocol.sendPacket(player, openSignObject);
|
||||||
} catch (InvocationTargetException e) {
|
|
||||||
Bukkit.getLogger().log(Level.SEVERE, "Invocation target exception", e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(BauSystem.getInstance(), PacketType.Play.Client.UPDATE_SIGN) {
|
{
|
||||||
@Override
|
ProtocolAPI.setIncomingHandler(updateSign, (player, o) -> {
|
||||||
public void onPacketReceiving(PacketEvent event) {
|
|
||||||
if (!event.getPlayer().equals(player))
|
|
||||||
return;
|
|
||||||
event.setCancelled(true);
|
|
||||||
Bukkit.getScheduler().runTask(BauSystem.getInstance(), () -> {
|
Bukkit.getScheduler().runTask(BauSystem.getInstance(), () -> {
|
||||||
PacketContainer packetContainer = event.getPacket();
|
BlockPosition position = getBlockPositionFieldAccessor.get(o);
|
||||||
BlockPosition position = packetContainer.getBlockPositionModifier().read(0);
|
String[] lines = stringFieldAccessor.get(o);
|
||||||
String[] lines = packetContainer.getStringArrays().read(0);
|
|
||||||
|
|
||||||
Block signLoc = position.toLocation(player.getWorld()).getBlock();
|
Block signLoc = new Location(player.getWorld(), position.getX(), position.getY(), position.getZ()).getBlock();
|
||||||
if (!signLoc.getType().name().contains("SIGN"))
|
if (!signLoc.getType().name().contains("SIGN"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -90,10 +86,8 @@ public class SignEdit implements Listener {
|
|||||||
sign.setLine(i, ChatColor.translateAlternateColorCodes('&', lines[i]));
|
sign.setLine(i, ChatColor.translateAlternateColorCodes('&', lines[i]));
|
||||||
}
|
}
|
||||||
sign.update();
|
sign.update();
|
||||||
|
|
||||||
ProtocolLibrary.getProtocolManager().removePacketListener(this);
|
|
||||||
});
|
});
|
||||||
}
|
return o;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren