use of org.spongepowered.api.text.format.TextColor in project Skree by Skelril.
the class WildernessWorldWrapper method run.
@Override
public void run() {
for (Player player : Sponge.getServer().getOnlinePlayers()) {
int currentLevel = getLevel(player.getLocation()).orElse(-1);
WildernessPlayerMeta meta = playerMetaMap.getOrDefault(player.getUniqueId(), new WildernessPlayerMeta());
int lastLevel = meta.getLevel();
// Always set the level so as to mark the player meta as relevant
// if it is -1 no time stamp update shall be performed
meta.setLevel(currentLevel);
// Display a title change, unless the current level is -1 (outside of the Wilderness)
if (currentLevel != -1 && currentLevel != lastLevel) {
TextColor color = (allowsPvP(currentLevel) ? TextColors.RED : TextColors.WHITE);
player.sendTitle(Title.builder().title(Text.of(color, "Wilderness Level")).subtitle(Text.of(color, currentLevel)).fadeIn(20).fadeOut(20).build());
playerMetaMap.putIfAbsent(player.getUniqueId(), meta);
}
}
playerMetaMap.entrySet().removeIf(entry -> System.currentTimeMillis() - entry.getValue().getLastChange() >= TimeUnit.MINUTES.toMillis(5));
}
Aggregations