mirror of
https://github.com/amalthea-mc/ShopChest.git
synced 2024-11-10 04:31:06 +00:00
Fix warnings regarding PlotSquared flags
This commit is contained in:
parent
f40b0b7418
commit
86322a1198
@ -278,7 +278,7 @@ public class ShopChest extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (hasPlotSquared()) {
|
if (hasPlotSquared()) {
|
||||||
new PlotSquaredShopFlag().register(this);
|
PlotSquaredShopFlag.register(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,10 @@ package de.epiceric.shopchest.external;
|
|||||||
|
|
||||||
import com.intellectualcrafters.plot.flag.Flag;
|
import com.intellectualcrafters.plot.flag.Flag;
|
||||||
import com.intellectualcrafters.plot.flag.Flags;
|
import com.intellectualcrafters.plot.flag.Flags;
|
||||||
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import de.epiceric.shopchest.ShopChest;
|
import de.epiceric.shopchest.ShopChest;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
@ -14,30 +18,53 @@ public class PlotSquaredShopFlag {
|
|||||||
OWNERS, MEMBERS, TRUSTED, EVERYONE, NONE
|
OWNERS, MEMBERS, TRUSTED, EVERYONE, NONE
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Flag CREATE_SHOP;
|
public static GroupFlag CREATE_SHOP = new GroupFlag("create-shop");
|
||||||
public static Flag USE_SHOP;
|
public static GroupFlag USE_SHOP = new GroupFlag("use-shop");
|
||||||
public static Flag USE_ADMIN_SHOP;
|
public static GroupFlag USE_ADMIN_SHOP = new GroupFlag("use-admin-shop");
|
||||||
|
|
||||||
private GroupFlag createShop = new GroupFlag("create-shop");
|
public static void register(ShopChest plugin) {
|
||||||
private GroupFlag useShop = new GroupFlag("use-shop");
|
|
||||||
private GroupFlag useAdminShop = new GroupFlag("use-admin-shop");
|
|
||||||
|
|
||||||
public void register(ShopChest plugin) {
|
|
||||||
if (registered) return;
|
if (registered) return;
|
||||||
|
|
||||||
CREATE_SHOP = createShop;
|
Flags.registerFlag(CREATE_SHOP);
|
||||||
USE_SHOP = useShop;
|
Flags.registerFlag(USE_SHOP);
|
||||||
USE_ADMIN_SHOP = useAdminShop;
|
Flags.registerFlag(USE_ADMIN_SHOP);
|
||||||
|
|
||||||
Flags.registerFlag(createShop);
|
|
||||||
Flags.registerFlag(useShop);
|
|
||||||
Flags.registerFlag(useAdminShop);
|
|
||||||
registered = true;
|
registered = true;
|
||||||
|
|
||||||
plugin.debug("Registered custom PlotSquared flags");
|
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) {
|
public GroupFlag(String name) {
|
||||||
super(name);
|
super(name);
|
||||||
|
@ -216,7 +216,7 @@ public class ChestProtectListener implements Listener {
|
|||||||
com.intellectualcrafters.plot.object.Location loc =
|
com.intellectualcrafters.plot.object.Location loc =
|
||||||
new com.intellectualcrafters.plot.object.Location(b.getWorld().getName(), b.getX(), b.getY(), b.getZ());
|
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) {
|
if (externalPluginsAllowed && plugin.hasUSkyBlock() && Config.enableUSkyblockIntegration) {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package de.epiceric.shopchest.listeners;
|
package de.epiceric.shopchest.listeners;
|
||||||
|
|
||||||
import com.google.gson.JsonPrimitive;
|
import com.google.gson.JsonPrimitive;
|
||||||
import com.intellectualcrafters.plot.flag.Flag;
|
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.palmergames.bukkit.towny.object.Resident;
|
import com.palmergames.bukkit.towny.object.Resident;
|
||||||
import com.palmergames.bukkit.towny.object.Town;
|
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.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;
|
||||||
@ -216,7 +216,7 @@ public class ShopInteractListener implements Listener {
|
|||||||
loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
|
loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
|
||||||
|
|
||||||
Plot plot = plotLocation.getOwnedPlot();
|
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());
|
new com.intellectualcrafters.plot.object.Location(b.getWorld().getName(), b.getX(), b.getY(), b.getZ());
|
||||||
|
|
||||||
Plot plot = plotLocation.getOwnedPlot();
|
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) {
|
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());
|
new com.intellectualcrafters.plot.object.Location(b.getWorld().getName(), b.getX(), b.getY(), b.getZ());
|
||||||
|
|
||||||
Plot plot = plotLocation.getOwnedPlot();
|
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) {
|
if (externalPluginsAllowed && plugin.hasWorldGuard() && Config.enableWorldGuardIntegration) {
|
||||||
|
@ -1,10 +1,7 @@
|
|||||||
package de.epiceric.shopchest.utils;
|
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.ShopChest;
|
||||||
import de.epiceric.shopchest.config.Placeholder;
|
import de.epiceric.shopchest.config.Placeholder;
|
||||||
import de.epiceric.shopchest.external.PlotSquaredShopFlag;
|
|
||||||
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;
|
||||||
@ -225,42 +222,6 @@ public class Utils {
|
|||||||
return item != null && axes.contains(item.getType().toString());
|
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>
|
* <p>Check if a player is allowed to create a shop that sells or buys the given item.</p>
|
||||||
* @param player Player to check
|
* @param player Player to check
|
||||||
|
Loading…
Reference in New Issue
Block a user