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

55 lines
1.4 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;
2023-04-24 18:10:55 +00:00
import java.util.UUID;
2023-04-24 16:12:50 +00:00
public class PacketEntity {
private final int entityId;
2023-04-24 18:10:55 +00:00
private final UUID uuid;
2023-04-24 16:12:50 +00:00
private final EntityType type;
private PacketLocation location;
public PacketEntity(EntityType type, PacketLocation location) {
this.entityId = EntityIDProvider.reserve();
2023-04-24 18:10:55 +00:00
this.uuid = UUID.randomUUID();
2023-04-24 16:12:50 +00:00
this.type = type;
this.location = location;
}
public int getEntityId() {
return entityId;
}
public PacketLocation getLocation() {
return location;
}
2023-04-24 18:10:55 +00:00
public UUID getUuid() {
return uuid;
}
2023-04-24 16:12:50 +00:00
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);
}
}