Fixed empty messages sent to chat/action bar

This commit is contained in:
Jules 2023-11-25 15:23:34 +01:00
parent c211c05a67
commit 36b5be13be
6 changed files with 21 additions and 6 deletions

View File

@ -22,10 +22,14 @@ public class ConfigMessage {
private ConfigMessage(@NotNull String key) {
this.key = key;
// Initialize message list
final Object obj = MMOCore.plugin.configManager.getMessageObject(key);
if (obj == null) lines.add("<message_not_found:'" + key + "'>");
else if (obj instanceof List<?>) lines.addAll((List<String>) obj);
else lines.add(obj.toString());
else {
final String tostr = obj.toString();
if (!tostr.isEmpty()) lines.add(tostr);
}
// Does message include placeholders
boolean hasPlaceholders = false;
@ -106,7 +110,7 @@ public class ConfigMessage {
final String rawMessage = format(player, messageFormat);
final PlayerData playerData = PlayerData.has(player) ? PlayerData.get(player) : null;
// Handle special case with player data+action bar
// Handle special case with player data + action bar
if (playerData != null && playerData.isOnline() && actionbar) {
playerData.displayActionBar(rawMessage, raw);
return;

View File

@ -24,6 +24,7 @@ public class SoundObject {
private final float volume;
private final float pitch;
@Deprecated
public SoundObject(String input) {
String[] split = input.split(",");
@ -43,6 +44,7 @@ public class SoundObject {
pitch = split.length > 2 ? Float.parseFloat(split[2]) : 1;
}
@Deprecated
public SoundObject(ConfigurationSection config) {
String input = config.getString("sound");
@ -65,32 +67,39 @@ public class SoundObject {
* @return If this object is custom a custom sound, potentially
* from a resource pack
*/
@Deprecated
public boolean isCustom() {
return sound == null;
}
@Nullable
@Deprecated
public Sound getSound() {
return sound;
}
@Nullable
@Deprecated
public String getKey() {
return key;
}
@Deprecated
public float getVolume() {
return volume;
}
@Deprecated
public float getPitch() {
return pitch;
}
@Deprecated
public void playTo(Player player) {
playTo(player, volume, pitch);
}
@Deprecated
public void playTo(Player player, float volume, float pitch) {
if (isCustom())
player.playSound(player.getLocation(), key, volume, pitch);
@ -98,10 +107,12 @@ public class SoundObject {
player.playSound(player.getLocation(), sound, volume, pitch);
}
@Deprecated
public void playAt(Location loc) {
playAt(loc, volume, pitch);
}
@Deprecated
public void playAt(Location loc, float volume, float pitch) {
if (isCustom())
loc.getWorld().playSound(loc, key, volume, pitch);

View File

@ -153,7 +153,7 @@ public class ConfigManager {
skillTreeScrollStepY = config.getInt("skill-tree-scroll-step-y", 1);
// Resources
staminaFull = getColorOrDefault("stamina-whole", ChatColor.GREEN);
staminaHalf = getColorOrDefault("stamina-half", ChatColor.DARK_GREEN);
staminaHalf = getColorOrDefault("stamina-half", ChatColor.DARK_GRAY);
staminaEmpty = getColorOrDefault("stamina-empty", ChatColor.WHITE);
passiveSkillNeedBound = MMOCore.plugin.getConfig().getBoolean("passive-skill-need-bound");

View File

@ -1,9 +1,9 @@
package net.Indyuce.mmocore.manager;
import io.lumine.mythic.lib.util.SoundObject;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.ConfigFile;
import net.Indyuce.mmocore.api.SoundEvent;
import net.Indyuce.mmocore.api.SoundObject;
import org.bukkit.configuration.file.FileConfiguration;
import org.jetbrains.annotations.NotNull;

View File

@ -6,8 +6,8 @@ import io.lumine.mythic.lib.api.player.EquipmentSlot;
import io.lumine.mythic.lib.player.PlayerMetadata;
import io.lumine.mythic.lib.skill.trigger.TriggerMetadata;
import io.lumine.mythic.lib.skill.trigger.TriggerType;
import io.lumine.mythic.lib.util.SoundObject;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.SoundObject;
import net.Indyuce.mmocore.api.event.PlayerKeyPressEvent;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.gui.api.item.Placeholders;

View File

@ -5,8 +5,8 @@ import io.lumine.mythic.lib.UtilityMethods;
import io.lumine.mythic.lib.api.player.EquipmentSlot;
import io.lumine.mythic.lib.player.PlayerMetadata;
import io.lumine.mythic.lib.skill.trigger.TriggerMetadata;
import io.lumine.mythic.lib.util.SoundObject;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.SoundObject;
import net.Indyuce.mmocore.api.event.PlayerKeyPressEvent;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.skill.ClassSkill;