From fbe88ab0fdbcdac824cc3b6b5fd5c602cb3151f6 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Thu, 6 Jan 2022 14:31:02 +0000 Subject: [PATCH] Added MythicMobs integration --- build.gradle.kts | 3 ++ .../customentities/CustomEntitiesManager.java | 40 +++++++++++++++++++ .../customentities/CustomEntitiesWrapper.java | 15 +++++++ eco-core/core-plugin/build.gradle | 1 + .../eco/internal/spigot/EcoSpigotPlugin.kt | 6 +++ .../CustomEntitiesMythicMobs.kt | 30 ++++++++++++++ 6 files changed, 95 insertions(+) create mode 100644 eco-api/src/main/java/com/willfp/eco/core/integrations/customentities/CustomEntitiesManager.java create mode 100644 eco-api/src/main/java/com/willfp/eco/core/integrations/customentities/CustomEntitiesWrapper.java create mode 100644 eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/integrations/customentities/CustomEntitiesMythicMobs.kt diff --git a/build.gradle.kts b/build.gradle.kts index caef7709..1514de08 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -61,6 +61,9 @@ allprojects { // IridiumSkyblock maven("https://nexus.iridiumdevelopment.net/repository/maven-releases/") + + // MythicMobs + maven("https://mvn.lumine.io/repository/maven-public/") } dependencies { diff --git a/eco-api/src/main/java/com/willfp/eco/core/integrations/customentities/CustomEntitiesManager.java b/eco-api/src/main/java/com/willfp/eco/core/integrations/customentities/CustomEntitiesManager.java new file mode 100644 index 00000000..a36d424a --- /dev/null +++ b/eco-api/src/main/java/com/willfp/eco/core/integrations/customentities/CustomEntitiesManager.java @@ -0,0 +1,40 @@ +package com.willfp.eco.core.integrations.customentities; + +import org.jetbrains.annotations.NotNull; + +import java.util.HashSet; +import java.util.Set; + +/** + * Class to handle custom entity integrations. + */ +public final class CustomEntitiesManager { + /** + * A set of all registered integrations. + */ + private static final Set REGISTERED = new HashSet<>(); + + /** + * Register a new integration. + * + * @param integration The integration to register. + */ + public static void register(@NotNull final CustomEntitiesWrapper integration) { + REGISTERED.add(integration); + } + + /** + * Register all the custom entities for a specific plugin into eco. + * + * @see com.willfp.eco.core.entities.Entities + */ + public static void registerAllEntities() { + for (CustomEntitiesWrapper wrapper : REGISTERED) { + wrapper.registerAllEntities(); + } + } + + private CustomEntitiesManager() { + throw new UnsupportedOperationException("This is a utility class and cannot be instantiated"); + } +} diff --git a/eco-api/src/main/java/com/willfp/eco/core/integrations/customentities/CustomEntitiesWrapper.java b/eco-api/src/main/java/com/willfp/eco/core/integrations/customentities/CustomEntitiesWrapper.java new file mode 100644 index 00000000..6d76e35c --- /dev/null +++ b/eco-api/src/main/java/com/willfp/eco/core/integrations/customentities/CustomEntitiesWrapper.java @@ -0,0 +1,15 @@ +package com.willfp.eco.core.integrations.customentities; + +import com.willfp.eco.core.integrations.Integration; + +/** + * Wrapper class for custom item integrations. + */ +public interface CustomEntitiesWrapper extends Integration { + /** + * Register all the custom entities for a specific plugin into eco. + * + * @see com.willfp.eco.core.entities.Entities + */ + void registerAllEntities(); +} diff --git a/eco-core/core-plugin/build.gradle b/eco-core/core-plugin/build.gradle index 622a20a1..e226aed1 100644 --- a/eco-core/core-plugin/build.gradle +++ b/eco-core/core-plugin/build.gradle @@ -43,6 +43,7 @@ dependencies { compileOnly 'com.github.WhipDevelopment:CrashClaim:f9cd7d92eb' compileOnly 'com.wolfyscript.wolfyutilities:wolfyutilities:1.7.8.1' compileOnly 'com.github.decentsoftware-eu:decentholograms:2.1.2' + compileOnly 'io.lumine.xikage:MythicMobs:4.9.1' // 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/internal/spigot/EcoSpigotPlugin.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/EcoSpigotPlugin.kt index 21d2e84f..f0a8baf1 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/EcoSpigotPlugin.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/EcoSpigotPlugin.kt @@ -10,6 +10,7 @@ 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.customentities.CustomEntitiesManager import com.willfp.eco.core.integrations.customitems.CustomItemsManager import com.willfp.eco.core.integrations.economy.EconomyManager import com.willfp.eco.core.integrations.hologram.HologramManager @@ -83,6 +84,7 @@ import com.willfp.eco.internal.spigot.integrations.antigrief.AntigriefLands import com.willfp.eco.internal.spigot.integrations.antigrief.AntigriefSuperiorSkyblock2 import com.willfp.eco.internal.spigot.integrations.antigrief.AntigriefTowny import com.willfp.eco.internal.spigot.integrations.antigrief.AntigriefWorldGuard +import com.willfp.eco.internal.spigot.integrations.customentities.CustomEntitiesMythicMobs import com.willfp.eco.internal.spigot.integrations.customitems.CustomItemsHeadDatabase import com.willfp.eco.internal.spigot.integrations.customitems.CustomItemsItemsAdder import com.willfp.eco.internal.spigot.integrations.customitems.CustomItemsOraxen @@ -194,6 +196,7 @@ abstract class EcoSpigotPlugin : EcoPlugin( override fun handleAfterLoad() { CustomItemsManager.registerAllItems() + CustomEntitiesManager.registerAllEntities() ShopManager.registerEcoProvider() } @@ -231,6 +234,9 @@ abstract class EcoSpigotPlugin : EcoPlugin( IntegrationLoader("Vulcan") { AnticheatManager.register(this, AnticheatVulcan()) }, IntegrationLoader("Alice") { AnticheatManager.register(this, AnticheatAlice()) }, + // Custom Entities + IntegrationLoader("MythicMobs") { CustomEntitiesManager.register(CustomEntitiesMythicMobs())}, + // Custom Items IntegrationLoader("Oraxen") { CustomItemsManager.register(CustomItemsOraxen()) }, IntegrationLoader("ItemsAdder") { CustomItemsManager.register(CustomItemsItemsAdder()) }, diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/integrations/customentities/CustomEntitiesMythicMobs.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/integrations/customentities/CustomEntitiesMythicMobs.kt new file mode 100644 index 00000000..a5bb6824 --- /dev/null +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/integrations/customentities/CustomEntitiesMythicMobs.kt @@ -0,0 +1,30 @@ +package com.willfp.eco.internal.spigot.integrations.customentities + +import com.willfp.eco.core.entities.CustomEntity +import com.willfp.eco.core.integrations.customentities.CustomEntitiesWrapper +import com.willfp.eco.util.NamespacedKeyUtils +import io.lumine.xikage.mythicmobs.MythicMobs + +class CustomEntitiesMythicMobs : CustomEntitiesWrapper { + override fun registerAllEntities() { + val mobManager = MythicMobs.inst().mobManager + + for (id in mobManager.mobNames) { + val key = NamespacedKeyUtils.create("mythicmobs", id.lowercase()) + CustomEntity( + key, + { + val entityId = mobManager.getMythicMobInstance(it)?.type?.entityType ?: return@CustomEntity false + entityId.equals(id, ignoreCase = true) + }, + { + MythicMobs.inst().apiHelper.spawnMythicMob(id, it) + } + ).register() + } + } + + override fun getPluginName(): String { + return "MythicMobs" + } +} \ No newline at end of file