Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions crowdin/lang/en-US/messages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,8 @@ support-disable-reason:
supertool-is-disabled: <red>Super tool is disabled. Cannot break any shops.
unknown-owner: Unknown
restricted-prices: '<red>Restricted price for {0}: Min {1}, max {2}'
restricted-price-max: '<red>Restricted price for {0}: Max {1}'
restricted-price-min: '<red>Restricted price for {0}: Min {1}'
nearby-shop-this-way: <green>Shop is {0} block(s) away from you.
owner-bypass-check: <yellow>Bypassed all checks. Trade successful! (You are now the shop owner!)
april-rick-and-roll-easter-egg: "<hover:show_text:'Click to open in browser for time limited rewards!'><click:open_url:'https://www.youtube.com/watch?v=dQw4w9WgXcQ'><green>Click here to acquire your time limited rewards that provided by QuickShop-Hikari developer!</green></click></hover>"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public class SimplePriceLimiter implements Reloadable, PriceLimiter, SubPasteIte
private final QuickShop plugin;
private final Map<String, RuleSet> rules = new LinkedHashMap<>();
private boolean wholeNumberOnly = false;
private double undefinedMin = 0.0d;
private double undefinedMax = Double.MAX_VALUE;
private double undefinedMin = -1;
private double undefinedMax = -1;

public SimplePriceLimiter(@NotNull QuickShop plugin) {
this.plugin = plugin;
Expand Down Expand Up @@ -72,8 +72,8 @@ public void loadConfiguration() {
plugin.logger().warn("Failed to save migrated price-restriction.yml.yml to plugin folder!", e);
}
}
this.undefinedMax = configuration.getDouble("undefined.max", 99999999999999999999999999999.99d);
this.undefinedMin = configuration.getDouble("undefined.min", 0.0d);
this.undefinedMin = configuration.getDouble("undefined.min", -1);
this.undefinedMax = configuration.getDouble("undefined.max", -1);
this.wholeNumberOnly = configuration.getBoolean("whole-number-only", false);
if (!configuration.getBoolean("enable", false)) {
return;
Expand Down Expand Up @@ -177,6 +177,7 @@ public PriceLimiterCheckResult check(@NotNull CommandSender sender, @NotNull Ite

double minPrice = 0;
double maxPrice = 0;
boolean hasMinPrice = false;
boolean hasMaxPrice = false;
final List<ItemStack> flattenedItems = ItemContainerUtil.flattenContents(itemStack, true, false);

Expand All @@ -194,6 +195,7 @@ public PriceLimiterCheckResult check(@NotNull CommandSender sender, @NotNull Ite
}

if (rule.hasMinPrice()) {
hasMinPrice = true;
minPrice += rule.getMin() * itemTally;
}
if (rule.hasMaxPrice()) {
Expand All @@ -202,14 +204,11 @@ public PriceLimiterCheckResult check(@NotNull CommandSender sender, @NotNull Ite
}
}

if (price < minPrice || (hasMaxPrice && price > maxPrice)) {
return new SimplePriceLimiterCheckResult(PriceLimiterStatus.PRICE_RESTRICTED, minPrice, maxPrice);
}
if (undefinedMin != -1 && price < undefinedMin) {
return new SimplePriceLimiterCheckResult(PriceLimiterStatus.PRICE_RESTRICTED, undefinedMin, undefinedMax);
}
if (undefinedMax != -1 && price > undefinedMax) {
return new SimplePriceLimiterCheckResult(PriceLimiterStatus.PRICE_RESTRICTED, undefinedMin, undefinedMax);
if ((hasMinPrice && price < minPrice) || (hasMaxPrice && price > maxPrice)
|| (undefinedMin > 0 && price < undefinedMin) || (undefinedMax >= 0 && price > undefinedMax)) {
return new SimplePriceLimiterCheckResult(PriceLimiterStatus.PRICE_RESTRICTED,
hasMinPrice ? minPrice : undefinedMin,
hasMaxPrice ? maxPrice : undefinedMax);
}
return new SimplePriceLimiterCheckResult(PriceLimiterStatus.PASS, undefinedMin, undefinedMax);
}
Expand Down Expand Up @@ -243,6 +242,7 @@ public PriceLimiterCheckResult check(@NotNull QUser user, @NotNull ItemStack ite

double minPrice = 0;
double maxPrice = 0;
boolean hasMinPrice = false;
boolean hasMaxPrice = false;
final List<ItemStack> flattenedItems = ItemContainerUtil.flattenContents(itemStack, true, false);

Expand All @@ -260,6 +260,7 @@ public PriceLimiterCheckResult check(@NotNull QUser user, @NotNull ItemStack ite
}

if (rule.hasMinPrice()) {
hasMinPrice = true;
minPrice += rule.getMin() * itemTally;
}
if (rule.hasMaxPrice()) {
Expand All @@ -268,14 +269,11 @@ public PriceLimiterCheckResult check(@NotNull QUser user, @NotNull ItemStack ite
}
}

if (price < minPrice || (hasMaxPrice && price > maxPrice)) {
return new SimplePriceLimiterCheckResult(PriceLimiterStatus.PRICE_RESTRICTED, minPrice, maxPrice);
}
if (undefinedMin != -1 && price < undefinedMin) {
return new SimplePriceLimiterCheckResult(PriceLimiterStatus.PRICE_RESTRICTED, undefinedMin, undefinedMax);
}
if (undefinedMax != -1 && price > undefinedMax) {
return new SimplePriceLimiterCheckResult(PriceLimiterStatus.PRICE_RESTRICTED, undefinedMin, undefinedMax);
if ((hasMinPrice && price < minPrice) || (hasMaxPrice && price > maxPrice)
|| (undefinedMin > 0 && price < undefinedMin) || (undefinedMax >= 0 && price > undefinedMax)) {
return new SimplePriceLimiterCheckResult(PriceLimiterStatus.PRICE_RESTRICTED,
hasMinPrice ? minPrice : undefinedMin,
hasMaxPrice ? maxPrice : undefinedMax);
}
return new SimplePriceLimiterCheckResult(PriceLimiterStatus.PASS, undefinedMin, undefinedMax);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@
import com.ghostchu.quickshop.obj.QUserImpl;
import com.ghostchu.quickshop.shop.inventory.BukkitInventoryWrapper;
import com.ghostchu.quickshop.shop.inventory.BukkitInventoryWrapperManager;
import com.ghostchu.quickshop.util.ChatSheetPrinter;
import com.ghostchu.quickshop.util.MsgUtil;
import com.ghostchu.quickshop.util.PackageUtil;
import com.ghostchu.quickshop.util.Util;
import com.ghostchu.quickshop.util.*;
import com.ghostchu.quickshop.util.holder.Result;
import com.ghostchu.quickshop.util.logger.Log;
import com.ghostchu.simplereloadlib.ReloadResult;
Expand Down Expand Up @@ -567,14 +564,34 @@ public void createShop(@NotNull Shop shop, @Nullable Block signBlock, boolean by
}

// Price limit checking
PriceLimiterCheckResult priceCheckResult = this.priceLimiter.check(p, shop.getItem(), plugin.getCurrency(), shop.getPrice());
switch (priceCheckResult.getStatus()) {
final PriceLimiterCheckResult priceResult = this.priceLimiter.check(p, shop.getItem(), plugin.getCurrency(), shop.getPrice());

final String currency = shop.getCurrency() == null ? (plugin.getCurrency() == null ? "" : plugin.getCurrency()) : shop.getCurrency();
final World world = shop.getLocation().getWorld();
final AbstractEconomy econ = plugin.getEconomy();

final double min = priceResult.getMin();
final double max = priceResult.getMax();
final String minFormatted = econ != null ? econ.format(min, world, currency) : String.valueOf(min);
final String maxFormatted = econ != null ? econ.format(max, world, currency) : String.valueOf(max);

switch (priceResult.getStatus()) {
case REACHED_PRICE_MIN_LIMIT ->
plugin.text().of(p, "price-too-cheap", Component.text((useDecFormat) ? MsgUtil.decimalFormat(priceCheckResult.getMax()) : Double.toString(priceCheckResult.getMin()))).send();
plugin.text().of(p, "price-too-cheap", minFormatted).send();
case REACHED_PRICE_MAX_LIMIT ->
plugin.text().of(p, "price-too-high", Component.text((useDecFormat) ? MsgUtil.decimalFormat(priceCheckResult.getMax()) : Double.toString(priceCheckResult.getMin()))).send();
case PRICE_RESTRICTED ->
plugin.text().of(p, "restricted-prices", Util.getItemStackName(shop.getItem()), Component.text(priceCheckResult.getMin()), Component.text(priceCheckResult.getMax())).send();
plugin.text().of(p, "price-too-high", maxFormatted).send();
case PRICE_RESTRICTED -> {
if (min > 0 && max >= 0) {
plugin.text().of(p, "restricted-prices",
Util.getItemStackName(shop.getItem()), minFormatted, maxFormatted).send();
} else if (min > 0) {
plugin.text().of(p, "restricted-price-min",
Util.getItemStackName(shop.getItem()), minFormatted).send();
} else {
plugin.text().of(p, "restricted-price-max",
Util.getItemStackName(shop.getItem()), maxFormatted).send();
}
}
case NOT_VALID -> plugin.text().of(p, "not-a-number", shop.getPrice()).send();
case NOT_A_WHOLE_NUMBER -> plugin.text().of(p, "not-a-integer", shop.getPrice()).send();
case PASS -> {
Expand All @@ -595,7 +612,7 @@ public void createShop(@NotNull Shop shop, @Nullable Block signBlock, boolean by
if (createCost > 0) {
SimpleEconomyTransaction economyTransaction = SimpleEconomyTransaction.builder().taxAccount(cacheTaxAccount).taxModifier(0.0).core(plugin.getEconomy()).from(QUserImpl.createFullFilled(p)).to(null).amount(createCost).currency(plugin.getCurrency()).world(shop.getLocation().getWorld()).build();
if (!economyTransaction.checkBalance()) {
plugin.text().of(p, "you-cant-afford-a-new-shop", format(createCost, shop.getLocation().getWorld(), shop.getCurrency())).send();
plugin.text().of(p, "you-cant-afford-a-new-shop", format(createCost, shop)).send();
return;
}
if (!economyTransaction.failSafeCommit()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

import com.ghostchu.quickshop.QuickShop;
import com.ghostchu.quickshop.api.economy.AbstractEconomy;
import com.ghostchu.quickshop.api.event.ShopOwnershipTransferEvent;
import com.ghostchu.quickshop.api.event.ShopPriceChangeEvent;
import com.ghostchu.quickshop.api.obj.QUser;
Expand All @@ -29,8 +30,8 @@
import com.ghostchu.quickshop.obj.QUserImpl;
import com.ghostchu.quickshop.util.logger.Log;
import lombok.Data;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -79,8 +80,6 @@ public static void setPrice(final QuickShop plugin, @NotNull QUser user, final d
return;
}

final boolean format = plugin.getConfig().getBoolean("use-decimal-format");

double fee = 0;

if (plugin.isPriceChangeRequiresFee()) {
Expand All @@ -103,19 +102,35 @@ public static void setPrice(final QuickShop plugin, @NotNull QUser user, final d

final PriceLimiterCheckResult checkResult = limiter.check(user, shop.getItem(), plugin.getCurrency(), price);

final String currency = shop.getCurrency() == null ? (plugin.getCurrency() == null ? "" : plugin.getCurrency()) : shop.getCurrency();
final World world = shop.getLocation().getWorld();
final AbstractEconomy econ = plugin.getEconomy();

final double min = checkResult.getMin();
final double max = checkResult.getMax();
final String minFormatted = econ != null ? econ.format(min, world, currency) : String.valueOf(min);
final String maxFormatted = econ != null ? econ.format(max, world, currency) : String.valueOf(max);

switch (checkResult.getStatus()) {
case PRICE_RESTRICTED -> {
plugin.text().of(user.getUniqueId(), "restricted-prices", Util.getItemStackName(shop.getItem()),
Component.text(checkResult.getMin()),
Component.text(checkResult.getMax())).send();
if (min > 0 && max >= 0) {
plugin.text().of(user.getUniqueId(), "restricted-prices",
Util.getItemStackName(shop.getItem()), minFormatted, maxFormatted).send();
} else if (min > 0) {
plugin.text().of(user.getUniqueId(), "restricted-price-min",
Util.getItemStackName(shop.getItem()), minFormatted).send();
} else {
plugin.text().of(user.getUniqueId(), "restricted-price-max",
Util.getItemStackName(shop.getItem()), maxFormatted).send();
}
return;
}
case REACHED_PRICE_MIN_LIMIT -> {
plugin.text().of(user, "price-too-cheap", (format) ? MsgUtil.decimalFormat(checkResult.getMin()) : Double.toString(checkResult.getMin())).send();
plugin.text().of(user, "price-too-cheap", minFormatted).send();
return;
}
case REACHED_PRICE_MAX_LIMIT -> {
plugin.text().of(user, "price-too-high", (format) ? MsgUtil.decimalFormat(checkResult.getMax()) : Double.toString(checkResult.getMax())).send();
plugin.text().of(user, "price-too-high", maxFormatted).send();
return;
}
case NOT_A_WHOLE_NUMBER -> {
Expand Down
2 changes: 2 additions & 0 deletions quickshop-bukkit/src/main/resources/lang/messages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,8 @@ support-disable-reason:
supertool-is-disabled: <red>Super tool is disabled. Cannot break any shops.
unknown-owner: Unknown
restricted-prices: '<red>Restricted price for {0}: Min {1}, max {2}'
restricted-price-max: '<red>Restricted price for {0}: Max {1}'
restricted-price-min: '<red>Restricted price for {0}: Min {1}'
nearby-shop-this-way: <green>Shop is {0} block(s) away from you.
owner-bypass-check: <yellow>Bypassed all checks. Trade successful! (You are now the
shop owner!)
Expand Down
2 changes: 1 addition & 1 deletion quickshop-bukkit/src/main/resources/price-restriction.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 3
whole-number-only: false # This option not control by enable option, always enabled
undefined: # This option not control by enable option, always enabled
min: 0.01 # Can be zero if you want player create a free shop
max: 999999999999999999999999999999.99 # Actually this can be up to 1.7976931348623157E308
max: -1 # This can be up to 1.7976931348623157E308, or -1 to disable maximum price.
enable: false
rules: # Rules set
example: # Rules name, used for identifier and permission node (quickshop.price.restriction.bypass.<name>)
Expand Down