Re-did the min price system, now called price limits

Took 57 minutes
This commit is contained in:
Kiran Hart 2024-10-09 14:06:43 -04:00
parent 215fe5f26d
commit b4649399e2
No known key found for this signature in database
GPG Key ID: 5F36C7BC79D3EBC3
26 changed files with 670 additions and 343 deletions

View File

@ -87,6 +87,7 @@ public class AuctionHouse extends TweetyPlugin {
private final GuiManager guiManager = new GuiManager(this); private final GuiManager guiManager = new GuiManager(this);
private final ListingManager listingManager = new ListingManager(); private final ListingManager listingManager = new ListingManager();
private final CategoryManager categoryManager = new CategoryManager(); private final CategoryManager categoryManager = new CategoryManager();
private final PriceLimitManager priceLimitManager = new PriceLimitManager();
private final AuctionPlayerManager auctionPlayerManager = new AuctionPlayerManager(); private final AuctionPlayerManager auctionPlayerManager = new AuctionPlayerManager();
private final AuctionItemManager auctionItemManager = new AuctionItemManager(); private final AuctionItemManager auctionItemManager = new AuctionItemManager();
@ -94,7 +95,6 @@ public class AuctionHouse extends TweetyPlugin {
private final FilterManager filterManager = new FilterManager(); private final FilterManager filterManager = new FilterManager();
private final BanManager banManager = new BanManager(); private final BanManager banManager = new BanManager();
private final AuctionStatisticManager auctionStatisticManager = new AuctionStatisticManager(); private final AuctionStatisticManager auctionStatisticManager = new AuctionStatisticManager();
private final MinItemPriceManager minItemPriceManager = new MinItemPriceManager();
private final PaymentsManager paymentsManager = new PaymentsManager(); private final PaymentsManager paymentsManager = new PaymentsManager();
private AuctionHouseAPI API; private AuctionHouseAPI API;
@ -116,11 +116,6 @@ public class AuctionHouse extends TweetyPlugin {
@Getter @Getter
private UpdateChecker.UpdateStatus status; private UpdateChecker.UpdateStatus status;
@Override
public void onPluginLoad() {
}
@Override @Override
public void onPluginEnable() { public void onPluginEnable() {
TweetyCore.registerPlugin(this, 1, "CHEST"); TweetyCore.registerPlugin(this, 1, "CHEST");
@ -190,7 +185,8 @@ public class AuctionHouse extends TweetyPlugin {
new _26_MultiSerAndCurrencyMigration(), new _26_MultiSerAndCurrencyMigration(),
new _27_FixMigration25to26Migration(), new _27_FixMigration25to26Migration(),
new _28_PriorityListingMigration(), new _28_PriorityListingMigration(),
new _29_PaymentMultiCurrencyMigration() new _29_PaymentMultiCurrencyMigration(),
new _30_MinMaxItemPriceMigration()
); );
dataMigrationManager.runMigrations(); dataMigrationManager.runMigrations();
@ -204,6 +200,7 @@ public class AuctionHouse extends TweetyPlugin {
this.banManager.load(); this.banManager.load();
this.currencyManager.load(); this.currencyManager.load();
this.paymentsManager.load(); this.paymentsManager.load();
this.priceLimitManager.load();
// listeners // listeners
Bukkit.getServer().getPluginManager().registerEvents(new PlayerListeners(), this); Bukkit.getServer().getPluginManager().registerEvents(new PlayerListeners(), this);
@ -219,7 +216,6 @@ public class AuctionHouse extends TweetyPlugin {
this.auctionItemManager.start(); this.auctionItemManager.start();
this.transactionManager.loadTransactions(); this.transactionManager.loadTransactions();
this.filterManager.loadItems(); this.filterManager.loadItems();
this.minItemPriceManager.loadMinPrices();
this.auctionStatisticManager.loadStatistics(); this.auctionStatisticManager.loadStatistics();
this.auctionPlayerManager.loadPlayers(); this.auctionPlayerManager.loadPlayers();
@ -240,7 +236,7 @@ public class AuctionHouse extends TweetyPlugin {
new CommandUnban(), new CommandUnban(),
new CommandMarkChest(), new CommandMarkChest(),
new CommandUpload(), new CommandUpload(),
new CommandMinPrice(), new CommandPriceLimit(),
new CommandStats(), new CommandStats(),
new CommandPayments(), new CommandPayments(),
new CommandBids(), new CommandBids(),
@ -347,6 +343,10 @@ public class AuctionHouse extends TweetyPlugin {
return (AuctionHouse) TweetyPlugin.getInstance(); return (AuctionHouse) TweetyPlugin.getInstance();
} }
@Override
public void onPluginLoad() {
}
public static AuctionHouseAPI getAPI() { public static AuctionHouseAPI getAPI() {
return getInstance().API; return getInstance().API;
} }
@ -391,8 +391,8 @@ public class AuctionHouse extends TweetyPlugin {
return getInstance().auctionStatisticManager; return getInstance().auctionStatisticManager;
} }
public static MinItemPriceManager getMinItemPriceManager() { public static PriceLimitManager getPriceLimitManager() {
return getInstance().minItemPriceManager; return getInstance().priceLimitManager;
} }
public static PaymentsManager getPaymentsManager() { public static PaymentsManager getPaymentsManager() {

View File

@ -19,9 +19,9 @@
package ca.tweetzy.auctionhouse.api; package ca.tweetzy.auctionhouse.api;
import ca.tweetzy.auctionhouse.AuctionHouse; import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.api.auction.ListingPriceLimit;
import ca.tweetzy.auctionhouse.auction.AuctionPayment; import ca.tweetzy.auctionhouse.auction.AuctionPayment;
import ca.tweetzy.auctionhouse.auction.AuctionedItem; import ca.tweetzy.auctionhouse.auction.AuctionedItem;
import ca.tweetzy.auctionhouse.auction.MinItemPrice;
import ca.tweetzy.auctionhouse.auction.enums.PaymentReason; import ca.tweetzy.auctionhouse.auction.enums.PaymentReason;
import ca.tweetzy.auctionhouse.settings.Settings; import ca.tweetzy.auctionhouse.settings.Settings;
import ca.tweetzy.core.compatibility.XMaterial; import ca.tweetzy.core.compatibility.XMaterial;
@ -612,14 +612,14 @@ public class AuctionAPI {
public boolean meetsMinItemPrice(boolean isUsingBundle, boolean isBiddingItem, ItemStack original, double basePrice, double bidStartPrice) { public boolean meetsMinItemPrice(boolean isUsingBundle, boolean isBiddingItem, ItemStack original, double basePrice, double bidStartPrice) {
boolean valid = true; boolean valid = true;
if (!AuctionHouse.getInstance().getMinItemPriceManager().getMinPrices().isEmpty() && !isUsingBundle) { if (!AuctionHouse.getPriceLimitManager().getManagerContent().isEmpty() && !isUsingBundle) {
final MinItemPrice foundMinPriceItem = AuctionHouse.getInstance().getMinItemPriceManager().getMinPrice(original); final ListingPriceLimit foundMinPriceItem = AuctionHouse.getPriceLimitManager().getPriceLimit(original);
if (foundMinPriceItem != null) { if (foundMinPriceItem != null) {
if (isBiddingItem) { if (isBiddingItem) {
if (basePrice < foundMinPriceItem.getPrice() || bidStartPrice < foundMinPriceItem.getPrice()) valid = false; if (basePrice < foundMinPriceItem.getMinPrice() || bidStartPrice < foundMinPriceItem.getMinPrice()) valid = false;
} else { } else {
if (basePrice < foundMinPriceItem.getPrice()) valid = false; if (basePrice < foundMinPriceItem.getMinPrice()) valid = false;
} }
} }
} }
@ -627,6 +627,27 @@ public class AuctionAPI {
return valid; return valid;
} }
public boolean isAtMaxItemPrice(boolean isUsingBundle, boolean isBiddingItem, ItemStack original, double basePrice, double bidStartPrice) {
boolean atLimit = false;
if (!AuctionHouse.getPriceLimitManager().getManagerContent().isEmpty() && !isUsingBundle) {
final ListingPriceLimit foundMinPriceItem = AuctionHouse.getPriceLimitManager().getPriceLimit(original);
if (foundMinPriceItem != null) {
if (foundMinPriceItem.getMaxPrice() == -1) {
return false;
}
if (isBiddingItem) {
if (basePrice > foundMinPriceItem.getMaxPrice() || bidStartPrice > foundMinPriceItem.getMaxPrice()) atLimit = true;
} else {
if (basePrice > foundMinPriceItem.getMaxPrice()) atLimit = true;
}
}
}
return atLimit;
}
public void logException(@Nullable Plugin plugin, @NotNull Throwable th) { public void logException(@Nullable Plugin plugin, @NotNull Throwable th) {
logException(plugin, th, null); logException(plugin, th, null);
} }

View File

@ -0,0 +1,23 @@
package ca.tweetzy.auctionhouse.api.auction;
import ca.tweetzy.auctionhouse.api.sync.*;
import lombok.NonNull;
import org.bukkit.inventory.ItemStack;
import java.util.UUID;
public interface ListingPriceLimit extends Identifiable<UUID>, Storeable<ListingPriceLimit>, Unstoreable<SynchronizeResult>, Synchronize {
ItemStack getItem();
void setItem(@NonNull ItemStack itemStack);
double getMinPrice();
void setMinPrice(final double minPrice);
double getMaxPrice();
void setMaxPrice(final double maxPrice);
}

View File

@ -32,6 +32,7 @@ public enum ListingResult {
CANNOT_SELL_BUNDLE_ITEM, CANNOT_SELL_BUNDLE_ITEM,
MINIMUM_PRICE_NOT_MET, MINIMUM_PRICE_NOT_MET,
ABOVE_MAXIMUM_PRICE,
UNKNOWN, UNKNOWN,
EVENT_CANCELED EVENT_CANCELED

View File

@ -5,7 +5,6 @@ import ca.tweetzy.auctionhouse.api.sync.Identifiable;
import ca.tweetzy.flight.comp.enums.CompMaterial; import ca.tweetzy.flight.comp.enums.CompMaterial;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import java.util.HashSet; import java.util.HashSet;
@ -106,7 +105,7 @@ public interface ItemCategory extends Identifiable<String> {
for (CategoryCondition condition : getConditions()) { for (CategoryCondition condition : getConditions()) {
final CategoryConditionType conditionType = condition.getType(); final CategoryConditionType conditionType = condition.getType();
final CategoryStringComparison stringComparison = condition.getComparisonType(); final CategoryStringComparison stringComparison = condition.getComparisonType();
final String value = condition.getValue(); final String value = condition.getValue();
switch (stringComparison) { switch (stringComparison) {
case STARTS_WITH: case STARTS_WITH:

View File

@ -35,7 +35,6 @@ import ca.tweetzy.flight.utils.Replacer;
import lombok.Getter; import lombok.Getter;
import lombok.NonNull; import lombok.NonNull;
import lombok.Setter; import lombok.Setter;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;

View File

@ -1,115 +0,0 @@
/*
* Auction House
* Copyright 2018-2022 Kiran Hart
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package ca.tweetzy.auctionhouse.commands;
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.api.AuctionAPI;
import ca.tweetzy.auctionhouse.auction.MinItemPrice;
import ca.tweetzy.auctionhouse.guis.admin.GUIMinItemPrices;
import ca.tweetzy.auctionhouse.helpers.PlayerHelper;
import ca.tweetzy.auctionhouse.settings.Settings;
import ca.tweetzy.core.compatibility.XMaterial;
import ca.tweetzy.core.utils.NumberUtils;
import ca.tweetzy.flight.command.AllowedExecutor;
import ca.tweetzy.flight.command.Command;
import ca.tweetzy.flight.command.ReturnType;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.Collections;
import java.util.List;
/**
* The current file has been created by Kiran Hart
* Date Created: June 22 2021
* Time Created: 3:18 p.m.
* Usage of any code found within this class is prohibited unless given explicit permission otherwise
*/
public class CommandMinPrice extends Command {
public CommandMinPrice() {
super(AllowedExecutor.PLAYER, Settings.CMD_ALIAS_SUB_MINPRICE.getStringList().toArray(new String[0]));
}
@Override
protected ReturnType execute(CommandSender sender, String... args) {
final Player player = (Player) sender;
// if (CommandMiddleware.handle(player) == ReturnType.FAIL) return ReturnType.FAIL;
if (args.length == 0) {
AuctionHouse.getGuiManager().showGUI(player, new GUIMinItemPrices(player));
return ReturnType.SUCCESS;
}
if (args.length == 2 && args[0].equalsIgnoreCase("add")) {
ItemStack held = PlayerHelper.getHeldItem(player);
if (held.getType() == XMaterial.AIR.parseMaterial()) {
AuctionHouse.getInstance().getLocale().getMessage("general.min item price air").sendPrefixedMessage(player);
return ReturnType.FAIL;
}
if (AuctionHouse.getMinItemPriceManager().getMinPrice(held.clone()) != null) {
AuctionHouse.getInstance().getLocale().getMessage("general.min price already added").sendPrefixedMessage(player);
return ReturnType.FAIL;
}
if (!NumberUtils.isNumeric(args[1])) {
AuctionHouse.getInstance().getLocale().getMessage("general.notanumber").processPlaceholder("value", args[1]).sendPrefixedMessage(player);
return ReturnType.FAIL;
}
final double price = Double.parseDouble(args[1]);
AuctionHouse.getDataManager().insertMinPrice(new MinItemPrice(held.clone(), price), (error, inserted) -> {
if (error == null) {
AuctionHouse.getMinItemPriceManager().addItem(inserted);
AuctionHouse.getInstance().getLocale().getMessage("general.added min price")
.processPlaceholder("item", AuctionAPI.getInstance().getItemName(inserted.getItemStack()))
.processPlaceholder("price", AuctionHouse.getAPI().getNumberAsCurrency(inserted.getPrice(), false))
.sendPrefixedMessage(player);
}
});
}
return ReturnType.SUCCESS;
}
@Override
public String getPermissionNode() {
return "auctionhouse.cmd.minprice";
}
@Override
public String getSyntax() {
return AuctionHouse.getInstance().getLocale().getMessage("commands.syntax.min price").getMessage();
}
@Override
public String getDescription() {
return AuctionHouse.getInstance().getLocale().getMessage("commands.description.min price").getMessage();
}
@Override
protected List<String> tab(CommandSender sender, String... args) {
if (args.length == 1) return Collections.singletonList("add");
return null;
}
}

View File

@ -0,0 +1,154 @@
/*
* Auction House
* Copyright 2018-2022 Kiran Hart
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package ca.tweetzy.auctionhouse.commands;
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.api.auction.ListingPriceLimit;
import ca.tweetzy.auctionhouse.guis.admin.GUIPriceLimits;
import ca.tweetzy.auctionhouse.helpers.PlayerHelper;
import ca.tweetzy.auctionhouse.impl.AuctionPriceLimit;
import ca.tweetzy.auctionhouse.settings.Settings;
import ca.tweetzy.core.utils.NumberUtils;
import ca.tweetzy.flight.command.AllowedExecutor;
import ca.tweetzy.flight.command.Command;
import ca.tweetzy.flight.command.ReturnType;
import ca.tweetzy.flight.comp.enums.CompMaterial;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
/**
* The current file has been created by Kiran Hart
* Date Created: June 22 2021
* Time Created: 3:18 p.m.
* Usage of any code found within this class is prohibited unless given explicit permission otherwise
*/
public class CommandPriceLimit extends Command {
public CommandPriceLimit() {
super(AllowedExecutor.PLAYER, Settings.CMD_ALIAS_SUB_PRICE_LIMIT.getStringList().toArray(new String[0]));
}
@Override
protected ReturnType execute(CommandSender sender, String... args) {
final Player player = (Player) sender;
if (args.length == 0) {
AuctionHouse.getGuiManager().showGUI(player, new GUIPriceLimits(player));
return ReturnType.SUCCESS;
}
if (args.length == 3 && args[0].equalsIgnoreCase("set")) {
// if (!args[1].equalsIgnoreCase("min") || !args[1].equalsIgnoreCase("max")) return ReturnType.INVALID_SYNTAX;
ItemStack held = PlayerHelper.getHeldItem(player);
if (held.getType() == CompMaterial.AIR.parseMaterial()) {
AuctionHouse.getInstance().getLocale().getMessage("general.min item price air").sendPrefixedMessage(player);
return ReturnType.FAIL;
}
ListingPriceLimit listingPriceLimit = AuctionHouse.getPriceLimitManager().getPriceLimit(held.clone());
if (!NumberUtils.isNumeric(args[2])) {
AuctionHouse.getInstance().getLocale().getMessage("general.notanumber").processPlaceholder("value", args[2]).sendPrefixedMessage(player);
return ReturnType.FAIL;
}
final double price = Double.parseDouble(args[2]);
boolean requiresCreate = false;
if (listingPriceLimit != null) {
switch (args[1]) {
case "min":
listingPriceLimit.setMinPrice(price);
break;
case "max":
listingPriceLimit.setMaxPrice(price);
break;
}
} else {
requiresCreate = true;
switch (args[1]) {
case "min":
listingPriceLimit = new AuctionPriceLimit(
UUID.randomUUID(),
held,
price,
-1
);
break;
case "max":
listingPriceLimit = new AuctionPriceLimit(
UUID.randomUUID(),
held,
Settings.MIN_AUCTION_PRICE.getDouble(),
price
);
break;
}
}
if (requiresCreate) {
// run store
listingPriceLimit.store(stored -> {
if (stored != null) {
AuctionHouse.getInstance().getLocale().getMessage("pricing.limit.added price limit").sendPrefixedMessage(player);
}
});
} else {
// run update
listingPriceLimit.sync(success -> {
if (success) {
AuctionHouse.getInstance().getLocale().getMessage("pricing.limit.updated price limit").sendPrefixedMessage(player);
}
});
}
}
return ReturnType.SUCCESS;
}
@Override
public String getPermissionNode() {
return "auctionhouse.cmd.pricelimit";
}
@Override
public String getSyntax() {
return AuctionHouse.getInstance().getLocale().getMessage("commands.syntax.price limit").getMessage();
}
@Override
public String getDescription() {
return AuctionHouse.getInstance().getLocale().getMessage("commands.description.price limit").getMessage();
}
@Override
protected List<String> tab(CommandSender sender, String... args) {
if (args.length == 1) return Collections.singletonList("set");
if (args.length == 2) return Arrays.asList("min", "max");
return null;
}
}

View File

@ -36,13 +36,11 @@ import ca.tweetzy.flight.command.AllowedExecutor;
import ca.tweetzy.flight.command.Command; import ca.tweetzy.flight.command.Command;
import ca.tweetzy.flight.command.ReturnType; import ca.tweetzy.flight.command.ReturnType;
import ca.tweetzy.flight.comp.enums.ServerVersion; import ca.tweetzy.flight.comp.enums.ServerVersion;
import net.minecraft.references.Blocks;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.ShulkerBox; import org.bukkit.block.ShulkerBox;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.Shulker;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BlockStateMeta; import org.bukkit.inventory.meta.BlockStateMeta;

View File

@ -224,7 +224,15 @@ public final class CommandSell extends Command {
if (!isBiddingItem) { if (!isBiddingItem) {
if (!AuctionAPI.getInstance().meetsMinItemPrice(isBundle, isBiddingItem, originalItem, buyNowPrice, isBiddingItem ? startingBid : 0)) { if (!AuctionAPI.getInstance().meetsMinItemPrice(isBundle, isBiddingItem, originalItem, buyNowPrice, isBiddingItem ? startingBid : 0)) {
AuctionHouse.getInstance().getLocale().getMessage("pricing.minitemprice") AuctionHouse.getInstance().getLocale().getMessage("pricing.minitemprice")
.processPlaceholder("price", AuctionHouse.getAPI().getNumberAsCurrency(AuctionHouse.getMinItemPriceManager().getMinPrice(originalItem).getPrice())) .processPlaceholder("price", AuctionHouse.getAPI().getNumberAsCurrency(AuctionHouse.getPriceLimitManager().getPriceLimit(originalItem).getMinPrice()))
.sendPrefixedMessage(player);
return ReturnType.FAIL;
}
if (AuctionAPI.getInstance().isAtMaxItemPrice(isBundle, isBiddingItem, originalItem, buyNowPrice, isBiddingItem ? startingBid : 0)) {
AuctionHouse.getInstance().getLocale().getMessage("pricing.maxitemprice")
.processPlaceholder("price", AuctionHouse.getAPI().getNumberAsCurrency(AuctionHouse.getPriceLimitManager().getPriceLimit(originalItem).getMaxPrice()))
.sendPrefixedMessage(player); .sendPrefixedMessage(player);
return ReturnType.FAIL; return ReturnType.FAIL;
@ -237,7 +245,15 @@ public final class CommandSell extends Command {
if (isBiddingItem && startingBid != null) { if (isBiddingItem && startingBid != null) {
if (!AuctionAPI.getInstance().meetsMinItemPrice(isBundle, isBiddingItem, originalItem, buyNowPrice, isBiddingItem ? startingBid : 0)) { if (!AuctionAPI.getInstance().meetsMinItemPrice(isBundle, isBiddingItem, originalItem, buyNowPrice, isBiddingItem ? startingBid : 0)) {
AuctionHouse.getInstance().getLocale().getMessage("pricing.minitemprice") AuctionHouse.getInstance().getLocale().getMessage("pricing.minitemprice")
.processPlaceholder("price", AuctionHouse.getAPI().getNumberAsCurrency(AuctionHouse.getMinItemPriceManager().getMinPrice(originalItem).getPrice())) .processPlaceholder("price", AuctionHouse.getAPI().getNumberAsCurrency(AuctionHouse.getPriceLimitManager().getPriceLimit(originalItem).getMinPrice()))
.sendPrefixedMessage(player);
return ReturnType.FAIL;
}
if (AuctionAPI.getInstance().isAtMaxItemPrice(isBundle, isBiddingItem, originalItem, buyNowPrice, isBiddingItem ? startingBid : 0)) {
AuctionHouse.getInstance().getLocale().getMessage("pricing.maxitemprice")
.processPlaceholder("price", AuctionHouse.getAPI().getNumberAsCurrency(AuctionHouse.getPriceLimitManager().getPriceLimit(originalItem).getMaxPrice()))
.sendPrefixedMessage(player); .sendPrefixedMessage(player);
return ReturnType.FAIL; return ReturnType.FAIL;

View File

@ -20,12 +20,14 @@ package ca.tweetzy.auctionhouse.database;
import ca.tweetzy.auctionhouse.AuctionHouse; import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.api.AuctionAPI; import ca.tweetzy.auctionhouse.api.AuctionAPI;
import ca.tweetzy.auctionhouse.api.auction.ListingPriceLimit;
import ca.tweetzy.auctionhouse.api.ban.Ban; import ca.tweetzy.auctionhouse.api.ban.Ban;
import ca.tweetzy.auctionhouse.api.ban.BanType; import ca.tweetzy.auctionhouse.api.ban.BanType;
import ca.tweetzy.auctionhouse.api.statistic.Statistic; import ca.tweetzy.auctionhouse.api.statistic.Statistic;
import ca.tweetzy.auctionhouse.auction.*; import ca.tweetzy.auctionhouse.auction.*;
import ca.tweetzy.auctionhouse.auction.enums.*; import ca.tweetzy.auctionhouse.auction.enums.*;
import ca.tweetzy.auctionhouse.impl.AuctionBan; import ca.tweetzy.auctionhouse.impl.AuctionBan;
import ca.tweetzy.auctionhouse.impl.AuctionPriceLimit;
import ca.tweetzy.auctionhouse.impl.AuctionStatistic; import ca.tweetzy.auctionhouse.impl.AuctionStatistic;
import ca.tweetzy.auctionhouse.settings.Settings; import ca.tweetzy.auctionhouse.settings.Settings;
import ca.tweetzy.auctionhouse.transaction.Transaction; import ca.tweetzy.auctionhouse.transaction.Transaction;
@ -590,22 +592,26 @@ public class DataManager extends DataManagerAbstract {
})); }));
} }
public void insertMinPrice(MinItemPrice item, Callback<MinItemPrice> callback) { //=================================================================================================//
// LISTING PRICE LIMITS //
//=================================================================================================//
public void insertListingPriceLimit(ListingPriceLimit priceLimit, Callback<ListingPriceLimit> callback) {
this.runAsync(() -> this.databaseConnector.connect(connection -> { this.runAsync(() -> this.databaseConnector.connect(connection -> {
try (PreparedStatement statement = connection.prepareStatement("INSERT INTO " + this.getTablePrefix() + "min_item_prices (id, item, price, serialize_version, itemstack) VALUES(?, ?, ?, ?, ?)")) { try (PreparedStatement statement = connection.prepareStatement("INSERT INTO " + this.getTablePrefix() + "listing_prices (id, item, min_price, max_price, serialize_version, itemstack) VALUES(?, ?, ?, ?, ?, ?)")) {
PreparedStatement fetch = connection.prepareStatement("SELECT * FROM " + this.getTablePrefix() + "min_item_prices WHERE id = ?"); PreparedStatement fetch = connection.prepareStatement("SELECT * FROM " + this.getTablePrefix() + "listing_prices WHERE id = ?");
fetch.setString(1, item.getUuid().toString()); fetch.setString(1, priceLimit.getId().toString());
statement.setString(1, item.getUuid().toString()); statement.setString(1, priceLimit.getId().toString());
statement.setString(2, AuctionAPI.encodeItem(item.getItemStack())); statement.setString(2, AuctionAPI.encodeItem(priceLimit.getItem()));
statement.setDouble(3, item.getPrice()); statement.setDouble(3, priceLimit.getMinPrice());
statement.setDouble(4, priceLimit.getMaxPrice());
try { try {
statement.setInt(4, 1); statement.setInt(5, 1);
statement.setString(5, QuickItem.toString(item.getItemStack())); statement.setString(6, QuickItem.toString(priceLimit.getItem()));
} catch (NbtApiException e) { } catch (NbtApiException e) {
statement.setInt(4, 0); statement.setInt(5, 0);
statement.setString(5, null); statement.setString(6, null);
} }
@ -614,7 +620,7 @@ public class DataManager extends DataManagerAbstract {
if (callback != null) { if (callback != null) {
ResultSet res = fetch.executeQuery(); ResultSet res = fetch.executeQuery();
res.next(); res.next();
callback.accept(null, extractMinItemPrice(res)); callback.accept(null, extractListingPriceLimit(res));
} }
} catch (Exception e) { } catch (Exception e) {
@ -624,20 +630,20 @@ public class DataManager extends DataManagerAbstract {
})); }));
} }
public void getMinItemPrices(Callback<ArrayList<MinItemPrice>> callback) { public void getListingPriceLimits(Callback<ArrayList<ListingPriceLimit>> callback) {
ArrayList<MinItemPrice> minItemPrices = new ArrayList<>(); ArrayList<ListingPriceLimit> listingPriceLimits = new ArrayList<>();
this.runAsync(() -> this.databaseConnector.connect(connection -> { this.runAsync(() -> this.databaseConnector.connect(connection -> {
try (PreparedStatement statement = connection.prepareStatement("SELECT * FROM " + this.getTablePrefix() + "min_item_prices")) { try (PreparedStatement statement = connection.prepareStatement("SELECT * FROM " + this.getTablePrefix() + "listing_prices")) {
ResultSet resultSet = statement.executeQuery(); ResultSet resultSet = statement.executeQuery();
while (resultSet.next()) { while (resultSet.next()) {
final MinItemPrice minItemPrice = extractMinItemPrice(resultSet); final ListingPriceLimit listingPrice = extractListingPriceLimit(resultSet);
if (minItemPrice == null || minItemPrice.getItemStack() == null || minItemPrice.getItemStack().getType() == CompMaterial.AIR.parseMaterial()) continue; if (listingPrice == null || listingPrice.getItem() == null || listingPrice.getItem().getType() == CompMaterial.AIR.parseMaterial()) continue;
if (resultSet.getInt("serialize_version") == 0) { if (resultSet.getInt("serialize_version") == 0) {
try (PreparedStatement updateStatement = connection.prepareStatement("UPDATE " + this.getTablePrefix() + "min_item_prices SET serialize_version = 1, itemstack = ? WHERE id = ?")) { try (PreparedStatement updateStatement = connection.prepareStatement("UPDATE " + this.getTablePrefix() + "listing_prices SET serialize_version = 1, itemstack = ? WHERE id = ?")) {
try { try {
String possible = QuickItem.toString(minItemPrice.getItemStack()); String possible = QuickItem.toString(listingPrice.getItem());
updateStatement.setString(1, possible); updateStatement.setString(1, possible);
updateStatement.setString(2, resultSet.getString("id")); updateStatement.setString(2, resultSet.getString("id"));
updateStatement.executeUpdate(); updateStatement.executeUpdate();
@ -646,29 +652,50 @@ public class DataManager extends DataManagerAbstract {
} }
} }
minItemPrices.add(minItemPrice); listingPriceLimits.add(listingPrice);
} }
callback.accept(null, minItemPrices); callback.accept(null, listingPriceLimits);
} catch (Exception e) { } catch (Exception e) {
resolveCallback(callback, e); resolveCallback(callback, e);
} }
})); }));
} }
public void deleteMinItemPrice(Collection<UUID> minPrices) { public void deleteListingPriceLimit(@NonNull final UUID uuid, Callback<Boolean> callback) {
this.runAsync(() -> this.databaseConnector.connect(connection -> { this.runAsync(() -> this.databaseConnector.connect(connection -> {
PreparedStatement statement = connection.prepareStatement("DELETE FROM " + this.getTablePrefix() + "min_item_prices WHERE id = ?"); try (PreparedStatement statement = connection.prepareStatement("DELETE FROM " + this.getTablePrefix() + "listing_prices WHERE id = ?")) {
for (UUID id : minPrices) { statement.setString(1, uuid.toString());
statement.setString(1, id.toString());
statement.addBatch(); int result = statement.executeUpdate();
callback.accept(null, result > 0);
} catch (Exception e) {
resolveCallback(callback, e);
} }
statement.executeBatch();
})); }));
} }
public void updateListingPriceLimit(@NonNull final ListingPriceLimit listingPriceLimit, Callback<Boolean> callback) {
this.runAsync(() -> this.databaseConnector.connect(connection -> {
try (PreparedStatement statement = connection.prepareStatement("UPDATE " + this.getTablePrefix() + "listing_prices SET min_price = ?, max_price = ? WHERE id = ?")) {
statement.setDouble(1, listingPriceLimit.getMinPrice());
statement.setDouble(2, listingPriceLimit.getMaxPrice());
statement.setString(3, listingPriceLimit.getId().toString());
int result = statement.executeUpdate();
if (callback != null)
callback.accept(null, result > 0);
} catch (Exception e) {
resolveCallback(callback, e);
}
}));
}
public void insertStatistic(Statistic statistic, Callback<Statistic> callback) { public void insertStatistic(Statistic statistic, Callback<Statistic> callback) {
this.runAsync(() -> this.databaseConnector.connect(connection -> { this.runAsync(() -> this.databaseConnector.connect(connection -> {
try (PreparedStatement statement = connection.prepareStatement("INSERT INTO " + this.getTablePrefix() + "statistic (uuid, stat_owner, stat_type, value, time) VALUES (?, ?, ?, ?, ?)")) { try (PreparedStatement statement = connection.prepareStatement("INSERT INTO " + this.getTablePrefix() + "statistic (uuid, stat_owner, stat_type, value, time) VALUES (?, ?, ?, ?, ?)")) {
@ -944,7 +971,7 @@ public class DataManager extends DataManagerAbstract {
); );
} }
private MinItemPrice extractMinItemPrice(ResultSet resultSet) throws SQLException { private ListingPriceLimit extractListingPriceLimit(ResultSet resultSet) throws SQLException {
String possibleItem = resultSet.getString("item"); String possibleItem = resultSet.getString("item");
if (possibleItem.contains("Head Database")) if (possibleItem.contains("Head Database"))
@ -952,10 +979,11 @@ public class DataManager extends DataManagerAbstract {
ItemStack item = resultSet.getInt("serialize_version") == 1 ? QuickItem.getItem(resultSet.getString("itemstack")) : AuctionAPI.decodeItem(possibleItem); ItemStack item = resultSet.getInt("serialize_version") == 1 ? QuickItem.getItem(resultSet.getString("itemstack")) : AuctionAPI.decodeItem(possibleItem);
return new MinItemPrice( return new AuctionPriceLimit(
UUID.fromString(resultSet.getString("id")), UUID.fromString(resultSet.getString("id")),
item, item,
resultSet.getDouble("price") resultSet.getDouble("min_price"),
resultSet.getDouble("max_price")
); );
} }

View File

@ -0,0 +1,38 @@
package ca.tweetzy.auctionhouse.database.migrations;
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.flight.database.DataMigration;
import ca.tweetzy.flight.database.MySQLConnector;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
public final class _30_MinMaxItemPriceMigration extends DataMigration {
public _30_MinMaxItemPriceMigration() {
super(30);
}
@Override
public void migrate(Connection connection, String tablePrefix) throws SQLException {
try (Statement statement = connection.createStatement()) {
// Rename table
if (AuctionHouse.getDatabaseConnector() instanceof MySQLConnector) {
statement.execute("ALTER TABLE " + tablePrefix + "min_item_prices RENAME TO " + tablePrefix + "listing_prices");
statement.execute("ALTER TABLE " + tablePrefix + "listing_prices CHANGE price min_price DOUBLE NOT NULL");
statement.execute("ALTER TABLE " + tablePrefix + "listing_prices ADD max_price DOUBLE NOT NULL DEFAULT -1");
} else {
statement.execute("DROP TABLE " + tablePrefix + "min_item_prices;");
statement.execute("CREATE TABLE IF NOT EXISTS " + tablePrefix + "listing_prices (" +
"id VARCHAR(36) PRIMARY KEY, " +
"item TEXT NOT NULL, " +
"itemstack TEXT NULL, " +
"serialize_version INTEGER DEFAULT 0, " +
"min_price DOUBLE NOT NULL, " +
"max_price DOUBLE NOT NULL DEFAULT -1" +
" )");
}
}
}
}

View File

@ -1,71 +0,0 @@
/*
* Auction House
* Copyright 2018-2022 Kiran Hart
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package ca.tweetzy.auctionhouse.guis.admin;
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.api.AuctionAPI;
import ca.tweetzy.auctionhouse.auction.MinItemPrice;
import ca.tweetzy.auctionhouse.guis.AuctionPagedGUI;
import ca.tweetzy.auctionhouse.settings.Settings;
import ca.tweetzy.core.gui.events.GuiClickEvent;
import ca.tweetzy.flight.utils.QuickItem;
import ca.tweetzy.flight.utils.Replacer;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.Collections;
import java.util.List;
/**
* Date Created: April 04 2022
* Time Created: 8:21 a.m.
*
* @author Kiran Hart
*/
public final class GUIMinItemPrices extends AuctionPagedGUI<MinItemPrice> {
public GUIMinItemPrices(Player player) {
super(null, player, Settings.GUI_MIN_ITEM_PRICES_TITLE.getString(), 6, AuctionHouse.getMinItemPriceManager().getMinPrices());
draw();
}
@Override
protected void drawFixed() {
applyBackExit();
}
@Override
protected ItemStack makeDisplayItem(MinItemPrice minItemPrice) {
final List<String> lore = AuctionAPI.getInstance().getItemLore(minItemPrice.getItemStack().clone());
lore.addAll(Settings.GUI_MIN_ITEM_PRICES_LORE.getStringList());
return QuickItem
.of(minItemPrice.getItemStack().clone())
.name(AuctionAPI.getInstance().getItemName(minItemPrice.getItemStack()))
.lore(this.player, Replacer.replaceVariables(lore, "price", AuctionHouse.getAPI().getNumberAsCurrency(minItemPrice.getPrice(), false)))
.make();
}
@Override
protected void onClick(MinItemPrice minItemPrice, GuiClickEvent event) {
AuctionHouse.getDataManager().deleteMinItemPrice(Collections.singletonList(minItemPrice.getUuid()));
AuctionHouse.getMinItemPriceManager().removeItem(minItemPrice);
event.manager.showGUI(event.player, new GUIMinItemPrices(event.player));
}
}

View File

@ -0,0 +1,153 @@
/*
* Auction House
* Copyright 2018-2022 Kiran Hart
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package ca.tweetzy.auctionhouse.guis.admin;
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.api.AuctionAPI;
import ca.tweetzy.auctionhouse.api.auction.ListingPriceLimit;
import ca.tweetzy.auctionhouse.api.sync.SynchronizeResult;
import ca.tweetzy.auctionhouse.guis.AuctionPagedGUI;
import ca.tweetzy.auctionhouse.helpers.input.TitleInput;
import ca.tweetzy.auctionhouse.settings.Settings;
import ca.tweetzy.core.gui.events.GuiClickEvent;
import ca.tweetzy.core.utils.NumberUtils;
import ca.tweetzy.flight.utils.QuickItem;
import ca.tweetzy.flight.utils.Replacer;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import java.util.List;
/**
* Date Created: April 04 2022
* Time Created: 8:21 a.m.
*
* @author Kiran Hart
*/
public final class GUIPriceLimits extends AuctionPagedGUI<ListingPriceLimit> {
public GUIPriceLimits(Player player) {
super(null, player, Settings.GUI_PRICE_LIMITS_TITLE.getString(), 6, AuctionHouse.getPriceLimitManager().getManagerContent());
draw();
}
@Override
protected void drawFixed() {
applyBackExit();
}
@Override
protected ItemStack makeDisplayItem(ListingPriceLimit listingPriceLimit) {
final List<String> lore = AuctionAPI.getInstance().getItemLore(listingPriceLimit.getItem().clone());
lore.addAll(Settings.GUI_PRICE_LIMITS_LORE.getStringList());
return QuickItem
.of(listingPriceLimit.getItem().clone())
.name(AuctionAPI.getInstance().getItemName(listingPriceLimit.getItem()))
.lore(this.player, Replacer.replaceVariables(lore,
"min_price", AuctionHouse.getAPI().getNumberAsCurrency(listingPriceLimit.getMinPrice(), false),
"max_price", AuctionHouse.getAPI().getNumberAsCurrency(listingPriceLimit.getMaxPrice(), false)
))
.make();
}
@Override
protected void onClick(ListingPriceLimit listingPriceLimit, GuiClickEvent event) {
if (event.clickType == ClickType.LEFT) {
new TitleInput(event.player, AuctionHouse.getInstance().getLocale().getMessage("titles.price limit.min.title").getMessage(), AuctionHouse.getInstance().getLocale().getMessage("titles.price limit.min.subtitle").getMessage()) {
@Override
public void onExit(Player player) {
event.manager.showGUI(player, GUIPriceLimits.this);
}
@Override
public boolean onResult(String string) {
string = ChatColor.stripColor(string);
if (!NumberUtils.isDouble(string)) {
AuctionHouse.getInstance().getLocale().getMessage("general.notanumber").processPlaceholder("value", string).sendPrefixedMessage(player);
return false;
}
double newPrice = Double.parseDouble(string);
if (Double.isNaN(newPrice)) {
AuctionHouse.getInstance().getLocale().getMessage("general.notanumber").processPlaceholder("value", string).sendPrefixedMessage(player);
return false;
}
listingPriceLimit.setMinPrice(newPrice);
listingPriceLimit.sync(success -> {
if (success)
event.manager.showGUI(event.player, new GUIPriceLimits(event.player));
});
return true;
}
};
}
if (event.clickType == ClickType.RIGHT) {
new TitleInput(event.player, AuctionHouse.getInstance().getLocale().getMessage("titles.price limit.max.title").getMessage(), AuctionHouse.getInstance().getLocale().getMessage("titles.price limit.max.subtitle").getMessage()) {
@Override
public void onExit(Player player) {
event.manager.showGUI(player, GUIPriceLimits.this);
}
@Override
public boolean onResult(String string) {
string = ChatColor.stripColor(string);
if (!NumberUtils.isDouble(string)) {
AuctionHouse.getInstance().getLocale().getMessage("general.notanumber").processPlaceholder("value", string).sendPrefixedMessage(player);
return false;
}
double newPrice = Double.parseDouble(string);
if (Double.isNaN(newPrice)) {
AuctionHouse.getInstance().getLocale().getMessage("general.notanumber").processPlaceholder("value", string).sendPrefixedMessage(player);
return false;
}
listingPriceLimit.setMaxPrice(newPrice);
listingPriceLimit.sync(success -> {
if (success)
event.manager.showGUI(event.player, new GUIPriceLimits(event.player));
});
return true;
}
};
}
if (event.clickType == ClickType.DROP) {
listingPriceLimit.unStore(result -> {
if (result == SynchronizeResult.SUCCESS)
event.manager.showGUI(event.player, new GUIPriceLimits(event.player));
});
}
}
}

View File

@ -19,7 +19,6 @@ import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType; import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -87,7 +86,7 @@ public final class GUICurrencyPicker extends AuctionPagedGUI<AbstractCurrency> {
quickItem.name(currency.getCurrencyName().equalsIgnoreCase("vault") ? "&a" + Settings.CURRENCY_VAULT_SYMBOL.getString() : "&e" + currency.getCurrencyName()); quickItem.name(currency.getCurrencyName().equalsIgnoreCase("vault") ? "&a" + Settings.CURRENCY_VAULT_SYMBOL.getString() : "&e" + currency.getCurrencyName());
} }
quickItem.lore(Replacer.replaceVariables(Settings.GUI_CURRENCY_PICKER_ITEMS_CURRENCY_LORE .getStringList(), "currency_owning_plugin", currency.getOwningPlugin())); quickItem.lore(Replacer.replaceVariables(Settings.GUI_CURRENCY_PICKER_ITEMS_CURRENCY_LORE.getStringList(), "currency_owning_plugin", currency.getOwningPlugin()));
return quickItem.make(); return quickItem.make();
} }

View File

@ -29,7 +29,6 @@ import ca.tweetzy.auctionhouse.helpers.AuctionCreator;
import ca.tweetzy.auctionhouse.helpers.input.TitleInput; import ca.tweetzy.auctionhouse.helpers.input.TitleInput;
import ca.tweetzy.auctionhouse.settings.Settings; import ca.tweetzy.auctionhouse.settings.Settings;
import ca.tweetzy.core.utils.NumberUtils; import ca.tweetzy.core.utils.NumberUtils;
import ca.tweetzy.flight.command.ReturnType;
import ca.tweetzy.flight.utils.QuickItem; import ca.tweetzy.flight.utils.QuickItem;
import ca.tweetzy.flight.utils.Replacer; import ca.tweetzy.flight.utils.Replacer;
import lombok.NonNull; import lombok.NonNull;

View File

@ -82,16 +82,26 @@ public final class AuctionCreator {
} }
} }
if (!auctionItem.isRequest()) if (!auctionItem.isRequest()) {
if (!AuctionAPI.getInstance().meetsMinItemPrice(BundleUtil.isBundledItem(auctionItem.getItem()), auctionItem.isBidItem(), auctionItem.getItem(), auctionItem.getBasePrice(), auctionItem.getBidStartingPrice())) { if (!AuctionAPI.getInstance().meetsMinItemPrice(BundleUtil.isBundledItem(auctionItem.getItem()), auctionItem.isBidItem(), auctionItem.getItem(), auctionItem.getBasePrice(), auctionItem.getBidStartingPrice())) {
instance.getLocale().getMessage("pricing.minitemprice") instance.getLocale().getMessage("pricing.minitemprice")
.processPlaceholder("price", AuctionHouse.getAPI().getNumberAsCurrency(AuctionHouse.getMinItemPriceManager().getMinPrice(auctionItem.getItem()).getPrice(), false)) .processPlaceholder("price", AuctionHouse.getAPI().getNumberAsCurrency(AuctionHouse.getPriceLimitManager().getPriceLimit(auctionItem.getItem()).getMinPrice(), false))
.sendPrefixedMessage(seller); .sendPrefixedMessage(seller);
result.accept(auctionItem, MINIMUM_PRICE_NOT_MET); result.accept(auctionItem, MINIMUM_PRICE_NOT_MET);
return; return;
} }
if (AuctionAPI.getInstance().isAtMaxItemPrice(BundleUtil.isBundledItem(auctionItem.getItem()), auctionItem.isBidItem(), auctionItem.getItem(), auctionItem.getBasePrice(), auctionItem.getBidStartingPrice())) {
instance.getLocale().getMessage("pricing.maxitemprice")
.processPlaceholder("price", AuctionHouse.getAPI().getNumberAsCurrency(AuctionHouse.getPriceLimitManager().getPriceLimit(auctionItem.getItem()).getMaxPrice(), false))
.sendPrefixedMessage(seller);
result.accept(auctionItem, ABOVE_MAXIMUM_PRICE);
return;
}
}
final ItemStack finalItemToSell = auctionItem.getItem().clone(); final ItemStack finalItemToSell = auctionItem.getItem().clone();
final double originalBasePrice = auctionItem.getBasePrice(); final double originalBasePrice = auctionItem.getBasePrice();

View File

@ -27,7 +27,6 @@ import org.bukkit.inventory.ItemStack;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols; import java.text.DecimalFormatSymbols;
import java.text.NumberFormat; import java.text.NumberFormat;
import java.util.Currency;
import java.util.Locale; import java.util.Locale;
public final class AuctionAPI implements AuctionHouseAPI { public final class AuctionAPI implements AuctionHouseAPI {
@ -64,7 +63,7 @@ public final class AuctionAPI implements AuctionHouseAPI {
currencyFormatter.setGroupingUsed(Settings.CURRENCY_USE_GROUPING.getBoolean()); currencyFormatter.setGroupingUsed(Settings.CURRENCY_USE_GROUPING.getBoolean());
String formatted = currencyFormatter.format(number); String formatted = currencyFormatter.format(number);
if (Settings.CURRENCY_STRIP_ENDING_ZEROES.getBoolean()) { if (Settings.CURRENCY_STRIP_ENDING_ZEROES.getBoolean()) {
formatted = replaceLastDecimal(formatted); formatted = replaceLastDecimal(formatted);

View File

@ -0,0 +1,96 @@
package ca.tweetzy.auctionhouse.impl;
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.api.auction.ListingPriceLimit;
import ca.tweetzy.auctionhouse.api.sync.SynchronizeResult;
import lombok.NonNull;
import org.bukkit.inventory.ItemStack;
import java.util.UUID;
import java.util.function.Consumer;
public final class AuctionPriceLimit implements ListingPriceLimit {
private final UUID id;
private ItemStack item;
private double minPrice;
private double maxPrice;
public AuctionPriceLimit(@NonNull final UUID id, @NonNull final ItemStack item, final double minPrice, final double maxPrice) {
this.id = id;
this.item = item;
this.minPrice = minPrice;
this.maxPrice = maxPrice;
}
public AuctionPriceLimit(@NonNull final ItemStack item, final double minPrice, final double maxPrice) {
this(UUID.randomUUID(), item, minPrice, maxPrice);
}
@Override
public @NonNull UUID getId() {
return this.id;
}
@Override
public ItemStack getItem() {
return this.item;
}
@Override
public void setItem(@NonNull ItemStack itemStack) {
this.item = itemStack;
}
@Override
public double getMinPrice() {
return this.minPrice;
}
@Override
public void setMinPrice(double minPrice) {
this.minPrice = minPrice;
}
@Override
public double getMaxPrice() {
return this.maxPrice;
}
@Override
public void setMaxPrice(double maxPrice) {
this.maxPrice = maxPrice;
}
@Override
public void store(Consumer<ListingPriceLimit> stored) {
AuctionHouse.getDataManager().insertListingPriceLimit(this, (error, result) -> {
if (error == null) {
AuctionHouse.getPriceLimitManager().add(result);
}
if (stored != null)
stored.accept(result);
});
}
@Override
public void sync(Consumer<Boolean> wasSuccess) {
AuctionHouse.getDataManager().updateListingPriceLimit(this, (error, result) -> {
if (wasSuccess != null)
wasSuccess.accept(error == null);
});
}
@Override
public void unStore(Consumer<SynchronizeResult> status) {
AuctionHouse.getDataManager().deleteListingPriceLimit(getId(), (error, success) -> {
if (error == null && success) {
AuctionHouse.getPriceLimitManager().remove(this);
}
if (status != null)
status.accept(success && error == null ? SynchronizeResult.SUCCESS : SynchronizeResult.FAILURE);
});
}
}

View File

@ -1,82 +0,0 @@
/*
* Auction House
* Copyright 2018-2022 Kiran Hart
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package ca.tweetzy.auctionhouse.managers;
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.auction.MinItemPrice;
import ca.tweetzy.auctionhouse.settings.Settings;
import ca.tweetzy.flight.comp.enums.ServerVersion;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.List;
/**
* Date Created: April 04 2022
* Time Created: 8:22 a.m.
*
* @author Kiran Hart
*/
public final class MinItemPriceManager {
private final List<MinItemPrice> minPrices = new ArrayList<>();
public void addItem(MinItemPrice minItemPrice) {
if (this.minPrices.contains(minItemPrice)) return;
this.minPrices.add(minItemPrice);
}
public void removeItem(MinItemPrice minItemPrice) {
if (!this.minPrices.contains(minItemPrice)) return;
this.minPrices.remove(minItemPrice);
}
public MinItemPrice getMinPrice(ItemStack item) {
if (Settings.MIN_ITEM_PRICE_USES_SIMPE_COMPARE.getBoolean())
return this.minPrices.stream().filter(mins -> simpleMatching(mins, item)).findFirst().orElse(null);
return this.minPrices.stream().filter(mins -> mins.getItemStack().isSimilar(item)).findFirst().orElse(null);
}
private boolean simpleMatching(MinItemPrice minItemPrice, ItemStack item) {
boolean modelDataMatch = true;
boolean typeMatch = minItemPrice.getItemStack().getType() == item.getType();
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_14))
if (minItemPrice.getItemStack().getItemMeta() != null && minItemPrice.getItemStack().getItemMeta().hasCustomModelData() && item.getItemMeta() != null && item.getItemMeta().hasCustomModelData())
modelDataMatch = minItemPrice.getItemStack().getItemMeta().getCustomModelData() == item.getItemMeta().getCustomModelData();
return typeMatch && modelDataMatch;
}
public List<MinItemPrice> getMinPrices() {
return this.minPrices;
}
public void loadMinPrices() {
this.minPrices.clear();
AuctionHouse.getInstance().getDataManager().getMinItemPrices((error, items) -> {
if (error == null)
items.forEach(this::addItem);
});
}
}

View File

@ -83,7 +83,7 @@ public final class BanManager extends KeyValueManager<UUID, Ban> {
@Override @Override
public void load() { public void load() {
AuctionHouse.getInstance().getDataManager().getBans((error, results) -> { AuctionHouse.getDataManager().getBans((error, results) -> {
if (error == null) if (error == null)
results.forEach(ban -> add(ban.getId(), ban)); results.forEach(ban -> add(ban.getId(), ban));
}); });

View File

@ -1,7 +1,10 @@
package ca.tweetzy.auctionhouse.model.manager; package ca.tweetzy.auctionhouse.model.manager;
import ca.tweetzy.auctionhouse.AuctionHouse; import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.api.auction.category.*; import ca.tweetzy.auctionhouse.api.auction.category.CategoryConditionType;
import ca.tweetzy.auctionhouse.api.auction.category.CategoryFieldCondition;
import ca.tweetzy.auctionhouse.api.auction.category.CategoryStringComparison;
import ca.tweetzy.auctionhouse.api.auction.category.ItemCategory;
import ca.tweetzy.auctionhouse.api.manager.KeyValueManager; import ca.tweetzy.auctionhouse.api.manager.KeyValueManager;
import ca.tweetzy.auctionhouse.impl.category.AuctionCategoryCondition; import ca.tweetzy.auctionhouse.impl.category.AuctionCategoryCondition;
import ca.tweetzy.auctionhouse.impl.category.AuctionItemCategory; import ca.tweetzy.auctionhouse.impl.category.AuctionItemCategory;

View File

@ -50,7 +50,7 @@ public class PaymentsManager extends KeyValueManager<UUID, AuctionPayment> {
@Override @Override
public void load() { public void load() {
AuctionHouse.getInstance().getDataManager().getAuctionPayments((error, results) -> { AuctionHouse.getDataManager().getAuctionPayments((error, results) -> {
if (error == null) { if (error == null) {
results.forEach(this::add); results.forEach(this::add);
} }

View File

@ -0,0 +1,46 @@
package ca.tweetzy.auctionhouse.model.manager;
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.api.auction.ListingPriceLimit;
import ca.tweetzy.auctionhouse.api.manager.ListManager;
import ca.tweetzy.auctionhouse.settings.Settings;
import ca.tweetzy.flight.comp.enums.ServerVersion;
import lombok.NonNull;
import org.bukkit.inventory.ItemStack;
public final class PriceLimitManager extends ListManager<ListingPriceLimit> {
public PriceLimitManager() {
super("Listing Price");
}
public ListingPriceLimit getPriceLimit(@NonNull ItemStack item) {
if (Settings.MIN_ITEM_PRICE_USES_SIMPE_COMPARE.getBoolean())
return this.managerContent.stream().filter(mins -> simpleMatching(mins, item)).findFirst().orElse(null);
return this.managerContent.stream().filter(mins -> mins.getItem().isSimilar(item)).findFirst().orElse(null);
}
private boolean simpleMatching(ListingPriceLimit listingPriceLimit, ItemStack item) {
boolean modelDataMatch = true;
boolean typeMatch = listingPriceLimit.getItem().getType() == item.getType();
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_14))
if (listingPriceLimit.getItem().getItemMeta() != null && listingPriceLimit.getItem().getItemMeta().hasCustomModelData() && item.getItemMeta() != null && item.getItemMeta().hasCustomModelData())
modelDataMatch = listingPriceLimit.getItem().getItemMeta().getCustomModelData() == item.getItemMeta().getCustomModelData();
return typeMatch && modelDataMatch;
}
@Override
public void load() {
clear();
AuctionHouse.getDataManager().getListingPriceLimits((error, prices) -> {
if (error == null)
prices.forEach(this::add);
});
}
}

View File

@ -99,8 +99,6 @@ public class LocaleSettings {
languageNodes.put("general.requires creative", "&cThat action requires you to be in creative mode"); languageNodes.put("general.requires creative", "&cThat action requires you to be in creative mode");
languageNodes.put("general.deleted transactions", "&cDeleted a total of &4%deleted_transactions% &ctransactions"); languageNodes.put("general.deleted transactions", "&cDeleted a total of &4%deleted_transactions% &ctransactions");
languageNodes.put("general.transaction delete begin", "&cBeginning transaction deletion, this may take some time."); languageNodes.put("general.transaction delete begin", "&cBeginning transaction deletion, this may take some time.");
languageNodes.put("general.min price already added", "&cThere is already a minimum price set, please delete the existing one first.");
languageNodes.put("general.added min price", "&aSuccessfully set minimum price for %item% &ato &2$%price%");
languageNodes.put("general.qtybuydisabled", "&4%item_owner%&c is only accepting purchases of the entire stack."); languageNodes.put("general.qtybuydisabled", "&4%item_owner%&c is only accepting purchases of the entire stack.");
languageNodes.put("general.invalid bid amount", "&cBid either too low or too high"); languageNodes.put("general.invalid bid amount", "&cBid either too low or too high");
languageNodes.put("general.invalid deletion range", "&cPlease enter a valid deletion range"); languageNodes.put("general.invalid deletion range", "&cPlease enter a valid deletion range");
@ -112,6 +110,9 @@ public class LocaleSettings {
languageNodes.put("pricing.request.min price", "&cThe minimum request price must be &a%price%"); languageNodes.put("pricing.request.min price", "&cThe minimum request price must be &a%price%");
languageNodes.put("pricing.request.max price", "&cThe maximum request price is &a%price%"); languageNodes.put("pricing.request.max price", "&cThe maximum request price is &a%price%");
languageNodes.put("pricing.limit.added price limit", "&aSuccessfully added a min/max price limit to that item.");
languageNodes.put("pricing.limit.updated price limit", "&aSuccessfully updated price limits for this item.");
languageNodes.put("pricing.minbaseprice", "&cThe minimum base price must be &a%price%"); languageNodes.put("pricing.minbaseprice", "&cThe minimum base price must be &a%price%");
languageNodes.put("pricing.minstartingprice", "&cThe minimum starting bid price must be &a%price%"); languageNodes.put("pricing.minstartingprice", "&cThe minimum starting bid price must be &a%price%");
@ -125,6 +126,7 @@ public class LocaleSettings {
languageNodes.put("pricing.moneyadd", "&a&l+ $%price% &7(%player_balance%)"); languageNodes.put("pricing.moneyadd", "&a&l+ $%price% &7(%player_balance%)");
languageNodes.put("pricing.bidmusthigherthanprevious", "&cYour bid must be higher than &4%current_bid%"); languageNodes.put("pricing.bidmusthigherthanprevious", "&cYour bid must be higher than &4%current_bid%");
languageNodes.put("pricing.minitemprice", "&cThe minimum price for this item must be &a%price%"); languageNodes.put("pricing.minitemprice", "&cThe minimum price for this item must be &a%price%");
languageNodes.put("pricing.maxitemprice", "&cThe maximum price for this item is &a%price%");
languageNodes.put("titles.end all confirm.title", "&eConfirm End All"); languageNodes.put("titles.end all confirm.title", "&eConfirm End All");
@ -164,6 +166,12 @@ public class LocaleSettings {
languageNodes.put("titles.material search.title", "&eSearch for material"); languageNodes.put("titles.material search.title", "&eSearch for material");
languageNodes.put("titles.material search.subtitle", "&fEnter item/material name in chat"); languageNodes.put("titles.material search.subtitle", "&fEnter item/material name in chat");
languageNodes.put("titles.price limit.min.title", "&eAdjust Price Limit");
languageNodes.put("titles.price limit.min.subtitle", "&fEnter new min price for this item in chat");
languageNodes.put("titles.price limit.max.title", "&eAdjust Price Limit");
languageNodes.put("titles.price limit.max.subtitle", "&fEnter new max price for this item in chat");
languageNodes.put("transaction.sale_type.bid_won", "Won Auction"); languageNodes.put("transaction.sale_type.bid_won", "Won Auction");
languageNodes.put("transaction.sale_type.immediate_buy", "Bought Immediately"); languageNodes.put("transaction.sale_type.immediate_buy", "Bought Immediately");
@ -273,7 +281,7 @@ public class LocaleSettings {
languageNodes.put("commands.syntax.unban", "unban <player>"); languageNodes.put("commands.syntax.unban", "unban <player>");
languageNodes.put("commands.syntax.togglelistinfo", "togglelistinfo"); languageNodes.put("commands.syntax.togglelistinfo", "togglelistinfo");
languageNodes.put("commands.syntax.markchest", "markchest"); languageNodes.put("commands.syntax.markchest", "markchest");
languageNodes.put("commands.syntax.min price", "minprices [add] [price]"); languageNodes.put("commands.syntax.price limit", "pricelimit [set <min/max> <price>]");
languageNodes.put("commands.syntax.stats", "stats [player]"); languageNodes.put("commands.syntax.stats", "stats [player]");
languageNodes.put("commands.syntax.request", "request <price> [-single]"); languageNodes.put("commands.syntax.request", "request <price> [-single]");
@ -293,7 +301,7 @@ public class LocaleSettings {
languageNodes.put("commands.description.unban", "Unban a player from the auction house"); languageNodes.put("commands.description.unban", "Unban a player from the auction house");
languageNodes.put("commands.description.togglelistinfo", "Toggle whether auction house should message you when you list an item"); languageNodes.put("commands.description.togglelistinfo", "Toggle whether auction house should message you when you list an item");
languageNodes.put("commands.description.markchest", "Toggles whether a chest is an auction chest"); languageNodes.put("commands.description.markchest", "Toggles whether a chest is an auction chest");
languageNodes.put("commands.description.min price", "Adds a minimum sell price to an item"); languageNodes.put("commands.description.price limit", "Adds a minimum sell price to an item");
languageNodes.put("commands.description.stats", "View yours or another players stats"); languageNodes.put("commands.description.stats", "View yours or another players stats");
languageNodes.put("commands.description.request", "Makes request for item your holding"); languageNodes.put("commands.description.request", "Makes request for item your holding");
} }

View File

@ -63,7 +63,7 @@ public class Settings {
public static final ConfigSetting CMD_ALIAS_SUB_EXPIRED = new ConfigSetting(config, "command aliases.subcommands.expired", Collections.singletonList("expired"), "Command aliases for the expired command"); public static final ConfigSetting CMD_ALIAS_SUB_EXPIRED = new ConfigSetting(config, "command aliases.subcommands.expired", Collections.singletonList("expired"), "Command aliases for the expired command");
public static final ConfigSetting CMD_ALIAS_SUB_FILTER = new ConfigSetting(config, "command aliases.subcommands.filter", Collections.singletonList("filter"), "Command aliases for the filter command"); public static final ConfigSetting CMD_ALIAS_SUB_FILTER = new ConfigSetting(config, "command aliases.subcommands.filter", Collections.singletonList("filter"), "Command aliases for the filter command");
public static final ConfigSetting CMD_ALIAS_SUB_MARKCHEST = new ConfigSetting(config, "command aliases.subcommands.markchest", Collections.singletonList("markchest"), "Command aliases for the markchest command"); public static final ConfigSetting CMD_ALIAS_SUB_MARKCHEST = new ConfigSetting(config, "command aliases.subcommands.markchest", Collections.singletonList("markchest"), "Command aliases for the markchest command");
public static final ConfigSetting CMD_ALIAS_SUB_MINPRICE = new ConfigSetting(config, "command aliases.subcommands.minprice", Collections.singletonList("minprices"), "Command aliases for the minprices command"); public static final ConfigSetting CMD_ALIAS_SUB_PRICE_LIMIT = new ConfigSetting(config, "command aliases.subcommands.price limit", Collections.singletonList("pricelimit"), "Command aliases for the price limits command, formally min prices");
public static final ConfigSetting CMD_ALIAS_SUB_PAYMENTS = new ConfigSetting(config, "command aliases.subcommands.payments", Collections.singletonList("payments"), "Command aliases for the payments command"); public static final ConfigSetting CMD_ALIAS_SUB_PAYMENTS = new ConfigSetting(config, "command aliases.subcommands.payments", Collections.singletonList("payments"), "Command aliases for the payments command");
public static final ConfigSetting CMD_ALIAS_SUB_REQUEST = new ConfigSetting(config, "command aliases.subcommands.request", Collections.singletonList("request"), "Command aliases for the request command"); public static final ConfigSetting CMD_ALIAS_SUB_REQUEST = new ConfigSetting(config, "command aliases.subcommands.request", Collections.singletonList("request"), "Command aliases for the request command");
public static final ConfigSetting CMD_ALIAS_SUB_SEARCH = new ConfigSetting(config, "command aliases.subcommands.search", Collections.singletonList("search"), "Command aliases for the search command"); public static final ConfigSetting CMD_ALIAS_SUB_SEARCH = new ConfigSetting(config, "command aliases.subcommands.search", Collections.singletonList("search"), "Command aliases for the search command");
@ -871,12 +871,18 @@ public class Settings {
/* =============================== /* ===============================
* MIN ITEM PRICES GUI * MIN ITEM PRICES GUI
* ===============================*/ * ===============================*/
public static final ConfigSetting GUI_MIN_ITEM_PRICES_TITLE = new ConfigSetting(config, "gui.min item prices.title", "&7&LMinimum Item Prices"); public static final ConfigSetting GUI_PRICE_LIMITS_TITLE = new ConfigSetting(config, "gui.price limits.title", "&7Auction House &f- &ePrice Limits");
public static final ConfigSetting GUI_MIN_ITEM_PRICES_LORE = new ConfigSetting(config, "gui.min item prices.lore", Arrays.asList( public static final ConfigSetting GUI_PRICE_LIMITS_LORE = new ConfigSetting(config, "gui.price limits.lore", Arrays.asList(
"&7&m-------------------------", "&7&m-------------------------",
"&7Minimum Price&f: &a%price%", "&7Minimum Price&f: &a%min_price%",
"&7Maximum Price&f: &a%max_price%",
"", "",
"&7Click to delete" "&7(&e!&7) &f- &BWhen setting the max price",
"&byou can use -1 to disable it.",
"",
"&7Left-Click to change min price",
"&7Right-Click to change max price",
"&7Press Drop to delete"
)); ));
/* =============================== /* ===============================
@ -1612,7 +1618,6 @@ public class Settings {
), "The info order for the stacks, if a listing doesnt require one of these, Auction House will just ignore it.", "This is mainly used to just change the ordering of listing stack information"); ), "The info order for the stacks, if a listing doesnt require one of these, Auction House will just ignore it.", "This is mainly used to just change the ordering of listing stack information");
/* =============================== /* ===============================
* AUCTION SOUNDS * AUCTION SOUNDS
* ===============================*/ * ===============================*/