NullValkyrie

Minecraft 1.19 multipurpose plugin for spigot servers with a lot of features where most modern servers have.
git clone https://codeberg.org/night0721/NullValkyrie
Log | Files | Refs | README | LICENSE

CustomEvents.java (2414B)


      1 package me.night.nullvalkyrie.events.listeners;
      2 
      3 import me.night.nullvalkyrie.entities.holograms.PerPlayerHologram;
      4 import me.night.nullvalkyrie.events.custom.InteractHologramEvent;
      5 import me.night.nullvalkyrie.events.custom.RightClickNPCEvent;
      6 import me.night.nullvalkyrie.entities.npcs.NPCManager;
      7 import me.night.nullvalkyrie.util.Util;
      8 import net.minecraft.network.protocol.game.ClientboundMoveEntityPacket;
      9 import net.minecraft.network.protocol.game.ClientboundRotateHeadPacket;
     10 import net.minecraft.server.network.ServerGamePacketListenerImpl;
     11 import org.bukkit.ChatColor;
     12 import org.bukkit.Location;
     13 import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer;
     14 import org.bukkit.entity.Player;
     15 import org.bukkit.event.EventHandler;
     16 import org.bukkit.event.Listener;
     17 import org.bukkit.event.player.PlayerMoveEvent;
     18 
     19 public class CustomEvents implements Listener {
     20     @EventHandler
     21     public void onClick(RightClickNPCEvent e) {
     22         Player player = e.getPlayer();
     23         if (e.getNPC().getBukkitEntity().getName().contains("VETTEL")) {
     24             player.sendMessage(Util.color("Hi"));
     25         }
     26     }
     27     @EventHandler
     28     public void onClickHologram(InteractHologramEvent e) {
     29         if (e.getHologram().getCustomName() == null) return;
     30         if (e.getHologram().getCustomName().equals(ChatColor.GOLD + ChatColor.BOLD.toString() + "CLICK")) {
     31             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()}));
     32         }
     33     }
     34     @EventHandler
     35     public void onMove(PlayerMoveEvent e) {
     36         NPCManager.getNPCs().values().forEach(npc -> {
     37             Location location = npc.getBukkitEntity().getLocation();
     38             location.setDirection(e.getPlayer().getLocation().subtract(location).toVector());
     39             float yaw = location.getYaw();
     40             float pitch = location.getPitch();
     41             ServerGamePacketListenerImpl con = ((CraftPlayer) e.getPlayer()).getHandle().connection;
     42             con.send(new ClientboundRotateHeadPacket(npc, (byte) ((yaw % 360) * 256 / 360)));
     43             con.send(new ClientboundMoveEntityPacket.Rot(npc.getBukkitEntity().getEntityId(), (byte) ((yaw % 360) * 256 / 360), (byte) ((pitch % 360) * 256 / 360), false));
     44         });
     45     }
     46 }