diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 11f628496..cd9f5b53a 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -15,11 +15,13 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Set up JDK 11 - uses: actions/setup-java@v2 - with: - java-version: '16' - distribution: 'adopt' - - name: Build with Maven - run: mvn -B compile --file pom.xml -Pdebug + - uses: actions/checkout@v2 + - name: Set up JDK 11 + uses: actions/setup-java@v2 + with: + java-version: '16' + distribution: 'adopt' + - name: Build Integration + run: mvn -B install --file src/integration/plotsquared/5/pom.xml + - name: Build with Maven + run: mvn -B compile --file pom.xml -Pdebug diff --git a/lib/PlotSquared-Bukkit.jar b/lib/PlotSquared4-Bukkit-4.4.jar similarity index 100% rename from lib/PlotSquared-Bukkit.jar rename to lib/PlotSquared4-Bukkit-4.4.jar diff --git a/lib/PlotSquared5-Core-5.13.11.jar b/lib/PlotSquared5-Core-5.13.11.jar new file mode 100644 index 000000000..f5d00bb80 Binary files /dev/null and b/lib/PlotSquared5-Core-5.13.11.jar differ diff --git a/pom.xml b/pom.xml index 6aa1d9c18..352b61ab3 100644 --- a/pom.xml +++ b/pom.xml @@ -272,7 +272,9 @@ ${project.basedir}/target/${artifactId}.jar ${project.basedir}/keystore.jks selfsigned + ${env.quickshop-signer-pwd} + ${env.quickshop-signer-pwd} @@ -684,17 +686,24 @@ - + + org.maxgamer.quickshop.integration + PlotSquared5 + 1.1 + + + * + * + + + + com.plotsquared PlotSquared-Core - 5.13.11 + 6.0.0-SNAPSHOT provided - - worldedit-core - com.sk89q.worldedit - snakeyaml org.yaml @@ -732,10 +741,10 @@ com.github.intellectualsite - PlotSquared + PlotSquared4 4 system - ${project.basedir}/lib/PlotSquared-Bukkit.jar + ${project.basedir}/lib/PlotSquared4-Bukkit-4.4.jar worldedit-core @@ -923,11 +932,5 @@ - - org.projectlombok - lombok - 1.18.20 - provided - diff --git a/src/integration/plotsquared/5/pom.xml b/src/integration/plotsquared/5/pom.xml new file mode 100644 index 000000000..005849ea4 --- /dev/null +++ b/src/integration/plotsquared/5/pom.xml @@ -0,0 +1,69 @@ + + 4.0.0 + org.maxgamer.quickshop.integration + PlotSquared5 + 1.1 + jar + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + enginehub-repo + https://maven.enginehub.org/repo/ + + + CodeMC + https://repo.codemc.io/repository/maven-public/ + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 8 + 8 + + + + + + + + com.plotsquared + PlotSquared5-Core + 5 + system + ${project.basedir}/../../../../lib/PlotSquared5-Core-5.13.11.jar + + + org.maxgamer + QuickShop + 4.0.9.2 + provided + + + org.spigotmc + spigot-api + 1.17-R0.1-SNAPSHOT + provided + + + com.sk89q.worldedit + worldedit-core + 7.2.0-SNAPSHOT + provided + + + org.jetbrains + annotations + 21.0.1 + provided + + + \ No newline at end of file diff --git a/src/main/java/org/maxgamer/quickshop/integration/plotsquared/PlotSquaredIntegrationV5.java b/src/integration/plotsquared/5/src/main/java/org/maxgamer/quickshop/integration/plotsquared/PlotSquaredIntegrationV5.java similarity index 100% rename from src/main/java/org/maxgamer/quickshop/integration/plotsquared/PlotSquaredIntegrationV5.java rename to src/integration/plotsquared/5/src/main/java/org/maxgamer/quickshop/integration/plotsquared/PlotSquaredIntegrationV5.java diff --git a/src/main/java/org/maxgamer/quickshop/integration/plotsquared/PlotSquaredIntegrationProxy.java b/src/main/java/org/maxgamer/quickshop/integration/plotsquared/PlotSquaredIntegrationProxy.java index 1a2bf4462..88cdd3948 100644 --- a/src/main/java/org/maxgamer/quickshop/integration/plotsquared/PlotSquaredIntegrationProxy.java +++ b/src/main/java/org/maxgamer/quickshop/integration/plotsquared/PlotSquaredIntegrationProxy.java @@ -26,6 +26,7 @@ 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.util.Util; @IntegrationStage(loadStage = IntegrateStage.onEnableAfter) public class PlotSquaredIntegrationProxy extends QSIntegratedPlugin { @@ -36,8 +37,10 @@ public class PlotSquaredIntegrationProxy extends QSIntegratedPlugin { if (plotSquared == null) { if (plugin.getServer().getPluginManager().getPlugin("PlotSquared").getClass().getPackage().getName().contains("intellectualsite")) { plotSquared = new PlotSquaredIntegrationV4(instance); - } else { + } else if (Util.isClassAvailable("com.plotsquared.core.configuration.Caption")) { plotSquared = new PlotSquaredIntegrationV5(instance); + } else { + plotSquared = new PlotSquaredIntegrationV6(instance); } } } diff --git a/src/main/java/org/maxgamer/quickshop/integration/plotsquared/PlotSquaredIntegrationV6.java b/src/main/java/org/maxgamer/quickshop/integration/plotsquared/PlotSquaredIntegrationV6.java new file mode 100644 index 000000000..453c4b4dc --- /dev/null +++ b/src/main/java/org/maxgamer/quickshop/integration/plotsquared/PlotSquaredIntegrationV6.java @@ -0,0 +1,176 @@ +package org.maxgamer.quickshop.integration.plotsquared;/* + * This file is a part of project QuickShop, the name is PlotSquaredIntegrationV5.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 . + * + */ + +import com.google.common.eventbus.Subscribe; +import com.plotsquared.core.PlotSquared; +import com.plotsquared.core.configuration.caption.Caption; +import com.plotsquared.core.configuration.caption.TranslatableCaption; +import com.plotsquared.core.events.PlotDeleteEvent; +import com.plotsquared.core.plot.Plot; +import com.plotsquared.core.plot.flag.GlobalFlagContainer; +import com.plotsquared.core.plot.flag.types.BooleanFlag; +import com.sk89q.worldedit.regions.CuboidRegion; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.entity.Player; +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 org.maxgamer.quickshop.util.Util; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +@SuppressWarnings("DuplicatedCode") +@IntegrationStage(loadStage = IntegrateStage.onEnableAfter) +public class PlotSquaredIntegrationV6 extends QSIntegratedPlugin { + private final boolean whiteList; + private final boolean deleteUntrusted; + private QuickshopCreateFlag createFlag; + private QuickshopTradeFlag tradeFlag; + + public PlotSquaredIntegrationV6(QuickShop plugin) { + super(plugin); + this.whiteList = plugin.getConfig().getBoolean("integration.plotsquared.whitelist-mode"); + this.deleteUntrusted = plugin.getConfig().getBoolean("integration.plotsquared.delete-when-user-untrusted"); + + } + + @Override + public @NotNull String getName() { + return "PlotSquared"; + } + + @Override + public boolean canCreateShopHere(@NotNull Player player, @NotNull Location location) { + com.plotsquared.core.location.Location pLocation = com.plotsquared.core.location.Location.at( + location.getWorld().getName(), + location.getBlockX(), + location.getBlockY(), + location.getBlockZ()); + Plot plot = pLocation.getPlot(); + if (plot == null) { + return !whiteList; + } + return plot.getFlag(createFlag); + } + + @Override + public boolean canTradeShopHere(@NotNull Player player, @NotNull Location location) { + com.plotsquared.core.location.Location pLocation = + com.plotsquared.core.location.Location.at( + location.getWorld().getName(), + location.getBlockX(), + location.getBlockY(), + location.getBlockZ()); + Plot plot = pLocation.getPlot(); + if (plot == null) { + return !whiteList; + } + return plot.getFlag(tradeFlag); + } + + @Override + public void load() { + this.createFlag = new QuickshopCreateFlag(); + this.tradeFlag = new QuickshopTradeFlag(); + GlobalFlagContainer.getInstance().addAll(Arrays.asList(createFlag, tradeFlag)); + plugin.getLogger().info(ChatColor.GREEN + getName() + " flags register successfully."); + Util.debugLog("Success register " + getName() + " flags."); + PlotSquared.get().getEventDispatcher().registerListener(this); + } + + @Override + public void unload() { + PlotSquared.get().getEventDispatcher().unregisterListener(this); + } + + private List getShops(Plot plot) { + List shopsList = new ArrayList<>(); + for (CuboidRegion region : plot.getRegions()) { + for (int x = region.getMinimumPoint().getX() >> 4; + x <= region.getMaximumPoint().getX() >> 4; x++) { + for (int z = region.getMinimumPoint().getZ() >> 4; + z <= region.getMaximumPoint().getZ() >> 4; z++) { + Map shops = plugin.getShopManager().getShops(plot.getWorldName(), x, z); + if (shops != null) { + shopsList.addAll(shops.values()); + } + } + } + } + return shopsList; + } + + @Subscribe + public void onPlotDelete(PlotDeleteEvent event) { + getShops(event.getPlot()).forEach(Shop::delete); + } + + @Subscribe + public void onPlotPlayerUntrusted(com.plotsquared.core.events.PlayerPlotTrustedEvent event) { + if (!deleteUntrusted) { + return; + } + if (event.wasAdded()) { + return; // We only check untrusted + } + getShops(event.getPlot()).stream().filter(shop -> shop.getOwner().equals(event.getPlayer())).forEach(Shop::delete); + } + + + static class QuickshopCreateFlag extends BooleanFlag { + + protected QuickshopCreateFlag(boolean value, Caption description) { + super(value, description); + } + + public QuickshopCreateFlag() { + super(true, TranslatableCaption.of("quickshop-create")); + } + + @Override + protected QuickshopCreateFlag flagOf(@NotNull Boolean aBoolean) { + return new QuickshopCreateFlag(aBoolean, TranslatableCaption.of("quickshop-create")); + } + } + + static class QuickshopTradeFlag extends BooleanFlag { + + protected QuickshopTradeFlag(boolean value, Caption description) { + super(value, description); + } + + public QuickshopTradeFlag() { + super(true, TranslatableCaption.of("quickshop-trade")); + } + + @Override + protected QuickshopTradeFlag flagOf(@NotNull Boolean aBoolean) { + return new QuickshopTradeFlag(aBoolean, TranslatableCaption.of("quickshop-trade")); + } + } + +} +