package com.example.mymod;
import com.frotty27.nameplatebuilder.api.NameplateAPI;
import com.frotty27.nameplatebuilder.api.SegmentTarget;
import com.hypixel.hytale.component.ComponentType;
import com.hypixel.hytale.server.core.plugin.JavaPlugin;
import com.hypixel.hytale.server.core.plugin.JavaPluginInit;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
import java.util.List;
public final class MyModPlugin extends JavaPlugin {
public MyModPlugin(JavaPluginInit init) {
super(init);
}
@Override
protected void setup() {
ComponentType<EntityStore, EntityStatMap> statMapType =
EntityStatMap.getComponentType();
ComponentType<EntityStore, FactionComponent> factionType =
FactionComponent.getComponentType();
// Health - resolver with format variants, recomputed every tick
NameplateAPI.define(this, "health", "Health",
SegmentTarget.ALL, "100/100")
.requires(statMapType)
.resolver((store, entityRef, variantIndex) -> {
EntityStatMap stats = store.getComponent(entityRef, statMapType);
if (stats == null) return null;
int current = Math.round(stats.get(health).get());
int max = Math.round(stats.get(health).getMax());
return switch (variantIndex) {
case 1 -> Math.round(100f * current / max) + "%";
default -> current + "/" + max;
};
});
NameplateAPI.defineVariants(this, "health", List.of(
"Current/Max", "Percentage"
));
// Faction - resolver with caching, rarely changes
NameplateAPI.define(this, "faction", "Faction",
SegmentTarget.NPCS, "<Undead>")
.requires(factionType)
.cacheTicks(100)
.resolver((store, entityRef, variantIndex) -> {
FactionComponent faction = store.getComponent(entityRef, factionType);
return faction != null ? "<" + faction.getName() + ">" : null;
});
// Guild - manual text, set from event handlers or commands
// No resolver needed - text is pushed via setText() at runtime
NameplateAPI.define(this, "guild", "Guild Tag",
SegmentTarget.PLAYERS, "[Warriors]");
}
}