package gq.unurled.raxen.manager.entity; import gq.unurled.raxen.Raxen; import gq.unurled.raxen.components.entity.Attributes.*; import gq.unurled.raxen.components.entity.other.EntityNamespacedKey; import gq.unurled.raxen.components.entity.player.RaxenPlayer; import gq.unurled.raxen.components.entity.player.classes.Class; import lombok.Getter; 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<>(); private HashMap classes = new HashMap<>(); @Getter private HashMap attribute = new HashMap<>(); // Attributes private Defense defense; private Health health; private ItemDefense itemDefense; private ItemHealth itemHealth; private ItemLuck itemLuck; private ItemMana itemMana; private ItemSpeed itemSpeed; private ItemStrength itemStrength; private Luck luck; private Mana mana; private MaxHealth maxHealth; private MaxMana maxMana; private Speed speed; private Strength strength; public PlayerManager(Raxen main) { this.main = main; registerAttributes(); } public RaxenPlayer getRaxenPlayer(Player player) { return new RaxenPlayer(main, player); } /** * add a task to the player action bar. * @param player */ public void registerActionBar(Player player) { PlayerManager pm = main.getManager().getPlayerManager(); BukkitTask task = new BukkitRunnable() { @Override public void run() { player.sendActionBar(Component.text(pm.getHealth().get(player) + "/" + pm.getMaxHealth().get(player) + "❤ " + pm.getMana().get(player) + "/" + pm.getMaxMana().get(player))); } }.runTaskTimer(main, 0L, 20L); if(actionBar.containsKey(player.getUniqueId())) { actionBar.replace(player.getUniqueId(), task); } else { actionBar.put(player.getUniqueId(), task); } } /** * removes the task of action bar to player * @param player */ public void unRegisterActionBar(Player player) { if(actionBar.containsKey(player.getUniqueId())) { BukkitTask task = actionBar.get(player.getUniqueId()); task.cancel(); actionBar.remove(player.getUniqueId()); } } public void unRegisterRaxenPlayer(Player player) { } public void registerClasses() { } /** * getClasses * @return the classes HashMap */ public HashMap getClasses() { return classes; } /** * add @param to hashmap of classes * @param clas a class instance * @param id the id of the class */ public void addClasses(Class clas, String id) { classes.put(id, clas); } /** * register all Attributes in gq.unurled.raxen.components.entity.Attributes; */ public void registerAttributes() { EntityNamespacedKey key = new EntityNamespacedKey(main); this.defense = new Defense(key.defense, "DEFENSE"); attribute.put("DEFENSE", defense); this.health = new Health(key.health, "HEALTH"); attribute.put("HEALTH", health); this.itemDefense = new ItemDefense(key.itemDefense, "ITEM_DEFENSE"); attribute.put("ITEM_DEFENSE", itemDefense); this.itemHealth = new ItemHealth(key.itemHealth, "ITEM_HEALTH"); attribute.put("ITEM_HEALTH", itemHealth); this.itemLuck = new ItemLuck(key.itemLuck, "ITEM_LUCK"); attribute.put("ITEM_LUCK", itemLuck); this.itemMana = new ItemMana(key.itemMana, "ITEM_MANA"); attribute.put("ITEM_MANA", itemMana); this.itemSpeed = new ItemSpeed(key.itemSpeed, "ITEM_SPEED"); attribute.put("ITEM_SPEED", itemSpeed); this.itemStrength = new ItemStrength(key.itemStrength, "ITEM_STRENGTH"); attribute.put("ITEM_STRENGTH", itemStrength); this.luck = new Luck(key.luck, "LUCK"); attribute.put("LUCK", luck); this.mana = new Mana(key.mana, "MANA"); attribute.put("MANA", mana); this.maxMana = new MaxManaBuilder().setNamespacekey(key.maxMana).setName("MAX_MANA").createMaxMana(); attribute.put("MAX_MANA", maxMana); this.maxHealth = new MaxHealth(key.maxHealth, "MAX_HEALTH"); attribute.put("MAX_HEALTH", maxHealth); this.speed = new Speed(key.speed, "SPEED"); attribute.put("SPEED", speed); this.strength = new Strength(key.strength, "STRENGTH"); attribute.put("STRENGTH", strength); } public Defense getDefense() { return (Defense) attribute.get("DEFENSE"); } public Health getHealth() { return (Health) attribute.get("HEALTH"); } public ItemDefense getItemDefense() { return (ItemDefense) attribute.get("ITEM_DEFENSE"); } public ItemHealth getItemHealth() { return (ItemHealth) attribute.get("ITEM_HEALTH"); } public ItemLuck getItemLuck() { return (ItemLuck) attribute.get("ITEM_LUCK"); } public ItemMana getItemMana() { return (ItemMana) attribute.get("ITEM_MANA"); } public ItemSpeed getItemSpeed() { return (ItemSpeed) attribute.get("ITEM_SPEED"); } public ItemStrength getItemStrength() { return (ItemStrength) attribute.get("ITEM_STRENGTH"); } public Luck getLuck() { return (Luck) attribute.get("LUCK"); } public Mana getMana() { return (Mana) attribute.get("MANA"); } public MaxMana getMaxMana() { return (MaxMana) attribute.get("MAX_MANA"); } public MaxHealth getMaxHealth() { return (MaxHealth) attribute.get("MAX_HEALTH"); } public Speed getSpeed() { return (Speed) attribute.get("SPEED"); } public Strength getStrength() { return (Strength) attribute.get("STRENGTH"); } }