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