Skip to content

Commit

Permalink
improve lower version support
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyrbu committed Apr 23, 2023
1 parent 280436f commit fb3d9ea
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 20 deletions.
14 changes: 12 additions & 2 deletions src/main/java/io/github/znetworkw/znpcservers/npc/NPC.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -238,7 +241,7 @@ public synchronized void spawn(ZUser user) {
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) {
Expand All @@ -247,6 +250,13 @@ public synchronized void spawn(ZUser user) {
}
}

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);
Expand All @@ -256,7 +266,7 @@ public synchronized void delete(ZUser user) {
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));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand Down

0 comments on commit fb3d9ea

Please sign in to comment.