Fixed repair and upgrade reference

This commit is contained in:
Jules 2023-11-26 21:53:28 +01:00
parent f200492fb2
commit 11b18f74ae
3 changed files with 18 additions and 16 deletions

View File

@ -209,7 +209,7 @@ public class UpgradeStat extends ItemStat<UpgradeData, UpgradeData> implements C
}
UpgradeData consumableSharpening = (UpgradeData) mmoitem.getData(ItemStats.UPGRADE);
if (!consumableSharpening.matchesReference(targetSharpening)) {
if (!MMOUtils.checkReference(consumableSharpening.getReference(), targetSharpening.getReference())) {
Message.WRONG_UPGRADE_REFERENCE.format(ChatColor.RED).send(player);
player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 2);
return false;

View File

@ -7,6 +7,7 @@ import net.Indyuce.mmoitems.api.item.build.MMOItemBuilder;
import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
import net.Indyuce.mmoitems.stat.data.random.RandomStatData;
import net.Indyuce.mmoitems.stat.data.type.StatData;
import net.Indyuce.mmoitems.util.MMOUtils;
import org.bukkit.configuration.ConfigurationSection;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -145,8 +146,9 @@ public class UpgradeData implements StatData, RandomStatData<UpgradeData> {
return success == 0 ? 1 : success;
}
@Deprecated
public boolean matchesReference(UpgradeData data) {
return reference == null || data.reference == null || reference.isEmpty() || data.reference.isEmpty() || reference.equals(data.reference);
return MMOUtils.checkReference(reference, data.reference);
}
@Override

View File

@ -67,14 +67,12 @@ public class MMOUtils {
/**
* References are helpful to classify items that can interact together.
* They are a piece of text stored as an NBTTag for instance. Items can
* interact (in a certain way) only if the corresponding reference match.
* They are a piece of text stored as an NBTTag for instance. Items are
* only able to interact with items with the same reference, or with
* the universal reference stored in variable {@link #UNIVERSAL_REFERENCE}
* <p>
* Any item can interact with an item with the universal reference 'all'.
* A null/empty reference is considered like the universal reference.
* <p>
* This is a simple symmetrical computation. Used for:
* - for item upgrading TODO
* At the moment, it is being used for:
* - for item upgrading
* - item repairing
*
* @param ref1 First reference
@ -82,7 +80,9 @@ public class MMOUtils {
* @return If items can interact
*/
public static boolean checkReference(@Nullable String ref1, @Nullable String ref2) {
return ref1 == null || ref1.isEmpty() || ref2 == null || ref2.isEmpty() || ref1.equals(UNIVERSAL_REFERENCE) || ref2.equals(UNIVERSAL_REFERENCE) || ref1.equals(ref2);
if (ref1 != null && ref1.equals(UNIVERSAL_REFERENCE)) return true;
if (ref2 != null && ref2.equals(UNIVERSAL_REFERENCE)) return true;
return Objects.equals(ref1, ref2);
}
/**
@ -262,7 +262,7 @@ public class MMOUtils {
*
* @param type Potion effect type
* @return The duration that MMOItems should be using to give player
* "permanent" potion effects, depending on the potion effect type
* "permanent" potion effects, depending on the potion effect type
*/
public static int getEffectDuration(PotionEffectType type) {
return type.equals(PotionEffectType.NIGHT_VISION) || type.equals(PotionEffectType.CONFUSION) ? 260 : type.equals(PotionEffectType.BLINDNESS) ? 140 : 80;
@ -285,7 +285,7 @@ public class MMOUtils {
* @param item The item to check
* @param lore Whether or not MI should check for an item lore
* @return If the item is not null, has an itemMeta and has a display name.
* If 'lore' is true, also checks if the itemMeta has a lore.
* If 'lore' is true, also checks if the itemMeta has a lore.
*/
public static boolean isMetaItem(ItemStack item, boolean lore) {
return item != null && item.getType() != Material.AIR && item.getItemMeta() != null && item.getItemMeta().getDisplayName() != null && (!lore || item.getItemMeta().getLore() != null);
@ -419,10 +419,10 @@ public class MMOUtils {
/**
* @param loc Where we are looking for nearby entities
* @return List of all entities surrounding a location. This method loops
* through the 9 surrounding chunks and collect all entities from
* them. This list can be cached and used multiple times in the same
* tick for projectile based spells which need to run entity
* checkups
* through the 9 surrounding chunks and collect all entities from
* them. This list can be cached and used multiple times in the same
* tick for projectile based spells which need to run entity
* checkups
*/
public static List<Entity> getNearbyChunkEntities(Location loc) {
List<Entity> entities = new ArrayList<>();