From b51b2a656a9e3ec952ebda15db4930b055d14578 Mon Sep 17 00:00:00 2001 From: DoctaEnkoda Date: Wed, 1 Sep 2021 19:03:46 +0200 Subject: [PATCH] Add Integration IridiumSkyblock 3.x --- pom.xml | 9 + .../integration/IntegrationHelper.java | 2 + .../IridiumSkyblockIntegration.java | 164 ++++++++++++++++++ 3 files changed, 175 insertions(+) create mode 100644 src/main/java/org/maxgamer/quickshop/integration/iridiumskyblock/IridiumSkyblockIntegration.java diff --git a/pom.xml b/pom.xml index 7e7ee8999..e7f0e7466 100644 --- a/pom.xml +++ b/pom.xml @@ -412,6 +412,10 @@ enginehub-repo https://maven.enginehub.org/repo/ + + savagelabs + https://nexus.savagelabs.net/repository/maven-releases/ + @@ -944,5 +948,10 @@ 3.3.5 provided + + com.iridium + IridiumSkyblock + 3.0.8 + diff --git a/src/main/java/org/maxgamer/quickshop/integration/IntegrationHelper.java b/src/main/java/org/maxgamer/quickshop/integration/IntegrationHelper.java index b31106de8..5d6346582 100644 --- a/src/main/java/org/maxgamer/quickshop/integration/IntegrationHelper.java +++ b/src/main/java/org/maxgamer/quickshop/integration/IntegrationHelper.java @@ -28,6 +28,7 @@ import org.maxgamer.quickshop.QuickShop; import org.maxgamer.quickshop.integration.advancedregionmarket.AdvancedShopRegionMarketIntegration; import org.maxgamer.quickshop.integration.factionsuuid.FactionsUUIDIntegration; import org.maxgamer.quickshop.integration.griefprevention.GriefPreventionIntegration; +import org.maxgamer.quickshop.integration.iridiumskyblock.IridiumSkyblockIntegration; import org.maxgamer.quickshop.integration.lands.LandsIntegration; import org.maxgamer.quickshop.integration.plotsquared.PlotSquaredIntegrationProxy; import org.maxgamer.quickshop.integration.residence.ResidenceIntegration; @@ -56,6 +57,7 @@ public class IntegrationHelper extends QuickShopInstanceHolder { integratedPluginNameMap.put("Towny", TownyIntegration.class); integratedPluginNameMap.put("WorldGuard", WorldGuardIntegration.class); //integratedPluginNameMap.put("FabledSkyblock", FabledIntegration.class); + integratedPluginNameMap.put("IridiumSkyblock", IridiumSkyblockIntegration.class); integratedPluginNameMap.put("SuperiorSkyblock", SuperiorSkyblock2Integration.class); integratedPluginNameMap.put("AdvancedRegionMarket", AdvancedShopRegionMarketIntegration.class); } diff --git a/src/main/java/org/maxgamer/quickshop/integration/iridiumskyblock/IridiumSkyblockIntegration.java b/src/main/java/org/maxgamer/quickshop/integration/iridiumskyblock/IridiumSkyblockIntegration.java new file mode 100644 index 000000000..d48eeb873 --- /dev/null +++ b/src/main/java/org/maxgamer/quickshop/integration/iridiumskyblock/IridiumSkyblockIntegration.java @@ -0,0 +1,164 @@ +/* + * This file is a part of project QuickShop, the name is IridiumSkyblockIntegration.java + * Copyright (C) PotatoCraft Studio and contributors + * + * 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 + * (at your option) 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 org.maxgamer.quickshop.integration.iridiumskyblock; + +import com.iridium.iridiumskyblock.api.IridiumSkyblockAPI; +import com.iridium.iridiumskyblock.api.IslandDeleteEvent; +import com.iridium.iridiumskyblock.api.IslandRegenEvent; +import com.iridium.iridiumskyblock.api.UserKickEvent; +import com.iridium.iridiumskyblock.database.Island; +import com.iridium.iridiumskyblock.database.User; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.jetbrains.annotations.NotNull; +import org.maxgamer.quickshop.QuickShop; +import org.maxgamer.quickshop.integration.IntegrateStage; +import org.maxgamer.quickshop.integration.IntegrationStage; +import org.maxgamer.quickshop.integration.QSIntegratedPlugin; +import org.maxgamer.quickshop.shop.Shop; + +import java.util.List; +import java.util.Optional; + +@IntegrationStage(loadStage = IntegrateStage.onEnableAfter) +public class IridiumSkyblockIntegration extends QSIntegratedPlugin implements Listener { + + private final boolean onlyOwnerCanCreateShop; + + public IridiumSkyblockIntegration(QuickShop plugin) { + super(plugin); + onlyOwnerCanCreateShop = plugin.getConfig().getBoolean("integration.iridiumskyblock.owner-create-only"); + } + + /** + * Return the integrated plugin name. + * For example, Residence + * + * @return integrated plugin + */ + @Override + public @NotNull String getName() { + return "IridiumSkyblock"; + } + + /** + * Check if a player can create shop here + * + * @param player the player want to create shop + * @param location shop location + * @return If you can create shop here + */ + @Override + public boolean canCreateShopHere(@NotNull Player player, @NotNull Location location) { + if (!IridiumSkyblockAPI.getInstance().isIslandWorld(location.getWorld())) return false; + Optional island = IridiumSkyblockAPI.getInstance().getIslandViaLocation(location); + if (!island.isPresent()) { + return false; + } + if (onlyOwnerCanCreateShop) { + return island.get().getOwner().getUuid().equals(player.getUniqueId()); + } else { + if (island.get().getOwner().getUuid().equals(player.getUniqueId())) { + return true; + } + return island.get().getMembers().stream().anyMatch(users -> users.getUuid().equals(player.getUniqueId())); + } + + } + + /** + * Check if a player can trade with shop here + * + * @param player the player want to trade with shop + * @param location shop location + * @return If you can trade with shop here + */ + @Override + public boolean canTradeShopHere(@NotNull Player player, @NotNull Location location) { + return true; + } + + /** + * Loading logic + * Execute Stage defined by IntegrationStage + */ + @Override + public void load() { + if (plugin.getConfig().getBoolean("integration.iridiumskyblock.delete-shop-on-member-leave")) { + Bukkit.getPluginManager().registerEvents(this, plugin); + } + } + + /** + * Unloding logic + * Will execute when Quickshop unloading + */ + @Override + public void unload() { + IslandDeleteEvent.getHandlerList().unregister(this); + IslandRegenEvent.getHandlerList().unregister(this); + UserKickEvent.getHandlerList().unregister(this); + } + + @EventHandler + public void deleteShopsWhenIslandDelete(IslandDeleteEvent event) { + Island island = event.getIsland(); + List members = event.getIsland().getMembers(); + for (Shop shop : plugin.getShopManager().getAllShops()) { + if (!island.isInIsland(shop.getLocation())) continue; + for (User user : members) { + if (shop.getOwner().equals(user.getUuid())) { + plugin.log(String.format("[%s Integration]Shop %s deleted caused by ShopOwnerQuitFromIsland", this.getName(), shop)); + shop.delete(); + } + } + } + } + + @EventHandler + public void deleteShopsWhenIslandDelete(IslandRegenEvent event) { + Island island = event.getIsland(); + List members = event.getIsland().getMembers(); + for (Shop shop : plugin.getShopManager().getAllShops()) { + if (!island.isInIsland(shop.getLocation())) continue; + for (User user : members) { + if (shop.getOwner().equals(user.getUuid())) { + plugin.log(String.format("[%s Integration]Shop %s deleted caused by ShopOwnerQuitFromIsland", this.getName(), shop)); + shop.delete(); + } + } + } + } + + @EventHandler + public void deleteShopWhenMemberKicked(UserKickEvent event) { + Island island = event.getIsland(); + for (Shop shop: plugin.getShopManager().getPlayerAllShops(event.getUser().getUuid())) { + if (!island.isInIsland(shop.getLocation())) continue; + plugin.log(String.format("[%s Integration]Shop %s deleted caused by ShopOwnerQuitFromIsland", this.getName(), shop)); + shop.delete(); + } + } + +}