forked from Upstream/mmocore
Added Stat placeholders
%mmocore_stat_STATNAME% %mmocore_formatted_stat_STATNAME%
This commit is contained in:
commit
c9c9b905fa
@ -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;
|
||||
@ -128,6 +122,7 @@ public class MMOCore extends JavaPlugin {
|
||||
public ServerVersion version;
|
||||
public InventoryManager inventoryManager;
|
||||
public RegionHandler regionHandler;
|
||||
public PlayerActionBar actionBarManager ;
|
||||
|
||||
/*
|
||||
* professions
|
||||
@ -140,7 +135,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;
|
||||
@ -261,29 +255,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.
|
||||
@ -439,15 +412,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
|
||||
|
@ -7,11 +7,10 @@ import net.Indyuce.mmocore.api.load.MMOLineConfig;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
|
||||
public abstract class Trigger {
|
||||
private long delay;
|
||||
private final long delay;
|
||||
|
||||
public Trigger(MMOLineConfig config) {
|
||||
if (config.contains("delay"))
|
||||
delay = (long) (config.getDouble("delay") * 20);
|
||||
delay = config.contains("delay") ? (long) (config.getDouble("delay") * 20) : 0;
|
||||
}
|
||||
|
||||
public boolean hasDelay() {
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -144,6 +144,11 @@ public class RPGPlaceholders extends PlaceholderExpansion {
|
||||
return data.hasCurrent() ? data.getCurrent().getFormattedLore() : "None";
|
||||
}
|
||||
|
||||
else if (identifier.startsWith("stat_"))
|
||||
return StatType.valueOf(identifier.substring(5).toUpperCase()) != null ? "" + PlayerData.get(player).getStats().getStat(StatType.valueOf(identifier.substring(5).toUpperCase())) : "Invalid stat";
|
||||
else if (identifier.startsWith("formatted_stat_"))
|
||||
return StatType.valueOf(identifier.substring(5).toUpperCase()) != null ? "" + StatType.valueOf(identifier.substring(5).toUpperCase()).format(PlayerData.get(player).getStats().getStat(StatType.valueOf(identifier.substring(5).toUpperCase()))) : "Invalid stat";
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,6 @@ import org.bukkit.metadata.FixedMetadataValue;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.event.CustomBlockMineEvent;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.api.quest.trigger.ExperienceTrigger;
|
||||
import net.Indyuce.mmocore.manager.CustomBlockManager.BlockInfo;
|
||||
import net.Indyuce.mmocore.manager.RestrictionManager.BlockPermissions;
|
||||
|
||||
@ -81,15 +80,11 @@ public class BlockListener implements Listener {
|
||||
* apply triggers, add experience info to the event so the other
|
||||
* events can give exp to other TOOLS and display HOLOGRAMS
|
||||
*/
|
||||
if (info.hasTriggers()) {
|
||||
if (info.hasTriggers() && !block.hasMetadata("player_placed")) {
|
||||
PlayerData playerData = PlayerData.get(player);
|
||||
info.getTriggers().forEach(trigger -> {
|
||||
if (!block.hasMetadata("player_placed") && trigger instanceof ExperienceTrigger)
|
||||
trigger.apply(playerData);
|
||||
});
|
||||
info.getTriggers().forEach(trigger -> trigger.apply(playerData));
|
||||
if (!block.hasMetadata("player_placed") && info.hasExperience() && MMOCore.plugin.hasHolograms())
|
||||
MMOCore.plugin.hologramSupport.displayIndicator(block.getLocation().add(.5, 1.5, .5),
|
||||
MMOCore.plugin.configManager.getSimpleMessage("exp-hologram", "exp", "" + called.getGainedExperience().getValue()).message(), player);
|
||||
MMOCore.plugin.hologramSupport.displayIndicator(block.getLocation().add(.5, 1.5, .5), MMOCore.plugin.configManager.getSimpleMessage("exp-hologram", "exp", "" + called.getGainedExperience().getValue()).message(), player);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -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
|
||||
|
@ -22,7 +22,7 @@ on-mine:
|
||||
- 'exp{profession=mining;amount=32}'
|
||||
|
||||
diamond:
|
||||
#the material you need to mine
|
||||
# The material you need to mine
|
||||
material: DIAMOND_ORE
|
||||
|
||||
# Refer to drop-tables.yml
|
||||
|
Loading…
Reference in New Issue
Block a user