From 864be74a74e0da814a026b297709229a226ec417 Mon Sep 17 00:00:00 2001 From: Sefiraat Date: Fri, 19 Jul 2024 15:20:41 +0100 Subject: [PATCH] Support WildStacker and RoseStacker --- pom.xml | 16 ++++++ .../managers/SupportedPluginManager.java | 52 +++++++++++++++++++ .../slimefun/network/NetworkVacuum.java | 12 ++++- src/main/resources/plugin.yml | 2 + 4 files changed, 80 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 17f5b9863..204040e4e 100644 --- a/pom.xml +++ b/pom.xml @@ -135,6 +135,10 @@ bg-repo https://repo.bg-software.com/repository/api/ + + rosewood-repo + https://repo.rosewooddev.io/repository/public/ + @@ -214,6 +218,18 @@ 2.2.017 provided + + com.bgsoftware + WildStackerAPI + 2023.2 + provided + + + dev.rosewood + rosestacker + 1.5.23 + provided + diff --git a/src/main/java/io/github/sefiraat/networks/managers/SupportedPluginManager.java b/src/main/java/io/github/sefiraat/networks/managers/SupportedPluginManager.java index 21690e291..7a07fb647 100644 --- a/src/main/java/io/github/sefiraat/networks/managers/SupportedPluginManager.java +++ b/src/main/java/io/github/sefiraat/networks/managers/SupportedPluginManager.java @@ -1,8 +1,13 @@ package io.github.sefiraat.networks.managers; +import com.bgsoftware.wildstacker.api.WildStackerAPI; import com.google.common.base.Preconditions; import io.github.sefiraat.networks.Networks; import org.bukkit.Bukkit; +import org.bukkit.entity.Item; + +import dev.rosewood.rosestacker.api.RoseStackerAPI; +import dev.rosewood.rosestacker.stack.StackedItem; public class SupportedPluginManager { @@ -11,6 +16,10 @@ public class SupportedPluginManager { private final boolean infinityExpansion; private final boolean netheopoiesis; private final boolean slimeHud; + private final boolean roseStacker; + private final boolean wildStacker; + + private RoseStackerAPI roseStackerAPI; // region First Tick Only Registrations private boolean mcMMO; @@ -24,6 +33,13 @@ public SupportedPluginManager() { this.infinityExpansion = Bukkit.getPluginManager().isPluginEnabled("InfinityExpansion"); this.netheopoiesis = Bukkit.getPluginManager().isPluginEnabled("Netheopoiesis"); this.slimeHud = Bukkit.getPluginManager().isPluginEnabled("SlimeHUD"); + + this.roseStacker = Bukkit.getPluginManager().isPluginEnabled("RoseStacker"); + if (roseStacker) { + this.roseStackerAPI = RoseStackerAPI.getInstance(); + } + + this.wildStacker = Bukkit.getPluginManager().isPluginEnabled("WildStacker"); Networks.getInstance() .getServer() .getScheduler() @@ -55,7 +71,43 @@ public boolean isWildChests() { return wildChests; } + public boolean isRoseStacker() { + return roseStacker; + } + + public RoseStackerAPI getRoseStackerAPI() { + return roseStackerAPI; + } + + public boolean isWildStacker() { + return wildStacker; + } + public static SupportedPluginManager getInstance() { return instance; } + + public static int getStackAmount(Item item) { + if (getInstance().isWildStacker()) { + return WildStackerAPI.getItemAmount(item); + } else if (getInstance().isRoseStacker()) { + StackedItem stackedItem = getInstance().getRoseStackerAPI().getStackedItem(item); + return stackedItem == null ? item.getItemStack().getAmount() : stackedItem.getStackSize(); + } else { + return item.getItemStack().getAmount(); + } + } + + public static void setStackAmount(Item item, int amount) { + if (getInstance().isWildStacker()) { + WildStackerAPI.getStackedItem(item).setStackAmount(amount, true); + } else if (getInstance().isRoseStacker()) { + StackedItem stackedItem = getInstance().getRoseStackerAPI().getStackedItem(item); + if (stackedItem != null) { + stackedItem.setStackSize(amount); + } + } else { + item.getItemStack().setAmount(amount); + } + } } diff --git a/src/main/java/io/github/sefiraat/networks/slimefun/network/NetworkVacuum.java b/src/main/java/io/github/sefiraat/networks/slimefun/network/NetworkVacuum.java index f201caf5d..8f21475af 100644 --- a/src/main/java/io/github/sefiraat/networks/slimefun/network/NetworkVacuum.java +++ b/src/main/java/io/github/sefiraat/networks/slimefun/network/NetworkVacuum.java @@ -3,6 +3,7 @@ import dev.sefiraat.sefilib.misc.ParticleUtils; import io.github.sefiraat.networks.NetworkStorage; import io.github.sefiraat.networks.Networks; +import io.github.sefiraat.networks.managers.SupportedPluginManager; import io.github.sefiraat.networks.network.NodeDefinition; import io.github.sefiraat.networks.network.NodeType; import io.github.sefiraat.networks.slimefun.NetworkSlimefunItems; @@ -95,10 +96,17 @@ private void findItem(@Nonnull BlockMenu blockMenu) { return; } if (item.getPickupDelay() <= 0 && !SlimefunUtils.hasNoPickupFlag(item)) { - final ItemStack itemStack = item.getItemStack(); + final ItemStack itemStack = item.getItemStack().clone(); + final int amount = SupportedPluginManager.getStackAmount(item); + if (amount > itemStack.getMaxStackSize()) { + SupportedPluginManager.setStackAmount(item, amount - itemStack.getMaxStackSize()); + itemStack.setAmount(itemStack.getMaxStackSize()); + } else { + itemStack.setAmount(amount); + item.remove(); + } blockMenu.replaceExistingItem(inputSlot, itemStack); ParticleUtils.displayParticleRandomly(item, 1, 5, new Particle.DustOptions(Color.BLUE, 1)); - item.remove(); } return; } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 3faa1fa33..e72d7ad43 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -12,6 +12,8 @@ softdepend: - Netheopoiesis - SlimeHUD - WildChests + - RoseStacker + - WildStacker commands: networks: description: /networks