Improved mana display options and loading error messages

This commit is contained in:
Indyuce 2020-04-18 12:28:09 +02:00
parent 61d297412a
commit c27d138c0a
17 changed files with 116 additions and 82 deletions

View File

@ -247,7 +247,6 @@ public class MMOCore extends JavaPlugin {
for (LootChest chest : new HashSet<>(lootChests.getActive()))
if (chest.shouldExpire())
chest.unregister(false);
}
}.runTaskTimer(this, 5 * 60 * 20, 5 * 60 * 20);

View File

@ -6,6 +6,7 @@ public class AltChar {
public static final String star = "";
public static final String rightArrow = "";
public static final String fourEdgedClub = "";
public static final String manaStar = "";
public static final String club = "";
public static final String diamond = "";

View File

@ -34,6 +34,7 @@ public class PlayerActionBar extends BukkitRunnable {
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_icon}", data.getProfess().getManaDisplay().getIcon())
.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()))

View File

@ -23,7 +23,6 @@ import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.AltChar;
import net.Indyuce.mmocore.api.experience.source.type.ExperienceSource;
import net.Indyuce.mmocore.api.load.MMOLoadException;
import net.Indyuce.mmocore.api.load.PostLoadObject;
@ -65,29 +64,26 @@ public class PlayerClass extends PostLoadObject {
this.id = id.toUpperCase().replace("-", "_").replace(" ", "_");
name = ChatColor.translateAlternateColorCodes('&', config.getString("display.name"));
icon = MMOCoreUtils.readIcon(config.getString("display.item"));
icon = MMOCoreUtils.readIcon(config.getString("display.item", "BARRIER"));
if (config.contains("display.texture"))
if (icon.getType() == VersionMaterial.PLAYER_HEAD.toMaterial()) {
if (config.contains("display.texture") && icon.getType() == VersionMaterial.PLAYER_HEAD.toMaterial())
try {
ItemMeta meta = icon.getItemMeta();
try {
Field profileField = meta.getClass().getDeclaredField("profile");
profileField.setAccessible(true);
GameProfile gp = new GameProfile(UUID.randomUUID(), null);
gp.getProperties().put("textures", new Property("textures", config.getString("display.texture")));
profileField.set(meta, gp);
} catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException exception) {
MMOCore.log(Level.WARNING, "[PlayerClasses:" + id + "] Could not apply playerhead texture: " + exception.getMessage());
}
Field profileField = meta.getClass().getDeclaredField("profile");
profileField.setAccessible(true);
GameProfile gp = new GameProfile(UUID.randomUUID(), null);
gp.getProperties().put("textures", new Property("textures", config.getString("display.texture")));
profileField.set(meta, gp);
icon.setItemMeta(meta);
} else
MMOCore.log(Level.WARNING, "[PlayerClasses:" + id + "] Could not add player head texture. The item is not a playerhead!");
} catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException exception) {
throw new IllegalArgumentException("Could not apply playerhead texture: " + exception.getMessage());
}
for (String string : config.getStringList("display.lore"))
description.add(ChatColor.GRAY + ChatColor.translateAlternateColorCodes('&', string));
for (String string : config.getStringList("display.attribute-lore"))
attrDescription.add(ChatColor.GRAY + ChatColor.translateAlternateColorCodes('&', string));
manaDisplay = new ManaDisplayOptions(config.getConfigurationSection("mana"));
manaDisplay = config.contains("mana") ? new ManaDisplayOptions(config.getConfigurationSection("mana")) : ManaDisplayOptions.DEFAULT;
maxLevel = config.getInt("max-level");
displayOrder = config.getInt("display.order");
@ -171,7 +167,7 @@ public class PlayerClass extends PostLoadObject {
this.id = id;
this.name = name;
manaDisplay = new ManaDisplayOptions(ChatColor.BLUE, "Mana", AltChar.listSquare.charAt(0));
manaDisplay = ManaDisplayOptions.DEFAULT;
maxLevel = 0;
displayOrder = 0;
expCurve = ExpCurve.DEFAULT;
@ -189,8 +185,13 @@ public class PlayerClass extends PostLoadObject {
protected void whenPostLoaded(FileConfiguration config) {
if (config.contains("subclasses"))
for (String key : config.getConfigurationSection("subclasses").getKeys(false))
subclasses.add(new Subclass(MMOCore.plugin.classManager.get(key.toUpperCase().replace("-", "_").replace(" ", "_")),
config.getInt("subclasses." + key)));
try {
subclasses.add(new Subclass(MMOCore.plugin.classManager.getOrThrow(key.toUpperCase().replace("-", "_").replace(" ", "_")),
config.getInt("subclasses." + key)));
} catch (IllegalArgumentException exception) {
MMOCore.plugin.getLogger().log(Level.WARNING,
"Could not load subclass '" + key + "' from class '" + getId() + "': " + exception.getMessage());
}
}
public String getId() {

View File

@ -4,46 +4,68 @@ import org.apache.commons.lang.Validate;
import org.bukkit.ChatColor;
import org.bukkit.configuration.ConfigurationSection;
import net.Indyuce.mmocore.api.AltChar;
public class ManaDisplayOptions {
private final ChatColor color;
private final String name;
private final ChatColor full, half, empty;
private final String name, icon;
private final char barCharacter;
public static final ManaDisplayOptions DEFAULT = new ManaDisplayOptions(ChatColor.AQUA, ChatColor.BLUE, ChatColor.WHITE, "Mana",
AltChar.listSquare.charAt(0), ChatColor.BLUE + AltChar.manaStar);
public ManaDisplayOptions(ConfigurationSection config) {
Validate.notNull(config, "Could not load mana display options");
name = config.getString("name");
Validate.notNull(name, "Could not load mana name");
String format = config.getString("color").toUpperCase().replace("-", "_").replace(" ", "_");
Validate.notNull(format, "Could not load mana color");
color = ChatColor.valueOf(format);
Validate.notNull(config.getConfigurationSection("color"), "Could not find mana color config");
full = ChatColor.valueOf(config.getString("color.full", "NO_INPUT").toUpperCase().replace("-", "_").replace(" ", "_"));
half = ChatColor.valueOf(config.getString("color.half", "NO_INPUT").toUpperCase().replace("-", "_").replace(" ", "_"));
empty = ChatColor.valueOf(config.getString("color.empty", "NO_INPUT").toUpperCase().replace("-", "_").replace(" ", "_"));
format = config.getString("char");
Validate.notNull(format, "Could not load mana bar character");
String format = config.getString("char", "");
Validate.notEmpty(format, "Could not load mana bar character");
barCharacter = format.charAt(0);
icon = ChatColor.translateAlternateColorCodes('&', config.getString("icon", ""));
Validate.notEmpty(format, "Could not load mana action bar icon");
}
public ManaDisplayOptions(ChatColor color, String name, char barCharacter) {
Validate.notNull(color, "Color cannot be null");
public ManaDisplayOptions(ChatColor full, ChatColor half, ChatColor empty, String name, char barCharacter, String icon) {
Validate.notNull(full, "Color cannot be null");
Validate.notNull(half, "Color cannot be null");
Validate.notNull(empty, "Color cannot be null");
Validate.notNull(name, "Name cannot be null");
Validate.notNull(barCharacter, "Bar character cannot be null");
this.color = color;
this.full = full;
this.half = half;
this.empty = empty;
this.name = name;
this.barCharacter = barCharacter;
this.icon = icon;
}
public String getName() {
return name;
}
/*
* used to display mana on the action bar
*/
public String getIcon() {
return icon;
}
public String generateBar(double mana, double max) {
String format = "";
double ratio = 20 * mana / max;
for (double j = 1; j < 20; j++)
format += "" + (ratio >= j ? color : ChatColor.WHITE) + barCharacter;
format += "" + (ratio >= j ? full : ratio >= j - .5 ? half : empty) + barCharacter;
return format;
}
}

View File

@ -5,7 +5,6 @@ import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
@ -56,8 +55,6 @@ public class MMOCoreUtils {
}
public static ItemStack readIcon(String string) throws IllegalArgumentException {
Validate.notNull(string, "String cannot be null");
String[] split = string.split("\\:");
Material material = Material.valueOf(split[0].toUpperCase().replace("-", "_").replace(" ", "_"));
return split.length > 1 ? MMOLib.plugin.getVersion().getWrapper().textureItem(material, Integer.parseInt(split[1])) : new ItemStack(material);

View File

@ -8,8 +8,8 @@ import org.bukkit.entity.Player;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.AltChar;
import net.Indyuce.mmocore.api.experience.Profession;
import net.Indyuce.mmocore.api.experience.PlayerProfessions;
import net.Indyuce.mmocore.api.experience.Profession;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.player.stats.StatType;
import net.Indyuce.mmocore.api.quest.PlayerQuests;
@ -58,13 +58,13 @@ public class RPGPlaceholders
PlayerProfessions professions = PlayerData.get(player).getCollectionSkills();
String name = identifier.substring(19).replace(" ", "-").replace("_", "-").toLowerCase();
Profession profession = MMOCore.plugin.professionManager.get(name);
double current = professions.getExperience(profession),
next = professions.getLevelUpExperience(profession);
double current = professions.getExperience(profession), next = professions.getLevelUpExperience(profession);
return MMOCore.plugin.configManager.decimal.format(current / next * 100);
}
else if (identifier.startsWith("profession_"))
return "" + PlayerData.get(player).getCollectionSkills().getLevel(identifier.substring(11).replace(" ", "-").replace("_", "-").toLowerCase());
return "" + PlayerData.get(player).getCollectionSkills()
.getLevel(identifier.substring(11).replace(" ", "-").replace("_", "-").toLowerCase());
else if (identifier.equals("max_health"))
return StatType.MAX_HEALTH.format(player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue());
@ -73,7 +73,7 @@ public class RPGPlaceholders
return "" + PlayerData.get(player).getExperience();
else if (identifier.equals("next_level"))
return "" +PlayerData.get(player).getLevelUpExperience();
return "" + PlayerData.get(player).getLevelUpExperience();
else if (identifier.equals("class_points"))
return "" + PlayerData.get(player).getClassPoints();
@ -88,18 +88,15 @@ public class RPGPlaceholders
return "" + PlayerData.get(player).getAttributeReallocationPoints();
else if (identifier.startsWith("attribute_"))
return String.valueOf(PlayerData.get(player).getAttributes().getAttribute(MMOCore.plugin.attributeManager.get(identifier.substring(10).toLowerCase().replace("_", "-"))));
return String.valueOf(PlayerData.get(player).getAttributes()
.getAttribute(MMOCore.plugin.attributeManager.get(identifier.substring(10).toLowerCase().replace("_", "-"))));
else if (identifier.equals("mana"))
return MMOCore.plugin.configManager.decimal.format(PlayerData.get(player).getMana());
else if (identifier.equals("mana_bar")) {
String format = "";
PlayerData data = PlayerData.get(player);
double ratio = 20 * data.getMana() / data.getStats().getStat(StatType.MAX_MANA);
for (double j = 1; j < 20; j++)
format += (ratio >= j ? MMOCore.plugin.configManager.manaFull : ratio >= j - .5 ? MMOCore.plugin.configManager.manaHalf : MMOCore.plugin.configManager.manaEmpty) + AltChar.listSquare;
return format;
return data.getProfess().getManaDisplay().generateBar(data.getMana(), data.getStats().getStat(StatType.MAX_MANA));
}
else if (identifier.equals("stamina"))
@ -110,7 +107,9 @@ public class RPGPlaceholders
PlayerData data = PlayerData.get(player);
double ratio = 20 * data.getStamina() / data.getStats().getStat(StatType.MAX_STAMINA);
for (double j = 1; j < 20; j++)
format += (ratio >= j ? MMOCore.plugin.configManager.staminaFull : ratio >= j - .5 ? MMOCore.plugin.configManager.staminaHalf : MMOCore.plugin.configManager.staminaEmpty) + AltChar.listSquare;
format += (ratio >= j ? MMOCore.plugin.configManager.staminaFull
: ratio >= j - .5 ? MMOCore.plugin.configManager.staminaHalf : MMOCore.plugin.configManager.staminaEmpty)
+ AltChar.listSquare;
return format;
}

View File

@ -8,6 +8,7 @@ import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.configuration.file.YamlConfiguration;
@ -60,7 +61,12 @@ public class ClassManager extends MMOManager {
}
public PlayerClass get(String id) {
return map.containsKey(id) ? map.get(id) : null;
return map.get(id);
}
public PlayerClass getOrThrow(String id) {
Validate.isTrue(map.containsKey(id), "Could not find class with ID '" + id + "'");
return map.get(id);
}
public Collection<PlayerClass> getAll() {

View File

@ -26,7 +26,7 @@ public class ConfigManager {
public boolean overrideVanillaExp, hotbarSwap;
public double expPartyBuff, regenPartyBuff;
public String partyChatPrefix;
public ChatColor manaFull, manaHalf, manaEmpty, staminaFull, staminaHalf, staminaEmpty;
public ChatColor staminaFull, staminaHalf, staminaEmpty;
public int combatLogTimer, lootChestExpireTime;
public final DecimalFormatSymbols formatSymbols = new DecimalFormatSymbols();
@ -102,9 +102,6 @@ public class ConfigManager {
combatLogTimer = MMOCore.plugin.getConfig().getInt("combat-log.timer");
lootChestExpireTime = Math.max(MMOCore.plugin.getConfig().getInt("loot-chest-expire-time"), 1) * 1000;
manaFull = getColorOrDefault("mana-whole", ChatColor.BLUE);
manaHalf = getColorOrDefault("mana-half", ChatColor.AQUA);
manaEmpty = getColorOrDefault("mana-empty", ChatColor.WHITE);
staminaFull = getColorOrDefault("stamina-whole", ChatColor.GREEN);
staminaHalf = getColorOrDefault("stamina-half", ChatColor.DARK_GREEN);
staminaEmpty = getColorOrDefault("stamina-empty", ChatColor.WHITE);
@ -163,7 +160,7 @@ public class ConfigManager {
public class SimpleMessage {
private final String message;
SimpleMessage(String message) {
public SimpleMessage(String message) {
this.message = message;
}

View File

@ -51,7 +51,7 @@ action-bar:
ticks-to-update: 5
# How to display the data.
format: "&c❤ {health}/{max_health} &f| &9⭐ {mana}/{max_mana} &f| &7⛨ {armor}"
format: "&c❤ {health}/{max_health} &f| {mana_icon} {mana}/{max_mana} &f| &7⛨ {armor}"
party:

View File

@ -1,9 +1,5 @@
options:
display: false
mana:
char:
color: BLUE
name: 'Mana'
# Display options
display:
name: 'Arcane Mage'
lore:
@ -38,6 +34,11 @@ exp-curve: levels
# Players cannot go further than Lvl 100
max-level: 100
# This class must not display in /class
# becasue it is a subclass of mage
options:
display: false
triggers:
level-up:
- 'command{format="mmocore admin skill-points give %player% 1"}'

View File

@ -1,6 +1,13 @@
# Display options, it's not displayed anywhere so pointless.
# Just need the name for reference and PAPI placeholders.
display:
name: 'Human'
# This is the default class which players have when
# joining the server. They can level it up, but they
# cannot choose this class again after changing their
# class because it is not displayed in /class
options:
default: true
display: false
@ -12,11 +19,6 @@ options:
# Must match an existing exp curve filename from the 'expcurves' folder
exp-curve: levels
mana:
char:
color: BLUE
name: 'Mana'
# Experience sources for main class experience.
main-exp-sources:
- 'killmob{type=ZOMBIE;amount=1-3}'

View File

@ -36,9 +36,21 @@ triggers:
level-up:
- 'command{format="mmocore admin skill-points give %player% 1"}'
# This is the default mana display options, however it is not mandatory
# to have it in your class config file. Other classes do not have this
# section and therefore have the default mana display options.
#
# 'char' is the character used to generate the mana bar as a message
# 'color' are also the colors used to generate the mana bar
# 'icon' is the icon display on the player action bar
# 'name' is basically displayed everywhere
mana:
char:
color: BLUE
icon: '&9⭐'
color:
full: AQUA
half: BLUE
empty: WHITE
name: 'Mana'
cast-particle:

View File

@ -35,11 +35,8 @@ triggers:
level-up:
- 'command{format="mmocore admin skill-points give %player% 1"}'
mana:
char:
color: BLUE
name: 'Mana'
# Particles displayed around the player
# when he enters the casting mode.
cast-particle:
particle: CRIT

View File

@ -33,11 +33,6 @@ exp-curve: levels
# Players cannot go further than Lvl 100
max-level: 100
mana:
char:
color: BLUE
name: 'Mana'
triggers:
level-up:
- 'command{format="mmocore admin skill-points give %player% 1"}'

View File

@ -42,11 +42,6 @@ options:
cast-particle:
particle: SPELL_WITCH
mana:
char:
color: BLUE
name: 'Mana'
skills:
DEEP_WOUND:
level: 1

View File

@ -39,9 +39,18 @@ max-level: 100
# Warrior has rage which he gains while casting spells
# Rage increase its skill damage. Use <mmocore.rage>
# to get the player's rage (MythicMobs formulas)
#
# 'char' is the character used to generate the mana bar as a message
# 'color' are also the colors used to generate the mana bar
# 'icon' is the icon display on the player action bar
# 'name' is basically displayed everywhere
mana:
char:
color: RED
icon: '&4♦'
color:
full: DARK_RED
half: RED
empty: WHITE
name: 'Rage'
# Rage charges when dealing weapon and physical damage.