mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2025-02-02 11:21:20 +01:00
Removed dyn lore occurences
This commit is contained in:
parent
46974b3202
commit
d4cbc3d051
@ -1,108 +0,0 @@
|
||||
package net.Indyuce.mmoitems.api.item.util;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import io.lumine.mythic.lib.MythicLib;
|
||||
import io.lumine.mythic.lib.api.item.NBTItem;
|
||||
import io.lumine.mythic.lib.api.util.LegacyComponent;
|
||||
import io.lumine.mythic.utils.adventure.text.Component;
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.stat.type.DynamicLoreStat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Stats like durability and consumable consume amounts need lore updates.
|
||||
* Dynamic lore is basically the default item lore with dynamic placeholders
|
||||
* marked with % instead of #.
|
||||
* <p>
|
||||
* Lore with unparsed dynamic placeholders is stored as a JSon array in MMOITEMS_DYNAMIC_LORE.
|
||||
* Its placeholders are parsed when using the #apply() method of this class.
|
||||
* <p>
|
||||
* Any plugin can now register extra stats with dynamic placeholders too
|
||||
* with {@link DynamicLoreStat}
|
||||
*
|
||||
* @author aria rewritten by indyuce
|
||||
*
|
||||
* @deprecated See {@link LoreUpdate}
|
||||
*/
|
||||
@Deprecated
|
||||
public class DynamicLore {
|
||||
private final NBTItem item;
|
||||
|
||||
/**
|
||||
* Constructor used when building an item
|
||||
*
|
||||
* @param item Item being built
|
||||
*/
|
||||
public DynamicLore(NBTItem item) {
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
public void update(List<String> lore) {
|
||||
for (int j = 0; j < lore.size(); j++)
|
||||
lore.set(j, applyDynamicLore(lore.get(j)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id The stat identifier
|
||||
* @return The corresponding stat, if found, which supports dynamic lore
|
||||
*/
|
||||
private DynamicLoreStat getCorrespondingStat(String id) {
|
||||
for (DynamicLoreStat stat : MMOItems.plugin.getStats().getDynamicLores())
|
||||
if (("%" + stat.getDynamicLoreId() + "%").equals(id))
|
||||
return stat;
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param input Lore line
|
||||
* @return Line with dynamic placeholders parsed
|
||||
*/
|
||||
private String applyDynamicLore(String input) {
|
||||
|
||||
// No dynamic lore for this line.
|
||||
if (!input.startsWith("%") || !input.endsWith("%"))
|
||||
return input;
|
||||
|
||||
/*
|
||||
* External plugins can now register stats with dynamic lore.
|
||||
* This can be used by RPG plugins to have attribute requirements
|
||||
* change color based on if they are met by the player or not.
|
||||
*/
|
||||
DynamicLoreStat stat = getCorrespondingStat(input);
|
||||
if (stat == null)
|
||||
return "<StatNotFound>";
|
||||
|
||||
return stat.calculatePlaceholder(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply all the necessary dynamic lore updates for an item
|
||||
*/
|
||||
public static void update(NBTItem item) {
|
||||
|
||||
// Backwards compatibility for items which do not have dynamic lores
|
||||
if (!item.hasTag("MMOITEMS_DYNAMIC_LORE"))
|
||||
return;
|
||||
|
||||
DynamicLore dynamic = new DynamicLore(item);
|
||||
JsonArray array = MythicLib.plugin.getJson().parse(item.getString("MMOITEMS_DYNAMIC_LORE"), JsonArray.class);
|
||||
List<Component> lore = new ArrayList<>(array.size());
|
||||
|
||||
for (JsonElement line : array) {
|
||||
if (line == null)
|
||||
continue;
|
||||
|
||||
String asString = line.getAsString();
|
||||
if (asString == null)
|
||||
continue;
|
||||
|
||||
lore.add(LegacyComponent.parse(dynamic.applyDynamicLore(asString)));
|
||||
}
|
||||
|
||||
item.setLoreComponents(lore);
|
||||
}
|
||||
}
|
||||
|
@ -24,12 +24,6 @@ public class StatManager {
|
||||
private final Set<ConsumableItemInteraction> consumableActions = new HashSet<>();
|
||||
private final Set<PlayerConsumable> playerConsumables = new HashSet<>();
|
||||
|
||||
/**
|
||||
* @deprecated See {@link net.Indyuce.mmoitems.api.item.util.LoreUpdate}
|
||||
*/
|
||||
@Deprecated
|
||||
private final Set<DynamicLoreStat> dynamicLores = new HashSet<>();
|
||||
|
||||
/*
|
||||
* load default stats using java reflection, get all public static final
|
||||
* fields in the ItemStat and register them as stat instances
|
||||
@ -48,14 +42,6 @@ public class StatManager {
|
||||
return stats.values();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection of all stats which feature dynamic lore support
|
||||
* @deprecated See {@link net.Indyuce.mmoitems.api.item.util.LoreUpdate}
|
||||
*/
|
||||
public Set<DynamicLoreStat> getDynamicLores() {
|
||||
return dynamicLores;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection of all stats which are based on vanilla player
|
||||
* attributes like movement speed, attack damage, max health..
|
||||
@ -148,9 +134,6 @@ public class StatManager {
|
||||
if (stat instanceof PlayerConsumable)
|
||||
playerConsumables.add((PlayerConsumable) stat);
|
||||
|
||||
if (stat instanceof DynamicLoreStat)
|
||||
dynamicLores.add((DynamicLoreStat) stat);
|
||||
|
||||
/**
|
||||
* Cache stat for every type which may have this stat. Really important
|
||||
* otherwise the stat will NOT be used anywhere in the plugin. This
|
||||
|
@ -1,17 +1,15 @@
|
||||
package net.Indyuce.mmoitems.stat;
|
||||
|
||||
import io.lumine.mythic.lib.api.item.ItemTag;
|
||||
import io.lumine.mythic.lib.api.item.NBTItem;
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
|
||||
import net.Indyuce.mmoitems.stat.data.DoubleData;
|
||||
import net.Indyuce.mmoitems.stat.data.type.StatData;
|
||||
import net.Indyuce.mmoitems.stat.type.DoubleStat;
|
||||
import net.Indyuce.mmoitems.stat.type.DynamicLoreStat;
|
||||
import org.bukkit.Material;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class MaxConsume extends DoubleStat implements DynamicLoreStat {
|
||||
public class MaxConsume extends DoubleStat {
|
||||
public MaxConsume() {
|
||||
super("MAX_CONSUME", Material.BLAZE_POWDER, "Max Consume", new String[]{"Max amount of usage before", "item disappears."}, new String[]{"consumable"});
|
||||
}
|
||||
@ -25,15 +23,4 @@ public class MaxConsume extends DoubleStat implements DynamicLoreStat {
|
||||
String format = MMOItems.plugin.getLanguage().getStatFormat("max-consume").replace("#", "" + left);
|
||||
item.getLore().insert("max-consume", format);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDynamicLoreId() {
|
||||
return "max-consume";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String calculatePlaceholder(NBTItem item) {
|
||||
int left = item.getInteger("MMOITEMS_MAX_CONSUME");
|
||||
return MMOItems.plugin.getLanguage().getStatFormat("max-consume").replace("#", "" + left);
|
||||
}
|
||||
}
|
||||
|
@ -1,37 +0,0 @@
|
||||
package net.Indyuce.mmoitems.stat.type;
|
||||
|
||||
import io.lumine.mythic.lib.api.item.NBTItem;
|
||||
|
||||
/**
|
||||
* The primordial problem is recalculating the item lore without having
|
||||
* to rebuild the entire item which would be too performance heavy.
|
||||
* <p>
|
||||
* Dynamic lore makes it so that you don't have to build it to update the lore.
|
||||
* <p>
|
||||
* See {@link net.Indyuce.mmoitems.api.item.util.DynamicLore}
|
||||
*
|
||||
* @author indyuce
|
||||
* @deprecated Now using {@link net.Indyuce.mmoitems.api.item.util.LoreUpdate}
|
||||
*/
|
||||
@Deprecated
|
||||
public interface DynamicLoreStat {
|
||||
|
||||
/**
|
||||
* The piece of text you would use in the lore format to reference this item stat.
|
||||
* <p>
|
||||
* Has to be lower case.
|
||||
*
|
||||
* @deprecated Not used anymore internally since dynamic placeholders are now
|
||||
* stored as every other placeholders in stats.yml
|
||||
*/
|
||||
@Deprecated
|
||||
public String getDynamicLoreId();
|
||||
|
||||
/**
|
||||
* Placeholder
|
||||
*
|
||||
* @param item
|
||||
* @return Null if the item does not have this stat,
|
||||
*/
|
||||
public String calculatePlaceholder(NBTItem item);
|
||||
}
|
Loading…
Reference in New Issue
Block a user