Code Patterns

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

← Back to Patterns
ecs

Break 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.BreakBlockEvent;
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, BreakBlockEvent> {

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

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

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

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