action bar + health management
This commit is contained in:
parent
39a1bb192f
commit
dd665fd455
4 changed files with 34 additions and 4 deletions
|
@ -158,7 +158,13 @@ public class CombatManager extends Manager {
|
|||
player.damage(damage);
|
||||
|
||||
SRPlayer player1 = pm.getPlayer(player.getUniqueId());
|
||||
if (player1 != null) updateActionBar(player, player1);
|
||||
if (player1 != null) {
|
||||
player1.setHealth(player.getHealth() - damage);
|
||||
if (player1.getHealth() <= 0) {
|
||||
player.damage(player.getHealth());
|
||||
}
|
||||
updateActionBar(player, player1);
|
||||
}
|
||||
|
||||
// TODO: check for status effects (apply status effects depending item of damager)
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import com.google.gson.Gson;
|
|||
import com.google.gson.GsonBuilder;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
import me.unurled.sacredrealms.sr.SR;
|
||||
import me.unurled.sacredrealms.sr.data.DataHandler;
|
||||
import me.unurled.sacredrealms.sr.data.DataManager;
|
||||
import me.unurled.sacredrealms.sr.data.gson.InventoryDeserializer;
|
||||
|
@ -16,6 +17,7 @@ import me.unurled.sacredrealms.sr.data.gson.PotionEffectDeserializer;
|
|||
import me.unurled.sacredrealms.sr.data.gson.PotionEffectSerializer;
|
||||
import me.unurled.sacredrealms.sr.managers.Manager;
|
||||
import me.unurled.sacredrealms.sr.utils.Items;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerItemHeldEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
@ -23,6 +25,7 @@ import org.bukkit.event.player.PlayerQuitEvent;
|
|||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
|
@ -32,9 +35,12 @@ public class PlayerManager extends Manager {
|
|||
private final HashMap<UUID, SRPlayer> players;
|
||||
private DataHandler dh;
|
||||
|
||||
private final HashMap<UUID, BukkitTask> actionBarTasks;
|
||||
|
||||
public PlayerManager() {
|
||||
super();
|
||||
players = new HashMap<>();
|
||||
actionBarTasks = new HashMap<>();
|
||||
}
|
||||
|
||||
/** Save the data */
|
||||
|
@ -109,8 +115,12 @@ public class PlayerManager extends Manager {
|
|||
e.getPlayer().getInventory().clear();
|
||||
e.getPlayer().getInventory().setContents(srPlayer.getInventory().getContents());
|
||||
|
||||
updateActionBar(e.getPlayer(), srPlayer);
|
||||
BukkitTask task =
|
||||
Bukkit.getScheduler()
|
||||
.runTaskTimerAsynchronously(
|
||||
SR.getInstance(), () -> updateActionBar(e.getPlayer(), srPlayer), 0, 20L);
|
||||
|
||||
actionBarTasks.put(e.getPlayer().getUniqueId(), task);
|
||||
e.getPlayer().updateInventory();
|
||||
}
|
||||
|
||||
|
@ -148,6 +158,9 @@ public class PlayerManager extends Manager {
|
|||
// save for player
|
||||
savePlayer(player);
|
||||
|
||||
actionBarTasks.get(e.getPlayer().getUniqueId()).cancel();
|
||||
actionBarTasks.remove(e.getPlayer().getUniqueId());
|
||||
|
||||
removePlayer(e.getPlayer().getUniqueId());
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ public class SRPlayer {
|
|||
|
||||
@Expose private UUID uuid = null;
|
||||
@Expose private int level = 0;
|
||||
private double health = 100;
|
||||
@Expose private HashMap<Attribute, Double> attributes = new HashMap<>();
|
||||
private HashMap<Attribute, HashMap<ItemStack, Double>> itemAttributes = new HashMap<>();
|
||||
@Expose private List<PotionEffect> potionEffects;
|
||||
|
@ -226,4 +227,12 @@ public class SRPlayer {
|
|||
public void setLevel(int i) {
|
||||
level = i;
|
||||
}
|
||||
|
||||
public double getHealth() {
|
||||
return health;
|
||||
}
|
||||
|
||||
public void setHealth(double health) {
|
||||
this.health = health;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,10 +50,12 @@ public class SRPlayerUtils {
|
|||
}
|
||||
|
||||
public static void updateActionBar(@NotNull Player p, @NotNull SRPlayer sr) {
|
||||
double health = sr.getAttribute(Attribute.HEALTH);
|
||||
double maxHealth = sr.getAttribute(Attribute.HEALTH);
|
||||
double health = sr.getHealth();
|
||||
double mana = sr.getAttribute(Attribute.MANA);
|
||||
|
||||
net.kyori.adventure.text.Component text = comp("<red>❤ " + health + " <blue>❈ " + mana);
|
||||
net.kyori.adventure.text.Component text =
|
||||
comp("<red>❤ " + health + "/" + maxHealth + " <blue>❈ " + mana);
|
||||
p.sendActionBar(text);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue