MMOCore 1.4.1 - The Colorful Update

You can now use hex colors with most things!
The format is '<#xxxxxx>' and it works just like the old '&x' did.
The old format is still supported and sometimes they can even be mixed!

Requires MMOLib 1.2.3 or later
This commit is contained in:
ASangarin 2020-06-27 01:00:04 +02:00
parent ed0c72c8da
commit 4d78a3a245
16 changed files with 75 additions and 61 deletions

Binary file not shown.

View File

@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>net.Indyuce</groupId>
<artifactId>MMOCore</artifactId>
<version>1.4</version>
<version>1.4.1</version>
<description>Offer your players a brand new RPG experience.</description>
<properties>

View File

@ -3,11 +3,11 @@ package net.Indyuce.mmocore.api;
import java.util.Collection;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import net.Indyuce.mmocore.MMOCore;
import net.asangarin.hexcolors.ColorParse;
import net.mmogroup.mmolib.MMOLib;
public class ConfigMessage {
@ -31,14 +31,14 @@ public class ConfigMessage {
}
public void send(CommandSender sender) {
messages.forEach(line -> sender.sendMessage(ChatColor.translateAlternateColorCodes('&', line)));
messages.forEach(line -> sender.sendMessage(new ColorParse('&', line).toChatColor()));
}
public void send(Collection<? extends Player> players) {
players.forEach(player -> messages.forEach(line -> player.sendMessage(ChatColor.translateAlternateColorCodes('&', MMOCore.plugin.placeholderParser.parse(player, line)))));
players.forEach(player -> messages.forEach(line -> player.sendMessage(new ColorParse('&', MMOCore.plugin.placeholderParser.parse(player, line)).toChatColor())));
}
public void sendAsJSon(Player player) {
messages.forEach(line -> MMOLib.plugin.getNMS().sendJson(player, ChatColor.translateAlternateColorCodes('&', line)));
messages.forEach(line -> MMOLib.plugin.getNMS().sendJson(player, new ColorParse('&', line).toChatColor()));
}
}

View File

@ -2,7 +2,6 @@ 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;
@ -10,6 +9,7 @@ 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.asangarin.hexcolors.ColorParse;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
@ -31,7 +31,7 @@ public class PlayerActionBar extends BukkitRunnable {
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)
new ColorParse('&', 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())
@ -45,7 +45,7 @@ public class PlayerActionBar extends BukkitRunnable {
.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())))));
.replace("{name}", data.getPlayer().getDisplayName())).toChatColor())));
}
}
}

View File

@ -7,10 +7,10 @@ import java.util.Set;
import java.util.logging.Level;
import org.apache.commons.lang.Validate;
import org.bukkit.ChatColor;
import org.bukkit.configuration.ConfigurationSection;
import net.Indyuce.mmocore.MMOCore;
import net.asangarin.hexcolors.ColorParse;
import net.mmogroup.mmolib.api.stat.modifier.StatModifier;
public class PlayerAttribute {
@ -48,7 +48,7 @@ public class PlayerAttribute {
}
public String getName() {
return ChatColor.translateAlternateColorCodes('&', name);
return new ColorParse('&', name).toChatColor();
}
public boolean hasMax() {

View File

@ -13,7 +13,6 @@ import java.util.UUID;
import java.util.logging.Level;
import org.apache.commons.lang.Validate;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.Particle;
import org.bukkit.configuration.ConfigurationSection;
@ -38,6 +37,8 @@ import net.Indyuce.mmocore.api.skill.Skill.SkillInfo;
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
import net.Indyuce.mmocore.api.util.math.formula.LinearValue;
import net.Indyuce.mmocore.api.util.math.particle.CastingParticle;
import net.asangarin.hexcolors.ColorParse;
import net.md_5.bungee.api.ChatColor;
import net.mmogroup.mmolib.api.MMOLineConfig;
import net.mmogroup.mmolib.version.VersionMaterial;
@ -64,7 +65,7 @@ public class PlayerClass extends PostLoadObject {
this.id = id.toUpperCase().replace("-", "_").replace(" ", "_");
name = ChatColor.translateAlternateColorCodes('&', config.getString("display.name"));
name = new ColorParse('&', config.getString("display.name")).toChatColor();
icon = MMOCoreUtils.readIcon(config.getString("display.item", "BARRIER"));
if (config.contains("display.texture") && icon.getType() == VersionMaterial.PLAYER_HEAD.toMaterial())
@ -76,20 +77,23 @@ public class PlayerClass extends PostLoadObject {
gp.getProperties().put("textures", new Property("textures", config.getString("display.texture")));
profileField.set(meta, gp);
icon.setItemMeta(meta);
} catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException exception) {
} 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));
description.add(ChatColor.GRAY + new ColorParse('&', string).toChatColor());
for (String string : config.getStringList("display.attribute-lore"))
attrDescription.add(ChatColor.GRAY + ChatColor.translateAlternateColorCodes('&', string));
manaDisplay = config.contains("mana") ? new ManaDisplayOptions(config.getConfigurationSection("mana")) : ManaDisplayOptions.DEFAULT;
attrDescription.add(ChatColor.GRAY + new ColorParse('&', string).toChatColor());
manaDisplay = config.contains("mana") ? new ManaDisplayOptions(config.getConfigurationSection("mana"))
: ManaDisplayOptions.DEFAULT;
maxLevel = config.getInt("max-level");
displayOrder = config.getInt("display.order");
expCurve = config.contains("exp-curve")
? MMOCore.plugin.experience.getOrThrow(config.get("exp-curve").toString().toLowerCase().replace("_", "-").replace(" ", "-"))
? MMOCore.plugin.experience.getOrThrow(
config.get("exp-curve").toString().toLowerCase().replace("_", "-").replace(" ", "-"))
: ExpCurve.DEFAULT;
if (config.contains("attributes"))
@ -98,27 +102,30 @@ public class PlayerClass extends PostLoadObject {
stats.put(StatType.valueOf(key.toUpperCase().replace("-", "_")),
new LinearValue(config.getConfigurationSection("attributes." + key)));
} catch (IllegalArgumentException exception) {
MMOCore.plugin.getLogger().log(Level.WARNING,
"Could not load stat info '" + key + "' from class '" + id + "': " + exception.getMessage());
MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load stat info '" + key + "' from class '"
+ id + "': " + exception.getMessage());
}
if (config.contains("skills"))
for (String key : config.getConfigurationSection("skills").getKeys(false))
try {
Validate.isTrue(MMOCore.plugin.skillManager.has(key), "Could not find skill " + key);
skills.put(key.toUpperCase(), MMOCore.plugin.skillManager.get(key).newSkillInfo(config.getConfigurationSection("skills." + key)));
skills.put(key.toUpperCase(), MMOCore.plugin.skillManager.get(key)
.newSkillInfo(config.getConfigurationSection("skills." + key)));
} catch (IllegalArgumentException exception) {
MMOCore.plugin.getLogger().log(Level.WARNING,
"Could not load skill info '" + key + "' from class '" + id + "': " + exception.getMessage());
MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load skill info '" + key + "' from class '"
+ id + "': " + exception.getMessage());
}
castParticle = config.contains("cast-particle") ? new CastingParticle(config.getConfigurationSection("cast-particle"))
castParticle = config.contains("cast-particle")
? new CastingParticle(config.getConfigurationSection("cast-particle"))
: new CastingParticle(Particle.SPELL_INSTANT);
if (config.contains("options"))
for (String key : config.getConfigurationSection("options").getKeys(false))
try {
setOption(ClassOption.valueOf(key.toUpperCase().replace("-", "_").replace(" ", "_")), config.getBoolean("options." + key));
setOption(ClassOption.valueOf(key.toUpperCase().replace("-", "_").replace(" ", "_")),
config.getBoolean("options." + key));
} catch (IllegalArgumentException exception) {
MMOCore.plugin.getLogger().log(Level.WARNING,
"Could not load option '" + key + "' from class '" + key + "': " + exception.getMessage());
@ -127,12 +134,13 @@ public class PlayerClass extends PostLoadObject {
if (config.contains("main-exp-sources"))
for (String key : config.getStringList("main-exp-sources"))
try {
ExperienceSource<?> source = MMOCore.plugin.loadManager.loadExperienceSource(new MMOLineConfig(key), null);
ExperienceSource<?> source = MMOCore.plugin.loadManager.loadExperienceSource(new MMOLineConfig(key),
null);
source.setClass(this);
MMOCore.plugin.professionManager.registerExpSource(source);
} catch (IllegalArgumentException exception) {
MMOCore.plugin.getLogger().log(Level.WARNING,
"Could not load exp source '" + key + "' from class '" + id + "': " + exception.getMessage());
MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load exp source '" + key + "' from class '"
+ id + "': " + exception.getMessage());
}
if (config.contains("triggers"))
@ -146,17 +154,17 @@ public class PlayerClass extends PostLoadObject {
}
/*
* must make sure all the resourceHandlers are registered when the
* placer class is initialized.
* must make sure all the resourceHandlers are registered when the placer class
* is initialized.
*/
for (PlayerResource resource : PlayerResource.values()) {
if (config.isConfigurationSection("resource." + resource.name().toLowerCase()))
try {
resourceHandlers.put(resource,
new ResourceHandler(resource, config.getConfigurationSection("resource." + resource.name().toLowerCase())));
resourceHandlers.put(resource, new ResourceHandler(resource,
config.getConfigurationSection("resource." + resource.name().toLowerCase())));
} catch (IllegalArgumentException exception) {
MMOCore.log(Level.WARNING, "[PlayerClasses:" + id + "] Could not load special resource regen for " + resource.name() + ": "
+ exception.getMessage());
MMOCore.log(Level.WARNING, "[PlayerClasses:" + id + "] Could not load special resource regen for "
+ resource.name() + ": " + exception.getMessage());
resourceHandlers.put(resource, new ResourceHandler(resource));
}
else
@ -191,11 +199,13 @@ public class PlayerClass extends PostLoadObject {
if (config.contains("subclasses"))
for (String key : config.getConfigurationSection("subclasses").getKeys(false))
try {
subclasses.add(new Subclass(MMOCore.plugin.classManager.getOrThrow(key.toUpperCase().replace("-", "_").replace(" ", "_")),
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());
MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load subclass '" + key + "' from class '"
+ getId() + "': " + exception.getMessage());
}
}

View File

@ -1,9 +1,10 @@
package net.Indyuce.mmocore.api.player.profess.resource;
import org.apache.commons.lang.Validate;
import org.bukkit.ChatColor;
import org.bukkit.configuration.ConfigurationSection;
import net.asangarin.hexcolors.ColorParse;
import net.md_5.bungee.api.ChatColor;
import net.mmogroup.mmolib.api.util.AltChar;
public class ManaDisplayOptions {
@ -21,15 +22,15 @@ public class ManaDisplayOptions {
Validate.notNull(name, "Could not load mana name");
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(" ", "_"));
full = ColorParse.getColor(config.getString("color.full", "NO_INPUT"));
half = ColorParse.getColor(config.getString("color.half", "NO_INPUT"));
empty = ColorParse.getColor(config.getString("color.empty", "NO_INPUT"));
String format = config.getString("char", "");
Validate.notEmpty(format, "Could not load mana bar character");
barCharacter = format.charAt(0);
icon = ChatColor.translateAlternateColorCodes('&', config.getString("icon", ""));
icon = new ColorParse('&', config.getString("icon", "")).toChatColor();
Validate.notEmpty(format, "Could not load mana action bar icon");
}

View File

@ -1,9 +1,8 @@
package net.Indyuce.mmocore.api.quest;
import org.bukkit.ChatColor;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.quest.objective.Objective;
import net.asangarin.hexcolors.ColorParse;
public class QuestProgress {
private final Quest quest;
@ -65,6 +64,6 @@ public class QuestProgress {
}
public String getFormattedLore() {
return ChatColor.translateAlternateColorCodes('&', objectiveProgress.formatLore(objectiveProgress.getObjective().getDefaultLore()));
return new ColorParse('&', objectiveProgress.formatLore(objectiveProgress.getObjective().getDefaultLore())).toChatColor();
}
}

View File

@ -9,7 +9,6 @@ import java.util.UUID;
import java.util.logging.Level;
import org.apache.commons.lang.Validate;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemFlag;
@ -20,6 +19,7 @@ import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import net.Indyuce.mmocore.MMOCore;
import net.asangarin.hexcolors.ColorParse;
import net.mmogroup.mmolib.MMOLib;
import net.mmogroup.mmolib.api.item.ItemTag;
import net.mmogroup.mmolib.api.item.NBTItem;
@ -138,6 +138,6 @@ public class ConfigItem {
for (String placeholder : placeholders.keySet())
if (string.contains("{" + placeholder + "}"))
string = string.replace("{" + placeholder + "}", "" + placeholders.get(placeholder));
return ChatColor.translateAlternateColorCodes('&', string);
return new ColorParse('&', string).toChatColor();
}
}

View File

@ -1,16 +1,17 @@
package net.Indyuce.mmocore.api.util.item;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import net.asangarin.hexcolors.ColorParse;
public class NamedItemStack extends ItemStack {
public NamedItemStack(Material material, String name) {
super(material);
ItemMeta meta = getItemMeta();
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name));
meta.setDisplayName(new ColorParse('&', name).toChatColor());
setItemMeta(meta);
}
}

View File

@ -1,11 +1,12 @@
package net.Indyuce.mmocore.comp.placeholder;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import net.asangarin.hexcolors.ColorParse;
public class DefaultParser implements PlaceholderParser {
@Override
public String parse(OfflinePlayer player, String string) {
return ChatColor.translateAlternateColorCodes('&', string.replace("%player%", player.getName()));
return new ColorParse('&', string.replace("%player%", player.getName())).toChatColor();
}
}

View File

@ -5,7 +5,6 @@ import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.configuration.ConfigurationSection;
@ -24,6 +23,7 @@ import net.Indyuce.mmocore.gui.api.GeneratedInventory;
import net.Indyuce.mmocore.gui.api.item.InventoryItem;
import net.Indyuce.mmocore.gui.api.item.NoPlaceholderItem;
import net.Indyuce.mmocore.manager.InventoryManager;
import net.asangarin.hexcolors.ColorParse;
import net.mmogroup.mmolib.api.item.ItemTag;
import net.mmogroup.mmolib.api.item.NBTItem;
@ -68,7 +68,7 @@ public class ClassSelect extends EditableInventory {
ItemMeta meta = item.getItemMeta();
if (hideFlags())
meta.addItemFlags(ItemFlag.values());
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name).replace("{name}", profess.getName()));
meta.setDisplayName(new ColorParse('&', name).toChatColor().replace("{name}", profess.getName()));
List<String> lore = new ArrayList<>(this.lore);
int index = lore.indexOf("{lore}");

View File

@ -27,6 +27,7 @@ import net.Indyuce.mmocore.gui.api.item.InventoryItem;
import net.Indyuce.mmocore.gui.api.item.InventoryPlaceholderItem;
import net.Indyuce.mmocore.gui.api.item.NoPlaceholderItem;
import net.Indyuce.mmocore.gui.api.item.Placeholders;
import net.asangarin.hexcolors.ColorParse;
import net.mmogroup.mmolib.api.item.ItemTag;
import net.mmogroup.mmolib.api.item.NBTItem;
@ -70,7 +71,7 @@ public class SkillList extends EditableInventory {
if (function.equals("slot"))
return new InventoryPlaceholderItem(config) {
private final String none = ChatColor.translateAlternateColorCodes('&', config.getString("no-skill"));
private final String none = new ColorParse('&', config.getString("no-skill")).toChatColor();
private final Material emptyMaterial = Material
.valueOf(config.getString("empty-item").toUpperCase().replace("-", "_").replace(" ", "_"));
@ -169,12 +170,12 @@ public class SkillList extends EditableInventory {
lore.add(index + j, skillLore.get(j));
for (int j = 0; j < lore.size(); j++)
lore.set(j, ChatColor.GRAY + ChatColor.translateAlternateColorCodes('&', lore.get(j)));
lore.set(j, ChatColor.GRAY + new ColorParse('&', lore.get(j)).toChatColor());
ItemStack item = cloneItem();
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', getName().replace("{skill}", skill.getSkill().getName())
.replace("{roman}", MMOCoreUtils.intToRoman(skillLevel)).replace("{level}", "" + skillLevel)));
meta.setDisplayName(new ColorParse('&', getName().replace("{skill}", skill.getSkill().getName())
.replace("{roman}", MMOCoreUtils.intToRoman(skillLevel)).replace("{level}", "" + skillLevel)).toChatColor());
meta.addItemFlags(ItemFlag.values());
meta.setLore(lore);
item.setItemMeta(meta);

View File

@ -4,7 +4,6 @@ import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import org.bukkit.ChatColor;
import org.bukkit.Sound;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.event.inventory.InventoryClickEvent;
@ -21,6 +20,7 @@ import net.Indyuce.mmocore.gui.api.GeneratedInventory;
import net.Indyuce.mmocore.gui.api.item.InventoryItem;
import net.Indyuce.mmocore.gui.api.item.NoPlaceholderItem;
import net.Indyuce.mmocore.manager.InventoryManager;
import net.asangarin.hexcolors.ColorParse;
import net.mmogroup.mmolib.api.item.ItemTag;
import net.mmogroup.mmolib.api.item.NBTItem;
@ -65,7 +65,7 @@ public class SubclassSelect extends EditableInventory {
ItemStack item = profess.getIcon();
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name).replace("{name}", profess.getName()));
meta.setDisplayName(new ColorParse('&', name).toChatColor().replace("{name}", profess.getName()));
List<String> lore = new ArrayList<>(this.lore);
int index = lore.indexOf("{lore}");

View File

@ -4,13 +4,13 @@ import java.util.ArrayList;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.gui.api.item.InventoryItem;
import net.Indyuce.mmocore.gui.api.item.TriggerItem;
import net.asangarin.hexcolors.ColorParse;
public abstract class GeneratedInventory extends PluginInventory {
private final EditableInventory editable;
@ -54,7 +54,7 @@ public abstract class GeneratedInventory extends PluginInventory {
@Override
public Inventory getInventory() {
Inventory inv = Bukkit.createInventory(this, editable.getSlots(), ChatColor.translateAlternateColorCodes('&', calculateName()));
Inventory inv = Bukkit.createInventory(this, editable.getSlots(), new ColorParse('&', calculateName()).toChatColor());
for (InventoryItem item : editable.getItems())
if (item.canDisplay(this))

View File

@ -20,6 +20,7 @@ import net.Indyuce.mmocore.api.util.input.AnvilGUI;
import net.Indyuce.mmocore.api.util.input.ChatInput;
import net.Indyuce.mmocore.api.util.input.PlayerInput;
import net.Indyuce.mmocore.api.util.input.PlayerInput.InputType;
import net.asangarin.hexcolors.ColorParse;
public class ConfigManager {
@ -155,7 +156,7 @@ public class ConfigManager {
String format = messages.getString(key, "");
for (int j = 0; j < placeholders.length - 1; j += 2)
format = format.replace("{" + placeholders[j] + "}", placeholders[j + 1]);
return new SimpleMessage(ChatColor.translateAlternateColorCodes('&', format));
return new SimpleMessage(new ColorParse('&', format).toChatColor());
}
public class SimpleMessage {