diff --git a/src/main/java/me/night/nullvalkyrie/NullValkyrie.java b/src/main/java/me/night/nullvalkyrie/NullValkyrie.java index cc9b098..33c41a0 100644 --- a/src/main/java/me/night/nullvalkyrie/NullValkyrie.java +++ b/src/main/java/me/night/nullvalkyrie/NullValkyrie.java @@ -24,7 +24,7 @@ public final class NullValkyrie extends JavaPlugin { Bukkit.getPluginManager().registerEvents(new ScoreboardListener(), this); Bukkit.getPluginManager().registerEvents(new CustomItemEvents(), this); Bukkit.getPluginManager().registerEvents(new DamageEffectEvents(), this); - Bukkit.getPluginManager().registerEvents(new NPCEvents(), this); + Bukkit.getPluginManager().registerEvents(new CustomEvents(), this); new DiscordClientManager(); NPCDataManager.reloadNPC(); CryptoMiner.reloadMiner(); diff --git a/src/main/java/me/night/nullvalkyrie/entities/npcs/NPCManager.java b/src/main/java/me/night/nullvalkyrie/entities/npcs/NPCManager.java index 4e42948..f707106 100644 --- a/src/main/java/me/night/nullvalkyrie/entities/npcs/NPCManager.java +++ b/src/main/java/me/night/nullvalkyrie/entities/npcs/NPCManager.java @@ -102,5 +102,7 @@ public class NPCManager { NPCs.put(ep.getId(), ep); } } - + public static ServerPlayer getNPC(int id) { + return NPCs.get(id); + } } diff --git a/src/main/java/me/night/nullvalkyrie/events/listeners/NPCEvents.java b/src/main/java/me/night/nullvalkyrie/events/listeners/CustomEvents.java similarity index 65% rename from src/main/java/me/night/nullvalkyrie/events/listeners/NPCEvents.java rename to src/main/java/me/night/nullvalkyrie/events/listeners/CustomEvents.java index 8336806..da154de 100644 --- a/src/main/java/me/night/nullvalkyrie/events/listeners/NPCEvents.java +++ b/src/main/java/me/night/nullvalkyrie/events/listeners/CustomEvents.java @@ -1,11 +1,14 @@ package me.night.nullvalkyrie.events.listeners; +import me.night.nullvalkyrie.entities.holograms.PerPlayerHologram; +import me.night.nullvalkyrie.events.custom.InteractHologramEvent; import me.night.nullvalkyrie.events.custom.RightClickNPCEvent; import me.night.nullvalkyrie.entities.npcs.NPCManager; import me.night.nullvalkyrie.util.Util; import net.minecraft.network.protocol.game.ClientboundMoveEntityPacket; import net.minecraft.network.protocol.game.ClientboundRotateHeadPacket; import net.minecraft.server.network.ServerGamePacketListenerImpl; +import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; import org.bukkit.entity.Player; @@ -13,15 +16,21 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerMoveEvent; -public class NPCEvents implements Listener { +public class CustomEvents implements Listener { @EventHandler public void onClick(RightClickNPCEvent e) { Player player = e.getPlayer(); - if (e.getNPC().getBukkitEntity().getName().contains("SAI")) { + if (e.getNPC().getBukkitEntity().getName().contains("VETTEL")) { player.sendMessage(Util.color("Hi")); } } - + @EventHandler + public void onClickHologram(InteractHologramEvent e) { + if (e.getHologram().getCustomName() == null) return; + if (e.getHologram().getCustomName().equals(ChatColor.GOLD + ChatColor.BOLD.toString() + "CLICK")) { + e.getHologram().getNearbyEntities(0, 5, 0).forEach(entity -> new PerPlayerHologram(e.getPlayer(), new String[]{ChatColor.RED + "Player Info:", ChatColor.GOLD + "Name: " + ChatColor.AQUA + e.getPlayer().getName(), ChatColor.BLUE + "IP: " + e.getPlayer().getAddress()})); + } + } @EventHandler public void onMove(PlayerMoveEvent e) { NPCManager.getNPCs().values().forEach(npc -> { diff --git a/src/main/java/me/night/nullvalkyrie/events/listeners/ServerEvents.java b/src/main/java/me/night/nullvalkyrie/events/listeners/ServerEvents.java index 09a8f99..3c0bba4 100644 --- a/src/main/java/me/night/nullvalkyrie/events/listeners/ServerEvents.java +++ b/src/main/java/me/night/nullvalkyrie/events/listeners/ServerEvents.java @@ -1,7 +1,5 @@ package me.night.nullvalkyrie.events.listeners; -import me.night.nullvalkyrie.entities.holograms.PerPlayerHologram; -import me.night.nullvalkyrie.events.custom.InteractHologramEvent; import me.night.nullvalkyrie.packets.handle.PacketInjector; import me.night.nullvalkyrie.util.Util; import org.bukkit.Bukkit; @@ -49,13 +47,6 @@ public class ServerEvents implements Listener { ee.printStackTrace(); } } - @EventHandler - public void onClickHologram(InteractHologramEvent e) { - if (e.getHologram().getCustomName() == null) return; - if (e.getHologram().getCustomName().equals(ChatColor.GOLD + ChatColor.BOLD.toString() + "CLICK")) { - e.getHologram().getNearbyEntities(0, 5, 0).forEach(entity -> new PerPlayerHologram(e.getPlayer(), new String[]{ChatColor.RED + "Player Info:", ChatColor.GOLD + "Name: " + ChatColor.AQUA + e.getPlayer().getName(), ChatColor.BLUE + "IP: " + e.getPlayer().getAddress()})); - } - } @EventHandler public void onWeatherChange(WeatherChangeEvent e) { diff --git a/src/main/java/me/night/nullvalkyrie/packets/handle/PacketHandler.java b/src/main/java/me/night/nullvalkyrie/packets/handle/PacketHandler.java index bc136c5..2848562 100644 --- a/src/main/java/me/night/nullvalkyrie/packets/handle/PacketHandler.java +++ b/src/main/java/me/night/nullvalkyrie/packets/handle/PacketHandler.java @@ -66,16 +66,6 @@ public class PacketHandler extends ChannelDuplexHandler { if (packet.getClass().getSimpleName().equalsIgnoreCase("PacketPlayInUseEntity")) { ServerboundInteractPacket pk = (ServerboundInteractPacket) packet; int entityID = (int) Util.getFieldValue(packet, "a"); -// if (pk.getType() == ServerboundInteractPacket.Action.INTERACT) { -// Entity entity = ((CraftWorld) player.getWorld()).getHandle().getEntity(entityID); -// if (entity == null) return; -// if (entity instanceof ArmorStand) { -// Bukkit.getPluginManager().callEvent(new InteractHologramEvent(player, entity)); -// } -// if (NPCManager.isNPC(entity)) { -// Bukkit.getPluginManager().callEvent(new RightClickNPCEvent(player, entity)); -// } -// } boolean sneak = (boolean) Util.getFieldValue(packet, "c"); Bukkit.getScheduler().scheduleSyncDelayedTask(NullValkyrie.getPlugin(NullValkyrie.class), () -> { net.minecraft.world.entity.decoration.ArmorStand[] stands = PerPlayerHologram.getHolograms().get(entityID); @@ -86,18 +76,15 @@ public class PacketHandler extends ChannelDuplexHandler { } }, 0); Object data = Util.getFieldValue(pk, "b"); - if (data.toString().split("\\$")[1].charAt(0) == 'e') - return; + if (data.toString().split("\\$")[1].charAt(0) == 'e') return; try { Object hand = Util.getFieldValue(data, "a"); if (!hand.toString().equals("MAIN_HAND")) return; + ServerPlayer npc = NPCManager.getNPC(entityID); + if (npc == null) return; //Right Click - for (ServerPlayer npcs : NPCManager.getNPCs().values()) { - if (npcs.getBukkitEntity().getEntityId() == entityID && sneak) { - Bukkit.getScheduler().scheduleSyncDelayedTask(NullValkyrie.getPlugin(NullValkyrie.class), () -> Bukkit.getPluginManager().callEvent(new RightClickNPCEvent(player, npcs)), 0); - - } - } + if (npc.getBukkitEntity().getEntityId() == entityID && sneak) + Bukkit.getScheduler().scheduleSyncDelayedTask(NullValkyrie.getPlugin(NullValkyrie.class), () -> Bukkit.getPluginManager().callEvent(new RightClickNPCEvent(player, npc)), 0); } catch (NoSuchFieldException x) { //Left Click }