-
Notifications
You must be signed in to change notification settings - Fork 22
Dynamic Title Update
Natan Vieira edited this page Apr 3, 2024
·
21 revisions
The Dynamic Title Update feature allows the developer to change the title of a view that's open, being displayed to the player, to be changed without requiring closing it, changing the title and opening it again.
Server version | Minimum IF version | Status |
---|---|---|
v1.8 | v1.0 | ✅ Supported |
v1.9-1.16 | v2.4.0 | ✅ Supported |
v1.17–1.18 | v3.0.0 | ✅ Supported |
v1.19 | v3.0.0-rc.2 | ✅ Supported |
v1.20 | v3.0.2 | ✅ Supported |
v1.20.4 | v3.1.0 | ✅ Supported |
Dynamic Title Update is a Protocol-Level Integration so its behavior is based on the current version and software of the server it is running on and may be inconsistent. See the Versions Compatibility table to know if it will work on your server.
// Updates the title for all players in the context
public void updateTitleForEveryone(String title);
// Updates the title for the subject player of the context
public void updateTitleForPlayer(String title);
// Updates the title for a specific player in the context
public void updateTitleForPlayer(String title, T player);
// Resets the title to the initial title of the context for all players in the context
public void resetTitleForEveryone();
// Resets the title to the initial title for the subject player of the context
public void resetTitleForPlayer();
// Resets the title to the initial title of the context for a specific player
public void resetTitleForPlayer(T player);
updateTitleForPlayer
and resetTitleForPlayer
the "player" is the subject of the context, if it's used in a click context the title will be updated only to the player that clicked on something.
In the example below, we will create a counter with initial value of zero and schedules the view to update every 1 second and on each update the counter will be incremented by one.
private final MutableIntState counterState = mutableIntState(0);
@Override
public void onInit(ViewConfigBuilder config) {
config.title("Initial title").scheduleUpdate(20L);
}
@Override
public void onUpdate(Context update) {
final int count = counterState.increment(update);
update.updateTitleForEveryone(String.format("Updated title: %d", count));
}
Using resetTitle*
after updateTitle*
resets the title to "Initial title".
This example uses State Management and Scheduled Updates features.