Stations name placeholders patched

This commit is contained in:
Roch Blonndiaux 2022-12-08 16:33:13 +01:00
parent d2ad83e218
commit 96d02969fd
6 changed files with 343 additions and 369 deletions

View File

@ -1,6 +1,5 @@
package net.Indyuce.mmoitems.api.crafting;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.api.util.PostLoadObject;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.crafting.ingredient.inventory.IngredientInventory;
@ -22,7 +21,6 @@ import java.util.logging.Level;
public class CraftingStation extends PostLoadObject {
private final String id;
private final String name;
private final String unparsedName;
private final Layout layout;
private final Sound sound;
private final StationItemOptions itemOptions;
@ -44,8 +42,7 @@ public class CraftingStation extends PostLoadObject {
super(config);
this.id = id.toLowerCase().replace("_", "-").replace(" ", "-");
this.unparsedName = config.getString("name", "Unnamed");
this.name = MythicLib.plugin.parseColors(unparsedName);
this.name = config.getString("name", "Unnamed");
this.layout = MMOItems.plugin.getLayouts().getLayout(config.getString("layout", "default"));
this.sound = Sound.valueOf(config.getString("sound", "ENTITY_EXPERIENCE_ORB_PICKUP").toUpperCase());
@ -69,8 +66,7 @@ public class CraftingStation extends PostLoadObject {
Validate.notNull(sound, "Crafting station sound must not be null");
this.id = id.toLowerCase().replace("_", "-").replace(" ", "-");
this.unparsedName = name;
this.name = MythicLib.plugin.parseColors(name);
this.name = name;
this.layout = layout;
this.sound = sound;
this.itemOptions = itemOptions;
@ -87,10 +83,6 @@ public class CraftingStation extends PostLoadObject {
return name;
}
public String getUnparsedName() {
return unparsedName;
}
public Layout getLayout() {
return layout;
}

View File

@ -68,7 +68,6 @@ public class StatEdition implements Edition {
@Override
public boolean processInput(String input) {
// apply string input parsers
for (StringInputParser parser : MMOItems.plugin.getStringInputParsers())
input = parser.parseInput(inv.getPlayer(), input);
@ -86,9 +85,7 @@ public class StatEdition implements Edition {
// Success
return true;
} catch (RuntimeException exception) {
// Add message to the FFP
if (!exception.getMessage().isEmpty()) { inv.getFFP().log(FriendlyFeedbackCategory.ERROR, exception.getMessage()); }

View File

@ -4,7 +4,6 @@ import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.api.item.NBTItem;
import io.lumine.mythic.lib.api.util.SmartGive;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.util.MMOUtils;
import net.Indyuce.mmoitems.api.crafting.CraftingStation;
import net.Indyuce.mmoitems.api.crafting.CraftingStatus.CraftingQueue;
import net.Indyuce.mmoitems.api.crafting.CraftingStatus.CraftingQueue.CraftingInfo;
@ -18,6 +17,7 @@ import net.Indyuce.mmoitems.api.event.PlayerUseCraftingStationEvent;
import net.Indyuce.mmoitems.api.item.util.ConfigItems;
import net.Indyuce.mmoitems.api.util.message.Message;
import net.Indyuce.mmoitems.listener.CustomSoundListener;
import net.Indyuce.mmoitems.util.MMOUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
@ -61,8 +61,8 @@ public class CraftingStationView extends PluginInventory {
@Override
public Inventory getInventory() {
Inventory inv = Bukkit.createInventory(this, layout.getSize(),
MythicLib.plugin.getPlaceholderParser().parse(getPlayer(), station.getName().replace("#page#", "" + page).replace("#max#", "" + station.getMaxPage())));
final String title = MythicLib.plugin.parseColors(MythicLib.plugin.getPlaceholderParser().parse(getPlayer(), station.getName().replace("#page#", "" + page).replace("#max#", "" + station.getMaxPage())));
Inventory inv = Bukkit.createInventory(this, layout.getSize(), title);
int min = (page - 1) * layout.getRecipeSlots().size(), max = page * layout.getRecipeSlots().size();
for (int j = min; j < max; j++) {
if (j >= recipes.size()) {

View File

@ -5,10 +5,10 @@ import io.lumine.mythic.lib.api.item.ItemTag;
import io.lumine.mythic.lib.api.item.NBTItem;
import io.lumine.mythic.lib.version.VersionMaterial;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.util.MMOUtils;
import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate;
import net.Indyuce.mmoitems.stat.type.InternalStat;
import net.Indyuce.mmoitems.stat.type.ItemStat;
import net.Indyuce.mmoitems.util.MMOUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
@ -20,11 +20,11 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public class ItemEdition extends EditionInventory {
private static final int[] slots = { 19, 20, 21, 22, 23, 24, 25, 28, 29, 30, 31, 32, 33, 34, 37, 38, 39, 40, 41, 42, 43 };
private static final int[] slots = {19, 20, 21, 22, 23, 24, 25, 28, 29, 30, 31, 32, 33, 34, 37, 38, 39, 40, 41, 42, 43};
public ItemEdition(Player player, MMOItemTemplate template) {
super(player, template);
@ -41,7 +41,7 @@ public class ItemEdition extends EditionInventory {
* the for loop will just let some slots empty
*/
List<ItemStat> appliable = new ArrayList<>(getEdited().getType().getAvailableStats()).stream()
.filter(stat -> stat.hasValidMaterial(getCachedItem()) && !(stat instanceof InternalStat)).collect(Collectors.toList());
.filter(stat -> stat.hasValidMaterial(getCachedItem()) && !(stat instanceof InternalStat)).toList();
Inventory inv = Bukkit.createInventory(this, 54, "Item Edition: " + getEdited().getId());
for (int j = min; j < Math.min(appliable.size(), max); j++) {
@ -50,9 +50,7 @@ public class ItemEdition extends EditionInventory {
ItemMeta meta = item.getItemMeta();
meta.addItemFlags(ItemFlag.values());
meta.setDisplayName(ChatColor.GREEN + stat.getName());
List<String> lore = new ArrayList<>();
for (String s1 : stat.getLore())
lore.add(ChatColor.GRAY + MythicLib.plugin.parseColors(s1));
List<String> lore = MythicLib.plugin.parseColors(Arrays.stream(stat.getLore()).map(s -> ChatColor.GRAY + s).toList());
lore.add("");
stat.whenDisplayed(lore, getEventualStatData(stat));

View File

@ -35,15 +35,14 @@ public class DisplayName extends StringStat implements GemStoneStat {
String format = data.toString();
ItemTier tier = item.getMMOItem().getTier();
format = format.replace("<tier-name>", tier != null ? parser.stripColors(tier.getUnparsedName()) : "");
format = format.replace("<tier-color>", tier != null ? parser.lastColor(tier.getUnparsedName(), true) : "&f");
format = format.replace("<tier-color-cleaned>", tier != null ? parser.lastColor(tier.getUnparsedName(), false) : "");
format = format.replace("<tier-name>", tier != null ? parser.stripColors(tier.getUnparsedName()) : "")
.replace("<tier-color>", tier != null ? parser.lastColor(tier.getUnparsedName(), true) : "&f")
.replace("<tier-color-cleaned>", tier != null ? parser.lastColor(tier.getUnparsedName(), false) : "");
// Is this upgradable?
format = cropUpgrade(format);
if (item.getMMOItem().hasUpgradeTemplate()) {
if (item.getMMOItem().hasUpgradeTemplate())
format = appendUpgradeLevel(format, item.getMMOItem().getUpgradeLevel());
}
item.getMeta().setDisplayName(format);

View File

@ -1,40 +1,29 @@
package net.Indyuce.mmoitems.stat;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.api.util.AltChar;
import io.lumine.mythic.lib.version.VersionMaterial;
import net.Indyuce.mmoitems.ItemStats;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.edition.StatEdition;
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.gui.edition.EditionInventory;
import net.Indyuce.mmoitems.stat.data.StringListData;
import net.Indyuce.mmoitems.stat.type.GemStoneStat;
import net.Indyuce.mmoitems.stat.type.StringListStat;
import org.apache.commons.lang.Validate;
import org.bukkit.ChatColor;
import org.bukkit.event.inventory.InventoryAction;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import io.lumine.mythic.lib.api.util.ui.SilentNumbers;
import org.apache.commons.lang.Validate;
import org.bouncycastle.util.StringList;
import org.bukkit.ChatColor;
import org.bukkit.event.inventory.InventoryAction;
import org.bukkit.event.inventory.InventoryClickEvent;
import com.google.gson.JsonArray;
import com.google.gson.JsonParser;
import net.Indyuce.mmoitems.ItemStats;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.edition.StatEdition;
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem;
import net.Indyuce.mmoitems.gui.edition.EditionInventory;
import net.Indyuce.mmoitems.stat.data.StringListData;
import net.Indyuce.mmoitems.stat.data.random.RandomStatData;
import net.Indyuce.mmoitems.stat.data.type.StatData;
import net.Indyuce.mmoitems.stat.type.GemStoneStat;
import net.Indyuce.mmoitems.stat.type.StringListStat;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.api.item.ItemTag;
import io.lumine.mythic.lib.api.util.AltChar;
import io.lumine.mythic.lib.version.VersionMaterial;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class Lore extends StringListStat implements GemStoneStat {
public Lore() {
super("LORE", VersionMaterial.WRITABLE_BOOK.toMaterial(), "Lore", new String[] { "The item lore." }, new String[] { "all" });
super("LORE", VersionMaterial.WRITABLE_BOOK.toMaterial(), "Lore", new String[]{"The item lore."}, new String[]{"all"});
}
@Override
@ -81,14 +70,13 @@ public class Lore extends StringListStat implements GemStoneStat {
@Override
public void whenDisplayed(List<String> lore, Optional<StringListData> statData) {
if (statData.isPresent()) {
statData.ifPresentOrElse(stringListData -> {
lore.add(ChatColor.GRAY + "Current Value:");
StringListData data = statData.get();
data.getList().forEach(element -> lore.add(ChatColor.GRAY + MythicLib.plugin.parseColors(element)));
} else
lore.add(ChatColor.GRAY + "Current Value: " + ChatColor.RED + "None");
lore.addAll(MythicLib.plugin.parseColors(stringListData.getList()
.stream()
.map(s -> ChatColor.GRAY + s)
.toList()));
}, () -> lore.add(ChatColor.GRAY + "Current Value: " + ChatColor.RED + "None"));
lore.add("");
lore.add(ChatColor.YELLOW + AltChar.listDash + " Click to add a line.");