feat: added method for easy getting player context
This commit is contained in:
parent
dc0f628a0d
commit
2b007d9897
@ -1,6 +1,7 @@
|
|||||||
package ru.dragonestia.msb3.api.player;
|
package ru.dragonestia.msb3.api.player;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import net.minestom.server.entity.Player;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public abstract class PlayerContext {
|
public abstract class PlayerContext {
|
||||||
@ -14,4 +15,8 @@ public abstract class PlayerContext {
|
|||||||
public abstract void init();
|
public abstract void init();
|
||||||
|
|
||||||
public abstract void dispose();
|
public abstract void dispose();
|
||||||
|
|
||||||
|
public static <T extends PlayerContext> T of(Player player, Class<T> clazz) {
|
||||||
|
return ((MsbPlayer) player).getContext(clazz);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import net.kyori.adventure.bossbar.BossBar;
|
|||||||
import net.kyori.adventure.key.Key;
|
import net.kyori.adventure.key.Key;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.minestom.server.entity.Player;
|
import net.minestom.server.entity.Player;
|
||||||
import ru.dragonestia.msb3.api.player.PlayerContextManager;
|
import ru.dragonestia.msb3.api.player.PlayerContext;
|
||||||
import ru.dragonestia.msb3.api.player.defaults.KeyedBossBarContext;
|
import ru.dragonestia.msb3.api.player.defaults.KeyedBossBarContext;
|
||||||
import ru.dragonestia.msb3.api.util.ResourceFromJar;
|
import ru.dragonestia.msb3.api.util.ResourceFromJar;
|
||||||
import ru.dragonestia.msb3.resource.Resources;
|
import ru.dragonestia.msb3.resource.Resources;
|
||||||
@ -23,22 +23,22 @@ public class KeyedBossBars {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void hideAll(Player player) {
|
public void hideAll(Player player) {
|
||||||
contextOf(player).hideAll();
|
context(player).hideAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void hide(Player player, String bossBarId) {
|
public void hide(Player player, String bossBarId) {
|
||||||
contextOf(player).hide(bossBarId);
|
context(player).hide(bossBarId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BossBar show(Player player, String bossBarId, BossBar bossBar) {
|
public BossBar show(Player player, String bossBarId, BossBar bossBar) {
|
||||||
return contextOf(player).show(bossBarId, bossBar);
|
return context(player).show(bossBarId, bossBar);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BossBar showText(Player player, String bossBarId, Component text) {
|
public BossBar showText(Player player, String bossBarId, Component text) {
|
||||||
return show(player, bossBarId, BossBar.bossBar(text, 1, BossBar.Color.WHITE, BossBar.Overlay.PROGRESS));
|
return show(player, bossBarId, BossBar.bossBar(text, 1, BossBar.Color.WHITE, BossBar.Overlay.PROGRESS));
|
||||||
}
|
}
|
||||||
|
|
||||||
private KeyedBossBarContext contextOf(Player player) {
|
private KeyedBossBarContext context(Player player) {
|
||||||
return PlayerContextManager.getContext(player, KeyedBossBarContext.class);
|
return PlayerContext.of(player, KeyedBossBarContext.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user