mirror of
https://gitlab.com/phoenix-dvpmt/mmocore.git
synced 2024-12-25 05:07:46 +01:00
Small action bar changes
This commit is contained in:
parent
3a2f6e20ed
commit
e326bad6b3
@ -6,7 +6,7 @@ import io.lumine.mythic.lib.version.SpigotPlugin;
|
|||||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||||
import net.Indyuce.mmocore.manager.social.PartyManager;
|
import net.Indyuce.mmocore.manager.social.PartyManager;
|
||||||
import net.Indyuce.mmocore.api.ConfigFile;
|
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.attribute.AttributeModifier;
|
||||||
import net.Indyuce.mmocore.api.player.profess.resource.PlayerResource;
|
import net.Indyuce.mmocore.api.player.profess.resource.PlayerResource;
|
||||||
import net.Indyuce.mmocore.command.*;
|
import net.Indyuce.mmocore.command.*;
|
||||||
@ -64,7 +64,7 @@ public class MMOCore extends JavaPlugin {
|
|||||||
public final SoundManager soundManager = new SoundManager();
|
public final SoundManager soundManager = new SoundManager();
|
||||||
public final RequestManager requestManager = new RequestManager();
|
public final RequestManager requestManager = new RequestManager();
|
||||||
public final ConfigItemManager configItems = new ConfigItemManager();
|
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 SkillManager skillManager = new SkillManager();
|
||||||
public final ClassManager classManager = new ClassManager();
|
public final ClassManager classManager = new ClassManager();
|
||||||
public final DropTableManager dropTableManager = new DropTableManager();
|
public final DropTableManager dropTableManager = new DropTableManager();
|
||||||
|
@ -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");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -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", "<No Action Bar Format Found>");
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
@ -238,7 +238,7 @@ public class KeyCombos implements Listener {
|
|||||||
|
|
||||||
public String format(CustomSkillCastingHandler casting) {
|
public String format(CustomSkillCastingHandler casting) {
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
Placeholders holders = MMOCore.plugin.actionBarManager.getActionBarPlaceholder(casting.getCaster());
|
Placeholders holders = MMOCore.plugin.actionBarManager.getActionBarPlaceholders(casting.getCaster());
|
||||||
|
|
||||||
builder.append(prefix);
|
builder.append(prefix);
|
||||||
// Join all keys with separator
|
// Join all keys with separator
|
||||||
|
@ -114,11 +114,8 @@ action-bar:
|
|||||||
# (This doesn't change any other action bars provided by MMOCore.)
|
# (This doesn't change any other action bars provided by MMOCore.)
|
||||||
enabled: true
|
enabled: true
|
||||||
|
|
||||||
# The decimal format for stats (not including stat formats in stats.yml)
|
# The amount of milliseconds the bar will be
|
||||||
decimal: "0.#"
|
# faded out when displaying other action bars.
|
||||||
|
|
||||||
# The amount of miliseconds the bar will be faded
|
|
||||||
#out when displaying other action bars.
|
|
||||||
time-out: 60
|
time-out: 60
|
||||||
|
|
||||||
# The amount of ticks before updating the info
|
# The amount of ticks before updating the info
|
||||||
|
Loading…
Reference in New Issue
Block a user