Fix warnings regarding PlotSquared flags

This commit is contained in:
Eric 2018-08-03 18:56:09 +02:00
parent f40b0b7418
commit 86322a1198
5 changed files with 52 additions and 64 deletions

View File

@ -278,7 +278,7 @@ public class ShopChest extends JavaPlugin {
}
if (hasPlotSquared()) {
new PlotSquaredShopFlag().register(this);
PlotSquaredShopFlag.register(this);
}
}

View File

@ -2,6 +2,10 @@ package de.epiceric.shopchest.external;
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.Flags;
import com.intellectualcrafters.plot.object.Plot;
import org.bukkit.entity.Player;
import de.epiceric.shopchest.ShopChest;
import java.util.Locale;
@ -14,30 +18,53 @@ public class PlotSquaredShopFlag {
OWNERS, MEMBERS, TRUSTED, EVERYONE, NONE
}
public static Flag CREATE_SHOP;
public static Flag USE_SHOP;
public static Flag USE_ADMIN_SHOP;
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 GroupFlag createShop = new GroupFlag("create-shop");
private GroupFlag useShop = new GroupFlag("use-shop");
private GroupFlag useAdminShop = new GroupFlag("use-admin-shop");
public void register(ShopChest plugin) {
public static void register(ShopChest plugin) {
if (registered) return;
CREATE_SHOP = createShop;
USE_SHOP = useShop;
USE_ADMIN_SHOP = useAdminShop;
Flags.registerFlag(createShop);
Flags.registerFlag(useShop);
Flags.registerFlag(useAdminShop);
Flags.registerFlag(CREATE_SHOP);
Flags.registerFlag(USE_SHOP);
Flags.registerFlag(USE_ADMIN_SHOP);
registered = true;
plugin.debug("Registered custom PlotSquared flags");
}
public class GroupFlag extends Flag<Group> {
/**
* 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, PlotSquaredShopFlag.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<Group> {
public GroupFlag(String name) {
super(name);

View File

@ -216,7 +216,7 @@ public class ChestProtectListener implements Listener {
com.intellectualcrafters.plot.object.Location loc =
new com.intellectualcrafters.plot.object.Location(b.getWorld().getName(), b.getX(), b.getY(), b.getZ());
externalPluginsAllowed = Utils.isFlagAllowedOnPlot(loc.getOwnedPlot(), PlotSquaredShopFlag.CREATE_SHOP, p);
externalPluginsAllowed = PlotSquaredShopFlag.isFlagAllowedOnPlot(loc.getOwnedPlot(), PlotSquaredShopFlag.CREATE_SHOP, p);
}
if (externalPluginsAllowed && plugin.hasUSkyBlock() && Config.enableUSkyblockIntegration) {

View File

@ -1,7 +1,6 @@
package de.epiceric.shopchest.listeners;
import com.google.gson.JsonPrimitive;
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.object.Plot;
import com.palmergames.bukkit.towny.object.Resident;
import com.palmergames.bukkit.towny.object.Town;
@ -18,6 +17,7 @@ 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;
@ -216,7 +216,7 @@ public class ShopInteractListener implements Listener {
loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
Plot plot = plotLocation.getOwnedPlot();
externalPluginsAllowed &= Utils.isFlagAllowedOnPlot(plot, PlotSquaredShopFlag.CREATE_SHOP, p);
externalPluginsAllowed &= PlotSquaredShopFlag.isFlagAllowedOnPlot(plot, PlotSquaredShopFlag.CREATE_SHOP, p);
}
}
@ -450,9 +450,9 @@ public class ShopInteractListener implements Listener {
new com.intellectualcrafters.plot.object.Location(b.getWorld().getName(), b.getX(), b.getY(), b.getZ());
Plot plot = plotLocation.getOwnedPlot();
Flag flag = (shop.getShopType() == Shop.ShopType.ADMIN ? PlotSquaredShopFlag.USE_ADMIN_SHOP : PlotSquaredShopFlag.USE_SHOP);
GroupFlag flag = shop.getShopType() == Shop.ShopType.ADMIN ? PlotSquaredShopFlag.USE_ADMIN_SHOP : PlotSquaredShopFlag.USE_SHOP;
externalPluginsAllowed = Utils.isFlagAllowedOnPlot(plot, flag, p);
externalPluginsAllowed = PlotSquaredShopFlag.isFlagAllowedOnPlot(plot, flag, p);
}
if (externalPluginsAllowed && plugin.hasWorldGuard() && Config.enableWorldGuardIntegration) {
@ -559,9 +559,9 @@ public class ShopInteractListener implements Listener {
new com.intellectualcrafters.plot.object.Location(b.getWorld().getName(), b.getX(), b.getY(), b.getZ());
Plot plot = plotLocation.getOwnedPlot();
Flag flag = (shop.getShopType() == Shop.ShopType.ADMIN ? PlotSquaredShopFlag.USE_ADMIN_SHOP : PlotSquaredShopFlag.USE_SHOP);
externalPluginsAllowed = Utils.isFlagAllowedOnPlot(plot, flag, p);
GroupFlag flag = shop.getShopType() == Shop.ShopType.ADMIN ? PlotSquaredShopFlag.USE_ADMIN_SHOP : PlotSquaredShopFlag.USE_SHOP;
externalPluginsAllowed = PlotSquaredShopFlag.isFlagAllowedOnPlot(plot, flag, p);
}
if (externalPluginsAllowed && plugin.hasWorldGuard() && Config.enableWorldGuardIntegration) {

View File

@ -1,10 +1,7 @@
package de.epiceric.shopchest.utils;
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.object.Plot;
import de.epiceric.shopchest.ShopChest;
import de.epiceric.shopchest.config.Placeholder;
import de.epiceric.shopchest.external.PlotSquaredShopFlag;
import de.epiceric.shopchest.language.LanguageUtils;
import de.epiceric.shopchest.language.Message;
import de.epiceric.shopchest.language.Replacement;
@ -225,42 +222,6 @@ public class Utils {
return item != null && axes.contains(item.getType().toString());
}
/**
* 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, Flag flag, Player p) {
if (plot != null && flag != null) {
Object o = plot.getFlag(flag, PlotSquaredShopFlag.Group.NONE);
if (o instanceof PlotSquaredShopFlag.Group) {
PlotSquaredShopFlag.Group group = (PlotSquaredShopFlag.Group) o;
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;
}
/**
* <p>Check if a player is allowed to create a shop that sells or buys the given item.</p>
* @param player Player to check