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
ecs
Exploration Player Setup System
RefSystem implementation
Example Code
package dev.myplugin.example;
import com.hypixel.hytale.component.*;
import com.hypixel.hytale.component.query.Query;
import com.hypixel.hytale.component.system.RefSystem;
import com.hypixel.hytale.server.core.entity.entities.Player;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
// import dev.myplugin.example.BetterMap; // Anonymized
// import dev.myplugin.example.ExplorationComponent; // Anonymized
import javax.annotation.Nonnull;
/**
* specific System that attaches the ExplorationComponent to players.
*/
public class ExampleSystem extends RefSystem<EntityStore> {
@Nonnull
private final ComponentType<EntityStore, ExplorationComponent> explorationComponentType;
@Nonnull
private final Query<EntityStore> query;
/**
* Constructs the setup system.
*/
public ExampleSystem() {
this.explorationComponentType = BetterMap.get().getExplorationComponentType();
ComponentType<EntityStore, Player> playerComponentType = Player.getComponentType();
this.query = Query.and(playerComponentType);
}
@Nonnull
@Override
public Query<EntityStore> getQuery() {
return this.query;
}
/**
* Called when a player entity is added. Ensures they have the ExplorationComponent.
*
* @param ref The entity reference.
* @param reason Reason for addition.
* @param store The entity store.
* @param commandBuffer The command buffer.
*/
@Override
public void onEntityAdded(
@Nonnull Ref<EntityStore> ref,
@Nonnull AddReason reason,
@Nonnull Store<EntityStore> store,
@Nonnull CommandBuffer<EntityStore> commandBuffer
) {
commandBuffer.ensureComponent(ref, this.explorationComponentType);
}
@Override
public void onEntityRemove(
@Nonnull Ref<EntityStore> ref,
@Nonnull RemoveReason reason,
@Nonnull Store<EntityStore> store,
@Nonnull CommandBuffer<EntityStore> commandBuffer
) {
}
}