fix 1.20.2 player npcs and clean up 1.19.2 packets
This commit is contained in:
parent
24a26cfb04
commit
f3dd4e3495
3 changed files with 41 additions and 15 deletions
|
@ -29,10 +29,7 @@ import lol.pyr.znpcsplus.entity.EntityPropertyRegistryImpl;
|
|||
import lol.pyr.znpcsplus.interaction.ActionRegistry;
|
||||
import lol.pyr.znpcsplus.interaction.InteractionPacketListener;
|
||||
import lol.pyr.znpcsplus.npc.*;
|
||||
import lol.pyr.znpcsplus.packets.PacketFactory;
|
||||
import lol.pyr.znpcsplus.packets.V1_17PacketFactory;
|
||||
import lol.pyr.znpcsplus.packets.V1_19PacketFactory;
|
||||
import lol.pyr.znpcsplus.packets.V1_8PacketFactory;
|
||||
import lol.pyr.znpcsplus.packets.*;
|
||||
import lol.pyr.znpcsplus.parsers.*;
|
||||
import lol.pyr.znpcsplus.scheduling.FoliaScheduler;
|
||||
import lol.pyr.znpcsplus.scheduling.SpigotScheduler;
|
||||
|
@ -220,7 +217,8 @@ public class ZNpcsPlus {
|
|||
HashMap<ServerVersion, LazyLoader<? extends PacketFactory>> versions = new HashMap<>();
|
||||
versions.put(ServerVersion.V_1_8, LazyLoader.of(() -> new V1_8PacketFactory(scheduler, packetEvents, propertyRegistry, textSerializer)));
|
||||
versions.put(ServerVersion.V_1_17, LazyLoader.of(() -> new V1_17PacketFactory(scheduler, packetEvents, propertyRegistry, textSerializer)));
|
||||
versions.put(ServerVersion.V_1_19, LazyLoader.of(() -> new V1_19PacketFactory(scheduler, packetEvents, propertyRegistry, textSerializer)));
|
||||
versions.put(ServerVersion.V_1_19_2, LazyLoader.of(() -> new V1_19_2PacketFactory(scheduler, packetEvents, propertyRegistry, textSerializer)));
|
||||
versions.put(ServerVersion.V_1_20_2, LazyLoader.of(() -> new V1_20_2PacketFactory(scheduler, packetEvents, propertyRegistry, textSerializer)));
|
||||
|
||||
ServerVersion version = packetEvents.getServerManager().getVersion();
|
||||
if (versions.containsKey(version)) return versions.get(version).get();
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package lol.pyr.znpcsplus.packets;
|
||||
|
||||
import com.github.retrooper.packetevents.PacketEventsAPI;
|
||||
import com.github.retrooper.packetevents.manager.server.ServerVersion;
|
||||
import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes;
|
||||
import com.github.retrooper.packetevents.protocol.player.GameMode;
|
||||
import com.github.retrooper.packetevents.protocol.player.UserProfile;
|
||||
|
@ -19,16 +18,13 @@ import org.bukkit.plugin.Plugin;
|
|||
import java.util.EnumSet;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class V1_19PacketFactory extends V1_17PacketFactory {
|
||||
private final boolean oldTabPackets;
|
||||
public V1_19PacketFactory(TaskScheduler scheduler, PacketEventsAPI<Plugin> packetEvents, EntityPropertyRegistryImpl propertyRegistry, LegacyComponentSerializer textSerializer) {
|
||||
public class V1_19_2PacketFactory extends V1_17PacketFactory {
|
||||
public V1_19_2PacketFactory(TaskScheduler scheduler, PacketEventsAPI<Plugin> packetEvents, EntityPropertyRegistryImpl propertyRegistry, LegacyComponentSerializer textSerializer) {
|
||||
super(scheduler, packetEvents, propertyRegistry, textSerializer);
|
||||
oldTabPackets = packetEvents.getServerManager().getVersion().isOlderThanOrEquals(ServerVersion.V_1_19_2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> addTabPlayer(Player player, PacketEntity entity, PropertyHolder properties) {
|
||||
if (oldTabPackets) return super.addTabPlayer(player, entity, properties);
|
||||
if (entity.getType() != EntityTypes.PLAYER) return CompletableFuture.completedFuture(null);
|
||||
CompletableFuture<Void> future = new CompletableFuture<>();
|
||||
skinned(player, properties, new UserProfile(entity.getUuid(), Integer.toString(entity.getEntityId()))).thenAccept(profile -> {
|
||||
|
@ -43,10 +39,6 @@ public class V1_19PacketFactory extends V1_17PacketFactory {
|
|||
|
||||
@Override
|
||||
public void removeTabPlayer(Player player, PacketEntity entity) {
|
||||
if (oldTabPackets) {
|
||||
super.removeTabPlayer(player, entity);
|
||||
return;
|
||||
}
|
||||
if (entity.getType() != EntityTypes.PLAYER) return;
|
||||
sendPacket(player, new WrapperPlayServerPlayerInfoRemove(entity.getUuid()));
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package lol.pyr.znpcsplus.packets;
|
||||
|
||||
import com.github.retrooper.packetevents.PacketEventsAPI;
|
||||
import com.github.retrooper.packetevents.util.Vector3d;
|
||||
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerEntityHeadLook;
|
||||
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerSpawnEntity;
|
||||
import lol.pyr.znpcsplus.api.entity.PropertyHolder;
|
||||
import lol.pyr.znpcsplus.entity.EntityPropertyRegistryImpl;
|
||||
import lol.pyr.znpcsplus.entity.PacketEntity;
|
||||
import lol.pyr.znpcsplus.scheduling.TaskScheduler;
|
||||
import lol.pyr.znpcsplus.util.NpcLocation;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class V1_20_2PacketFactory extends V1_19_2PacketFactory {
|
||||
public V1_20_2PacketFactory(TaskScheduler scheduler, PacketEventsAPI<Plugin> packetEvents, EntityPropertyRegistryImpl propertyRegistry, LegacyComponentSerializer textSerializer) {
|
||||
super(scheduler, packetEvents, propertyRegistry, textSerializer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void spawnPlayer(Player player, PacketEntity entity, PropertyHolder properties) {
|
||||
addTabPlayer(player, entity, properties).thenAccept(ignored -> {
|
||||
createTeam(player, entity, properties.getProperty(propertyRegistry.getByName("glow", NamedTextColor.class)));
|
||||
NpcLocation location = entity.getLocation();
|
||||
sendPacket(player, new WrapperPlayServerSpawnEntity(entity.getEntityId(), Optional.of(entity.getUuid()), entity.getType(),
|
||||
npcLocationToVector(location), location.getPitch(), location.getYaw(), location.getYaw(), 0, Optional.of(new Vector3d())));
|
||||
sendPacket(player, new WrapperPlayServerEntityHeadLook(entity.getEntityId(), location.getYaw()));
|
||||
sendAllMetadata(player, entity, properties);
|
||||
scheduler.runLaterAsync(() -> removeTabPlayer(player, entity), 60);
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue