Skip to content
  • Our Product
    • Namazu Elements
      • What is Elements?
      • Why open source?
      • Docs
        • Namazu Elements in Five Minutes or Less
        • RESTful APIs Library
        • Security Model
        • Accessing the Web UI (CMS)

    Our Product

    A logomark with three layered rhombuses adorning the lettermark that says Elements in bold all-caps sans-serif letters.
    • What is Namazu Elements? Discover our easy-to-use backend network solution built for online games. Rapidly enables full-scale multiplayer games or online solo adventures.
    • Why open source? Is there a truly open source server backend for connected games? There is now. Download and run a local copy of Namazu Elements and try it for yourself.
    Download Namazu Elements

    Get started

    • Quick start Read our Elements 5-minute quick start guide
    • Documentation Read our developer docs for learning more about Elements
    • RESTful APIs A full list of core API specs for working with the Elements framework
    • Security An overview of the server-authoritative security model of Elements
    • Accessing the CMS Manage your game with ease via the Namazu Elements CMS.

    Co-development Reimagined

    • Reduce your costs Would you rather outsource your backend development? Hire Namazu Studios to build your server backend with the power of Namazu Elements.
      Co-dev

    Recent Posts

    • The watercolor-styled Namazu Studios logo over a giant namazu lurking in the depth
      Namazu Studios Featured in San Diego Business Journal
      22 Sep 2025 Press
    • Namazu Elements 3.1 Released – Service Layer Fixes, Secure APIs, and Steam Bug Fix
      22 Apr 2025 Release Notes
  • Case Studies
  • About Us
  • News
  • Services
  • Book a call
namazu-studios-logo
Book a call

Getting Started

  • Namazu Elements in Five Minutes or Less
  • Accessing the Web UI (CMS)
  • CMS Feature Overview

Fundamentals

  • Why You Need a Server (and What “Authoritative” Means)
  • Elements as a Game Runtime
  • Where Your Authoritative Code Runs
  • Lifecycles and Flows

General Concepts

  • Overview
  • Custom Elements
  • Data Models
  • Security Model
  • N-Tier Architecture

Namazu Elements Core Features

  • User Authentication / Sign In
    • What is a User?
    • User Authentication in Elements
    • Auth Schemes
      • Auth Schemes
      • OAuth2
      • OIDC
  • Features
    • Applications
    • Sessions
    • Users and Profiles
    • Digital Goods
    • Progress and Missions
    • Progress and Missions (3.4+)
    • Leaderboards
    • Matchmaking – Comprehensive Guide
    • Followers
    • Friends
    • Receipts
    • Reward Issuances
    • Save Data
    • Metadata
    • Metadata (3.4+)
    • Queries
    • Web3
      • Wallets
      • Vaults
      • Omni Chain Support
      • Smart Contracts
        • Smart Contracts
  • Queries
    • Advanced Operators
    • Object Graph Navigation
    • Boolean Queries
    • Base Query Syntax
  • Advanced Operators
    • .name
    • .ref

Your Game Code - Adding Custom Elements

  • Custom Code Overview
  • Windows Setup
  • Mac OS Setup
  • Ubuntu Linux Setup
  • Element Anatomy: A Technical Deep Dive
  • Introduction to Guice and Jakarta in Elements
  • Structuring your Element
  • Events
  • Packaging an Element with Maven
  • Deploying an Element
  • Preparing for code generation
  • Properties
  • Websockets
  • RESTful APIs
  • Direct MongoDB Access (3.5+)

Configuration

  • Matchmaking – Comprehensive Guide
  • Direct Database Access and Batch Configuration
  • Batch Samples
    • Mission Upload Bash Script Sample
    • Item Upload Bash Script Sample

RESTful APIs

  • Importing into Postman
  • RESTful APIs Library
  • Swagger and Swagger UI

Add-Ons

  • Custom Elements
    • Crossplay
      • Namazu Crossfire (Multiplayer)
      • Deploying Namazu Crossfire in your game
  • Game Engines
    • Unity
      • Elements Codegen
      • Crossfire
    • Roblox
      • Roblox Overview
      • Secure Player Authentication & Registration
      • Global Matchmaking
      • Roblox Security Best Practices

Troubleshooting

  • Common Issues with Docker
  • Local SDK
    • Unable to deploy application : dev.getelements.elements.sdk.exception.SdkElementNotFoundException
    • Could not load class : java.lang.NoClassDefFoundError
  • Namazu Elements Community Edition
    • Common Issues with Docker
    • Unable to deploy application : dev.getelements.elements.sdk.exception.SdkElementNotFoundException
    • Running in the IDE
      • Exception in monitor thread while connecting to server localhost:27017
      • Could not deployAvailableApplications Jetty server Failed to bind to /0.0.0.0:8080 Address already in use

Releases

  • 3.6 Release Notes
  • 3.5 Release Notes
  • 3.4 Release Notes
  • 3.3 Release Notes
  • 3.2 Release Notes
  • 3.1 Release Notes
View Categories
  • Home
  • Docs
  • Your Game Code - Adding Custom Elements
  • Events

Events

Est. read time: 2 min read

Namazu Elements provides the ability to react to various events that are produced by either the core system, or other custom Elements. This allows for your code to react to things as they happen, such as setting startup code when an Element is loader, or configuring a Profile with default properties when a new Profile is created. Functions that receive the event are called Event Consumers, and functions that send the event are called Event Producers.


Determining Available Events #

You can see which events are available to consume by looking under Produced Events in the Core Elements section of the CMS.

DAO level events will always have two versions – one that occurs during the transaction, with a reference to the transaction itself, and one that occurs after the transaction. This is important, as sometimes you might want to communicate with the database and ensure that your event consumer has the same protections and retries that a transaction provides. In these cases, it’s important to ensure that your code is idempotent, and that you use the transaction itself to get any DAO classes. For example:

@ElementEventConsumer(ReceiptDao.RECEIPT_CREATED)
public void onReceiptCreated(Receipt receipt, Transaction transaction) {
final User user = transaction.performAndCloseV(txn -> {
final var dao = txn.getDao(UserDao.class);
final var txUser = dao.getUser(receipt.getUser.getId());
//Do something with the User here
return txUser;
});

//The transaction has completed at this point
}

You can also view the Produced Events for an individual Element by navigating to the Element Info screen for that Element.

This information comes from the SystemElementsResource (GET /elements/system) and the ApplicationElementResource (GET /elements/application) respectively.

Code Samples #

To consume an event, be sure to place it in a service that has been registered in package-info.java like so:

// Makes this discoverable by the event system
@ElementService(
        value = EventHandler.class,
        implementation = @ElementServiceImplementation(EventHandlerImpl.class)
)

where in this case, EventHandler is an interface that has been made public:

@ElementPublic
public interface EventHandler {}

and EventHandlerImpl is the implementation class that looks like so:

package com.namazustudios.events;

import dev.getelements.elements.sdk.ElementLoader;
import dev.getelements.elements.sdk.Event;
import dev.getelements.elements.sdk.annotation.ElementEventConsumer;
import dev.getelements.elements.sdk.dao.DistinctInventoryItemDao;
import dev.getelements.elements.sdk.dao.InventoryItemDao;
import dev.getelements.elements.sdk.dao.ItemDao;
import dev.getelements.elements.sdk.model.goods.Item;
import dev.getelements.elements.sdk.model.inventory.DistinctInventoryItem;
import dev.getelements.elements.sdk.model.inventory.InventoryItem;
import dev.getelements.elements.sdk.model.profile.Profile;
import dev.getelements.elements.sdk.service.profile.ProfileService;
import io.swagger.v3.oas.annotations.Hidden;
import jakarta.inject.Inject;

import static com.namazustudios.util.Constants.STARTING_AVATAR_ITEM_NAME;
import static com.namazustudios.util.Constants.EXP_ITEM_NAME;

@Hidden
public class EventHandlerImpl implements EventHandler {

    @Inject
    private InventoryItemDao inventoryItemDao;

    @Inject
    private DistinctInventoryItemDao distinctInventoryItemDao;

    private Item startingAvatarItem;

    private Item expItem;

    @Inject
    private void init(ItemDao itemDao) {
        startingAvatarItem = itemDao.getItemByIdOrName(STARTING_AVATAR_ITEM_NAME);
        expItem = itemDao.getItemByIdOrName(EXP_ITEM_NAME);
    }

    @ElementEventConsumer(ProfileService.PROFILE_CREATED_EVENT)
    public void onNewProfileCreatedEvent(final Profile profile) {
        assignStartingAvatarItem(profile);
        assignStartingExp(profile);
    }

    @ElementEventConsumer(ElementLoader.SYSTEM_EVENT_ELEMENT_LOADED)
    public void onElementLoadedEvent(Event event) {
        System.out.println("System event loaded");
    }

    private void assignStartingAvatarItem(final Profile profile) {


        final var distinctInventoryItem = new DistinctInventoryItem();
        distinctInventoryItem.setItem(startingAvatarItem);
        distinctInventoryItem.setProfile(profile);
        distinctInventoryItem.setUser(profile.getUser());


        distinctInventoryItemDao.createDistinctInventoryItem(distinctInventoryItem);
    }

    private void assignStartingExp(final Profile profile) {

        final var inventoryItem = new InventoryItem();
        inventoryItem.setItem(expItem);
        inventoryItem.setUser(profile.getUser());
        inventoryItem.setPriority(0);
        inventoryItem.setQuantity(0);

        inventoryItemDao.createInventoryItem(inventoryItem);
    }
}

In this example, we have Event Consumers for when the Element is first loaded (only produced once), and when a new Profile is created (produced every time).

Warning

If you use this event: @ElementEventConsumer(ElementLoader.SYSTEM_EVENT_ELEMENT_LOADED) in conjunction with Elements Core services, then you must lazily load the services instead of injecting them, as they are not made available yet when this event fires. Injecting DAO level classes is perfectly fine though. For example:

Element element = ElementSupplier
        .getElementLocal(ThisClass.class)
        .get();
SomeService someService = element        .getServiceLocator()
        .getInstance(SomeService.class);

What are your Feelings
Still stuck? How can we help?

How can we help?

Updated on February 4, 2026
Direct MongoDB Access (3.5+)Element Anatomy: A Technical Deep Dive
Table of Contents
  • Determining Available Events
  • Code Samples
  • Documentation
  • Terms of Service
  • Privacy Policy
  • Contact us
  • Linkedin
  • Join our Discord

Namazu Studios LLC is powered by Namazu Elements, an Elemental Computing Inc. product.

Elements
  • Download
  • About Elements
  • Open source
  • Documentation
  • Support
About Namazu
  • Case Studies
  • About Us
  • News
Get in Touch
  • info@namazustudios.com
  • Book a call
  • (619) 862-2890
  • Linkedin
  • Discord

©2008-2025 Namazu Studios. All Rights Reserved.