This commit is contained in:
NK 2022-12-27 19:44:15 +00:00
parent 6525ea9f65
commit ce5ad39302
5 changed files with 21 additions and 32 deletions

View file

@ -24,7 +24,7 @@ public final class NullValkyrie extends JavaPlugin {
Bukkit.getPluginManager().registerEvents(new ScoreboardListener(), this); Bukkit.getPluginManager().registerEvents(new ScoreboardListener(), this);
Bukkit.getPluginManager().registerEvents(new CustomItemEvents(), this); Bukkit.getPluginManager().registerEvents(new CustomItemEvents(), this);
Bukkit.getPluginManager().registerEvents(new DamageEffectEvents(), this); Bukkit.getPluginManager().registerEvents(new DamageEffectEvents(), this);
Bukkit.getPluginManager().registerEvents(new NPCEvents(), this); Bukkit.getPluginManager().registerEvents(new CustomEvents(), this);
new DiscordClientManager(); new DiscordClientManager();
NPCDataManager.reloadNPC(); NPCDataManager.reloadNPC();
CryptoMiner.reloadMiner(); CryptoMiner.reloadMiner();

View file

@ -102,5 +102,7 @@ public class NPCManager {
NPCs.put(ep.getId(), ep); NPCs.put(ep.getId(), ep);
} }
} }
public static ServerPlayer getNPC(int id) {
return NPCs.get(id);
}
} }

View file

@ -1,11 +1,14 @@
package me.night.nullvalkyrie.events.listeners; 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.events.custom.RightClickNPCEvent;
import me.night.nullvalkyrie.entities.npcs.NPCManager; import me.night.nullvalkyrie.entities.npcs.NPCManager;
import me.night.nullvalkyrie.util.Util; import me.night.nullvalkyrie.util.Util;
import net.minecraft.network.protocol.game.ClientboundMoveEntityPacket; import net.minecraft.network.protocol.game.ClientboundMoveEntityPacket;
import net.minecraft.network.protocol.game.ClientboundRotateHeadPacket; import net.minecraft.network.protocol.game.ClientboundRotateHeadPacket;
import net.minecraft.server.network.ServerGamePacketListenerImpl; import net.minecraft.server.network.ServerGamePacketListenerImpl;
import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -13,15 +16,21 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerMoveEvent;
public class NPCEvents implements Listener { public class CustomEvents implements Listener {
@EventHandler @EventHandler
public void onClick(RightClickNPCEvent e) { public void onClick(RightClickNPCEvent e) {
Player player = e.getPlayer(); Player player = e.getPlayer();
if (e.getNPC().getBukkitEntity().getName().contains("SAI")) { if (e.getNPC().getBukkitEntity().getName().contains("VETTEL")) {
player.sendMessage(Util.color("Hi")); 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 @EventHandler
public void onMove(PlayerMoveEvent e) { public void onMove(PlayerMoveEvent e) {
NPCManager.getNPCs().values().forEach(npc -> { NPCManager.getNPCs().values().forEach(npc -> {

View file

@ -1,7 +1,5 @@
package me.night.nullvalkyrie.events.listeners; 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.packets.handle.PacketInjector;
import me.night.nullvalkyrie.util.Util; import me.night.nullvalkyrie.util.Util;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -49,13 +47,6 @@ public class ServerEvents implements Listener {
ee.printStackTrace(); 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 @EventHandler
public void onWeatherChange(WeatherChangeEvent e) { public void onWeatherChange(WeatherChangeEvent e) {

View file

@ -66,16 +66,6 @@ public class PacketHandler extends ChannelDuplexHandler {
if (packet.getClass().getSimpleName().equalsIgnoreCase("PacketPlayInUseEntity")) { if (packet.getClass().getSimpleName().equalsIgnoreCase("PacketPlayInUseEntity")) {
ServerboundInteractPacket pk = (ServerboundInteractPacket) packet; ServerboundInteractPacket pk = (ServerboundInteractPacket) packet;
int entityID = (int) Util.getFieldValue(packet, "a"); 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"); boolean sneak = (boolean) Util.getFieldValue(packet, "c");
Bukkit.getScheduler().scheduleSyncDelayedTask(NullValkyrie.getPlugin(NullValkyrie.class), () -> { Bukkit.getScheduler().scheduleSyncDelayedTask(NullValkyrie.getPlugin(NullValkyrie.class), () -> {
net.minecraft.world.entity.decoration.ArmorStand[] stands = PerPlayerHologram.getHolograms().get(entityID); net.minecraft.world.entity.decoration.ArmorStand[] stands = PerPlayerHologram.getHolograms().get(entityID);
@ -86,18 +76,15 @@ public class PacketHandler extends ChannelDuplexHandler {
} }
}, 0); }, 0);
Object data = Util.getFieldValue(pk, "b"); Object data = Util.getFieldValue(pk, "b");
if (data.toString().split("\\$")[1].charAt(0) == 'e') if (data.toString().split("\\$")[1].charAt(0) == 'e') return;
return;
try { try {
Object hand = Util.getFieldValue(data, "a"); Object hand = Util.getFieldValue(data, "a");
if (!hand.toString().equals("MAIN_HAND")) return; if (!hand.toString().equals("MAIN_HAND")) return;
ServerPlayer npc = NPCManager.getNPC(entityID);
if (npc == null) return;
//Right Click //Right Click
for (ServerPlayer npcs : NPCManager.getNPCs().values()) { if (npc.getBukkitEntity().getEntityId() == entityID && sneak)
if (npcs.getBukkitEntity().getEntityId() == entityID && sneak) { Bukkit.getScheduler().scheduleSyncDelayedTask(NullValkyrie.getPlugin(NullValkyrie.class), () -> Bukkit.getPluginManager().callEvent(new RightClickNPCEvent(player, npc)), 0);
Bukkit.getScheduler().scheduleSyncDelayedTask(NullValkyrie.getPlugin(NullValkyrie.class), () -> Bukkit.getPluginManager().callEvent(new RightClickNPCEvent(player, npcs)), 0);
}
}
} catch (NoSuchFieldException x) { } catch (NoSuchFieldException x) {
//Left Click //Left Click
} }