From ab329e4fbf7d139a20ec6d457973e7308bdf3a79 Mon Sep 17 00:00:00 2001 From: LoJoSho Date: Sun, 15 Oct 2023 11:05:29 -0500 Subject: [PATCH] feat: define what offline and invalid player return in translations --- .../placeholders/HMCPlaceholderExpansion.java | 24 +++++-------------- common/src/main/resources/translations.yml | 3 +++ 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/hooks/placeholders/HMCPlaceholderExpansion.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/hooks/placeholders/HMCPlaceholderExpansion.java index f92732cc..83eb7b95 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/hooks/placeholders/HMCPlaceholderExpansion.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/hooks/placeholders/HMCPlaceholderExpansion.java @@ -54,18 +54,15 @@ public class HMCPlaceholderExpansion extends PlaceholderExpansion { @Override public String onRequest(@NotNull OfflinePlayer player, @NotNull String params) { - if (!player.isOnline()) return null; + if (!player.isOnline()) return TranslationUtil.getTranslation("user-cosmetic", "offline"); CosmeticUser user = CosmeticUsers.getUser(player.getPlayer()); - if (user == null) return null; + if (user == null) return TranslationUtil.getTranslation("user-cosmetic", "invalid-user"); List placeholderArgs = Arrays.asList(params.split("_", 3)); switch (placeholderArgs.get(0).toLowerCase()) { case "using": - if (placeholderArgs == null) { - return null; - } - if (placeholderArgs.get(1) != null) { + if (placeholderArgs.size() >= 2) { Cosmetic cosmetic = Cosmetics.getCosmetic(placeholderArgs.get(1)); if (cosmetic == null) return "INVALID_COSMETIC"; Cosmetic currentCosmetic = user.getCosmetic(cosmetic.getSlot()); @@ -74,10 +71,7 @@ public class HMCPlaceholderExpansion extends PlaceholderExpansion { return TranslationUtil.getTranslation("using-cosmetic", String.valueOf(false)); } case "current": - if (placeholderArgs == null) { - return null; - } - if (placeholderArgs.get(1) != null) { + if (placeholderArgs.size() >= 2) { CosmeticSlot slot = CosmeticSlot.valueOf(placeholderArgs.get(1).toUpperCase()); if (slot == null) return null; if (user.getCosmetic(slot) == null) return TranslationUtil.getTranslation("current-cosmetic", "no-cosmetic"); @@ -108,10 +102,7 @@ public class HMCPlaceholderExpansion extends PlaceholderExpansion { return TranslationUtil.getTranslation("current-cosmetic", output); } case "unlocked": - if (placeholderArgs == null) { - return null; - } - if (placeholderArgs.get(1) != null) { + if (placeholderArgs.size() >= 2) { Cosmetic cosmetic = Cosmetics.getCosmetic(placeholderArgs.get(1)); if (cosmetic == null) { if (placeholderArgs.size() >= 3) { @@ -128,10 +119,7 @@ public class HMCPlaceholderExpansion extends PlaceholderExpansion { return TranslationUtil.getTranslation("unlocked-cosmetic", String.valueOf(user.canEquipCosmetic(cosmetic, true))); } case "equipped": - if (placeholderArgs == null) { - return null; - } - if (placeholderArgs.get(1) != null) { + if (placeholderArgs.size() >= 2) { String args1 = placeholderArgs.get(1); if (EnumUtils.isValidEnum(CosmeticSlot.class, args1.toUpperCase())) { diff --git a/common/src/main/resources/translations.yml b/common/src/main/resources/translations.yml index 52f134b4..5429c173 100644 --- a/common/src/main/resources/translations.yml +++ b/common/src/main/resources/translations.yml @@ -1,3 +1,6 @@ +user-cosmetic: + offline: "Offline" + invalid-user: "Invalid User" unlocked-cosmetic: true: "true" false: "false"