Skip to content

Commit

Permalink
Fix stat retrocompatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Sentropic committed Mar 1, 2024
1 parent d0872b9 commit 5eff4a6
Show file tree
Hide file tree
Showing 20 changed files with 96 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ public class ItemTags {
public static final String TAG_ITEM_LEVEL = "ITEM_LEVEL";
public static final String TAG_ITEM_SOCKET_RATE = "ITEM_SOCKET_RATE";
public static final String TAG_ITEM_SOCKET = "ITEM_SOCKET_";
public static final String TAG_ITEM_AMMO = "ITEM_AMMO";
public static final String TAG_ITEM_HAND = "ITEM_HAND";
public static final String TAG_ITEM_AMMO = "ITEM_AMMO_";
public static final String TAG_ITEM_HAND = "ITEM_HAND_";
public static final String TAG_ITEM_CHARGES = "ITEM_CHARGES";
public static final String TAG_ITEM_STAT = "ITEM_STAT_";
public static final String TAG_ITEM_DAMAGE = "ITEM_DAMAGE_";
Expand All @@ -19,7 +19,7 @@ public class ItemTags {
public static final String TAG_REQ_USER_LEVEL = "ITEM_USER_LEVEL";
public static final String TAG_REQ_USER_CLASS = "ITEM_USER_CLASS";
public static final String TAG_REQ_USER_BANNED_CLASS = "ITEM_USER_BANNED_CLASS";
public static final String TAG_REQ_USER_OWNER = "ITEM_USER_UUID";
public static final String TAG_REQ_USER_OWNER = "ITEM_USER_UUID_";


public static final String TAG_REQ_ITEM_TYPE = "REQ_ITEM_TYPE";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public abstract class ItemLoreStat<Z> {
protected final String placeholder;
protected final List<NamespacedKey> keys;
protected PersistentDataType<?, Z> dataType;
private final String uniqueMetaTag;
protected final String metaId;

public ItemLoreStat(
Expand All @@ -40,18 +39,11 @@ public ItemLoreStat(
this.name = StringUT.color(name);
this.format = StringUT.color(format.replace("%name%", this.getName()));
this.placeholder = placeholder.toUpperCase();
this.uniqueMetaTag = uniqueTag.toLowerCase();

this.keys = new ArrayList<>();
if (this.uniqueMetaTag.endsWith(this.id)) {
this.metaId = this.uniqueMetaTag;
keys.add(new NamespacedKey(QuantumRPG.getInstance(), this.uniqueMetaTag));
keys.add(new NamespacedKey(QuantumRPG.getInstance(), this.uniqueMetaTag+this.id));
} else {
this.metaId = this.uniqueMetaTag + this.id;
keys.add(new NamespacedKey(QuantumRPG.getInstance(), this.metaId));
}
keys.add(NamespacedKey.fromString("quantumrpg:" + this.getMetaTag() + this.getId()));
uniqueTag = uniqueTag.toLowerCase();
this.metaId = uniqueTag.endsWith(this.id) ? uniqueTag : uniqueTag + this.id;
keys.add(new NamespacedKey(QuantumRPG.getInstance(), this.metaId));

this.dataType = dataType;
}
Expand Down Expand Up @@ -107,11 +99,6 @@ public final NamespacedKey getKey() {
return this.keys.get(0);
}

@NotNull
protected final String getMetaTag() {
return this.uniqueMetaTag;
}

@NotNull
public final String getPlaceholder() {
return this.placeholder;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package su.nightexpress.quantumrpg.stats.items.attributes;

import org.bukkit.Location;
import org.bukkit.NamespacedKey;
import org.bukkit.entity.*;
import org.bukkit.inventory.ItemStack;
import org.bukkit.persistence.PersistentDataType;
Expand All @@ -20,6 +21,11 @@ public AmmoAttribute(
) {
super(type.name(), name, format, ItemTags.PLACEHOLDER_ITEM_AMMO, ItemTags.TAG_ITEM_AMMO, PersistentDataType.STRING);
this.type = type;

// Legacy keys
this.keys.add(NamespacedKey.fromString("prorpgitems:item_ammo" + this.getId()));
this.keys.add(NamespacedKey.fromString("prorpgitems:qrpg_item_ammo" + this.getId()));
this.keys.add(NamespacedKey.fromString("quantumrpg:qrpg_item_ammo" + this.getId()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package su.nightexpress.quantumrpg.stats.items.attributes;

import org.bukkit.NamespacedKey;
import org.bukkit.inventory.ItemStack;
import org.bukkit.persistence.PersistentDataType;
import org.jetbrains.annotations.NotNull;
Expand All @@ -14,6 +15,10 @@ public ChargesAttribute(
@NotNull String format
) {
super("ITEM_CHARGES", name, format, ItemTags.PLACEHOLDER_ITEM_CHARGES, ItemTags.TAG_ITEM_CHARGES, PersistentDataType.INTEGER_ARRAY);

// Legacy keys
this.keys.add(NamespacedKey.fromString("prorpgitems:qrpg_item_chargesitem_charges"));
this.keys.add(NamespacedKey.fromString("quantumrpg:qrpg_item_chargesitem_charges"));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ public DamageAttribute(
this.defenseAttached = null;

ItemStats.registerDynamicStat(this);

// Legacy keys
this.keys.add(NamespacedKey.fromString("prorpgitems:qrpg_item_damage_" + this.getId()));
this.keys.add(NamespacedKey.fromString("quantumrpg:qrpg_item_damage_" + this.getId()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ public DefenseAttribute(
this.protectionFactor = protectionFactor;

ItemStats.registerDynamicStat(this);

// Legacy keys
this.keys.add(NamespacedKey.fromString("prorpgitems:qrpg_item_defense_" + this.getId()));
this.keys.add(NamespacedKey.fromString("quantumrpg:qrpg_item_defense_" + this.getId()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package su.nightexpress.quantumrpg.stats.items.attributes;

import org.bukkit.NamespacedKey;
import org.bukkit.inventory.ItemStack;
import org.bukkit.persistence.PersistentDataType;
import org.jetbrains.annotations.NotNull;
Expand All @@ -17,6 +18,11 @@ public HandAttribute(
) {
super(type.name(), name, format, ItemTags.PLACEHOLDER_ITEM_HAND, ItemTags.TAG_ITEM_HAND, PersistentDataType.STRING);
this.type = type;

// Legacy keys
this.keys.add(NamespacedKey.fromString("prorpgitems:item_hand" + this.getId()));
this.keys.add(NamespacedKey.fromString("prorpgitems:qrpg_item_hand" + this.getId()));
this.keys.add(NamespacedKey.fromString("quantumrpg:qrpg_item_hand" + this.getId()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package su.nightexpress.quantumrpg.stats.items.attributes;

import mc.promcteam.engine.utils.NumberUT;
import org.bukkit.NamespacedKey;
import org.bukkit.inventory.ItemStack;
import org.bukkit.persistence.PersistentDataType;
import org.jetbrains.annotations.NotNull;
Expand All @@ -15,6 +16,9 @@ public SkillAPIAttribute(
@NotNull String name,
@NotNull String format) {
super(id, name, format.replace("%name%", name), "%SKILLAPI_ATTRIBUTE_"+id+"%", ItemTags.TAG_ITEM_SKILLAPI_ATTR, PersistentDataType.INTEGER);

// Legacy keys
this.keys.add(NamespacedKey.fromString("prorpgitems:qrpg_item_skillapi_attr_" + this.getId()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import mc.promcteam.engine.utils.DataUT;
import mc.promcteam.engine.utils.StringUT;
import org.bukkit.NamespacedKey;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -38,13 +39,18 @@ public SocketAttribute(
@NotNull String formatValueEmpty,
@NotNull String formatValueFilled
) {
super(id, name, format, "%SOCKET_" + type.name() + "_" + id + "%", ItemTags.TAG_ITEM_SOCKET + type.name(), DataUT.STRING_ARRAY);
super(id, name, format, "%SOCKET_" + type.name() + "_" + id + "%", ItemTags.TAG_ITEM_SOCKET + type.name() + '_', DataUT.STRING_ARRAY);
this.type = type;
this.tier = tier;

this.name = this.getTier().format(this.name);
this.formatValueEmpty = this.getTier().format(StringUT.color(formatValueEmpty).replace("%name%", this.getName()));
this.formatValueFilled = this.getTier().format(StringUT.color(formatValueFilled).replace("%name%", this.getName()));

// Legacy keys
this.keys.add(NamespacedKey.fromString("prorpgitems:item_socket_" + type.name().toLowerCase() + this.getId()));
this.keys.add(NamespacedKey.fromString("prorpgitems:qrpg_item_socket_" + type.name().toLowerCase() + this.getId()));
this.keys.add(NamespacedKey.fromString("quantumrpg:qrpg_item_socket_" + type.name().toLowerCase() + this.getId()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ public SimpleStat(
this.cap = cap;

ItemStats.registerDynamicStat(this);

// Legacy keys
this.keys.add(NamespacedKey.fromString("prorpgitems:qrpg_item_stat_" + this.getId()));
this.keys.add(NamespacedKey.fromString("quantumrpg:qrpg_item_stat_" + this.getId()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import mc.promcteam.engine.utils.DataUT;
import mc.promcteam.engine.utils.random.Rnd;
import org.bukkit.NamespacedKey;
import org.bukkit.Sound;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.LivingEntity;
Expand Down Expand Up @@ -33,6 +34,10 @@ public DurabilityStat(
ItemTags.TAG_ITEM_STAT,
DataUT.DOUBLE_ARRAY);
this.cap = cap;

// Legacy keys
this.keys.add(NamespacedKey.fromString("prorpgitems:qrpg_item_stat_durability"));
this.keys.add(NamespacedKey.fromString("quantumrpg:qrpg_item_stat_durability"));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package su.nightexpress.quantumrpg.stats.items.requirements.item;

import mc.promcteam.engine.config.api.ILangMsg;
import org.bukkit.NamespacedKey;
import org.bukkit.inventory.ItemStack;
import org.bukkit.persistence.PersistentDataType;
import org.jetbrains.annotations.NotNull;
Expand All @@ -23,6 +24,10 @@ public ItemLevelRequirement(
ItemTags.PLACEHOLDER_REQ_ITEM_LEVEL,
ItemTags.TAG_REQ_ITEM_LEVEL,
PersistentDataType.INTEGER_ARRAY);

// Legacy keys
this.keys.add(NamespacedKey.fromString("prorpgitems:qrpg_req_item_levellevel"));
this.keys.add(NamespacedKey.fromString("quantumrpg:qrpg_req_item_levellevel"));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import mc.promcteam.engine.modules.IModule;
import mc.promcteam.engine.utils.DataUT;
import org.apache.commons.lang.ArrayUtils;
import org.bukkit.NamespacedKey;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import su.nightexpress.quantumrpg.QuantumRPG;
Expand Down Expand Up @@ -31,6 +32,10 @@ public ItemModuleRequirement(
ItemTags.PLACEHOLDER_REQ_ITEM_MODULE,
ItemTags.TAG_REQ_ITEM_LEVEL,
DataUT.STRING_ARRAY);

// Legacy keys
this.keys.add(NamespacedKey.fromString("prorpgitems:qrpg_req_item_levelmodule"));
this.keys.add(NamespacedKey.fromString("quantumrpg:qrpg_req_item_levelmodule"));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import mc.promcteam.engine.config.api.ILangMsg;
import mc.promcteam.engine.utils.DataUT;
import org.apache.commons.lang.ArrayUtils;
import org.bukkit.NamespacedKey;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import su.nightexpress.quantumrpg.QuantumRPG;
Expand All @@ -24,6 +25,10 @@ public ItemSocketRequirement(
ItemTags.PLACEHOLDER_REQ_ITEM_SOCKET,
ItemTags.TAG_REQ_ITEM_SOCKET,
DataUT.STRING_ARRAY);

// Legacy keys
this.keys.add(NamespacedKey.fromString("prorpgitems:qrpg_req_item_socketsocket"));
this.keys.add(NamespacedKey.fromString("quantumrpg:qrpg_req_item_socketsocket"));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package su.nightexpress.quantumrpg.stats.items.requirements.item;

import mc.promcteam.engine.config.api.ILangMsg;
import org.bukkit.NamespacedKey;
import org.bukkit.inventory.ItemStack;
import org.bukkit.persistence.PersistentDataType;
import org.jetbrains.annotations.NotNull;
Expand All @@ -22,6 +23,10 @@ public ItemTierRequirement(@NotNull String name, @NotNull String format) {
ItemTags.PLACEHOLDER_REQ_ITEM_TIER,
ItemTags.TAG_REQ_ITEM_TIER,
PersistentDataType.STRING);

// Legacy keys
this.keys.add(NamespacedKey.fromString("prorpgitems:qrpg_req_item_tiertier"));
this.keys.add(NamespacedKey.fromString("quantumrpg:qrpg_req_item_tiertier"));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import mc.promcteam.engine.config.api.ILangMsg;
import mc.promcteam.engine.utils.DataUT;
import org.apache.commons.lang.ArrayUtils;
import org.bukkit.NamespacedKey;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import su.nightexpress.quantumrpg.QuantumRPG;
Expand All @@ -25,6 +26,10 @@ public ItemTypeRequirement(
ItemTags.PLACEHOLDER_REQ_ITEM_TYPE,
ItemTags.TAG_REQ_ITEM_TYPE,
DataUT.STRING_ARRAY);

// Legacy keys
this.keys.add(NamespacedKey.fromString("prorpgitems:qrpg_req_item_typetype"));
this.keys.add(NamespacedKey.fromString("quantumrpg:qrpg_req_item_typetype"));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package su.nightexpress.quantumrpg.stats.items.requirements.user;

import mc.promcteam.engine.utils.DataUT;
import org.bukkit.NamespacedKey;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import su.nightexpress.quantumrpg.stats.items.ItemTags;
Expand All @@ -26,6 +27,11 @@ public AbstractOwnerRequirement(
ItemTags.TAG_REQ_USER_OWNER,
DataUT.UUID
);

// Legacy keys
this.keys.add(NamespacedKey.fromString("prorpgitems:item_user_uuid" + this.getId()));
this.keys.add(NamespacedKey.fromString("prorpgitems:qrpg_item_user_uuid" + this.getId()));
this.keys.add(NamespacedKey.fromString("quantumrpg:qrpg_item_user_uuid" + this.getId()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ public BannedClassRequirement(@NotNull String name, @NotNull String format) {
ItemTags.PLACEHOLDER_REQ_USER_BANNED_CLASS,
ItemTags.TAG_REQ_USER_BANNED_CLASS,
DataUT.STRING_ARRAY);
this.keys.add(NamespacedKey.fromString("prorpgitems:item_user_banned_classbanned-class"));

// Legacy keys
this.keys.add(NamespacedKey.fromString("prorpgitems:qrpg_item_user_banned_classbanned-class"));
this.keys.add(NamespacedKey.fromString("quantumrpg:qrpg_item_user_banned_classbanned-class"));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import mc.promcteam.engine.config.api.ILangMsg;
import mc.promcteam.engine.utils.DataUT;
import org.bukkit.NamespacedKey;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
Expand All @@ -27,6 +28,10 @@ public ClassRequirement(
ItemTags.PLACEHOLDER_REQ_USER_CLASS,
ItemTags.TAG_REQ_USER_CLASS,
DataUT.STRING_ARRAY);

// Legacy keys
this.keys.add(NamespacedKey.fromString("prorpgitems:qrpg_item_user_classclass"));
this.keys.add(NamespacedKey.fromString("quantumrpg:qrpg_item_user_classclass"));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package su.nightexpress.quantumrpg.stats.items.requirements.user;

import mc.promcteam.engine.config.api.ILangMsg;
import org.bukkit.NamespacedKey;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.persistence.PersistentDataType;
Expand All @@ -24,6 +25,10 @@ public LevelRequirement(
ItemTags.PLACEHOLDER_REQ_USER_LEVEL,
ItemTags.TAG_REQ_USER_LEVEL,
PersistentDataType.INTEGER_ARRAY);

// Legacy keys
this.keys.add(NamespacedKey.fromString("prorpgitems:qrpg_item_user_levellevel"));
this.keys.add(NamespacedKey.fromString("quantumrpg:qrpg_item_user_levellevel"));
}

@Override
Expand Down

0 comments on commit 5eff4a6

Please sign in to comment.