use of net.minecraft.server.level.WorldServer in project Nokaut by smaks6.
the class NpcNew method spawnNPC.
// ChatColor.RED +
private EntityPlayer spawnNPC() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, NoSuchFieldException {
Location location = knockedPlayer.getLocation();
MinecraftServer nmsServer = (MinecraftServer) Reflection.getNMSServer();
WorldServer nmsWorld = (WorldServer) Reflection.getNMSWorld();
GameProfile gameProfile = new GameProfile(UUID.randomUUID(), knockedPlayer.getName());
if (is1_18()) {
if (Main.getVersion().equals("v1_18_R1")) {
Method method = EntityPlayer.class.getMethod("fp");
GameProfile knockedPlayerGameProfile = (GameProfile) method.invoke(((EntityPlayer) Reflection.getEntityPlayer(knockedPlayer)));
gameProfile.getProperties().putAll(knockedPlayerGameProfile.getProperties());
} else {
gameProfile.getProperties().putAll(((EntityPlayer) Reflection.getEntityPlayer(knockedPlayer)).fq().getProperties());
}
} else {
Method method = EntityPlayer.class.getMethod("getProfile");
GameProfile knockedPlayerGameProfile = (GameProfile) method.invoke(((EntityPlayer) Reflection.getEntityPlayer(knockedPlayer)));
gameProfile.getProperties().putAll(knockedPlayerGameProfile.getProperties());
}
EntityPlayer npc = new EntityPlayer(nmsServer, nmsWorld, gameProfile);
setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), npc);
// npc.a(location.getX(), location.getY(), location.getZ(), location.getYaw(), 40f);
DataWatcher watcher = null;
if (is1_18()) {
entityplayerId = npc.ae();
} else {
Method getId = EntityPlayer.class.getMethod("getId");
entityplayerId = (int) getId.invoke(npc);
}
// a - ADD_Player
// e - REMOVE-PLAYER
sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.a, npc));
sendPacket(new PacketPlayOutNamedEntitySpawn(npc));
// d - swimming
if (is1_18()) {
watcher = npc.ai();
byte o = (Byte) watcher.a(DataWatcherRegistry.a.a(17));
watcher.b(DataWatcherRegistry.a.a(17), o);
watcher.b(DataWatcherRegistry.s.a(6), EntityPose.d);
sendPacket(new PacketPlayOutEntityMetadata(entityplayerId, watcher, true));
} else {
Method getDataWatcher = EntityPlayer.class.getMethod("getDataWatcher");
watcher = (DataWatcher) getDataWatcher.invoke(npc);
setPose(npc);
sendPacket(new PacketPlayOutEntityMetadata(entityplayerId, watcher, false));
}
return npc;
}
use of net.minecraft.server.level.WorldServer in project Panilla by ds58.
the class PacketInspector method checkPacketPlayOutSpawnEntity.
@Override
public void checkPacketPlayOutSpawnEntity(Object _packet) throws EntityNbtNotPermittedException {
if (_packet instanceof PacketPlayOutSpawnEntity) {
PacketPlayOutSpawnEntity packet = (PacketPlayOutSpawnEntity) _packet;
try {
Field typeField = PacketPlayOutSpawnEntity.class.getDeclaredField("d");
typeField.setAccessible(true);
UUID entityId = (UUID) typeField.get(packet);
Entity entity = null;
for (WorldServer worldServer : MinecraftServer.getServer().getWorlds()) {
entity = worldServer.G.d().a(entityId);
if (entity != null)
break;
}
if (entity != null) {
if (entity instanceof EntityItem) {
EntityItem item = (EntityItem) entity;
if (item.getItemStack() == null) {
return;
}
if (!item.getItemStack().hasTag()) {
return;
}
INbtTagCompound tag = new NbtTagCompound(item.getItemStack().getTag());
String itemName = item.getItemStack().getItem().getName();
FailedNbt failedNbt = NbtChecks.checkAll(tag, itemName, panilla);
if (FailedNbt.fails(failedNbt)) {
throw new EntityNbtNotPermittedException(packet.getClass().getSimpleName(), false, failedNbt, entityId, entity.getWorld().getWorld().getName());
}
}
}
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
}
}
}
use of net.minecraft.server.level.WorldServer in project Panilla by ds58.
the class PacketInspector method stripNbtFromItemEntity.
@Override
public void stripNbtFromItemEntity(UUID entityId) {
Entity entity = null;
for (WorldServer worldServer : MinecraftServer.getServer().getWorlds()) {
entity = worldServer.G.d().a(entityId);
if (entity != null)
break;
}
if (entity instanceof EntityItem) {
EntityItem item = (EntityItem) entity;
if (item.getItemStack() == null)
return;
if (!item.getItemStack().hasTag())
return;
item.getItemStack().setTag(null);
}
}
use of net.minecraft.server.level.WorldServer in project Panilla by ds58.
the class PacketInspector method stripNbtFromItemEntity.
@Override
public void stripNbtFromItemEntity(UUID entityId) {
Entity entity = null;
for (WorldServer worldServer : MinecraftServer.getServer().F()) {
entity = worldServer.P.d().a(entityId);
if (entity != null)
break;
}
if (entity instanceof EntityItem) {
EntityItem item = (EntityItem) entity;
if (item.h() == null)
return;
if (!item.h().r())
return;
item.h().c((NBTTagCompound) null);
}
}
use of net.minecraft.server.level.WorldServer in project Panilla by ds58.
the class PacketInspector method checkPacketPlayOutSpawnEntity.
@Override
public void checkPacketPlayOutSpawnEntity(Object _packet) throws EntityNbtNotPermittedException {
if (_packet instanceof PacketPlayOutSpawnEntity) {
PacketPlayOutSpawnEntity packet = (PacketPlayOutSpawnEntity) _packet;
try {
Field typeField = PacketPlayOutSpawnEntity.class.getDeclaredField("d");
typeField.setAccessible(true);
UUID entityId = (UUID) typeField.get(packet);
Entity entity = null;
for (WorldServer worldServer : MinecraftServer.getServer().F()) {
entity = worldServer.P.d().a(entityId);
if (entity != null)
break;
}
if (entity != null) {
if (entity instanceof EntityItem) {
EntityItem item = (EntityItem) entity;
if (item.h() == null) {
return;
}
if (!item.h().r()) {
return;
}
INbtTagCompound tag = new NbtTagCompound(item.h().t());
String itemName = item.h().c().a();
FailedNbt failedNbt = NbtChecks.checkAll(tag, itemName, panilla);
if (FailedNbt.fails(failedNbt)) {
throw new EntityNbtNotPermittedException(packet.getClass().getSimpleName(), false, failedNbt, entityId, entity.W().getWorld().getName());
}
}
}
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
}
}
}
Aggregations