Skip to content

Commit

Permalink
Merge pull request #592 from Johanmans10/bypass-price-limit
Browse files Browse the repository at this point in the history
  • Loading branch information
Phoenix616 committed Apr 30, 2024
2 parents 9f4037c + 8a26b15 commit 7dbc1ad
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
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;
Expand All @@ -21,10 +23,8 @@
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
Expand Down Expand Up @@ -106,6 +106,7 @@ public void onPreShopCreation(PreShopCreationEvent event) {
ItemParseEvent parseEvent = new ItemParseEvent(ChestShopSign.getItem(event.getSignLines()));
Bukkit.getPluginManager().callEvent(parseEvent);
ItemStack material = parseEvent.getItem();
Player player = event.getPlayer();

if (material == null) {
return;
Expand All @@ -124,31 +125,35 @@ public void onPreShopCreation(PreShopCreationEvent event) {
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());
}
}

if (PriceUtil.hasSellPrice(priceLine)) {
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());
}
}
}
Expand Down
15 changes: 13 additions & 2 deletions src/main/java/com/Acrobot/ChestShop/Permission.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.bukkit.entity.Player;

import java.util.Locale;
import java.util.Optional;

/**
* @author Acrobot
Expand Down Expand Up @@ -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;

Expand Down
16 changes: 16 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 7dbc1ad

Please sign in to comment.