diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/MMOCore.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/MMOCore.java index 7a613398..ea6dc7b2 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/MMOCore.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/MMOCore.java @@ -6,7 +6,7 @@ import io.lumine.mythic.lib.version.SpigotPlugin; import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.manager.social.PartyManager; import net.Indyuce.mmocore.api.ConfigFile; -import net.Indyuce.mmocore.api.PlayerActionBar; +import net.Indyuce.mmocore.manager.ActionBarManager; import net.Indyuce.mmocore.api.player.attribute.AttributeModifier; import net.Indyuce.mmocore.api.player.profess.resource.PlayerResource; import net.Indyuce.mmocore.command.*; @@ -64,7 +64,7 @@ public class MMOCore extends JavaPlugin { public final SoundManager soundManager = new SoundManager(); public final RequestManager requestManager = new RequestManager(); public final ConfigItemManager configItems = new ConfigItemManager(); - public final PlayerActionBar actionBarManager = new PlayerActionBar(); + public final ActionBarManager actionBarManager = new ActionBarManager(); public final SkillManager skillManager = new SkillManager(); public final ClassManager classManager = new ClassManager(); public final DropTableManager dropTableManager = new DropTableManager(); diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/PlayerActionBar.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/PlayerActionBar.java deleted file mode 100644 index ad7fd332..00000000 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/PlayerActionBar.java +++ /dev/null @@ -1,81 +0,0 @@ -package net.Indyuce.mmocore.api; - -import io.lumine.mythic.lib.MythicLib; -import io.lumine.mythic.lib.manager.StatManager; -import net.Indyuce.mmocore.MMOCore; -import net.Indyuce.mmocore.api.player.PlayerActivity; -import net.Indyuce.mmocore.api.player.PlayerData; -import net.Indyuce.mmocore.gui.api.item.Placeholders; -import net.md_5.bungee.api.ChatMessageType; -import net.md_5.bungee.api.chat.TextComponent; -import org.bukkit.attribute.Attribute; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.scheduler.BukkitRunnable; - -import java.text.DecimalFormat; - -public class PlayerActionBar extends BukkitRunnable { - boolean initialized = false; - - private ActionBarConfig config; - private DecimalFormat digit; - - public void reload(ConfigurationSection cfg) { - config = new ActionBarConfig(cfg); - digit = MythicLib.plugin.getMMOConfig().newDecimalFormat(config.digit); - - if (!initialized && config.enabled) { - runTaskTimer(MMOCore.plugin, 0, config.ticks); - initialized = true; - } - } - - public long getTimeOut() { - return config.timeout; - } - - @Override - public void run() { - for (PlayerData data : PlayerData.getAll()) - if (data.isOnline() && !data.getPlayer().isDead() && !data.isCasting() && data.getActivityTimeOut(PlayerActivity.ACTION_BAR_MESSAGE) == 0) { - Placeholders holders=getActionBarPlaceholder(data); - data.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText( - holders.apply(data.getPlayer(), data.getProfess().hasActionBar() ? data.getProfess().getActionBar() : config.format))); - - } - } - - public Placeholders getActionBarPlaceholder(PlayerData data) { - Placeholders holders= new Placeholders(); - holders.register("health", digit.format(data.getPlayer().getHealth())); - holders.register("max_health", StatManager.format("MAX_HEALTH", data.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue())); - holders.register("mana_icon", data.getProfess().getManaDisplay().getIcon()); - holders.register("mana", digit.format(data.getMana())); - holders.register("max_mana", StatManager.format("MAX_MANA", data.getStats().getStat("MAX_MANA"))); - holders.register("stamina", digit.format(data.getStamina())); - holders.register("max_stamina", StatManager.format("MAX_STAMINA", data.getStats().getStat("MAX_STAMINA"))); - holders.register("stellium", digit.format(data.getStellium())); - holders.register("max_stellium", StatManager.format("MAX_STELLIUM", data.getStats().getStat("MAX_STELLIUM"))); - holders.register("class", data.getProfess().getName()); - holders.register("xp", MythicLib.plugin.getMMOConfig().decimal.format(data.getExperience())); - holders.register("armor", StatManager.format("ARMOR", data.getPlayer().getAttribute(Attribute.GENERIC_ARMOR).getValue())); - holders.register("level", "" + data.getLevel()); - holders.register("name", data.getPlayer().getDisplayName()); - return holders; - } - - - private static class ActionBarConfig { - private final boolean enabled; - private final int ticks, timeout; - private final String digit, format; - - private ActionBarConfig(ConfigurationSection config) { - enabled = config.getBoolean("enabled", false); - timeout = config.getInt("", 60); - digit = config.getString("decimal", "0.#"); - ticks = config.getInt("ticks-to-update", 5); - format = config.getString("format", "please format me :c"); - } - } -} diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/ActionBarManager.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/ActionBarManager.java new file mode 100644 index 00000000..93fa969c --- /dev/null +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/ActionBarManager.java @@ -0,0 +1,68 @@ +package net.Indyuce.mmocore.manager; + +import io.lumine.mythic.lib.MythicLib; +import io.lumine.mythic.lib.manager.StatManager; +import net.Indyuce.mmocore.MMOCore; +import net.Indyuce.mmocore.api.player.PlayerActivity; +import net.Indyuce.mmocore.api.player.PlayerData; +import net.Indyuce.mmocore.gui.api.item.Placeholders; +import net.md_5.bungee.api.ChatMessageType; +import net.md_5.bungee.api.chat.TextComponent; +import org.bukkit.attribute.Attribute; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.scheduler.BukkitRunnable; + +public class ActionBarManager extends BukkitRunnable { + private int updateTicks, timeOut; + private String barFormat; + private boolean enabled, scheduled; + + public void reload(ConfigurationSection config) { + enabled = config.getBoolean("enabled", false); + timeOut = config.getInt("", 60); + updateTicks = config.getInt("ticks-to-update", 5); + barFormat = config.getString("format", ""); + + if (!scheduled && enabled) { + runTaskTimer(MMOCore.plugin, 0, updateTicks); + scheduled = true; + } else if (scheduled && !enabled) { + cancel(); + scheduled = false; + } + } + + public long getTimeOut() { + return timeOut; + } + + @Override + public void run() { + for (PlayerData data : PlayerData.getAll()) + if (data.isOnline() && !data.getPlayer().isDead() && !data.isCasting() && data.getActivityTimeOut(PlayerActivity.ACTION_BAR_MESSAGE) == 0) { + Placeholders holders = getActionBarPlaceholders(data); + data.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText( + holders.apply(data.getPlayer(), data.getProfess().hasActionBar() ? data.getProfess().getActionBar() : barFormat))); + + } + } + + public Placeholders getActionBarPlaceholders(PlayerData data) { + Placeholders holders = new Placeholders(); + holders.register("health", StatManager.format("MAX_HEALTH", data.getPlayer().getHealth())); + holders.register("max_health", StatManager.format("MAX_HEALTH", data.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue())); + holders.register("mana_icon", data.getProfess().getManaDisplay().getIcon()); + holders.register("mana", StatManager.format("MAX_MANA", data.getMana())); + holders.register("max_mana", StatManager.format("MAX_MANA", data.getStats().getStat("MAX_MANA"))); + holders.register("stamina", StatManager.format("MAX_STAMINA", data.getStamina())); + holders.register("max_stamina", StatManager.format("MAX_STAMINA", data.getStats().getStat("MAX_STAMINA"))); + holders.register("stellium", StatManager.format("MAX_STELLIUM", data.getStellium())); + holders.register("max_stellium", StatManager.format("MAX_STELLIUM", data.getStats().getStat("MAX_STELLIUM"))); + holders.register("class", data.getProfess().getName()); + holders.register("xp", MythicLib.plugin.getMMOConfig().decimal.format(data.getExperience())); + holders.register("armor", StatManager.format("ARMOR", data.getPlayer().getAttribute(Attribute.GENERIC_ARMOR).getValue())); + holders.register("level", String.valueOf(data.getLevel())); + holders.register("name", data.getPlayer().getDisplayName()); + return holders; + } +} diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/cast/listener/KeyCombos.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/cast/listener/KeyCombos.java index 8a8562f8..10d26842 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/cast/listener/KeyCombos.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/cast/listener/KeyCombos.java @@ -238,7 +238,7 @@ public class KeyCombos implements Listener { public String format(CustomSkillCastingHandler casting) { StringBuilder builder = new StringBuilder(); - Placeholders holders = MMOCore.plugin.actionBarManager.getActionBarPlaceholder(casting.getCaster()); + Placeholders holders = MMOCore.plugin.actionBarManager.getActionBarPlaceholders(casting.getCaster()); builder.append(prefix); // Join all keys with separator diff --git a/MMOCore-Dist/src/main/resources/config.yml b/MMOCore-Dist/src/main/resources/config.yml index 84dc994b..cb4e59a4 100644 --- a/MMOCore-Dist/src/main/resources/config.yml +++ b/MMOCore-Dist/src/main/resources/config.yml @@ -114,11 +114,8 @@ action-bar: # (This doesn't change any other action bars provided by MMOCore.) enabled: true - # The decimal format for stats (not including stat formats in stats.yml) - decimal: "0.#" - - # The amount of miliseconds the bar will be faded - #out when displaying other action bars. + # The amount of milliseconds the bar will be + # faded out when displaying other action bars. time-out: 60 # The amount of ticks before updating the info