Added Internal Revision IDs to update items when devs make breaking changes.

This commit is contained in:
Ethan 2020-12-08 13:03:32 -05:00
parent 7aa189ad4c
commit 6668f76fb7
5 changed files with 41 additions and 3 deletions

View File

@ -25,6 +25,7 @@ import net.Indyuce.mmoitems.stat.HideDye;
import net.Indyuce.mmoitems.stat.HideEnchants;
import net.Indyuce.mmoitems.stat.HidePotionEffects;
import net.Indyuce.mmoitems.stat.Inedible;
import net.Indyuce.mmoitems.stat.InternalRevisionID;
import net.Indyuce.mmoitems.stat.ItemDamage;
import net.Indyuce.mmoitems.stat.ItemLevel;
import net.Indyuce.mmoitems.stat.ItemParticles;
@ -238,5 +239,6 @@ public class ItemStats {
// Internal Stats
SOULBOUND = new Soulbound(),
STORED_TAGS = new StoredTags(),
ITEM_LEVEL = new ItemLevel();
ITEM_LEVEL = new ItemLevel(),
INTERNAL_REVISION_ID = new InternalRevisionID();
}

View File

@ -89,6 +89,9 @@ import java.util.logging.Level;
public class MMOItems extends JavaPlugin {
public static MMOItems plugin;
// Increment this when making breaking changes to items.
public static int INTERNAL_REVISION_ID = 1;
private final PluginUpdateManager pluginUpdateManager = new PluginUpdateManager();
private final CraftingManager stationRecipeManager = new CraftingManager();
private final LoreFormatManager formatManager = new LoreFormatManager();

View File

@ -63,6 +63,8 @@ public class ItemStackBuilder {
tags.add(new ItemTag("MMOITEMS_ITEM_TYPE", mmoitem.getType().getId()));
tags.add(new ItemTag("MMOITEMS_ITEM_ID", mmoitem.getId()));
if (MMOItems.INTERNAL_REVISION_ID > 1)
tags.add(new ItemTag("MMOITEMS_INTERNAL_REVISION_ID", MMOItems.INTERNAL_REVISION_ID));
/*if (MMOItems.plugin.getUpdater().hasData(mmoitem))
tags.add(new ItemTag("MMOITEMS_ITEM_UUID",

View File

@ -86,8 +86,10 @@ public class ItemListener implements Listener {
/* Whether or not data should be kept when updating an item to latest revision. */
private boolean shouldUpdate(NBTItem nbt, String type) {
if(!MMOItems.plugin.getTemplates().hasTemplate(nbt)) return false;
return !MMOItems.plugin.getConfig().getBoolean("item-revision.disable-on." + type) &&
(MMOItems.plugin.getTemplates().getTemplate(nbt).getRevisionId() > (nbt.hasTag("MMOITEMS_REVISION_ID")
? nbt.getInteger("MMOITEMS_REVISION_ID") : 1));
((MMOItems.plugin.getTemplates().getTemplate(nbt).getRevisionId() > (nbt.hasTag("MMOITEMS_REVISION_ID")
? nbt.getInteger("MMOITEMS_REVISION_ID") : 1)) || (MMOItems.INTERNAL_REVISION_ID >
(nbt.hasTag("MMOITEMS_INTERNAL_REVISION_ID") ? nbt.getInteger("MMOITEMS_INTERNAL_REVISION_ID") : 1)) );
}
}

View File

@ -0,0 +1,29 @@
package net.Indyuce.mmoitems.stat;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem;
import net.Indyuce.mmoitems.stat.data.DoubleData;
import net.Indyuce.mmoitems.stat.data.type.StatData;
import net.Indyuce.mmoitems.stat.type.InternalStat;
import net.mmogroup.mmolib.api.item.ItemTag;
import org.bukkit.Material;
public class InternalRevisionID extends InternalStat {
public InternalRevisionID() {
super("INTERNAL_REVISION_ID", Material.ITEM_FRAME, "Internal Revision ID", new String[] { "The Internal Revision ID is used to determine",
"if an item is outdated or not. You", "should increase this whenever", "you make changes to your item!"},
new String[] { "all" });
}
@Override
public void whenApplied(ItemStackBuilder item, StatData data) {
item.addItemTag(new ItemTag(getNBTPath(), MMOItems.INTERNAL_REVISION_ID));
}
@Override
public void whenLoaded(ReadMMOItem mmoitem) {
if (mmoitem.getNBT().hasTag(getNBTPath()))
mmoitem.setData(this, new DoubleData(mmoitem.getNBT().getInteger(getNBTPath())));
}
}