From 8a26b15ea996bd57aec1bdf38dbcdafa4d00ca0f Mon Sep 17 00:00:00 2001 From: Johanmans10 Date: Tue, 30 Apr 2024 01:00:13 +0200 Subject: [PATCH] #539 Implemented permissions for bypassing min/max sell/buy prices --- .../Modules/PriceRestrictionModule.java | 29 +++++++++++-------- .../com/Acrobot/ChestShop/Permission.java | 15 ++++++++-- src/main/resources/plugin.yml | 16 ++++++++++ 3 files changed, 46 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/Modules/PriceRestrictionModule.java b/src/main/java/com/Acrobot/ChestShop/Listeners/Modules/PriceRestrictionModule.java index 1c30511..b3ef65b 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/Modules/PriceRestrictionModule.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/Modules/PriceRestrictionModule.java @@ -6,11 +6,13 @@ import com.Acrobot.ChestShop.Configuration.Messages; import com.Acrobot.ChestShop.Events.ChestShopReloadEvent; import com.Acrobot.ChestShop.Events.ItemParseEvent; import com.Acrobot.ChestShop.Events.PreShopCreationEvent; +import com.Acrobot.ChestShop.Permission; import com.Acrobot.ChestShop.Signs.ChestShopSign; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.inventory.ItemStack; @@ -21,10 +23,8 @@ import java.math.BigDecimal; import java.util.Locale; import java.util.logging.Level; -import static com.Acrobot.ChestShop.Events.PreShopCreationEvent.CreationOutcome.BUY_PRICE_ABOVE_MAX; -import static com.Acrobot.ChestShop.Events.PreShopCreationEvent.CreationOutcome.BUY_PRICE_BELOW_MIN; -import static com.Acrobot.ChestShop.Events.PreShopCreationEvent.CreationOutcome.SELL_PRICE_ABOVE_MAX; -import static com.Acrobot.ChestShop.Events.PreShopCreationEvent.CreationOutcome.SELL_PRICE_BELOW_MIN; +import static com.Acrobot.ChestShop.Events.PreShopCreationEvent.CreationOutcome.*; +import static com.Acrobot.ChestShop.Permission.*; /** * @author Acrobot @@ -106,6 +106,7 @@ public class PriceRestrictionModule implements Listener { ItemParseEvent parseEvent = new ItemParseEvent(ChestShopSign.getItem(event.getSignLines())); Bukkit.getPluginManager().callEvent(parseEvent); ItemStack material = parseEvent.getItem(); + Player player = event.getPlayer(); if (material == null) { return; @@ -124,15 +125,17 @@ public class PriceRestrictionModule implements Listener { BigDecimal buyPrice = PriceUtil.getExactBuyPrice(priceLine); BigDecimal minBuyPrice = BigDecimal.valueOf(configuration.getDouble("min.buy_price." + itemType) * amount); - if (isValid("min.buy_price." + itemType) && buyPrice.compareTo(minBuyPrice) < 0) { + if (isValid("min.buy_price." + itemType) && buyPrice.compareTo(minBuyPrice) < 0 + && !Permission.has(player, NOLIMIT_MIN_BUY) && !Permission.has(player, NOLIMIT_MIN_BUY_ID + itemType)) { event.setOutcome(BUY_PRICE_BELOW_MIN); - Messages.BUY_PRICE_BELOW_MIN.sendWithPrefix(event.getPlayer(), "price", buyPrice.toPlainString(), "minprice", minBuyPrice.toPlainString()); + Messages.BUY_PRICE_BELOW_MIN.sendWithPrefix(player, "price", buyPrice.toPlainString(), "minprice", minBuyPrice.toPlainString()); } BigDecimal maxBuyPrice = BigDecimal.valueOf(configuration.getDouble("max.buy_price." + itemType) * amount); - if (isValid("max.buy_price." + itemType) && buyPrice.compareTo(maxBuyPrice) > 0) { + if (isValid("max.buy_price." + itemType) && buyPrice.compareTo(maxBuyPrice) > 0 + && !Permission.has(player, NOLIMIT_MAX_BUY) && !Permission.has(player, NOLIMIT_MAX_BUY_ID + itemType)) { event.setOutcome(BUY_PRICE_ABOVE_MAX); - Messages.BUY_PRICE_ABOVE_MAX.sendWithPrefix(event.getPlayer(), "price", buyPrice.toPlainString(), "maxprice", maxBuyPrice.toPlainString()); + Messages.BUY_PRICE_ABOVE_MAX.sendWithPrefix(player, "price", buyPrice.toPlainString(), "maxprice", maxBuyPrice.toPlainString()); } } @@ -140,15 +143,17 @@ public class PriceRestrictionModule implements Listener { BigDecimal sellPrice = PriceUtil.getExactSellPrice(priceLine); BigDecimal minSellPrice = BigDecimal.valueOf(configuration.getDouble("min.sell_price." + itemType) * amount); - if (isValid("min.sell_price." + itemType) && sellPrice.compareTo(minSellPrice) < 0) { + if (isValid("min.sell_price." + itemType) && sellPrice.compareTo(minSellPrice) < 0 + && !Permission.has(player, NOLIMIT_MIN_SELL) && !Permission.has(player, NOLIMIT_MIN_SELL_ID + itemType)) { event.setOutcome(SELL_PRICE_BELOW_MIN); - Messages.SELL_PRICE_BELOW_MIN.sendWithPrefix(event.getPlayer(), "price", sellPrice.toPlainString(), "minprice", minSellPrice.toPlainString()); + Messages.SELL_PRICE_BELOW_MIN.sendWithPrefix(player, "price", sellPrice.toPlainString(), "minprice", minSellPrice.toPlainString()); } BigDecimal maxSellPrice = BigDecimal.valueOf(configuration.getDouble("max.sell_price." + itemType) * amount); - if (isValid("max.sell_price." + itemType) && sellPrice.compareTo(maxSellPrice) > 0) { + if (isValid("max.sell_price." + itemType) && sellPrice.compareTo(maxSellPrice) > 0 + && !Permission.has(player, NOLIMIT_MAX_SELL) && !Permission.has(player, NOLIMIT_MAX_SELL_ID + itemType)) { event.setOutcome(SELL_PRICE_ABOVE_MAX); - Messages.SELL_PRICE_ABOVE_MAX.sendWithPrefix(event.getPlayer(), "price", sellPrice.toPlainString(), "maxprice", maxSellPrice.toPlainString()); + Messages.SELL_PRICE_ABOVE_MAX.sendWithPrefix(player, "price", sellPrice.toPlainString(), "maxprice", maxSellPrice.toPlainString()); } } } diff --git a/src/main/java/com/Acrobot/ChestShop/Permission.java b/src/main/java/com/Acrobot/ChestShop/Permission.java index 5fc4ed1..ba826cc 100644 --- a/src/main/java/com/Acrobot/ChestShop/Permission.java +++ b/src/main/java/com/Acrobot/ChestShop/Permission.java @@ -5,7 +5,6 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import java.util.Locale; -import java.util.Optional; /** * @author Acrobot @@ -43,7 +42,19 @@ public enum Permission { NOTIFY_TOGGLE("ChestShop.toggle"), ACCESS_TOGGLE("ChestShop.accesstoggle"), ITEMINFO("ChestShop.iteminfo"), - SHOPINFO("ChestShop.shopinfo"); + SHOPINFO("ChestShop.shopinfo"), + + NOLIMIT_MIN_BUY("ChestShop.nolimit.buy.min"), + NOLIMIT_MIN_BUY_ID("ChestShop.nolimit.buy.min."), + + NOLIMIT_MAX_BUY("ChestShop.nolimit.buy.max"), + NOLIMIT_MAX_BUY_ID("ChestShop.nolimit.buy.max."), + + NOLIMIT_MIN_SELL("ChestShop.nolimit.sell.min"), + NOLIMIT_MIN_SELL_ID("ChestShop.nolimit.sell.min."), + + NOLIMIT_MAX_SELL("ChestShop.nolimit.sell.max"), + NOLIMIT_MAX_SELL_ID("ChestShop.nolimit.sell.max."); private final String permission; diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index d2103e2..5cd426f 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -123,6 +123,22 @@ permissions: description: Gives you the power to do access shops for all names. ChestShop.othername.access.(some name): description: Gives you the power to do access shops for (some name), for example your town. + ChestShop.nolimit.buy.min: + description: Allows user to bypass the minimal buy price for all items + ChestShop.nolimit.buy.min.(itemType): + description: Allows user to bypass the minimal buy price for itemType + ChestShop.nolimit.buy.max: + description: Allows user to bypass the maximal buy price for all items + ChestShop.nolimit.buy.max.(itemType): + description: Allows user to bypass the maximal buy price for itemType + ChestShop.nolimit.sell.min: + description: Allows user to bypass the minimal sell price for all items + ChestShop.nolimit.sell.min.(itemType): + description: Allows user to bypass the minimal sell price for itemType + ChestShop.nolimit.sell.max: + description: Allows user to bypass the maximal sell price for all items + ChestShop.nolimit.sell.max.(itemType): + description: Allows user to bypass the maximal sell price for itemType ChestShop.shop.create.food: description: Allows to create a shop that sells food children: