mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2025-02-01 11:11:21 +01:00
Merge conflicts resolved
This commit is contained in:
parent
129a51a9a9
commit
f070ebd1c4
@ -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();
|
||||
|
@ -436,8 +436,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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -8,8 +8,6 @@ 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;
|
||||
import net.Indyuce.mmoitems.util.ColorUtils;
|
||||
import net.Indyuce.mmoitems.util.MMOUtils;
|
||||
import net.Indyuce.mmoitems.api.Type;
|
||||
import net.Indyuce.mmoitems.api.edition.NewItemEdition;
|
||||
import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate;
|
||||
@ -134,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: ")) + ColorUtils.stripColors(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
|
||||
|
@ -14,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;
|
||||
@ -31,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);
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -31,13 +31,13 @@ import java.util.*;
|
||||
public class PlayerListener implements Listener {
|
||||
private final Map<Player, List<ItemStack>> deathItems = new HashMap<>();
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void loadPlayerData(PlayerJoinEvent event) {
|
||||
MMOItems.plugin.getRecipes().refreshRecipeBook(event.getPlayer());
|
||||
PlayerData.load(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void savePlayerData(PlayerQuitEvent event) {
|
||||
PlayerData.get(event.getPlayer()).save(true);
|
||||
}
|
||||
@ -49,7 +49,11 @@ public class PlayerListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onDeathForUpgradeLoss(@NotNull PlayerDeathEvent event) {
|
||||
// No
|
||||
if (event instanceof Cancellable) { if (((Cancellable) event).isCancelled()) { return; } }
|
||||
if (event instanceof Cancellable) {
|
||||
if (((Cancellable) event).isCancelled()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Supports NPCs
|
||||
if (!PlayerData.has(event.getEntity())) return;
|
||||
@ -161,7 +165,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 +179,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 +190,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 +203,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() {
|
||||
|
Loading…
Reference in New Issue
Block a user