Code Patterns

Copy-paste examples for common plugin tasks. Commands, events, ECS, GUI, and more.

← Back to Patterns
ecs

Place Block Listener

EntityEventSystem implementation

Example Code

java
package dev.myplugin.example;

import com.hypixel.hytale.component.Archetype;
import com.hypixel.hytale.component.ArchetypeChunk;
import com.hypixel.hytale.component.CommandBuffer;
import com.hypixel.hytale.component.Store;
import com.hypixel.hytale.component.query.Query;
import com.hypixel.hytale.component.system.EntityEventSystem;
import com.hypixel.hytale.server.core.event.events.ecs.PlaceBlockEvent;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
import org.checkerframework.checker.nullness.compatqual.NonNullDecl;
import org.checkerframework.checker.nullness.compatqual.NullableDecl;

import static ar.ncode.plugin.TroubleInTrorkTownPlugin.config;

public class ExampleClass extends EntityEventSystem<EntityStore, PlaceBlockEvent> {

	public ExampleClass() {
		super(PlaceBlockEvent.class);
	}

	@Override
	public void handle(
			int i, @NonNullDecl ArchetypeChunk<EntityStore> archetypeChunk,
			@NonNullDecl Store<EntityStore> store, @NonNullDecl CommandBuffer<EntityStore> commandBuffer,
			@NonNullDecl PlaceBlockEvent event
	) {
		if (config.get().isDebugMode()) {
			return;
		}

		// By default, block players from breaking blocks
		event.setCancelled(true);
	}

	@NullableDecl
	@Override
	public Query<EntityStore> getQuery() {
		return Archetype.empty();
	}
}