diff --git a/.gitignore b/.gitignore index 7ca1ad39..6db9d797 100644 --- a/.gitignore +++ b/.gitignore @@ -1,13 +1,19 @@ /bin/ /target/ +MMOItems-API/target/ +MMOItems-Dist/target/ /.settings/ /.idea/ /.m2/ .classpath .project + MMOItems.eml MMOItems.iml MMOItems-API.eml MMOItems-API.iml MMOItems-Dist.eml MMOItems-Dist.iml + +.flattened-pom.xml +dependency-reduced-pom.xml diff --git a/MMOItems-API/pom.xml b/MMOItems-API/pom.xml index 8c89d2a0..b709e2e5 100644 --- a/MMOItems-API/pom.xml +++ b/MMOItems-API/pom.xml @@ -118,7 +118,6 @@ the first wins when multiple classpaths match --> - org.spigotmc @@ -126,7 +125,6 @@ 1.18-R0.1-SNAPSHOT provided - org.apache.maven.plugins @@ -134,211 +132,209 @@ 3.1.0 provided - + com.mojang authlib 1.5.21 provided - + net.Indyuce MMOCore-API 1.9.5-SNAPSHOT provided - + io.lumine MythicEnchants 0.0.1-SNAPSHOT provided - + com.github.RednedEpic PhatLoots 4.2.3 provided - + me.clip placeholderapi 2.9.2 provided - + io.lumine Mythic-Dist 5.1.2-SNAPSHOT provided - + com.sk89q.worldguard worldguard-bukkit 7.0.2-SNAPSHOT provided - + com.github.MilkBowl VaultAPI 1.7 provided - - + com.github.Eniripsa96 SkillAPI master provided - + n3kas ae.api 5.7.6 provided - + org.black_ixx BossShop 2.0.9 provided - + com.bekvon.bukkit.residence Residence 4.8.7.2 provided - + com.herocraftonline Heroes 1.9.22 provided - + com.gmail.nossr50 mcMMO 2.1.104 provided - + us.eunoians McRPG 1.1.2 provided - + me.baks rpl 3.9.30 provided - + me.leothepro555 skills 12.3.5 provided - + org.skills.main SkillsPro 18.9.0.1 provided - + me.robin BattleLevels 6.9.1 provided - + me.arasple.mc TrHologram 1.11 provided - + com.gmail.filoghost.holographicdisplays holographicdisplays-api 2.4.0 provided - + de.tobiyas RacesAndClasses 1.2.6 provided - + ru.endlesscode rpginventory 2.3.0 provided - + com.sainttx.holograms Holograms 2.9.1 provided - + com.archyx AureliumSkills 1.2.8 provided - + me.badbones69 crazyenchantments 1.8-db9 provided - + net.citizensnpcs Citizens 2.0.25 provided - + com.denizenscript denizen 1.2.1-b1744-REL provided - + com.denizenscript depenizen 2.0.0-b709 provided - \ No newline at end of file diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/ItemStats.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/ItemStats.java index bfee5159..3430741b 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/ItemStats.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/ItemStats.java @@ -70,7 +70,7 @@ public class ItemStats { PARRY_COOLDOWN_REDUCTION = new DoubleStat("PARRY_COOLDOWN_REDUCTION", Material.BUCKET, "Parry Cooldown Reduction", new String[]{"Reduces the parrying cooldown (%)."}, new String[]{"!miscellaneous", "!block", "all"}), COOLDOWN_REDUCTION = new DoubleStat("COOLDOWN_REDUCTION", Material.BOOK, "Cooldown Reduction", new String[]{"Reduces cooldowns of item and player skills (%)."}), RANGE = new DoubleStat("RANGE", Material.STICK, "Range", new String[]{"The range of your item attacks."}, new String[]{"staff", "whip", "wand", "musket"}), - MANA_COST = new DoubleStat("MANA_COST", VersionMaterial.LAPIS_LAZULI.toMaterial(), "Mana Cost", new String[]{"Mana spent by your weapon to be used."}, new String[]{"piercing", "slashing", "blunt", "range"}), + MANA_COST = new ManaCost(), STAMINA_COST = new DoubleStat("STAMINA_COST", VersionMaterial.LIGHT_GRAY_DYE.toMaterial(), "Stamina Cost", new String[]{"Stamina spent by your weapon to be used."}, new String[]{"piercing", "slashing", "blunt", "range"}), ARROW_VELOCITY = new DoubleStat("ARROW_VELOCITY", Material.ARROW, "Arrow Velocity", new String[]{"Determines how far your", "weapon can shoot.", "Default: 1.0"}, new String[]{"gem_stone", "bow", "crossbow"}), ARROW_POTION_EFFECTS = new ArrowPotionEffects(), diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/MMOItems.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/MMOItems.java index 6e76fed0..cc27ad28 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/MMOItems.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/MMOItems.java @@ -41,6 +41,7 @@ import net.Indyuce.mmoitems.gui.PluginInventory; import net.Indyuce.mmoitems.gui.edition.recipe.RecipeBrowserGUI; import net.Indyuce.mmoitems.listener.CraftingListener; import net.Indyuce.mmoitems.manager.*; +import net.Indyuce.mmoitems.util.PluginUtils; import org.apache.commons.lang.Validate; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -61,39 +62,39 @@ import java.util.List; import java.util.logging.Level; public class MMOItems extends JavaPlugin { - public static MMOItems plugin; + public static MMOItems plugin; - // Increment this when making breaking changes to items. - public static final int INTERNAL_REVISION_ID = 1; + // Increment this when making breaking changes to items. + public static final int INTERNAL_REVISION_ID = 1; - private final PluginUpdateManager pluginUpdateManager = new PluginUpdateManager(); - private final CraftingManager stationRecipeManager = new CraftingManager(); - private final LoreFormatManager formatManager = new LoreFormatManager(); - private final TemplateManager templateManager = new TemplateManager(); - private final SkillManager skillManager = new SkillManager(); - private final EntityManager entityManager = new EntityManager(); - private final RecipeManager recipeManager = new RecipeManager(); - private final LayoutManager layoutManager = new LayoutManager(); - private final TypeManager typeManager = new TypeManager(); - private final ItemManager itemManager = new ItemManager(); - private final PlayerInventoryHandler inventory = new PlayerInventoryHandler(); - @Deprecated - private final List stringInputParsers = new ArrayList<>(); - private final List> enchantPlugins = new ArrayList<>(); - private final StatManager statManager = new StatManager(); + private final PluginUpdateManager pluginUpdateManager = new PluginUpdateManager(); + private final CraftingManager stationRecipeManager = new CraftingManager(); + private final LoreFormatManager formatManager = new LoreFormatManager(); + private final TemplateManager templateManager = new TemplateManager(); + private final SkillManager skillManager = new SkillManager(); + private final EntityManager entityManager = new EntityManager(); + private final RecipeManager recipeManager = new RecipeManager(); + private final LayoutManager layoutManager = new LayoutManager(); + private final TypeManager typeManager = new TypeManager(); + private final ItemManager itemManager = new ItemManager(); + private final PlayerInventoryHandler inventory = new PlayerInventoryHandler(); + @Deprecated + private final List stringInputParsers = new ArrayList<>(); + private final List> enchantPlugins = new ArrayList<>(); + private final StatManager statManager = new StatManager(); - private DropTableManager dropTableManager; - private WorldGenManager worldGenManager; - private UpgradeManager upgradeManager; - private ConfigManager configManager; - private BlockManager blockManager; - private TierManager tierManager; - private SetManager setManager; + private DropTableManager dropTableManager; + private WorldGenManager worldGenManager; + private UpgradeManager upgradeManager; + private ConfigManager configManager; + private BlockManager blockManager; + private TierManager tierManager; + private SetManager setManager; - @Deprecated - private PlaceholderParser placeholderParser = new DefaultPlaceholderParser(); - private VaultSupport vaultSupport; - private RPGHandler rpgPlugin; + @Deprecated + private PlaceholderParser placeholderParser = new DefaultPlaceholderParser(); + private VaultSupport vaultSupport; + private RPGHandler rpgPlugin; /** * Startup issues usually prevent the plugin from loading and just @@ -105,696 +106,690 @@ public class MMOItems extends JavaPlugin { */ private boolean hasLoadedSuccessfully; - public MMOItems() { plugin = this; } + public MMOItems() { + plugin = this; + } - @Override - public void onLoad() { + @Override + public void onLoad() { + PluginUtils.isDependencyPresent("WorldEdit", u -> { + try { + new WorldEditSupport(); + getLogger().log(Level.INFO, "Hooked onto WorldEdit"); + } catch (Exception exception) { + getLogger().log(Level.WARNING, "Could not initialize support with WorldEdit 7: ", exception); + } + }); - if (getServer().getPluginManager().getPlugin("WorldEdit") != null) try { - new WorldEditSupport(); - getLogger().log(Level.INFO, "Hooked onto WorldEdit"); - } catch (Exception exception) { - getLogger().log(Level.WARNING, "Could not initialize support with WorldEdit 7: " + exception.getMessage()); - } + // Initialize default config files + saveDefaultConfig(); + configManager = new ConfigManager(); - // Initialize default config files - saveDefaultConfig(); - configManager = new ConfigManager(); + statManager.load(); + typeManager.reload(); + templateManager.preloadTemplates(); - statManager.load(); - typeManager.reload(); - templateManager.preloadTemplates(); + PluginUtils.isDependencyPresent("MMOCore", u -> new MMOCoreMMOLoader()); + PluginUtils.isDependencyPresent("mcMMO", u -> statManager.register(McMMOHook.disableMcMMORepair)); + PluginUtils.isDependencyPresent("AdvancedEnchantments", u -> { + statManager.register(AdvancedEnchantmentsHook.ADVANCED_ENCHANTMENTS); + statManager.register(AdvancedEnchantmentsHook.DISABLE_ADVANCED_ENCHANTMENTS); + }); + PluginUtils.isDependencyPresent("MythicEnchants", u -> enchantPlugins.add(new MythicEnchantsSupport())); + PluginUtils.isDependencyPresent("Heroes", u -> statManager.register(HeroesHook.MAX_STAMINA)); + } - if (Bukkit.getPluginManager().getPlugin("MMOCore") != null) new MMOCoreMMOLoader(); + @Override + public void onEnable() { + new SpigotPlugin(39267, this).checkForUpdate(); + new MMOItemsMetrics(); + MMOItemUIFilter.register(); - if (Bukkit.getPluginManager().getPlugin("mcMMO") != null) - //statManager.register(McMMOHook.MCMMO_SUPER_TOOL); - statManager.register(McMMOHook.disableMcMMORepair); + RecipeBrowserGUI.registerNativeRecipes(); + skillManager.initialize(false); - if (Bukkit.getPluginManager().getPlugin("AdvancedEnchantments") != null) { - statManager.register(AdvancedEnchantmentsHook.ADVANCED_ENCHANTMENTS); - statManager.register(AdvancedEnchantmentsHook.DISABLE_ADVANCED_ENCHANTMENTS); - } + final int configVersion = getConfig().contains("config-version", true) ? getConfig().getInt("config-version") : -1; + final int defConfigVersion = getConfig().getDefaults().getInt("config-version"); + if (configVersion != defConfigVersion) { + getLogger().warning("You may be using an outdated config.yml!"); + getLogger().warning("(Your config version: '" + configVersion + "' | Expected config version: '" + defConfigVersion + "')"); + } - if (Bukkit.getPluginManager().getPlugin("MythicEnchants") != null) enchantPlugins.add(new MythicEnchantsSupport()); + // registering here so the stats will load with the templates + PluginUtils.hookDependencyIfPresent("MythicMobs", unused -> { + new MythicMobsCompatibility(); + if (getConfig().getBoolean("lootsplosion.enabled")) + Bukkit.getPluginManager().registerEvents(new LootsplosionListener(), this); + }); + PluginUtils.hookDependencyIfPresent("MMOInventory", unused -> new MMOInventorySupport()); - if (Bukkit.getPluginManager().getPlugin("Heroes") != null) - statManager.register(HeroesHook.MAX_STAMINA); - } + findRpgPlugin(); - @Override - public void onEnable() { - new SpigotPlugin(39267, this).checkForUpdate(); - new MMOItemsMetrics(); - MMOItemUIFilter.register(); + /* + * After tiers, sets and upgrade templates are loaded, MI template data + * can be fully loaded + */ + statManager.loadElements(); + formatManager.reload(); + tierManager = new TierManager(); + setManager = new SetManager(); + upgradeManager = new UpgradeManager(); + templateManager.postloadTemplates(); - RecipeBrowserGUI.registerNativeRecipes(); - skillManager.initialize(false); + dropTableManager = new DropTableManager(); + worldGenManager = new WorldGenManager(); + blockManager = new BlockManager(); + statManager.reload(false); - final int configVersion = getConfig().contains("config-version", true) ? getConfig().getInt("config-version") : -1; - final int defConfigVersion = getConfig().getDefaults().getInt("config-version"); - if (configVersion != defConfigVersion) { - getLogger().warning("You may be using an outdated config.yml!"); - getLogger().warning("(Your config version: '" + configVersion + "' | Expected config version: '" + defConfigVersion + "')"); - } - // registering here so the stats will load with the templates - if (Bukkit.getPluginManager().getPlugin("MythicMobs") != null) { - new MythicMobsCompatibility(); - if (getConfig().getBoolean("lootsplosion.enabled")) Bukkit.getPluginManager().registerEvents(new LootsplosionListener(), this); - getLogger().log(Level.INFO, "Hooked onto MythicMobs"); - } + PluginUtils.hookDependencyIfPresent("Vault", u -> vaultSupport = new VaultSupport()); - if (Bukkit.getPluginManager().getPlugin("MMOInventory") != null) { - new MMOInventorySupport(); - getLogger().log(Level.INFO, "Hooked onto MMOInventory"); - } + getLogger().log(Level.INFO, "Loading crafting stations, please wait.."); + layoutManager.reload(); + stationRecipeManager.reload(); - findRpgPlugin(); + // This ones are not implementing Reloadable + NumericStatFormula.reload(); + MMOItemReforger.reload(); - /* - * After tiers, sets and upgrade templates are loaded, MI template data - * can be fully loaded - */ - formatManager.reload(); - tierManager = new TierManager(); - setManager = new SetManager(); - upgradeManager = new UpgradeManager(); - templateManager.postloadTemplates(); + Bukkit.getPluginManager().registerEvents(entityManager, this); + Bukkit.getPluginManager().registerEvents(dropTableManager, this); - dropTableManager = new DropTableManager(); - worldGenManager = new WorldGenManager(); - blockManager = new BlockManager(); - MMOItems.plugin.getStats().reload(false); + // Load Dist module + // Load MMOCore-Bukkit module + try { + Class.forName("net.Indyuce.mmoitems.MMOItemsBukkit").getConstructor(MMOItems.class).newInstance(this); + } catch (Throwable exception) { + throw new RuntimeException("Cannot run an API build on Spigot!"); + } - if (Bukkit.getPluginManager().getPlugin("Vault") != null) vaultSupport = new VaultSupport(); + /* + * This tasks updates twice a second player inventories on the server. + * allows now to use a glitchy itemEquipEvent. Must be called after + * loading the config since it checks for a config option + */ + Bukkit.getScheduler().runTaskTimer(this, () -> { + for (Player player : Bukkit.getOnlinePlayers()) + PlayerData.get(player).getInventory().updateCheck(); + }, 100, getConfig().getInt("inventory-update-delay")); - getLogger().log(Level.INFO, "Loading crafting stations, please wait.."); - layoutManager.reload(); - stationRecipeManager.reload(); + PluginUtils.isDependencyPresent("mcMMO", unused -> Bukkit.getPluginManager().registerEvents(new McMMONonRPGHook(), this)); - // This ones are not implementing Reloadable - NumericStatFormula.reload(); - MMOItemReforger.reload(); + /* + * Registers Player Inventories. Each of these add locations of items to search for + * when doing inventory updates. + */ + getInventory().register(new DefaultPlayerInventory()); + PluginUtils.hookDependencyIfPresent("RPGInventory", unused -> getInventory().register(new RPGInventoryHook())); + PluginUtils.hookDependencyIfPresent("CrazyEnchantments", unused -> getStats().register(new CrazyEnchantsStat())); + PluginUtils.hookDependencyIfPresent("AdvancedEnchantments", unused -> Bukkit.getPluginManager().registerEvents(new AdvancedEnchantmentsHook(), this)); + PluginUtils.hookDependencyIfPresent("PlaceholderAPI", unused -> placeholderParser = new PlaceholderAPIParser()); + if (MMOItems.plugin.getConfig().getBoolean("iterate-whole-inventory")) + getInventory().register(new OrnamentPlayerInventory()); - Bukkit.getPluginManager().registerEvents(entityManager, this); - Bukkit.getPluginManager().registerEvents(dropTableManager, this); - // Load Dist module - // Load MMOCore-Bukkit module - try { - Class.forName("net.Indyuce.mmoitems.MMOItemsBukkit").getConstructor(MMOItems.class).newInstance(this); - } catch(Throwable exception) { - throw new RuntimeException("Cannot run an API build on Spigot!"); - } - - /* - * This tasks updates twice a second player inventories on the server. - * allows now to use a glitchy itemEquipEvent. Must be called after - * loading the config since it checks for a config option - */ - Bukkit.getScheduler().runTaskTimer(this, () -> { - for (Player player : Bukkit.getOnlinePlayers()) - PlayerData.get(player).getInventory().updateCheck(); - }, 100, getConfig().getInt("inventory-update-delay")); - - if (Bukkit.getPluginManager().getPlugin("mcMMO") != null) Bukkit.getPluginManager().registerEvents(new McMMONonRPGHook(), this); - - /* - * Registers Player Inventories. Each of these add locations of items to search for - * when doing inventory updates. - */ - getInventory().register(new DefaultPlayerInventory()); - if (Bukkit.getPluginManager().getPlugin("RPGInventory") != null) { - getInventory().register(new RPGInventoryHook()); - getLogger().log(Level.INFO, "Hooked onto RPGInventory"); - } - if (MMOItems.plugin.getConfig().getBoolean("iterate-whole-inventory")) getInventory().register(new OrnamentPlayerInventory()); - - if (Bukkit.getPluginManager().getPlugin("CrazyEnchantments") != null) { - getStats().register(new CrazyEnchantsStat()); - getLogger().log(Level.INFO, "Hooked onto CrazyEnchantments"); - } - - if (Bukkit.getPluginManager().getPlugin("AdvancedEnchantments") != null) { - Bukkit.getPluginManager().registerEvents(new AdvancedEnchantmentsHook(), this); - getLogger().log(Level.INFO, "Hooked onto AdvancedEnchantments"); - } - - if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) { - getLogger().log(Level.INFO, "Hooked onto PlaceholderAPI"); - placeholderParser = new PlaceholderAPIParser(); - } - - if (Bukkit.getPluginManager().getPlugin("BossShopPro") != null) { - getLogger().log(Level.INFO, "Hooked onto BossShopPro"); - (new BukkitRunnable() { - public void run() { - //noinspection ProhibitedExceptionCaught - try { - new MMOItemsRewardTypes().register(); - } catch (NullPointerException ignored) { - getLogger().log(Level.INFO, "Could not Hook onto BossShopPro"); - } - } - }).runTaskLater(this, 1L); - } + if (Bukkit.getPluginManager().getPlugin("BossShopPro") != null) { + getLogger().log(Level.INFO, "Hooked onto BossShopPro"); + (new BukkitRunnable() { + public void run() { + //noinspection ProhibitedExceptionCaught + try { + new MMOItemsRewardTypes().register(); + } catch (NullPointerException ignored) { + getLogger().log(Level.INFO, "Could not Hook onto BossShopPro"); + } + } + }).runTaskLater(this, 1L); + } /*if (Bukkit.getPluginManager().getPlugin("Denizen") != null) { new DenizenHook(); getLogger().log(Level.INFO, "Hooked onto Denizen"); }*/ - // Compatibility with /reload - Bukkit.getScheduler().runTask(this, () -> Bukkit.getOnlinePlayers().forEach(PlayerData::load)); - - boolean book = getConfig().getBoolean("recipes.use-recipe-book"); - boolean amounts = getConfig().getBoolean("recipes.recipe-amounts"); - - if (book && amounts) { - getLogger().warning("Tried to enable recipe book while amounts are active!"); - getLogger().warning("Please use only ONE of these options!"); - getLogger().warning("Disabling both options for now..."); - book = false; - amounts = false; - } - - recipeManager.load(book, amounts); - if (amounts) Bukkit.getPluginManager().registerEvents(new CraftingListener(), this); - - // Amount and bukkit recipes - getLogger().log(Level.INFO, "Loading recipes, please wait..."); - recipeManager.loadRecipes(); - - // Main command - MMOItemsCommandTreeRoot mmoitemsCommand = new MMOItemsCommandTreeRoot(); - getCommand("mmoitems").setExecutor(mmoitemsCommand); - getCommand("mmoitems").setTabCompleter(mmoitemsCommand); - - // Mark plugin as successfully enabled - hasLoadedSuccessfully = true; - } - - @Override - public void onDisable() { - - // Support for early plugin disabling - if (!hasLoadedSuccessfully) - return; - - // Save player data - PlayerData.getLoaded().forEach(data -> data.save(false)); - - // Drop abandonned soulbound items - SoulboundInfo.getAbandonnedInfo().forEach(SoulboundInfo::dropItems); - - // Close inventories - for (Player player : Bukkit.getOnlinePlayers()) - if (player.getOpenInventory() != null && player.getOpenInventory().getTopInventory().getHolder() instanceof PluginInventory) - player.closeInventory(); - } - - public String getPrefix() { - return ChatColor.DARK_GRAY + "[" + ChatColor.YELLOW + "MMOItems" + ChatColor.DARK_GRAY + "] " + ChatColor.GRAY; - } - - public File getJarFile() { - return plugin.getFile(); - } - - public CraftingManager getCrafting() { - return stationRecipeManager; - } - - public LayoutManager getLayouts() { - return layoutManager; - } - - public SetManager getSets() { - return setManager; - } - - public RPGHandler getRPG() { - return rpgPlugin; - } - - /** - * 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; - - // Preferred rpg provider - String preferred = plugin.getConfig().getString("preferred-rpg-provider", null); - if (preferred != null && setRPG(RPGHandler.PluginEnum.valueOf(preferred.toUpperCase()))) - return; - - // Look through installed plugins - for (RPGHandler.PluginEnum pluginEnum : RPGHandler.PluginEnum.values()) - if (Bukkit.getPluginManager().getPlugin(pluginEnum.getName()) != null && setRPG(pluginEnum)) - return; - - // Just use the default - setRPG(new DefaultHook()); - } - - /** - * The RPGHandler interface lets MMOItems fetch and manipulate RPG data like - * player level, class, resources like mana and stamina for item or skill - * costs, item restrictions, etc. - * - * @param handler Your RPGHandler instance - */ - public void setRPG(RPGHandler handler) { - Validate.notNull(handler, "RPGHandler cannot be null"); - - // Unregister events from current RPGPlugin instance - if (rpgPlugin != null && rpgPlugin instanceof Listener && isEnabled()) - HandlerList.unregisterAll((Listener) rpgPlugin); - - rpgPlugin = handler; - getLogger().log(Level.INFO, "Now using " + handler.getClass().getSimpleName() + " as RPG provider"); - - // Register new events - 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) { - - try { - Validate.notNull(Bukkit.getPluginManager().getPlugin(potentialPlugin.getName()), "Plugin is not installed"); - setRPG(potentialPlugin.load()); - return true; - - // Some loading issue - } catch (Exception 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; - } - - public PlayerInventoryHandler getInventory() { - return inventory; - } - - /** - * The PlayerInventory interface lets MMOItems knows what items to look for - * in player inventories whe doing inventory updates. By default, it only - * checks held items + armor slots. However other plugins like MMOInv do - * implement custom slots and therefore must register a custom - * PlayerInventory instance that tells of additional items to look for. - */ - public void registerPlayerInventory(PlayerInventory value) { - - // Registers in the Inventory Handler - getInventory().register(value); - } - - /** - * The PlayerInventory interface lets MMOItems knows what items to look for - * in player inventories whe doing inventory updates. By default, it only - * checks held items + armor slots. However other plugins like MMOInv do - * implement custom slots and therefore must register a custom - * PlayerInventory instance. - *

- * Default instance is DefaultPlayerInventory in comp.inventory - * - * @param value The player inventory subclass - * @deprecated Rather than setting this to the only inventory MMOItems will - * search equipment within, you must add your inventory to the - * handler with getInventory().register(). This method - * will clear all other PlayerInventories for now, as to keep - * backwards compatibility. - */ - @Deprecated - public void setPlayerInventory(PlayerInventory value) { - - // Unregisters those previously registered - getInventory().unregisterAll(); - - // Registers this as the only - getInventory().register(value); - } - - /** - * Plugins like MythicEnchants which utilize the Bukkit - * class Enchantment by extending it don't use any ItemStat - * to store their enchants and therefore need to be called - * to update the item lore when any item is built. - * - * @param enchantPlugin Enchantment plugin - */ - public void registerEnchantPlugin(EnchantPlugin enchantPlugin) { - Validate.notNull(enchantPlugin, "Enchant plugin cannot be null"); - enchantPlugins.add(enchantPlugin); - } - - public StatManager getStats() { - return statManager; - } - - public TierManager getTiers() { - return tierManager; - } - - public EntityManager getEntities() { - return entityManager; - } - - public DropTableManager getDropTables() { - return dropTableManager; - } - - public SkillManager getSkills() { - return skillManager; - } - - public BlockManager getCustomBlocks() { - return blockManager; - } - - public WorldGenManager getWorldGen() { - return worldGenManager; - } - - public RecipeManager getRecipes() { - return recipeManager; - } - - public ConfigManager getLanguage() { - return configManager; - } - - public TypeManager getTypes() { - return typeManager; - } - - public UpgradeManager getUpgrades() { - return upgradeManager; - } - - @Deprecated - public PlaceholderParser getPlaceholderParser() { - return placeholderParser; - } - - public TemplateManager getTemplates() { - return templateManager; - } - - public LoreFormatManager getFormats() { - return formatManager; - } - - @Deprecated - public ItemManager getItems() { - return itemManager; - } - - /* - * External API's - */ - public boolean hasPermissions() { - return vaultSupport != null && vaultSupport.getPermissions() != null; - } - - public List> getEnchantPlugins() { - return enchantPlugins; - } - - public boolean hasEconomy() { - return vaultSupport != null && vaultSupport.getEconomy() != null; - } - - public VaultSupport getVault() { - return vaultSupport; - } - - /** - * @deprecated Not used - */ - @Deprecated - public List getStringInputParsers() { - return stringInputParsers; - } - - //region Easy-Access API - - /** - * @return Generates an item given an item template. The item level will - * scale according to the player RPG level if the template has the - * 'level-item' option. The item will pick a random tier if the - * template has the 'tiered' option - */ - @Nullable - public MMOItem getMMOItem(@Nullable Type type, @Nullable String id, @Nullable PlayerData player) { - if (type == null || id == null) { return null; } - - // Valid template? - MMOItemTemplate found = getTemplates().getTemplate(type, id); - if (found == null) return null; - - // Build if found - return found.newBuilder(player).build(); - } - - /** - * @return Generates an item given an item template. The item level will - * scale according to the player RPG level if the template has the - * 'level-item' option. The item will pick a random tier if the - * template has the 'tiered' option - */ - @Nullable - public ItemStack getItem(@Nullable Type type, @Nullable String id, @NotNull PlayerData player) { - - // Valid MMOItem? - MMOItem m = getMMOItem(type, id, player); - if (m == null) return null; - - // Build if found - return m.newBuilder().build(); - } - - /** - * @param itemLevel The desired item level - * @param itemTier The desired item tier, can be null - * @return Generates an item given an item template with a - * specific item level and item tier - */ - @Nullable - public MMOItem getMMOItem(@Nullable Type type, @Nullable String id, int itemLevel, @Nullable ItemTier itemTier) { - if (type == null || id == null) { return null; } - - // Valid template? - MMOItemTemplate found = getTemplates().getTemplate(type, id); - if (found == null) return null; - - // Build if found - return found.newBuilder(itemLevel, itemTier).build(); - } - - /** - * @param itemLevel The desired item level - * @param itemTier The desired item tier, can be null - * - * @return Generates an item given an item template with a - * specific item level and item tier - */ - @Nullable - public ItemStack getItem(@Nullable Type type, @Nullable String id, int itemLevel, @Nullable ItemTier itemTier) { - - // Valid MMOItem? - MMOItem m = getMMOItem(type, id, itemLevel, itemTier); - if (m == null) return null; - - // Build if found - return m.newBuilder().build(); - } - - /** - * @return Generates an item given an item template. The item level will be - * 0 and the item will have no item tier unless one is specified in - * the base item data. - *

- * Will return null if such MMOItem does not exist. - */ - @Nullable - public MMOItem getMMOItem(@Nullable Type type, @Nullable String id) { return getMMOItem(type, id, 0, null); } - - /** - * @return Generates an item given an item template. The item level will be - * 0 and the item will have no item tier unless one is specified in - * the base item data. - *

- * Will return null if such MMOItem does not exist. - */ - - @Nullable - public ItemStack getItem(@Nullable String type, @Nullable String id) { - if (type == null || id == null) { return null; } - return getItem(getTypes().get(type), id); - } - - /** - * @return Generates an item given an item template. The item level will be - * 0 and the item will have no item tier unless one is specified in - * the base item data. - *

- * Will return null if such MMOItem does not exist. - */ - @Nullable - public ItemStack getItem(@Nullable Type type, @Nullable String id) { - if (type == null || id == null) { return null; } - - // Valid MMOItem? - MMOItem m = getMMOItem(type, id); - if (m == null) { return null; } - - // Build if found - return m.newBuilder().build(); - } - - //region Reading MMOItems from ItemStacks - - /** - * @param stack The stack you trying to read - * @return The MMOItems type of this stack, if it has one - * @see #getType(NBTItem) - */ - @Nullable - public static Type getType(@Nullable ItemStack stack) { - - // Get from nbt - return getType(NBTItem.get(stack)); - } - - /** - * @param nbt The NBTItem you trying to read - * @return The MMOItems type of this nbt, if it has one - */ - @Nullable - public static Type getType(@Nullable NBTItem nbt) { - - // That's it - return plugin.getTypes().get(getTypeName(nbt)); - } - - /** - * @param stack The stack you trying to read - * @return The MMOItems type of this stack, if it has one - * @see #getTypeName(NBTItem) - */ - @Nullable - public static String getTypeName(@Nullable ItemStack stack) { - - // Get from nbt - return getTypeName(NBTItem.get(stack)); - } - - /** - * @param nbt The NBTItem you trying to read - * @return The MMOItems type of this nbt, if it has one - */ - @Nullable - public static String getTypeName(@Nullable NBTItem nbt) { - - // Straight up no - if (nbt == null) { - return null; - } - - // Get from nbt - if (!nbt.hasType()) { - return null; - } - - // That's it - return nbt.getType(); - } - - /** - * @param nbt The ItemStack you trying to read - * @return The MMOItems ID of this stack, if it has one - * @see #getID(NBTItem) - */ - @Nullable - public static String getID(@Nullable ItemStack nbt) { - - // That's it - return getID(NBTItem.get(nbt)); - } - - /** - * @param nbt The NBTItem you trying to read - * @return The MMOItems ID of this nbt, if it has one - */ - @Nullable - public static String getID(@Nullable NBTItem nbt) { - - // Straight up no - if (nbt == null) { - return null; - } - - // That's it - return nbt.getString("MMOITEMS_ITEM_ID"); - } - //endregion - - /** - * Easily log something using the FriendlyFeedbackProvider, nice! - *

- * Use a null level to use the normal console sender. - * - * @author Gunging - */ - public static void print(@Nullable Level level, @Nullable String message, @Nullable String prefix, @NotNull String... replaces) { - if (message == null) { - message = "< null >"; - } - if (level != null) { - plugin.getLogger().log(level, FriendlyFeedbackProvider.quickForConsole(FFPMMOItems.get(), message, replaces)); - } else { - FriendlyFeedbackMessage p = new FriendlyFeedbackMessage("", prefix); - FriendlyFeedbackMessage r = FriendlyFeedbackProvider.generateMessage(p, message, replaces); - getConsole().sendMessage(r.forConsole(FFPMMOItems.get())); - } - } - - /** - * JULES DO NOT DELETE THIS AGAIN I KNOW ITS UNUSED PRECISELY BECAUSE I ALWAYS COMMENT - * ALL ITS USAGES BEFORE PUSHING ANY UPDATES, I USE IT FOR SPAMMY DEVELOPER MESSAGES - * - * Note that {@link #print(Level, String, String, String...)} is used for actual warnings - * or such that the users may see, so dont delete that one either. - * - * @author Gunging - */ - public static void log(@Nullable String message, @NotNull String... replaces) { print(null, message, null, replaces); } - - /** - * @return The server's console sender. - * @author Gunging - */ - @NotNull - public static ConsoleCommandSender getConsole() { - return plugin.getServer().getConsoleSender(); - } - //endregion + // Compatibility with /reload + Bukkit.getScheduler().runTask(this, () -> Bukkit.getOnlinePlayers().forEach(PlayerData::load)); + + boolean book = getConfig().getBoolean("recipes.use-recipe-book"); + boolean amounts = getConfig().getBoolean("recipes.recipe-amounts"); + + if (book && amounts) { + getLogger().warning("Tried to enable recipe book while amounts are active!"); + getLogger().warning("Please use only ONE of these options!"); + getLogger().warning("Disabling both options for now..."); + book = false; + amounts = false; + } + + recipeManager.load(book, amounts); + if (amounts) Bukkit.getPluginManager().registerEvents(new CraftingListener(), this); + + // Amount and bukkit recipes + getLogger().log(Level.INFO, "Loading recipes, please wait..."); + recipeManager.loadRecipes(); + + // Main command + MMOItemsCommandTreeRoot mmoitemsCommand = new MMOItemsCommandTreeRoot(); + getCommand("mmoitems").setExecutor(mmoitemsCommand); + getCommand("mmoitems").setTabCompleter(mmoitemsCommand); + + // Mark plugin as successfully enabled + hasLoadedSuccessfully = true; + } + + @Override + public void onDisable() { + + // Support for early plugin disabling + if (!hasLoadedSuccessfully) + return; + + // Save player data + PlayerData.getLoaded().forEach(data -> data.save(false)); + + // Drop abandonned soulbound items + SoulboundInfo.getAbandonnedInfo().forEach(SoulboundInfo::dropItems); + + // Close inventories + for (Player player : Bukkit.getOnlinePlayers()) + if (player.getOpenInventory() != null && player.getOpenInventory().getTopInventory().getHolder() instanceof PluginInventory) + player.closeInventory(); + } + + public String getPrefix() { + return ChatColor.DARK_GRAY + "[" + ChatColor.YELLOW + "MMOItems" + ChatColor.DARK_GRAY + "] " + ChatColor.GRAY; + } + + public File getJarFile() { + return plugin.getFile(); + } + + public CraftingManager getCrafting() { + return stationRecipeManager; + } + + public LayoutManager getLayouts() { + return layoutManager; + } + + public SetManager getSets() { + return setManager; + } + + public RPGHandler getRPG() { + return rpgPlugin; + } + + /** + * 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; + + // Preferred rpg provider + String preferred = plugin.getConfig().getString("preferred-rpg-provider", null); + if (preferred != null && setRPG(RPGHandler.PluginEnum.valueOf(preferred.toUpperCase()))) + return; + + // Look through installed plugins + for (RPGHandler.PluginEnum pluginEnum : RPGHandler.PluginEnum.values()) + if (Bukkit.getPluginManager().getPlugin(pluginEnum.getName()) != null && setRPG(pluginEnum)) + return; + + // Just use the default + setRPG(new DefaultHook()); + } + + /** + * The RPGHandler interface lets MMOItems fetch and manipulate RPG data like + * player level, class, resources like mana and stamina for item or skill + * costs, item restrictions, etc. + * + * @param handler Your RPGHandler instance + */ + public void setRPG(RPGHandler handler) { + Validate.notNull(handler, "RPGHandler cannot be null"); + + // Unregister events from current RPGPlugin instance + if (rpgPlugin != null && rpgPlugin instanceof Listener && isEnabled()) + HandlerList.unregisterAll((Listener) rpgPlugin); + + rpgPlugin = handler; + getLogger().log(Level.INFO, "Now using " + handler.getClass().getSimpleName() + " as RPG provider"); + + // Register new events + 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) { + + try { + Validate.notNull(Bukkit.getPluginManager().getPlugin(potentialPlugin.getName()), "Plugin is not installed"); + setRPG(potentialPlugin.load()); + return true; + + // Some loading issue + } catch (Exception 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; + } + + public PlayerInventoryHandler getInventory() { + return inventory; + } + + /** + * The PlayerInventory interface lets MMOItems knows what items to look for + * in player inventories whe doing inventory updates. By default, it only + * checks held items + armor slots. However other plugins like MMOInv do + * implement custom slots and therefore must register a custom + * PlayerInventory instance that tells of additional items to look for. + */ + public void registerPlayerInventory(PlayerInventory value) { + + // Registers in the Inventory Handler + getInventory().register(value); + } + + /** + * The PlayerInventory interface lets MMOItems knows what items to look for + * in player inventories whe doing inventory updates. By default, it only + * checks held items + armor slots. However other plugins like MMOInv do + * implement custom slots and therefore must register a custom + * PlayerInventory instance. + *

+ * Default instance is DefaultPlayerInventory in comp.inventory + * + * @param value The player inventory subclass + * @deprecated Rather than setting this to the only inventory MMOItems will + * search equipment within, you must add your inventory to the + * handler with getInventory().register(). This method + * will clear all other PlayerInventories for now, as to keep + * backwards compatibility. + */ + @Deprecated + public void setPlayerInventory(PlayerInventory value) { + + // Unregisters those previously registered + getInventory().unregisterAll(); + + // Registers this as the only + getInventory().register(value); + } + + /** + * Plugins like MythicEnchants which utilize the Bukkit + * class Enchantment by extending it don't use any ItemStat + * to store their enchants and therefore need to be called + * to update the item lore when any item is built. + * + * @param enchantPlugin Enchantment plugin + */ + public void registerEnchantPlugin(EnchantPlugin enchantPlugin) { + Validate.notNull(enchantPlugin, "Enchant plugin cannot be null"); + enchantPlugins.add(enchantPlugin); + } + + public StatManager getStats() { + return statManager; + } + + public TierManager getTiers() { + return tierManager; + } + + public EntityManager getEntities() { + return entityManager; + } + + public DropTableManager getDropTables() { + return dropTableManager; + } + + public SkillManager getSkills() { + return skillManager; + } + + public BlockManager getCustomBlocks() { + return blockManager; + } + + public WorldGenManager getWorldGen() { + return worldGenManager; + } + + public RecipeManager getRecipes() { + return recipeManager; + } + + public ConfigManager getLanguage() { + return configManager; + } + + public TypeManager getTypes() { + return typeManager; + } + + public UpgradeManager getUpgrades() { + return upgradeManager; + } + + @Deprecated + public PlaceholderParser getPlaceholderParser() { + return placeholderParser; + } + + public TemplateManager getTemplates() { + return templateManager; + } + + public LoreFormatManager getFormats() { + return formatManager; + } + + @Deprecated + public ItemManager getItems() { + return itemManager; + } + + /* + * External API's + */ + public boolean hasPermissions() { + return vaultSupport != null && vaultSupport.getPermissions() != null; + } + + public List> getEnchantPlugins() { + return enchantPlugins; + } + + public boolean hasEconomy() { + return vaultSupport != null && vaultSupport.getEconomy() != null; + } + + public VaultSupport getVault() { + return vaultSupport; + } + + /** + * @deprecated Not used + */ + @Deprecated + public List getStringInputParsers() { + return stringInputParsers; + } + + //region Easy-Access API + + /** + * @return Generates an item given an item template. The item level will + * scale according to the player RPG level if the template has the + * 'level-item' option. The item will pick a random tier if the + * template has the 'tiered' option + */ + @Nullable + public MMOItem getMMOItem(@Nullable Type type, @Nullable String id, @Nullable PlayerData player) { + if (type == null || id == null) { + return null; + } + + // Valid template? + MMOItemTemplate found = getTemplates().getTemplate(type, id); + if (found == null) return null; + + // Build if found + return found.newBuilder(player).build(); + } + + /** + * @return Generates an item given an item template. The item level will + * scale according to the player RPG level if the template has the + * 'level-item' option. The item will pick a random tier if the + * template has the 'tiered' option + */ + @Nullable + public ItemStack getItem(@Nullable Type type, @Nullable String id, @NotNull PlayerData player) { + + // Valid MMOItem? + MMOItem m = getMMOItem(type, id, player); + if (m == null) return null; + + // Build if found + return m.newBuilder().build(); + } + + /** + * @param itemLevel The desired item level + * @param itemTier The desired item tier, can be null + * @return Generates an item given an item template with a + * specific item level and item tier + */ + @Nullable + public MMOItem getMMOItem(@Nullable Type type, @Nullable String id, int itemLevel, @Nullable ItemTier itemTier) { + if (type == null || id == null) { + return null; + } + + // Valid template? + MMOItemTemplate found = getTemplates().getTemplate(type, id); + if (found == null) return null; + + // Build if found + return found.newBuilder(itemLevel, itemTier).build(); + } + + /** + * @param itemLevel The desired item level + * @param itemTier The desired item tier, can be null + * @return Generates an item given an item template with a + * specific item level and item tier + */ + @Nullable + public ItemStack getItem(@Nullable Type type, @Nullable String id, int itemLevel, @Nullable ItemTier itemTier) { + + // Valid MMOItem? + MMOItem m = getMMOItem(type, id, itemLevel, itemTier); + if (m == null) return null; + + // Build if found + return m.newBuilder().build(); + } + + /** + * @return Generates an item given an item template. The item level will be + * 0 and the item will have no item tier unless one is specified in + * the base item data. + *

+ * Will return null if such MMOItem does not exist. + */ + @Nullable + public MMOItem getMMOItem(@Nullable Type type, @Nullable String id) { + return getMMOItem(type, id, 0, null); + } + + /** + * @return Generates an item given an item template. The item level will be + * 0 and the item will have no item tier unless one is specified in + * the base item data. + *

+ * Will return null if such MMOItem does not exist. + */ + + @Nullable + public ItemStack getItem(@Nullable String type, @Nullable String id) { + if (type == null || id == null) { + return null; + } + return getItem(getTypes().get(type), id); + } + + /** + * @return Generates an item given an item template. The item level will be + * 0 and the item will have no item tier unless one is specified in + * the base item data. + *

+ * Will return null if such MMOItem does not exist. + */ + @Nullable + public ItemStack getItem(@Nullable Type type, @Nullable String id) { + if (type == null || id == null) { + return null; + } + + // Valid MMOItem? + MMOItem m = getMMOItem(type, id); + if (m == null) { + return null; + } + + // Build if found + return m.newBuilder().build(); + } + + //region Reading MMOItems from ItemStacks + + /** + * @param stack The stack you trying to read + * @return The MMOItems type of this stack, if it has one + * @see #getType(NBTItem) + */ + @Nullable + public static Type getType(@Nullable ItemStack stack) { + + // Get from nbt + return getType(NBTItem.get(stack)); + } + + /** + * @param nbt The NBTItem you trying to read + * @return The MMOItems type of this nbt, if it has one + */ + @Nullable + public static Type getType(@Nullable NBTItem nbt) { + + // That's it + return plugin.getTypes().get(getTypeName(nbt)); + } + + /** + * @param stack The stack you trying to read + * @return The MMOItems type of this stack, if it has one + * @see #getTypeName(NBTItem) + */ + @Nullable + public static String getTypeName(@Nullable ItemStack stack) { + + // Get from nbt + return getTypeName(NBTItem.get(stack)); + } + + /** + * @param nbt The NBTItem you trying to read + * @return The MMOItems type of this nbt, if it has one + */ + @Nullable + public static String getTypeName(@Nullable NBTItem nbt) { + + // Straight up no + if (nbt == null) { + return null; + } + + // Get from nbt + if (!nbt.hasType()) { + return null; + } + + // That's it + return nbt.getType(); + } + + /** + * @param nbt The ItemStack you trying to read + * @return The MMOItems ID of this stack, if it has one + * @see #getID(NBTItem) + */ + @Nullable + public static String getID(@Nullable ItemStack nbt) { + + // That's it + return getID(NBTItem.get(nbt)); + } + + /** + * @param nbt The NBTItem you trying to read + * @return The MMOItems ID of this nbt, if it has one + */ + @Nullable + public static String getID(@Nullable NBTItem nbt) { + + // Straight up no + if (nbt == null) { + return null; + } + + // That's it + return nbt.getString("MMOITEMS_ITEM_ID"); + } + //endregion + + /** + * Easily log something using the FriendlyFeedbackProvider, nice! + *

+ * Use a null level to use the normal console sender. + * + * @author Gunging + */ + public static void print(@Nullable Level level, @Nullable String message, @Nullable String prefix, @NotNull String... replaces) { + if (message == null) { + message = "< null >"; + } + if (level != null) { + plugin.getLogger().log(level, FriendlyFeedbackProvider.quickForConsole(FFPMMOItems.get(), message, replaces)); + } else { + FriendlyFeedbackMessage p = new FriendlyFeedbackMessage("", prefix); + FriendlyFeedbackMessage r = FriendlyFeedbackProvider.generateMessage(p, message, replaces); + getConsole().sendMessage(r.forConsole(FFPMMOItems.get())); + } + } + + /** + * JULES DO NOT DELETE THIS AGAIN I KNOW ITS UNUSED PRECISELY BECAUSE I ALWAYS COMMENT + * ALL ITS USAGES BEFORE PUSHING ANY UPDATES, I USE IT FOR SPAMMY DEVELOPER MESSAGES + *

+ * Note that {@link #print(Level, String, String, String...)} is used for actual warnings + * or such that the users may see, so dont delete that one either. + * + * @author Gunging + */ + public static void log(@Nullable String message, @NotNull String... replaces) { + print(null, message, null, replaces); + } + + /** + * @return The server's console sender. + * @author Gunging + */ + @NotNull + public static ConsoleCommandSender getConsole() { + return plugin.getServer().getConsoleSender(); + } + //endregion } \ No newline at end of file diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/CustomSound.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/CustomSound.java index 0821ba7e..53e918b1 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/CustomSound.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/CustomSound.java @@ -3,7 +3,7 @@ package net.Indyuce.mmoitems.api; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import io.lumine.mythic.lib.version.VersionMaterial; public enum CustomSound { diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/ItemSet.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/ItemSet.java index fc620ba3..56d764dd 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/ItemSet.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/ItemSet.java @@ -1,10 +1,10 @@ package net.Indyuce.mmoitems.api; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.MMOUtils; import net.Indyuce.mmoitems.stat.data.AbilityData; import net.Indyuce.mmoitems.stat.data.ParticleData; import net.Indyuce.mmoitems.stat.type.ItemStat; +import net.Indyuce.mmoitems.util.MMOUtils; import org.apache.commons.lang.Validate; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.potion.PotionEffect; @@ -31,50 +31,55 @@ public class ItemSet { this.loreTag = config.getStringList("lore-tag"); this.name = config.getString("name"); - Validate.isTrue(config.contains("bonuses"), "Could not find item set bonuses"); + Validate.isTrue(config.isConfigurationSection("bonuses"), "Could not find item set bonuses"); for (int j = 2; j <= itemLimit; j++) if (config.getConfigurationSection("bonuses").contains(String.valueOf(j))) { - SetBonuses bonuses = new SetBonuses(); + final String bonusesKey = "bonuses.%d".formatted(j); + final SetBonuses bonuses = new SetBonuses(); + final ConfigurationSection bonusesSection = config.getConfigurationSection(bonusesKey); + Validate.notNull(bonusesSection, "Item set '%s' is not a valid configuration section.".formatted(id)); // Add permissions - for (String perm : config.getConfigurationSection("bonuses." + j).getStringList("granted-permissions")) + for (String perm : bonusesSection.getStringList("granted-permissions")) bonuses.addPermission(perm); - for (String key : config.getConfigurationSection("bonuses." + j).getKeys(false)) + for (String key : bonusesSection.getKeys(false)) if (!key.equals("granted-permissions")) { - try { String format = key.toUpperCase().replace("-", "_").replace(" ", "_"); // ability if (key.startsWith("ability-")) { - bonuses.addAbility(new AbilityData(config.getConfigurationSection("bonuses." + j + "." + key))); + final ConfigurationSection section = config.getConfigurationSection("%s.%s".formatted(bonusesKey, key)); + Validate.notNull(section, "Ability '%s' is not a valid configuration section.".formatted(key)); + bonuses.addAbility(new AbilityData(section)); continue; } // potion effect if (key.startsWith("potion-")) { PotionEffectType potionEffectType = PotionEffectType.getByName(format.substring("potion-".length())); - Validate.notNull(potionEffectType, "Could not load potion effect type from '" + format + "'"); + Validate.notNull(potionEffectType, "Could not load potion effect type from '%s'".formatted(format)); bonuses.addPotionEffect(new PotionEffect(potionEffectType, MMOUtils.getEffectDuration(potionEffectType), - config.getInt("bonuses." + j + "." + key) - 1, true, false)); + config.getInt("%s.%s".formatted(bonusesKey, key)) - 1, true, false)); continue; } // particle effect if (key.startsWith("particle-")) { - bonuses.addParticle(new ParticleData(config.getConfigurationSection("bonuses." + j + "." + key))); + final ConfigurationSection section = config.getConfigurationSection("bonuses.%d.%s".formatted(j, key)); + Validate.notNull(section, "Particle effect '%s' is not a valid configuration section.".formatted(key)); + bonuses.addParticle(new ParticleData(section)); continue; } // stat - ItemStat stat = MMOItems.plugin.getStats().get(format); - Validate.notNull(stat, "Could not find stat called '" + format + "'"); - bonuses.addStat(stat, config.getDouble("bonuses." + j + "." + key)); - + ItemStat stat = MMOItems.plugin.getStats().get(format); + Validate.notNull(stat, "Could not find stat called '%s'".formatted(format)); + bonuses.addStat(stat, config.getDouble("bonuses.%d.%s".formatted(j, key))); } catch (IllegalArgumentException exception) { - throw new IllegalArgumentException("Could not load set bonus '" + key + "': " + exception.getMessage()); + throw new IllegalArgumentException("Could not load set bonus '%s': %s".formatted(key, exception.getMessage())); } } @@ -103,13 +108,13 @@ public class ItemSet { } public static class SetBonuses { - private final Map stats = new HashMap<>(); + private final Map, Double> stats = new HashMap<>(); private final Map permEffects = new HashMap<>(); private final Set abilities = new HashSet<>(); private final Set particles = new HashSet<>(); private final ArrayList permissions = new ArrayList<>(); - public void addStat(ItemStat stat, double value) { + public void addStat(ItemStat stat, double value) { stats.put(stat, value); } @@ -129,15 +134,15 @@ public class ItemSet { permissions.add(permission); } - public boolean hasStat(ItemStat stat) { + public boolean hasStat(ItemStat stat) { return stats.containsKey(stat); } - public double getStat(ItemStat stat) { + public double getStat(ItemStat stat) { return stats.get(stat); } - public Map getStats() { + public Map, Double> getStats() { return stats; } diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/TypeSet.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/TypeSet.java index 51ae6ade..e3d03c5e 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/TypeSet.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/TypeSet.java @@ -6,7 +6,7 @@ import io.lumine.mythic.lib.damage.AttackMetadata; import io.lumine.mythic.lib.damage.DamageType; import io.lumine.mythic.lib.version.VersionSound; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.interaction.weapon.Weapon; import net.Indyuce.mmoitems.api.player.PlayerData; import net.Indyuce.mmoitems.api.player.PlayerData.CooldownType; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/crafting/ingredient/MMOItemIngredient.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/crafting/ingredient/MMOItemIngredient.java index 5b1aaa89..777723e8 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/crafting/ingredient/MMOItemIngredient.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/crafting/ingredient/MMOItemIngredient.java @@ -6,7 +6,7 @@ import io.lumine.mythic.lib.api.util.ui.QuickNumberRange; import io.lumine.mythic.lib.api.util.ui.SilentNumbers; import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.api.crafting.ConfigMMOItem; import net.Indyuce.mmoitems.api.crafting.ingredient.inventory.MMOItemPlayerIngredient; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/crafting/ingredient/VanillaIngredient.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/crafting/ingredient/VanillaIngredient.java index b8084497..1d6adb31 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/crafting/ingredient/VanillaIngredient.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/crafting/ingredient/VanillaIngredient.java @@ -10,8 +10,7 @@ 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.api.util.ui.SilentNumbers; -import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.crafting.ingredient.inventory.VanillaPlayerIngredient; import net.Indyuce.mmoitems.api.player.RPGPlayer; import net.Indyuce.mmoitems.api.util.message.FFPMMOItems; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/crafting/recipe/UpgradingRecipe.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/crafting/recipe/UpgradingRecipe.java index f103b938..bb815a80 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/crafting/recipe/UpgradingRecipe.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/crafting/recipe/UpgradingRecipe.java @@ -2,7 +2,7 @@ package net.Indyuce.mmoitems.api.crafting.recipe; import io.lumine.mythic.lib.api.item.NBTItem; import net.Indyuce.mmoitems.ItemStats; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.crafting.ConfigMMOItem; import net.Indyuce.mmoitems.api.crafting.CraftingStation; import net.Indyuce.mmoitems.api.crafting.ingredient.CheckedIngredient; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/event/item/RepairItemEvent.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/event/item/RepairItemEvent.java index 6ff40a96..3cc45af7 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/event/item/RepairItemEvent.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/event/item/RepairItemEvent.java @@ -8,67 +8,63 @@ import net.Indyuce.mmoitems.api.player.PlayerData; import io.lumine.mythic.lib.api.item.NBTItem; public class RepairItemEvent extends PlayerDataEvent { - private static final HandlerList handlers = new HandlerList(); + private static final HandlerList handlers = new HandlerList(); - private final VolatileMMOItem consumable; - private final NBTItem target; + private final VolatileMMOItem consumable; + private final NBTItem target; - private int repaired; - private double repairedPercent; + private int repaired = -1; + private double repairedPercent = -1; - /** - * Called when a player repairs an item using a consumable - * - * @param playerData - * Player repairing the item - * @param consumable - * Consumable used to repair the item - * @param target - * Item being repaired - * @param repaired - * Amount of durability being repaired - */ - public RepairItemEvent(PlayerData playerData, VolatileMMOItem consumable, NBTItem target, int repaired) { - super(playerData); + /** + * Called when a player repairs an item using a consumable + * + * @param playerData Player repairing the item + * @param consumable Consumable used to repair the item + * @param target Item being repaired + * @param repaired Amount of durability being repaired + */ + public RepairItemEvent(PlayerData playerData, VolatileMMOItem consumable, NBTItem target, int repaired) { + super(playerData); - this.consumable = consumable; - this.target = target; - this.repaired = repaired; - } + this.consumable = consumable; + this.target = target; + this.repaired = repaired; + } - public RepairItemEvent(PlayerData playerData, VolatileMMOItem consumable, NBTItem target, double repaired) { - super(playerData); + public RepairItemEvent(PlayerData playerData, VolatileMMOItem consumable, NBTItem target, double repaired) { + super(playerData); - this.consumable = consumable; - this.target = target; - this.repairedPercent = repaired; - } + this.consumable = consumable; + this.target = target; + this.repairedPercent = repaired; + } - public VolatileMMOItem getConsumable() { - return consumable; - } + public VolatileMMOItem getConsumable() { + return consumable; + } - public NBTItem getTargetItem() { - return target; - } + public NBTItem getTargetItem() { + return target; + } - public int getRepaired() { - return repaired; - } + public int getRepaired() { + return repaired; + } - public double getRepairedPercent(){ - return repairedPercent; - } + public double getRepairedPercent() { + return repairedPercent; + } - public void setRepaired(int repaired) { - this.repaired = repaired; - } + public void setRepaired(int repaired) { + this.repaired = repaired; + } - public HandlerList getHandlers() { - return handlers; - } + public HandlerList getHandlers() { + return handlers; + } - public static HandlerList getHandlerList() { - return handlers; - } + public static HandlerList getHandlerList() { + return handlers; + } } diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/GemStone.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/GemStone.java index d5d93646..3edb7701 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/GemStone.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/GemStone.java @@ -2,7 +2,7 @@ package net.Indyuce.mmoitems.api.interaction; import io.lumine.mythic.lib.api.item.NBTItem; import net.Indyuce.mmoitems.ItemStats; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.api.event.item.ApplyGemStoneEvent; import net.Indyuce.mmoitems.api.item.mmoitem.LiveMMOItem; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/ItemSkin.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/ItemSkin.java index 32a0779c..c0c3c0b5 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/ItemSkin.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/ItemSkin.java @@ -5,7 +5,7 @@ import io.lumine.mythic.lib.api.item.NBTItem; import io.lumine.mythic.lib.version.VersionMaterial; import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.api.item.mmoitem.VolatileMMOItem; import net.Indyuce.mmoitems.api.util.message.Message; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/weapon/untargeted/Lute.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/weapon/untargeted/Lute.java index 1eab584b..1941495b 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/weapon/untargeted/Lute.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/weapon/untargeted/Lute.java @@ -11,7 +11,7 @@ import io.lumine.mythic.lib.player.PlayerMetadata; import io.lumine.mythic.lib.version.VersionSound; import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.util.SoundReader; import net.Indyuce.mmoitems.stat.LuteAttackEffectStat.LuteAttackEffect; import net.Indyuce.mmoitems.stat.data.ProjectileParticlesData; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/weapon/untargeted/lute/BruteLuteAttack.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/weapon/untargeted/lute/BruteLuteAttack.java index 2b36223c..1a2e6765 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/weapon/untargeted/lute/BruteLuteAttack.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/weapon/untargeted/lute/BruteLuteAttack.java @@ -5,12 +5,10 @@ import io.lumine.mythic.lib.MythicLib; import io.lumine.mythic.lib.UtilityMethods; import io.lumine.mythic.lib.api.item.NBTItem; import io.lumine.mythic.lib.comp.target.InteractionType; -import io.lumine.mythic.lib.damage.AttackMetadata; -import io.lumine.mythic.lib.damage.DamageMetadata; import io.lumine.mythic.lib.damage.DamageType; import io.lumine.mythic.lib.player.PlayerMetadata; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.util.SoundReader; import net.Indyuce.mmoitems.stat.data.ProjectileParticlesData; import org.bukkit.Location; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/weapon/untargeted/lute/CircularLuteAttack.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/weapon/untargeted/lute/CircularLuteAttack.java index 3226423a..0e292af3 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/weapon/untargeted/lute/CircularLuteAttack.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/weapon/untargeted/lute/CircularLuteAttack.java @@ -5,12 +5,10 @@ import io.lumine.mythic.lib.MythicLib; import io.lumine.mythic.lib.UtilityMethods; import io.lumine.mythic.lib.api.item.NBTItem; import io.lumine.mythic.lib.comp.target.InteractionType; -import io.lumine.mythic.lib.damage.AttackMetadata; -import io.lumine.mythic.lib.damage.DamageMetadata; import io.lumine.mythic.lib.damage.DamageType; import io.lumine.mythic.lib.player.PlayerMetadata; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.util.SoundReader; import net.Indyuce.mmoitems.stat.data.ProjectileParticlesData; import org.bukkit.Location; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/weapon/untargeted/lute/SimpleLuteAttack.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/weapon/untargeted/lute/SimpleLuteAttack.java index 89d9921f..630bcce7 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/weapon/untargeted/lute/SimpleLuteAttack.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/weapon/untargeted/lute/SimpleLuteAttack.java @@ -5,12 +5,10 @@ import io.lumine.mythic.lib.MythicLib; import io.lumine.mythic.lib.UtilityMethods; import io.lumine.mythic.lib.api.item.NBTItem; import io.lumine.mythic.lib.comp.target.InteractionType; -import io.lumine.mythic.lib.damage.AttackMetadata; -import io.lumine.mythic.lib.damage.DamageMetadata; import io.lumine.mythic.lib.damage.DamageType; import io.lumine.mythic.lib.player.PlayerMetadata; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.util.SoundReader; import net.Indyuce.mmoitems.stat.data.ProjectileParticlesData; import org.bukkit.Location; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/weapon/untargeted/lute/SlashLuteAttack.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/weapon/untargeted/lute/SlashLuteAttack.java index abfb98a2..b455b7f1 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/weapon/untargeted/lute/SlashLuteAttack.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/weapon/untargeted/lute/SlashLuteAttack.java @@ -5,12 +5,10 @@ import io.lumine.mythic.lib.MythicLib; import io.lumine.mythic.lib.UtilityMethods; import io.lumine.mythic.lib.api.item.NBTItem; import io.lumine.mythic.lib.comp.target.InteractionType; -import io.lumine.mythic.lib.damage.AttackMetadata; -import io.lumine.mythic.lib.damage.DamageMetadata; import io.lumine.mythic.lib.damage.DamageType; import io.lumine.mythic.lib.player.PlayerMetadata; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.util.SoundReader; import net.Indyuce.mmoitems.stat.data.ProjectileParticlesData; import org.bukkit.Location; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/weapon/untargeted/lute/WaveLuteAttack.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/weapon/untargeted/lute/WaveLuteAttack.java index 1eef891a..1e0516a0 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/weapon/untargeted/lute/WaveLuteAttack.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/weapon/untargeted/lute/WaveLuteAttack.java @@ -5,12 +5,10 @@ import io.lumine.mythic.lib.MythicLib; import io.lumine.mythic.lib.UtilityMethods; import io.lumine.mythic.lib.api.item.NBTItem; import io.lumine.mythic.lib.comp.target.InteractionType; -import io.lumine.mythic.lib.damage.AttackMetadata; -import io.lumine.mythic.lib.damage.DamageMetadata; import io.lumine.mythic.lib.damage.DamageType; import io.lumine.mythic.lib.player.PlayerMetadata; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.util.SoundReader; import net.Indyuce.mmoitems.stat.data.ProjectileParticlesData; import org.bukkit.Location; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/weapon/untargeted/staff/ManaSpirit.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/weapon/untargeted/staff/ManaSpirit.java index 927c504e..4b8c23a8 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/weapon/untargeted/staff/ManaSpirit.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/weapon/untargeted/staff/ManaSpirit.java @@ -4,11 +4,10 @@ import io.lumine.mythic.lib.UtilityMethods; import io.lumine.mythic.lib.api.item.NBTItem; import io.lumine.mythic.lib.api.player.EquipmentSlot; import io.lumine.mythic.lib.comp.target.InteractionType; -import io.lumine.mythic.lib.damage.AttackMetadata; import io.lumine.mythic.lib.damage.DamageType; import io.lumine.mythic.lib.player.PlayerMetadata; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import org.bukkit.Color; import org.bukkit.Location; import org.bukkit.Particle; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/weapon/untargeted/staff/NetherSpirit.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/weapon/untargeted/staff/NetherSpirit.java index a0a9f7d6..7890235f 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/weapon/untargeted/staff/NetherSpirit.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/weapon/untargeted/staff/NetherSpirit.java @@ -4,11 +4,10 @@ import io.lumine.mythic.lib.UtilityMethods; import io.lumine.mythic.lib.api.item.NBTItem; import io.lumine.mythic.lib.api.player.EquipmentSlot; import io.lumine.mythic.lib.comp.target.InteractionType; -import io.lumine.mythic.lib.damage.AttackMetadata; import io.lumine.mythic.lib.damage.DamageType; import io.lumine.mythic.lib.player.PlayerMetadata; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import org.bukkit.Location; import org.bukkit.Particle; import org.bukkit.Sound; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/weapon/untargeted/staff/SunfireSpirit.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/weapon/untargeted/staff/SunfireSpirit.java index d7c4fbfb..4509f193 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/weapon/untargeted/staff/SunfireSpirit.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/weapon/untargeted/staff/SunfireSpirit.java @@ -4,12 +4,11 @@ import io.lumine.mythic.lib.UtilityMethods; import io.lumine.mythic.lib.api.item.NBTItem; import io.lumine.mythic.lib.api.player.EquipmentSlot; import io.lumine.mythic.lib.comp.target.InteractionType; -import io.lumine.mythic.lib.damage.AttackMetadata; import io.lumine.mythic.lib.damage.DamageType; import io.lumine.mythic.lib.player.PlayerMetadata; import io.lumine.mythic.lib.version.VersionSound; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import org.bukkit.Location; import org.bukkit.Particle; import org.bukkit.Sound; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/weapon/untargeted/staff/ThunderSpirit.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/weapon/untargeted/staff/ThunderSpirit.java index 948b565e..c451c9df 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/weapon/untargeted/staff/ThunderSpirit.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/weapon/untargeted/staff/ThunderSpirit.java @@ -8,7 +8,7 @@ import io.lumine.mythic.lib.damage.DamageType; import io.lumine.mythic.lib.player.PlayerMetadata; import io.lumine.mythic.lib.version.VersionSound; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import org.bukkit.Location; import org.bukkit.Particle; import org.bukkit.Sound; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/weapon/untargeted/staff/VoidSpirit.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/weapon/untargeted/staff/VoidSpirit.java index 57aa444f..b479ce7b 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/weapon/untargeted/staff/VoidSpirit.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/weapon/untargeted/staff/VoidSpirit.java @@ -2,12 +2,11 @@ package net.Indyuce.mmoitems.api.interaction.weapon.untargeted.staff; import io.lumine.mythic.lib.api.item.NBTItem; import io.lumine.mythic.lib.api.player.EquipmentSlot; -import io.lumine.mythic.lib.damage.AttackMetadata; import io.lumine.mythic.lib.damage.DamageMetadata; import io.lumine.mythic.lib.damage.DamageType; import io.lumine.mythic.lib.player.PlayerMetadata; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.skill.Shulker_Missile; +import net.Indyuce.mmoitems.skill.ShulkerMissile; import org.bukkit.Sound; import org.bukkit.entity.EntityType; import org.bukkit.entity.ShulkerBullet; @@ -34,6 +33,6 @@ public class VoidSpirit implements StaffAttackHandler { shulkerBullet.setVelocity(vec); } }.runTaskTimer(MMOItems.plugin, 0, 1); - MMOItems.plugin.getEntities().registerCustomEntity(shulkerBullet, new Shulker_Missile.ShulkerMissileEntityData(caster, new DamageMetadata(damage, DamageType.WEAPON, DamageType.MAGIC, DamageType.PROJECTILE), 0, nbt)); + MMOItems.plugin.getEntities().registerCustomEntity(shulkerBullet, new ShulkerMissile.ShulkerMissileEntityData(caster, new DamageMetadata(damage, DamageType.WEAPON, DamageType.MAGIC, DamageType.PROJECTILE), 0, nbt)); } } diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/item/template/NameModifier.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/item/template/NameModifier.java index a504a334..7e87a8f6 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/item/template/NameModifier.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/item/template/NameModifier.java @@ -1,7 +1,6 @@ package net.Indyuce.mmoitems.api.item.template; -import io.lumine.mythic.lib.MythicLib; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import org.apache.commons.lang.Validate; import org.bukkit.configuration.ConfigurationSection; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/item/util/ConfigItem.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/item/util/ConfigItem.java index 20533af5..b2b3572a 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/item/util/ConfigItem.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/item/util/ConfigItem.java @@ -3,7 +3,7 @@ package net.Indyuce.mmoitems.api.item.util; import io.lumine.mythic.lib.MythicLib; import io.lumine.mythic.lib.api.item.ItemTag; import io.lumine.mythic.lib.api.util.ui.SilentNumbers; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import org.apache.commons.lang.Validate; import org.bukkit.ChatColor; import org.bukkit.Material; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/item/util/crafting/CraftingRecipeDisplay.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/item/util/crafting/CraftingRecipeDisplay.java index bf59f37a..9cf7359f 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/item/util/crafting/CraftingRecipeDisplay.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/item/util/crafting/CraftingRecipeDisplay.java @@ -5,7 +5,7 @@ import io.lumine.mythic.lib.adventure.text.Component; import io.lumine.mythic.lib.api.item.ItemTag; import io.lumine.mythic.lib.api.item.NBTItem; import io.lumine.mythic.lib.api.util.LegacyComponent; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.crafting.ConditionalDisplay; import net.Indyuce.mmoitems.api.crafting.condition.CheckedCondition; import net.Indyuce.mmoitems.api.crafting.recipe.CheckedRecipe; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/item/util/crafting/UpgradingRecipeDisplay.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/item/util/crafting/UpgradingRecipeDisplay.java index e71abd19..f1ba20e5 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/item/util/crafting/UpgradingRecipeDisplay.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/item/util/crafting/UpgradingRecipeDisplay.java @@ -4,7 +4,7 @@ import io.lumine.mythic.lib.adventure.text.Component; import io.lumine.mythic.lib.api.item.ItemTag; import io.lumine.mythic.lib.api.item.NBTItem; import io.lumine.mythic.lib.api.util.LegacyComponent; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.crafting.ConditionalDisplay; import net.Indyuce.mmoitems.api.crafting.condition.CheckedCondition; import net.Indyuce.mmoitems.api.crafting.recipe.CheckedRecipe; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/player/PlayerStats.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/player/PlayerStats.java index 3d79104a..9ba0c830 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/player/PlayerStats.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/player/PlayerStats.java @@ -8,7 +8,6 @@ import io.lumine.mythic.lib.player.PlayerMetadata; import io.lumine.mythic.lib.player.modifier.ModifierSource; import io.lumine.mythic.lib.player.modifier.ModifierType; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.api.player.inventory.EquippedItem; import net.Indyuce.mmoitems.stat.type.AttackWeaponStat; import net.Indyuce.mmoitems.stat.type.ItemStat; @@ -28,11 +27,11 @@ public class PlayerStats { return playerData.getMMOPlayerData().getStatMap(); } - public double getStat(ItemStat stat) { + public double getStat(ItemStat stat) { return getMap().getInstance(stat.getId()).getTotal(); } - public StatInstance getInstance(ItemStat stat) { + public StatInstance getInstance(ItemStat stat) { return getMap().getInstance(stat.getId()); } @@ -50,8 +49,7 @@ public class PlayerStats { } public void updateStats() { - - for (ItemStat stat : MMOItems.plugin.getStats().getNumericStats()) { + for (ItemStat stat : MMOItems.plugin.getStats().getNumericStats()) { // Let MMOItems first add stat modifiers, and then update the stat instance StatInstance.ModifierPacket packet = getInstance(stat).newPacket(); diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/recipe/CraftingType.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/recipe/CraftingType.java index eac9ac63..d97ebeb7 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/recipe/CraftingType.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/recipe/CraftingType.java @@ -2,7 +2,7 @@ package net.Indyuce.mmoitems.api.recipe; import io.lumine.mythic.lib.MythicLib; import io.lumine.mythic.lib.version.VersionMaterial; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.manager.RecipeManager; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/GiveCommandTreeNode.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/GiveCommandTreeNode.java index 744b3d97..66e99ad7 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/GiveCommandTreeNode.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/GiveCommandTreeNode.java @@ -5,7 +5,7 @@ import io.lumine.mythic.lib.command.api.CommandTreeNode; import io.lumine.mythic.lib.command.api.Parameter; import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem; import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/mmocore/MMOCoreHook.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/mmocore/MMOCoreHook.java index 2bd42c8c..5a73779b 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/mmocore/MMOCoreHook.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/mmocore/MMOCoreHook.java @@ -13,8 +13,8 @@ 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.stat.ExtraAttribute; -import net.Indyuce.mmoitems.comp.mmocore.stat.Required_Attribute; -import net.Indyuce.mmoitems.comp.mmocore.stat.Required_Profession; +import net.Indyuce.mmoitems.comp.mmocore.stat.RequiredAttribute; +import net.Indyuce.mmoitems.comp.mmocore.stat.RequiredProfession; import net.Indyuce.mmoitems.comp.rpg.RPGHandler; import net.Indyuce.mmoitems.stat.type.DoubleStat; import org.bukkit.event.EventHandler; @@ -32,7 +32,7 @@ public class MMOCoreHook implements RPGHandler, Listener { */ public MMOCoreHook() { for (PlayerAttribute attribute : MMOCore.plugin.attributeManager.getAll()) { - MMOItems.plugin.getStats().register(new Required_Attribute(attribute)); + MMOItems.plugin.getStats().register(new RequiredAttribute(attribute)); MMOItems.plugin.getStats().register(new ExtraAttribute(attribute)); } @@ -43,8 +43,7 @@ public class MMOCoreHook implements RPGHandler, Listener { .replace('-', '_').replace(' ', '_').toUpperCase(Locale.ROOT), VersionMaterial.EXPERIENCE_BOTTLE.toMaterial(), profession.getName() + ' ' + "Additional Experience (MMOCore)" , new String[]{"Additional MMOCore profession " + profession.getName() + " experience in %."}, new String[]{"!block", "all"})); - - MMOItems.plugin.getStats().register(new Required_Profession(profession)); + MMOItems.plugin.getStats().register(new RequiredProfession(profession)); } } diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/mmocore/stat/Required_Attribute.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/mmocore/stat/RequiredAttribute.java similarity index 91% rename from MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/mmocore/stat/Required_Attribute.java rename to MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/mmocore/stat/RequiredAttribute.java index b3ddc068..3dc03dc7 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/mmocore/stat/Required_Attribute.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/mmocore/stat/RequiredAttribute.java @@ -12,11 +12,11 @@ import net.Indyuce.mmoitems.stat.type.ItemRestriction; import org.bukkit.ChatColor; import org.bukkit.Sound; -public class Required_Attribute extends DoubleStat implements ItemRestriction, GemStoneStat { +public class RequiredAttribute extends DoubleStat implements ItemRestriction, GemStoneStat { private final PlayerAttribute attribute; // TODO merge with RequiredLevelStat - public Required_Attribute(PlayerAttribute attribute) { + public RequiredAttribute(PlayerAttribute attribute) { super("REQUIRED_" + attribute.getId().toUpperCase().replace("-", "_"), VersionMaterial.GRAY_DYE.toMaterial(), attribute.getName() + " Requirement (MMOCore)", new String[]{"Amount of " + attribute.getName() + " points the", "player needs to use the item."}, new String[]{"!block", "all"}); this.attribute = attribute; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/mmocore/stat/Required_Profession.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/mmocore/stat/RequiredProfession.java similarity index 91% rename from MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/mmocore/stat/Required_Profession.java rename to MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/mmocore/stat/RequiredProfession.java index f5271972..cdec8b75 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/mmocore/stat/Required_Profession.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/mmocore/stat/RequiredProfession.java @@ -12,11 +12,11 @@ import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.Sound; -public class Required_Profession extends DoubleStat implements ItemRestriction, GemStoneStat { +public class RequiredProfession extends DoubleStat implements ItemRestriction, GemStoneStat { private final Profession profession; // TODO merge with RequiredLevelStat - public Required_Profession(Profession profession) { + public RequiredProfession(Profession profession) { super("PROFESSION_" + profession.getId().toUpperCase().replace("-", "_"), Material.PINK_DYE, profession.getName() + " Requirement (MMOCore)", new String[]{"Amount of " + profession.getName() + " levels the", "player needs to use the item."}, new String[]{"!block", "all"}); diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/mythicmobs/LootsplosionListener.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/mythicmobs/LootsplosionListener.java index 520012c9..8ce3249f 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/mythicmobs/LootsplosionListener.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/mythicmobs/LootsplosionListener.java @@ -4,7 +4,7 @@ import io.lumine.mythic.bukkit.events.MythicMobDeathEvent; import io.lumine.mythic.lib.MythicLib; import io.lumine.mythic.lib.api.item.NBTItem; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.ItemTier; import org.bukkit.Bukkit; import org.bukkit.ChatColor; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/CraftingStationPreview.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/CraftingStationPreview.java index 160d1a58..0ed9f6cf 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/CraftingStationPreview.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/CraftingStationPreview.java @@ -5,7 +5,7 @@ import io.lumine.mythic.lib.adventure.text.Component; import io.lumine.mythic.lib.api.item.NBTItem; import io.lumine.mythic.lib.api.util.LegacyComponent; import io.lumine.mythic.lib.api.util.ui.SilentNumbers; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.crafting.ingredient.CheckedIngredient; import net.Indyuce.mmoitems.api.crafting.recipe.CheckedRecipe; import net.Indyuce.mmoitems.api.crafting.recipe.CraftingRecipe; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/CraftingStationView.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/CraftingStationView.java index 74fb3ad2..63133e21 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/CraftingStationView.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/CraftingStationView.java @@ -4,7 +4,7 @@ import io.lumine.mythic.lib.MythicLib; import io.lumine.mythic.lib.api.item.NBTItem; import io.lumine.mythic.lib.api.util.SmartGive; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.crafting.CraftingStation; import net.Indyuce.mmoitems.api.crafting.CraftingStatus.CraftingQueue; import net.Indyuce.mmoitems.api.crafting.CraftingStatus.CraftingQueue.CraftingInfo; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/ItemBrowser.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/ItemBrowser.java index ee5c3a47..145e1fe6 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/ItemBrowser.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/ItemBrowser.java @@ -7,7 +7,7 @@ import io.lumine.mythic.lib.api.util.AltChar; import io.lumine.mythic.lib.api.util.ui.SilentNumbers; import io.lumine.mythic.lib.version.VersionMaterial; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.api.edition.NewItemEdition; import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/AbilityEdition.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/AbilityEdition.java index 469f182d..bd5f1e1e 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/AbilityEdition.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/AbilityEdition.java @@ -3,7 +3,7 @@ package net.Indyuce.mmoitems.gui.edition; import io.lumine.mythic.lib.skill.trigger.TriggerType; import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.edition.StatEdition; import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate; import net.Indyuce.mmoitems.api.util.NumericStatFormula; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/AbilityListEdition.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/AbilityListEdition.java index 15a7b00a..41dfe6f3 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/AbilityListEdition.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/AbilityListEdition.java @@ -17,7 +17,7 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate; import net.Indyuce.mmoitems.api.util.NumericStatFormula; import io.lumine.mythic.lib.MythicLib; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/ArrowParticlesEdition.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/ArrowParticlesEdition.java index 86ee4d14..754e4e5a 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/ArrowParticlesEdition.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/ArrowParticlesEdition.java @@ -2,7 +2,7 @@ package net.Indyuce.mmoitems.gui.edition; import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.edition.StatEdition; import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate; import net.Indyuce.mmoitems.stat.data.ParticleData; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/CommandListEdition.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/CommandListEdition.java index f2b00fd7..207ca634 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/CommandListEdition.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/CommandListEdition.java @@ -2,7 +2,7 @@ package net.Indyuce.mmoitems.gui.edition; import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.edition.StatEdition; import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate; import io.lumine.mythic.lib.MythicLib; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/ElementsEdition.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/ElementsEdition.java index a34fb536..c55c6b7c 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/ElementsEdition.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/ElementsEdition.java @@ -5,7 +5,7 @@ import io.lumine.mythic.lib.api.util.AltChar; import io.lumine.mythic.lib.element.Element; import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.edition.StatEdition; import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate; import net.Indyuce.mmoitems.stat.data.random.RandomElementListData; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/ItemEdition.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/ItemEdition.java index 77cdd5d5..aec3b8ff 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/ItemEdition.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/ItemEdition.java @@ -5,7 +5,7 @@ import io.lumine.mythic.lib.api.item.ItemTag; import io.lumine.mythic.lib.api.item.NBTItem; import io.lumine.mythic.lib.version.VersionMaterial; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate; import net.Indyuce.mmoitems.stat.type.InternalStat; import net.Indyuce.mmoitems.stat.type.ItemStat; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/ParticlesEdition.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/ParticlesEdition.java index bb676fe8..4d088ea2 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/ParticlesEdition.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/ParticlesEdition.java @@ -2,7 +2,7 @@ package net.Indyuce.mmoitems.gui.edition; import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.edition.StatEdition; import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate; import net.Indyuce.mmoitems.particle.api.ParticleType; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/RevisionInventory.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/RevisionInventory.java index 2754ffef..f5025529 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/RevisionInventory.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/RevisionInventory.java @@ -5,14 +5,12 @@ import io.lumine.mythic.lib.version.VersionMaterial; import io.lumine.mythic.lib.api.util.ItemFactory; import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate; import net.Indyuce.mmoitems.api.util.MMOItemReforger; import net.Indyuce.mmoitems.stat.RevisionID; import org.bukkit.Bukkit; -import org.bukkit.ChatColor; import org.bukkit.Material; -import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.event.inventory.InventoryAction; import org.bukkit.event.inventory.InventoryClickEvent; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/SoundsEdition.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/SoundsEdition.java index d4a72c6b..c3254349 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/SoundsEdition.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/SoundsEdition.java @@ -2,7 +2,7 @@ package net.Indyuce.mmoitems.gui.edition; import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.CustomSound; import net.Indyuce.mmoitems.api.edition.StatEdition; import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/UpgradingEdition.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/UpgradingEdition.java index 6ba866a8..6ba1b301 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/UpgradingEdition.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/UpgradingEdition.java @@ -2,7 +2,7 @@ package net.Indyuce.mmoitems.gui.edition; import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.api.edition.StatEdition; import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/recipe/RecipeListEdition.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/recipe/RecipeListEdition.java index 443b9e9b..4d605281 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/recipe/RecipeListEdition.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/recipe/RecipeListEdition.java @@ -15,7 +15,7 @@ import org.bukkit.inventory.meta.ItemMeta; import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.edition.StatEdition; import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate; import net.Indyuce.mmoitems.api.recipe.CraftingType; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/listener/GuiListener.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/listener/GuiListener.java index c8a4322d..53142409 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/listener/GuiListener.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/listener/GuiListener.java @@ -2,15 +2,13 @@ package net.Indyuce.mmoitems.gui.listener; import io.lumine.mythic.lib.api.item.NBTItem; import io.lumine.mythic.lib.api.util.AltChar; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate; import net.Indyuce.mmoitems.gui.ItemBrowser; import net.Indyuce.mmoitems.gui.PluginInventory; import net.Indyuce.mmoitems.gui.edition.EditionInventory; import net.Indyuce.mmoitems.gui.edition.ItemEdition; import net.Indyuce.mmoitems.gui.edition.recipe.RecipeBrowserGUI; -import net.Indyuce.mmoitems.gui.edition.recipe.RecipeEdition; -import net.Indyuce.mmoitems.gui.edition.recipe.RecipeListEdition; import net.Indyuce.mmoitems.gui.edition.recipe.RecipeListGUI; import net.Indyuce.mmoitems.gui.edition.recipe.recipes.RecipeMakerGUI; import org.bukkit.ChatColor; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/manager/ConfigManager.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/manager/ConfigManager.java index 5e47af57..f8c55bd6 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/manager/ConfigManager.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/manager/ConfigManager.java @@ -4,7 +4,7 @@ import io.lumine.mythic.lib.MythicLib; import io.lumine.mythic.lib.api.util.AltChar; import io.lumine.mythic.lib.skill.trigger.TriggerType; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.ConfigFile; import net.Indyuce.mmoitems.api.ReforgeOptions; import net.Indyuce.mmoitems.api.item.util.ConfigItem; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/manager/DropTableManager.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/manager/DropTableManager.java index d26de9d3..829476f1 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/manager/DropTableManager.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/manager/DropTableManager.java @@ -2,7 +2,7 @@ package net.Indyuce.mmoitems.manager; import io.lumine.mythic.lib.UtilityMethods; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.ConfigFile; import net.Indyuce.mmoitems.api.block.CustomBlock; import net.Indyuce.mmoitems.api.droptable.DropTable; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/manager/SetManager.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/manager/SetManager.java index 1180f098..6708bb63 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/manager/SetManager.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/manager/SetManager.java @@ -3,6 +3,7 @@ package net.Indyuce.mmoitems.manager; import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.api.ConfigFile; import net.Indyuce.mmoitems.api.ItemSet; +import org.bukkit.configuration.ConfigurationSection; import java.util.Collection; import java.util.HashMap; @@ -10,37 +11,40 @@ import java.util.Map; import java.util.logging.Level; public class SetManager implements Reloadable { - private final Map itemSets = new HashMap<>(); + private final Map itemSets = new HashMap<>(); - public SetManager() { - reload(); - } + public SetManager() { + reload(); + } - public void reload() { - itemSets.clear(); + public void reload() { + itemSets.clear(); - ConfigFile config = new ConfigFile("item-sets"); - for (String id : config.getConfig().getKeys(false)) - try { - itemSets.put(id, new ItemSet(config.getConfig().getConfigurationSection(id))); - } catch (IllegalArgumentException exception) { - MMOItems.plugin.getLogger().log(Level.WARNING, "Could not load item set '" + id + "': " + exception.getMessage()); - } - } + ConfigFile config = new ConfigFile("item-sets"); + for (String id : config.getConfig().getKeys(false)) + try { + final ConfigurationSection section = config.getConfig().getConfigurationSection(id); + if (section == null) + throw new IllegalStateException("Item set '%s' is not a valid configuration section.".formatted(id)); + itemSets.put(id, new ItemSet(section)); + } catch (IllegalArgumentException exception) { + MMOItems.plugin.getLogger().log(Level.WARNING, "Could not load item set '%s': %s".formatted(id, exception.getMessage())); + } + } - public void register(ItemSet set) { - itemSets.put(set.getId(), set); - } + public void register(ItemSet set) { + itemSets.put(set.getId(), set); + } - public boolean has(String id) { - return itemSets.containsKey(id); - } + public boolean has(String id) { + return itemSets.containsKey(id); + } - public Collection getAll() { - return itemSets.values(); - } + public Collection getAll() { + return itemSets.values(); + } - public ItemSet get(String id) { - return itemSets.getOrDefault(id, null); - } + public ItemSet get(String id) { + return itemSets.getOrDefault(id, null); + } } diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/manager/SkillManager.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/manager/SkillManager.java index 902c3b44..d58588ad 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/manager/SkillManager.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/manager/SkillManager.java @@ -3,10 +3,10 @@ package net.Indyuce.mmoitems.manager; import io.lumine.mythic.lib.MythicLib; import io.lumine.mythic.lib.skill.handler.SkillHandler; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.ConfigFile; import net.Indyuce.mmoitems.skill.RegisteredSkill; -import net.Indyuce.mmoitems.skill.Shulker_Missile; +import net.Indyuce.mmoitems.skill.ShulkerMissile; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -81,7 +81,7 @@ public class SkillManager { if (clearBefore) skills.clear(); - MythicLib.plugin.getSkills().registerSkillHandler(new Shulker_Missile()); + MythicLib.plugin.getSkills().registerSkillHandler(new ShulkerMissile()); File skillFolder = new File(MMOItems.plugin.getDataFolder() + "/skill"); if (!skillFolder.exists()) { diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/manager/StatManager.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/manager/StatManager.java index 95e69347..aaac421e 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/manager/StatManager.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/manager/StatManager.java @@ -14,148 +14,160 @@ import java.util.*; import java.util.logging.Level; public class StatManager { - private final Map stats = new LinkedHashMap<>(); + private final Map> stats = new LinkedHashMap<>(); - /* - * These lists are sets of stats collected when the stats are registered for - * the first time to make their access easier. Check the classes - * individually to understand better - */ - private final Set numeric = new HashSet<>(); - private final Set itemRestriction = new HashSet<>(); - private final Set consumableActions = new HashSet<>(); - private final Set playerConsumables = new HashSet<>(); + /* + * These lists are sets of stats collected when the stats are registered for + * the first time to make their access easier. Check the classes + * individually to understand better + */ + private final Set numeric = new HashSet<>(); + private final Set itemRestriction = new HashSet<>(); + private final Set consumableActions = new HashSet<>(); + private final Set playerConsumables = new HashSet<>(); - /** - * Load default stats using java reflection, get all public static final - * fields in the ItemStat and register them as stat instances - */ - public void load() { - for (Field field : ItemStats.class.getFields()) - try { - if (Modifier.isStatic(field.getModifiers()) && Modifier.isFinal(field.getModifiers()) && field.get(null) instanceof ItemStat) - register((ItemStat) field.get(null)); - } catch (IllegalArgumentException | IllegalAccessException exception) { - MMOItems.plugin.getLogger().log(Level.WARNING, "Couldn't register stat called '" + field.getName() + "': " + exception.getMessage()); - } - } + /** + * Load default stats using java reflection, get all public static final + * fields in the ItemStat and register them as stat instances + */ + public void load() { + for (Field field : ItemStats.class.getFields()) + try { + if (Modifier.isStatic(field.getModifiers()) && Modifier.isFinal(field.getModifiers()) && field.get(null) instanceof ItemStat) + register((ItemStat) field.get(null)); + } catch (IllegalArgumentException | IllegalAccessException exception) { + MMOItems.plugin.getLogger().log(Level.WARNING, "Couldn't register stat called '%s'".formatted(field.getName()), exception.getMessage()); + } + } - /** - * @see FictiveNumericStat - * @deprecated - */ - @Deprecated - public void reload(boolean cleanFirst) { + /** + * @see FictiveNumericStat + * @deprecated + */ + @Deprecated + public void reload(boolean cleanFirst) { + // Clean fictive numeric stats before + if (cleanFirst) + numeric.removeIf(stat -> stat instanceof FictiveNumericStat); - // Clean fictive numeric stats before - if (cleanFirst) - for (Iterator ite = numeric.iterator(); ite.hasNext(); ) { - DoubleStat stat = ite.next(); - if (stat instanceof FictiveNumericStat) - ite.remove(); - } + // Register elemental stats + loadElements(); + } - // Register elemental stats - for (ElementStatType type : ElementStatType.values()) - for (Element element : MythicLib.plugin.getElements().getAll()) - numeric.add(new FictiveNumericStat(element, type)); - } + /** + * Register all MythicLib elements as stats + */ + public void loadElements() { + for (ElementStatType type : ElementStatType.values()) { + for (Element element : MythicLib.plugin.getElements().getAll()) { + numeric.add(new FictiveNumericStat(element, type)); + } + } + } - public Collection getAll() { - return stats.values(); - } + public Collection> getAll() { + return stats.values(); + } - /** - * @return Collection of all numeric stats like atk damage, crit strike - * chance, max mana... which can be applied on a gem stone. This is - * used when applying gem stones to quickly access all the stats - * which needs to be applied - */ - public Set getNumericStats() { - return numeric; - } + /** + * @return Collection of all numeric stats like atk damage, crit strike + * chance, max mana... which can be applied on a gem stone. This is + * used when applying gem stones to quickly access all the stats + * which needs to be applied + */ + public Set getNumericStats() { + return numeric; + } - /** - * @return Collection of all stats which constitute an item restriction: - * required level, required class, soulbound.. - */ - public Set getItemRestrictionStats() { - return itemRestriction; - } + /** + * @return Collection of all stats which constitute an item restriction: + * required level, required class, soulbound.. + */ + public Set getItemRestrictionStats() { + return itemRestriction; + } - /** - * @return Collection of all stats implementing a consumable action like - * deconstructing, identifying... - */ - public Set getConsumableActions() { - return consumableActions; - } + /** + * @return Collection of all stats implementing a consumable action like + * deconstructing, identifying... + */ + public Set getConsumableActions() { + return consumableActions; + } - /** - * @return Collection of all stats implementing self consumable like - * restore health, mana, hunger... - */ - public Set getPlayerConsumables() { - return playerConsumables; - } + /** + * @return Collection of all stats implementing self consumable like + * restore health, mana, hunger... + */ + public Set getPlayerConsumables() { + return playerConsumables; + } - public boolean has(String id) { - return stats.containsKey(id); - } + public boolean has(String id) { + return stats.containsKey(id); + } - public ItemStat get(String id) { - return stats.getOrDefault(id, null); - } + public ItemStat get(String id) { + ItemStat stat = stats.getOrDefault(id, null); + if (stat == null) + stat = numeric.stream() + .filter(doubleStat -> doubleStat.getId().equals(id)) + .findFirst() + .orElse(null); + return stat; + } - /** - * Registers a stat in MMOItems - * - * @param id Useless. - * @param stat The stat instance - * @deprecated Stat IDs are now stored in the stat instance directly. - * Please use StatManager#register(ItemStat) instead - */ - @Deprecated - @SuppressWarnings("unused") - public void register(String id, ItemStat stat) { - register(stat); - } + /** + * Registers a stat in MMOItems + * + * @param id Useless. + * @param stat The stat instance + * @deprecated Stat IDs are now stored in the stat instance directly. + * Please use StatManager#register(ItemStat) instead + */ + @Deprecated + @SuppressWarnings("unused") + public void register(String id, ItemStat stat) { + register(stat); + } - /** - * Registers a stat in MMOItems. It must be done right after MMOItems loads - * before any manager is initialized because stats are commonly used when - * loading configs. - * - * @param stat The stat to register - */ - public void register(ItemStat stat) { - if (!stat.isEnabled()) - return; + /** + * Registers a stat in MMOItems. It must be done right after MMOItems loads + * before any manager is initialized because stats are commonly used when + * loading configs. + * + * @param stat The stat to register + */ + public void register(ItemStat stat) { + if (!stat.isEnabled()) + return; - stats.put(stat.getId(), stat); + stats.put(stat.getId(), stat); - if (stat instanceof DoubleStat && !(stat instanceof GemStoneStat) && stat.isCompatible(Type.GEM_STONE)) - numeric.add((DoubleStat) stat); + if (stat instanceof DoubleStat && !(stat instanceof GemStoneStat) && stat.isCompatible(Type.GEM_STONE)) + numeric.add((DoubleStat) stat); - if (stat instanceof ItemRestriction) - itemRestriction.add((ItemRestriction) stat); + if (stat instanceof ItemRestriction) + itemRestriction.add((ItemRestriction) stat); - if (stat instanceof ConsumableItemInteraction) - consumableActions.add((ConsumableItemInteraction) stat); + if (stat instanceof ConsumableItemInteraction) + consumableActions.add((ConsumableItemInteraction) stat); - if (stat instanceof PlayerConsumable) - playerConsumables.add((PlayerConsumable) stat); + if (stat instanceof PlayerConsumable) + playerConsumables.add((PlayerConsumable) stat); - /** - * Cache stat for every type which may have this stat. Really important - * otherwise the stat will NOT be used anywhere in the plugin. This - * process is also done in the TypeManager when registering new types - * but since stats can be registered after types are loaded, we must - * take it into account - */ - if (MMOItems.plugin.getTypes() != null) - for (Type type : MMOItems.plugin.getTypes().getAll()) - if (stat.isCompatible(type)) - type.getAvailableStats().add(stat); - } + /* + * Cache stat for every type which may have this stat. Really important + * otherwise the stat will NOT be used anywhere in the plugin. This + * process is also done in the TypeManager when registering new types + * but since stats can be registered after types are loaded, we must + * take it into account + */ + if (MMOItems.plugin.getTypes() != null) + MMOItems.plugin.getTypes() + .getAll() + .stream() + .filter(stat::isCompatible) + .forEach(type -> type.getAvailableStats().add(stat)); + } } diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/particle/api/ParticleType.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/particle/api/ParticleType.java index 8071ebdf..1ecc64d5 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/particle/api/ParticleType.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/particle/api/ParticleType.java @@ -5,7 +5,7 @@ import java.util.Map; import java.util.Set; import java.util.function.BiFunction; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.player.PlayerData; import net.Indyuce.mmoitems.api.util.StringValue; import net.Indyuce.mmoitems.particle.AuraParticles; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/skill/Shulker_Missile.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/skill/ShulkerMissile.java similarity index 96% rename from MMOItems-API/src/main/java/net/Indyuce/mmoitems/skill/Shulker_Missile.java rename to MMOItems-API/src/main/java/net/Indyuce/mmoitems/skill/ShulkerMissile.java index 7e6e2d63..bf9d4adb 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/skill/Shulker_Missile.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/skill/ShulkerMissile.java @@ -26,16 +26,18 @@ import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.util.Vector; +import org.jetbrains.annotations.NotNull; import javax.annotation.Nullable; -public class Shulker_Missile extends SkillHandler implements Listener { - public Shulker_Missile() { +public class ShulkerMissile extends SkillHandler implements Listener { + public ShulkerMissile() { super(); registerModifiers("damage", "effect-duration", "duration"); } + @NotNull @Override public VectorSkillResult getResult(SkillMetadata meta) { return new VectorSkillResult(meta); diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Abilities.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Abilities.java index f658c561..63a9a223 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Abilities.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Abilities.java @@ -7,7 +7,7 @@ import io.lumine.mythic.lib.api.item.SupportedNBTTagValues; import io.lumine.mythic.lib.api.util.AltChar; import io.lumine.mythic.lib.skill.trigger.TriggerType; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder; import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem; import net.Indyuce.mmoitems.api.util.NumericStatFormula; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/ArrowParticles.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/ArrowParticles.java index fb5fd850..9046c8f5 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/ArrowParticles.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/ArrowParticles.java @@ -5,28 +5,24 @@ import java.util.List; import java.util.Optional; import io.lumine.mythic.lib.api.item.SupportedNBTTagValues; -import net.Indyuce.mmoitems.stat.data.StringData; import org.apache.commons.lang.Validate; import org.bukkit.ChatColor; import org.bukkit.Particle; import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.entity.Item; import org.bukkit.event.inventory.InventoryClickEvent; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.google.gson.JsonSyntaxException; -import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder; import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem; import net.Indyuce.mmoitems.gui.edition.ArrowParticlesEdition; import net.Indyuce.mmoitems.gui.edition.EditionInventory; import net.Indyuce.mmoitems.stat.data.ArrowParticlesData; import net.Indyuce.mmoitems.stat.data.ParticleData; -import net.Indyuce.mmoitems.stat.data.random.RandomStatData; import net.Indyuce.mmoitems.stat.data.type.StatData; import net.Indyuce.mmoitems.stat.type.ItemStat; import io.lumine.mythic.lib.api.item.ItemTag; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/ArrowPotionEffects.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/ArrowPotionEffects.java index 4f547ba8..ead59a6e 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/ArrowPotionEffects.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/ArrowPotionEffects.java @@ -8,7 +8,7 @@ import io.lumine.mythic.lib.api.item.SupportedNBTTagValues; import io.lumine.mythic.lib.api.util.AltChar; import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.edition.StatEdition; import net.Indyuce.mmoitems.api.interaction.projectile.ArrowPotionEffectArrayItem; import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CanDeconstruct.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CanDeconstruct.java index 9fa61d42..5f1a19d0 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CanDeconstruct.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CanDeconstruct.java @@ -11,7 +11,7 @@ import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.inventory.ItemStack; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.ItemTier; import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.api.event.item.DeconstructItemEvent; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CanDeskin.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CanDeskin.java index 8d7191cc..173b7e86 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CanDeskin.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CanDeskin.java @@ -7,7 +7,7 @@ import io.lumine.mythic.lib.api.util.SmartGive; import io.lumine.mythic.lib.version.VersionMaterial; import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.api.interaction.Consumable; import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CanIdentify.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CanIdentify.java index 1550ddde..71eb5d8d 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CanIdentify.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CanIdentify.java @@ -7,7 +7,7 @@ import org.bukkit.Sound; import org.bukkit.entity.Player; import org.bukkit.event.inventory.InventoryClickEvent; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.api.event.item.IdentifyItemEvent; import net.Indyuce.mmoitems.api.interaction.Consumable; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CanUnsocket.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CanUnsocket.java index fbc0393f..2332de71 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CanUnsocket.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CanUnsocket.java @@ -2,11 +2,8 @@ package net.Indyuce.mmoitems.stat; import io.lumine.mythic.lib.api.item.NBTItem; import net.Indyuce.mmoitems.ItemStats; -import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.MMOUtils; -import net.Indyuce.mmoitems.api.ItemTier; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.Type; -import net.Indyuce.mmoitems.api.event.item.DeconstructItemEvent; import net.Indyuce.mmoitems.api.interaction.Consumable; import net.Indyuce.mmoitems.api.item.mmoitem.LiveMMOItem; import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem; @@ -18,16 +15,12 @@ import net.Indyuce.mmoitems.stat.data.GemstoneData; import net.Indyuce.mmoitems.stat.type.BooleanStat; import net.Indyuce.mmoitems.stat.type.ConsumableItemInteraction; import net.Indyuce.mmoitems.util.Pair; -import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; -import org.bukkit.Sound; import org.bukkit.entity.Player; import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; -import java.util.ArrayList; import java.util.List; /** diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Commands.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Commands.java index 702b723c..80758089 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Commands.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Commands.java @@ -5,17 +5,14 @@ import io.lumine.mythic.lib.api.item.ItemTag; import io.lumine.mythic.lib.api.item.SupportedNBTTagValues; import io.lumine.mythic.lib.api.util.AltChar; import io.lumine.mythic.lib.version.VersionMaterial; -import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder; import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem; import net.Indyuce.mmoitems.gui.edition.CommandListEdition; import net.Indyuce.mmoitems.gui.edition.EditionInventory; import net.Indyuce.mmoitems.stat.data.CommandData; import net.Indyuce.mmoitems.stat.data.CommandListData; -import net.Indyuce.mmoitems.stat.data.random.RandomStatData; -import net.Indyuce.mmoitems.stat.data.type.StatData; import net.Indyuce.mmoitems.stat.type.ItemStat; import org.apache.commons.lang.Validate; import org.bukkit.ChatColor; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CustomSounds.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CustomSounds.java index fddc5cca..c027a992 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CustomSounds.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CustomSounds.java @@ -5,7 +5,7 @@ import io.lumine.mythic.lib.api.item.SupportedNBTTagValues; import io.lumine.mythic.lib.api.util.AltChar; import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.CustomSound; import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder; import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem; @@ -14,8 +14,6 @@ import net.Indyuce.mmoitems.gui.edition.EditionInventory; import net.Indyuce.mmoitems.gui.edition.SoundsEdition; import net.Indyuce.mmoitems.stat.data.SoundData; import net.Indyuce.mmoitems.stat.data.SoundListData; -import net.Indyuce.mmoitems.stat.data.random.RandomStatData; -import net.Indyuce.mmoitems.stat.data.type.StatData; import net.Indyuce.mmoitems.stat.type.GemStoneStat; import net.Indyuce.mmoitems.stat.type.ItemStat; import net.Indyuce.mmoitems.stat.type.PlayerConsumable; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Effects.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Effects.java index affe4f83..b72b8c22 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Effects.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Effects.java @@ -8,7 +8,7 @@ import io.lumine.mythic.lib.api.util.AltChar; import io.lumine.mythic.lib.api.util.ui.FriendlyFeedbackProvider; import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.edition.StatEdition; import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder; import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem; @@ -37,200 +37,189 @@ import org.jetbrains.annotations.Nullable; import java.util.*; public class Effects extends ItemStat implements PlayerConsumable { - public Effects() { - super("EFFECTS", Material.POTION, "Effects", new String[]{"The potion effects your", "consumable item grants."}, - new String[]{"consumable"}); - } + public Effects() { + super("EFFECTS", Material.POTION, "Effects", new String[]{"The potion effects your", "consumable item grants."}, + new String[]{"consumable"}); + } - @Override - public RandomPotionEffectListData whenInitialized(Object object) { - Validate.isTrue(object instanceof ConfigurationSection, "Must specify a config section"); - return new RandomPotionEffectListData((ConfigurationSection) object); - } + @Override + public RandomPotionEffectListData whenInitialized(Object object) { + Validate.isTrue(object instanceof ConfigurationSection, "Must specify a config section"); + return new RandomPotionEffectListData((ConfigurationSection) object); + } - @Override - public void whenClicked(@NotNull EditionInventory inv, @NotNull InventoryClickEvent event) { - if (event.getAction() == InventoryAction.PICKUP_ALL) - new StatEdition(inv, ItemStats.EFFECTS).enable("Write in the chat the permanent potion effect you want to add.", - ChatColor.AQUA + "Format: {Potion Effect Name}|{Duration Numeric Formula}|{Amplifier Numeric Formula}", ChatColor.DARK_RED + "Note: " + ChatColor.RED + "The '|' lines are literal."); + @Override + public void whenClicked(@NotNull EditionInventory inv, @NotNull InventoryClickEvent event) { + if (event.getAction() == InventoryAction.PICKUP_ALL) + new StatEdition(inv, ItemStats.EFFECTS).enable("Write in the chat the permanent potion effect you want to add.", + ChatColor.AQUA + "Format: {Potion Effect Name}|{Duration Numeric Formula}|{Amplifier Numeric Formula}", ChatColor.DARK_RED + "Note: " + ChatColor.RED + "The '|' lines are literal."); - if (event.getAction() == InventoryAction.PICKUP_HALF) { - if (inv.getEditedSection().contains("effects")) { - Set set = inv.getEditedSection().getConfigurationSection("effects").getKeys(false); - String last = Arrays.asList(set.toArray(new String[0])).get(set.size() - 1); - inv.getEditedSection().set("effects." + last, null); - if (set.size() <= 1) - inv.getEditedSection().set("effects", null); - inv.registerTemplateEdition(); - inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Successfully removed " + last.substring(0, 1).toUpperCase() - + last.substring(1).toLowerCase() + ChatColor.GRAY + "."); - } - } - } + if (event.getAction() == InventoryAction.PICKUP_HALF) { + if (inv.getEditedSection().contains("effects")) { + Set set = inv.getEditedSection().getConfigurationSection("effects").getKeys(false); + String last = Arrays.asList(set.toArray(new String[0])).get(set.size() - 1); + inv.getEditedSection().set("effects." + last, null); + if (set.size() <= 1) + inv.getEditedSection().set("effects", null); + inv.registerTemplateEdition(); + inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Successfully removed " + last.substring(0, 1).toUpperCase() + + last.substring(1).toLowerCase() + ChatColor.GRAY + "."); + } + } + } - @Override - public void whenInput(@NotNull EditionInventory inv, @NotNull String message, Object... info) { - String[] split = message.split("\\|"); - Validate.isTrue(split.length > 1, FriendlyFeedbackProvider.quickForConsole(FFPMMOItems.get(),"Use this format: $e{Potion Effect Name}|{Duration Numeric Formula}|{Amplifier Numeric Formula}$b.")); + @Override + public void whenInput(@NotNull EditionInventory inv, @NotNull String message, Object... info) { + String[] split = message.split("\\|"); + Validate.isTrue(split.length > 1, FriendlyFeedbackProvider.quickForConsole(FFPMMOItems.get(), "Use this format: $e{Potion Effect Name}|{Duration Numeric Formula}|{Amplifier Numeric Formula}$b.")); - PotionEffectType effect = PotionEffectType.getByName(split[0].replace("-", "_").replace(" ", "_").toUpperCase()); - Validate.notNull(effect, split[0] + FriendlyFeedbackProvider.quickForConsole(FFPMMOItems.get()," is not a valid potion effect. All potion effects can be found here:$e https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/potion/PotionEffectType.html")); + PotionEffectType effect = PotionEffectType.getByName(split[0].replace("-", "_").replace(" ", "_").toUpperCase()); + Validate.notNull(effect, split[0] + FriendlyFeedbackProvider.quickForConsole(FFPMMOItems.get(), " is not a valid potion effect. All potion effects can be found here:$e https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/potion/PotionEffectType.html")); - NumericStatFormula duration = new NumericStatFormula(split[1]); - NumericStatFormula amplifier = split.length > 2 ? new NumericStatFormula(split[2]) : new NumericStatFormula(1, 0, 0, 0); + NumericStatFormula duration = new NumericStatFormula(split[1]); + NumericStatFormula amplifier = split.length > 2 ? new NumericStatFormula(split[2]) : new NumericStatFormula(1, 0, 0, 0); - duration.fillConfigurationSection(inv.getEditedSection(), "effects." + effect.getName() + ".duration"); - amplifier.fillConfigurationSection(inv.getEditedSection(), "effects." + effect.getName() + ".amplifier"); - inv.registerTemplateEdition(); - inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + effect.getName() + " " + amplifier + " successfully added."); - } + duration.fillConfigurationSection(inv.getEditedSection(), "effects." + effect.getName() + ".duration"); + amplifier.fillConfigurationSection(inv.getEditedSection(), "effects." + effect.getName() + ".amplifier"); + inv.registerTemplateEdition(); + inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + effect.getName() + " " + amplifier + " successfully added."); + } - @Override - public void whenDisplayed(List lore, Optional statData) { + @Override + public void whenDisplayed(List lore, Optional statData) { + statData.ifPresentOrElse(randomPotionEffectListData -> { + lore.add(ChatColor.GRAY + "Current Value:"); + for (RandomPotionEffectData effect : randomPotionEffectListData.getEffects()) + lore.add(ChatColor.GRAY + "* " + ChatColor.GREEN + MMOUtils.caseOnWords(effect.getType().getName().toLowerCase().replace("_", " ")) + + ChatColor.GRAY + " Level: " + ChatColor.GREEN + effect.getAmplifier() + ChatColor.GRAY + " Duration: " + ChatColor.GREEN + + effect.getDuration()); + }, () -> lore.add(ChatColor.GRAY + "Current Value: " + ChatColor.RED + "None")); + lore.add(""); + lore.add(ChatColor.YELLOW + AltChar.listDash + " Click to add an effect."); + lore.add(ChatColor.YELLOW + AltChar.listDash + " Right click to remove the last effect."); + } - if (statData.isPresent()) { - lore.add(ChatColor.GRAY + "Current Value:"); - RandomPotionEffectListData data = statData.get(); - for (RandomPotionEffectData effect : data.getEffects()) - lore.add(ChatColor.GRAY + "* " + ChatColor.GREEN + MMOUtils.caseOnWords(effect.getType().getName().toLowerCase().replace("_", " ")) - + ChatColor.GRAY + " Level: " + ChatColor.GREEN + effect.getAmplifier() + ChatColor.GRAY + " Duration: " + ChatColor.GREEN - + effect.getDuration()); - } else - lore.add(ChatColor.GRAY + "Current Value: " + ChatColor.RED + "None"); + @NotNull + @Override + public PotionEffectListData getClearStatData() { + return new PotionEffectListData(); + } - lore.add(""); - lore.add(ChatColor.YELLOW + AltChar.listDash + " Click to add an effect."); - lore.add(ChatColor.YELLOW + AltChar.listDash + " Right click to remove the last effect."); - } + @Override + public void whenApplied(@NotNull ItemStackBuilder item, @NotNull PotionEffectListData data) { + // Process Lore + List lore = new ArrayList<>(); + String effectFormat = ItemStat.translate("effect"); + data.getEffects().forEach(effect -> lore.add(effectFormat + .replace("{effect}", + MMOItems.plugin.getLanguage().getPotionEffectName(effect.getType()) + + (effect.getLevel() < 2 ? "" : " " + MMOUtils.intToRoman(effect.getLevel()))) + .replace("{duration}", MythicLib.plugin.getMMOConfig().decimal.format(effect.getDuration())))); + item.getLore().insert("effects", lore); - @NotNull - @Override - public PotionEffectListData getClearStatData() { - return new PotionEffectListData(); - } + // Add tags to item + item.addItemTag(getAppliedNBT(data)); + } - @Override - public void whenApplied(@NotNull ItemStackBuilder item, @NotNull PotionEffectListData data) { + @NotNull + @Override + public ArrayList getAppliedNBT(@NotNull PotionEffectListData data) { - // Process Lore - List lore = new ArrayList<>(); - String effectFormat = ItemStat.translate("effect"); - data.getEffects().forEach(effect -> { - lore.add(effectFormat - .replace("{effect}", - MMOItems.plugin.getLanguage().getPotionEffectName(effect.getType()) - + (effect.getLevel() < 2 ? "" : " " + MMOUtils.intToRoman(effect.getLevel()))) - .replace("{duration}", MythicLib.plugin.getMMOConfig().decimal.format(effect.getDuration()))); - }); - item.getLore().insert("effects", lore); + // Create aJson Array + JsonArray array = new JsonArray(); - // Add tags to item - item.addItemTag(getAppliedNBT(data)); - } + // For every effect + for (PotionEffectData effect : data.getEffects()) { + // Convert to Json Object + JsonObject object = new JsonObject(); + object.addProperty("Type", effect.getType().getName()); + object.addProperty("Duration", effect.getDuration()); + object.addProperty("Level", effect.getLevel()); + array.add(object); + } - @NotNull - @Override - public ArrayList getAppliedNBT(@NotNull PotionEffectListData data) { + // Make the tag + ArrayList ret = new ArrayList<>(); + ret.add(new ItemTag(getNBTPath(), array.toString())); - // Create aJson Array - JsonArray array = new JsonArray(); + // Thats it + return ret; + } - // For every effect - for (PotionEffectData effect : data.getEffects()) { + @Override + public void whenLoaded(@NotNull ReadMMOItem mmoitem) { + // Find relevant tag + ArrayList relevantTags = new ArrayList<>(); + if (mmoitem.getNBT().hasTag(getNBTPath())) + relevantTags.add(ItemTag.getTagAtPath(getNBTPath(), mmoitem.getNBT(), SupportedNBTTagValues.STRING)); - // Convert to Json Object - JsonObject object = new JsonObject(); - object.addProperty("Type", effect.getType().getName()); - object.addProperty("Duration", effect.getDuration()); - object.addProperty("Level", effect.getLevel()); - array.add(object); - } + // Attempt to build data + StatData data = getLoadedNBT(relevantTags); - // Make the tag - ArrayList ret = new ArrayList<>(); - ret.add(new ItemTag(getNBTPath(), array.toString())); + // Valid? Append. + if (data != null) + mmoitem.setData(this, data); + } - // Thats it - return ret; - } + @Nullable + @Override + public PotionEffectListData getLoadedNBT(@NotNull ArrayList storedTags) { - @Override - public void whenLoaded(@NotNull ReadMMOItem mmoitem) { + // Find tag + ItemTag rTag = ItemTag.getTagAtPath(getNBTPath(), storedTags); - // Find relevant tag - ArrayList relevantTags = new ArrayList<>(); - if (mmoitem.getNBT().hasTag(getNBTPath())) - relevantTags.add(ItemTag.getTagAtPath(getNBTPath(), mmoitem.getNBT(), SupportedNBTTagValues.STRING)); + // Found? + if (rTag == null) + return null; + // Must be Json Array, attempt to parse. + try { + PotionEffectListData effects = new PotionEffectListData(); - // Attempt to build data - StatData data = getLoadedNBT(relevantTags); + // Get as Array + JsonArray array = new JsonParser().parse((String) rTag.getValue()).getAsJsonArray(); - // Valid? Append. - if (data != null) { mmoitem.setData(this, data); } - } + // BUild each element + for (JsonElement e : array) { - @Nullable - @Override - public PotionEffectListData getLoadedNBT(@NotNull ArrayList storedTags) { + // Must be object + if (e.isJsonObject()) { - // Find tag - ItemTag rTag = ItemTag.getTagAtPath(getNBTPath(), storedTags); + // Extract + JsonObject key = e.getAsJsonObject(); - // Found? - if (rTag != null) { + effects.add(new PotionEffectData(PotionEffectType.getByName( + key.get("Type").getAsString()), + key.get("Duration").getAsDouble(), + key.get("Level").getAsInt())); + } + } - // Must be Json Array, attempt to parse. - try { - PotionEffectListData effects = new PotionEffectListData(); + // Success + return effects; - // Get as Array - JsonArray array = new JsonParser().parse((String) rTag.getValue()).getAsJsonArray(); + } catch (JsonSyntaxException | IllegalStateException exception) { + /* + * OLD ITEM WHICH MUST BE UPDATED. + */ + } + return null; + } - // BUild each element - for (JsonElement e : array) { + @Override + public void onConsume(@NotNull VolatileMMOItem mmo, @NotNull Player player, boolean vanillaEating) { + // Does it have effects? + if (!mmo.hasData(ItemStats.EFFECTS)) + return; - // Must be object - if (e.isJsonObject()) { + // Get Data + PotionEffectListData pelData = (PotionEffectListData) mmo.getData(ItemStats.EFFECTS); - // Extract - JsonObject key = e.getAsJsonObject(); - - effects.add(new PotionEffectData(PotionEffectType.getByName( - key.get("Type").getAsString()), - key.get("Duration").getAsDouble(), - key.get("Level").getAsInt())); - } - } - - // Success - return effects; - - } catch (JsonSyntaxException|IllegalStateException exception) { - /* - * OLD ITEM WHICH MUST BE UPDATED. - */ - } - } - - return null; - } - - @Override - public void onConsume(@NotNull VolatileMMOItem mmo, @NotNull Player player, boolean vanillaEating) { - - // Does it have effects? - if (!mmo.hasData(ItemStats.EFFECTS)) - return; - - // Get Data - PotionEffectListData pelData = (PotionEffectListData) mmo.getData(ItemStats.EFFECTS); - - // Apply - for (PotionEffectData ped : pelData.getEffects()) - if (ped != null) { - player.removePotionEffect(ped.getType()); - player.addPotionEffect(ped.toEffect()); - } - - } + // Apply + for (PotionEffectData ped : pelData.getEffects()) { + if (ped == null) + continue; + player.removePotionEffect(ped.getType()); + player.addPotionEffect(ped.toEffect()); + } + } } diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Elements.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Elements.java index acd6acf1..433be79c 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Elements.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Elements.java @@ -6,7 +6,7 @@ import io.lumine.mythic.lib.api.util.AltChar; import io.lumine.mythic.lib.api.util.ui.SilentNumbers; import io.lumine.mythic.lib.element.Element; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder; import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem; import net.Indyuce.mmoitems.api.util.NumericStatFormula; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Enchants.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Enchants.java index d511d345..767753b5 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Enchants.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Enchants.java @@ -9,7 +9,7 @@ import io.lumine.mythic.lib.api.util.ui.PlusMinusPercent; import io.lumine.mythic.lib.api.util.ui.SilentNumbers; import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.edition.StatEdition; import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder; import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem; @@ -20,7 +20,6 @@ import net.Indyuce.mmoitems.comp.enchants.EnchantPlugin; import net.Indyuce.mmoitems.gui.edition.EditionInventory; import net.Indyuce.mmoitems.stat.data.EnchantListData; import net.Indyuce.mmoitems.stat.data.random.RandomEnchantListData; -import net.Indyuce.mmoitems.stat.data.random.RandomStatData; import net.Indyuce.mmoitems.stat.data.type.StatData; import net.Indyuce.mmoitems.stat.data.type.UpgradeInfo; import net.Indyuce.mmoitems.stat.type.ItemStat; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/ItemParticles.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/ItemParticles.java index f2031594..52f91fe9 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/ItemParticles.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/ItemParticles.java @@ -7,7 +7,7 @@ import io.lumine.mythic.lib.api.item.SupportedNBTTagValues; import io.lumine.mythic.lib.api.util.AltChar; import io.lumine.mythic.lib.version.VersionMaterial; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder; import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem; import net.Indyuce.mmoitems.gui.edition.EditionInventory; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/ItemSetStat.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/ItemSetStat.java index 78286caa..9fa94e2e 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/ItemSetStat.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/ItemSetStat.java @@ -1,15 +1,13 @@ package net.Indyuce.mmoitems.stat; +import io.lumine.mythic.lib.api.item.ItemTag; import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.api.ItemSet; import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder; -import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem; import net.Indyuce.mmoitems.gui.edition.EditionInventory; import net.Indyuce.mmoitems.stat.data.StringData; -import net.Indyuce.mmoitems.stat.data.type.StatData; import net.Indyuce.mmoitems.stat.type.GemStoneStat; import net.Indyuce.mmoitems.stat.type.StringStat; -import io.lumine.mythic.lib.api.item.ItemTag; import org.apache.commons.lang.Validate; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -20,64 +18,67 @@ import org.jetbrains.annotations.NotNull; import java.util.ArrayList; public class ItemSetStat extends StringStat implements GemStoneStat { - public ItemSetStat() { - super("SET", Material.LEATHER_CHESTPLATE, "Item Set", - new String[] { "Item sets can give to the player extra", "bonuses that depend on how many items", "from the same set your wear." }, - new String[] { "!gem_stone", "!consumable", "!material", "!block", "!miscellaneous", "all" }); - } + public ItemSetStat() { + super("SET", Material.LEATHER_CHESTPLATE, "Item Set", + new String[]{"Item sets can give to the player extra", "bonuses that depend on how many items", "from the same set your wear."}, + new String[]{"!gem_stone", "!consumable", "!material", "!block", "!miscellaneous", "all"}); + } - @Override - public void whenClicked(@NotNull EditionInventory inv, @NotNull InventoryClickEvent e) { - super.whenClicked(inv, e); - if (e.getAction() != InventoryAction.PICKUP_HALF) { - inv.getPlayer().sendMessage(ChatColor.GREEN + "Available Item Sets:"); - StringBuilder builder = new StringBuilder(); - for (ItemSet set : MMOItems.plugin.getSets().getAll()) - builder.append(ChatColor.GREEN).append(set.getId()).append(ChatColor.GRAY) - .append(" (").append(set.getName()).append(ChatColor.GRAY).append("), "); - if(builder.length() > 1) - builder.setLength(builder.length() - 2); - inv.getPlayer().sendMessage(builder.toString()); - } - } + @Override + public void whenClicked(@NotNull EditionInventory inv, @NotNull InventoryClickEvent e) { + super.whenClicked(inv, e); + if (e.getAction() != InventoryAction.PICKUP_HALF) { + inv.getPlayer().sendMessage(ChatColor.GREEN + "Available Item Sets:"); + StringBuilder builder = new StringBuilder(); + for (ItemSet set : MMOItems.plugin.getSets().getAll()) + builder.append(ChatColor.GREEN).append(set.getId()).append(ChatColor.GRAY) + .append(" (").append(set.getName()).append(ChatColor.GRAY).append("), "); + if (builder.length() > 1) + builder.setLength(builder.length() - 2); + inv.getPlayer().sendMessage(builder.toString()); + } + } - @Override - public void whenApplied(@NotNull ItemStackBuilder item, @NotNull StringData data) { + @Override + public void whenApplied(@NotNull ItemStackBuilder item, @NotNull StringData data) { - // Display in lore - ItemSet set = MMOItems.plugin.getSets().get(data.toString()); + // Display in lore + ItemSet set = MMOItems.plugin.getSets().get(data.toString()); - // Apply lore - if (set != null) { item.getLore().insert("set", set.getLoreTag()); } + // Apply lore + if (set != null) + item.getLore().insert("set", set.getLoreTag()); - // Add NBT - item.addItemTag(getAppliedNBT(data)); - } + // Add NBT + item.addItemTag(getAppliedNBT(data)); + } - @NotNull - @Override - public ArrayList getAppliedNBT(@NotNull StringData data) { + @NotNull + @Override + public ArrayList getAppliedNBT(@NotNull StringData data) { + ItemSet set = MMOItems.plugin.getSets().get(data.toString()); + Validate.notNull(set, "Could not find item set with ID '%s'".formatted(data)); - ItemSet set = MMOItems.plugin.getSets().get(data.toString()); - Validate.notNull(set, "Could not find item set with ID '" + data.toString() + "'"); + // Make Array + ArrayList ret = new ArrayList<>(); - // Make Array - ArrayList ret = new ArrayList<>(); + // Add that tag + ret.add(new ItemTag(getNBTPath(), data.toString())); - // Add that tag - ret.add(new ItemTag(getNBTPath(), data.toString())); + // Thats it + return ret; + } - // Thats it - return ret; - } + @Override + @NotNull + public String getNBTPath() { + return "MMOITEMS_ITEM_SET"; + } - @Override - @NotNull public String getNBTPath() { return "MMOITEMS_ITEM_SET"; } - - @Override - public void whenInput(@NotNull EditionInventory inv, @NotNull String message, Object... info) { - ItemSet set = MMOItems.plugin.getSets().get(message); - Validate.notNull(set, "Couldn't find the set named '" + message + "'."); - super.whenInput(inv, message, info); - } + @Override + public void whenInput(@NotNull EditionInventory inv, @NotNull String message, Object... info) { + ItemSet set = MMOItems.plugin.getSets().get(message); + Validate.notNull(set, "Couldn't find the set named '%s'.".formatted(message)); + super.whenInput(inv, message, info); + } } diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/ManaCost.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/ManaCost.java new file mode 100644 index 00000000..b568b607 --- /dev/null +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/ManaCost.java @@ -0,0 +1,55 @@ +package net.Indyuce.mmoitems.stat; + +import io.lumine.mythic.lib.api.item.NBTItem; +import io.lumine.mythic.lib.version.VersionMaterial; +import net.Indyuce.mmoitems.ItemStats; +import net.Indyuce.mmoitems.api.item.mmoitem.VolatileMMOItem; +import net.Indyuce.mmoitems.api.player.PlayerData; +import net.Indyuce.mmoitems.api.player.RPGPlayer; +import net.Indyuce.mmoitems.api.util.message.Message; +import net.Indyuce.mmoitems.stat.data.DoubleData; +import net.Indyuce.mmoitems.stat.type.DoubleStat; +import net.Indyuce.mmoitems.stat.type.ItemRestriction; +import net.Indyuce.mmoitems.stat.type.PlayerConsumable; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +/** + * mmoitems + * + * @author Roch Blondiaux + * @date 24/10/2022 + */ +public class ManaCost extends DoubleStat implements ItemRestriction, PlayerConsumable { + + public ManaCost() { + super("MANA_COST", VersionMaterial.LAPIS_LAZULI.toMaterial(), "Mana Cost", new String[]{"Mana spent by your weapon to be used."}, new String[]{"piercing", "slashing", "blunt", "range"}); + } + + + @Override + public boolean canUse(RPGPlayer player, NBTItem item, boolean message) { + // No data no service + if (!item.hasTag(ItemStats.MANA_COST.getNBTPath())) + return true; + double manaCost = item.getDouble(ItemStats.MANA_COST.getNBTPath()); + boolean hasMana = manaCost > 0 && player.getMana() >= manaCost; + if (!hasMana) + Message.NOT_ENOUGH_MANA.format(ChatColor.RED).send(player.getPlayer()); + return hasMana; + } + + @Override + public void onConsume(@NotNull VolatileMMOItem mmo, @NotNull Player player, boolean vanillaEating) { + // No data no service + if (!mmo.hasData(ItemStats.MANA_COST)) return; + + // Get value + DoubleData d = (DoubleData) mmo.getData(ItemStats.MANA_COST); + if (d.getValue() > 0) { + final RPGPlayer rpgPlayer = PlayerData.get(player).getRPG(); + rpgPlayer.setMana(rpgPlayer.getMana() - d.getValue()); + } + } +} diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/MaterialStat.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/MaterialStat.java index ce490a62..2c7014d3 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/MaterialStat.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/MaterialStat.java @@ -6,14 +6,12 @@ import io.lumine.mythic.lib.api.util.EnumUtils; import io.lumine.mythic.lib.version.VersionMaterial; import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.edition.StatEdition; import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder; import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem; import net.Indyuce.mmoitems.gui.edition.EditionInventory; import net.Indyuce.mmoitems.stat.data.MaterialData; -import net.Indyuce.mmoitems.stat.data.random.RandomStatData; -import net.Indyuce.mmoitems.stat.data.type.StatData; import net.Indyuce.mmoitems.stat.type.ItemStat; import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.chat.ClickEvent; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/PermanentEffects.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/PermanentEffects.java index 0ef81250..d2ff4593 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/PermanentEffects.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/PermanentEffects.java @@ -21,7 +21,7 @@ import com.google.gson.JsonParser; import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.edition.StatEdition; import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder; import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem; @@ -31,7 +31,6 @@ import net.Indyuce.mmoitems.stat.data.PotionEffectData; import net.Indyuce.mmoitems.stat.data.PotionEffectListData; import net.Indyuce.mmoitems.stat.data.random.RandomPotionEffectData; import net.Indyuce.mmoitems.stat.data.random.RandomPotionEffectListData; -import net.Indyuce.mmoitems.stat.data.random.RandomStatData; import net.Indyuce.mmoitems.stat.data.type.StatData; import net.Indyuce.mmoitems.stat.type.ItemStat; import io.lumine.mythic.lib.api.item.ItemTag; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/PotionEffects.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/PotionEffects.java index 5f03f3cc..b19cec4c 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/PotionEffects.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/PotionEffects.java @@ -4,7 +4,7 @@ import io.lumine.mythic.lib.api.item.ItemTag; import io.lumine.mythic.lib.api.util.AltChar; import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.edition.StatEdition; import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder; import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/ProjectileParticles.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/ProjectileParticles.java index a37aaab0..a26598a3 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/ProjectileParticles.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/ProjectileParticles.java @@ -9,7 +9,7 @@ import io.lumine.mythic.lib.api.item.SupportedNBTTagValues; import io.lumine.mythic.lib.api.util.AltChar; import io.lumine.mythic.lib.version.VersionMaterial; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.edition.StatEdition; import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder; import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RandomUnsocket.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RandomUnsocket.java index d3c3008b..4a6aec24 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RandomUnsocket.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RandomUnsocket.java @@ -4,7 +4,7 @@ import io.lumine.mythic.lib.api.item.NBTItem; import io.lumine.mythic.lib.api.util.ui.SilentNumbers; import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.api.interaction.Consumable; import net.Indyuce.mmoitems.api.item.mmoitem.LiveMMOItem; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RepairPower.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RepairPower.java index 24b2e140..aa2994d5 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RepairPower.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RepairPower.java @@ -1,86 +1,67 @@ package net.Indyuce.mmoitems.stat; -import net.Indyuce.mmoitems.listener.CustomSoundListener; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.Sound; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.inventory.meta.Damageable; -import org.bukkit.inventory.meta.ItemMeta; - +import io.lumine.mythic.lib.api.item.NBTItem; import net.Indyuce.mmoitems.ItemStats; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.api.event.item.RepairItemEvent; import net.Indyuce.mmoitems.api.interaction.Consumable; import net.Indyuce.mmoitems.api.interaction.util.DurabilityItem; import net.Indyuce.mmoitems.api.player.PlayerData; import net.Indyuce.mmoitems.api.util.message.Message; +import net.Indyuce.mmoitems.listener.CustomSoundListener; import net.Indyuce.mmoitems.stat.type.ConsumableItemInteraction; import net.Indyuce.mmoitems.stat.type.DoubleStat; -import io.lumine.mythic.lib.api.item.NBTItem; +import net.Indyuce.mmoitems.util.RepairUtils; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.InventoryClickEvent; import org.jetbrains.annotations.NotNull; public class RepairPower extends DoubleStat implements ConsumableItemInteraction { - public RepairPower() { - super("REPAIR", Material.ANVIL, "Repair", new String[] { "The amount of durability your item", "can repair when set an item." }, - new String[] { "consumable" }); - } + public RepairPower() { + super("REPAIR", Material.ANVIL, "Repair", new String[]{"The amount of durability your item", "can repair when set an item."}, + new String[]{"consumable"}); + } - @Override - public boolean handleConsumableEffect(@NotNull InventoryClickEvent event, @NotNull PlayerData playerData, @NotNull Consumable consumable, @NotNull NBTItem target, Type targetType) { - int repairPower = (int) consumable.getNBTItem().getStat(ItemStats.REPAIR.getId()); - if (repairPower <= 0) - return false; + @Override + public boolean handleConsumableEffect(@NotNull InventoryClickEvent event, @NotNull PlayerData playerData, @NotNull Consumable consumable, @NotNull NBTItem target, Type targetType) { + int repairPower = (int) consumable.getNBTItem().getStat(ItemStats.REPAIR.getId()); + if (repairPower <= 0) + return false; - // custom durability - Player player = playerData.getPlayer(); + // custom durability + Player player = playerData.getPlayer(); - final String type = "MMOITEMS_REPAIR_TYPE"; - if((target.hasTag(type) || consumable.getNBTItem().hasTag(type)) && - !target.getString(type).equals(consumable.getNBTItem().getString(type))) { - Message.UNABLE_TO_REPAIR.format(ChatColor.RED, "#item#", MMOUtils.getDisplayName(target.getItem())).send(player); - player.getPlayer().playSound(player.getPlayer().getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 1.5f); - return false; - } + final String type = "MMOITEMS_REPAIR_TYPE"; + if ((target.hasTag(type) || consumable.getNBTItem().hasTag(type)) && + !target.getString(type).equals(consumable.getNBTItem().getString(type))) { + Message.UNABLE_TO_REPAIR.format(ChatColor.RED, "#item#", MMOUtils.getDisplayName(target.getItem())).send(player); + player.getPlayer().playSound(player.getPlayer().getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 1.5f); + return false; + } - if (target.hasTag("MMOITEMS_DURABILITY")) { - RepairItemEvent called = new RepairItemEvent(playerData, consumable.getMMOItem(), target, repairPower); - Bukkit.getPluginManager().callEvent(called); - if (called.isCancelled()) - return false; + if (target.hasTag("MMOITEMS_DURABILITY")) { + RepairItemEvent called = new RepairItemEvent(playerData, consumable.getMMOItem(), target, repairPower); + Bukkit.getPluginManager().callEvent(called); + if (called.isCancelled()) + return false; - DurabilityItem durItem = new DurabilityItem(player, target); - if (durItem.getDurability() < durItem.getMaxDurability()) { - target.getItem().setItemMeta(durItem.addDurability(called.getRepaired()).toItem().getItemMeta()); - Message.REPAIRED_ITEM - .format(ChatColor.YELLOW, "#item#", MMOUtils.getDisplayName(target.getItem()), "#amount#", String.valueOf(called.getRepaired())) - .send(player); - CustomSoundListener.playConsumableSound(consumable.getItem(), player); - } - return true; - } + DurabilityItem durItem = new DurabilityItem(player, target); + if (durItem.getDurability() < durItem.getMaxDurability()) { + target.getItem().setItemMeta(durItem.addDurability(called.getRepaired()).toItem().getItemMeta()); + Message.REPAIRED_ITEM + .format(ChatColor.YELLOW, "#item#", MMOUtils.getDisplayName(target.getItem()), "#amount#", String.valueOf(called.getRepaired())) + .send(player); + CustomSoundListener.playConsumableSound(consumable.getItem(), player); + } + return true; + } - // vanilla durability - if (!target.getBoolean("Unbreakable") && target.getItem().hasItemMeta() && target.getItem().getItemMeta() instanceof Damageable - && ((Damageable) target.getItem().getItemMeta()).getDamage() > 0) { - - RepairItemEvent called = new RepairItemEvent(playerData, consumable.getMMOItem(), target, repairPower); - Bukkit.getPluginManager().callEvent(called); - if (called.isCancelled()) - return false; - - ItemMeta meta = target.getItem().getItemMeta(); - ((Damageable) meta).setDamage(Math.max(0, ((Damageable) meta).getDamage() - called.getRepaired())); - target.getItem().setItemMeta(meta); - Message.REPAIRED_ITEM.format(ChatColor.YELLOW, "#item#", MMOUtils.getDisplayName(target.getItem()), "#amount#", "" + called.getRepaired()) - .send(player); - CustomSoundListener.playConsumableSound(consumable.getItem(), player); - return true; - } - - return false; - } + // vanilla durability + return RepairUtils.repairPower(playerData, target, consumable, repairPower); + } } diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RepairPowerPercent.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RepairPowerPercent.java index 30bd264c..fe8c0dfb 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RepairPowerPercent.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RepairPowerPercent.java @@ -2,7 +2,7 @@ package net.Indyuce.mmoitems.stat; import io.lumine.mythic.lib.api.item.NBTItem; import net.Indyuce.mmoitems.ItemStats; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.api.event.item.RepairItemEvent; import net.Indyuce.mmoitems.api.interaction.Consumable; @@ -12,14 +12,13 @@ import net.Indyuce.mmoitems.api.util.message.Message; import net.Indyuce.mmoitems.listener.CustomSoundListener; import net.Indyuce.mmoitems.stat.type.ConsumableItemInteraction; import net.Indyuce.mmoitems.stat.type.DoubleStat; +import net.Indyuce.mmoitems.util.RepairUtils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.entity.Player; import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.inventory.meta.Damageable; -import org.bukkit.inventory.meta.ItemMeta; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -65,23 +64,6 @@ public class RepairPowerPercent extends DoubleStat implements ConsumableItemInte } // vanilla durability - if (!target.getBoolean("Unbreakable") && target.getItem().hasItemMeta() && target.getItem().getItemMeta() instanceof Damageable - && ((Damageable) target.getItem().getItemMeta()).getDamage() > 0) { - - RepairItemEvent called = new RepairItemEvent(playerData, consumable.getMMOItem(), target, repairPower); - Bukkit.getPluginManager().callEvent(called); - if (called.isCancelled()) - return false; - - ItemMeta meta = target.getItem().getItemMeta(); - ((Damageable) meta).setDamage(Math.max(0, ((Damageable) meta).getDamage() - called.getRepaired())); - target.getItem().setItemMeta(meta); - Message.REPAIRED_ITEM.format(ChatColor.YELLOW, "#item#", MMOUtils.getDisplayName(target.getItem()), "#amount#", "" + called.getRepaired()) - .send(player); - CustomSoundListener.playConsumableSound(consumable.getItem(), player); - return true; - } - - return false; + return RepairUtils.repairPower(playerData, target, consumable, repairPower); } } diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RestoreFood.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RestoreFood.java index 6d24609d..54591da8 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RestoreFood.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RestoreFood.java @@ -4,7 +4,7 @@ import io.lumine.mythic.lib.MythicLib; import io.lumine.mythic.lib.api.util.ui.SilentNumbers; import io.lumine.mythic.lib.version.VersionMaterial; import net.Indyuce.mmoitems.ItemStats; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.item.mmoitem.VolatileMMOItem; import net.Indyuce.mmoitems.stat.data.DoubleData; import net.Indyuce.mmoitems.stat.type.DoubleStat; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RestoreHealth.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RestoreHealth.java index 0b610c33..bd45527a 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RestoreHealth.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RestoreHealth.java @@ -2,7 +2,7 @@ package net.Indyuce.mmoitems.stat; import io.lumine.mythic.lib.version.VersionMaterial; import net.Indyuce.mmoitems.ItemStats; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.item.mmoitem.VolatileMMOItem; import net.Indyuce.mmoitems.stat.data.DoubleData; import net.Indyuce.mmoitems.stat.type.DoubleStat; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RestoreSaturation.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RestoreSaturation.java index a85326f1..e862b8e3 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RestoreSaturation.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RestoreSaturation.java @@ -2,7 +2,7 @@ package net.Indyuce.mmoitems.stat; import io.lumine.mythic.lib.MythicLib; import net.Indyuce.mmoitems.ItemStats; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.item.mmoitem.VolatileMMOItem; import net.Indyuce.mmoitems.stat.data.DoubleData; import net.Indyuce.mmoitems.stat.type.DoubleStat; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/ShieldPatternStat.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/ShieldPatternStat.java index 0c081eaa..ec115ef5 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/ShieldPatternStat.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/ShieldPatternStat.java @@ -6,7 +6,6 @@ import java.util.Optional; import java.util.Set; import io.lumine.mythic.lib.api.item.ItemTag; -import net.Indyuce.mmoitems.stat.data.BooleanData; import net.Indyuce.mmoitems.stat.type.ItemStat; import org.apache.commons.lang.Validate; import org.bukkit.ChatColor; @@ -23,15 +22,12 @@ import org.bukkit.inventory.meta.BlockStateMeta; import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.edition.StatEdition; import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder; import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem; import net.Indyuce.mmoitems.gui.edition.EditionInventory; import net.Indyuce.mmoitems.stat.data.ShieldPatternData; -import net.Indyuce.mmoitems.stat.data.random.RandomStatData; -import net.Indyuce.mmoitems.stat.data.type.StatData; -import net.Indyuce.mmoitems.stat.type.StringStat; import io.lumine.mythic.lib.api.util.AltChar; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/SoulbindingBreakChance.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/SoulbindingBreakChance.java index 05bd6868..ec9f8334 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/SoulbindingBreakChance.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/SoulbindingBreakChance.java @@ -3,7 +3,7 @@ package net.Indyuce.mmoitems.stat; import io.lumine.mythic.lib.api.item.NBTItem; import io.lumine.mythic.lib.version.VersionMaterial; import net.Indyuce.mmoitems.ItemStats; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.api.event.item.BreakSoulboundEvent; import net.Indyuce.mmoitems.api.interaction.Consumable; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/SoulbindingChance.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/SoulbindingChance.java index df979ca2..9f53c7e7 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/SoulbindingChance.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/SoulbindingChance.java @@ -3,8 +3,7 @@ package net.Indyuce.mmoitems.stat; import io.lumine.mythic.lib.api.item.NBTItem; import io.lumine.mythic.lib.version.VersionMaterial; import net.Indyuce.mmoitems.ItemStats; -import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.api.event.item.ApplySoulboundEvent; import net.Indyuce.mmoitems.api.interaction.Consumable; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Soulbound.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Soulbound.java index 23684f28..7e49bc07 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Soulbound.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Soulbound.java @@ -19,7 +19,7 @@ import com.google.gson.JsonSyntaxException; import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder; import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem; import net.Indyuce.mmoitems.api.player.RPGPlayer; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/SoulboundLevel.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/SoulboundLevel.java index d02dde12..0ecafc69 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/SoulboundLevel.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/SoulboundLevel.java @@ -2,7 +2,7 @@ package net.Indyuce.mmoitems.stat; import io.lumine.mythic.lib.api.item.ItemTag; import io.lumine.mythic.lib.version.VersionMaterial; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder; import net.Indyuce.mmoitems.api.util.NumericStatFormula; import net.Indyuce.mmoitems.stat.data.DoubleData; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/UpgradeStat.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/UpgradeStat.java index 989a9fae..75590289 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/UpgradeStat.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/UpgradeStat.java @@ -8,7 +8,7 @@ import io.lumine.mythic.lib.api.item.SupportedNBTTagValues; import io.lumine.mythic.lib.api.util.AltChar; import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.api.event.item.UpgradeItemEvent; import net.Indyuce.mmoitems.api.interaction.Consumable; @@ -22,7 +22,6 @@ import net.Indyuce.mmoitems.api.util.message.Message; import net.Indyuce.mmoitems.gui.edition.EditionInventory; import net.Indyuce.mmoitems.gui.edition.UpgradingEdition; import net.Indyuce.mmoitems.stat.data.UpgradeData; -import net.Indyuce.mmoitems.stat.data.random.RandomStatData; import net.Indyuce.mmoitems.stat.data.type.StatData; import net.Indyuce.mmoitems.stat.type.ConsumableItemInteraction; import net.Indyuce.mmoitems.stat.type.ItemStat; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/AbilityData.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/AbilityData.java index daa2e5e8..54044bab 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/AbilityData.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/AbilityData.java @@ -9,7 +9,7 @@ import io.lumine.mythic.lib.skill.SkillMetadata; import io.lumine.mythic.lib.skill.handler.SkillHandler; import io.lumine.mythic.lib.skill.trigger.TriggerType; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.player.PlayerData; import net.Indyuce.mmoitems.api.player.RPGPlayer; import net.Indyuce.mmoitems.api.util.message.Message; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/GemstoneData.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/GemstoneData.java index b25b4592..1ae08862 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/GemstoneData.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/GemstoneData.java @@ -3,7 +3,7 @@ package net.Indyuce.mmoitems.stat.data; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import net.Indyuce.mmoitems.ItemStats; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.item.mmoitem.LiveMMOItem; import net.Indyuce.mmoitems.stat.GemUpgradeScaling; import net.Indyuce.mmoitems.stat.type.ItemStat; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/PotionEffectData.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/PotionEffectData.java index 2b581802..0de8951e 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/PotionEffectData.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/PotionEffectData.java @@ -1,6 +1,6 @@ package net.Indyuce.mmoitems.stat.data; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/random/RandomAbilityData.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/random/RandomAbilityData.java index bd97798f..38027968 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/random/RandomAbilityData.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/random/RandomAbilityData.java @@ -5,7 +5,7 @@ import java.util.Map; import java.util.Set; import io.lumine.mythic.lib.skill.trigger.TriggerType; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.skill.RegisteredSkill; import org.apache.commons.lang.Validate; import org.bukkit.configuration.ConfigurationSection; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/random/RandomPotionEffectData.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/random/RandomPotionEffectData.java index e59e02d2..64a1d571 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/random/RandomPotionEffectData.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/random/RandomPotionEffectData.java @@ -4,7 +4,7 @@ import org.apache.commons.lang.Validate; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.potion.PotionEffectType; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.item.build.MMOItemBuilder; import net.Indyuce.mmoitems.api.util.NumericStatFormula; import net.Indyuce.mmoitems.stat.data.PotionEffectData; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/BooleanStat.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/BooleanStat.java index 1e209cf6..ab059f59 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/BooleanStat.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/BooleanStat.java @@ -13,7 +13,7 @@ import org.bukkit.event.inventory.InventoryAction; import org.bukkit.event.inventory.InventoryClickEvent; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.edition.StatEdition; import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder; import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/DoubleStat.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/DoubleStat.java index 66ed06bb..f5579414 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/DoubleStat.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/DoubleStat.java @@ -10,7 +10,7 @@ import io.lumine.mythic.lib.api.util.ui.PlusMinusPercent; import io.lumine.mythic.lib.api.util.ui.SilentNumbers; import io.lumine.mythic.lib.manager.StatManager; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.UpgradeTemplate; import net.Indyuce.mmoitems.api.edition.StatEdition; import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/StatHistory.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/StatHistory.java index 839262ec..f1f77cb3 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/StatHistory.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/StatHistory.java @@ -6,7 +6,7 @@ import io.lumine.mythic.lib.api.util.ui.FriendlyFeedbackCategory; import io.lumine.mythic.lib.api.util.ui.FriendlyFeedbackProvider; import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem; import net.Indyuce.mmoitems.api.util.message.FFPMMOItems; import net.Indyuce.mmoitems.stat.data.*; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/MMOUtils.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/util/MMOUtils.java similarity index 98% rename from MMOItems-API/src/main/java/net/Indyuce/mmoitems/MMOUtils.java rename to MMOItems-API/src/main/java/net/Indyuce/mmoitems/util/MMOUtils.java index 98d4d509..fbe275b9 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/MMOUtils.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/util/MMOUtils.java @@ -1,4 +1,4 @@ -package net.Indyuce.mmoitems; +package net.Indyuce.mmoitems.util; import com.google.common.collect.ImmutableMap; import com.mojang.authlib.GameProfile; @@ -8,6 +8,7 @@ import io.lumine.mythic.lib.api.item.ItemTag; import io.lumine.mythic.lib.api.item.NBTItem; import io.lumine.mythic.lib.api.item.SupportedNBTTagValues; import io.lumine.mythic.lib.skill.trigger.TriggerType; +import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.api.Type; import org.apache.commons.codec.binary.Base64; import org.bukkit.ChatColor; @@ -33,6 +34,10 @@ import java.util.*; @SuppressWarnings("unused") public class MMOUtils { + public MMOUtils() { + throw new IllegalArgumentException("This class cannot be instantiated."); + } + /** * @return The skull texture URL from a given player head */ diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/util/PluginUtils.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/util/PluginUtils.java new file mode 100644 index 00000000..af2403d5 --- /dev/null +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/util/PluginUtils.java @@ -0,0 +1,34 @@ +package net.Indyuce.mmoitems.util; + +import net.Indyuce.mmoitems.MMOItems; +import org.bukkit.Bukkit; +import org.jetbrains.annotations.NotNull; + +import java.util.function.Consumer; +import java.util.logging.Level; + +/** + * mmoitems + * + * @author Roch Blondiaux + * @date 24/10/2022 + */ +public class PluginUtils { + + public PluginUtils() { + throw new IllegalStateException("Utility class"); + } + + public static void isDependencyPresent(@NotNull String name, @NotNull Consumer callback) { + if (Bukkit.getPluginManager().getPlugin(name) != null) + callback.accept(null); + } + + public static void hookDependencyIfPresent(@NotNull String name, @NotNull Consumer callback) { + if (Bukkit.getPluginManager().getPlugin(name) == null) + return; + callback.accept(null); + MMOItems.plugin.getLogger().log(Level.INFO, "Hooked onto %s".formatted(name)); + } + +} diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/util/RepairUtils.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/util/RepairUtils.java new file mode 100644 index 00000000..e1648fff --- /dev/null +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/util/RepairUtils.java @@ -0,0 +1,51 @@ +package net.Indyuce.mmoitems.util; + +import io.lumine.mythic.lib.api.item.NBTItem; +import net.Indyuce.mmoitems.api.event.item.RepairItemEvent; +import net.Indyuce.mmoitems.api.interaction.Consumable; +import net.Indyuce.mmoitems.api.player.PlayerData; +import net.Indyuce.mmoitems.api.util.message.Message; +import net.Indyuce.mmoitems.listener.CustomSoundListener; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import org.bukkit.inventory.meta.Damageable; +import org.bukkit.inventory.meta.ItemMeta; +import org.jetbrains.annotations.NotNull; + +/** + * mmoitems + * + * @author Roch Blondiaux + * @date 24/10/2022 + */ +public class RepairUtils { + + public RepairUtils() { + throw new IllegalStateException("Utility class"); + } + + public static boolean repairPower(@NotNull PlayerData playerData, @NotNull NBTItem target, @NotNull Consumable consumable, double repairPower) { + final Player player = playerData.getPlayer(); + if (!target.getBoolean("Unbreakable") && target.getItem().hasItemMeta() && target.getItem().getItemMeta() instanceof Damageable + && ((Damageable) target.getItem().getItemMeta()).getDamage() > 0) { + RepairItemEvent called = new RepairItemEvent(playerData, consumable.getMMOItem(), target, repairPower); + Bukkit.getPluginManager().callEvent(called); + if (called.isCancelled()) + return false; + + ItemMeta meta = target.getItem().getItemMeta(); + ((Damageable) meta).setDamage(Math.max(0, ((Damageable) meta).getDamage() - called.getRepaired())); + target.getItem().setItemMeta(meta); + Message.REPAIRED_ITEM.format(ChatColor.YELLOW, + "#item#", + MMOUtils.getDisplayName(target.getItem()), + "#amount#", + String.valueOf(called.getRepaired() == -1 ? called.getRepairedPercent() : called.getRepaired())) + .send(player); + CustomSoundListener.playConsumableSound(consumable.getItem(), player); + return true; + } + return false; + } +} diff --git a/MMOItems-Dist/pom.xml b/MMOItems-Dist/pom.xml index 5c8a3951..eaa7c2a6 100644 --- a/MMOItems-Dist/pom.xml +++ b/MMOItems-Dist/pom.xml @@ -17,8 +17,26 @@ 16 - + + + + + org.spigotmc + spigot-api + 1.18-R0.1-SNAPSHOT + provided + + + + net.Indyuce + MMOItems-API + ${revision} + true + + + + @@ -28,7 +46,6 @@ - org.apache.maven.plugins @@ -92,28 +109,6 @@ - - - - - - - - org.spigotmc - spigot-api - 1.18-R0.1-SNAPSHOT - provided - - - - net.Indyuce - MMOItems-API - ${revision} - true - - - - \ No newline at end of file diff --git a/MMOItems-Dist/src/main/java/net/Indyuce/mmoitems/listener/CustomBlockListener.java b/MMOItems-Dist/src/main/java/net/Indyuce/mmoitems/listener/CustomBlockListener.java index 65d89633..4e1eba7c 100644 --- a/MMOItems-Dist/src/main/java/net/Indyuce/mmoitems/listener/CustomBlockListener.java +++ b/MMOItems-Dist/src/main/java/net/Indyuce/mmoitems/listener/CustomBlockListener.java @@ -1,7 +1,7 @@ package net.Indyuce.mmoitems.listener; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.block.CustomBlock; import io.lumine.mythic.lib.MythicLib; import io.lumine.mythic.lib.api.item.NBTItem; diff --git a/MMOItems-Dist/src/main/java/net/Indyuce/mmoitems/listener/reforging/RFGKeepUpgrades.java b/MMOItems-Dist/src/main/java/net/Indyuce/mmoitems/listener/reforging/RFGKeepUpgrades.java index 8cc6cc60..a3e67c13 100644 --- a/MMOItems-Dist/src/main/java/net/Indyuce/mmoitems/listener/reforging/RFGKeepUpgrades.java +++ b/MMOItems-Dist/src/main/java/net/Indyuce/mmoitems/listener/reforging/RFGKeepUpgrades.java @@ -16,13 +16,14 @@ public class RFGKeepUpgrades implements Listener { @EventHandler public void onReforge(MMOItemReforgeEvent event) { - if (!event.getOptions().shouldKeepUpgrades()) { return; } - //RFG// MMOItems.log("§8Reforge §4EFG§7 Keeping Upgrades"); + final UpgradeData upgrade = ((UpgradeData) event.getOldMMOItem().getData(ItemStats.UPGRADE)); + final UpgradeData newOne = ((UpgradeData) event.getNewMMOItem().getData(ItemStats.UPGRADE)); - UpgradeData upgrade = ((UpgradeData) event.getOldMMOItem().getData(ItemStats.UPGRADE)); - UpgradeData newOne = ((UpgradeData) event.getNewMMOItem().getData(ItemStats.UPGRADE)); - - if (upgrade == null || newOne == null) { return; } + if (!event.getOptions().shouldKeepUpgrades() + || upgrade == null + || newOne == null + || newOne.getMaxUpgrades() <= 0) + return; //UPGRD//MMOItems.log(" \u00a7e* \u00a77Existing Upgrade Detected"); diff --git a/pom.xml b/pom.xml index 8f9bf04c..9fb40aff 100644 --- a/pom.xml +++ b/pom.xml @@ -23,6 +23,38 @@ UTF-8 + + + + phoenix + https://nexus.phoenixdvpt.fr/repository/maven-public/ + + + nexus + https://mvn.lumine.io/repository/maven-public/ + + + + + + + + io.lumine + MythicLib-dist + 1.4.2-SNAPSHOT + provided + + + + org.jetbrains + annotations + 23.0.0 + provided + + + + + @@ -56,35 +88,4 @@ - - - - phoenix - https://nexus.phoenixdvpt.fr/repository/maven-public/ - - - - nexus - https://mvn.lumine.io/repository/maven-public/ - - - - - - - - io.lumine - MythicLib-dist - 1.4.2-SNAPSHOT - provided - - - - org.jetbrains - annotations - 22.0.0 - provided - - -