state_and_updates - Hazebyte/base GitHub Wiki

State

Every component holds its own state and properties. States trigger changes. Properties holds values.

For example, we use this internally in each menu to determine a few things

  • (Property) Entity's UUID - Refers to the page that the entity is viewing
  • (Property) menu - refers to the menu for finding the parent

To perform state or property changes

public class StateChangePage extends Base implements Listener {

    /**
     * Creates a inventory that lists players
     */
    public StateChangePage(JavaPlugin plugin, String title, Size size) {
        super(plugin, title, size);

        Button xpButton = new Button(new ItemBuilder(Material.DIAMOND)
                .displayName("%player")
                .lore("XP: %xp", "Health: %health", "Msg: %msg")
                .asItemStack());
        this.attach(xpButton);
        this.addIcon(xpButton);
    }

    @Override
    public void update(HumanEntity entity) {
        if (!(entity instanceof Player)) return;

        Player player = (Player) entity;
        this.setState(entity, "player", player.getDisplayName());
        this.setState(entity, "xp", player.getExp());
        this.setState(entity, "health", player.getHealth());
        this.setState(entity, "msg", "random msg test");
    }
}