diff --git a/src/main/java/com/alttd/playerutils/commands/playerutils_subcommands/XPCheque.java b/src/main/java/com/alttd/playerutils/commands/playerutils_subcommands/XPCheque.java index 3c9602b..2ccb3ac 100644 --- a/src/main/java/com/alttd/playerutils/commands/playerutils_subcommands/XPCheque.java +++ b/src/main/java/com/alttd/playerutils/commands/playerutils_subcommands/XPCheque.java @@ -5,6 +5,7 @@ import com.alttd.playerutils.commands.SubCommand; import com.alttd.playerutils.config.Messages; import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; +import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; import org.bukkit.Material; import org.bukkit.NamespacedKey; import org.bukkit.command.CommandSender; @@ -82,6 +83,18 @@ public class XPCheque extends SubCommand { return true; } + public String addDots(String input) { + StringBuilder stringBuilder = new StringBuilder(input); + int length = input.length(); + + // Start from the third character from the right and add a dot after every third character + for (int i = length - 3; i > 0; i -= 3) { + stringBuilder.insert(i, '.'); + } + + return stringBuilder.toString(); + } + private Optional getExpBottleItem(Player player, int xpValue) { ItemStack expBottle = new ItemStack(Material.EXPERIENCE_BOTTLE); ItemMeta itemMeta = expBottle.getItemMeta(); @@ -93,9 +106,13 @@ public class XPCheque extends SubCommand { return Optional.empty(); } persistentDataContainer.set(customXp, PersistentDataType.INTEGER, xpValue); - itemMeta.displayName(miniMessage.deserialize(Messages.XP_CHEQUE.DISPLAY_NAME, Placeholder.parsed("xp", String.valueOf(xpValue)))); + String xpWithDots = addDots(String.valueOf(xpValue)); + itemMeta.displayName(miniMessage.deserialize(Messages.XP_CHEQUE.DISPLAY_NAME, Placeholder.parsed("xp", xpWithDots))); itemMeta.lore(Messages.XP_CHEQUE.LORE.stream() - .map(str -> miniMessage.deserialize(str, Placeholder.component("name", player.displayName()))) + .map(str -> miniMessage.deserialize(str, TagResolver.resolver( + Placeholder.component("name", player.displayName()), + Placeholder.parsed("xp", xpWithDots) + ))) .collect(Collectors.toList())); expBottle.setItemMeta(itemMeta); return Optional.of(expBottle); diff --git a/src/main/java/com/alttd/playerutils/config/Messages.java b/src/main/java/com/alttd/playerutils/config/Messages.java index 3431312..268a762 100644 --- a/src/main/java/com/alttd/playerutils/config/Messages.java +++ b/src/main/java/com/alttd/playerutils/config/Messages.java @@ -30,8 +30,8 @@ public class Messages extends AbstractConfig { public static String HELP_MESSAGE_WRAPPER = "PlayerUtils help:\n"; public static String HELP_MESSAGE = "Show this menu: /pu help"; public static String GLOW = "Glow in a specified color: /pu glow "; - public static String XP_CHEQUE = "Create an xp cheque: /pu xpcheque "; - public static String XP_CALC = "Calculate the amount of xp between levels: /pu xpcalc "; + public static String XP_CHEQUE = "Create an XP cheque: /pu xpcheque "; + public static String XP_CALC = "Calculate the amount of XP between levels: /pu xpcalc "; public static String RELOAD = "Reload the configs for PlayerUtils: /pu reload"; public static String ROTATE_BLOCK = "Enable rotating blocks with a blaze rod: /pu rotateblock"; @@ -78,12 +78,12 @@ public class Messages extends AbstractConfig { public static class XP_CHEQUE { private static final String prefix = "pu-command.xp-cheque."; - public static String FAILED_STORAGE = "Unable to create custom item for xp cheque"; - public static String NEGATIVE = "You cannot enter a negative value for xp."; - public static String NOT_ENOUGH_XP = "Not enough xp, you have "; + public static String FAILED_STORAGE = "Unable to create custom item for XP cheque"; + public static String NEGATIVE = "You cannot enter a negative value for XP."; + public static String NOT_ENOUGH_XP = "Not enough XP, you have "; public static String NOT_HOLDING_BOTTLE = "You need to hold an empty glass bottle while executing this command"; - public static String DISPLAY_NAME = "Xp bottle containing xp"; - public static List LORE = List.of("Issued by ", "Throw to retrieve xp"); + public static String DISPLAY_NAME = "XP bottle containing XP"; + public static List LORE = List.of("Issued by ", "Throw to retrieve XP"); @SuppressWarnings("unused") private static void load() {