improve lower version support

This commit is contained in:
Pyrbu 2023-04-23 03:10:50 +01:00
parent 280436fa91
commit fb3d9ea3a3
3 changed files with 48 additions and 20 deletions

@ -1,7 +1,10 @@
package io.github.znetworkw.znpcservers.npc;
import com.github.retrooper.packetevents.PacketEvents;
import com.github.retrooper.packetevents.manager.server.ServerVersion;
import com.github.retrooper.packetevents.protocol.player.Equipment;
import com.github.retrooper.packetevents.protocol.player.UserProfile;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import com.github.retrooper.packetevents.wrapper.play.server.*;
import com.google.common.collect.ImmutableList;
import com.mojang.authlib.GameProfile;
@ -238,7 +241,7 @@ public class NPC {
sendEquipPackets(user);
lookAt(user, getLocation(), true);
if (npcIsPlayer) ZNPCsPlus.SCHEDULER.scheduleSyncDelayedTask(() -> {
PacketEvents.getAPI().getPlayerManager().sendPacket(player, new WrapperPlayServerPlayerInfoRemove(gameProfile.getId()));
removeFromTab(player);
Utils.sendPackets(user, this.updateTabConstructor);
}, 60);
} catch (ReflectiveOperationException operationException) {
@ -247,6 +250,13 @@ public class NPC {
}
}
private void removeFromTab(Player player) {
PacketWrapper<?> packet;
if (PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_19_3)) packet = new WrapperPlayServerPlayerInfoRemove(gameProfile.getId());
else packet = new WrapperPlayServerPlayerInfo(WrapperPlayServerPlayerInfo.Action.REMOVE_PLAYER, new WrapperPlayServerPlayerInfo.PlayerData(null, new UserProfile(gameProfile.getId(), gameProfile.getName()), null, 1));
PacketEvents.getAPI().getPlayerManager().sendPacket(player, packet);
}
public synchronized void delete(ZUser user) {
if (!this.viewers.contains(user)) throw new IllegalStateException(user.getUUID().toString() + " is not a viewer.");
this.viewers.remove(user);
@ -256,7 +266,7 @@ public class NPC {
private void handleDelete(ZUser user) {
Player player = user.toPlayer();
this.hologram.delete(user);
if (this.npcPojo.getNpcType() == NPCType.PLAYER) PacketEvents.getAPI().getPlayerManager().sendPacket(player, new WrapperPlayServerPlayerInfoRemove(gameProfile.getId()));
if (this.npcPojo.getNpcType() == NPCType.PLAYER) removeFromTab(player);
PacketEvents.getAPI().getPlayerManager().sendPacket(player, new WrapperPlayServerDestroyEntities(this.entityID));
}

@ -93,7 +93,8 @@ public enum NPCType {
ZOMBIE(ENTITY_ZOMBIE_CLASS, 0.135, "setBaby"),
ZOMBIE_HORSE(ENTITY_ZOMBIE_HORSE_CLASS, -0.215, "setBaby"),
ZOMBIE_VILLAGER(ENTITY_ZOMBIE_VILLAGER_CLASS, 0.135, "setVillagerType", "setVillagerProfession", "setBaby"),
ZOMBIFIED_PIGLIN(ENTITY_ZOMBIFIED_PIGLIN_CLASS, 0.135, "setBaby");
ZOMBIFIED_PIGLIN(Utils.versionNewer(16) ? ENTITY_ZOMBIFIED_PIGLIN_CLASS : null, 0.135, "setBaby"),
PIG_ZOMBIE(Utils.versionNewer(16) ? null : ENTITY_ZOMBIFIED_PIGLIN_CLASS, 0.135);
private final double holoHeight;
private final CustomizationLoader customizationLoader;

@ -88,15 +88,18 @@ public final class Reflections {
public static final Class<?> ENTITY_DONKEY_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY)
.withSubClass("animal.horse")
.withClassName("EntityHorseDonkey")).get();
.withClassName("EntityHorseDonkey")
.setStrict(Utils.versionNewer(11))).get();
public static final Class<?> ENTITY_DROWNED_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY)
.withSubClass("monster")
.withClassName("EntityDrowned").setStrict(Utils.versionNewer(13))).get();
.withClassName("EntityDrowned")
.setStrict(Utils.versionNewer(13))).get();
public static final Class<?> ENTITY_ELDER_GUARDIAN_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY)
.withSubClass("monster")
.withClassName("EntityGuardianElder")).get();
.withClassName("EntityGuardianElder")
.setStrict(Utils.versionNewer(11))).get();
public static final Class<?> ENTITY_ENDER_DRAGON_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY)
.withSubClass("boss.enderdragon")
@ -151,11 +154,13 @@ public final class Reflections {
public static final Class<?> ENTITY_HUSK_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY)
.withSubClass("monster")
.withClassName("EntityZombieHusk").setStrict(Utils.versionNewer(10))).get();
.withClassName("EntityZombieHusk")
.setStrict(Utils.versionNewer(11))).get();
public static final Class<?> ENTITY_ILLUSIONER_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY)
.withSubClass("monster")
.withClassName("EntityIllagerIllusioner").setStrict(Utils.versionNewer(11))).get();
.withClassName("EntityIllagerIllusioner")
.setStrict(Utils.versionNewer(12))).get();
public static final Class<?> ENTITY_IRON_GOLEM_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY)
.withSubClass("animal")
@ -175,7 +180,8 @@ public final class Reflections {
public static final Class<?> ENTITY_MULE_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY)
.withSubClass("animal.horse")
.withClassName("EntityHorseMule")).get();
.withClassName("EntityHorseMule")
.setStrict(Utils.versionNewer(11))).get();
public static final Class<?> ENTITY_OCELOT_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY)
.withSubClass("animal")
@ -250,7 +256,8 @@ public final class Reflections {
public static final Class<?> ENTITY_SKELETON_HORSE_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY)
.withSubClass("animal.horse")
.withClassName("EntityHorseSkeleton")).get();
.withClassName("EntityHorseSkeleton")
.setStrict(Utils.versionNewer(11))).get();
public static final Class<?> ENTITY_SLIME_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY)
.withSubClass("monster")
@ -271,19 +278,23 @@ public final class Reflections {
public static final Class<?> ENTITY_STRAY_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY)
.withSubClass("monster")
.withClassName("EntitySkeletonStray").setStrict(Utils.versionNewer(10))).get();
.withClassName("EntitySkeletonStray")
.setStrict(Utils.versionNewer(11))).get();
public static final Class<?> ENTITY_STRIDER_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY)
.withSubClass("monster")
.withClassName("EntityStrider").setStrict(Utils.versionNewer(16))).get();
.withClassName("EntityStrider")
.setStrict(Utils.versionNewer(16))).get();
public static final Class<?> ENTITY_TADPOLE_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY)
.withSubClass("animal.frog")
.withClassName("Tadpole").setStrict(Utils.versionNewer(19))).get();
.withClassName("Tadpole")
.setStrict(Utils.versionNewer(19))).get();
public static final Class<?> ENTITY_TRADER_LLAMA_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY)
.withSubClass("animal.horse")
.withClassName("EntityLlamaTrader").setStrict(Utils.versionNewer(11))).get();
.withClassName("EntityLlamaTrader")
.setStrict(Utils.versionNewer(14))).get();
public static final Class<?> ENTITY_TROPICAL_FISH_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY)
.withSubClass("animal")
@ -295,7 +306,8 @@ public final class Reflections {
public static final Class<?> ENTITY_VEX_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY)
.withSubClass("monster")
.withClassName("EntityVex").setStrict(Utils.versionNewer(11))).get();
.withClassName("EntityVex")
.setStrict(Utils.versionNewer(11))).get();
public static final Class<?> ENTITY_VILLAGER_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY)
.withSubClass("npc")
@ -307,12 +319,14 @@ public final class Reflections {
public static final Class<?> ENTITY_WANDERING_TRADER_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY)
.withSubClass("npc")
.withClassName("EntityVillagerTrader").setStrict(Utils.versionNewer(14))).get();
.withClassName("EntityVillagerTrader")
.setStrict(Utils.versionNewer(14))).get();
public static final Class<?> ENTITY_WARDEN = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY)
.withSubClass("monster.warden")
.withClassName("EntityWarden")
.withClassName("Warden").setStrict(Utils.versionNewer(19))).get();
.withClassName("Warden")
.setStrict(Utils.versionNewer(19))).get();
public static final Class<?> ENTITY_WITCH_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY)
.withSubClass("monster")
@ -324,7 +338,8 @@ public final class Reflections {
public static final Class<?> ENTITY_WITHER_SKELETON_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY)
.withSubClass("monster")
.withClassName("EntitySkeletonWither")).get();
.withClassName("EntitySkeletonWither")
.setStrict(Utils.versionNewer(11))).get();
public static final Class<?> ENTITY_WOLF_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY)
.withSubClass("animal")
@ -340,11 +355,13 @@ public final class Reflections {
public static final Class<?> ENTITY_ZOMBIE_HORSE_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY)
.withSubClass("animal.horse")
.withClassName("EntityHorseZombie")).get();
.withClassName("EntityHorseZombie")
.setStrict(Utils.versionNewer(11))).get();
public static final Class<?> ENTITY_ZOMBIE_VILLAGER_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY)
.withSubClass("monster")
.withClassName("EntityZombieVillager")).get();
.withClassName("EntityZombieVillager")
.setStrict(Utils.versionNewer(11))).get();
public static final Class<?> ENTITY_ZOMBIFIED_PIGLIN_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY)
.withSubClass("monster")