npcs 1.19.3

This commit is contained in:
NK 2022-12-22 23:45:25 +00:00
parent faf9caf6fd
commit 42fbf357c7
2 changed files with 9 additions and 10 deletions

View file

@ -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);
}

View file

@ -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");
}