9
0
mirror of https://github.com/Auxilor/EcoSkills.git synced 2026-01-04 15:41:36 +00:00

Added Essentials integration to prevent gaining experience while AFK

This commit is contained in:
Auxilor
2021-09-13 09:50:02 +01:00
parent 5b795a7023
commit 0fdb69611b
16 changed files with 101 additions and 2 deletions

View File

@@ -33,6 +33,7 @@ allprojects {
maven { url 'https://repo.codemc.org/repository/nms/' }
maven { url 'https://repo.codemc.io/repository/maven-public/' }
maven { url 'https://repo.dmulloy2.net/repository/public/' }
maven { url 'https://repo.essentialsx.net/releases/' }
}
jar {

View File

@@ -6,4 +6,5 @@ dependencies {
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'
compileOnly 'net.essentialsx:EssentialsX:2.19.0'
}

View File

@@ -0,0 +1,19 @@
package com.willfp.ecoskills.integrations.afk
import org.bukkit.entity.Player
private val registry = mutableSetOf<AFKIntegration>()
fun registerIntegration(integration: AFKIntegration) {
registry.add(integration)
}
val Player.isAfk: Boolean
get() {
for (afkIntegration in registry) {
if (afkIntegration.isAfk(this)) {
return true
}
}
return false
}

View File

@@ -0,0 +1,8 @@
package com.willfp.ecoskills.integrations.afk
import com.willfp.eco.core.integrations.Integration
import org.bukkit.entity.Player
interface AFKIntegration : Integration {
fun isAfk(player: Player): Boolean
}

View File

@@ -0,0 +1,18 @@
package com.willfp.ecoskills.integrations.afk.impl
import com.earth2me.essentials.Essentials
import com.willfp.ecoskills.integrations.afk.AFKIntegration
import org.bukkit.entity.Player
import org.bukkit.plugin.java.JavaPlugin
class AFKIntegrationEssentials: AFKIntegration {
private val ess: Essentials = JavaPlugin.getPlugin(Essentials::class.java)
override fun isAfk(player: Player): Boolean {
return ess.getUser(player) != null && ess.getUser(player).isAfk
}
override fun getPluginName(): String {
return "Essentials"
}
}

View File

@@ -1,6 +1,7 @@
package com.willfp.ecoskills.skills.skills
import com.willfp.ecoskills.giveSkillExperience
import com.willfp.ecoskills.integrations.afk.isAfk
import com.willfp.ecoskills.skills.Skill
import org.bukkit.GameMode
import org.bukkit.Material
@@ -45,6 +46,10 @@ class SkillAlchemy : Skill(
}
}
if (plugin.configYml.getBool("skills.prevent-levelling-while-afk") && player.isAfk) {
return
}
val type = event.contents.ingredient?.type ?: return
val toGive = rewards[type] ?: return

View File

@@ -1,6 +1,7 @@
package com.willfp.ecoskills.skills.skills
import com.willfp.ecoskills.giveSkillExperience
import com.willfp.ecoskills.integrations.afk.isAfk
import com.willfp.ecoskills.skills.Skill
import org.bukkit.GameMode
import org.bukkit.entity.Player
@@ -22,6 +23,10 @@ class SkillArmory : Skill(
return
}
if (plugin.configYml.getBool("skills.prevent-levelling-while-afk") && player.isAfk) {
return
}
val xp = event.damage * this.config.getDouble("xp-per-hp")
player.giveSkillExperience(this, xp)
}

View File

@@ -2,6 +2,7 @@ package com.willfp.ecoskills.skills.skills
import com.willfp.eco.core.events.EntityDeathByEntityEvent
import com.willfp.ecoskills.giveSkillExperience
import com.willfp.ecoskills.integrations.afk.isAfk
import com.willfp.ecoskills.skills.Skill
import com.willfp.ecoskills.tryAsPlayer
import org.bukkit.GameMode
@@ -20,6 +21,10 @@ class SkillCombat : Skill(
return
}
if (plugin.configYml.getBool("skills.prevent-levelling-while-afk") && player.isAfk) {
return
}
val xp = event.victim.getAttribute(Attribute.GENERIC_MAX_HEALTH)!!.value * this.config.getDouble("xp-per-heart")
player.giveSkillExperience(this, xp)
}

View File

@@ -1,6 +1,7 @@
package com.willfp.ecoskills.skills.skills
import com.willfp.ecoskills.giveSkillExperience
import com.willfp.ecoskills.integrations.afk.isAfk
import com.willfp.ecoskills.skills.Skill
import org.bukkit.GameMode
import org.bukkit.event.EventHandler
@@ -19,6 +20,10 @@ class SkillEnchanting : Skill(
return
}
if (plugin.configYml.getBool("skills.prevent-levelling-while-afk") && player.isAfk) {
return
}
val xp = cost * this.config.getDouble("xp-per-level")
player.giveSkillExperience(this, xp)
}

View File

@@ -2,6 +2,7 @@ package com.willfp.ecoskills.skills.skills
import com.willfp.eco.util.NumberUtils
import com.willfp.ecoskills.giveSkillExperience
import com.willfp.ecoskills.integrations.afk.isAfk
import com.willfp.ecoskills.skills.Skill
import org.bukkit.GameMode
import org.bukkit.entity.Player
@@ -34,6 +35,10 @@ class SkillExploration : Skill(
xp *= speed
}
if (plugin.configYml.getBool("skills.prevent-levelling-while-afk") && player.isAfk) {
return
}
if (NumberUtils.randFloat(0.0, 100.0) < this.config.getDouble("xp-on-move-chance")) {
player.giveSkillExperience(this, xp)
}
@@ -41,7 +46,9 @@ class SkillExploration : Skill(
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
fun handleLevelling(event: EntityDamageEvent) {
if (event.entity !is Player) {
val player = event.entity
if (player !is Player) {
return
}
@@ -49,7 +56,9 @@ class SkillExploration : Skill(
return
}
val player = event.entity as Player
if (plugin.configYml.getBool("skills.prevent-levelling-while-afk") && player.isAfk) {
return
}
val xp = this.config.getDouble("fall-damage-xp-per-hp") * event.finalDamage
player.giveSkillExperience(this, xp)

View File

@@ -1,6 +1,7 @@
package com.willfp.ecoskills.skills.skills
import com.willfp.ecoskills.giveSkillExperience
import com.willfp.ecoskills.integrations.afk.isAfk
import com.willfp.ecoskills.skills.Skill
import org.bukkit.GameMode
import org.bukkit.Material
@@ -37,6 +38,10 @@ class SkillFarming : Skill(
return
}
if (plugin.configYml.getBool("skills.prevent-levelling-while-afk") && player.isAfk) {
return
}
if (event.block.blockData is Ageable && event.block.type != Material.SUGAR_CANE) {
val data = event.block.blockData as Ageable
if (data.age < data.maximumAge) {

View File

@@ -1,6 +1,7 @@
package com.willfp.ecoskills.skills.skills
import com.willfp.ecoskills.giveSkillExperience
import com.willfp.ecoskills.integrations.afk.isAfk
import com.willfp.ecoskills.skills.Skill
import org.bukkit.GameMode
import org.bukkit.event.EventHandler
@@ -18,6 +19,10 @@ class SkillFishing : Skill(
return
}
if (plugin.configYml.getBool("skills.prevent-levelling-while-afk") && player.isAfk) {
return
}
val expToDrop = event.expToDrop
val xp = expToDrop * this.config.getDouble("xp-per-experience-dropped")

View File

@@ -2,6 +2,7 @@ package com.willfp.ecoskills.skills.skills
import com.willfp.ecoskills.data.isPlayerPlaced
import com.willfp.ecoskills.giveSkillExperience
import com.willfp.ecoskills.integrations.afk.isAfk
import com.willfp.ecoskills.skills.Skill
import org.bukkit.GameMode
import org.bukkit.Material
@@ -43,6 +44,10 @@ class SkillMining : Skill(
return
}
if (plugin.configYml.getBool("skills.prevent-levelling-while-afk") && player.isAfk) {
return
}
player.giveSkillExperience(this, toGive)
}
}

View File

@@ -2,6 +2,7 @@ package com.willfp.ecoskills.skills.skills
import com.willfp.ecoskills.data.isPlayerPlaced
import com.willfp.ecoskills.giveSkillExperience
import com.willfp.ecoskills.integrations.afk.isAfk
import com.willfp.ecoskills.skills.Skill
import org.bukkit.GameMode
import org.bukkit.Material
@@ -43,6 +44,10 @@ class SkillWoodcutting : Skill(
return
}
if (plugin.configYml.getBool("skills.prevent-levelling-while-afk") && player.isAfk) {
return
}
player.giveSkillExperience(this, toGive)
}
}

View File

@@ -228,6 +228,8 @@ skills:
- 3700000
- 4000000
prevent-levelling-while-afk: true # If the player is afk (Essentials) then don't give xp
# Ways to tell the player about skill progress
progress:
action-bar:

View File

@@ -10,6 +10,7 @@ depend:
- PlaceholderAPI
softdepend:
- HolographicDisplays
- Essentials
libraries:
- org.jetbrains.kotlin:kotlin-stdlib:1.5.21