package gq.unurled.raxen.manager; import gq.unurled.raxen.Raxen; import gq.unurled.raxen.components.player.Attributes.Attribute; import gq.unurled.raxen.components.player.Attributes.Attributes; import gq.unurled.raxen.components.player.RaxenPlayer; import net.kyori.adventure.text.Component; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitTask; import java.util.HashMap; import java.util.UUID; public class PlayerManager { private Raxen main; private HashMap actionBar = new HashMap<>(); public PlayerManager(Raxen main) { this.main = main; } public RaxenPlayer getRaxenPlayer(Player player) { return new RaxenPlayer(main, player); } public void registerActionBar(Player player) { Attribute attributes = getRaxenPlayer(player).getAttributes().getAttribute(player); BukkitTask task = new BukkitRunnable() { @Override public void run() { player.sendActionBar(Component.text(attributes.getHealth() + "/" + attributes.getMaxHealth() + "❤ " + attributes.getMana() + "/" + attributes.getMaxMana())); } }.runTaskTimer(main, 0L, 20L); if(actionBar.containsKey(player.getUniqueId())) { actionBar.replace(player.getUniqueId(), task); } else { actionBar.put(player.getUniqueId(), task); } } public void unRegisterActionBar(Player player) { if(actionBar.containsKey(player.getUniqueId())) { BukkitTask task = actionBar.get(player.getUniqueId()); task.cancel(); actionBar.remove(player.getUniqueId()); } } public void unEegisterRaxenPlayer(Player player) { } }