From bee0e7e91cfa982ad3dd46fb856b35a4db1193af Mon Sep 17 00:00:00 2001 From: Auxilor Date: Tue, 5 Oct 2021 09:39:26 +0100 Subject: [PATCH] Added EcoSkills integration --- eco-core/core-plugin/build.gradle | 1 + .../com/willfp/reforges/ReforgesPlugin.java | 9 +++++ .../com/willfp/reforges/effects/Effect.java | 11 ++++++ .../ecoskills/EcoSkillsIntegration.kt | 11 ++++++ .../integrations/ecoskills/EffectAddStat.kt | 38 +++++++++++++++++++ .../core-plugin/src/main/resources/plugin.yml | 1 + 6 files changed, 71 insertions(+) create mode 100644 eco-core/core-plugin/src/main/kotlin/com/willfp/reforges/integrations/ecoskills/EcoSkillsIntegration.kt create mode 100644 eco-core/core-plugin/src/main/kotlin/com/willfp/reforges/integrations/ecoskills/EffectAddStat.kt diff --git a/eco-core/core-plugin/build.gradle b/eco-core/core-plugin/build.gradle index 543f004..49f20ac 100644 --- a/eco-core/core-plugin/build.gradle +++ b/eco-core/core-plugin/build.gradle @@ -4,6 +4,7 @@ version rootProject.version dependencies { compileOnly 'io.papermc.paper:paper-api:1.17.1-R0.1-SNAPSHOT' compileOnly 'com.github.MilkBowl:VaultAPI:1.7' + compileOnly 'com.willfp:EcoSkills:1.4.0' } build.dependsOn publishToMavenLocal diff --git a/eco-core/core-plugin/src/main/java/com/willfp/reforges/ReforgesPlugin.java b/eco-core/core-plugin/src/main/java/com/willfp/reforges/ReforgesPlugin.java index c188819..cd8a7a7 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/reforges/ReforgesPlugin.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/reforges/ReforgesPlugin.java @@ -3,6 +3,7 @@ package com.willfp.reforges; import com.willfp.eco.core.EcoPlugin; import com.willfp.eco.core.command.impl.PluginCommand; import com.willfp.eco.core.display.DisplayModule; +import com.willfp.eco.core.integrations.IntegrationLoader; import com.willfp.eco.core.items.Items; import com.willfp.reforges.commands.CommandReforge; import com.willfp.reforges.commands.CommandReforges; @@ -11,6 +12,7 @@ import com.willfp.reforges.config.TargetYml; import com.willfp.reforges.display.ReforgesDisplay; import com.willfp.reforges.effects.Effect; import com.willfp.reforges.effects.Effects; +import com.willfp.reforges.integrations.ecoskills.EcoSkillsIntegration; import com.willfp.reforges.reforges.Reforges; import com.willfp.reforges.reforges.util.ReforgeArgParser; import com.willfp.reforges.reforges.util.ReforgeEnableListeners; @@ -108,6 +110,13 @@ public class ReforgesPlugin extends EcoPlugin { return new ReforgesDisplay(this); } + @Override + protected List loadIntegrationLoaders() { + return Arrays.asList( + new IntegrationLoader("EcoSkills", EcoSkillsIntegration.INSTANCE::load) + ); + } + @Override public String getMinimumEcoVersion() { return "6.9.0"; diff --git a/eco-core/core-plugin/src/main/java/com/willfp/reforges/effects/Effect.java b/eco-core/core-plugin/src/main/java/com/willfp/reforges/effects/Effect.java index 6634c44..4ea5496 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/reforges/effects/Effect.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/reforges/effects/Effect.java @@ -5,6 +5,7 @@ import com.willfp.reforges.ReforgesPlugin; import com.willfp.reforges.reforges.util.Watcher; import lombok.AccessLevel; import lombok.Getter; +import org.bukkit.NamespacedKey; import org.bukkit.entity.Player; import org.bukkit.event.Listener; import org.jetbrains.annotations.NotNull; @@ -56,6 +57,16 @@ public abstract class Effect implements Listener, Watcher { return UUID.nameUUIDFromBytes((this.id + index + Arrays.hashCode(extra)).getBytes()); } + /** + * Generate a NamespacedKey with a specified index. + * + * @param index The index. + * @return The NamespacedKey. + */ + protected NamespacedKey getNamespacedKey(final int index) { + return this.getPlugin().getNamespacedKeyFactory().create(this.id + "_" + index); + } + /** * Handle application of a reforge containing this effect. * diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/reforges/integrations/ecoskills/EcoSkillsIntegration.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/reforges/integrations/ecoskills/EcoSkillsIntegration.kt new file mode 100644 index 0000000..ab6e867 --- /dev/null +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/reforges/integrations/ecoskills/EcoSkillsIntegration.kt @@ -0,0 +1,11 @@ +package com.willfp.reforges.integrations.ecoskills + +import com.willfp.reforges.effects.Effect + +object EcoSkillsIntegration { + lateinit var ADD_STAT: Effect + + fun load() { + ADD_STAT = EffectAddStat() + } +} \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/reforges/integrations/ecoskills/EffectAddStat.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/reforges/integrations/ecoskills/EffectAddStat.kt new file mode 100644 index 0000000..175544b --- /dev/null +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/reforges/integrations/ecoskills/EffectAddStat.kt @@ -0,0 +1,38 @@ +package com.willfp.reforges.integrations.ecoskills + +import com.willfp.eco.core.config.interfaces.JSONConfig +import com.willfp.ecoskills.api.EcoSkillsAPI +import com.willfp.ecoskills.api.modifier.PlayerStatModifier +import com.willfp.ecoskills.stats.Stats +import com.willfp.reforges.effects.Effect +import com.willfp.reforges.effects.getEffectAmount +import org.bukkit.entity.Player + +class EffectAddStat : Effect("add_stat") { + private val api = EcoSkillsAPI.getInstance() + + override fun handleEnable( + player: Player, + config: JSONConfig + ) { + api.addStatModifier( + player, + PlayerStatModifier( + this.getNamespacedKey(player.getEffectAmount(this)), + Stats.getByID(config.getString("stat", false)) ?: Stats.WISDOM, + config.getInt("amount") + ) + ) + } + + override fun handleDisable(player: Player) { + api.removeStatModifier( + player, + PlayerStatModifier( + this.getNamespacedKey(player.getEffectAmount(this)), + Stats.STRENGTH, + 0 + ) + ) + } +} \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/resources/plugin.yml b/eco-core/core-plugin/src/main/resources/plugin.yml index fefcdf9..678ec8c 100644 --- a/eco-core/core-plugin/src/main/resources/plugin.yml +++ b/eco-core/core-plugin/src/main/resources/plugin.yml @@ -10,6 +10,7 @@ depend: - ProtocolLib softdepend: - Vault + - EcoSkills libraries: - 'org.jetbrains.kotlin:kotlin-stdlib:1.5.21'