Моддинг Hytale
Server Plugins

Creating Events

Learn how to create custom events for your Hytale mod.

Event Class

You can import a Event class and create a function with the Event as a argument. Click here to look at all available events.

Example plugin when a player is ready (joins a server):


public class ExampleEvent {

    public static void onPlayerReady(PlayerReadyEvent event) {
        Player player = event.getPlayer();
        player.sendMessage(Message.raw("Welcome " + player.getDisplayName()));
    }

}

Registering the Event

You need to register all events you make in the Main plugin class, usually in the setup function.

public class MyPlugin extends JavaPlugin {

    @Override
    public void setup() {
        this.getEventRegistry().registerGlobal(PlayerReadyEvent.class, ExampleEvent::onPlayerReady);
    }
}

ESC Event Classes

For events that fall under the ESC Events list you will need to instead create and register an entity event system. An example is included below that will cancel the crafting of a recipe if it uses fibre as an input.

class ExampleCancelCraft extends EntityEventSystem<EntityStore, CraftRecipeEvent.Pre> {
    public ExampleCancelCraft() {
        super(CraftRecipeEvent.Pre.class);
    }

    @Override
    public void handle(int index,
                       @NonNullDecl ArchetypeChunk<EntityStore> archetypeChunk,
                       @NonNullDecl Store<EntityStore> store,
                       @NonNullDecl CommandBuffer<EntityStore> commandBuffer,
                       @NonNullDecl CraftRecipeEvent.Pre craftRecipeEvent) {
        CraftingRecipe recipe = craftRecipeEvent.getCraftedRecipe();
        if (recipe.getInput() != null) {
            for (MaterialQuantity mq : recipe.getInput()) {
                if (Objects.equals(mq.getItemId(), "Ingredient_Fibre")) {
                    craftRecipeEvent.setCancelled(true);
                    break;
                }
            }
        }
    }

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

Registering ESC Events

You will need to register the system in your plugin:

public class MyPlugin extends JavaPlugin {

    @Override
    public void setup() {
        this.getEntityStoreRegistry().registerSystem(new ExampleCancelCraft());
    }
}
Автор Neil Revin, EllieAU