diff --git a/build.gradle.kts b/build.gradle.kts index c9ac24d..b12bf3a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -32,13 +32,13 @@ repositories { maven("https://jitpack.io/") maven("https://repo.projectshard.dev/repository/releases/") maven("https://repo.oraxen.com/releases") + maven("https://nexus.phoenixdevt.fr/repository/maven-public/") } dependencies { compileOnly("io.papermc.paper:paper-api:1.21-R0.1-SNAPSHOT") - compileOnly("gg.auroramc:Aurora:1.5.5") - compileOnly("gg.auroramc:AuroraLevels:1.3.0") - compileOnly("gg.auroramc:AuroraCollections:1.0.0-SNAPSHOT") + compileOnly("gg.auroramc:Aurora:1.5.9") + compileOnly("gg.auroramc:AuroraLevels:1.5.1") compileOnly("net.luckperms:api:5.4") compileOnly("dev.aurelium:auraskills-api-bukkit:2.2.0") compileOnly("io.lumine:Mythic-Dist:5.6.1") @@ -52,6 +52,7 @@ dependencies { compileOnly("com.github.Gypopo:EconomyShopGUI-API:1.7.1") compileOnly("io.th0rgal:oraxen:1.179.0") compileOnly("com.github.brcdev-minecraft:shopgui-api:3.0.0") + compileOnly("io.lumine:MythicLib-dist:1.6.2-SNAPSHOT") implementation("co.aikar:acf-paper:0.5.1-SNAPSHOT") diff --git a/src/main/java/gg/auroramc/quests/hooks/Hooks.java b/src/main/java/gg/auroramc/quests/hooks/Hooks.java index 1ec0142..93c20ac 100644 --- a/src/main/java/gg/auroramc/quests/hooks/Hooks.java +++ b/src/main/java/gg/auroramc/quests/hooks/Hooks.java @@ -5,6 +5,7 @@ import gg.auroramc.quests.hooks.citizens.CitizensHook; import gg.auroramc.quests.hooks.customfishing.CustomFishingHook; import gg.auroramc.quests.hooks.luckperms.LuckPermsHook; +import gg.auroramc.quests.hooks.mmolib.MMOLibHook; import gg.auroramc.quests.hooks.mythicmobs.MythicHook; import gg.auroramc.quests.hooks.oraxen.OraxenHook; import gg.auroramc.quests.hooks.shopguiplus.ShopGUIPlusHook; @@ -25,6 +26,7 @@ public enum Hooks { CITIZENS(CitizensHook.class, "Citizens"), SHOPKEEPERS(ShopkeepersHook.class, "Shopkeepers"), ORAXEN(OraxenHook.class, "Oraxen"), + MMOLIB(MMOLibHook.class, "MythicLib"), SHOP_GUI_PLUS(ShopGUIPlusHook.class, "ShopGUIPlus"), ECONOMY_SHOP_GUI(CitizensHook.class, Set.of("EconomyShopGUI", "EconomyShopGUI-Premium")), LUCK_PERMS(LuckPermsHook.class, "LuckPerms"); @@ -43,8 +45,8 @@ public enum Hooks { } public boolean canHook() { - for(String plugin : plugins) { - if(Bukkit.getPluginManager().getPlugin(plugin) != null) { + for (String plugin : plugins) { + if (Bukkit.getPluginManager().getPlugin(plugin) != null) { return true; } } diff --git a/src/main/java/gg/auroramc/quests/hooks/mmolib/MMOLibHook.java b/src/main/java/gg/auroramc/quests/hooks/mmolib/MMOLibHook.java new file mode 100644 index 0000000..a15c805 --- /dev/null +++ b/src/main/java/gg/auroramc/quests/hooks/mmolib/MMOLibHook.java @@ -0,0 +1,16 @@ +package gg.auroramc.quests.hooks.mmolib; + +import gg.auroramc.aurora.api.util.NamespacedId; +import gg.auroramc.quests.AuroraQuests; +import gg.auroramc.quests.hooks.Hook; + +public class MMOLibHook implements Hook { + @Override + public void hook(AuroraQuests plugin) { + plugin.getQuestManager().getRewardFactory() + .registerRewardType(NamespacedId.fromDefault("mmo_stat"), MMOStatReward.class); + + plugin.getQuestManager().getRewardAutoCorrector() + .registerCorrector(NamespacedId.fromDefault("mmo_stat"), new MMOStatCorrector(plugin)); + } +} diff --git a/src/main/java/gg/auroramc/quests/hooks/mmolib/MMOStatCorrector.java b/src/main/java/gg/auroramc/quests/hooks/mmolib/MMOStatCorrector.java new file mode 100644 index 0000000..d7dbf3f --- /dev/null +++ b/src/main/java/gg/auroramc/quests/hooks/mmolib/MMOStatCorrector.java @@ -0,0 +1,88 @@ +package gg.auroramc.quests.hooks.mmolib; + +import com.google.common.collect.Maps; +import gg.auroramc.aurora.api.reward.RewardCorrector; +import gg.auroramc.aurora.api.util.NamespacedId; +import gg.auroramc.quests.AuroraQuests; +import io.lumine.mythic.lib.api.player.EquipmentSlot; +import io.lumine.mythic.lib.api.player.MMOPlayerData; +import io.lumine.mythic.lib.api.stat.StatMap; +import io.lumine.mythic.lib.api.stat.modifier.StatModifier; +import io.lumine.mythic.lib.player.modifier.ModifierSource; +import io.lumine.mythic.lib.player.modifier.ModifierType; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +import java.util.Map; +import java.util.UUID; + +public class MMOStatCorrector implements RewardCorrector { + private final AuroraQuests plugin; + + public MMOStatCorrector(AuroraQuests plugin) { + this.plugin = plugin; + } + + @Override + public void correctRewards(Player player) { + var manager = plugin.getQuestManager(); + + MMOPlayerData playerData = MMOPlayerData.get(player); + StatMap stats = playerData.getStatMap(); + + Map statMap = Maps.newHashMap(); + + // Gather new stat modifiers + for (var pool : manager.getQuestPools()) { + if (pool.isGlobal()) { + for (var quest : pool.getQuests()) { + if (!quest.isCompleted(player)) continue; + + for (var reward : quest.getRewards().values()) { + if (reward instanceof MMOStatReward statReward && statReward.isValid()) { + var key = NamespacedId.of(MMOStatReward.getMMO_STAT(), statReward.getStat()).toString(); + var current = statReward.getCurrentModifier(key, stats); + UUID uuid = current != null ? current.getUniqueId() : UUID.randomUUID(); + statMap.merge(statReward.getStat(), + new MMOStat(statReward.getModifierType(), statReward.getValue(quest.getPlaceholders(player)), key, uuid), + (a, b) -> new MMOStat(statReward.getModifierType(), a.value() + b.value(), a.key(), a.uuid())); + } + } + } + } + + + if (!pool.hasLeveling()) continue; + var level = pool.getPlayerLevel(player); + + for (int i = 1; i < level + 1; i++) { + var matcher = pool.getMatcherManager().getBestMatcher(i); + if (matcher == null) continue; + var placeholders = pool.getLevelPlaceholders(player, i); + for (var reward : matcher.computeRewards(i)) { + if (reward instanceof MMOStatReward statReward && statReward.isValid()) { + var key = NamespacedId.of(MMOStatReward.getMMO_STAT(), statReward.getStat()).toString(); + var current = statReward.getCurrentModifier(key, stats); + UUID uuid = current != null ? current.getUniqueId() : UUID.randomUUID(); + statMap.merge(statReward.getStat(), + new MMOStat(statReward.getModifierType(), statReward.getValue(placeholders), key, uuid), + (a, b) -> new MMOStat(statReward.getModifierType(), a.value() + b.value(), a.key(), a.uuid())); + } + } + } + } + + Bukkit.getGlobalRegionScheduler().runDelayed(plugin, (task) -> { + for (var entry : statMap.entrySet()) { + var statType = entry.getKey(); + var s = entry.getValue(); + + new StatModifier(s.uuid, s.key, statType, s.value, s.modifierType, EquipmentSlot.OTHER, ModifierSource.OTHER) + .register(playerData); + } + }, 3); + } + + public record MMOStat(ModifierType modifierType, double value, String key, UUID uuid) { + } +} diff --git a/src/main/java/gg/auroramc/quests/hooks/mmolib/MMOStatReward.java b/src/main/java/gg/auroramc/quests/hooks/mmolib/MMOStatReward.java new file mode 100644 index 0000000..1c18868 --- /dev/null +++ b/src/main/java/gg/auroramc/quests/hooks/mmolib/MMOStatReward.java @@ -0,0 +1,75 @@ +package gg.auroramc.quests.hooks.mmolib; + +import gg.auroramc.aurora.api.message.Placeholder; +import gg.auroramc.aurora.api.reward.NumberReward; +import gg.auroramc.aurora.api.util.NamespacedId; +import gg.auroramc.quests.AuroraQuests; +import io.lumine.mythic.lib.api.player.MMOPlayerData; +import io.lumine.mythic.lib.api.stat.StatMap; +import io.lumine.mythic.lib.api.stat.modifier.StatModifier; +import io.lumine.mythic.lib.player.modifier.ModifierType; +import lombok.Getter; +import org.bukkit.Bukkit; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +@Getter +public class MMOStatReward extends NumberReward { + @Getter + private static final String MMO_STAT = "aurora_quests"; + private String stat; + private ModifierType modifierType; + private boolean valid = true; + + @Override + public void execute(Player player, long level, List> placeholders) { + if (!valid) return; + + MMOPlayerData playerData = MMOPlayerData.get(player); + StatMap statMap = playerData.getStatMap(); + String key = NamespacedId.of(MMO_STAT, stat).toString(); + StatModifier currentModifier = getCurrentModifier(key, statMap); + + double value = getValue(placeholders); + + if (currentModifier != null) { + value += currentModifier.getValue(); + currentModifier.unregister(playerData); + } + + StatModifier modifier = new StatModifier(key, stat, value, modifierType); + + modifier.register(playerData); + + Bukkit.getGlobalRegionScheduler().runDelayed(AuroraQuests.getInstance(), (task) -> { + statMap.getInstance(stat).update(); + }, 3); + } + + @Override + public void init(ConfigurationSection args) { + super.init(args); + + this.stat = args.getString("stat"); + + if (this.stat == null) { + this.valid = false; + AuroraQuests.logger().warning("Stat is not defined in MMOStatReward"); + } + + this.modifierType = ModifierType.valueOf(args.getString("modifier", "FLAT")); + } + + @Nullable + public StatModifier getCurrentModifier(String key, StatMap statMap) { + for (StatModifier stat : statMap.getInstance(stat).getModifiers()) { + if (stat.getKey().equals(key)) { + return stat; + } + } + return null; + } +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 94f8b9e..a8f1b38 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -19,6 +19,7 @@ softdepend: - "AuroraLevels" - "Oraxen" - "ShopGUIPlus" + - "MythicLib" website: https://auroramc.gg