From 63ee83c795cf72b20f15bee0cd83a880acf6a9b0 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Mon, 1 Nov 2021 15:50:10 +0000 Subject: [PATCH] Added Essentials / CMI AFK integrations --- .../eco/core/integrations/afk/AFKManager.java | 44 +++++++++++++++++++ .../eco/core/integrations/afk/AFKWrapper.java | 18 ++++++++ eco-core/core-plugin/build.gradle | 1 + .../com/willfp/eco/spigot/EcoSpigotPlugin.kt | 7 +++ .../integrations/afk/AFKIntegrationCMI.kt | 15 +++++++ .../afk/AFKIntegrationEssentials.kt | 18 ++++++++ .../core-plugin/src/main/resources/plugin.yml | 1 + 7 files changed, 104 insertions(+) create mode 100644 eco-api/src/main/java/com/willfp/eco/core/integrations/afk/AFKManager.java create mode 100644 eco-api/src/main/java/com/willfp/eco/core/integrations/afk/AFKWrapper.java create mode 100644 eco-core/core-plugin/src/main/kotlin/com/willfp/eco/spigot/integrations/afk/AFKIntegrationCMI.kt create mode 100644 eco-core/core-plugin/src/main/kotlin/com/willfp/eco/spigot/integrations/afk/AFKIntegrationEssentials.kt diff --git a/eco-api/src/main/java/com/willfp/eco/core/integrations/afk/AFKManager.java b/eco-api/src/main/java/com/willfp/eco/core/integrations/afk/AFKManager.java new file mode 100644 index 00000000..4c5309b9 --- /dev/null +++ b/eco-api/src/main/java/com/willfp/eco/core/integrations/afk/AFKManager.java @@ -0,0 +1,44 @@ +package com.willfp.eco.core.integrations.afk; + +import lombok.experimental.UtilityClass; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +import java.util.HashSet; +import java.util.Set; + +/** + * Class to handle afk integrations. + */ +@UtilityClass +public class AFKManager { + /** + * A set of all registered integrations. + */ + private final Set registered = new HashSet<>(); + + /** + * Register a new integration. + * + * @param integration The integration to register. + */ + public void register(@NotNull final AFKWrapper integration) { + registered.add(integration); + } + + /** + * Get if a player is afk. + * + * @param player The player. + * @return If afk. + */ + public boolean isAfk(@NotNull final Player player) { + for (AFKWrapper afkWrapper : registered) { + if (afkWrapper.isAfk(player)) { + return true; + } + } + + return false; + } +} diff --git a/eco-api/src/main/java/com/willfp/eco/core/integrations/afk/AFKWrapper.java b/eco-api/src/main/java/com/willfp/eco/core/integrations/afk/AFKWrapper.java new file mode 100644 index 00000000..f3e9f6b1 --- /dev/null +++ b/eco-api/src/main/java/com/willfp/eco/core/integrations/afk/AFKWrapper.java @@ -0,0 +1,18 @@ +package com.willfp.eco.core.integrations.afk; + +import com.willfp.eco.core.integrations.Integration; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +/** + * Wrapper class for afk integrations. + */ +public interface AFKWrapper extends Integration { + /** + * Get if a player is afk. + * + * @param player The player. + * @return If afk. + */ + boolean isAfk(@NotNull final Player player); +} diff --git a/eco-core/core-plugin/build.gradle b/eco-core/core-plugin/build.gradle index 41995681..88007f86 100644 --- a/eco-core/core-plugin/build.gradle +++ b/eco-core/core-plugin/build.gradle @@ -35,6 +35,7 @@ dependencies { compileOnly 'org.jetbrains.exposed:exposed-jdbc:0.35.1' compileOnly 'mysql:mysql-connector-java:8.0.25' compileOnly 'com.gmail.filoghost.holographicdisplays:holographicdisplays-api:2.4.0' + compileOnly 'net.essentialsx:EssentialsX:2.19.0' // CombatLogX V10 + NewbieHelper Expansion compileOnly 'com.SirBlobman.combatlogx:CombatLogX-API:10.0.0.0-SNAPSHOT' diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/spigot/EcoSpigotPlugin.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/spigot/EcoSpigotPlugin.kt index eb7ba051..09761279 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/spigot/EcoSpigotPlugin.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/spigot/EcoSpigotPlugin.kt @@ -6,6 +6,7 @@ import com.willfp.eco.core.EcoPlugin import com.willfp.eco.core.Prerequisite import com.willfp.eco.core.display.Display import com.willfp.eco.core.integrations.IntegrationLoader +import com.willfp.eco.core.integrations.afk.AFKManager import com.willfp.eco.core.integrations.anticheat.AnticheatManager import com.willfp.eco.core.integrations.antigrief.AntigriefManager import com.willfp.eco.core.integrations.customitems.CustomItemsManager @@ -35,6 +36,8 @@ import com.willfp.eco.spigot.eventlisteners.PlayerJumpListeners import com.willfp.eco.spigot.eventlisteners.armor.ArmorChangeEventListeners import com.willfp.eco.spigot.eventlisteners.armor.ArmorListener import com.willfp.eco.spigot.gui.GUIListener +import com.willfp.eco.spigot.integrations.afk.AFKIntegrationCMI +import com.willfp.eco.spigot.integrations.afk.AFKIntegrationEssentials import com.willfp.eco.spigot.integrations.anticheat.* import com.willfp.eco.spigot.integrations.antigrief.* import com.willfp.eco.spigot.integrations.customitems.CustomItemsHeadDatabase @@ -184,6 +187,10 @@ abstract class EcoSpigotPlugin : EcoPlugin( IntegrationLoader("CMI") { HologramManager.register(HologramCMI()) }, IntegrationLoader("GHolo") { HologramManager.register(HologramGHolo()) }, + // AFK + IntegrationLoader("Essentials") { AFKManager.register(AFKIntegrationEssentials()) }, + IntegrationLoader("CMI") { AFKManager.register(AFKIntegrationCMI()) }, + // Misc IntegrationLoader("mcMMO") { McmmoManager.register(McmmoIntegrationImpl()) }, IntegrationLoader("Multiverse-Inventories") { diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/spigot/integrations/afk/AFKIntegrationCMI.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/spigot/integrations/afk/AFKIntegrationCMI.kt new file mode 100644 index 00000000..b6e8cf18 --- /dev/null +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/spigot/integrations/afk/AFKIntegrationCMI.kt @@ -0,0 +1,15 @@ +package com.willfp.eco.spigot.integrations.afk + +import com.Zrips.CMI.CMI +import com.willfp.eco.core.integrations.afk.AFKWrapper +import org.bukkit.entity.Player + +class AFKIntegrationCMI : AFKWrapper { + override fun isAfk(player: Player): Boolean { + return CMI.getInstance().playerManager.getUser(player)?.isAfk ?: false + } + + override fun getPluginName(): String { + return "CMI" + } +} diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/spigot/integrations/afk/AFKIntegrationEssentials.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/spigot/integrations/afk/AFKIntegrationEssentials.kt new file mode 100644 index 00000000..c2c13e2c --- /dev/null +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/spigot/integrations/afk/AFKIntegrationEssentials.kt @@ -0,0 +1,18 @@ +package com.willfp.eco.spigot.integrations.afk + +import com.earth2me.essentials.Essentials +import com.willfp.eco.core.integrations.afk.AFKWrapper +import org.bukkit.entity.Player +import org.bukkit.plugin.java.JavaPlugin + +class AFKIntegrationEssentials : AFKWrapper { + private val ess = 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" + } +} diff --git a/eco-core/core-plugin/src/main/resources/plugin.yml b/eco-core/core-plugin/src/main/resources/plugin.yml index 6a500cf6..90e515e7 100644 --- a/eco-core/core-plugin/src/main/resources/plugin.yml +++ b/eco-core/core-plugin/src/main/resources/plugin.yml @@ -30,6 +30,7 @@ softdepend: - HolographicDisplays - GHolo - CMI + - Essentials libraries: - 'org.reflections:reflections:0.9.12' - 'org.apache.maven:maven-artifact:3.0.3'