Add support for PlotSquared 6 (WIP) (#1208)

* Add support for PlotSquared 6 (WIP)

* Resolved package name conflicting by multiple projects

* Fix build
This commit is contained in:
sandtechnology authored and GitHub committed 2021-06-24 21:11:48 +08:00
1 parent 2a33065279
commit 124993e9a7
8 files changed
+276 -23

No files matched your search

+69
View File
@@ -0,0 +1,69 @@
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.maxgamer.quickshop.integration</groupId>
<artifactId>PlotSquared5</artifactId>
<version>1.1</version>
<packaging>jar</packaging>
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>enginehub-repo</id>
<url>https://maven.enginehub.org/repo/</url>
</repository>
<repository>
<id>CodeMC</id>
<url>https://repo.codemc.io/repository/maven-public/</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!--PlotSquared 5 Core-->
<dependency>
<groupId>com.plotsquared</groupId>
<artifactId>PlotSquared5-Core</artifactId>
<version>5</version>
<scope>system</scope>
<systemPath>${project.basedir}/../../../../lib/PlotSquared5-Core-5.13.11.jar</systemPath>
</dependency>
<dependency>
<groupId>org.maxgamer</groupId>
<artifactId>QuickShop</artifactId>
<version>4.0.9.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.17-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sk89q.worldedit</groupId>
<artifactId>worldedit-core</artifactId>
<version>7.2.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>21.0.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
@@ -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);
}
}
}
@@ -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 <http://www.gnu.org/licenses/>.
*
*/
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<Shop> getShops(Plot plot) {
List<Shop> 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<Location, Shop> 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<QuickshopCreateFlag> {
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<QuickshopTradeFlag> {
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"));
}
}
}