I'm creating a Minecraft Item Placing System. Basically it's like looping through 100 string like "Hi, %employee, welcome to %company." and I would replace those %employee with their name and %company with the company name.
But in my case, I tried replacing them but, it didn't workout very well after the second object.
What I mean is that after the first Item, the second item won't replace the string.
I've tried debugging, using async, everything I could possibly imagined. But no luck.
public ItemStack getMailItem(Mail m) {
ItemStack item = null;
if (m.isRead()) {
item = items.get(ItemData.READ_MAIL);
}
else {
item = items.get(ItemData.MAIL);
item.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1);
item.addItemFlags(ItemFlag.HIDE_ENCHANTS);
}
ItemMeta meta = item.getItemMeta();
String name = meta.getDisplayName();
name = name.replaceAll("%a", m.getSender());
name = name.replaceAll("%b", m.getDate());
Utility.broadcast("Date: " + m.getDate());
meta.setDisplayName(Utility.TransColor(name));
ArrayList<String> msgs = new ArrayList<String>();
for (String str : m.getMessages()) {
msgs.add("&f" + str);
}
meta.setLore(Utility.TransColor(msgs));
item.setItemMeta(meta);
NBTItem nbt = new NBTItem(item);
nbt.setString("c2e", m.getUniqueID().toString());
return nbt.getItem();
}
Basically It works the first time but the second time it doesn't work. It will use the name of the first sender and the date from the first mail.
I expect that for example it has a data like this: Johnny, 5 AM Mark, 5 PM Albert, 1 PM
But when It's done:
Johnny, 5 AM Johnny, 5 AM Johnny, 5 AM
It's replaced but it doesn't use the right string.
I've debugged and it shows the right string but it doesn't replace the right string.