diff --git a/lib/PlotSquared-Bukkit-4.4.495.jar b/lib/PlotSquared-Bukkit-4.4.495.jar new file mode 100644 index 0000000..5ea845b Binary files /dev/null and b/lib/PlotSquared-Bukkit-4.4.495.jar differ diff --git a/pom.xml b/pom.xml index 2a978f5..848403b 100644 --- a/pom.xml +++ b/pom.xml @@ -162,6 +162,13 @@ system ${project.basedir}/lib/IslandWorld-8.5.jar + + com.github.intellectualsites.plotsquared + PlotSquared-API + 4.495 + system + ${project.basedir}/lib/PlotSquared-Bukkit-4.4.495.jar + diff --git a/src/main/java/de/epiceric/shopchest/ShopChest.java b/src/main/java/de/epiceric/shopchest/ShopChest.java index e883e55..ddde89b 100644 --- a/src/main/java/de/epiceric/shopchest/ShopChest.java +++ b/src/main/java/de/epiceric/shopchest/ShopChest.java @@ -35,6 +35,7 @@ import de.epiceric.shopchest.config.Config; import de.epiceric.shopchest.config.HologramFormat; import de.epiceric.shopchest.event.ShopInitializedEvent; import de.epiceric.shopchest.external.BentoBoxShopFlag; +import de.epiceric.shopchest.external.PlotSquaredOldShopFlag; import de.epiceric.shopchest.external.PlotSquaredShopFlag; import de.epiceric.shopchest.external.WorldGuardShopFlag; import de.epiceric.shopchest.external.listeners.ASkyBlockListener; @@ -318,14 +319,12 @@ public class ShopChest extends JavaPlugin { WorldGuardWrapper.getInstance().registerEvents(this); } - if (getServer().getPluginManager().isPluginEnabled("PlotSquared")) { + if (hasPlotSquared()) { 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); + PlotSquaredOldShopFlag.register(this); } } @@ -627,14 +626,6 @@ 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(); } diff --git a/src/main/java/de/epiceric/shopchest/external/PlotSquaredOldShopFlag.java b/src/main/java/de/epiceric/shopchest/external/PlotSquaredOldShopFlag.java new file mode 100644 index 0000000..d56205e --- /dev/null +++ b/src/main/java/de/epiceric/shopchest/external/PlotSquaredOldShopFlag.java @@ -0,0 +1,114 @@ +package de.epiceric.shopchest.external; + +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 org.bukkit.entity.Player; + +import de.epiceric.shopchest.ShopChest; + +import java.util.Locale; + +public class PlotSquaredOldShopFlag { + + 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"); + + public static void register(ShopChest plugin) { + if (registered) return; + + Flags.registerFlag(CREATE_SHOP); + Flags.registerFlag(USE_SHOP); + Flags.registerFlag(USE_ADMIN_SHOP); + registered = true; + + plugin.debug("Registered custom PlotSquared flags"); + } + + /** + * 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) { + if (plot != null && flag != null) { + Group group = plot.getFlag(flag, PlotSquaredOldShopFlag.Group.NONE); + ShopChest.getInstance().debug("Flag " + flag.getName() + " is set to " + group); + + switch (group) { + case OWNERS: + return plot.getOwners().contains(p.getUniqueId()); + case TRUSTED: + return plot.getOwners().contains(p.getUniqueId()) || plot.getTrusted().contains(p.getUniqueId()); + case MEMBERS: + return plot.getOwners().contains(p.getUniqueId()) || plot.getTrusted().contains(p.getUniqueId()) || plot.getMembers().contains(p.getUniqueId()); + case EVERYONE: + return true; + case NONE: + return false; + } + } + + ShopChest.getInstance().debug("Flag or plot is null, or value of flag is not a group"); + + return true; + } + + public static class GroupFlag extends Flag { + + public GroupFlag(String name) { + super(name); + } + + @Override + public String valueToString(Object value) { + return String.valueOf(value); + } + + @Override + public Group parseValue(String s) { + String val = s.toLowerCase(Locale.ENGLISH); + + switch (val) { + case "owners": + case "owner": + return Group.OWNERS; + case "members": + case "member": + case "helpers": + case "helper": + return Group.MEMBERS; + case "trusted": + return Group.TRUSTED; + case "everyone": + case "all": + return Group.EVERYONE; + case "deny": + case "false": + case "no": + case "0": + case "none": + case "noone": + return Group.NONE; + } + + return null; + } + + @Override + public String getValueDescription() { + return "Flag value must be a group: 'owner' , 'members', 'trusted', 'everyone' or 'none'"; + } + } + +} \ No newline at end of file diff --git a/src/main/java/de/epiceric/shopchest/external/listeners/PlotSquaredListener.java b/src/main/java/de/epiceric/shopchest/external/listeners/PlotSquaredListener.java index ef58bf1..3cab944 100644 --- a/src/main/java/de/epiceric/shopchest/external/listeners/PlotSquaredListener.java +++ b/src/main/java/de/epiceric/shopchest/external/listeners/PlotSquaredListener.java @@ -15,6 +15,7 @@ import de.epiceric.shopchest.ShopChest; import de.epiceric.shopchest.config.Config; import de.epiceric.shopchest.event.ShopCreateEvent; import de.epiceric.shopchest.event.ShopExtendEvent; +import de.epiceric.shopchest.external.PlotSquaredOldShopFlag; import de.epiceric.shopchest.external.PlotSquaredShopFlag; import de.epiceric.shopchest.utils.Utils; @@ -65,9 +66,21 @@ public class PlotSquaredListener implements Listener { // } private boolean handleForLocation(Player player, org.bukkit.Location loc, Cancellable e) { - Location plotLocation = new Location(loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); - Plot plot = plotLocation.getOwnedPlot(); - if (!PlotSquaredShopFlag.isFlagAllowedOnPlot(plot, PlotSquaredShopFlag.CREATE_SHOP, player)) { + boolean isAllowed = false; + + try { + Class.forName("com.plotsquared.core.PlotSquared"); + Location plotLocation = new Location(loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); + Plot plot = plotLocation.getOwnedPlot(); + isAllowed = PlotSquaredShopFlag.isFlagAllowedOnPlot(plot, PlotSquaredShopFlag.CREATE_SHOP, player); + } catch (ClassNotFoundException ex) { + com.github.intellectualsites.plotsquared.plot.object.Location plotLocation = new com.github.intellectualsites.plotsquared.plot.object.Location( + loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); + com.github.intellectualsites.plotsquared.plot.object.Plot plot = plotLocation.getOwnedPlot(); + isAllowed = PlotSquaredOldShopFlag.isFlagAllowedOnPlot(plot, PlotSquaredOldShopFlag.CREATE_SHOP, player); + } + + if (!isAllowed) { e.setCancelled(true); plugin.debug("Cancel Reason: PlotSquared"); return true; diff --git a/src/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java b/src/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java index bd85053..ee09b38 100644 --- a/src/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java +++ b/src/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java @@ -10,7 +10,6 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import com.google.gson.JsonPrimitive; -import com.plotsquared.core.plot.Plot; import org.bukkit.Bukkit; import org.bukkit.GameMode; @@ -44,6 +43,7 @@ import de.epiceric.shopchest.event.ShopCreateEvent; import de.epiceric.shopchest.event.ShopInfoEvent; import de.epiceric.shopchest.event.ShopOpenEvent; import de.epiceric.shopchest.event.ShopRemoveEvent; +import de.epiceric.shopchest.external.PlotSquaredOldShopFlag; import de.epiceric.shopchest.external.PlotSquaredShopFlag; import de.epiceric.shopchest.language.LanguageUtils; import de.epiceric.shopchest.language.Message; @@ -254,10 +254,18 @@ public class ShopInteractListener implements Listener { boolean externalPluginsAllowed = true; if (plugin.hasPlotSquared() && Config.enablePlotsquaredIntegration) { - 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(); - externalPluginsAllowed = PlotSquaredShopFlag.isFlagAllowedOnPlot(plot, PlotSquaredShopFlag.USE_SHOP, p); + try { + Class.forName("com.plotsquared.core.PlotSquared"); + com.plotsquared.core.location.Location plotLocation = + new com.plotsquared.core.location.Location(b.getWorld().getName(), b.getX(), b.getY(), b.getZ()); + com.plotsquared.core.plot.Plot plot = plotLocation.getOwnedPlot(); + externalPluginsAllowed = PlotSquaredShopFlag.isFlagAllowedOnPlot(plot, PlotSquaredShopFlag.USE_SHOP, p); + } catch (ClassNotFoundException ex) { + 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.github.intellectualsites.plotsquared.plot.object.Plot plot = plotLocation.getOwnedPlot(); + externalPluginsAllowed = PlotSquaredOldShopFlag.isFlagAllowedOnPlot(plot, PlotSquaredOldShopFlag.USE_SHOP, p); + } } if (externalPluginsAllowed && plugin.hasWorldGuard() && Config.enableWorldGuardIntegration) { @@ -366,10 +374,18 @@ public class ShopInteractListener implements Listener { boolean externalPluginsAllowed = true; if (plugin.hasPlotSquared() && Config.enablePlotsquaredIntegration) { - 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(); - externalPluginsAllowed = PlotSquaredShopFlag.isFlagAllowedOnPlot(plot, PlotSquaredShopFlag.USE_SHOP, p); + try { + Class.forName("com.plotsquared.core.PlotSquared"); + com.plotsquared.core.location.Location plotLocation = + new com.plotsquared.core.location.Location(b.getWorld().getName(), b.getX(), b.getY(), b.getZ()); + com.plotsquared.core.plot.Plot plot = plotLocation.getOwnedPlot(); + externalPluginsAllowed = PlotSquaredShopFlag.isFlagAllowedOnPlot(plot, PlotSquaredShopFlag.USE_SHOP, p); + } catch (ClassNotFoundException ex) { + 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.github.intellectualsites.plotsquared.plot.object.Plot plot = plotLocation.getOwnedPlot(); + externalPluginsAllowed = PlotSquaredOldShopFlag.isFlagAllowedOnPlot(plot, PlotSquaredOldShopFlag.USE_SHOP, p); + } } if (externalPluginsAllowed && plugin.hasWorldGuard() && Config.enableWorldGuardIntegration) {