From 835bfcdb440d3bb18cd7ccea839f851e210b9de3 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Sun, 29 Aug 2021 12:54:30 +0100 Subject: [PATCH] Added EcoEnchants integration --- eco-core/core-plugin/build.gradle | 1 + .../com/willfp/ecoskills/EcoSkillsPlugin.java | 4 ++- .../willfp/ecoskills/commands/CommandTop.kt | 2 ++ .../ecoskills/data/LeaderboardHandler.kt | 1 + .../EcoEnchantsEnchantingLeveller.kt | 33 +++++++++++++++++++ .../src/main/resources/skills/enchanting.yml | 6 +++- 6 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/integrations/EcoEnchantsEnchantingLeveller.kt diff --git a/eco-core/core-plugin/build.gradle b/eco-core/core-plugin/build.gradle index 9f7d387..7f2d623 100644 --- a/eco-core/core-plugin/build.gradle +++ b/eco-core/core-plugin/build.gradle @@ -5,4 +5,5 @@ dependencies { compileOnly 'org.spigotmc:spigot-api:1.16.4-R0.1-SNAPSHOT' compileOnly 'com.gmail.filoghost.holographicdisplays:holographicdisplays-api:2.4.0' compileOnly 'com.comphenix.protocol:ProtocolLib:4.7.0' + compileOnly 'com.willfp:EcoEnchants:8.2.0' } \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoskills/EcoSkillsPlugin.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoskills/EcoSkillsPlugin.java index 3fc7f1a..15a4118 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoskills/EcoSkillsPlugin.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoskills/EcoSkillsPlugin.java @@ -13,6 +13,7 @@ import com.willfp.ecoskills.config.EffectsYml; import com.willfp.ecoskills.data.LeaderboardHandler; import com.willfp.ecoskills.effects.Effect; import com.willfp.ecoskills.effects.Effects; +import com.willfp.ecoskills.integrations.EcoEnchantsEnchantingLeveller; import com.willfp.ecoskills.skills.Skill; import com.willfp.ecoskills.skills.SkillDisplayListener; import com.willfp.ecoskills.skills.SkillLevellingListener; @@ -132,7 +133,8 @@ public class EcoSkillsPlugin extends EcoPlugin { @Override protected List loadIntegrationLoaders() { return Arrays.asList( - new IntegrationLoader("HolographicDisplays", () -> this.getEventManager().registerListener(new DamageIndicatorListener(this))) + new IntegrationLoader("HolographicDisplays", () -> this.getEventManager().registerListener(new DamageIndicatorListener(this))), + new IntegrationLoader("EcoEnchants", () -> this.getEventManager().registerListener(new EcoEnchantsEnchantingLeveller(this))) ); } } diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/commands/CommandTop.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/commands/CommandTop.kt index 71b2a2f..1234f28 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/commands/CommandTop.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/commands/CommandTop.kt @@ -6,6 +6,7 @@ import com.willfp.eco.core.command.impl.Subcommand import com.willfp.eco.util.StringUtils import com.willfp.ecoskills.data.LeaderboardHandler import com.willfp.ecoskills.getTotalSkillLevel +import org.bukkit.Bukkit import org.bukkit.command.CommandSender import org.bukkit.entity.Player @@ -20,6 +21,7 @@ class CommandTop(plugin: EcoPlugin) : override fun getHandler(): CommandHandler { return CommandHandler { sender: CommandSender, args: List -> val page = args.firstOrNull()?.toIntOrNull() ?: 1 + Bukkit.getLogger().info("page raw $page") val top = LeaderboardHandler.getPage(page) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/data/LeaderboardHandler.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/data/LeaderboardHandler.kt index 2470111..e062e59 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/data/LeaderboardHandler.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/data/LeaderboardHandler.kt @@ -14,6 +14,7 @@ class LeaderboardHandler { fun getPage(page: Int): MutableMap { val maxPage = ceil(sortedLeaderboard.size / 10.0).toInt() val finalPage = max(1, min(page, maxPage)) + Bukkit.getLogger().info("page final $finalPage") val startIndex = (finalPage - 1) * 10 val endIndex = min(startIndex + 9, sortedLeaderboard.size - 1) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/integrations/EcoEnchantsEnchantingLeveller.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/integrations/EcoEnchantsEnchantingLeveller.kt new file mode 100644 index 0000000..185f2a1 --- /dev/null +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/integrations/EcoEnchantsEnchantingLeveller.kt @@ -0,0 +1,33 @@ +package com.willfp.ecoskills.integrations + +import com.willfp.ecoenchants.enchantments.EcoEnchants +import com.willfp.ecoenchants.enchantments.meta.EnchantmentType +import com.willfp.ecoskills.EcoSkillsPlugin +import com.willfp.ecoskills.giveSkillExperience +import com.willfp.ecoskills.skills.Skills +import org.bukkit.GameMode +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.enchantment.EnchantItemEvent + +class EcoEnchantsEnchantingLeveller( + private val plugin: EcoSkillsPlugin +) : Listener { + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + fun handleLevelling(event: EnchantItemEvent) { + val player = event.enchanter + + if (player.gameMode == GameMode.CREATIVE || player.gameMode == GameMode.SPECTATOR) { + return + } + + this.plugin.scheduler.runLater({ + if (EcoEnchants.hasAnyOfType(event.item, EnchantmentType.SPECIAL)) { + val toGive = Skills.ENCHANTING.config.getDouble("ecoenchants.xp-for-special") + + player.giveSkillExperience(Skills.ENCHANTING, toGive) + } + }, 2) + } +} \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/resources/skills/enchanting.yml b/eco-core/core-plugin/src/main/resources/skills/enchanting.yml index 6026823..bfc6abf 100644 --- a/eco-core/core-plugin/src/main/resources/skills/enchanting.yml +++ b/eco-core/core-plugin/src/main/resources/skills/enchanting.yml @@ -66,5 +66,9 @@ rewards: - " %ecoskills_reimbursement_description%" - " &8ยป &r&6Overcompensation %ecoskills_over_compensation_numeral%" - " %ecoskills_overcompensation_description%" + # The experience to give for each level cost of enchanting -xp-per-level: 4 \ No newline at end of file +xp-per-level: 4 + +ecoenchants: #Config for EcoEnchants integration + xp-for-special: 2500 \ No newline at end of file