Fixed <1.20 startup issue

This commit is contained in:
Jules 2023-11-25 13:46:14 +01:00
parent 724184b67c
commit 81efe1abcd
13 changed files with 76 additions and 59 deletions

View File

@ -1,14 +1,11 @@
package net.Indyuce.mmoitems.api.edition; package net.Indyuce.mmoitems.api.edition;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.edition.input.AnvilGUI;
import net.Indyuce.mmoitems.api.edition.input.ChatEdition; import net.Indyuce.mmoitems.api.edition.input.ChatEdition;
import net.Indyuce.mmoitems.gui.ItemBrowser; import net.Indyuce.mmoitems.gui.ItemBrowser;
import net.Indyuce.mmoitems.gui.PluginInventory; import net.Indyuce.mmoitems.gui.PluginInventory;
import io.lumine.mythic.lib.MythicLib; import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
public class NewItemEdition implements Edition { public class NewItemEdition implements Edition {
private final ItemBrowser inv; private final ItemBrowser inv;
@ -30,15 +27,6 @@ public class NewItemEdition implements Edition {
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Write in the chat, the id of the new item."); inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Write in the chat, the id of the new item.");
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Type 'cancel' to abort editing."); inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Type 'cancel' to abort editing.");
/*
* Anvil text input feature. Enables players to use an anvil to input
* text if they are having conflicts with their chat management plugins.
*/
if (MMOItems.plugin.getConfig().getBoolean("anvil-text-input") && MythicLib.plugin.getVersion().isBelowOrEqual(1, 13)) {
new AnvilGUI(this);
return;
}
// Default chat edition feature // Default chat edition feature
new ChatEdition(this); new ChatEdition(this);
inv.getPlayer().sendTitle(ChatColor.GOLD + "" + ChatColor.BOLD + "Item Creation", "See chat.", 10, 40, 10); inv.getPlayer().sendTitle(ChatColor.GOLD + "" + ChatColor.BOLD + "Item Creation", "See chat.", 10, 40, 10);

View File

@ -47,15 +47,6 @@ public class StatEdition implements Edition {
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + ChatColor.translateAlternateColorCodes('&', line)); inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + ChatColor.translateAlternateColorCodes('&', line));
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Type 'cancel' to abort editing."); inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Type 'cancel' to abort editing.");
/*
* Anvil text input feature. enables players to use an anvil to input
* text if they are having conflicts with their chat management plugins.
*
if (MMOItems.plugin.getConfig().getBoolean("anvil-text-input") && MythicLib.plugin.getVersion().isBelowOrEqual(1, 13)) {
new AnvilGUI(this);
return;
}*/
// Default chat edition feature // Default chat edition feature
new ChatEdition(this); new ChatEdition(this);
inv.getPlayer().sendTitle(ChatColor.GOLD + "" + ChatColor.BOLD + "Item Edition", "See chat.", 10, 40, 10); inv.getPlayer().sendTitle(ChatColor.GOLD + "" + ChatColor.BOLD + "Item Edition", "See chat.", 10, 40, 10);

View File

@ -0,0 +1,19 @@
package net.Indyuce.mmoitems.api.event;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
public class MMOItemsReloadEvent extends Event {
private static final HandlerList handlers = new HandlerList();
@NotNull
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}

View File

@ -74,13 +74,6 @@ public class Tool extends UseItem {
}.runTaskTimer(MMOItems.plugin, 0, 1); }.runTaskTimer(MMOItems.plugin, 0, 1);
} }
/*if (getNBTItem().hasTag("MMOITEMS_BREAK_SIZE")) {
int breakSize = getNBTItem().getInteger("MMOITEMS_BREAK_SIZE");
if(breakSize % 2 != 0) {
BlockFace face = player.getFacing();
System.out.println("Debug: Facing - " + face);
}
}*/
return cancel; return cancel;
} }
} }

View File

@ -3,8 +3,10 @@ package net.Indyuce.mmoitems.command.mmoitems;
import io.lumine.mythic.lib.MythicLib; import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.command.api.CommandTreeNode; import io.lumine.mythic.lib.command.api.CommandTreeNode;
import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.event.MMOItemsReloadEvent;
import net.Indyuce.mmoitems.api.util.MMOItemReforger; import net.Indyuce.mmoitems.api.util.MMOItemReforger;
import net.Indyuce.mmoitems.api.util.NumericStatFormula; import net.Indyuce.mmoitems.api.util.NumericStatFormula;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -53,6 +55,8 @@ public class ReloadCommandTreeNode extends CommandTreeNode {
} }
public void reloadMain(CommandSender sender) { public void reloadMain(CommandSender sender) {
Bukkit.getPluginManager().callEvent(new MMOItemsReloadEvent());
MMOItems.plugin.getLanguage().reload(); MMOItems.plugin.getLanguage().reload();
MMOItems.plugin.getDropTables().reload(); MMOItems.plugin.getDropTables().reload();
MMOItems.plugin.getTypes().reload(); MMOItems.plugin.getTypes().reload();

View File

@ -37,6 +37,7 @@ public class StatManager {
* Load default stats using java reflection, get all public static final * Load default stats using java reflection, get all public static final
* fields in the ItemStat and register them as stat instances * fields in the ItemStat and register them as stat instances
*/ */
@Deprecated
public void load() { public void load() {
for (Field field : ItemStats.class.getFields()) for (Field field : ItemStats.class.getFields())
try { try {

View File

@ -346,7 +346,6 @@ public class TemplateManager implements Reloadable {
* be refreshed afterwards. * be refreshed afterwards.
*/ */
public void reload() { public void reload() {
System.out.println("RELOADING TEMPLATE MANAGER");
templates.clear(); templates.clear();
modifierNodes.clear(); modifierNodes.clear();

View File

@ -1,13 +1,13 @@
package net.Indyuce.mmoitems.stat; package net.Indyuce.mmoitems.stat;
import io.lumine.mythic.lib.api.item.ItemTag; import io.lumine.mythic.lib.api.item.ItemTag;
import io.lumine.mythic.lib.version.VersionMaterial;
import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.ItemStats;
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder; import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem; import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem;
import net.Indyuce.mmoitems.stat.data.BooleanData; import net.Indyuce.mmoitems.stat.data.BooleanData;
import net.Indyuce.mmoitems.stat.data.type.StatData;
import net.Indyuce.mmoitems.stat.type.BooleanStat; import net.Indyuce.mmoitems.stat.type.BooleanStat;
import io.lumine.mythic.lib.version.VersionMaterial; import net.Indyuce.mmoitems.util.VersionDependant;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemFlag;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -19,16 +19,11 @@ import java.util.ArrayList;
* @deprecated Merge with other Hide- stats * @deprecated Merge with other Hide- stats
*/ */
@Deprecated @Deprecated
@VersionDependant(minor = 16, patch = 3)
public class HideDye extends BooleanStat { public class HideDye extends BooleanStat {
public HideDye() { public HideDye() {
super("HIDE_DYE", Material.CYAN_DYE, "Hide Dyed", new String[] { "Enable to hide the 'Dyed' tag from the item." }, new String[] { "all" }, super("HIDE_DYE", Material.CYAN_DYE, "Hide Dyed", new String[] { "Enable to hide the 'Dyed' tag from the item." }, new String[] { "all" },
Material.LEATHER_HELMET, Material.LEATHER_CHESTPLATE, Material.LEATHER_LEGGINGS, Material.LEATHER_BOOTS, VersionMaterial.LEATHER_HORSE_ARMOR.toMaterial()); Material.LEATHER_HELMET, Material.LEATHER_CHESTPLATE, Material.LEATHER_LEGGINGS, Material.LEATHER_BOOTS, VersionMaterial.LEATHER_HORSE_ARMOR.toMaterial());
try {
ItemFlag.valueOf("HIDE_DYE");
} catch(IllegalArgumentException exception) {
disable();
}
} }
@Override @Override

View File

@ -6,6 +6,7 @@ import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem; import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem;
import net.Indyuce.mmoitems.stat.data.BooleanData; import net.Indyuce.mmoitems.stat.data.BooleanData;
import net.Indyuce.mmoitems.stat.type.BooleanStat; import net.Indyuce.mmoitems.stat.type.BooleanStat;
import net.Indyuce.mmoitems.util.VersionDependant;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemFlag;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -17,15 +18,10 @@ import java.util.ArrayList;
* @deprecated Merge with other Hide- stats * @deprecated Merge with other Hide- stats
*/ */
@Deprecated @Deprecated
@VersionDependant(minor = 20)
public class HideTrim extends BooleanStat { public class HideTrim extends BooleanStat {
public HideTrim() { public HideTrim() {
super("HIDE_ARMOR_TRIM", Material.LEATHER_CHESTPLATE, "Hide Armor Trim", new String[]{"Hides armor trim from item lore."}, new String[]{"armor"}); super("HIDE_ARMOR_TRIM", Material.LEATHER_CHESTPLATE, "Hide Armor Trim", new String[]{"Hides armor trim from item lore."}, new String[]{"armor"});
try {
ItemFlag.valueOf("HIDE_ARMOR_TRIM");
} catch (IllegalArgumentException exception) {
disable();
}
} }
@Override @Override

View File

@ -1,12 +1,12 @@
package net.Indyuce.mmoitems.stat; package net.Indyuce.mmoitems.stat;
import io.lumine.mythic.lib.MythicLib;
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder; import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem; import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem;
import net.Indyuce.mmoitems.stat.data.StringData; import net.Indyuce.mmoitems.stat.data.StringData;
import net.Indyuce.mmoitems.stat.type.ChooseStat; import net.Indyuce.mmoitems.stat.type.ChooseStat;
import net.Indyuce.mmoitems.stat.type.GemStoneStat; import net.Indyuce.mmoitems.stat.type.GemStoneStat;
import net.Indyuce.mmoitems.util.StatChoice; import net.Indyuce.mmoitems.util.StatChoice;
import net.Indyuce.mmoitems.util.VersionDependant;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
import org.bukkit.Registry; import org.bukkit.Registry;
@ -20,14 +20,13 @@ import org.jetbrains.annotations.Nullable;
/** /**
* @author Jules * @author Jules
*/ */
@VersionDependant(minor = 20)
public class TrimMaterialStat extends ChooseStat implements GemStoneStat { public class TrimMaterialStat extends ChooseStat implements GemStoneStat {
public TrimMaterialStat() { public TrimMaterialStat() {
super("TRIM_MATERIAL", Material.LEATHER_CHESTPLATE, "Trim Material", new String[]{"Material to trim your armor with."}, new String[]{"armor"}); super("TRIM_MATERIAL", Material.LEATHER_CHESTPLATE, "Trim Material", new String[]{"Material to trim your armor with."}, new String[]{"armor"});
if (MythicLib.plugin.getVersion().isBelowOrEqual(1, 19)) { // Version dependency
disable(); if (!isEnabled()) return;
return;
}
for (TrimMaterial mat : Registry.TRIM_MATERIAL) for (TrimMaterial mat : Registry.TRIM_MATERIAL)
addChoices(new StatChoice(mat.getKey().getKey())); addChoices(new StatChoice(mat.getKey().getKey()));

View File

@ -1,12 +1,12 @@
package net.Indyuce.mmoitems.stat; package net.Indyuce.mmoitems.stat;
import io.lumine.mythic.lib.MythicLib;
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder; import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem; import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem;
import net.Indyuce.mmoitems.stat.data.StringData; import net.Indyuce.mmoitems.stat.data.StringData;
import net.Indyuce.mmoitems.stat.type.ChooseStat; import net.Indyuce.mmoitems.stat.type.ChooseStat;
import net.Indyuce.mmoitems.stat.type.GemStoneStat; import net.Indyuce.mmoitems.stat.type.GemStoneStat;
import net.Indyuce.mmoitems.util.StatChoice; import net.Indyuce.mmoitems.util.StatChoice;
import net.Indyuce.mmoitems.util.VersionDependant;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
import org.bukkit.Registry; import org.bukkit.Registry;
@ -20,14 +20,13 @@ import org.jetbrains.annotations.Nullable;
/** /**
* @author Jules * @author Jules
*/ */
@VersionDependant(minor = 20)
public class TrimPatternStat extends ChooseStat implements GemStoneStat { public class TrimPatternStat extends ChooseStat implements GemStoneStat {
public TrimPatternStat() { public TrimPatternStat() {
super("TRIM_PATTERN", Material.LEATHER_CHESTPLATE, "Trim Pattern", new String[]{"Pattern of trimmed armor."}, new String[]{"armor"}); super("TRIM_PATTERN", Material.LEATHER_CHESTPLATE, "Trim Pattern", new String[]{"Pattern of trimmed armor."}, new String[]{"armor"});
if (MythicLib.plugin.getVersion().isBelowOrEqual(1, 19)) { // Version dependency
disable(); if (!isEnabled()) return;
return;
}
for (TrimPattern mat : Registry.TRIM_PATTERN) for (TrimPattern mat : Registry.TRIM_PATTERN)
addChoices(new StatChoice(mat.getKey().getKey())); addChoices(new StatChoice(mat.getKey().getKey()));

View File

@ -1,5 +1,6 @@
package net.Indyuce.mmoitems.stat.type; package net.Indyuce.mmoitems.stat.type;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.api.item.ItemTag; import io.lumine.mythic.lib.api.item.ItemTag;
import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.api.Type;
@ -8,6 +9,7 @@ import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem;
import net.Indyuce.mmoitems.gui.edition.EditionInventory; import net.Indyuce.mmoitems.gui.edition.EditionInventory;
import net.Indyuce.mmoitems.stat.data.random.RandomStatData; import net.Indyuce.mmoitems.stat.data.random.RandomStatData;
import net.Indyuce.mmoitems.stat.data.type.StatData; import net.Indyuce.mmoitems.stat.data.type.StatData;
import net.Indyuce.mmoitems.util.VersionDependant;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryClickEvent;
@ -58,6 +60,13 @@ public abstract class ItemStat<R extends RandomStatData<S>, S extends StatData>
this.configPath = id.toLowerCase().replace("_", "-"); this.configPath = id.toLowerCase().replace("_", "-");
this.nbtPath = "MMOITEMS_" + id; this.nbtPath = "MMOITEMS_" + id;
// Version dependency
if (getClass().isAnnotationPresent(VersionDependant.class)) {
final VersionDependant implVersion = getClass().getAnnotation(VersionDependant.class);
if (MythicLib.plugin.getVersion().isBelowOrEqual(implVersion.major(), implVersion.minor(), implVersion.patch() - 1))
disable();
}
} }
/** /**
@ -187,7 +196,7 @@ public abstract class ItemStat<R extends RandomStatData<S>, S extends StatData>
/** /**
* @return The stat ID * @return The stat ID
* @deprecated Use getId() instead. Type is no longer an util since they can * @deprecated Use getId() instead. Type is no longer an util since they can
* now be registered from external plugins * now be registered from external plugins
*/ */
@Deprecated @Deprecated
@NotNull @NotNull
@ -205,8 +214,8 @@ public abstract class ItemStat<R extends RandomStatData<S>, S extends StatData>
/** /**
* @return The NBT path used by the stat to save data in an item's NBTTags. * @return The NBT path used by the stat to save data in an item's NBTTags.
* The format is 'MMOITEMS_' followed by the stat name in capital * The format is 'MMOITEMS_' followed by the stat name in capital
* letters only using _ * letters only using _
*/ */
@NotNull @NotNull
public String getNBTPath() { public String getNBTPath() {

View File

@ -0,0 +1,24 @@
package net.Indyuce.mmoitems.util;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* Version string is MAJOR.MINOR.PATCH
* <p>
* This annotation indicates the LOWEST VERSION at which
* the given feature is available. Usually, it's the
* version where some non-backwards compatible feature was
* implemented into Minecraft or Spigot.
*
* @author Jules
*/
@Retention(RetentionPolicy.RUNTIME)
public @interface VersionDependant {
public int major() default 1;
public int minor();
public int patch() default 0;
}