From 484a5ec0a08da1729f0abc47560b9874689cc55a Mon Sep 17 00:00:00 2001 From: AlexProgrammerDE <40795980+AlexProgrammerDE@users.noreply.github.com> Date: Tue, 19 Nov 2024 20:19:22 +0100 Subject: [PATCH] Add lookup method using named entity metadata --- .../protocol/bot/state/EntityMetadataState.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/server/src/main/java/com/soulfiremc/server/protocol/bot/state/EntityMetadataState.java b/server/src/main/java/com/soulfiremc/server/protocol/bot/state/EntityMetadataState.java index 20afc8a09..695c45d5e 100644 --- a/server/src/main/java/com/soulfiremc/server/protocol/bot/state/EntityMetadataState.java +++ b/server/src/main/java/com/soulfiremc/server/protocol/bot/state/EntityMetadataState.java @@ -17,10 +17,14 @@ */ package com.soulfiremc.server.protocol.bot.state; +import com.soulfiremc.server.data.NamedEntityData; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import lombok.Data; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata; +import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.MetadataType; + +import java.util.Optional; @Data public class EntityMetadataState { @@ -29,4 +33,14 @@ public class EntityMetadataState { public void setMetadata(EntityMetadata metadata) { this.metadataStore.put(metadata.getId(), metadata); } + + public Optional getMetadata(NamedEntityData namedEntityData, MetadataType ignored) { + return getMetadata(namedEntityData.networkId(), ignored); + } + + @SuppressWarnings("unchecked") + public Optional getMetadata(int id, MetadataType ignored) { + return (Optional) Optional.ofNullable(this.metadataStore.get(id)) + .map(EntityMetadata::getValue); + } }