nms comments
This commit is contained in:
parent
0f39c1bc73
commit
5b6e509cbf
4 changed files with 41 additions and 31 deletions
|
@ -1,21 +1,12 @@
|
||||||
package me.night.nullvalkyrie.database;
|
package me.night.nullvalkyrie.database;
|
||||||
|
|
||||||
import com.mojang.authlib.GameProfile;
|
|
||||||
import com.mojang.authlib.properties.Property;
|
|
||||||
import com.mongodb.client.MongoCursor;
|
import com.mongodb.client.MongoCursor;
|
||||||
import me.night.nullvalkyrie.util.Util;
|
import me.night.nullvalkyrie.entities.npcs.NPCManager;
|
||||||
import net.minecraft.server.MinecraftServer;
|
|
||||||
import net.minecraft.server.level.EntityPlayer;
|
|
||||||
import net.minecraft.server.level.WorldServer;
|
|
||||||
import org.bson.Document;
|
import org.bson.Document;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.craftbukkit.v1_19_R1.CraftServer;
|
|
||||||
import org.bukkit.craftbukkit.v1_19_R1.CraftWorld;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import static me.night.nullvalkyrie.entities.npcs.NPCManager.*;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
public class NPCDataManager {
|
public class NPCDataManager {
|
||||||
|
@ -39,9 +30,11 @@ public class NPCDataManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void reloadNPC() {
|
public static void reloadNPC() {
|
||||||
|
List<HashMap<String, Object>> npcList = new ArrayList<>();
|
||||||
try (MongoCursor<Document> cursor = DatabaseManager.getNPCsDB().find().cursor()) {
|
try (MongoCursor<Document> cursor = DatabaseManager.getNPCsDB().find().cursor()) {
|
||||||
while (cursor.hasNext()) {
|
while (cursor.hasNext()) {
|
||||||
Document document = cursor.next();
|
Document document = cursor.next();
|
||||||
|
HashMap<String, Object> npc = new HashMap<>();
|
||||||
String name = document.getString("Name");
|
String name = document.getString("Name");
|
||||||
int x = document.getInteger("x");
|
int x = document.getInteger("x");
|
||||||
int y = document.getInteger("y");
|
int y = document.getInteger("y");
|
||||||
|
@ -51,18 +44,18 @@ public class NPCDataManager {
|
||||||
String world = document.getString("world");
|
String world = document.getString("world");
|
||||||
String texture = document.getString("texture");
|
String texture = document.getString("texture");
|
||||||
String signature = document.getString("signature");
|
String signature = document.getString("signature");
|
||||||
Location location = new Location(Bukkit.getWorld(world), x, y, z);
|
npc.put("name", name);
|
||||||
location.setPitch((float) pitch);
|
npc.put("x", x);
|
||||||
location.setYaw((float) yaw);
|
npc.put("y", y);
|
||||||
GameProfile gameProfile = new GameProfile(UUID.randomUUID(), Util.color(name));
|
npc.put("z", z);
|
||||||
gameProfile.getProperties().put("textures", new Property("textures", texture, signature));
|
npc.put("pitch", pitch);
|
||||||
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
|
npc.put("yaw", yaw);
|
||||||
WorldServer w = ((CraftWorld) location.getWorld()).getHandle();
|
npc.put("world", world);
|
||||||
EntityPlayer npc = new EntityPlayer(server, w, gameProfile, null);
|
npc.put("texture", texture);
|
||||||
npc.a(location.getX(), location.getY(), location.getZ(), location.getPitch(), location.getPitch());
|
npc.put("signature", signature);
|
||||||
addNPCPacket(npc);
|
npcList.add(npc);
|
||||||
getNPCs().add(npc);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
NPCManager.reloadNPC(npcList);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -16,6 +16,7 @@ import net.minecraft.world.entity.EnumItemSlot;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
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.CraftWorld;
|
||||||
import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer;
|
||||||
import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack;
|
import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack;
|
||||||
|
@ -23,6 +24,7 @@ import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@ -32,7 +34,7 @@ public class NPCManager {
|
||||||
public static List<EntityPlayer> getNPCs() {
|
public static List<EntityPlayer> getNPCs() {
|
||||||
return NPCs;
|
return NPCs;
|
||||||
}
|
}
|
||||||
public static void createNPC(Player player, String name) { //name must be less than 16 characters including color codes **
|
public static void createNPC(Player player, String name) { // name must be less than 16 characters including color codes
|
||||||
EntityPlayer sp = ((CraftPlayer) player).getHandle();
|
EntityPlayer sp = ((CraftPlayer) player).getHandle();
|
||||||
MinecraftServer server = sp.c;
|
MinecraftServer server = sp.c;
|
||||||
WorldServer level = ((CraftWorld) player.getLocation().getWorld()).getHandle();
|
WorldServer level = ((CraftWorld) player.getLocation().getWorld()).getHandle();
|
||||||
|
@ -83,5 +85,18 @@ public class NPCManager {
|
||||||
pc.a(new PacketPlayOutEntityEquipment(npc.ae(), list));
|
pc.a(new PacketPlayOutEntityEquipment(npc.ae(), list));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public static void reloadNPC(List<HashMap<String, Object>> npcs) {
|
||||||
|
for (HashMap<String, Object> npc : npcs) {
|
||||||
|
Location location = new Location(Bukkit.getWorld((String) npc.get("world")), (int) npc.get("x"), (int) npc.get("y"), (int) npc.get("z"), (int) npc.get("yaw"), (int) npc.get("pitch"));
|
||||||
|
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
|
||||||
|
addNPCPacket(ep);
|
||||||
|
NPCs.add(ep);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import org.bukkit.boss.*;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
import org.bukkit.event.server.ServerListPingEvent;
|
import org.bukkit.event.server.ServerListPingEvent;
|
||||||
import org.bukkit.event.weather.WeatherChangeEvent;
|
import org.bukkit.event.weather.WeatherChangeEvent;
|
||||||
|
|
||||||
|
@ -26,6 +27,11 @@ public class ServerEvents implements Listener {
|
||||||
bossbar.addPlayer(e.getPlayer());
|
bossbar.addPlayer(e.getPlayer());
|
||||||
injector.addPlayer(e.getPlayer());
|
injector.addPlayer(e.getPlayer());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onQuit(PlayerQuitEvent e) {
|
||||||
|
injector.removePlayer(e.getPlayer());
|
||||||
|
}
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPing(ServerListPingEvent e) {
|
public void onPing(ServerListPingEvent e) {
|
||||||
e.setMaxPlayers(8964);
|
e.setMaxPlayers(8964);
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
package me.night.nullvalkyrie.packets;
|
package me.night.nullvalkyrie.packets;
|
||||||
|
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import net.minecraft.server.level.EntityPlayer;
|
|
||||||
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;
|
||||||
|
|
||||||
public class PacketInjector {
|
public class PacketInjector {
|
||||||
public void addPlayer(Player p) {
|
public void addPlayer(Player p) {
|
||||||
try {
|
try {
|
||||||
Channel ch = nms(p).b.b.m;
|
Channel ch = ((CraftPlayer) p).getHandle().b.b.m;
|
||||||
if (ch.pipeline().get("PacketInjector") == null) {
|
if (ch.pipeline().get("PacketInjector") == null) {
|
||||||
PacketHandler h = new PacketHandler(p);
|
PacketHandler h = new PacketHandler(p);
|
||||||
ch.pipeline().addBefore("packet_handler", "PacketInjector", h);
|
ch.pipeline().addBefore("packet_handler", "PacketInjector", h);
|
||||||
|
@ -20,7 +19,7 @@ public class PacketInjector {
|
||||||
|
|
||||||
public void removePlayer(Player p) {
|
public void removePlayer(Player p) {
|
||||||
try {
|
try {
|
||||||
Channel ch = nms(p).b.b.m;
|
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
|
||||||
if (ch.pipeline().get("PacketInjector") != null) {
|
if (ch.pipeline().get("PacketInjector") != null) {
|
||||||
ch.pipeline().remove("PacketInjector");
|
ch.pipeline().remove("PacketInjector");
|
||||||
}
|
}
|
||||||
|
@ -29,7 +28,4 @@ public class PacketInjector {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static EntityPlayer nms(Player p) {
|
|
||||||
return ((CraftPlayer) p).getHandle();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue