Code Patterns
Copy-paste examples for common plugin tasks. Commands, events, ECS, GUI, and more.
All
225
Command
60
Damage
2
Ecs
27
Entity
5
Gui
75
Interaction
2
Inventory
4
Moderation
3
Permission
2
Player
9
Plugin
4
Storage
2
Teleport
3
Ui
22
Util
5
← Back to Patterns
java
entity
Heal Player
Heal a player to full health and stamina using EntityStatsModule. Based on working AdminUI code.
Example Code
// Heal player to full health and stamina (from AdminUI PlayerGui)
import com.hypixel.hytale.server.core.modules.entitystats.EntityStatsModule;
import com.hypixel.hytale.server.core.modules.entitystats.EntityStatValue;
import com.hypixel.hytale.server.core.modules.entitystats.asset.EntityStatType;
public void heal(Store<EntityStore> store, Ref<EntityStore> ref) {
// Get the entity stat map component
var entityStatMap = store.getComponent(ref,
EntityStatsModule.get().getEntityStatMapComponentType());
if (entityStatMap == null) return;
// Get stat indices
int healthIndex = EntityStatType.getAssetMap().getIndex("Health");
int staminaIndex = EntityStatType.getAssetMap().getIndex("Stamina");
// Heal to max
EntityStatValue health = entityStatMap.get(healthIndex);
if (health != null) {
entityStatMap.setStatValue(healthIndex, health.getMax());
}
// Restore stamina
EntityStatValue stamina = entityStatMap.get(staminaIndex);
if (stamina != null) {
entityStatMap.setStatValue(staminaIndex, stamina.getMax());
}
}
Thread Safety
Run on world thread.
Common Mistakes
Forgetting to get the stat map component type from EntityStatsModule.