Merged adventure

This commit is contained in:
Indyuce 2022-12-23 00:13:45 +01:00
commit 0993b6face
6 changed files with 24 additions and 61 deletions

View File

@ -3,6 +3,7 @@ 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;
@ -17,7 +18,6 @@ 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,10 +111,8 @@ 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()));
AdventureUtils.setDisplayName(meta, name.replace("#name#", (amount > 1 ? (ChatColor.WHITE + "" + amount + " x ") : "") + MMOUtils.getDisplayName(item)));
AdventureUtils.setLore(meta, lore);
item.setItemMeta(meta);
return NBTItem.get(item).addTag(new ItemTag("recipeId", craftingRecipe.getId())).toItem();

View File

@ -434,8 +434,8 @@ public class PlayerData {
/**
* Called when the corresponding MMOPlayerData has already been initialized.
*/
public static void load(@NotNull Player player) {
load(player.getUniqueId());
public static @NotNull PlayerData load(@NotNull Player player) {
return load(player.getUniqueId());
}
/**

View File

@ -132,7 +132,7 @@ public class ItemBrowser extends PluginInventory {
* Displays all the items of the chosen Type
* ------------------------------
*/
Inventory inv = Bukkit.createInventory(this, 54, (deleteMode ? ("Delete Mode: ") : ("Item Explorer: ")) + type.getName());
Inventory inv = Bukkit.createInventory(this, 54, (deleteMode ? "Delete Mode: " : "Item Explorer: ") + MythicLib.plugin.getAdventureParser().stripColors(type.getName()));
/*
* Build cool Item Stacks for buttons and sh

View File

@ -1,7 +1,9 @@
package net.Indyuce.mmoitems.stat;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.api.item.ItemTag;
import io.lumine.mythic.lib.api.item.SupportedNBTTagValues;
import io.lumine.mythic.lib.comp.adventure.AdventureParser;
import io.lumine.mythic.lib.version.VersionMaterial;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.ItemTier;
@ -12,7 +14,6 @@ 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;
@ -29,12 +30,14 @@ public class DisplayName extends StringStat implements GemStoneStat {
@Override
public void whenApplied(@NotNull ItemStackBuilder item, @NotNull StringData data) {
final ItemTier tier = item.getMMOItem().getTier();
final AdventureParser parser = MythicLib.plugin.getAdventureParser();
String format = data.toString();
// 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");
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);

View File

@ -1,38 +0,0 @@
package net.Indyuce.mmoitems.util;
import org.bukkit.ChatColor;
import org.jetbrains.annotations.NotNull;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* mmoitems
* 09/11/2022
*
* @author Roch Blondiaux (Kiwix).
*/
public class ColorUtils {
private static final Pattern STRIP_DECORATION_PATTERN = Pattern.compile("(?i)" + '§' + "[K-O]");
private static final Pattern COLOR_TAG_PATTERN = Pattern.compile("(?i)<.*>");
private static final Pattern START_COLOR_TAG_PATTERN = Pattern.compile("(?i)<[^/]*>");
private static final Pattern MINI_MSG_DECORATION_PATTERN = Pattern.compile("(?i)(<|</)(bold|italic|underlined|strikethrough|obfuscated|b|em|i|u|st|obf).*>");
public static @NotNull String stripDecoration(@NotNull String input) {
return "%s%s".formatted(ChatColor.RESET, MINI_MSG_DECORATION_PATTERN.matcher(STRIP_DECORATION_PATTERN.matcher(input).replaceAll("")).replaceAll(""))
.replace('§', '&');
}
public static @NotNull String stripColors(@NotNull String input) {
return ChatColor.stripColor(COLOR_TAG_PATTERN.matcher(input).replaceAll(""));
}
public static @NotNull String getLastColors(@NotNull String input) {
Matcher matcher = START_COLOR_TAG_PATTERN.matcher(input);
String lastMatch = null;
while (matcher.find())
lastMatch = matcher.group();
return lastMatch == null ? ChatColor.getLastColors(input) : lastMatch;
}
}

View File

@ -15,7 +15,6 @@ import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.entity.Trident;
import org.bukkit.event.Cancellable;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
@ -46,10 +45,8 @@ public class PlayerListener implements Listener {
* If the player dies, its time to roll the death-downgrade stat!
*/
@SuppressWarnings("InstanceofIncompatibleInterface")
@EventHandler(priority = EventPriority.MONITOR)
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onDeathForUpgradeLoss(@NotNull PlayerDeathEvent event) {
// No
if (event instanceof Cancellable) { if (((Cancellable) event).isCancelled()) { return; } }
// Supports NPCs
if (!PlayerData.has(event.getEntity())) return;
@ -161,7 +158,7 @@ public class PlayerListener implements Listener {
* player cast abilities or attacks with not the correct stats
*
* @deprecated This does cost some performance and that update
* method NEEDS some improvement in the future
* method NEEDS some improvement in the future
*/
@Deprecated
@EventHandler
@ -175,7 +172,7 @@ public class PlayerListener implements Listener {
* player cast abilities or attacks with not the correct stats
*
* @deprecated This does cost some performance and that update
* method NEEDS some improvement in the future
* method NEEDS some improvement in the future
*/
@Deprecated
@EventHandler
@ -186,11 +183,11 @@ public class PlayerListener implements Listener {
/**
* Some plugins like to interfere with dropping items when the
* player dies, or whatever of that sort.
*
* <p>
* MMOItems would hate to dupe items because of this, as such, we wait
* 3 ticks for those plugins to reasonably complete their operations and
* then downgrade the items the player still has equipped.
*
* <p>
* If a plugin removes items in this time, they will be completely excluded
* and no dupes will be caused, and if a plugin adds items, they will be
* included and downgraded. I think that's reasonable behaviour.
@ -199,9 +196,12 @@ public class PlayerListener implements Listener {
*/
private static class DelayedDeathDowngrade extends BukkitRunnable {
@NotNull final PlayerDeathEvent event;
@NotNull
final PlayerDeathEvent event;
DelayedDeathDowngrade(@NotNull PlayerDeathEvent event) {this.event = event;}
DelayedDeathDowngrade(@NotNull PlayerDeathEvent event) {
this.event = event;
}
@Override
public void run() {