Search in sources :

Example 21 with TextColor

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));
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) TextColor(org.spongepowered.api.text.format.TextColor)

Aggregations

TextColor (org.spongepowered.api.text.format.TextColor)21 Text (org.spongepowered.api.text.Text)9 TextStyle (org.spongepowered.api.text.format.TextStyle)6 TextColors (org.spongepowered.api.text.format.TextColors)4 List (java.util.List)3 Map (java.util.Map)3 Optional (java.util.Optional)3 Collectors (java.util.stream.Collectors)3 LanternDisplaySlot (org.lanternpowered.server.scoreboard.LanternDisplaySlot)3 Sponge (org.spongepowered.api.Sponge)3 Player (org.spongepowered.api.entity.living.player.Player)3 ItemStack (org.spongepowered.api.item.inventory.ItemStack)3 Score (org.spongepowered.api.scoreboard.Score)3 IOException (java.io.IOException)2 Files (java.nio.file.Files)2 Path (java.nio.file.Path)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2 Set (java.util.Set)2