Merge remote-tracking branch 'origin/adventure-like-impl'

# Conflicts:
#	MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/item/util/crafting/CraftingRecipeDisplay.java
#	MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/ItemBrowser.java
#	MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/DisplayName.java
This commit is contained in:
Indyuce 2022-12-22 12:30:40 +01:00
commit b9b61b1616
6 changed files with 139 additions and 160 deletions

View File

@ -3,7 +3,6 @@ package net.Indyuce.mmoitems.api.item.util.crafting;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.api.item.ItemTag;
import io.lumine.mythic.lib.api.item.NBTItem;
import io.lumine.mythic.lib.util.AdventureUtils;
import net.Indyuce.mmoitems.api.crafting.ConditionalDisplay;
import net.Indyuce.mmoitems.api.crafting.condition.CheckedCondition;
import net.Indyuce.mmoitems.api.crafting.recipe.CheckedRecipe;
@ -18,6 +17,7 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.*;
import java.util.stream.Collectors;
public class CraftingRecipeDisplay extends ConfigItem {
public CraftingRecipeDisplay() {
@ -111,18 +111,13 @@ public class CraftingRecipeDisplay extends ConfigItem {
ItemMeta meta = item.getItemMeta();
meta.addItemFlags(ItemFlag.values());
meta.setDisplayName(MythicLib.plugin.parseColors(name.replace("#name#", (amount > 1 ? (ChatColor.WHITE + "" + amount + " x ") : "") + MMOUtils.getDisplayName(item))));
meta.setLore(lore.stream()
.map(s -> MythicLib.plugin.parseColors(s))
.collect(Collectors.toList()));
item.setItemMeta(meta);
NBTItem nbtItem = NBTItem.get(item);
// Name
nbtItem.setDisplayNameComponent(AdventureUtils.asComponent(name.replace("#name#", (amount > 1 ? (ChatColor.WHITE + "" + amount + " x ") : "") + MMOUtils.getDisplayName(item))));
// Lore
List<String> formattedLore = MythicLib.plugin.parseColors(lore);
nbtItem.setLoreComponents(formattedLore.stream()
.map(AdventureUtils::asComponent)
.toList());
return nbtItem.addTag(new ItemTag("recipeId", craftingRecipe.getId())).toItem();
return NBTItem.get(item).addTag(new ItemTag("recipeId", craftingRecipe.getId())).toItem();
}
}
}

View File

@ -1,6 +1,5 @@
package net.Indyuce.mmoitems.api.item.util.crafting;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.api.item.ItemTag;
import io.lumine.mythic.lib.api.item.NBTItem;
import io.lumine.mythic.lib.util.AdventureUtils;
@ -14,93 +13,87 @@ import org.bukkit.inventory.meta.ItemMeta;
import java.util.*;
public class QueueItemDisplay extends ConfigItem {
private static final long[] ms = { 1000, 60 * 1000, 60 * 60 * 1000, 24 * 60 * 60 * 1000 };
private static final String[] chars = { "s", "m", "h", "d" };
private static final long[] ms = {1000, 60 * 1000, 60 * 60 * 1000, 24 * 60 * 60 * 1000};
private static final String[] chars = {"s", "m", "h", "d"};
public QueueItemDisplay() {
super("QUEUE_ITEM_DISPLAY", Material.BARRIER, "&6&lQueue&f #name#", "{ready}&7&oThis item was successfully crafted.",
"{queue}&7&oThis item is in the crafting queue.", "{queue}", "{queue}&7Time Left: &c#left#", "", "{ready}&eClick to claim!",
"{queue}&eClick to cancel.");
}
public QueueItemDisplay() {
super("QUEUE_ITEM_DISPLAY", Material.BARRIER, "&6&lQueue&f #name#", "{ready}&7&oThis item was successfully crafted.",
"{queue}&7&oThis item is in the crafting queue.", "{queue}", "{queue}&7Time Left: &c#left#", "", "{ready}&eClick to claim!",
"{queue}&eClick to cancel.");
}
public ItemBuilder newBuilder(CraftingInfo crafting, int position) {
return new ItemBuilder(crafting, position);
}
public ItemBuilder newBuilder(CraftingInfo crafting, int position) {
return new ItemBuilder(crafting, position);
}
public class ItemBuilder {
private final CraftingInfo crafting;
private final int position;
public class ItemBuilder {
private final CraftingInfo crafting;
private final int position;
private final String name = getName();
private final List<String> lore = new ArrayList<>(getLore());
private final String name = getName();
private final List<String> lore = new ArrayList<>(getLore());
public ItemBuilder(CraftingInfo crafting, int position) {
this.crafting = crafting;
this.position = position;
}
public ItemBuilder(CraftingInfo crafting, int position) {
this.crafting = crafting;
this.position = position;
}
public ItemStack build() {
Map<String, String> replace = new HashMap<>();
public ItemStack build() {
Map<String, String> replace = new HashMap<>();
for (Iterator<String> iterator = lore.iterator(); iterator.hasNext();) {
String str = iterator.next();
for (Iterator<String> iterator = lore.iterator(); iterator.hasNext(); ) {
String str = iterator.next();
/*
* crafting time
*/
if (str.startsWith("{queue}")) {
if (crafting.isReady()) {
iterator.remove();
continue;
}
/*
* crafting time
*/
if (str.startsWith("{queue}")) {
if (crafting.isReady()) {
iterator.remove();
continue;
}
replace.put(str, str.replace("{queue}", ""));
}
replace.put(str, str.replace("{queue}", ""));
}
if (str.startsWith("{ready}")) {
if (!crafting.isReady()) {
iterator.remove();
continue;
}
if (str.startsWith("{ready}")) {
if (!crafting.isReady()) {
iterator.remove();
continue;
}
replace.put(str, str.replace("{ready}", ""));
}
}
replace.put(str, str.replace("{ready}", ""));
}
}
for (String key : replace.keySet())
lore.set(lore.indexOf(key), replace.get(key).replace("#left#", formatDelay(crafting.getLeft())));
for (String key : replace.keySet())
lore.set(lore.indexOf(key), replace.get(key).replace("#left#", formatDelay(crafting.getLeft())));
ItemStack item = crafting.getRecipe().getPreviewItemStack();
item.setAmount(position);
ItemMeta meta = item.getItemMeta();
meta.addItemFlags(ItemFlag.values());
item.setItemMeta(meta);
ItemStack item = crafting.getRecipe().getPreviewItemStack();
item.setAmount(position);
ItemMeta meta = item.getItemMeta();
AdventureUtils.setDisplayName(meta, name.replace("#name#", meta.getDisplayName()));
AdventureUtils.setLore(meta, lore);
meta.addItemFlags(ItemFlag.values());
item.setItemMeta(meta);
NBTItem nbtItem = NBTItem.get(item);
// Name
nbtItem.setDisplayNameComponent(AdventureUtils.asComponent(name.replace("#name#", meta.getDisplayName())));
// Lore
List<String> formattedLore = MythicLib.plugin.parseColors(lore);
nbtItem.setLoreComponents(formattedLore.stream()
.map(AdventureUtils::asComponent)
.toList());
return NBTItem.get(item)
.addTag(new ItemTag("queueId", crafting.getUniqueId().toString()))
.toItem();
}
}
return nbtItem.addTag(new ItemTag("queueId", crafting.getUniqueId().toString()))
.toItem();
}
}
private String formatDelay(long delay) {
StringBuilder format = new StringBuilder();
private String formatDelay(long delay) {
StringBuilder format = new StringBuilder();
int n = 0;
for (int j = ms.length - 1; j >= 0 && n < 2; j--)
if (delay >= ms[j]) {
format.append(delay / ms[j]).append(chars[j]).append(" ");
delay = delay % ms[j];
n++;
}
int n = 0;
for (int j = ms.length - 1; j >= 0 && n < 2; j--)
if (delay >= ms[j]) {
format.append(delay / ms[j]).append(chars[j]).append(" ");
delay = delay % ms[j];
n++;
}
return (format.length() == 0) ? "1s" : format.toString();
}
return (format.length() == 0) ? "1s" : format.toString();
}
}

View File

@ -1,6 +1,5 @@
package net.Indyuce.mmoitems.api.item.util.crafting;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.api.item.ItemTag;
import io.lumine.mythic.lib.api.item.NBTItem;
import io.lumine.mythic.lib.util.AdventureUtils;
@ -81,19 +80,12 @@ public class UpgradingRecipeDisplay extends ConfigItem {
ItemStack item = upgradingRecipe.getItem().getPreview();
ItemMeta meta = item.getItemMeta();
AdventureUtils.setDisplayName(meta, name.replace("#name#", MMOUtils.getDisplayName(item)));
AdventureUtils.setLore(meta, lore);
meta.addItemFlags(ItemFlag.values());
item.setItemMeta(meta);
NBTItem nbtItem = NBTItem.get(item);
// Name
nbtItem.setDisplayNameComponent(AdventureUtils.asComponent(name.replace("#name#", MMOUtils.getDisplayName(item))));
// Lore
List<String> formattedLore = MythicLib.plugin.parseColors(lore);
nbtItem.setLoreComponents(formattedLore.stream()
.map(AdventureUtils::asComponent)
.toList());
return nbtItem.addTag(new ItemTag("recipeId", recipe.getRecipe().getId())).toItem();
return NBTItem.get(item).addTag(new ItemTag("recipeId", recipe.getRecipe().getId())).toItem();
}
}
}

View File

@ -153,21 +153,19 @@ public class CraftingStationPreview extends PluginInventory {
NBTItem nbtItem = MythicLib.plugin.getVersion().getWrapper().getNBTItem(event.getCurrentItem());
switch (nbtItem.getString("ItemId")) {
case "CONFIRM":
case "CONFIRM" -> {
previous.processRecipe(recipe);
previous.open();
break;
case "PREVIOUS_PAGE":
}
case "PREVIOUS_PAGE" -> {
page--;
open();
break;
case "NEXT_PAGE":
}
case "NEXT_PAGE" -> {
page++;
open();
break;
case "BACK":
previous.open();
break;
}
case "BACK" -> previous.open();
}
}
}

View File

@ -8,6 +8,11 @@ import io.lumine.mythic.lib.api.util.ui.SilentNumbers;
import io.lumine.mythic.lib.util.AdventureUtils;
import io.lumine.mythic.lib.version.VersionMaterial;
import net.Indyuce.mmoitems.MMOItems;
<<<<<<<<< Temporary merge branch 1
=========
import net.Indyuce.mmoitems.util.ColorUtils;
import net.Indyuce.mmoitems.util.MMOUtils;
>>>>>>>>> Temporary merge branch 2
import net.Indyuce.mmoitems.api.Type;
import net.Indyuce.mmoitems.api.edition.NewItemEdition;
import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate;

View File

@ -14,6 +14,7 @@ import net.Indyuce.mmoitems.stat.type.GemStoneStat;
import net.Indyuce.mmoitems.stat.type.NameData;
import net.Indyuce.mmoitems.stat.type.StatHistory;
import net.Indyuce.mmoitems.stat.type.StringStat;
import net.Indyuce.mmoitems.util.ColorUtils;
import org.bukkit.ChatColor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -21,6 +22,7 @@ import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
public class DisplayName extends StringStat implements GemStoneStat {
public DisplayName() {
super("NAME", VersionMaterial.OAK_SIGN.toMaterial(), "Display Name", new String[]{"The item display name."},
new String[]{"all"});
@ -28,14 +30,13 @@ public class DisplayName extends StringStat implements GemStoneStat {
@Override
public void whenApplied(@NotNull ItemStackBuilder item, @NotNull StringData data) {
final AdventureParser parser = MythicLib.plugin.getAdventureParser();
// Bake
String format = data.toString();
final ItemTier tier = item.getMMOItem().getTier();
ItemTier tier = item.getMMOItem().getTier();
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) : "");
// Bake
String format = data.toString()
.replace("<tier-name>", tier != null ? ColorUtils.stripColors(tier.getName()) : "")
.replace("<tier-color>", tier != null ? ColorUtils.getLastColors(tier.getName()) : "&f")
.replace("<tier-color-cleaned>", tier != null ? ColorUtils.stripDecoration(ColorUtils.getLastColors(tier.getName())) : "&f");
// Is this upgradable?
format = cropUpgrade(format);
@ -54,69 +55,66 @@ public class DisplayName extends StringStat implements GemStoneStat {
@NotNull
String cropUpgrade(@NotNull String format) {
String suffix = MMOItems.plugin.getConfig().getString("item-upgrading.name-suffix", " &8(&e+#lvl#&8)");
if (suffix == null || suffix.isEmpty()) {
if (suffix == null || suffix.isEmpty())
return format;
}
//MMOItems.getConsole().sendMessage("Level " + upgradeLevel);
//MMOItems.getConsole().sendMessage("Format " + format);
if (suffix != null) {
// Crop lvl
int lvlOFFSET = suffix.indexOf("#lvl#");
if (lvlOFFSET < 0) {
return format;
}
String sB4 = suffix.substring(0, lvlOFFSET);
String aFt = suffix.substring(lvlOFFSET + "#lvl#".length());
String sB4_alt = sB4.replace("+", "-");
String aFt_alt = aFt.replace("+", "-");
// Crop lvl
int lvlOFFSET = suffix.indexOf("#lvl#");
if (lvlOFFSET < 0)
return format;
String sB4 = suffix.substring(0, lvlOFFSET);
String aFt = suffix.substring(lvlOFFSET + "#lvl#".length());
String sB4_alt = sB4.replace("+", "-");
String aFt_alt = aFt.replace("+", "-");
// Remove it
if (format.contains(sB4)) {
// Remove it
if (format.contains(sB4)) {
// Get offsets
int sB4_offset = format.indexOf(sB4);
int aFt_offset = format.lastIndexOf(aFt);
// Get offsets
int sB4_offset = format.indexOf(sB4);
int aFt_offset = format.lastIndexOf(aFt);
// No after = to completion
if (aFt_offset < 0) {
aFt_offset = format.length();
} else {
aFt_offset += aFt.length();
}
// Remove that
String beforePrefix = format.substring(0, sB4_offset);
String afterPrefix = format.substring(aFt_offset);
// Replace
format = beforePrefix + afterPrefix;
// No after = to completion
if (aFt_offset < 0) {
aFt_offset = format.length();
} else {
aFt_offset += aFt.length();
}
// Remove it
if (format.contains(sB4_alt)) {
// Remove that
String beforePrefix = format.substring(0, sB4_offset);
String afterPrefix = format.substring(aFt_offset);
// Get offsets
int sB4_offset = format.indexOf(sB4_alt);
int aFt_offset = format.lastIndexOf(aFt_alt);
// Replace
format = beforePrefix + afterPrefix;
}
// No after = to completion
if (aFt_offset < 0) {
aFt_offset = format.length();
} else {
aFt_offset += aFt_alt.length();
}
// Remove it
if (format.contains(sB4_alt)) {
// Remove that
String beforePrefix = format.substring(0, sB4_offset);
String afterPrefix = format.substring(aFt_offset);
// Get offsets
int sB4_offset = format.indexOf(sB4_alt);
int aFt_offset = format.lastIndexOf(aFt_alt);
// Replace
format = beforePrefix + afterPrefix;
// No after = to completion
if (aFt_offset < 0) {
aFt_offset = format.length();
} else {
aFt_offset += aFt_alt.length();
}
// Remove that
String beforePrefix = format.substring(0, sB4_offset);
String afterPrefix = format.substring(aFt_offset);
// Replace
format = beforePrefix + afterPrefix;
}
/*/ Bake old indices for removal
ArrayList<String> oldSuffixii = new ArrayList<>(); boolean negativity = false;
if (upgradeLevel < 0) { upgradeLevel = -upgradeLevel; negativity = true; }
@ -135,8 +133,7 @@ public class DisplayName extends StringStat implements GemStoneStat {
//MMOItems.getConsole().sendMessage("Edited " + format);
} //*/
//MMOItems.getConsole().sendMessage("Final " + format);
}
//MMOItems.getConsole().sendMessage("Final " + format);
return format;
}
@ -148,7 +145,6 @@ public class DisplayName extends StringStat implements GemStoneStat {
String actSuffix = levelPrefix(suffix, lvl);
return format + actSuffix;
}
return format;
}