From cb28726bc34a0fa1f111cd587178241fa4caf782 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Tue, 12 Oct 2021 12:04:52 +0100 Subject: [PATCH] Cleaned up Multiverse-Inventories integration --- .../com/willfp/eco/spigot/EcoSpigotPlugin.kt | 4 +- .../MultiverseInventoriesEvent.java | 40 ------------------- .../MultiverseInventoriesIntegration.kt | 21 ++++++++++ .../core-plugin/src/main/resources/plugin.yml | 1 + 4 files changed, 24 insertions(+), 42 deletions(-) delete mode 100644 eco-core/core-plugin/src/main/kotlin/com/willfp/eco/spigot/integrations/multiverseinventories/MultiverseInventoriesEvent.java create mode 100644 eco-core/core-plugin/src/main/kotlin/com/willfp/eco/spigot/integrations/multiverseinventories/MultiverseInventoriesIntegration.kt 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 13c9cae8..eb9ba56d 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 @@ -35,7 +35,7 @@ import com.willfp.eco.spigot.integrations.customitems.CustomItemsHeadDatabase import com.willfp.eco.spigot.integrations.customitems.CustomItemsItemsAdder import com.willfp.eco.spigot.integrations.customitems.CustomItemsOraxen import com.willfp.eco.spigot.integrations.mcmmo.McmmoIntegrationImpl -import com.willfp.eco.spigot.integrations.multiverseinventories.MultiverseInventoriesEvent +import com.willfp.eco.spigot.integrations.multiverseinventories.MultiverseInventoriesIntegration import com.willfp.eco.spigot.integrations.shop.ShopShopGuiPlus import com.willfp.eco.spigot.recipes.ShapedRecipeListener import com.willfp.eco.util.BlockUtils @@ -158,7 +158,7 @@ abstract class EcoSpigotPlugin : EcoPlugin( // Misc IntegrationLoader("mcMMO") { McmmoManager.register(McmmoIntegrationImpl()) }, - IntegrationLoader("Multiverse-Inventories") { this.eventManager.registerListener(MultiverseInventoriesEvent(this)) } + IntegrationLoader("Multiverse-Inventories") { this.eventManager.registerListener(MultiverseInventoriesIntegration(this)) } ) } diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/spigot/integrations/multiverseinventories/MultiverseInventoriesEvent.java b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/spigot/integrations/multiverseinventories/MultiverseInventoriesEvent.java deleted file mode 100644 index 7a799310..00000000 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/spigot/integrations/multiverseinventories/MultiverseInventoriesEvent.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.willfp.eco.spigot.integrations.multiverseinventories; - -import com.onarandombox.multiverseinventories.event.WorldChangeShareHandlingEvent; -import com.willfp.eco.core.EcoPlugin; -import com.willfp.eco.core.PluginDependent; -import com.willfp.eco.core.events.ArmorChangeEvent; -import org.bukkit.Bukkit; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -public class MultiverseInventoriesEvent extends PluginDependent implements Listener { - - /** - * Pass an {@link EcoPlugin} in order to interface with it. - * - * @param plugin The plugin to manage. - */ - public MultiverseInventoriesEvent(@NotNull EcoPlugin plugin) { - super(plugin); - } - - @EventHandler - public void onWorldChange(WorldChangeShareHandlingEvent event) { - List before = new ArrayList<>(Arrays.asList(event.getPlayer().getInventory().getArmorContents())); - - this.getPlugin().getScheduler().runLater(() -> { - List after = new ArrayList<>(Arrays.asList(event.getPlayer().getInventory().getArmorContents())); - - ArmorChangeEvent armorChangeEvent = new ArmorChangeEvent(event.getPlayer(), before, after); - Bukkit.getPluginManager().callEvent(armorChangeEvent); - }, 1); - } - -} diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/spigot/integrations/multiverseinventories/MultiverseInventoriesIntegration.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/spigot/integrations/multiverseinventories/MultiverseInventoriesIntegration.kt new file mode 100644 index 00000000..d6c4e0ee --- /dev/null +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/spigot/integrations/multiverseinventories/MultiverseInventoriesIntegration.kt @@ -0,0 +1,21 @@ +package com.willfp.eco.spigot.integrations.multiverseinventories + +import com.onarandombox.multiverseinventories.event.WorldChangeShareHandlingEvent +import com.willfp.eco.core.EcoPlugin +import com.willfp.eco.core.events.ArmorChangeEvent +import org.bukkit.Bukkit +import org.bukkit.event.EventHandler +import org.bukkit.event.Listener + +class MultiverseInventoriesIntegration( + private val plugin: EcoPlugin +): Listener { + @EventHandler + fun onWorldChange(event: WorldChangeShareHandlingEvent) { + val before = event.player.inventory.armorContents.toMutableList() + this.plugin.scheduler.run { + val after = event.player.inventory.armorContents.toMutableList() + Bukkit.getPluginManager().callEvent(ArmorChangeEvent(event.player, before, after)) + } + } +} \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/resources/plugin.yml b/eco-core/core-plugin/src/main/resources/plugin.yml index 39634b9b..e8b06228 100644 --- a/eco-core/core-plugin/src/main/resources/plugin.yml +++ b/eco-core/core-plugin/src/main/resources/plugin.yml @@ -25,6 +25,7 @@ softdepend: - ItemsAdder - Oraxen - HeadDatabase + - Multiverse-Inventories libraries: - 'org.reflections:reflections:0.9.12' - 'org.apache.maven:maven-artifact:3.0.3'