From 42fbf357c79d9a852a77650da65918f780d6dea6 Mon Sep 17 00:00:00 2001 From: NK Date: Thu, 22 Dec 2022 23:45:25 +0000 Subject: [PATCH] npcs 1.19.3 --- .../night/nullvalkyrie/packets/PacketHandler.java | 13 ++++++------- .../night/nullvalkyrie/packets/PacketInjector.java | 6 +++--- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/main/java/me/night/nullvalkyrie/packets/PacketHandler.java b/src/main/java/me/night/nullvalkyrie/packets/PacketHandler.java index 8420654..0414829 100644 --- a/src/main/java/me/night/nullvalkyrie/packets/PacketHandler.java +++ b/src/main/java/me/night/nullvalkyrie/packets/PacketHandler.java @@ -8,8 +8,8 @@ import me.night.nullvalkyrie.entities.npcs.NPCManager; import me.night.nullvalkyrie.events.custom.InteractHologramEvent; import me.night.nullvalkyrie.events.custom.RightClickNPCEvent; import me.night.nullvalkyrie.util.Util; -import net.minecraft.network.protocol.game.PacketPlayInUseEntity; -import net.minecraft.server.level.EntityPlayer; +import net.minecraft.network.protocol.game.ServerboundInteractPacket; +import net.minecraft.server.level.ServerPlayer; import org.bukkit.Bukkit; import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Entity; @@ -31,7 +31,7 @@ public class PacketHandler extends ChannelDuplexHandler { @Override public void channelRead(ChannelHandlerContext c, Object packet) throws Exception { if (packet.getClass().getSimpleName().equalsIgnoreCase("PacketPlayInUseEntity")) { - PacketPlayInUseEntity pk = (PacketPlayInUseEntity) packet; + ServerboundInteractPacket pk = (ServerboundInteractPacket) packet; int entityID = (int) Util.getFieldValue(packet, "a"); boolean sneak = (boolean) Util.getFieldValue(packet, "c"); Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getPlugin(Main.class), () -> { @@ -42,15 +42,14 @@ public class PacketHandler extends ChannelDuplexHandler { } }, 0); Object data = Util.getFieldValue(pk, "b"); - if (data.toString().split("\\$")[1].charAt(0) == 'e') { + if (data.toString().split("\\$")[1].charAt(0) == 'e') return; - } try { Object hand = Util.getFieldValue(data, "a"); if (!hand.toString().equals("MAIN_HAND")) return; //Right Click - for (EntityPlayer npcs : NPCManager.getNPCs()) { - if (npcs.ae() == entityID && sneak) { + for (ServerPlayer npcs : NPCManager.getNPCs()) { + if (npcs.getBukkitEntity().getEntityId() == entityID && sneak) { Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getPlugin(Main.class), () -> Bukkit.getPluginManager().callEvent(new RightClickNPCEvent(player, npcs)), 0); } diff --git a/src/main/java/me/night/nullvalkyrie/packets/PacketInjector.java b/src/main/java/me/night/nullvalkyrie/packets/PacketInjector.java index 4e18f42..4c66f18 100644 --- a/src/main/java/me/night/nullvalkyrie/packets/PacketInjector.java +++ b/src/main/java/me/night/nullvalkyrie/packets/PacketInjector.java @@ -1,13 +1,13 @@ package me.night.nullvalkyrie.packets; import io.netty.channel.Channel; -import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_19_R2.entity.CraftPlayer; import org.bukkit.entity.Player; public class PacketInjector { public void addPlayer(Player p) { try { - Channel ch = ((CraftPlayer) p).getHandle().b.b.m; + Channel ch = ((CraftPlayer) p).getHandle().connection.getConnection().channel; if (ch.pipeline().get("PacketInjector") == null) { PacketHandler h = new PacketHandler(p); ch.pipeline().addBefore("packet_handler", "PacketInjector", h); @@ -19,7 +19,7 @@ public class PacketInjector { public void removePlayer(Player p) { try { - Channel ch = ((CraftPlayer) p).getHandle().b.b.m; // NMS: 1.19.2 https://nms.screamingsandals.org/1.19.2/net/minecraft/server/network/ServerGamePacketListenerImpl.html PlayerConnection -> NetworkManager -> Channel + Channel ch = ((CraftPlayer) p).getHandle().connection.getConnection().channel; // NMS: 1.19.2 https://nms.screamingsandals.org/1.19.2/net/minecraft/server/network/ServerGamePacketListenerImpl.html PlayerConnection -> NetworkManager -> Channel if (ch.pipeline().get("PacketInjector") != null) { ch.pipeline().remove("PacketInjector"); }