diff --git a/DeathMessagesLegacy/src/main/java/dev/mrshawn/deathmessages/listeners/EntityDeath.java b/DeathMessagesLegacy/src/main/java/dev/mrshawn/deathmessages/listeners/EntityDeath.java index e306468..793f203 100644 --- a/DeathMessagesLegacy/src/main/java/dev/mrshawn/deathmessages/listeners/EntityDeath.java +++ b/DeathMessagesLegacy/src/main/java/dev/mrshawn/deathmessages/listeners/EntityDeath.java @@ -9,6 +9,7 @@ import dev.mrshawn.deathmessages.enums.MessageType; import dev.mrshawn.deathmessages.enums.MobType; import dev.mrshawn.deathmessages.utils.Assets; +import dev.mrshawn.deathmessages.utils.ComponentUtil; import dev.mrshawn.deathmessages.utils.EntityUtil; import dev.mrshawn.deathmessages.utils.Util; import net.kyori.adventure.text.TextComponent; @@ -48,18 +49,20 @@ void onEntityDeath(EntityDeathEvent e) { if (!(pm.getLastEntityDamager() instanceof LivingEntity) || pm.getLastEntityDamager() == e.getEntity()) { TextComponent[] naturalDeath = Assets.playerNatureDeathMessage(pm, player); - TextComponent oldNaturalDeath = naturalDeath[0] != null ? naturalDeath[0].append(naturalDeath[1]) : naturalDeath[1]; // Dreeam TODO: Remove in 1.4.21 - - BroadcastDeathMessageEvent event = new BroadcastDeathMessageEvent( - player, - null, - MessageType.NATURAL, - oldNaturalDeath, - naturalDeath, - Util.getBroadcastWorlds(player), - false - ); - Bukkit.getPluginManager().callEvent(event); + TextComponent oldNaturalDeath = naturalDeath[0].append(naturalDeath[1]); // Dreeam TODO: Remove in 1.4.21 + + if (!ComponentUtil.isMessageEmpty(naturalDeath)) { + BroadcastDeathMessageEvent event = new BroadcastDeathMessageEvent( + player, + null, + MessageType.NATURAL, + oldNaturalDeath, + naturalDeath, + Util.getBroadcastWorlds(player), + false + ); + Bukkit.getPluginManager().callEvent(event); + } } else { // Killed by mob Entity ent = pm.getLastEntityDamager(); @@ -88,32 +91,21 @@ void onEntityDeath(EntityDeathEvent e) { } TextComponent[] playerDeath = Assets.playerDeathMessage(pm, gangKill); - TextComponent oldPlayerDeath = playerDeath[0] != null ? playerDeath[0].append(playerDeath[1]) : playerDeath[1]; // Dreeam TODO: Remove in 1.4.21 + TextComponent oldPlayerDeath = playerDeath[0].append(playerDeath[1]); // Dreeam TODO: Remove in 1.4.21 - if (ent instanceof Player) { + if (!ComponentUtil.isMessageEmpty(playerDeath)) { + MessageType messageType = ent instanceof Player ? MessageType.PLAYER : MessageType.MOB; BroadcastDeathMessageEvent event = new BroadcastDeathMessageEvent( player, (LivingEntity) pm.getLastEntityDamager(), - MessageType.PLAYER, + messageType, oldPlayerDeath, playerDeath, Util.getBroadcastWorlds(player), gangKill ); Bukkit.getPluginManager().callEvent(event); - return; } - - BroadcastDeathMessageEvent event = new BroadcastDeathMessageEvent( - player, - (LivingEntity) pm.getLastEntityDamager(), - MessageType.MOB, - oldPlayerDeath, - playerDeath, - Util.getBroadcastWorlds(player), - gangKill - ); - Bukkit.getPluginManager().callEvent(event); } }); @@ -135,17 +127,19 @@ void onEntityDeath(EntityDeathEvent e) { if (damager == null) return; // Entity killed by Entity should not include in DM TextComponent[] entityDeath = Assets.entityDeathMessage(em, mobType); - TextComponent oldEntityDeath = entityDeath[0] != null ? entityDeath[0].append(entityDeath[1]) : entityDeath[1]; // Dreeam TODO: Remove in 1.4.21 - - BroadcastEntityDeathMessageEvent event = new BroadcastEntityDeathMessageEvent( - damager, - e.getEntity(), - MessageType.ENTITY, - oldEntityDeath, - entityDeath, - Util.getBroadcastWorlds(e.getEntity()) - ); - Bukkit.getPluginManager().callEvent(event); + TextComponent oldEntityDeath = entityDeath[0].append(entityDeath[1]); // Dreeam TODO: Remove in 1.4.21 + + if (!ComponentUtil.isMessageEmpty(entityDeath)) { + BroadcastEntityDeathMessageEvent event = new BroadcastEntityDeathMessageEvent( + damager, + e.getEntity(), + MessageType.ENTITY, + oldEntityDeath, + entityDeath, + Util.getBroadcastWorlds(e.getEntity()) + ); + Bukkit.getPluginManager().callEvent(event); + } }); } } diff --git a/DeathMessagesLegacy/src/main/java/dev/mrshawn/deathmessages/listeners/combatlogx/PlayerUntag.java b/DeathMessagesLegacy/src/main/java/dev/mrshawn/deathmessages/listeners/combatlogx/PlayerUntag.java index a91d00b..cf2c6e2 100644 --- a/DeathMessagesLegacy/src/main/java/dev/mrshawn/deathmessages/listeners/combatlogx/PlayerUntag.java +++ b/DeathMessagesLegacy/src/main/java/dev/mrshawn/deathmessages/listeners/combatlogx/PlayerUntag.java @@ -10,6 +10,7 @@ import dev.mrshawn.deathmessages.enums.MessageType; import dev.mrshawn.deathmessages.files.Config; import dev.mrshawn.deathmessages.utils.Assets; +import dev.mrshawn.deathmessages.utils.ComponentUtil; import dev.mrshawn.deathmessages.utils.Util; import net.kyori.adventure.text.TextComponent; import org.bukkit.Bukkit; @@ -66,18 +67,20 @@ public void untagPlayer(PlayerUntagEvent e) { deathMessage[1] = deathMessageBody; - TextComponent oldDeathMessage = deathMessage[0] != null ? deathMessage[0].append(deathMessage[1]) : deathMessage[1]; // Dreeam TODO: Remove in 1.4.21 - - BroadcastDeathMessageEvent event = new BroadcastDeathMessageEvent( - player, - (LivingEntity) e.getPreviousEnemies().get(0), - MessageType.PLAYER, - oldDeathMessage, - deathMessage, - Util.getBroadcastWorlds(player), - gangKill - ); - Bukkit.getPluginManager().callEvent(event); + TextComponent oldDeathMessage = deathMessage[0].append(deathMessage[1]); // Dreeam TODO: Remove in 1.4.21 + + if (!ComponentUtil.isMessageEmpty(deathMessage)) { + BroadcastDeathMessageEvent event = new BroadcastDeathMessageEvent( + player, + (LivingEntity) e.getPreviousEnemies().get(0), + MessageType.PLAYER, + oldDeathMessage, + deathMessage, + Util.getBroadcastWorlds(player), + gangKill + ); + Bukkit.getPluginManager().callEvent(event); + } }); if (!getPlayer.isPresent()) { diff --git a/DeathMessagesLegacy/src/main/java/dev/mrshawn/deathmessages/listeners/customlisteners/BroadcastEntityDeathListener.java b/DeathMessagesLegacy/src/main/java/dev/mrshawn/deathmessages/listeners/customlisteners/BroadcastEntityDeathListener.java index e39898b..f1fd992 100644 --- a/DeathMessagesLegacy/src/main/java/dev/mrshawn/deathmessages/listeners/customlisteners/BroadcastEntityDeathListener.java +++ b/DeathMessagesLegacy/src/main/java/dev/mrshawn/deathmessages/listeners/customlisteners/BroadcastEntityDeathListener.java @@ -28,16 +28,13 @@ public class BroadcastEntityDeathListener implements Listener { @EventHandler public void broadcastListener(BroadcastEntityDeathMessageEvent e) { - if (e.getTextComponents() == ComponentUtil.EMPTY) - return; // Dreeam - in Assets: return null -> return ComponentUtil.EMPTY - final Optional pm = Optional.of(e.getPlayer()); final Entity entity = e.getEntity(); final boolean hasOwner = EntityUtil.hasOwner(entity); final TextComponent[] components = e.getTextComponents(); final TextComponent prefix = components[0]; final TextComponent messageBody = components[1]; - final TextComponent message = prefix != null ? prefix.append(messageBody) : messageBody; + final TextComponent message = prefix.append(messageBody); if (Messages.getInstance().getConfig().getBoolean("Console.Enabled")) { Component rawMessage = Util.convertFromLegacy(Messages.getInstance().getConfig().getString("Console.Message")); diff --git a/DeathMessagesLegacy/src/main/java/dev/mrshawn/deathmessages/listeners/customlisteners/BroadcastPlayerDeathListener.java b/DeathMessagesLegacy/src/main/java/dev/mrshawn/deathmessages/listeners/customlisteners/BroadcastPlayerDeathListener.java index 7a0d851..c015c00 100644 --- a/DeathMessagesLegacy/src/main/java/dev/mrshawn/deathmessages/listeners/customlisteners/BroadcastPlayerDeathListener.java +++ b/DeathMessagesLegacy/src/main/java/dev/mrshawn/deathmessages/listeners/customlisteners/BroadcastPlayerDeathListener.java @@ -28,9 +28,6 @@ public class BroadcastPlayerDeathListener implements Listener { @EventHandler public void broadcastListener(BroadcastDeathMessageEvent e) { - if (e.getTextComponents() == ComponentUtil.EMPTY) - return; // Dreeam - in Assets: return null -> return ComponentUtil.EMPTY - Optional getPlayer = PlayerManager.getPlayer(e.getPlayer()); if (!getPlayer.isPresent()) return; @@ -38,7 +35,7 @@ public void broadcastListener(BroadcastDeathMessageEvent e) { final TextComponent[] components = e.getTextComponents(); final TextComponent prefix = components[0]; final TextComponent messageBody = components[1]; - final TextComponent message = prefix != null ? prefix.append(messageBody) : messageBody; + final TextComponent message = prefix.append(messageBody); if (Messages.getInstance().getConfig().getBoolean("Console.Enabled")) { // Dreeam TODO: maybe just use formatMessage is also ok? diff --git a/DeathMessagesLegacy/src/main/java/dev/mrshawn/deathmessages/listeners/mythicmobs/MobDeath.java b/DeathMessagesLegacy/src/main/java/dev/mrshawn/deathmessages/listeners/mythicmobs/MobDeath.java index e346210..f72beea 100644 --- a/DeathMessagesLegacy/src/main/java/dev/mrshawn/deathmessages/listeners/mythicmobs/MobDeath.java +++ b/DeathMessagesLegacy/src/main/java/dev/mrshawn/deathmessages/listeners/mythicmobs/MobDeath.java @@ -6,6 +6,7 @@ import dev.mrshawn.deathmessages.enums.MessageType; import dev.mrshawn.deathmessages.enums.MobType; import dev.mrshawn.deathmessages.utils.Assets; +import dev.mrshawn.deathmessages.utils.ComponentUtil; import dev.mrshawn.deathmessages.utils.Util; import io.lumine.mythic.bukkit.events.MythicMobDeathEvent; import net.kyori.adventure.text.TextComponent; @@ -36,17 +37,19 @@ public void onMythicMobDeath(MythicMobDeathEvent e) { getEntity.ifPresent(em -> { PlayerManager damager = em.getLastPlayerDamager(); TextComponent[] mythicDeath = Assets.entityDeathMessage(em, MobType.MYTHIC_MOB); - TextComponent oldMythicDeath = mythicDeath[0] != null ? mythicDeath[0].append(mythicDeath[1]) : mythicDeath[1]; // Dreeam TODO: Remove in 1.4.21 - - BroadcastEntityDeathMessageEvent event = new BroadcastEntityDeathMessageEvent( - damager, - e.getEntity(), - MessageType.ENTITY, - oldMythicDeath, - mythicDeath, - Util.getBroadcastWorlds(e.getEntity()) - ); - Bukkit.getPluginManager().callEvent(event); + TextComponent oldMythicDeath = mythicDeath[0].append(mythicDeath[1]); // Dreeam TODO: Remove in 1.4.21 + + if (!ComponentUtil.isMessageEmpty(mythicDeath)) { + BroadcastEntityDeathMessageEvent event = new BroadcastEntityDeathMessageEvent( + damager, + e.getEntity(), + MessageType.ENTITY, + oldMythicDeath, + mythicDeath, + Util.getBroadcastWorlds(e.getEntity()) + ); + Bukkit.getPluginManager().callEvent(event); + } }); } } diff --git a/DeathMessagesLegacy/src/main/java/dev/mrshawn/deathmessages/utils/Assets.java b/DeathMessagesLegacy/src/main/java/dev/mrshawn/deathmessages/utils/Assets.java index d9758ae..34d01cc 100644 --- a/DeathMessagesLegacy/src/main/java/dev/mrshawn/deathmessages/utils/Assets.java +++ b/DeathMessagesLegacy/src/main/java/dev/mrshawn/deathmessages/utils/Assets.java @@ -61,7 +61,7 @@ public class Assets { //private static final CommentedConfiguration config = Settings.getInstance().getConfig(); public static TextComponent[] playerNatureDeathMessage(PlayerManager pm, Player player) { - TextComponent[] components = new TextComponent[2]; + TextComponent[] components = ComponentUtil.empty(); if (Settings.getInstance().getConfig().getBoolean(Config.ADD_PREFIX_TO_ALL_MESSAGES.getPath())) { TextComponent prefix = Util.convertFromLegacy(Messages.getInstance().getConfig().getString("Prefix")); @@ -112,7 +112,7 @@ public static TextComponent[] playerNatureDeathMessage(PlayerManager pm, Player public static TextComponent[] playerDeathMessage(PlayerManager pm, boolean gang) { LivingEntity mob = (LivingEntity) pm.getLastEntityDamager(); - TextComponent[] components = new TextComponent[2]; + TextComponent[] components = ComponentUtil.empty(); if (Settings.getInstance().getConfig().getBoolean(Config.ADD_PREFIX_TO_ALL_MESSAGES.getPath())) { TextComponent prefix = Util.convertFromLegacy(Messages.getInstance().getConfig().getString("Prefix")); @@ -190,17 +190,17 @@ public static TextComponent[] playerDeathMessage(PlayerManager pm, boolean gang) } } - return ComponentUtil.EMPTY; + return ComponentUtil.empty(); } } public static TextComponent[] entityDeathMessage(EntityManager em, MobType mobType) { Optional pm = Optional.ofNullable(em.getLastPlayerDamager()); - if (!pm.isPresent()) return ComponentUtil.EMPTY; + if (!pm.isPresent()) return ComponentUtil.empty(); Player p = pm.get().getPlayer(); - TextComponent[] components = new TextComponent[2]; + TextComponent[] components = ComponentUtil.empty(); if (Settings.getInstance().getConfig().getBoolean(Config.ADD_PREFIX_TO_ALL_MESSAGES.getPath())) { TextComponent prefix = Util.convertFromLegacy(Messages.getInstance().getConfig().getString("Prefix")); @@ -277,7 +277,7 @@ public static TextComponent[] entityDeathMessage(EntityManager em, MobType mobTy } } - return ComponentUtil.EMPTY; + return ComponentUtil.empty(); } } @@ -383,10 +383,13 @@ public static TextComponent getWeapon(boolean gang, PlayerManager pm, LivingEnti final String affiliation = gang ? DeathAffiliation.GANG.getValue() : DeathAffiliation.SOLO.getValue(); //Bukkit.broadcastMessage(DeathMessages.getInstance().mythicmobsEnabled + " - " + DeathMessages.getInstance().mythicMobs.getAPIHelper().isMythicMob(mob.getUniqueId())); List msgs = sortList(getPlayerDeathMessages().getStringList(mode + "." + affiliation + ".Weapon"), pm.getPlayer(), mob); + if (DeathMessages.getHooks().mythicmobsEnabled && DeathMessages.getHooks().mythicMobs.getAPIHelper().isMythicMob(mob.getUniqueId())) { - String internalMobType = DeathMessages.getHooks().mythicMobs.getAPIHelper().getMythicMobInstance(mob).getMobType(); - //Bukkit.broadcastMessage("is myth - " + internalMobType); - msgs = sortList(getPlayerDeathMessages().getStringList("Custom-Mobs.Mythic-Mobs." + internalMobType + "." + affiliation + ".Weapon"), pm.getPlayer(), mob); + String mmMobType = DeathMessages.getHooks().mythicMobs.getAPIHelper().getMythicMobInstance(mob).getMobType(); + //Bukkit.broadcastMessage("is myth - " + mmMobType); + msgs = sortList(getPlayerDeathMessages().getStringList("Custom-Mobs.Mythic-Mobs." + mmMobType + "." + affiliation + ".Weapon"), pm.getPlayer(), mob); + + if (msgs.isEmpty()) return Component.empty(); // Don't send mm mob death msg if no configured death msg. } if (Settings.getInstance().getConfig().getBoolean(Config.DEBUG.getPath())) @@ -451,13 +454,16 @@ public static TextComponent getEntityDeathWeapon(Player p, Entity e, MobType mob List msgs = sortList(getEntityDeathMessages().getStringList("Entities." + entityName + ".Weapon"), p, e); if (mobType.equals(MobType.MYTHIC_MOB)) { - String internalMobType = null; + String mmMobType = null; if (DeathMessages.getHooks().mythicmobsEnabled && DeathMessages.getHooks().mythicMobs.getAPIHelper().isMythicMob(e.getUniqueId())) { - internalMobType = DeathMessages.getHooks().mythicMobs.getAPIHelper().getMythicMobInstance(e).getMobType(); + mmMobType = DeathMessages.getHooks().mythicMobs.getAPIHelper().getMythicMobInstance(e).getMobType(); } else { // reserved } - msgs = sortList(getEntityDeathMessages().getStringList("Mythic-Mobs-Entities." + internalMobType + ".Weapon"), p, e); + + msgs = sortList(getEntityDeathMessages().getStringList("Mythic-Mobs-Entities." + mmMobType + ".Weapon"), p, e); + + if (msgs.isEmpty()) return Component.empty(); // Don't send mm mob death msg if no configured death msg. } if (Settings.getInstance().getConfig().getBoolean(Config.DEBUG.getPath())) @@ -525,9 +531,11 @@ public static TextComponent get(boolean gang, PlayerManager pm, LivingEntity mob List msgs = sortList(getPlayerDeathMessages().getStringList(mode + "." + affiliation + "." + damageCause), pm.getPlayer(), mob); if (DeathMessages.getHooks().mythicmobsEnabled && DeathMessages.getHooks().mythicMobs.getAPIHelper().isMythicMob(mob.getUniqueId())) { - String internalMobType = DeathMessages.getHooks().mythicMobs.getAPIHelper().getMythicMobInstance(mob).getMobType(); - //System.out.println("is myth - " + internalMobType); - msgs = sortList(getPlayerDeathMessages().getStringList("Custom-Mobs.Mythic-Mobs." + internalMobType + "." + affiliation + "." + damageCause), pm.getPlayer(), mob); + String mmMobType = DeathMessages.getHooks().mythicMobs.getAPIHelper().getMythicMobInstance(mob).getMobType(); + //System.out.println("is myth - " + mmMobType); + msgs = sortList(getPlayerDeathMessages().getStringList("Custom-Mobs.Mythic-Mobs." + mmMobType + "." + affiliation + "." + damageCause), pm.getPlayer(), mob); + + if (msgs.isEmpty()) return Component.empty(); // Don't send mm mob death msg if no configured death msg. } if (Settings.getInstance().getConfig().getBoolean(Config.DEBUG.getPath())) @@ -579,8 +587,10 @@ public static TextComponent getProjectile(boolean gang, PlayerManager pm, Living List msgs = sortList(getPlayerDeathMessages().getStringList(mode + "." + affiliation + "." + projectileDamage), pm.getPlayer(), mob); if (DeathMessages.getHooks().mythicmobsEnabled && DeathMessages.getHooks().mythicMobs.getAPIHelper().isMythicMob(mob.getUniqueId())) { - String internalMobType = DeathMessages.getHooks().mythicMobs.getAPIHelper().getMythicMobInstance(mob).getMobType(); - msgs = sortList(getPlayerDeathMessages().getStringList("Custom-Mobs.Mythic-Mobs." + internalMobType + "." + affiliation + "." + projectileDamage), pm.getPlayer(), mob); + String mmMobType = DeathMessages.getHooks().mythicMobs.getAPIHelper().getMythicMobInstance(mob).getMobType(); + msgs = sortList(getPlayerDeathMessages().getStringList("Custom-Mobs.Mythic-Mobs." + mmMobType + "." + affiliation + "." + projectileDamage), pm.getPlayer(), mob); + + if (msgs.isEmpty()) return Component.empty(); // Don't send mm mob death msg if no configured death msg. } if (Settings.getInstance().getConfig().getBoolean(Config.DEBUG.getPath())) @@ -665,11 +675,14 @@ public static TextComponent getEntityDeathProjectile(Player p, EntityManager em, List msgs = sortList(getEntityDeathMessages().getStringList("Entities." + entityName + "." + projectileDamage), p, em.getEntity()); if (mobType.equals(MobType.MYTHIC_MOB)) { - String internalMobType = null; + String mmMobType = null; if (DeathMessages.getHooks().mythicmobsEnabled && DeathMessages.getHooks().mythicMobs.getAPIHelper().isMythicMob(em.getEntityUUID())) { - internalMobType = DeathMessages.getHooks().mythicMobs.getAPIHelper().getMythicMobInstance(em.getEntity()).getMobType(); + mmMobType = DeathMessages.getHooks().mythicMobs.getAPIHelper().getMythicMobInstance(em.getEntity()).getMobType(); } - msgs = sortList(getEntityDeathMessages().getStringList("Mythic-Mobs-Entities." + internalMobType + "." + projectileDamage), p, em.getEntity()); + + msgs = sortList(getEntityDeathMessages().getStringList("Mythic-Mobs-Entities." + mmMobType + "." + projectileDamage), p, em.getEntity()); + + if (msgs.isEmpty()) return Component.empty(); // Don't send mm mob death msg if no configured death msg. } if (Settings.getInstance().getConfig().getBoolean(Config.DEBUG.getPath())) @@ -750,13 +763,16 @@ public static TextComponent getEntityDeath(Player player, Entity e, String damag msgs = sortList(getEntityDeathMessages().getStringList("Entities." + e.getName().toLowerCase() + ".Tamed"), player, e); } else if (mobType.equals(MobType.MYTHIC_MOB)) { - String internalMobType = null; + String mmMobType = null; if (DeathMessages.getHooks().mythicmobsEnabled && DeathMessages.getHooks().mythicMobs.getAPIHelper().isMythicMob(e.getUniqueId())) { - internalMobType = DeathMessages.getHooks().mythicMobs.getAPIHelper().getMythicMobInstance(e).getMobType(); + mmMobType = DeathMessages.getHooks().mythicMobs.getAPIHelper().getMythicMobInstance(e).getMobType(); } else { // reserved } - msgs = sortList(getEntityDeathMessages().getStringList("Mythic-Mobs-Entities." + internalMobType + "." + damageCause), player, e); + + msgs = sortList(getEntityDeathMessages().getStringList("Mythic-Mobs-Entities." + mmMobType + "." + damageCause), player, e); + + if (msgs.isEmpty()) return Component.empty(); // Don't send mm mob death msg if no configured death msg. } if (Settings.getInstance().getConfig().getBoolean(Config.DEBUG.getPath())) diff --git a/DeathMessagesLegacy/src/main/java/dev/mrshawn/deathmessages/utils/ComponentUtil.java b/DeathMessagesLegacy/src/main/java/dev/mrshawn/deathmessages/utils/ComponentUtil.java index f1303a5..eb34a55 100644 --- a/DeathMessagesLegacy/src/main/java/dev/mrshawn/deathmessages/utils/ComponentUtil.java +++ b/DeathMessagesLegacy/src/main/java/dev/mrshawn/deathmessages/utils/ComponentUtil.java @@ -16,13 +16,14 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import java.util.Arrays; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; public class ComponentUtil { - public static TextComponent[] EMPTY = new TextComponent[]{Component.empty(), Component.empty()}; + private static final TextComponent[] EMPTY = new TextComponent[]{Component.empty(), Component.empty()}; /* Process hover event string in message @@ -168,4 +169,12 @@ public static void sendMessage(Player player, Component component) { public static void sendConsoleMessage(Component component) { Util.CONSOLE.sendMessage(component); } + + public static TextComponent[] empty() { + return EMPTY.clone(); + } + + public static boolean isMessageEmpty(TextComponent[] components) { + return Arrays.equals(components, EMPTY) || components[1].equals(Component.empty()); + } } diff --git a/DeathMessagesModern/src/main/java/dev/mrshawn/deathmessages/listeners/EntityDeath.java b/DeathMessagesModern/src/main/java/dev/mrshawn/deathmessages/listeners/EntityDeath.java index e306468..793f203 100644 --- a/DeathMessagesModern/src/main/java/dev/mrshawn/deathmessages/listeners/EntityDeath.java +++ b/DeathMessagesModern/src/main/java/dev/mrshawn/deathmessages/listeners/EntityDeath.java @@ -9,6 +9,7 @@ import dev.mrshawn.deathmessages.enums.MessageType; import dev.mrshawn.deathmessages.enums.MobType; import dev.mrshawn.deathmessages.utils.Assets; +import dev.mrshawn.deathmessages.utils.ComponentUtil; import dev.mrshawn.deathmessages.utils.EntityUtil; import dev.mrshawn.deathmessages.utils.Util; import net.kyori.adventure.text.TextComponent; @@ -48,18 +49,20 @@ void onEntityDeath(EntityDeathEvent e) { if (!(pm.getLastEntityDamager() instanceof LivingEntity) || pm.getLastEntityDamager() == e.getEntity()) { TextComponent[] naturalDeath = Assets.playerNatureDeathMessage(pm, player); - TextComponent oldNaturalDeath = naturalDeath[0] != null ? naturalDeath[0].append(naturalDeath[1]) : naturalDeath[1]; // Dreeam TODO: Remove in 1.4.21 - - BroadcastDeathMessageEvent event = new BroadcastDeathMessageEvent( - player, - null, - MessageType.NATURAL, - oldNaturalDeath, - naturalDeath, - Util.getBroadcastWorlds(player), - false - ); - Bukkit.getPluginManager().callEvent(event); + TextComponent oldNaturalDeath = naturalDeath[0].append(naturalDeath[1]); // Dreeam TODO: Remove in 1.4.21 + + if (!ComponentUtil.isMessageEmpty(naturalDeath)) { + BroadcastDeathMessageEvent event = new BroadcastDeathMessageEvent( + player, + null, + MessageType.NATURAL, + oldNaturalDeath, + naturalDeath, + Util.getBroadcastWorlds(player), + false + ); + Bukkit.getPluginManager().callEvent(event); + } } else { // Killed by mob Entity ent = pm.getLastEntityDamager(); @@ -88,32 +91,21 @@ void onEntityDeath(EntityDeathEvent e) { } TextComponent[] playerDeath = Assets.playerDeathMessage(pm, gangKill); - TextComponent oldPlayerDeath = playerDeath[0] != null ? playerDeath[0].append(playerDeath[1]) : playerDeath[1]; // Dreeam TODO: Remove in 1.4.21 + TextComponent oldPlayerDeath = playerDeath[0].append(playerDeath[1]); // Dreeam TODO: Remove in 1.4.21 - if (ent instanceof Player) { + if (!ComponentUtil.isMessageEmpty(playerDeath)) { + MessageType messageType = ent instanceof Player ? MessageType.PLAYER : MessageType.MOB; BroadcastDeathMessageEvent event = new BroadcastDeathMessageEvent( player, (LivingEntity) pm.getLastEntityDamager(), - MessageType.PLAYER, + messageType, oldPlayerDeath, playerDeath, Util.getBroadcastWorlds(player), gangKill ); Bukkit.getPluginManager().callEvent(event); - return; } - - BroadcastDeathMessageEvent event = new BroadcastDeathMessageEvent( - player, - (LivingEntity) pm.getLastEntityDamager(), - MessageType.MOB, - oldPlayerDeath, - playerDeath, - Util.getBroadcastWorlds(player), - gangKill - ); - Bukkit.getPluginManager().callEvent(event); } }); @@ -135,17 +127,19 @@ void onEntityDeath(EntityDeathEvent e) { if (damager == null) return; // Entity killed by Entity should not include in DM TextComponent[] entityDeath = Assets.entityDeathMessage(em, mobType); - TextComponent oldEntityDeath = entityDeath[0] != null ? entityDeath[0].append(entityDeath[1]) : entityDeath[1]; // Dreeam TODO: Remove in 1.4.21 - - BroadcastEntityDeathMessageEvent event = new BroadcastEntityDeathMessageEvent( - damager, - e.getEntity(), - MessageType.ENTITY, - oldEntityDeath, - entityDeath, - Util.getBroadcastWorlds(e.getEntity()) - ); - Bukkit.getPluginManager().callEvent(event); + TextComponent oldEntityDeath = entityDeath[0].append(entityDeath[1]); // Dreeam TODO: Remove in 1.4.21 + + if (!ComponentUtil.isMessageEmpty(entityDeath)) { + BroadcastEntityDeathMessageEvent event = new BroadcastEntityDeathMessageEvent( + damager, + e.getEntity(), + MessageType.ENTITY, + oldEntityDeath, + entityDeath, + Util.getBroadcastWorlds(e.getEntity()) + ); + Bukkit.getPluginManager().callEvent(event); + } }); } } diff --git a/DeathMessagesModern/src/main/java/dev/mrshawn/deathmessages/listeners/combatlogx/PlayerUntag.java b/DeathMessagesModern/src/main/java/dev/mrshawn/deathmessages/listeners/combatlogx/PlayerUntag.java index 54a49d7..870e525 100644 --- a/DeathMessagesModern/src/main/java/dev/mrshawn/deathmessages/listeners/combatlogx/PlayerUntag.java +++ b/DeathMessagesModern/src/main/java/dev/mrshawn/deathmessages/listeners/combatlogx/PlayerUntag.java @@ -10,6 +10,7 @@ import dev.mrshawn.deathmessages.enums.MessageType; import dev.mrshawn.deathmessages.files.Config; import dev.mrshawn.deathmessages.utils.Assets; +import dev.mrshawn.deathmessages.utils.ComponentUtil; import dev.mrshawn.deathmessages.utils.Util; import net.kyori.adventure.text.TextComponent; import org.bukkit.Bukkit; @@ -66,18 +67,20 @@ public void untagPlayer(PlayerUntagEvent e) { deathMessage[1] = deathMessageBody; - TextComponent oldDeathMessage = deathMessage[0] != null ? deathMessage[0].append(deathMessage[1]) : deathMessage[1]; // Dreeam TODO: Remove in 1.4.21 - - BroadcastDeathMessageEvent event = new BroadcastDeathMessageEvent( - player, - (LivingEntity) e.getPreviousEnemies().get(0), - MessageType.PLAYER, - oldDeathMessage, - deathMessage, - Util.getBroadcastWorlds(player), - gangKill - ); - Bukkit.getPluginManager().callEvent(event); + TextComponent oldDeathMessage = deathMessage[0].append(deathMessage[1]); // Dreeam TODO: Remove in 1.4.21 + + if (!ComponentUtil.isMessageEmpty(deathMessage)) { + BroadcastDeathMessageEvent event = new BroadcastDeathMessageEvent( + player, + (LivingEntity) e.getPreviousEnemies().get(0), + MessageType.PLAYER, + oldDeathMessage, + deathMessage, + Util.getBroadcastWorlds(player), + gangKill + ); + Bukkit.getPluginManager().callEvent(event); + } }); if (getPlayer.isEmpty()) { diff --git a/DeathMessagesModern/src/main/java/dev/mrshawn/deathmessages/listeners/customlisteners/BroadcastEntityDeathListener.java b/DeathMessagesModern/src/main/java/dev/mrshawn/deathmessages/listeners/customlisteners/BroadcastEntityDeathListener.java index 19e349d..1418907 100644 --- a/DeathMessagesModern/src/main/java/dev/mrshawn/deathmessages/listeners/customlisteners/BroadcastEntityDeathListener.java +++ b/DeathMessagesModern/src/main/java/dev/mrshawn/deathmessages/listeners/customlisteners/BroadcastEntityDeathListener.java @@ -28,16 +28,13 @@ public class BroadcastEntityDeathListener implements Listener { @EventHandler public void broadcastListener(BroadcastEntityDeathMessageEvent e) { - if (e.getTextComponents() == ComponentUtil.EMPTY) - return; // Dreeam - in Assets: return null -> return ComponentUtil.EMPTY - final Optional pm = Optional.of(e.getPlayer()); final Entity entity = e.getEntity(); final boolean hasOwner = EntityUtil.hasOwner(entity); final TextComponent[] components = e.getTextComponents(); final TextComponent prefix = components[0]; final TextComponent messageBody = components[1]; - final TextComponent message = prefix != null ? prefix.append(messageBody) : messageBody; + final TextComponent message = prefix.append(messageBody); if (Messages.getInstance().getConfig().getBoolean("Console.Enabled")) { Component rawMessage = Util.convertFromLegacy(Messages.getInstance().getConfig().getString("Console.Message")); diff --git a/DeathMessagesModern/src/main/java/dev/mrshawn/deathmessages/listeners/customlisteners/BroadcastPlayerDeathListener.java b/DeathMessagesModern/src/main/java/dev/mrshawn/deathmessages/listeners/customlisteners/BroadcastPlayerDeathListener.java index ea97dc7..332b15d 100644 --- a/DeathMessagesModern/src/main/java/dev/mrshawn/deathmessages/listeners/customlisteners/BroadcastPlayerDeathListener.java +++ b/DeathMessagesModern/src/main/java/dev/mrshawn/deathmessages/listeners/customlisteners/BroadcastPlayerDeathListener.java @@ -28,9 +28,6 @@ public class BroadcastPlayerDeathListener implements Listener { @EventHandler public void broadcastListener(BroadcastDeathMessageEvent e) { - if (e.getTextComponents() == ComponentUtil.EMPTY) - return; // Dreeam - in Assets: return null -> return ComponentUtil.EMPTY - Optional getPlayer = PlayerManager.getPlayer(e.getPlayer()); if (!getPlayer.isPresent()) return; @@ -38,7 +35,7 @@ public void broadcastListener(BroadcastDeathMessageEvent e) { final TextComponent[] components = e.getTextComponents(); final TextComponent prefix = components[0]; final TextComponent messageBody = components[1]; - final TextComponent message = prefix != null ? prefix.append(messageBody) : messageBody; + final TextComponent message = prefix.append(messageBody); if (Messages.getInstance().getConfig().getBoolean("Console.Enabled")) { // Dreeam TODO: maybe just use formatMessage is also ok? diff --git a/DeathMessagesModern/src/main/java/dev/mrshawn/deathmessages/listeners/mythicmobs/MobDeath.java b/DeathMessagesModern/src/main/java/dev/mrshawn/deathmessages/listeners/mythicmobs/MobDeath.java index e346210..f72beea 100644 --- a/DeathMessagesModern/src/main/java/dev/mrshawn/deathmessages/listeners/mythicmobs/MobDeath.java +++ b/DeathMessagesModern/src/main/java/dev/mrshawn/deathmessages/listeners/mythicmobs/MobDeath.java @@ -6,6 +6,7 @@ import dev.mrshawn.deathmessages.enums.MessageType; import dev.mrshawn.deathmessages.enums.MobType; import dev.mrshawn.deathmessages.utils.Assets; +import dev.mrshawn.deathmessages.utils.ComponentUtil; import dev.mrshawn.deathmessages.utils.Util; import io.lumine.mythic.bukkit.events.MythicMobDeathEvent; import net.kyori.adventure.text.TextComponent; @@ -36,17 +37,19 @@ public void onMythicMobDeath(MythicMobDeathEvent e) { getEntity.ifPresent(em -> { PlayerManager damager = em.getLastPlayerDamager(); TextComponent[] mythicDeath = Assets.entityDeathMessage(em, MobType.MYTHIC_MOB); - TextComponent oldMythicDeath = mythicDeath[0] != null ? mythicDeath[0].append(mythicDeath[1]) : mythicDeath[1]; // Dreeam TODO: Remove in 1.4.21 - - BroadcastEntityDeathMessageEvent event = new BroadcastEntityDeathMessageEvent( - damager, - e.getEntity(), - MessageType.ENTITY, - oldMythicDeath, - mythicDeath, - Util.getBroadcastWorlds(e.getEntity()) - ); - Bukkit.getPluginManager().callEvent(event); + TextComponent oldMythicDeath = mythicDeath[0].append(mythicDeath[1]); // Dreeam TODO: Remove in 1.4.21 + + if (!ComponentUtil.isMessageEmpty(mythicDeath)) { + BroadcastEntityDeathMessageEvent event = new BroadcastEntityDeathMessageEvent( + damager, + e.getEntity(), + MessageType.ENTITY, + oldMythicDeath, + mythicDeath, + Util.getBroadcastWorlds(e.getEntity()) + ); + Bukkit.getPluginManager().callEvent(event); + } }); } } diff --git a/DeathMessagesModern/src/main/java/dev/mrshawn/deathmessages/utils/Assets.java b/DeathMessagesModern/src/main/java/dev/mrshawn/deathmessages/utils/Assets.java index 572be9d..df4d6d0 100644 --- a/DeathMessagesModern/src/main/java/dev/mrshawn/deathmessages/utils/Assets.java +++ b/DeathMessagesModern/src/main/java/dev/mrshawn/deathmessages/utils/Assets.java @@ -60,7 +60,7 @@ public class Assets { //private static final CommentedConfiguration config = Settings.getInstance().getConfig(); public static TextComponent[] playerNatureDeathMessage(PlayerManager pm, Player player) { - TextComponent[] components = new TextComponent[2]; + TextComponent[] components = ComponentUtil.empty(); if (Settings.getInstance().getConfig().getBoolean(Config.ADD_PREFIX_TO_ALL_MESSAGES.getPath())) { TextComponent prefix = Util.convertFromLegacy(Messages.getInstance().getConfig().getString("Prefix")); @@ -109,7 +109,7 @@ public static TextComponent[] playerNatureDeathMessage(PlayerManager pm, Player public static TextComponent[] playerDeathMessage(PlayerManager pm, boolean gang) { LivingEntity mob = (LivingEntity) pm.getLastEntityDamager(); - TextComponent[] components = new TextComponent[2]; + TextComponent[] components = ComponentUtil.empty(); if (Settings.getInstance().getConfig().getBoolean(Config.ADD_PREFIX_TO_ALL_MESSAGES.getPath())) { TextComponent prefix = Util.convertFromLegacy(Messages.getInstance().getConfig().getString("Prefix")); @@ -186,17 +186,17 @@ public static TextComponent[] playerDeathMessage(PlayerManager pm, boolean gang) } } - return ComponentUtil.EMPTY; + return ComponentUtil.empty(); } } public static TextComponent[] entityDeathMessage(EntityManager em, MobType mobType) { Optional pm = Optional.ofNullable(em.getLastPlayerDamager()); - if (pm.isEmpty()) return ComponentUtil.EMPTY; + if (pm.isEmpty()) return ComponentUtil.empty(); Player p = pm.get().getPlayer(); - TextComponent[] components = new TextComponent[2]; + TextComponent[] components = ComponentUtil.empty(); if (Settings.getInstance().getConfig().getBoolean(Config.ADD_PREFIX_TO_ALL_MESSAGES.getPath())) { TextComponent prefix = Util.convertFromLegacy(Messages.getInstance().getConfig().getString("Prefix")); @@ -272,7 +272,7 @@ public static TextComponent[] entityDeathMessage(EntityManager em, MobType mobTy } } - return ComponentUtil.EMPTY; + return ComponentUtil.empty(); } } @@ -374,10 +374,13 @@ public static TextComponent getWeapon(boolean gang, PlayerManager pm, LivingEnti final String affiliation = gang ? DeathAffiliation.GANG.getValue() : DeathAffiliation.SOLO.getValue(); //Bukkit.broadcastMessage(DeathMessages.getInstance().mythicmobsEnabled + " - " + DeathMessages.getInstance().mythicMobs.getAPIHelper().isMythicMob(mob.getUniqueId())); List msgs = sortList(getPlayerDeathMessages().getStringList(mode + "." + affiliation + ".Weapon"), pm.getPlayer(), mob); + if (DeathMessages.getHooks().mythicmobsEnabled && DeathMessages.getHooks().mythicMobs.getAPIHelper().isMythicMob(mob.getUniqueId())) { - String internalMobType = DeathMessages.getHooks().mythicMobs.getAPIHelper().getMythicMobInstance(mob).getMobType(); - //Bukkit.broadcastMessage("is myth - " + internalMobType); - msgs = sortList(getPlayerDeathMessages().getStringList("Custom-Mobs.Mythic-Mobs." + internalMobType + "." + affiliation + ".Weapon"), pm.getPlayer(), mob); + String mmMobType = DeathMessages.getHooks().mythicMobs.getAPIHelper().getMythicMobInstance(mob).getMobType(); + //Bukkit.broadcastMessage("is myth - " + mmMobType); + msgs = sortList(getPlayerDeathMessages().getStringList("Custom-Mobs.Mythic-Mobs." + mmMobType + "." + affiliation + ".Weapon"), pm.getPlayer(), mob); + + if (msgs.isEmpty()) return Component.empty(); // Don't send mm mob death msg if no configured death msg. } if (Settings.getInstance().getConfig().getBoolean(Config.DEBUG.getPath())) @@ -442,13 +445,16 @@ public static TextComponent getEntityDeathWeapon(Player p, Entity e, MobType mob List msgs = sortList(getEntityDeathMessages().getStringList("Entities." + entityName + ".Weapon"), p, e); if (mobType.equals(MobType.MYTHIC_MOB)) { - String internalMobType = null; + String mmMobType = null; if (DeathMessages.getHooks().mythicmobsEnabled && DeathMessages.getHooks().mythicMobs.getAPIHelper().isMythicMob(e.getUniqueId())) { - internalMobType = DeathMessages.getHooks().mythicMobs.getAPIHelper().getMythicMobInstance(e).getMobType(); + mmMobType = DeathMessages.getHooks().mythicMobs.getAPIHelper().getMythicMobInstance(e).getMobType(); } else { // reserved } - msgs = sortList(getEntityDeathMessages().getStringList("Mythic-Mobs-Entities." + internalMobType + ".Weapon"), p, e); + + msgs = sortList(getEntityDeathMessages().getStringList("Mythic-Mobs-Entities." + mmMobType + ".Weapon"), p, e); + + if (msgs.isEmpty()) return Component.empty(); // Don't send mm mob death msg if no configured death msg. } if (Settings.getInstance().getConfig().getBoolean(Config.DEBUG.getPath())) @@ -516,9 +522,11 @@ public static TextComponent get(boolean gang, PlayerManager pm, LivingEntity mob List msgs = sortList(getPlayerDeathMessages().getStringList(mode + "." + affiliation + "." + damageCause), pm.getPlayer(), mob); if (DeathMessages.getHooks().mythicmobsEnabled && DeathMessages.getHooks().mythicMobs.getAPIHelper().isMythicMob(mob.getUniqueId())) { - String internalMobType = DeathMessages.getHooks().mythicMobs.getAPIHelper().getMythicMobInstance(mob).getMobType(); - //System.out.println("is myth - " + internalMobType); - msgs = sortList(getPlayerDeathMessages().getStringList("Custom-Mobs.Mythic-Mobs." + internalMobType + "." + affiliation + "." + damageCause), pm.getPlayer(), mob); + String mmMobType = DeathMessages.getHooks().mythicMobs.getAPIHelper().getMythicMobInstance(mob).getMobType(); + //System.out.println("is myth - " + mmMobType); + msgs = sortList(getPlayerDeathMessages().getStringList("Custom-Mobs.Mythic-Mobs." + mmMobType + "." + affiliation + "." + damageCause), pm.getPlayer(), mob); + + if (msgs.isEmpty()) return Component.empty(); // Don't send mm mob death msg if no configured death msg. } if (Settings.getInstance().getConfig().getBoolean(Config.DEBUG.getPath())) @@ -570,8 +578,10 @@ public static TextComponent getProjectile(boolean gang, PlayerManager pm, Living List msgs = sortList(getPlayerDeathMessages().getStringList(mode + "." + affiliation + "." + projectileDamage), pm.getPlayer(), mob); if (DeathMessages.getHooks().mythicmobsEnabled && DeathMessages.getHooks().mythicMobs.getAPIHelper().isMythicMob(mob.getUniqueId())) { - String internalMobType = DeathMessages.getHooks().mythicMobs.getAPIHelper().getMythicMobInstance(mob).getMobType(); - msgs = sortList(getPlayerDeathMessages().getStringList("Custom-Mobs.Mythic-Mobs." + internalMobType + "." + affiliation + "." + projectileDamage), pm.getPlayer(), mob); + String mmMobType = DeathMessages.getHooks().mythicMobs.getAPIHelper().getMythicMobInstance(mob).getMobType(); + msgs = sortList(getPlayerDeathMessages().getStringList("Custom-Mobs.Mythic-Mobs." + mmMobType + "." + affiliation + "." + projectileDamage), pm.getPlayer(), mob); + + if (msgs.isEmpty()) return Component.empty(); // Don't send mm mob death msg if no configured death msg. } if (Settings.getInstance().getConfig().getBoolean(Config.DEBUG.getPath())) @@ -656,11 +666,14 @@ public static TextComponent getEntityDeathProjectile(Player p, EntityManager em, List msgs = sortList(getEntityDeathMessages().getStringList("Entities." + entityName + "." + projectileDamage), p, em.getEntity()); if (mobType.equals(MobType.MYTHIC_MOB)) { - String internalMobType = null; + String mmMobType = null; if (DeathMessages.getHooks().mythicmobsEnabled && DeathMessages.getHooks().mythicMobs.getAPIHelper().isMythicMob(em.getEntityUUID())) { - internalMobType = DeathMessages.getHooks().mythicMobs.getAPIHelper().getMythicMobInstance(em.getEntity()).getMobType(); + mmMobType = DeathMessages.getHooks().mythicMobs.getAPIHelper().getMythicMobInstance(em.getEntity()).getMobType(); } - msgs = sortList(getEntityDeathMessages().getStringList("Mythic-Mobs-Entities." + internalMobType + "." + projectileDamage), p, em.getEntity()); + + msgs = sortList(getEntityDeathMessages().getStringList("Mythic-Mobs-Entities." + mmMobType + "." + projectileDamage), p, em.getEntity()); + + if (msgs.isEmpty()) return Component.empty(); // Don't send mm mob death msg if no configured death msg. } if (Settings.getInstance().getConfig().getBoolean(Config.DEBUG.getPath())) @@ -741,13 +754,16 @@ public static TextComponent getEntityDeath(Player player, Entity e, String damag msgs = sortList(getEntityDeathMessages().getStringList("Entities." + e.getName().toLowerCase() + ".Tamed"), player, e); } else if (mobType.equals(MobType.MYTHIC_MOB)) { - String internalMobType = null; + String mmMobType = null; if (DeathMessages.getHooks().mythicmobsEnabled && DeathMessages.getHooks().mythicMobs.getAPIHelper().isMythicMob(e.getUniqueId())) { - internalMobType = DeathMessages.getHooks().mythicMobs.getAPIHelper().getMythicMobInstance(e).getMobType(); + mmMobType = DeathMessages.getHooks().mythicMobs.getAPIHelper().getMythicMobInstance(e).getMobType(); } else { // reserved } - msgs = sortList(getEntityDeathMessages().getStringList("Mythic-Mobs-Entities." + internalMobType + "." + damageCause), player, e); + + msgs = sortList(getEntityDeathMessages().getStringList("Mythic-Mobs-Entities." + mmMobType + "." + damageCause), player, e); + + if (msgs.isEmpty()) return Component.empty(); // Don't send mm mob death msg if no configured death msg. } if (Settings.getInstance().getConfig().getBoolean(Config.DEBUG.getPath())) diff --git a/DeathMessagesModern/src/main/java/dev/mrshawn/deathmessages/utils/ComponentUtil.java b/DeathMessagesModern/src/main/java/dev/mrshawn/deathmessages/utils/ComponentUtil.java index 350afe9..f78352c 100644 --- a/DeathMessagesModern/src/main/java/dev/mrshawn/deathmessages/utils/ComponentUtil.java +++ b/DeathMessagesModern/src/main/java/dev/mrshawn/deathmessages/utils/ComponentUtil.java @@ -10,13 +10,14 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import java.util.Arrays; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; public class ComponentUtil { - public static TextComponent[] EMPTY = new TextComponent[]{Component.empty(), Component.empty()}; + private static final TextComponent[] EMPTY = new TextComponent[]{Component.empty(), Component.empty()}; /* Process hover event string in message @@ -139,4 +140,12 @@ public static Component getItemStackDisplayName(ItemStack i) { public static void sendConsoleMessage(Component component) { Util.CONSOLE.sendMessage(component); } + + public static TextComponent[] empty() { + return EMPTY.clone(); + } + + public static boolean isMessageEmpty(TextComponent[] components) { + return Arrays.equals(components, EMPTY) || components[1].equals(Component.empty()); + } }