Added more locations for xp to be shown on item, improved readability by seperating large numbers with .'s
This commit is contained in:
parent
1b9278ca25
commit
977ed00cb8
|
|
@ -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<ItemStack> 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);
|
||||
|
|
|
|||
|
|
@ -30,8 +30,8 @@ public class Messages extends AbstractConfig {
|
|||
public static String HELP_MESSAGE_WRAPPER = "<gold>PlayerUtils help:\n<commands></gold>";
|
||||
public static String HELP_MESSAGE = "<green>Show this menu: <gold>/pu help</gold></green>";
|
||||
public static String GLOW = "<green>Glow in a specified color: <gold>/pu glow <color></gold></green>";
|
||||
public static String XP_CHEQUE = "<green>Create an xp cheque: <gold>/pu xpcheque <amount></gold></green>";
|
||||
public static String XP_CALC = "<green>Calculate the amount of xp between levels: <gold>/pu xpcalc <from> <to></gold></green>";
|
||||
public static String XP_CHEQUE = "<green>Create an XP cheque: <gold>/pu xpcheque <amount></gold></green>";
|
||||
public static String XP_CALC = "<green>Calculate the amount of XP between levels: <gold>/pu xpcalc <from> <to></gold></green>";
|
||||
public static String RELOAD = "<green>Reload the configs for PlayerUtils: <gold>/pu reload</gold></green>";
|
||||
public static String ROTATE_BLOCK = "<green>Enable rotating blocks with a blaze rod: <gold>/pu rotateblock</gold></green>";
|
||||
|
||||
|
|
@ -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 = "<red>Unable to create custom item for xp cheque</red>";
|
||||
public static String NEGATIVE = "<red>You cannot enter a negative value for xp.</red>";
|
||||
public static String NOT_ENOUGH_XP = "<red>Not enough xp, you have <xp></red>";
|
||||
public static String FAILED_STORAGE = "<red>Unable to create custom item for XP cheque</red>";
|
||||
public static String NEGATIVE = "<red>You cannot enter a negative value for XP.</red>";
|
||||
public static String NOT_ENOUGH_XP = "<red>Not enough XP, you have <xp></red>";
|
||||
public static String NOT_HOLDING_BOTTLE = "<red>You need to hold an empty glass bottle while executing this command</red>";
|
||||
public static String DISPLAY_NAME = "<yellow>Xp bottle containing <xp> xp</yellow>";
|
||||
public static List<String> LORE = List.of("Issued by <name>", "Throw to retrieve xp");
|
||||
public static String DISPLAY_NAME = "<yellow>XP bottle containing <xp> XP</yellow>";
|
||||
public static List<String> LORE = List.of("Issued by <name>", "Throw to retrieve <xp> XP");
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static void load() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user