ZNPCsPlus/src/main/java/lol/pyr/znpcsplus/entity/PacketEntity.java

47 lines
1.3 KiB
Java
Raw Normal View History

2023-04-24 16:12:50 +00:00
package lol.pyr.znpcsplus.entity;
import com.github.retrooper.packetevents.protocol.entity.type.EntityType;
import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes;
import lol.pyr.znpcsplus.packets.PacketFactory;
import org.bukkit.entity.Player;
import java.util.Set;
public class PacketEntity {
private final int entityId;
private final EntityType type;
private PacketLocation location;
public PacketEntity(EntityType type, PacketLocation location) {
this.entityId = EntityIDProvider.reserve();
this.type = type;
this.location = location;
}
public int getEntityId() {
return entityId;
}
public PacketLocation getLocation() {
return location;
}
public EntityType getType() {
return type;
}
public void setLocation(PacketLocation location, Set<Player> viewers) {
this.location = location;
for (Player viewer : viewers) PacketFactory.get().teleportEntity(viewer, this);
}
public void spawn(Player player) {
if (type == EntityTypes.PLAYER) PacketFactory.get().spawnPlayer(player, this);
else PacketFactory.get().spawnEntity(player, this);
}
public void despawn(Player player) {
PacketFactory.get().destroyEntity(player, this);
}
}