feat: implemented KeyedBossBars
This commit is contained in:
parent
899e7ac4ca
commit
5253b89779
@ -5,11 +5,13 @@ import lombok.experimental.UtilityClass;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.event.player.PlayerDisconnectEvent;
|
||||
import ru.dragonestia.msb3.api.entity.PickableItem;
|
||||
import ru.dragonestia.msb3.api.item.ItemUtil;
|
||||
import ru.dragonestia.msb3.api.resource.DialogueResources;
|
||||
import ru.dragonestia.msb3.api.resource.MonologueResources;
|
||||
import ru.dragonestia.msb3.api.ui.BlackScreen;
|
||||
import ru.dragonestia.msb3.api.ui.bossbar.KeyedBossBars;
|
||||
import ru.dragonestia.msb3.api.ui.navigator.Navigator;
|
||||
import ru.dragonestia.msb3.api.util.ResourceFromJar;
|
||||
import ru.dragonestia.msb3.resource.Resources;
|
||||
@ -75,6 +77,12 @@ public final class ServerBootstrap {
|
||||
|
||||
compileResourcePack();
|
||||
initializer.onResourcePackCompiled(Resources.getResourcePack());
|
||||
|
||||
MinecraftServer.getGlobalEventHandler().addListener(PlayerDisconnectEvent.class, event -> {
|
||||
var player = event.getPlayer();
|
||||
|
||||
KeyedBossBars.hideAll(player);
|
||||
});
|
||||
}
|
||||
|
||||
private void initDefaultModules() {
|
||||
@ -96,6 +104,7 @@ public final class ServerBootstrap {
|
||||
private void initDefaultGlyphs() {
|
||||
ClassPreLoader.preload(BlackScreen.class);
|
||||
ClassPreLoader.preload(Navigator.class);
|
||||
ClassPreLoader.preload(KeyedBossBars.class);
|
||||
|
||||
MonologueResources.registerAvatar(MonologueResources.DEFAULT, ResourceFromJar.of(ServerBootstrap.CLASS_LOADER, "glyphs/monologue/default_avatar.png"));
|
||||
MonologueResources.registerFrame(MonologueResources.DEFAULT, ResourceFromJar.of(ServerBootstrap.CLASS_LOADER, "glyphs/monologue/avatar_frame.png"));
|
||||
|
||||
@ -0,0 +1,57 @@
|
||||
package ru.dragonestia.msb3.api.ui.bossbar;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
import net.kyori.adventure.bossbar.BossBar;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.entity.Player;
|
||||
import ru.dragonestia.msb3.api.util.ResourceFromJar;
|
||||
import ru.dragonestia.msb3.resource.Resources;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@UtilityClass
|
||||
public class KeyedBossBars {
|
||||
|
||||
static {
|
||||
var rp = Resources.getResourcePack();
|
||||
rp.texture(Key.key("minecraft", "gui/sprites/boss_bar/white_background.png"),
|
||||
ResourceFromJar.of("glyphs/navigator/notched_20_background.png"));
|
||||
|
||||
rp.texture(Key.key("minecraft", "gui/sprites/boss_bar/white_progress.png"),
|
||||
ResourceFromJar.of("glyphs/navigator/notched_20_progress.png"));
|
||||
}
|
||||
|
||||
private final Map<UUID, Map<String, BossBar>> bars = new ConcurrentHashMap<>();
|
||||
|
||||
public void hideAll(Player player) {
|
||||
var map = bars.remove(player.getUuid());
|
||||
if (map == null) return;
|
||||
|
||||
map.forEach((barId, bossBar) -> player.hideBossBar(bossBar));
|
||||
}
|
||||
|
||||
public void hide(Player player, String bossBarId) {
|
||||
var map = bars.get(player.getUuid());
|
||||
if (map == null) return;
|
||||
|
||||
var bossBar = map.remove(bossBarId);
|
||||
if (bossBar == null) return;
|
||||
|
||||
player.hideBossBar(bossBar);
|
||||
}
|
||||
|
||||
public BossBar show(Player player, String bossBarId, BossBar bossBar) {
|
||||
var playerBars = bars.computeIfAbsent(player.getUuid(), uuid -> new ConcurrentHashMap<>());
|
||||
var prev = playerBars.put(bossBarId, bossBar);
|
||||
if (prev != null) player.hideBossBar(prev);
|
||||
player.showBossBar(bossBar);
|
||||
return bossBar;
|
||||
}
|
||||
|
||||
public BossBar showText(Player player, String bossBarId, Component text) {
|
||||
return show(player, bossBarId, BossBar.bossBar(text, 1, BossBar.Color.WHITE, BossBar.Overlay.PROGRESS));
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user