From ba82ecb290053453d3229a44f6ca61b1cbd8de74 Mon Sep 17 00:00:00 2001 From: _OfTeN_ Date: Wed, 5 Jan 2022 22:34:26 +0300 Subject: [PATCH] Added prevent-levelling-from-spawners to Combat skill --- .../willfp/ecoskills/skills/skills/SkillCombat.kt | 15 +++++++++++++++ .../src/main/resources/skills/combat.yml | 3 +++ 2 files changed, 18 insertions(+) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/skills/skills/SkillCombat.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/skills/skills/SkillCombat.kt index 6b0b94d..2997d39 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/skills/skills/SkillCombat.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/skills/skills/SkillCombat.kt @@ -7,8 +7,11 @@ import com.willfp.ecoskills.skills.Skill import com.willfp.ecoskills.tryAsPlayer import org.bukkit.GameMode import org.bukkit.attribute.Attribute +import org.bukkit.entity.Monster import org.bukkit.event.EventHandler import org.bukkit.event.EventPriority +import org.bukkit.event.entity.CreatureSpawnEvent +import org.bukkit.metadata.FixedMetadataValue class SkillCombat : Skill( "combat" @@ -29,7 +32,19 @@ class SkillCombat : Skill( return } + if (this.config.getBool("skills.prevent-levelling-from-spawners") && event.victim.hasMetadata("ecoIsSpawner")) { + return + } + val xp = event.victim.getAttribute(Attribute.GENERIC_MAX_HEALTH)!!.value * this.config.getDouble("xp-per-heart") player.giveSkillExperience(this, xp) } + + @EventHandler + fun onSpawn(event: CreatureSpawnEvent) { + if (event.spawnReason == CreatureSpawnEvent.SpawnReason.SPAWNER) { + event.entity.setMetadata("ecoIsSpawner", FixedMetadataValue(this.plugin, true)) + } + } + } \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/resources/skills/combat.yml b/eco-core/core-plugin/src/main/resources/skills/combat.yml index 8456ae5..85099a5 100644 --- a/eco-core/core-plugin/src/main/resources/skills/combat.yml +++ b/eco-core/core-plugin/src/main/resources/skills/combat.yml @@ -3,6 +3,9 @@ description: "Kill mobs to earn Combat XP" max-level: 50 disabled-in-worlds: [] +# Prevent gaining xp killing mobs from spawners +prevent-levelling-from-spawners: true + gui: item: 'player_head texture:eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZGVlYmI4YjAzY2QyN2QzNDM1ZTExNTYxNmI4ZWQzNWRjYjQyN2FmNWIwYjFjYzUyNmQzMjY1YTcyZDQ5M2UifX19' position: