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;
@ -73,19 +72,13 @@ public class QueueItemDisplay extends ConfigItem {
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.addTag(new ItemTag("queueId", crafting.getUniqueId().toString()))
return NBTItem.get(item)
.addTag(new ItemTag("queueId", crafting.getUniqueId().toString()))
.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;
@ -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,20 +55,17 @@ 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) {
if (lvlOFFSET < 0)
return format;
}
String sB4 = suffix.substring(0, lvlOFFSET);
String aFt = suffix.substring(lvlOFFSET + "#lvl#".length());
String sB4_alt = sB4.replace("+", "-");
@ -136,7 +134,6 @@ public class DisplayName extends StringStat implements GemStoneStat {
} //*/
//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;
}