From 0bedc5d8ca3bb4e80211f33d6cd6f51f96e7f9bf Mon Sep 17 00:00:00 2001 From: XiaoMoMi Date: Mon, 16 Dec 2024 03:42:13 +0800 Subject: [PATCH] ShopGUI --- compatibility/build.gradle.kts | 1 + .../shop/ShopGUICFItemProvider.java | 63 +++++++++++++++++++ .../bukkit/integration/shop/ShopGUIHook.java | 28 +++++++++ .../integration/BukkitIntegrationManager.java | 5 ++ core/src/main/resources/plugin.yml | 1 + 5 files changed, 98 insertions(+) create mode 100644 compatibility/src/main/java/net/momirealms/customfishing/bukkit/integration/shop/ShopGUICFItemProvider.java create mode 100644 compatibility/src/main/java/net/momirealms/customfishing/bukkit/integration/shop/ShopGUIHook.java diff --git a/compatibility/build.gradle.kts b/compatibility/build.gradle.kts index 8fcf3aac..deff0b08 100644 --- a/compatibility/build.gradle.kts +++ b/compatibility/build.gradle.kts @@ -58,6 +58,7 @@ dependencies { compileOnly("io.lumine:MythicLib-dist:1.6.2-SNAPSHOT") compileOnly("pers.neige.neigeitems:NeigeItems:1.17.13") compileOnly("io.th0rgal:oraxen:1.168.0") + compileOnly("com.github.brcdev-minecraft:shopgui-api:3.0.0") // entity compileOnly("io.lumine:Mythic-Dist:5.6.2") // eco diff --git a/compatibility/src/main/java/net/momirealms/customfishing/bukkit/integration/shop/ShopGUICFItemProvider.java b/compatibility/src/main/java/net/momirealms/customfishing/bukkit/integration/shop/ShopGUICFItemProvider.java new file mode 100644 index 00000000..a5093e81 --- /dev/null +++ b/compatibility/src/main/java/net/momirealms/customfishing/bukkit/integration/shop/ShopGUICFItemProvider.java @@ -0,0 +1,63 @@ +/* + * Copyright (C) <2024> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.momirealms.customfishing.bukkit.integration.shop; + +import net.brcdev.shopgui.ShopGuiPlusApi; +import net.brcdev.shopgui.event.ShopGUIPlusPostEnableEvent; +import net.brcdev.shopgui.provider.item.ItemProvider; +import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; +import net.momirealms.customfishing.api.mechanic.context.Context; +import net.momirealms.customfishing.api.mechanic.context.ContextKeys; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.inventory.ItemStack; + +import java.util.Objects; + +public class ShopGUICFItemProvider extends ItemProvider implements Listener { + + private final BukkitCustomFishingPlugin plugin; + + public ShopGUICFItemProvider(BukkitCustomFishingPlugin plugin) { + super("CustomFishing"); + this.plugin = plugin; + } + + @Override + public boolean isValidItem(ItemStack itemStack) { + return plugin.getItemManager().getCustomFishingItemID(itemStack) != null; + } + + @Override + public ItemStack loadItem(ConfigurationSection configurationSection) { + String id = configurationSection.getString("customfishing"); + if (id == null) return null; + return plugin.getItemManager().buildInternal(Context.player(null).arg(ContextKeys.ID, id), id); + } + + @Override + public boolean compare(ItemStack i1, ItemStack i2) { + return Objects.equals(plugin.getItemManager().getCustomFishingItemID(i1), plugin.getItemManager().getCustomFishingItemID(i2)); + } + + @EventHandler + public void onShopGUIPlusPostEnable(ShopGUIPlusPostEnableEvent event) { + ShopGuiPlusApi.registerItemProvider(this); + } +} diff --git a/compatibility/src/main/java/net/momirealms/customfishing/bukkit/integration/shop/ShopGUIHook.java b/compatibility/src/main/java/net/momirealms/customfishing/bukkit/integration/shop/ShopGUIHook.java new file mode 100644 index 00000000..374317f9 --- /dev/null +++ b/compatibility/src/main/java/net/momirealms/customfishing/bukkit/integration/shop/ShopGUIHook.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) <2024> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.momirealms.customfishing.bukkit.integration.shop; + +import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; +import org.bukkit.Bukkit; + +public class ShopGUIHook { + + public static void register() { + Bukkit.getPluginManager().registerEvents(new ShopGUICFItemProvider(BukkitCustomFishingPlugin.getInstance()), BukkitCustomFishingPlugin.getInstance().getBootstrap()); + } +} diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/integration/BukkitIntegrationManager.java b/core/src/main/java/net/momirealms/customfishing/bukkit/integration/BukkitIntegrationManager.java index d553e124..468a8943 100644 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/integration/BukkitIntegrationManager.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/integration/BukkitIntegrationManager.java @@ -39,6 +39,8 @@ import net.momirealms.customfishing.bukkit.integration.region.WorldGuardRegion; import net.momirealms.customfishing.bukkit.integration.season.AdvancedSeasonsProvider; import net.momirealms.customfishing.bukkit.integration.season.CustomCropsSeasonProvider; import net.momirealms.customfishing.bukkit.integration.season.RealisticSeasonsProvider; +import net.momirealms.customfishing.bukkit.integration.shop.ShopGUICFItemProvider; +import net.momirealms.customfishing.bukkit.integration.shop.ShopGUIHook; import net.momirealms.customfishing.bukkit.item.BukkitItemManager; import net.momirealms.customfishing.common.util.Pair; import org.bukkit.Bukkit; @@ -179,6 +181,9 @@ public class BukkitIntegrationManager implements IntegrationManager { new CompetitionPapi(plugin).load(); new StatisticsPapi(plugin).load(); } + if (isHooked("ShopGUIPlus")) { + ShopGUIHook.register(); + } } private boolean isHooked(String hooked) { diff --git a/core/src/main/resources/plugin.yml b/core/src/main/resources/plugin.yml index 082b2a96..04130654 100644 --- a/core/src/main/resources/plugin.yml +++ b/core/src/main/resources/plugin.yml @@ -25,6 +25,7 @@ softdepend: - EcoJobs - Zaphkiel - WorldGuard + - ShopGUIPlus permissions: fishingbag.user: default: true