mirror of
https://github.com/amalthea-mc/ShopChest.git
synced 2024-11-09 12:11:08 +00:00
Support PlotSquared v5
Does not support older PlotSquared versions anymore
This commit is contained in:
parent
d4729de3f4
commit
0f51cc34c2
10
pom.xml
10
pom.xml
@ -87,6 +87,10 @@
|
||||
<id>nlthijs48-repo</id>
|
||||
<url>http://maven.wiefferink.me</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>plotsquared-repo</id>
|
||||
<url>https://mvn.intellectualsites.com/content/groups/public/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
@ -109,9 +113,9 @@
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.intellectualsites.plotsquared</groupId>
|
||||
<artifactId>PlotSquared-API</artifactId>
|
||||
<version>4.226</version>
|
||||
<groupId>com.plotsquared</groupId>
|
||||
<artifactId>PlotSquared</artifactId>
|
||||
<version>5.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -16,6 +16,7 @@ import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import com.palmergames.bukkit.towny.Towny;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.wasteofplastic.askyblock.ASkyBlock;
|
||||
|
||||
import org.bstats.bukkit.Metrics;
|
||||
@ -317,8 +318,15 @@ public class ShopChest extends JavaPlugin {
|
||||
WorldGuardWrapper.getInstance().registerEvents(this);
|
||||
}
|
||||
|
||||
if (hasPlotSquared()) {
|
||||
if (getServer().getPluginManager().isPluginEnabled("PlotSquared")) {
|
||||
try {
|
||||
Class.forName("com.plotsquared.core.PlotSquared");
|
||||
PlotSquaredShopFlag.register(this);
|
||||
} catch (ClassNotFoundException ex) {
|
||||
String ver = getServer().getPluginManager().getPlugin("PlotSquared").getDescription().getVersion();
|
||||
debug("PlotSquared v5 required. Installed: " + ver);
|
||||
getLogger().warning("PlotSquared v5 required. You have version " + ver);
|
||||
}
|
||||
}
|
||||
|
||||
if (hasBentoBox()) {
|
||||
@ -619,6 +627,14 @@ public class ShopChest extends JavaPlugin {
|
||||
// Supported PlotSquared versions don't support versions below 1.13
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
// Check for PlotSquared v5
|
||||
Class.forName("com.plotsquared.core.PlotSquared");
|
||||
} catch (ClassNotFoundException ex) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Plugin p = getServer().getPluginManager().getPlugin("PlotSquared");
|
||||
return p != null && p.isEnabled();
|
||||
}
|
||||
|
@ -1,33 +1,42 @@
|
||||
package de.epiceric.shopchest.external;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Locale;
|
||||
|
||||
import com.github.intellectualsites.plotsquared.plot.flag.Flag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
||||
import com.plotsquared.core.configuration.Caption;
|
||||
import com.plotsquared.core.configuration.Captions;
|
||||
import com.plotsquared.core.configuration.StaticCaption;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.plot.flag.FlagParseException;
|
||||
import com.plotsquared.core.plot.flag.GlobalFlagContainer;
|
||||
import com.plotsquared.core.plot.flag.PlotFlag;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import de.epiceric.shopchest.ShopChest;
|
||||
|
||||
public class PlotSquaredShopFlag {
|
||||
|
||||
private static boolean registered = false;
|
||||
|
||||
public enum Group {
|
||||
OWNERS, MEMBERS, TRUSTED, EVERYONE, NONE
|
||||
}
|
||||
|
||||
public static GroupFlag CREATE_SHOP = new GroupFlag("create-shop");
|
||||
public static GroupFlag USE_SHOP = new GroupFlag("use-shop");
|
||||
public static GroupFlag USE_ADMIN_SHOP = new GroupFlag("use-admin-shop");
|
||||
private static final String[] lowercaseValues = Arrays.asList(Group.values()).stream()
|
||||
.map(value -> String.valueOf(value).toLowerCase(Locale.ENGLISH))
|
||||
.toArray(String[]::new);
|
||||
|
||||
private static boolean registered = false;
|
||||
|
||||
public static final CreateShopFlag CREATE_SHOP = new CreateShopFlag(Group.MEMBERS);
|
||||
public static final UseShopFlag USE_SHOP = new UseShopFlag(Group.EVERYONE);
|
||||
|
||||
public static void register(ShopChest plugin) {
|
||||
if (registered) return;
|
||||
if (registered)
|
||||
return;
|
||||
|
||||
Flags.registerFlag(CREATE_SHOP);
|
||||
Flags.registerFlag(USE_SHOP);
|
||||
Flags.registerFlag(USE_ADMIN_SHOP);
|
||||
GlobalFlagContainer.getInstance().addFlag(CREATE_SHOP);
|
||||
GlobalFlagContainer.getInstance().addFlag(USE_SHOP);
|
||||
registered = true;
|
||||
|
||||
plugin.debug("Registered custom PlotSquared flags");
|
||||
@ -35,14 +44,15 @@ public class PlotSquaredShopFlag {
|
||||
|
||||
/**
|
||||
* Check if a flag is allowed for a player on a plot from PlotSquared
|
||||
*
|
||||
* @param plot Plot from PlotSquared
|
||||
* @param flag Flag to check
|
||||
* @param p Player to check
|
||||
* @return Whether the flag is allowed for the player
|
||||
*/
|
||||
public static boolean isFlagAllowedOnPlot(Plot plot, GroupFlag flag, Player p) {
|
||||
public static boolean isFlagAllowedOnPlot(Plot plot, GroupFlag<?> flag, Player p) {
|
||||
if (plot != null && flag != null) {
|
||||
Group group = plot.getFlag(flag, PlotSquaredShopFlag.Group.NONE);
|
||||
Group group = plot.getFlag(flag);
|
||||
ShopChest.getInstance().debug("Flag " + flag.getName() + " is set to " + group);
|
||||
|
||||
switch (group) {
|
||||
@ -64,51 +74,80 @@ public class PlotSquaredShopFlag {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static class GroupFlag extends Flag<Group> {
|
||||
|
||||
public GroupFlag(String name) {
|
||||
super(name);
|
||||
public static class CreateShopFlag extends GroupFlag<CreateShopFlag> {
|
||||
public CreateShopFlag(Group value) {
|
||||
super(value, new StaticCaption("Set to the group that is allowed to create shops."));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String valueToString(Object value) {
|
||||
return String.valueOf(value);
|
||||
protected CreateShopFlag flagOf(@NotNull Group value) {
|
||||
return new CreateShopFlag(value);
|
||||
}
|
||||
}
|
||||
|
||||
public static class UseShopFlag extends GroupFlag<UseShopFlag> {
|
||||
public UseShopFlag(Group value) {
|
||||
super(value, new StaticCaption("Set to the group that is allowed to use shops."));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Group parseValue(String s) {
|
||||
String val = s.toLowerCase(Locale.ENGLISH);
|
||||
protected UseShopFlag flagOf(@NotNull Group value) {
|
||||
return new UseShopFlag(value);
|
||||
}
|
||||
}
|
||||
|
||||
switch (val) {
|
||||
public abstract static class GroupFlag<F extends PlotFlag<Group, F>> extends PlotFlag<Group, F> {
|
||||
public GroupFlag(Group value, Caption description) {
|
||||
super(value, Captions.FLAG_CATEGORY_ENUM, description);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.valueOf(getValue()).toLowerCase(Locale.ENGLISH);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getExample() {
|
||||
return "members";
|
||||
}
|
||||
|
||||
@Override
|
||||
public F merge(@NotNull Group newValue) {
|
||||
return flagOf(newValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public F parse(@NotNull String input) throws FlagParseException {
|
||||
switch (input.toLowerCase(Locale.ENGLISH)) {
|
||||
case "owners":
|
||||
case "owner":
|
||||
return Group.OWNERS;
|
||||
return this.flagOf(Group.OWNERS);
|
||||
case "members":
|
||||
case "member":
|
||||
case "helpers":
|
||||
case "helper":
|
||||
return Group.MEMBERS;
|
||||
return this.flagOf(Group.MEMBERS);
|
||||
case "trusted":
|
||||
return Group.TRUSTED;
|
||||
return this.flagOf(Group.TRUSTED);
|
||||
case "everyone":
|
||||
case "all":
|
||||
return Group.EVERYONE;
|
||||
return this.flagOf(Group.EVERYONE);
|
||||
case "deny":
|
||||
case "disallow":
|
||||
case "false":
|
||||
case "no":
|
||||
case "0":
|
||||
case "none":
|
||||
case "noone":
|
||||
return Group.NONE;
|
||||
return this.flagOf(Group.NONE);
|
||||
}
|
||||
|
||||
return null;
|
||||
throw new FlagParseException(this, input, Captions.FLAG_ERROR_ENUM, (Object[]) lowercaseValues);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValueDescription() {
|
||||
return "Flag value must be a group: 'owner' , 'members', 'trusted', 'everyone' or 'none'";
|
||||
public Collection<String> getTabCompletions() {
|
||||
return Arrays.asList(lowercaseValues);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,8 +2,8 @@ package de.epiceric.shopchest.external.listeners;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import com.github.intellectualsites.plotsquared.plot.object.Location;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
@ -52,14 +52,11 @@ public class PlotSquaredListener implements Listener {
|
||||
// if (!Config.enablePlotsquaredIntegration)
|
||||
// return;
|
||||
|
||||
// ShopType shopType = e.getShop().getShopType();
|
||||
// GroupFlag flag = shopType == ShopType.ADMIN ? PlotSquaredShopFlag.USE_ADMIN_SHOP : PlotSquaredShopFlag.USE_SHOP;
|
||||
|
||||
// Set<org.bukkit.Location> chestLocations = Utils.getChestLocations(e.getShop());
|
||||
// for (org.bukkit.Location loc : chestLocations) {
|
||||
// Location plotLocation = new Location(loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
|
||||
// Plot plot = plotLocation.getOwnedPlot();
|
||||
// if (!isFlagAllowed(plot, flag, e.getPlayer())) {
|
||||
// if (!isFlagAllowed(plot, PlotSquaredShopFlag.USE_SHOP, e.getPlayer())) {
|
||||
// e.setCancelled(true);
|
||||
// plugin.debug("Cancel Reason: PlotSquared");
|
||||
// return;
|
||||
|
@ -9,8 +9,8 @@ import java.util.UUID;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
@ -45,7 +45,6 @@ import de.epiceric.shopchest.event.ShopInfoEvent;
|
||||
import de.epiceric.shopchest.event.ShopOpenEvent;
|
||||
import de.epiceric.shopchest.event.ShopRemoveEvent;
|
||||
import de.epiceric.shopchest.external.PlotSquaredShopFlag;
|
||||
import de.epiceric.shopchest.external.PlotSquaredShopFlag.GroupFlag;
|
||||
import de.epiceric.shopchest.language.LanguageUtils;
|
||||
import de.epiceric.shopchest.language.Message;
|
||||
import de.epiceric.shopchest.language.Replacement;
|
||||
@ -255,13 +254,10 @@ public class ShopInteractListener implements Listener {
|
||||
boolean externalPluginsAllowed = true;
|
||||
|
||||
if (plugin.hasPlotSquared() && Config.enablePlotsquaredIntegration) {
|
||||
com.github.intellectualsites.plotsquared.plot.object.Location plotLocation =
|
||||
new com.github.intellectualsites.plotsquared.plot.object.Location(b.getWorld().getName(), b.getX(), b.getY(), b.getZ());
|
||||
|
||||
com.plotsquared.core.location.Location plotLocation =
|
||||
new com.plotsquared.core.location.Location(b.getWorld().getName(), b.getX(), b.getY(), b.getZ());
|
||||
Plot plot = plotLocation.getOwnedPlot();
|
||||
GroupFlag flag = shop.getShopType() == Shop.ShopType.ADMIN ? PlotSquaredShopFlag.USE_ADMIN_SHOP : PlotSquaredShopFlag.USE_SHOP;
|
||||
|
||||
externalPluginsAllowed = PlotSquaredShopFlag.isFlagAllowedOnPlot(plot, flag, p);
|
||||
externalPluginsAllowed = PlotSquaredShopFlag.isFlagAllowedOnPlot(plot, PlotSquaredShopFlag.USE_SHOP, p);
|
||||
}
|
||||
|
||||
if (externalPluginsAllowed && plugin.hasWorldGuard() && Config.enableWorldGuardIntegration) {
|
||||
@ -370,13 +366,10 @@ public class ShopInteractListener implements Listener {
|
||||
boolean externalPluginsAllowed = true;
|
||||
|
||||
if (plugin.hasPlotSquared() && Config.enablePlotsquaredIntegration) {
|
||||
com.github.intellectualsites.plotsquared.plot.object.Location plotLocation =
|
||||
new com.github.intellectualsites.plotsquared.plot.object.Location(b.getWorld().getName(), b.getX(), b.getY(), b.getZ());
|
||||
|
||||
com.plotsquared.core.location.Location plotLocation =
|
||||
new com.plotsquared.core.location.Location(b.getWorld().getName(), b.getX(), b.getY(), b.getZ());
|
||||
Plot plot = plotLocation.getOwnedPlot();
|
||||
GroupFlag flag = shop.getShopType() == Shop.ShopType.ADMIN ? PlotSquaredShopFlag.USE_ADMIN_SHOP : PlotSquaredShopFlag.USE_SHOP;
|
||||
|
||||
externalPluginsAllowed = PlotSquaredShopFlag.isFlagAllowedOnPlot(plot, flag, p);
|
||||
externalPluginsAllowed = PlotSquaredShopFlag.isFlagAllowedOnPlot(plot, PlotSquaredShopFlag.USE_SHOP, p);
|
||||
}
|
||||
|
||||
if (externalPluginsAllowed && plugin.hasWorldGuard() && Config.enableWorldGuardIntegration) {
|
||||
|
Loading…
Reference in New Issue
Block a user