diff --git a/src/main/java/net/Indyuce/mmoitems/MMOItems.java b/src/main/java/net/Indyuce/mmoitems/MMOItems.java index acf5a8aa..73e6a388 100644 --- a/src/main/java/net/Indyuce/mmoitems/MMOItems.java +++ b/src/main/java/net/Indyuce/mmoitems/MMOItems.java @@ -1,8 +1,7 @@ package net.Indyuce.mmoitems; - + import io.lumine.mythic.lib.MythicLib; import io.lumine.mythic.lib.api.item.NBTItem; -import io.lumine.mythic.lib.api.util.ui.FriendlyFeedbackCategory; import io.lumine.mythic.lib.api.util.ui.FriendlyFeedbackMessage; import io.lumine.mythic.lib.api.util.ui.FriendlyFeedbackProvider; import io.lumine.mythic.lib.version.SpigotPlugin; @@ -19,22 +18,13 @@ import net.Indyuce.mmoitems.api.util.MMOItemReforger; import net.Indyuce.mmoitems.api.util.NumericStatFormula; import net.Indyuce.mmoitems.api.util.message.FFPMMOItems; import net.Indyuce.mmoitems.command.MMOItemsCommandTreeRoot; -import net.Indyuce.mmoitems.comp.MMOItemsMetrics; -import net.Indyuce.mmoitems.comp.MMOItemsRewardTypes; -import net.Indyuce.mmoitems.comp.McMMONonRPGHook; -import net.Indyuce.mmoitems.comp.PhatLootsHook; -import net.Indyuce.mmoitems.comp.RealDualWieldHook; -import net.Indyuce.mmoitems.comp.WorldEditSupport; +import net.Indyuce.mmoitems.comp.*; import net.Indyuce.mmoitems.comp.eco.VaultSupport; import net.Indyuce.mmoitems.comp.enchants.CrazyEnchantsStat; import net.Indyuce.mmoitems.comp.enchants.EnchantPlugin; import net.Indyuce.mmoitems.comp.enchants.MythicEnchantsSupport; import net.Indyuce.mmoitems.comp.enchants.advanced_enchants.AdvancedEnchantmentsHook; -import net.Indyuce.mmoitems.comp.inventory.DefaultPlayerInventory; -import net.Indyuce.mmoitems.comp.inventory.OrnamentPlayerInventory; -import net.Indyuce.mmoitems.comp.inventory.PlayerInventory; -import net.Indyuce.mmoitems.comp.inventory.PlayerInventoryHandler; -import net.Indyuce.mmoitems.comp.inventory.RPGInventoryHook; +import net.Indyuce.mmoitems.comp.inventory.*; import net.Indyuce.mmoitems.comp.itemglow.ItemGlowListener; import net.Indyuce.mmoitems.comp.itemglow.NoGlowListener; import net.Indyuce.mmoitems.comp.mmocore.MMOCoreMMOLoader; @@ -51,16 +41,7 @@ import net.Indyuce.mmoitems.comp.rpg.RPGHandler; import net.Indyuce.mmoitems.gui.PluginInventory; import net.Indyuce.mmoitems.gui.edition.recipe.RecipeBrowserGUI; import net.Indyuce.mmoitems.gui.listener.GuiListener; -import net.Indyuce.mmoitems.listener.CraftingListener; -import net.Indyuce.mmoitems.listener.CustomBlockListener; -import net.Indyuce.mmoitems.listener.CustomSoundListener; -import net.Indyuce.mmoitems.listener.DisableInteractions; -import net.Indyuce.mmoitems.listener.DurabilityListener; -import net.Indyuce.mmoitems.listener.ElementListener; -import net.Indyuce.mmoitems.listener.EquipListener; -import net.Indyuce.mmoitems.listener.ItemListener; -import net.Indyuce.mmoitems.listener.ItemUse; -import net.Indyuce.mmoitems.listener.PlayerListener; +import net.Indyuce.mmoitems.listener.*; import net.Indyuce.mmoitems.manager.*; import net.Indyuce.mmoitems.skill.Shulker_Missile; import org.apache.commons.lang.Validate; @@ -77,6 +58,7 @@ import org.jetbrains.annotations.NotNull; import javax.annotation.Nullable; import java.io.File; +import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.List; import java.util.logging.Level; @@ -116,7 +98,7 @@ public class MMOItems extends LuminePlugin { private VaultSupport vaultSupport; private RPGHandler rpgPlugin; - private static final int MYTHICLIB_COMPATIBILITY_INDEX = 1; + private static final int MYTHICLIB_COMPATIBILITY_INDEX = 2; public MMOItems() { plugin = this; @@ -128,7 +110,7 @@ public class MMOItems extends LuminePlugin { // Check if the ML build matches if (MYTHICLIB_COMPATIBILITY_INDEX != MythicLib.MMOITEMS_COMPATIBILITY_INDEX) { getLogger().log(Level.WARNING, "Your versions of MythicLib and MMOItems do not match. Make sure you are using the latest builds of both plugins"); - disable(); + setEnabled(false); return; } @@ -141,8 +123,8 @@ public class MMOItems extends LuminePlugin { saveDefaultConfig(); - /* - * stat manager must be initialized before MMOCore compatibility + /** + * Stat manager must be initialized before MMOCore compatibility * initializes so that MMOCore can register its stats */ statManager = new StatManager(); @@ -343,6 +325,10 @@ public class MMOItems extends LuminePlugin { @Override public void disable() { + // Support for early plugin disabling + if (!isEnabled()) + return; + // save player data PlayerData.getLoaded().forEach(PlayerData::save); @@ -401,6 +387,30 @@ public class MMOItems extends LuminePlugin { if (handler instanceof Listener && isEnabled()) Bukkit.getPluginManager().registerEvents((Listener) handler, this); } + /** + * @param potentialPlugin Some plugin that the user wants compatibility with + * @return If it worked + */ + public boolean setRPG(RPGHandler.PluginEnum potentialPlugin) { + + // Check if the plugin is installed + if (Bukkit.getPluginManager().getPlugin(potentialPlugin.getName()) == null) { + MMOItems.plugin.getLogger().log(Level.WARNING, "Could not initialize RPG plugin compatibility with " + potentialPlugin.getName() + ": plugin is not installed"); + return false; + } + + try { + setRPG(potentialPlugin.load()); + return true; + + // Some loading issue + } catch (InvocationTargetException | NoSuchMethodException | InstantiationException | IllegalAccessException exception) { + MMOItems.plugin.getLogger().log(Level.WARNING, "Could not initialize RPG plugin compatibility with " + potentialPlugin.getName() + ":"); + exception.printStackTrace(); + return false; + } + } + public PluginUpdateManager getUpdates() { return pluginUpdateManager; } @@ -558,57 +568,32 @@ public class MMOItems extends LuminePlugin { /** * Decide by which system will the RPG Requirements of the player will be checked. - *
+ ** For example, required level, is that vanilla XP levels, MMOCore levels, McMMO Leves or what? + * + * This method is called on server startup and will try to read the preferred RPG + * provider in the main plugin config. If it can't be found, it will look for RPG + * plugins in the installed plugin list. */ public void findRpgPlugin() { if (rpgPlugin != null) return; String preferred = plugin.getConfig().getString("preferred-rpg-provider", null); - if (preferred != null) { - + if (preferred != null) try { - RPGHandler.PluginEnum preferredRPG = RPGHandler.PluginEnum.valueOf(preferred.toUpperCase()); - // Found the plugin? - if (Bukkit.getPluginManager().getPlugin(preferredRPG.getName()) != null) { - - // Load that one - setRPG(preferredRPG.load()); - - // Mention it - print(null, "Using $s{0}$b as RPGPlayer provider", "RPG Provider", preferredRPG.getName()); + if (setRPG(RPGHandler.PluginEnum.valueOf(preferred.toUpperCase()))) return; - } else - - print(null, "Preferred RPGPlayer provider $r{0}$b is not installed!", "RPG Provider", preferred); - - } catch (IllegalArgumentException ignored) { - - // Log error - FriendlyFeedbackProvider ffp = new FriendlyFeedbackProvider(FFPMMOItems.get()); - ffp.activatePrefix(true, "RPG Provider"); - ffp.log(FriendlyFeedbackCategory.ERROR, "Invalid RPG Provider '$u{0}$b' --- These are the supported ones:", preferred); - for (RPGHandler.PluginEnum pgrep : RPGHandler.PluginEnum.values()) { - ffp.log(FriendlyFeedbackCategory.ERROR, " $r+ $b{0}", pgrep.getName()); - } - ffp.sendTo(FriendlyFeedbackCategory.ERROR, getConsole()); + } catch (IllegalArgumentException exception) { + MMOItems.plugin.getLogger().log(Level.WARNING, "'" + preferred.toUpperCase() + "' is not a valid RPG plugin:"); + for (RPGHandler.PluginEnum pgrep : RPGHandler.PluginEnum.values()) + MMOItems.plugin.getLogger().log(Level.WARNING, "- " + pgrep.getName()); } - } - // For each supported plugin - for (RPGHandler.PluginEnum pluginEnum : RPGHandler.PluginEnum.values()) { - - // Found the plugin? - if (Bukkit.getPluginManager().getPlugin(pluginEnum.getName()) != null) { - - // Load that one - setRPG(pluginEnum.load()); - - // Mention it - print(null, "Using $s{0}$b as RPGPlayer provider", "RPG Provider", pluginEnum.getName()); - return; - } - } + // Look through installed plugins + for (RPGHandler.PluginEnum pluginEnum : RPGHandler.PluginEnum.values()) + if (Bukkit.getPluginManager().getPlugin(pluginEnum.getName()) != null) + if (setRPG(pluginEnum)) + return; // Just use the default setRPG(new DefaultHook()); @@ -815,22 +800,6 @@ public class MMOItems extends LuminePlugin { } //endregion - /** - * Logs something into the console with a cool [MMOItems] prefix :) - *
- * Parses color codes. Mostly for DEV testing. these may removed any release. - * - * @author Gunging - */ - public static void log(@Nullable String message) { - if (message == null) { - message = "< null >"; - } - //String prefix = "\u00a78[" + ChatColor.YELLOW + "MMOItems\u00a78] \u00a77"; - String prefix = ""; - plugin.getServer().getConsoleSender().sendMessage(prefix + message); - } - /** * Easily log something using the FriendlyFeedbackProvider, nice! * diff --git a/src/main/java/net/Indyuce/mmoitems/api/Type.java b/src/main/java/net/Indyuce/mmoitems/api/Type.java index e07691a9..2535058c 100644 --- a/src/main/java/net/Indyuce/mmoitems/api/Type.java +++ b/src/main/java/net/Indyuce/mmoitems/api/Type.java @@ -20,18 +20,18 @@ import java.util.List; @SuppressWarnings("unused") public class Type { - // slashing + // Slashing public static final Type SWORD = new Type(TypeSet.SLASHING, "SWORD", true, EquipmentSlot.MAIN_HAND); - // piercing + // Piercing public static final Type DAGGER = new Type(TypeSet.PIERCING, "DAGGER", true, EquipmentSlot.MAIN_HAND); public static final Type SPEAR = new Type(TypeSet.PIERCING, "SPEAR", true, EquipmentSlot.MAIN_HAND); - // blunt + // Blunt public static final Type HAMMER = new Type(TypeSet.BLUNT, "HAMMER", true, EquipmentSlot.MAIN_HAND); public static final Type GAUNTLET = new Type(TypeSet.BLUNT, "GAUNTLET", true, EquipmentSlot.MAIN_HAND); - // range + // Range public static final Type WHIP = new Type(TypeSet.RANGE, "WHIP", true, EquipmentSlot.MAIN_HAND); public static final Type STAFF = new Type(TypeSet.RANGE, "STAFF", true, EquipmentSlot.MAIN_HAND); public static final Type BOW = new Type(TypeSet.RANGE, "BOW", true, EquipmentSlot.BOTH_HANDS); @@ -39,14 +39,14 @@ public class Type { public static final Type MUSKET = new Type(TypeSet.RANGE, "MUSKET", true, EquipmentSlot.MAIN_HAND); public static final Type LUTE = new Type(TypeSet.RANGE, "LUTE", true, EquipmentSlot.MAIN_HAND); - // offhand + // Offhand public static final Type CATALYST = new Type(TypeSet.OFFHAND, "CATALYST", false, EquipmentSlot.BOTH_HANDS); public static final Type OFF_CATALYST = new Type(TypeSet.OFFHAND, "OFF_CATALYST", false, EquipmentSlot.OFF_HAND); - // any + // Any public static final Type ORNAMENT = new Type(TypeSet.EXTRA, "ORNAMENT", false, EquipmentSlot.ANY); - // extra + // Extra public static final Type ARMOR = new Type(TypeSet.EXTRA, "ARMOR", false, EquipmentSlot.ARMOR, true); public static final Type TOOL = new Type(TypeSet.EXTRA, "TOOL", false, EquipmentSlot.MAIN_HAND); public static final Type CONSUMABLE = new Type(TypeSet.EXTRA, "CONSUMABLE", false, EquipmentSlot.MAIN_HAND); @@ -96,8 +96,8 @@ public class Type { private UnidentifiedItem unidentifiedTemplate; - /* - * list of stats which can be applied onto an item which has this type. This + /** + * List of stats which can be applied onto an item which has this type. This * improves performance when generating an item by a significant amount. */ private final List
+ * These stats are only updated on a server reload because that
+ * class has to be instanciated again for the registered stats to update
*/
public MMOCoreHook() {
- /*
- * only works when the server is reloaded. needs /reload when changing
- * attributes or professions to refresh MMOItems stats
- */
for (PlayerAttribute attribute : MMOCore.plugin.attributeManager.getAll())
MMOItems.plugin.getStats().register(new Required_Attribute(attribute));
for (Profession profession : MMOCore.plugin.professionManager.getAll())
@@ -105,12 +104,12 @@ public class MMOCoreHook implements RPGHandler, Listener {
@Override
public void giveMana(double value) {
- data.giveMana(value, PlayerResourceUpdateEvent.UpdateReason.REGENERATION);
+ data.giveMana(value, PlayerResourceUpdateEvent.UpdateReason.OTHER);
}
@Override
public void giveStamina(double value) {
- data.giveStamina(value, PlayerResourceUpdateEvent.UpdateReason.REGENERATION);
+ data.giveStamina(value, PlayerResourceUpdateEvent.UpdateReason.OTHER);
}
}
}
\ No newline at end of file
diff --git a/src/main/java/net/Indyuce/mmoitems/comp/rpg/RPGHandler.java b/src/main/java/net/Indyuce/mmoitems/comp/rpg/RPGHandler.java
index d9ae6207..b0236062 100644
--- a/src/main/java/net/Indyuce/mmoitems/comp/rpg/RPGHandler.java
+++ b/src/main/java/net/Indyuce/mmoitems/comp/rpg/RPGHandler.java
@@ -1,12 +1,10 @@
package net.Indyuce.mmoitems.comp.rpg;
-import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.player.PlayerData;
import net.Indyuce.mmoitems.api.player.RPGPlayer;
import net.Indyuce.mmoitems.comp.mmocore.MMOCoreHook;
import java.lang.reflect.InvocationTargetException;
-import java.util.logging.Level;
public interface RPGHandler {
@@ -52,14 +50,8 @@ public interface RPGHandler {
this.name = name;
}
- public RPGHandler load() {
- try {
- return pluginClass.getDeclaredConstructor().newInstance();
- } catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException exception) {
- MMOItems.plugin.getLogger().log(Level.WARNING,
- "Could not initialize RPG plugin compatibility with " + name + ": " + exception.getMessage());
- return new DefaultHook();
- }
+ public RPGHandler load() throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
+ return pluginClass.getDeclaredConstructor().newInstance();
}
public String getName() {
diff --git a/src/main/java/net/Indyuce/mmoitems/manager/StatManager.java b/src/main/java/net/Indyuce/mmoitems/manager/StatManager.java
index 14d3b86f..3ed21fcd 100644
--- a/src/main/java/net/Indyuce/mmoitems/manager/StatManager.java
+++ b/src/main/java/net/Indyuce/mmoitems/manager/StatManager.java
@@ -24,8 +24,8 @@ public class StatManager {
private final Set