Skip to content

Commit

Permalink
Add lookup method using named entity metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexProgrammerDE committed Nov 19, 2024
1 parent 5591cdc commit 484a5ec
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -29,4 +33,14 @@ public class EntityMetadataState {
public void setMetadata(EntityMetadata<?, ?> metadata) {
this.metadataStore.put(metadata.getId(), metadata);
}

public <T> Optional<T> getMetadata(NamedEntityData namedEntityData, MetadataType<T> ignored) {
return getMetadata(namedEntityData.networkId(), ignored);
}

@SuppressWarnings("unchecked")
public <T> Optional<T> getMetadata(int id, MetadataType<T> ignored) {
return (Optional<T>) Optional.ofNullable(this.metadataStore.get(id))
.map(EntityMetadata::getValue);
}
}

0 comments on commit 484a5ec

Please sign in to comment.