add ActionBar with health & mana
This commit is contained in:
parent
75d89e7974
commit
8111b2b8f2
3 changed files with 20 additions and 2 deletions
|
@ -1,6 +1,7 @@
|
|||
package me.unurled.sacredrealms.sr.components.combat;
|
||||
|
||||
import static me.unurled.sacredrealms.sr.utils.Component.comp;
|
||||
import static me.unurled.sacredrealms.sr.utils.SRPlayerUtils.updateActionBar;
|
||||
|
||||
import java.util.Random;
|
||||
import me.unurled.sacredrealms.sr.components.attributes.Attribute;
|
||||
|
@ -156,6 +157,9 @@ public class CombatManager extends Manager {
|
|||
// apply damage
|
||||
player.damage(damage);
|
||||
|
||||
SRPlayer player1 = pm.getPlayer(player.getUniqueId());
|
||||
if (player1 != null) updateActionBar(player, player1);
|
||||
|
||||
// TODO: check for status effects (apply status effects depending item of damager)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package me.unurled.sacredrealms.sr.components.player;
|
||||
|
||||
import static me.unurled.sacredrealms.sr.utils.Logger.error;
|
||||
import static me.unurled.sacredrealms.sr.utils.SRPlayerUtils.updateActionBar;
|
||||
|
||||
import com.destroystokyo.paper.event.player.PlayerArmorChangeEvent;
|
||||
import com.google.gson.Gson;
|
||||
|
@ -100,6 +101,8 @@ public class PlayerManager extends Manager {
|
|||
e.getPlayer().getInventory().clear();
|
||||
e.getPlayer().getInventory().setContents(srPlayer.getInventory().getContents());
|
||||
|
||||
updateActionBar(e.getPlayer(), srPlayer);
|
||||
|
||||
e.getPlayer().updateInventory();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,19 +1,22 @@
|
|||
package me.unurled.sacredrealms.sr.utils;
|
||||
|
||||
import static me.unurled.sacredrealms.sr.utils.Component.comp;
|
||||
|
||||
import java.util.List;
|
||||
import me.unurled.sacredrealms.sr.components.attributes.Attribute;
|
||||
import me.unurled.sacredrealms.sr.components.player.SRPlayer;
|
||||
import org.bukkit.attribute.AttributeInstance;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class SRPlayerUtils {
|
||||
public static void syncPlayerToSR(Player p, SRPlayer sr) {
|
||||
public static void syncPlayerToSR(@NotNull Player p, @NotNull SRPlayer sr) {
|
||||
sr.setInventory(p.getInventory());
|
||||
sr.setPotionEffects((List<PotionEffect>) p.getActivePotionEffects());
|
||||
}
|
||||
|
||||
public static void syncSRToPlayer(SRPlayer sr, Player p) {
|
||||
public static void syncSRToPlayer(@NotNull SRPlayer sr, @NotNull Player p) {
|
||||
p.getInventory().setContents(sr.getInventory().getContents());
|
||||
|
||||
// agility (speed)
|
||||
|
@ -45,4 +48,12 @@ public class SRPlayerUtils {
|
|||
p.sendHealthUpdate();
|
||||
p.updateInventory();
|
||||
}
|
||||
|
||||
public static void updateActionBar(@NotNull Player p, @NotNull SRPlayer sr) {
|
||||
double health = sr.getAttribute(Attribute.HEALTH);
|
||||
double mana = sr.getAttribute(Attribute.MANA);
|
||||
|
||||
net.kyori.adventure.text.Component text = comp("<red>❤ " + health + " <blue>❈ " + mana);
|
||||
p.sendActionBar(text);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue