Scheduled Updates - DevNatan/inventory-framework GitHub Wiki
Scheduled Updates is a built-in feature of the Inventory Framework that allows developers to automatically refresh any view at fixed intervals — essentially, it “calls update() every X ticks.”
Configuration
Scheduled updates are defined in the view configuration using the onInit method.
Use the scheduleUpdate setting to specify the update interval in ticks or Duration.
@Override
public void onInit(ViewConfigBuilder config) {
config.scheduleUpdate(intervalInTicks);
}
Code Examples
Example: Automatically update the view every 1 second (20 ticks):
@Override
public void onInit(ViewConfigBuilder config) {
config.scheduleUpdate(20L /* ticks */);
config.scheduleUpdate(Duration.ofSeconds(1));
}
Since scheduled updates only trigger a view refresh, dynamically rendered items will automatically react to these updates.
The example below demonstrates Dynamic Item Rendering and State Management.
private final MutableIntState counterState = mutableState(0);
@Override
public void onInit(ViewConfigBuilder config) {
config.scheduleUpdate(20L /* ticks */);
}
@Override
public void onFirstRender(RenderContext render) {
render.firstSlot().renderWith(() -> new ItemStack(
/* type = */ Material.DIAMOND,
/* amount = */ counterState.increment(render)
));
}
Internal Mechanics
A global scheduler manages all scheduled updates across views.
When a player opens a view, it is added to the scheduler’s task list.
At each interval, the scheduler executes the update() method for all active view contexts.
- The scheduler is initialized when a new player's view triggers
onOpen. - When a player closes a view, if its context becomes invalid (i.e., no other viewers share it), the scheduler stops executing updates for that context.