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 6da3c9a..62f14b5 100644 --- a/src/main/java/me/night/nullvalkyrie/entities/npcs/NPCManager.java +++ b/src/main/java/me/night/nullvalkyrie/entities/npcs/NPCManager.java @@ -9,17 +9,17 @@ import me.night.nullvalkyrie.util.*; import net.minecraft.network.protocol.game.*; import net.minecraft.network.syncher.*; import net.minecraft.server.MinecraftServer; -import net.minecraft.server.level.EntityPlayer; -import net.minecraft.server.level.WorldServer; -import net.minecraft.server.network.PlayerConnection; -import net.minecraft.world.entity.EnumItemSlot; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerGamePacketListenerImpl; +import net.minecraft.world.entity.EquipmentSlot; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; -import org.bukkit.craftbukkit.v1_19_R1.CraftServer; -import org.bukkit.craftbukkit.v1_19_R1.CraftWorld; -import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack; +import org.bukkit.craftbukkit.v1_19_R2.CraftServer; +import org.bukkit.craftbukkit.v1_19_R2.CraftWorld; +import org.bukkit.craftbukkit.v1_19_R2.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_19_R2.inventory.CraftItemStack; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -29,60 +29,62 @@ import java.util.List; import java.util.UUID; public class NPCManager { - private static final List NPCs = new ArrayList<>(); + private static final List NPCs = new ArrayList<>(); - public static List getNPCs() { + public static List getNPCs() { return NPCs; } public static void createNPC(Player player, String name) { // name must be less than 16 characters including color codes - EntityPlayer sp = ((CraftPlayer) player).getHandle(); - MinecraftServer server = sp.c; - WorldServer level = ((CraftWorld) player.getLocation().getWorld()).getHandle(); + ServerPlayer sp = ((CraftPlayer) player).getHandle(); + MinecraftServer server = sp.server; + ServerLevel level = ((CraftWorld) player.getLocation().getWorld()).getHandle(); GameProfile gameProfile = new GameProfile(UUID.randomUUID(), Util.color(name)); String[] skin = Skin.getSkin(player); gameProfile.getProperties().put("textures", new Property("textures", skin[0], skin[1])); - EntityPlayer npc = new EntityPlayer(server, level, gameProfile, null); + ServerPlayer npc = new ServerPlayer(server, level, gameProfile); Location location = player.getLocation(); - npc.a(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); + npc.setPos(location.getX(), location.getY(), location.getZ()); addNPCPacket(npc); NPCs.add(npc); NPCDataManager.setNPC(name, (int) player.getLocation().getX(), (int) player.getLocation().getY(), (int) player.getLocation().getZ(), (int) player.getLocation().getPitch(), (int) player.getLocation().getYaw(), player.getLocation().getWorld().getName(), skin[0], skin[1]); } - public static void addNPCPacket(EntityPlayer npc) { + public static void addNPCPacket(ServerPlayer npc) { for (Player player : Bukkit.getOnlinePlayers()) { - PlayerConnection pc = ((CraftPlayer) player).getHandle().b; - pc.a(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.a, npc)); - pc.a(new PacketPlayOutNamedEntitySpawn(npc)); - pc.a(new PacketPlayOutEntityHeadRotation(npc, (byte) (npc.getBukkitYaw() * 256 / 360))); - DataWatcher watcher = npc.ai(); - watcher.b(new DataWatcherObject<>(17, DataWatcherRegistry.a), (byte) 127); - pc.a(new PacketPlayOutEntityMetadata(npc.ae(), watcher, true)); - Bukkit.getScheduler().runTaskLaterAsynchronously(Main.getPlugin(Main.class), () -> pc.a(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.e, npc)), 50); + ServerGamePacketListenerImpl pc = ((CraftPlayer) player).getHandle().connection; + pc.send(new ClientboundPlayerInfoUpdatePacket(ClientboundPlayerInfoUpdatePacket.Action.ADD_PLAYER, npc)); + pc.send(new ClientboundAddPlayerPacket(npc)); + pc.send(new ClientboundRotateHeadPacket(npc, (byte) (npc.getBukkitYaw() * 256 / 360))); + SynchedEntityData watcher = npc.getEntityData(); + watcher.set(new EntityDataAccessor<>(17, EntityDataSerializers.BYTE), (byte) 127); + List> list = watcher.getNonDefaultValues(); + pc.send(new ClientboundSetEntityDataPacket(npc.getBukkitEntity().getEntityId(), list)); + Bukkit.getScheduler().runTaskLaterAsynchronously(Main.getPlugin(Main.class), () -> pc.send(new ClientboundPlayerInfoRemovePacket(List.of(npc.getUUID()))), 50); ItemStack netheriteAxe = new ItemStack(Material.NETHERITE_AXE); ItemStack anotherAxe = new ItemStack(Material.NETHERITE_INGOT); - List> list = new ArrayList<>(); - list.add(new Pair<>(EnumItemSlot.a, CraftItemStack.asNMSCopy(netheriteAxe))); - list.add(new Pair<>(EnumItemSlot.b, CraftItemStack.asNMSCopy(anotherAxe))); - pc.a(new PacketPlayOutEntityEquipment(npc.ae(), list)); + List> itemList = new ArrayList<>(); + itemList.add(new Pair<>(EquipmentSlot.MAINHAND, CraftItemStack.asNMSCopy(netheriteAxe))); + itemList.add(new Pair<>(EquipmentSlot.OFFHAND, CraftItemStack.asNMSCopy(anotherAxe))); + pc.send(new ClientboundSetEquipmentPacket(npc.getBukkitEntity().getEntityId(), itemList)); } } public static void addJoinPacket(Player player) { - for (EntityPlayer npc : NPCs) { - PlayerConnection pc = ((CraftPlayer) player).getHandle().b; - pc.a(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.a, npc)); - pc.a(new PacketPlayOutNamedEntitySpawn(npc)); - pc.a(new PacketPlayOutEntityHeadRotation(npc, (byte) (npc.getBukkitYaw() * 256 / 360))); - DataWatcher watcher = npc.ai(); - watcher.b(new DataWatcherObject<>(17, DataWatcherRegistry.a), (byte) 127); - pc.a(new PacketPlayOutEntityMetadata(npc.ae(), watcher, true)); - Bukkit.getScheduler().runTaskLaterAsynchronously(Main.getPlugin(Main.class), () -> pc.a(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.e, npc)), 50); + for (ServerPlayer npc : NPCs) { + ServerGamePacketListenerImpl pc = ((CraftPlayer) player).getHandle().connection; + pc.send(new ClientboundPlayerInfoUpdatePacket(ClientboundPlayerInfoUpdatePacket.Action.ADD_PLAYER, npc)); + pc.send(new ClientboundAddPlayerPacket(npc)); + pc.send(new ClientboundRotateHeadPacket(npc, (byte) (npc.getBukkitYaw() * 256 / 360))); + SynchedEntityData watcher = npc.getEntityData(); + watcher.set(new EntityDataAccessor<>(17, EntityDataSerializers.BYTE), (byte) 127); + List> list = watcher.getNonDefaultValues(); + pc.send(new ClientboundSetEntityDataPacket(npc.getBukkitEntity().getEntityId(), list)); + Bukkit.getScheduler().runTaskLaterAsynchronously(Main.getPlugin(Main.class), () -> pc.send(new ClientboundPlayerInfoRemovePacket(List.of(npc.getUUID()))), 50); ItemStack netheriteAxe = new ItemStack(Material.NETHERITE_AXE); ItemStack anotherAxe = new ItemStack(Material.NETHERITE_INGOT); - List> list = new ArrayList<>(); - list.add(new Pair<>(EnumItemSlot.a, CraftItemStack.asNMSCopy(netheriteAxe))); - list.add(new Pair<>(EnumItemSlot.b, CraftItemStack.asNMSCopy(anotherAxe))); - pc.a(new PacketPlayOutEntityEquipment(npc.ae(), list)); + List> itemList = new ArrayList<>(); + itemList.add(new Pair<>(EquipmentSlot.MAINHAND, CraftItemStack.asNMSCopy(netheriteAxe))); + itemList.add(new Pair<>(EquipmentSlot.OFFHAND, CraftItemStack.asNMSCopy(anotherAxe))); + pc.send(new ClientboundSetEquipmentPacket(npc.getBukkitEntity().getEntityId(), itemList)); } } public static void reloadNPC(List> npcs) { @@ -91,9 +93,9 @@ public class NPCManager { GameProfile gameProfile = new GameProfile(UUID.randomUUID(), Util.color((String) npc.get("name"))); gameProfile.getProperties().put("textures", new Property("textures", (String) npc.get("texture"), (String) npc.get("signature"))); MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); - WorldServer w = ((CraftWorld) location.getWorld()).getHandle(); - EntityPlayer ep = new EntityPlayer(server, w, gameProfile, null); - ep.a(location.getX(), location.getY(), location.getZ(), location.getPitch(), location.getPitch()); // NMS: 1.19.2 https://nms.screamingsandals.org/1.19.2/net/minecraft/world/entity/Entity.html absMoveTo + ServerLevel w = ((CraftWorld) location.getWorld()).getHandle(); + ServerPlayer ep = new ServerPlayer(server, w, gameProfile); + ep.setPos(location.getX(), location.getY(), location.getZ()); // NMS: 1.19.2 https://nms.screamingsandals.org/1.19.2/net/minecraft/world/entity/Entity.html absMoveTo addNPCPacket(ep); NPCs.add(ep); } diff --git a/src/main/java/me/night/nullvalkyrie/events/listeners/NPCEvents.java b/src/main/java/me/night/nullvalkyrie/events/listeners/NPCEvents.java index 627a368..407a40f 100644 --- a/src/main/java/me/night/nullvalkyrie/events/listeners/NPCEvents.java +++ b/src/main/java/me/night/nullvalkyrie/events/listeners/NPCEvents.java @@ -3,11 +3,11 @@ package me.night.nullvalkyrie.events.listeners; 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.PacketPlayOutEntity; -import net.minecraft.network.protocol.game.PacketPlayOutEntityHeadRotation; -import net.minecraft.server.network.PlayerConnection; +import net.minecraft.network.protocol.game.ClientboundMoveEntityPacket; +import net.minecraft.network.protocol.game.ClientboundRotateHeadPacket; +import net.minecraft.server.network.ServerGamePacketListenerImpl; import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_19_R2.entity.CraftPlayer; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -17,7 +17,7 @@ public class NPCEvents implements Listener { @EventHandler public void onClick(RightClickNPCEvent e) { Player player = e.getPlayer(); - if (e.getNPC().getBukkitEntity().getName().equalsIgnoreCase(Util.color("&1&lRB18"))) { + if (e.getNPC().getBukkitEntity().getName().contains("SAI")) { player.sendMessage(Util.color("Hi")); } } @@ -29,9 +29,9 @@ public class NPCEvents implements Listener { location.setDirection(e.getPlayer().getLocation().subtract(location).toVector()); float yaw = location.getYaw(); float pitch = location.getPitch(); - PlayerConnection con = ((CraftPlayer) e.getPlayer()).getHandle().b; - con.a(new PacketPlayOutEntityHeadRotation(npc, (byte) ((yaw % 360) * 256 / 360))); - con.a(new PacketPlayOutEntity.PacketPlayOutEntityLook(npc.ae(), (byte) ((yaw % 360) * 256 / 360), (byte) ((pitch % 360) * 256 / 360), false)); + ServerGamePacketListenerImpl con = ((CraftPlayer) e.getPlayer()).getHandle().connection; + con.send(new ClientboundRotateHeadPacket(npc, (byte) ((yaw % 360) * 256 / 360))); + con.send(new ClientboundMoveEntityPacket.Rot(npc.getBukkitEntity().getEntityId(), (byte) ((yaw % 360) * 256 / 360), (byte) ((pitch % 360) * 256 / 360), false)); }); } } 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 08d70fe..b1afd18 100644 --- a/src/main/java/me/night/nullvalkyrie/events/listeners/ServerEvents.java +++ b/src/main/java/me/night/nullvalkyrie/events/listeners/ServerEvents.java @@ -10,6 +10,7 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.event.player.PlayerResourcePackStatusEvent; import org.bukkit.event.server.ServerListPingEvent; import org.bukkit.event.weather.WeatherChangeEvent; @@ -18,25 +19,29 @@ import java.io.File; public class ServerEvents implements Listener { public final BossBar bossbar; public final PacketInjector injector; + public ServerEvents() { bossbar = Bukkit.createBossBar(ChatColor.GOLD + "Kuudra", BarColor.RED, BarStyle.SEGMENTED_12); this.injector = new PacketInjector(); } + @EventHandler public void onJoin(PlayerJoinEvent e) { bossbar.addPlayer(e.getPlayer()); injector.addPlayer(e.getPlayer()); + e.getPlayer().setResourcePack("https://www.dropbox.com/s/7y7p93xzhar6vvw/%C2%A7b%C2%A7lNKRP%201.19.3.zip?dl=1"); } @EventHandler public void onQuit(PlayerQuitEvent e) { injector.removePlayer(e.getPlayer()); } + @EventHandler public void onPing(ServerListPingEvent e) { e.setMaxPlayers(8964); String s = Util.centerText("Vanadium", 45); - String s2 = Util.centerText("Support 1.19.2", 45); + String s2 = Util.centerText("Support 1.19.3", 45); e.setMotd(ChatColor.AQUA.toString() + ChatColor.BOLD + s + "\n" + ChatColor.GOLD + ChatColor.BOLD + s2); try { e.setServerIcon(Bukkit.loadServerIcon(new File("nuke.png"))); @@ -44,6 +49,7 @@ public class ServerEvents implements Listener { ee.printStackTrace(); } } + @EventHandler public void onClickHologram(InteractHologramEvent e) { if (e.getHologram().getCustomName() == null) return; @@ -51,8 +57,16 @@ public class ServerEvents implements Listener { // TODO: change hologram things } } + @EventHandler public void onWeatherChange(WeatherChangeEvent e) { e.setCancelled(true); } + + @EventHandler + public void onResourcePackChange(PlayerResourcePackStatusEvent e) { + if (e.getStatus() == PlayerResourcePackStatusEvent.Status.DECLINED || e.getStatus() == PlayerResourcePackStatusEvent.Status.FAILED_DOWNLOAD) { + e.getPlayer().kickPlayer("You must download the resource pack to play on this server!"); + } + } }