forked from Upstream/mmocore
!Moved action bar to another class
This commit is contained in:
parent
d846044cf3
commit
ad392038dd
@ -2,15 +2,10 @@ package net.Indyuce.mmocore;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.command.CommandMap;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
@ -19,6 +14,7 @@ import org.bukkit.scheduler.BukkitRunnable;
|
||||
import com.codingforcookies.armorequip.ArmorListener;
|
||||
|
||||
import net.Indyuce.mmocore.api.ConfigFile;
|
||||
import net.Indyuce.mmocore.api.PlayerActionBar;
|
||||
import net.Indyuce.mmocore.api.debug.DebugMode;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.api.player.profess.resource.PlayerResource;
|
||||
@ -96,8 +92,6 @@ import net.Indyuce.mmocore.manager.social.PartyManager;
|
||||
import net.Indyuce.mmocore.manager.social.RequestManager;
|
||||
import net.Indyuce.mmocore.version.ServerVersion;
|
||||
import net.Indyuce.mmocore.version.nms.NMSHandler;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
|
||||
public class MMOCore extends JavaPlugin {
|
||||
public static MMOCore plugin;
|
||||
@ -127,6 +121,7 @@ public class MMOCore extends JavaPlugin {
|
||||
public ServerVersion version;
|
||||
public InventoryManager inventoryManager;
|
||||
public RegionHandler regionHandler;
|
||||
public PlayerActionBar actionBarManager ;
|
||||
|
||||
/*
|
||||
* professions
|
||||
@ -139,7 +134,6 @@ public class MMOCore extends JavaPlugin {
|
||||
public final MMOLoadManager loadManager = new MMOLoadManager();
|
||||
public RPGUtilHandler rpgUtilHandler = new DefaultRPGUtilHandler();
|
||||
|
||||
private List<UUID> pausePlayers = new ArrayList<>();
|
||||
|
||||
public void onLoad() {
|
||||
plugin = this;
|
||||
@ -260,29 +254,8 @@ public class MMOCore extends JavaPlugin {
|
||||
/*
|
||||
* default action bar. only ran if the action bar is enabled
|
||||
*/
|
||||
if (getConfig().getBoolean("action-bar.enabled")) {
|
||||
DecimalFormat format = new DecimalFormat(getConfig().getString("action-bar.decimal"), configManager.formatSymbols);
|
||||
int ticks = getConfig().getInt("action-bar.ticks-to-update");
|
||||
|
||||
new BukkitRunnable() {
|
||||
public void run() {
|
||||
for (PlayerData data : PlayerData.getAll()) {
|
||||
if (data.isOnline() && !data.getPlayer().isDead() && !data.isCasting() && !pausePlayers.contains(data.getUniqueId())) {
|
||||
data.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(placeholderParser.parse(data.getPlayer(),
|
||||
ChatColor.translateAlternateColorCodes('&', getConfig().getString("action-bar.format").replace("{health}", format.format(data.getPlayer().getHealth()))
|
||||
.replace("{max_health}", "" + StatType.MAX_HEALTH.format(data.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue())).replace("{mana}", format.format(data.getMana()))
|
||||
.replace("{max_mana}", "" + StatType.MAX_MANA.format(data.getStats().getStat(StatType.MAX_MANA))).replace("{stamina}", format.format(data.getStamina()))
|
||||
.replace("{max_stamina}", "" + StatType.MAX_STAMINA.format(data.getStats().getStat(StatType.MAX_STAMINA)))
|
||||
.replace("{stellium}", format.format(data.getStellium()))
|
||||
.replace("{max_stellium}", "" + StatType.MAX_STELLIUM.format(data.getStats().getStat(StatType.MAX_STELLIUM)))
|
||||
.replace("{class}", data.getProfess().getName()).replace("{xp}", "" + data.getExperience())
|
||||
.replace("{armor}", "" + StatType.ARMOR.format(data.getPlayer().getAttribute(Attribute.GENERIC_ARMOR).getValue())).replace("{level}", "" + data.getLevel())
|
||||
.replace("{name}", data.getPlayer().getDisplayName())))));
|
||||
}
|
||||
}
|
||||
}
|
||||
}.runTaskTimerAsynchronously(MMOCore.plugin, 100, ticks);
|
||||
}
|
||||
if (getConfig().getBoolean("action-bar.enabled"))
|
||||
new PlayerActionBar(getConfig().getConfigurationSection("action-bar"));
|
||||
|
||||
/*
|
||||
* enable debug mode for extra debug tools.
|
||||
@ -438,15 +411,4 @@ public class MMOCore extends JavaPlugin {
|
||||
public boolean hasEconomy() {
|
||||
return economy != null && economy.isValid();
|
||||
}
|
||||
|
||||
public void pauseDefaultActionBar(UUID uuid, int ticks) {
|
||||
pausePlayers.add(uuid);
|
||||
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
pausePlayers.remove(uuid);
|
||||
}
|
||||
}.runTaskLater(MMOCore.plugin, ticks);
|
||||
}
|
||||
}
|
||||
|
50
src/main/java/net/Indyuce/mmocore/api/PlayerActionBar.java
Normal file
50
src/main/java/net/Indyuce/mmocore/api/PlayerActionBar.java
Normal file
@ -0,0 +1,50 @@
|
||||
package net.Indyuce.mmocore.api;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.api.player.stats.StatType;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
|
||||
public class PlayerActionBar extends BukkitRunnable {
|
||||
private final int ticks;
|
||||
private final DecimalFormat digit;
|
||||
private final String format;
|
||||
|
||||
public PlayerActionBar(ConfigurationSection config) {
|
||||
digit = new DecimalFormat(config.getString("decimal"), MMOCore.plugin.configManager.formatSymbols);
|
||||
ticks = config.getInt("ticks-to-update");
|
||||
format = config.getString("format");
|
||||
|
||||
runTaskTimerAsynchronously(MMOCore.plugin, 0, ticks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for (PlayerData data : PlayerData.getAll())
|
||||
if (data.isOnline() && !data.getPlayer().isDead() && !data.isCasting() && data.canSeeActionBar()) {
|
||||
data.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(MMOCore.plugin.placeholderParser.parse(data.getPlayer(),
|
||||
ChatColor.translateAlternateColorCodes('&', new String(format)
|
||||
.replace("{health}", digit.format(data.getPlayer().getHealth()))
|
||||
.replace("{max_health}", "" + StatType.MAX_HEALTH.format(data.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()))
|
||||
.replace("{mana}", digit.format(data.getMana()))
|
||||
.replace("{max_mana}", "" + StatType.MAX_MANA.format(data.getStats().getStat(StatType.MAX_MANA)))
|
||||
.replace("{stamina}", digit.format(data.getStamina()))
|
||||
.replace("{max_stamina}", "" + StatType.MAX_STAMINA.format(data.getStats().getStat(StatType.MAX_STAMINA)))
|
||||
.replace("{stellium}", digit.format(data.getStellium()))
|
||||
.replace("{max_stellium}", "" + StatType.MAX_STELLIUM.format(data.getStats().getStat(StatType.MAX_STELLIUM)))
|
||||
.replace("{class}", data.getProfess().getName())
|
||||
.replace("{xp}", "" + data.getExperience())
|
||||
.replace("{armor}", "" + StatType.ARMOR.format(data.getPlayer().getAttribute(Attribute.GENERIC_ARMOR).getValue()))
|
||||
.replace("{level}", "" + data.getLevel())
|
||||
.replace("{name}", data.getPlayer().getDisplayName())))));
|
||||
}
|
||||
}
|
||||
}
|
@ -77,7 +77,7 @@ public class PlayerData {
|
||||
private final PlayerAttributes attributes = new PlayerAttributes(this);
|
||||
|
||||
private final PlayerStats playerStats = new PlayerStats(this);
|
||||
private long lastWaypoint, lastLogin, lastFriendRequest, lastActionbarUpdate;
|
||||
private long lastWaypoint, lastLogin, lastFriendRequest, actionBarTimeOut;
|
||||
|
||||
private final Map<String, Integer> skills = new HashMap<>();
|
||||
private final PlayerSkillData skillData = new PlayerSkillData(this);
|
||||
@ -519,9 +519,7 @@ public class PlayerData {
|
||||
}
|
||||
|
||||
public void giveMana(double amount) {
|
||||
if (mana != (mana = Math.max(0, Math.min(getStats().getStat(StatType.MAX_MANA), mana + amount))))
|
||||
if (MMOCore.plugin.getConfig().getBoolean("display.mana"))
|
||||
displayMana();
|
||||
mana = Math.max(0, Math.min(getStats().getStat(StatType.MAX_MANA), mana + amount));
|
||||
}
|
||||
|
||||
public void giveStamina(double amount) {
|
||||
@ -576,28 +574,28 @@ public class PlayerData {
|
||||
return skillCasting != null;
|
||||
}
|
||||
|
||||
public void displayActionBar(String message) {
|
||||
MMOCore.plugin.pauseDefaultActionBar(uuid, 60);
|
||||
/*
|
||||
* returns if the action bar is not being used to display anything else and
|
||||
* if the general info action bar can be displayed
|
||||
*/
|
||||
public boolean canSeeActionBar() {
|
||||
return actionBarTimeOut + 100 < System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public void setActionBarTimeOut(long actionBarTimeOut) {
|
||||
this.actionBarTimeOut = actionBarTimeOut;
|
||||
}
|
||||
|
||||
lastActionbarUpdate = System.currentTimeMillis();
|
||||
public void displayActionBar(String message) {
|
||||
actionBarTimeOut = System.currentTimeMillis();
|
||||
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message));
|
||||
}
|
||||
|
||||
/*
|
||||
* 200ms timeout to prevent action bar displayed gitches when casting spells
|
||||
* and when using a waypoint.
|
||||
*/
|
||||
public void displayMana() {
|
||||
if (System.currentTimeMillis() > lastActionbarUpdate + 1200)
|
||||
MMOCore.plugin.pauseDefaultActionBar(uuid, 60);
|
||||
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(getProfess().getManaDisplay().generateBar(getMana(), getStats().getStat(StatType.MAX_MANA))));
|
||||
public void setAttribute(PlayerAttribute attribute, int value) {
|
||||
setAttribute(attribute.getId(), value);
|
||||
}
|
||||
|
||||
public void setAttributes(PlayerAttribute attribute, int value) {
|
||||
setAttributes(attribute.getId(), value);
|
||||
}
|
||||
|
||||
public void setAttributes(String id, int value) {
|
||||
public void setAttribute(String id, int value) {
|
||||
attributes.setBaseAttribute(id, value);
|
||||
}
|
||||
|
||||
|
@ -140,7 +140,7 @@ public class SavedClassInformation {
|
||||
player.setAttributePoints(attributePoints);
|
||||
player.setAttributeReallocationPoints(attributeReallocationPoints);
|
||||
skills.keySet().forEach(id -> player.setSkillLevel(id, skills.get(id)));
|
||||
attributes.keySet().forEach(id -> player.setAttributes(id, attributes.get(id)));
|
||||
attributes.keySet().forEach(id -> player.setAttribute(id, attributes.get(id)));
|
||||
|
||||
/*
|
||||
* unload current class information and set the new profess once
|
||||
|
@ -5,7 +5,7 @@ import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.command.api.CommandEnd;
|
||||
import net.Indyuce.mmocore.command.api.CommandMap;
|
||||
import net.Indyuce.mmocore.command.api.Parameter;
|
||||
@ -36,8 +36,8 @@ public class HideActionBarCommandMap extends CommandEnd {
|
||||
sender.sendMessage(ChatColor.RED + args[3] + " is not a valid number.");
|
||||
return CommandResult.FAILURE;
|
||||
}
|
||||
|
||||
MMOCore.plugin.pauseDefaultActionBar(player.getUniqueId(), amount);
|
||||
|
||||
PlayerData.get(player).setActionBarTimeOut(System.currentTimeMillis() - 100 + amount * 50);
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
@ -36,21 +36,17 @@ lootsplosion:
|
||||
offset: .2
|
||||
height: .6
|
||||
|
||||
# settings for the default action bar
|
||||
# Settings for the default action bar
|
||||
action-bar:
|
||||
# Whether or not to use the default 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)
|
||||
# The decimal format for stats (not including stat formats in stats.yml)
|
||||
decimal: "0.#"
|
||||
# The amount of ticks before updating the info
|
||||
ticks-to-update: 5
|
||||
# how to display the data.
|
||||
# How to display the data.
|
||||
format: "&c❤ {health}/{max_health} &f| &9⭐ {mana}/{max_mana} &f| &7⛨ {armor}"
|
||||
|
||||
# Whether or not to display the mana bar when regenerating mana
|
||||
display:
|
||||
mana: true
|
||||
|
||||
party:
|
||||
|
||||
# Edit party buffs here. You may
|
||||
|
Loading…
Reference in New Issue
Block a user