mirror of
https://github.com/HibiscusMC/HMCCosmetics.git
synced 2025-12-29 03:49:19 +00:00
fix: prevent kicking when message is null/empty
This commit is contained in:
@@ -4,7 +4,6 @@ import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||
import com.hibiscusmc.hmccosmetics.config.WardrobeSettings;
|
||||
import com.hibiscusmc.hmccosmetics.hooks.Hooks;
|
||||
import com.hibiscusmc.hmccosmetics.hooks.placeholders.HMCPlaceholderExpansion;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.util.misc.Adventure;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
@@ -26,14 +25,16 @@ import java.util.logging.Level;
|
||||
public class MessagesUtil {
|
||||
|
||||
private static String prefix;
|
||||
private static final HashMap<String, String> messages = new HashMap<>();
|
||||
private static final HashMap<String, String> MESSAGES = new HashMap<>();
|
||||
|
||||
public static void setup(@NotNull ConfigurationNode config) {
|
||||
MESSAGES.clear();
|
||||
|
||||
prefix = config.node("prefix").getString("");
|
||||
for (ConfigurationNode node : config.childrenMap().values()) {
|
||||
if (node.virtual()) continue;
|
||||
if (node.empty()) continue;
|
||||
messages.put(node.key().toString(), node.getString());
|
||||
MESSAGES.put(node.key().toString(), node.getString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +44,7 @@ public class MessagesUtil {
|
||||
|
||||
public static void sendMessage(Player player, String key) {
|
||||
Component finalMessage = processString(player, key);
|
||||
if (finalMessage == null) return;
|
||||
Audience target = BukkitAudiences.create(HMCCosmeticsPlugin.getInstance()).player(player);
|
||||
|
||||
target.sendMessage(finalMessage);
|
||||
@@ -58,6 +60,7 @@ public class MessagesUtil {
|
||||
|
||||
public static void sendMessage(Player player, String key, TagResolver placeholder) {
|
||||
Component finalMessage = processString(player, key, placeholder);
|
||||
if (finalMessage == null) return;
|
||||
Audience target = BukkitAudiences.create(HMCCosmeticsPlugin.getInstance()).player(player);
|
||||
|
||||
target.sendMessage(finalMessage);
|
||||
@@ -65,6 +68,7 @@ public class MessagesUtil {
|
||||
|
||||
public static void sendMessageNoKey(Player player, String message) {
|
||||
Component finalMessage = processStringNoKey(player, message);
|
||||
if (finalMessage == null) return;
|
||||
Audience target = BukkitAudiences.create(HMCCosmeticsPlugin.getInstance()).player(player);
|
||||
|
||||
target.sendMessage(finalMessage);
|
||||
@@ -72,6 +76,7 @@ public class MessagesUtil {
|
||||
|
||||
public static void sendActionBar(Player player, String key) {
|
||||
Component finalMessage = processString(player, key);
|
||||
if (finalMessage == null) return;
|
||||
Audience target = BukkitAudiences.create(HMCCosmeticsPlugin.getInstance()).player(player);
|
||||
|
||||
target.sendActionBar(finalMessage);
|
||||
@@ -96,9 +101,9 @@ public class MessagesUtil {
|
||||
|
||||
@Nullable
|
||||
public static Component processString(Player player, String key, TagResolver placeholders) {
|
||||
if (!messages.containsKey(key)) return null;
|
||||
if (messages.get(key) == null) return null;
|
||||
String message = messages.get(key);
|
||||
if (!MESSAGES.containsKey(key)) return null;
|
||||
if (MESSAGES.get(key) == null) return null;
|
||||
String message = MESSAGES.get(key);
|
||||
if (Hooks.isActiveHook("PlaceholderAPI") && player != null) message = PlaceholderAPI.setPlaceholders(player, message);
|
||||
message = message.replaceAll("%prefix%", prefix);
|
||||
if (placeholders != null ) {
|
||||
|
||||
Reference in New Issue
Block a user