This commit is contained in:
Kiran Hart 2021-08-14 17:48:06 -04:00
parent e7afa4989e
commit e74d2aecb0
58 changed files with 1793 additions and 974 deletions

32
pom.xml
View File

@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>ca.tweetzy</groupId>
<artifactId>auctionhouse</artifactId>
<version>2.24.0</version>
<version>2.25.2</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@ -60,7 +60,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.0</version>
<version>3.2.4</version>
<executions>
<execution>
<id>shaded</id>
@ -96,11 +96,11 @@
<relocations>
<relocation>
<pattern>ca.tweetzy.core</pattern>
<shadedPattern>${project.groupId}.auctionhouse.core</shadedPattern>
<shadedPattern>${project.groupId}.${project.artifactId}.core</shadedPattern>
</relocation>
<relocation>
<pattern>co.aikar.taskchain</pattern>
<shadedPattern>${project.groupId}.auctionhouse.taskchain</shadedPattern> <!-- Replace this -->
<shadedPattern>${project.groupId}.${project.artifactId}.taskchain</shadedPattern> <!-- Replace this -->
</relocation>
</relocations>
</configuration>
@ -127,9 +127,18 @@
<id>aikar</id>
<url>https://repo.aikar.co/content/groups/aikar/</url>
</repository>
<repository>
<id>nexus</id>
<name>Lumine Releases</name>
<url>https://mvn.lumine.io/repository/maven-public/</url>
</repository>
<repository>
<id>placeholderapi</id>
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
@ -139,7 +148,7 @@
<dependency>
<groupId>ca.tweetzy</groupId>
<artifactId>tweetycore</artifactId>
<version>2.6.1</version>
<version>2.7.1</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
@ -157,5 +166,16 @@
<artifactId>HikariCP</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>io.lumine</groupId>
<artifactId>MythicLib</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.10.10</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -1,13 +1,11 @@
package ca.tweetzy.auctionhouse;
import ca.tweetzy.auctionhouse.api.AuctionAPI;
import ca.tweetzy.auctionhouse.api.UpdateChecker;
import ca.tweetzy.auctionhouse.api.hook.PlaceholderAPI;
import ca.tweetzy.auctionhouse.auction.AuctionPlayer;
import ca.tweetzy.auctionhouse.commands.*;
import ca.tweetzy.auctionhouse.database.DataManager;
import ca.tweetzy.auctionhouse.database.migrations._1_InitialMigration;
import ca.tweetzy.auctionhouse.database.migrations._2_FilterWhitelistMigration;
import ca.tweetzy.auctionhouse.database.migrations._3_BansMigration;
import ca.tweetzy.auctionhouse.database.migrations.*;
import ca.tweetzy.auctionhouse.listeners.AuctionListeners;
import ca.tweetzy.auctionhouse.listeners.PlayerListeners;
import ca.tweetzy.auctionhouse.managers.*;
@ -18,11 +16,13 @@ import ca.tweetzy.auctionhouse.tasks.TickAuctionsTask;
import ca.tweetzy.core.TweetyCore;
import ca.tweetzy.core.TweetyPlugin;
import ca.tweetzy.core.commands.CommandManager;
import ca.tweetzy.core.compatibility.ServerProject;
import ca.tweetzy.core.compatibility.ServerVersion;
import ca.tweetzy.core.configuration.Config;
import ca.tweetzy.core.database.DataMigrationManager;
import ca.tweetzy.core.database.DatabaseConnector;
import ca.tweetzy.core.database.MySQLConnector;
import ca.tweetzy.core.database.SQLiteConnector;
import ca.tweetzy.core.gui.GuiManager;
import ca.tweetzy.core.hooks.EconomyManager;
import ca.tweetzy.core.utils.Metrics;
@ -31,6 +31,7 @@ import co.aikar.taskchain.BukkitTaskChainFactory;
import co.aikar.taskchain.TaskChain;
import co.aikar.taskchain.TaskChainFactory;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.Bukkit;
import java.util.List;
@ -49,6 +50,10 @@ public class AuctionHouse extends TweetyPlugin {
private static TaskChainFactory taskChainFactory;
private static AuctionHouse instance;
@Getter
@Setter
private boolean migrating = false;
@Getter
private final GuiManager guiManager = new GuiManager(this);
@ -101,9 +106,6 @@ public class AuctionHouse extends TweetyPlugin {
taskChainFactory = BukkitTaskChainFactory.create(this);
// Load Economy
EconomyManager.load();
@ -133,32 +135,35 @@ public class AuctionHouse extends TweetyPlugin {
Bukkit.getOnlinePlayers().forEach(p -> this.auctionPlayerManager.addPlayer(new AuctionPlayer(p)));
// Setup the database if enabled
if (Settings.DATABASE_USE.getBoolean()) {
this.databaseConnector = new MySQLConnector(this, Settings.DATABASE_HOST.getString(), Settings.DATABASE_PORT.getInt(), Settings.DATABASE_NAME.getString(), Settings.DATABASE_USERNAME.getString(), Settings.DATABASE_PASSWORD.getString(), Settings.DATABASE_USE_SSL.getBoolean());
this.dataManager = new DataManager(this.databaseConnector, this);
DataMigrationManager dataMigrationManager = new DataMigrationManager(this.databaseConnector, this.dataManager,
new _1_InitialMigration(),
new _2_FilterWhitelistMigration(),
new _3_BansMigration()
);
dataMigrationManager.runMigrations();
}
this.databaseConnector = Settings.DATABASE_USE.getBoolean() ? new MySQLConnector(this, Settings.DATABASE_HOST.getString(), Settings.DATABASE_PORT.getInt(), Settings.DATABASE_NAME.getString(), Settings.DATABASE_USERNAME.getString(), Settings.DATABASE_PASSWORD.getString(), Settings.DATABASE_USE_SSL.getBoolean()) : new SQLiteConnector(this);
this.dataManager = new DataManager(this.databaseConnector, this);
DataMigrationManager dataMigrationManager = new DataMigrationManager(this.databaseConnector, this.dataManager,
new _1_InitialMigration(),
new _2_FilterWhitelistMigration(),
new _3_BansMigration(),
new _4_ItemsChangeMigration(),
new _5_TransactionChangeMigration(),
new _6_BigIntMigration()
);
dataMigrationManager.runMigrations();
// load auction items
this.auctionItemManager = new AuctionItemManager();
this.auctionItemManager.loadItems(Settings.DATABASE_USE.getBoolean());
this.auctionItemManager.start();
// load transactions
this.transactionManager = new TransactionManager();
this.transactionManager.loadTransactions(Settings.DATABASE_USE.getBoolean());
this.transactionManager.loadTransactions();
// load the filter whitelist items
this.filterManager = new FilterManager();
this.filterManager.loadItems(Settings.DATABASE_USE.getBoolean());
this.filterManager.loadItems();
// load the bans
this.auctionBanManager = new AuctionBanManager();
this.auctionBanManager.loadBans(Settings.DATABASE_USE.getBoolean());
this.auctionBanManager.loadBans();
// gui manager
this.guiManager.init();
@ -174,16 +179,21 @@ public class AuctionHouse extends TweetyPlugin {
new CommandTransactions(),
new CommandSearch(),
new CommandSettings(),
new CommandConvert(),
new CommandToggleListInfo(),
new CommandMigrate(),
new CommandReload(),
new CommandFilter(),
new CommandUpload(),
new CommandStatus(),
new CommandAdmin(),
new CommandBan(),
new CommandUnban()
);
// Placeholder API
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
new PlaceholderAPI(this).register();
}
// start the auction tick task
TickAuctionsTask.startTask();
// auto save task
@ -196,14 +206,36 @@ public class AuctionHouse extends TweetyPlugin {
// metrics
this.metrics = new Metrics(this, 6806);
getServer().getScheduler().runTaskLater(this, () -> {
if (!ServerProject.isServer(ServerProject.SPIGOT, ServerProject.PAPER)) {
getLogger().severe("You're running Auction House on a non-supported Jar");
getLogger().severe("You will not receive any support while using a non-supported jar, support jars: Spigot or Paper");
}
if (!System.getProperty("java.version").startsWith("16")) {
getLogger().severe("You are not running Java 16, Auction House will be updated to use Java 16 in the coming months. If you do not update, you will not be able to use Auction House.");
}
if (USER.equals("%%__USER__%%")) {
getLogger().severe("Could not detect user ID, are you running a cracked / self-compiled copy of auction house?");
} else {
getConsole().sendMessage(TextUtils.formatText("&aThank you for purchasing Auction House, it means a lot"));
getConsole().sendMessage(TextUtils.formatText("&7 - Kiran Hart"));
}
}, 1L);
}
@Override
public void onPluginDisable() {
this.auctionItemManager.saveItems(Settings.DATABASE_USE.getBoolean(), false);
this.transactionManager.saveTransactions(Settings.DATABASE_USE.getBoolean(), false);
this.filterManager.saveFilterWhitelist(Settings.DATABASE_USE.getBoolean(), false);
this.auctionBanManager.saveBans(Settings.DATABASE_USE.getBoolean(), false);
if (this.dataManager != null) {
this.auctionItemManager.end();
this.filterManager.saveFilterWhitelist(false);
this.auctionBanManager.saveBans(false);
this.dataManager.close();
}
getServer().getScheduler().cancelTasks(this);
}
@Override

View File

@ -1,22 +1,42 @@
package ca.tweetzy.auctionhouse.api;
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.api.events.AuctionStartEvent;
import ca.tweetzy.auctionhouse.api.hook.MMOItems;
import ca.tweetzy.auctionhouse.api.hook.PlaceholderAPI;
import ca.tweetzy.auctionhouse.auction.AuctionItem;
import ca.tweetzy.auctionhouse.auction.AuctionPlayer;
import ca.tweetzy.auctionhouse.auction.AuctionSaleType;
import ca.tweetzy.auctionhouse.auction.AuctionedItem;
import ca.tweetzy.auctionhouse.helpers.ConfigurationItemHelper;
import ca.tweetzy.auctionhouse.helpers.MaterialCategorizer;
import ca.tweetzy.auctionhouse.managers.SoundManager;
import ca.tweetzy.auctionhouse.settings.Settings;
import ca.tweetzy.core.compatibility.CompatibleHand;
import ca.tweetzy.core.compatibility.XMaterial;
import ca.tweetzy.core.hooks.EconomyManager;
import ca.tweetzy.core.utils.PlayerUtils;
import ca.tweetzy.core.utils.TextUtils;
import ca.tweetzy.core.utils.items.ItemUtils;
import ca.tweetzy.core.utils.nms.NBTEditor;
import io.lumine.mythic.lib.api.item.NBTItem;
import io.lumine.mythic.lib.api.itemtype.MMOItemType;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.WordUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.plugin.Plugin;
import org.bukkit.util.io.BukkitObjectInputStream;
import org.bukkit.util.io.BukkitObjectOutputStream;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.awt.*;
import java.io.*;
@ -27,6 +47,8 @@ import java.util.List;
import java.util.*;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -171,6 +193,37 @@ public class AuctionAPI {
return null;
}
// ========================================================================================
public static String encodeItem(ItemStack itemStack) {
YamlConfiguration config = new YamlConfiguration();
config.set("i", itemStack);
return config.saveToString();
// return DatatypeConverter.printBase64Binary(config.saveToString().getBytes(StandardCharsets.UTF_8));
}
public static ItemStack decodeItem(String string) {
YamlConfiguration config = new YamlConfiguration();
try {
config.loadFromString(string);
} catch (IllegalArgumentException | InvalidConfigurationException e) {
e.printStackTrace();
return null;
}
return config.getItemStack("i", null);
}
public static boolean tellMigrationStatus(CommandSender commandSender) {
if (AuctionHouse.getInstance().isMigrating()) {
AuctionHouse.getInstance().getLocale().newMessage("&cAuction House is currently migrating auction items, auction usage is disabled until it's finished").sendPrefixedMessage(commandSender);
return true;
}
return false;
}
// ========================================================================================
/**
* Used to create a player head
*
@ -195,7 +248,7 @@ public class AuctionAPI {
* @param isNew Is this the start of a new auction or the end of one?
* @param isBid Is this auction a bid enabled auction, or a single sale auction?
*/
public void sendDiscordMessage(String webhook, OfflinePlayer seller, OfflinePlayer buyer, AuctionItem auctionItem, AuctionSaleType saleType, boolean isNew, boolean isBid) {
public void sendDiscordMessage(String webhook, OfflinePlayer seller, OfflinePlayer buyer, AuctionedItem auctionItem, AuctionSaleType saleType, boolean isNew, boolean isBid) {
DiscordWebhook hook = new DiscordWebhook(webhook);
hook.setUsername(Settings.DISCORD_MSG_USERNAME.getString());
hook.setAvatarUrl(Settings.DISCORD_MSG_PFP.getString());
@ -205,6 +258,9 @@ public class AuctionAPI {
? Color.getHSBColor(ThreadLocalRandom.current().nextFloat() * 360F, ThreadLocalRandom.current().nextFloat() * 101F, ThreadLocalRandom.current().nextFloat() * 101F)
: Color.getHSBColor(Float.parseFloat(possibleColours[0]) / 360, Float.parseFloat(possibleColours[1]) / 100, Float.parseFloat(possibleColours[2]) / 100);
ItemStack itemStack = auctionItem.getItem();
String itemName = MMOItems.isEnabled() ? MMOItems.getItemType(itemStack) : ChatColor.stripColor(getItemName(itemStack));
hook.addEmbed(new DiscordWebhook.EmbedObject()
.setTitle(isNew ? Settings.DISCORD_MSG_START_TITLE.getString() : Settings.DISCORD_MSG_FINISH_TITLE.getString())
.setColor(colour)
@ -214,8 +270,8 @@ public class AuctionAPI {
.addField(Settings.DISCORD_MSG_FIELD_FINAL_PRICE_NAME.getString(), isNew ? AuctionHouse.getInstance().getLocale().getMessage("discord.not_sold").getMessage() : Settings.DISCORD_MSG_FIELD_FINAL_PRICE_VALUE.getString().replace("%final_price%", this.getFriendlyNumber(isBid ? auctionItem.getCurrentPrice() : auctionItem.getBasePrice())), Settings.DISCORD_MSG_FIELD_FINAL_PRICE_INLINE.getBoolean())
.addField(Settings.DISCORD_MSG_FIELD_IS_BID_NAME.getString(), Settings.DISCORD_MSG_FIELD_IS_BID_VALUE.getString().replace("%is_bid%", isBid ? AuctionHouse.getInstance().getLocale().getMessage("discord.is_bid_true").getMessage() : AuctionHouse.getInstance().getLocale().getMessage("discord.is_bid_false").getMessage()), Settings.DISCORD_MSG_FIELD_IS_BID_INLINE.getBoolean())
.addField(Settings.DISCORD_MSG_FIELD_PURCHASE_TYPE_NAME.getString(), isNew ? AuctionHouse.getInstance().getLocale().getMessage("discord.not_bought").getMessage() : Settings.DISCORD_MSG_FIELD_PURCHASE_TYPE_VALUE.getString().replace("%purchase_type%", saleType == AuctionSaleType.USED_BIDDING_SYSTEM ? AuctionHouse.getInstance().getLocale().getMessage("discord.sale_bid_win").getMessage() : AuctionHouse.getInstance().getLocale().getMessage("discord.sale_immediate_buy").getMessage()), Settings.DISCORD_MSG_FIELD_PURCHASE_INLINE.getBoolean())
.addField(Settings.DISCORD_MSG_FIELD_ITEM_NAME.getString(), Settings.DISCORD_MSG_FIELD_ITEM_VALUE.getString().replace("%item_name%", ChatColor.stripColor(getItemName(deserializeItem(auctionItem.getRawItem())))), Settings.DISCORD_MSG_FIELD_ITEM_INLINE.getBoolean())
.addField(Settings.DISCORD_MSG_FIELD_ITEM_AMOUNT_NAME.getString(), Settings.DISCORD_MSG_FIELD_ITEM_AMOUNT_VALUE.getString().replace("%item_amount%", String.valueOf(this.deserializeItem(auctionItem.getRawItem()).getAmount())), Settings.DISCORD_MSG_FIELD_ITEM_AMOUNT_INLINE.getBoolean())
.addField(Settings.DISCORD_MSG_FIELD_ITEM_NAME.getString(), Settings.DISCORD_MSG_FIELD_ITEM_VALUE.getString().replace("%item_name%", itemName), Settings.DISCORD_MSG_FIELD_ITEM_INLINE.getBoolean())
.addField(Settings.DISCORD_MSG_FIELD_ITEM_AMOUNT_NAME.getString(), Settings.DISCORD_MSG_FIELD_ITEM_AMOUNT_VALUE.getString().replace("%item_amount%", String.valueOf(itemStack.getAmount())), Settings.DISCORD_MSG_FIELD_ITEM_AMOUNT_INLINE.getBoolean())
);
try {
@ -264,12 +320,16 @@ public class AuctionAPI {
Objects.requireNonNull(stack, "Item Stack cannot be null when getting enchantments");
if (!stack.getEnchantments().isEmpty()) {
stack.getEnchantments().forEach((k, i) -> {
enchantments.add(k.getName());
enchantments.add(k.getName() + i);
});
}
return enchantments;
}
public String serializeLines(List<String> lines) {
return StringUtils.join(lines, ";=;");
}
/**
* Used to match patterns
*
@ -479,4 +539,126 @@ public class AuctionAPI {
return 0L;
}
}
/**
* Used to insert an auction into the database
*
* @param seller Is the player who is listing the item
* @param item Is the item stack being listed to the auction house
* @param original Is the original item stack (only applies if using a bundle)
* @param seconds Is the total amount of seconds the item will be active for
* @param basePrice Is the buy now price
* @param bidStartPrice Is the price the bidding will start at if the item is an auction
* @param bidIncPrice Is the default price increment for an auction
* @param currentPrice Is the current/start price of an item
* @param isBiddingItem States whether the item is an auction or bin item
* @param isUsingBundle States whether the item is a bundled item
*/
public void listAuction(Player seller, ItemStack original, ItemStack item, int seconds, double basePrice, double bidStartPrice, double bidIncPrice, double currentPrice, boolean isBiddingItem, boolean isUsingBundle) {
AuctionedItem auctionedItem = new AuctionedItem();
auctionedItem.setId(UUID.randomUUID());
auctionedItem.setOwner(seller.getUniqueId());
auctionedItem.setHighestBidder(seller.getUniqueId());
auctionedItem.setOwnerName(seller.getName());
auctionedItem.setHighestBidderName(seller.getName());
auctionedItem.setItem(item);
auctionedItem.setCategory(MaterialCategorizer.getMaterialCategory(item));
auctionedItem.setExpiresAt(System.currentTimeMillis() + 1000L * seconds);
auctionedItem.setBidItem(isBiddingItem);
auctionedItem.setExpired(false);
auctionedItem.setBasePrice(basePrice);
auctionedItem.setBidStartingPrice(bidStartPrice);
auctionedItem.setBidIncrementPrice(bidIncPrice);
auctionedItem.setCurrentPrice(currentPrice);
if (Settings.TAX_ENABLED.getBoolean() && Settings.TAX_CHARGE_LISTING_FEE.getBoolean()) {
if (!EconomyManager.hasBalance(seller, Settings.TAX_LISTING_FEE.getDouble())) {
AuctionHouse.getInstance().getLocale().getMessage("auction.tax.cannotpaylistingfee").processPlaceholder("price", AuctionAPI.getInstance().formatNumber(Settings.TAX_LISTING_FEE.getDouble())).sendPrefixedMessage(seller);
return;
}
EconomyManager.withdrawBalance(seller, Settings.TAX_LISTING_FEE.getDouble());
AuctionHouse.getInstance().getLocale().getMessage("auction.tax.paidlistingfee").processPlaceholder("price", AuctionAPI.getInstance().formatNumber(Settings.TAX_LISTING_FEE.getDouble())).sendPrefixedMessage(seller);
AuctionHouse.getInstance().getLocale().getMessage("pricing.moneyremove").processPlaceholder("price", AuctionAPI.getInstance().formatNumber(Settings.TAX_LISTING_FEE.getDouble())).sendPrefixedMessage(seller);
}
AuctionStartEvent startEvent = new AuctionStartEvent(seller, auctionedItem);
Bukkit.getServer().getPluginManager().callEvent(startEvent);
if (startEvent.isCancelled()) return;
ItemStack finalItemToSell = item.clone();
int totalOriginal = isUsingBundle ? AuctionAPI.getInstance().getItemCountInPlayerInventory(seller, original) : finalItemToSell.getAmount();
if (isUsingBundle) {
AuctionAPI.getInstance().removeSpecificItemQuantityFromPlayer(seller, original, totalOriginal);
} else {
PlayerUtils.takeActiveItem(seller, CompatibleHand.MAIN_HAND, totalOriginal);
}
SoundManager.getInstance().playSound(seller, Settings.SOUNDS_LISTED_ITEM_ON_AUCTION_HOUSE.getString(), 1.0F, 1.0F);
String NAX = AuctionHouse.getInstance().getLocale().getMessage("auction.biditemwithdisabledbuynow").getMessage();
String msg = AuctionHouse.getInstance().getLocale().getMessage(auctionedItem.isBidItem() ? "auction.listed.withbid" : "auction.listed.nobid")
.processPlaceholder("amount", finalItemToSell.getAmount())
.processPlaceholder("item", AuctionAPI.getInstance().getItemName(finalItemToSell))
.processPlaceholder("base_price", auctionedItem.getBasePrice() <= -1 ? NAX : AuctionAPI.getInstance().formatNumber(auctionedItem.getBasePrice()))
.processPlaceholder("start_price", AuctionAPI.getInstance().formatNumber(auctionedItem.getBidStartingPrice()))
.processPlaceholder("increment_price", AuctionAPI.getInstance().formatNumber(auctionedItem.getBidIncrementPrice())).getMessage();
String msgToAll = AuctionHouse.getInstance().getLocale().getMessage(auctionedItem.isBidItem() ? "auction.broadcast.withbid" : "auction.broadcast.nobid")
.processPlaceholder("amount", finalItemToSell.getAmount())
.processPlaceholder("player", seller.getName())
.processPlaceholder("item", AuctionAPI.getInstance().getItemName(finalItemToSell))
.processPlaceholder("base_price", auctionedItem.getBasePrice() <= -1 ? NAX : AuctionAPI.getInstance().formatNumber(auctionedItem.getBasePrice()))
.processPlaceholder("start_price", AuctionAPI.getInstance().formatNumber(auctionedItem.getBidStartingPrice()))
.processPlaceholder("increment_price", AuctionAPI.getInstance().formatNumber(auctionedItem.getBidIncrementPrice())).getMessage();
if (AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(seller.getUniqueId()) == null) {
AuctionHouse.getInstance().getLocale().newMessage(TextUtils.formatText("&cCould not find auction player instance for&f: &e" + seller.getName() + "&c creating one now.")).sendPrefixedMessage(Bukkit.getConsoleSender());
AuctionHouse.getInstance().getAuctionPlayerManager().addPlayer(new AuctionPlayer(seller));
}
if (AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(seller.getUniqueId()).isShowListingInfo()) {
AuctionHouse.getInstance().getLocale().newMessage(msg).sendPrefixedMessage(seller);
}
// Actually attempt the insertion now
AuctionHouse.getInstance().getDataManager().insertAuctionAsync(auctionedItem, (error, inserted) -> {
if (error != null) {
AuctionHouse.getInstance().getLocale().getMessage("general.something_went_wrong_while_listing").sendPrefixedMessage(seller);
ItemStack originalCopy = original.clone();
if (isUsingBundle) {
originalCopy.setAmount(1);
for (int i = 0; i < totalOriginal; i++) PlayerUtils.giveItem(seller, originalCopy);
} else {
originalCopy.setAmount(totalOriginal);
PlayerUtils.giveItem(seller, originalCopy);
}
// If the item could not be added for whatever reason and the tax listing fee is enabled, refund them
if (Settings.TAX_ENABLED.getBoolean() && Settings.TAX_CHARGE_LISTING_FEE.getBoolean()) {
EconomyManager.deposit(seller, Settings.TAX_LISTING_FEE.getDouble());
AuctionHouse.getInstance().getLocale().getMessage("pricing.moneyadd").processPlaceholder("price", AuctionAPI.getInstance().formatNumber(Settings.TAX_LISTING_FEE.getDouble())).sendPrefixedMessage(seller);
}
return;
}
AuctionHouse.getInstance().getAuctionItemManager().addAuctionItem(auctionedItem);
if (Settings.BROADCAST_AUCTION_LIST.getBoolean()) {
Bukkit.getOnlinePlayers().forEach(p -> AuctionHouse.getInstance().getLocale().newMessage(msgToAll).sendPrefixedMessage(p));
}
});
}
public void logException(@Nullable Plugin plugin, @NotNull Throwable th) {
logException(plugin, th, null);
}
public void logException(@Nullable Plugin plugin, @NotNull Throwable th, @Nullable String type) {
Logger logger = plugin != null ? plugin.getLogger() : Logger.getGlobal();
logger.log(Level.FINER, th, () -> "A " + (type == null ? "critical" : type) + " error occurred");
}
void x(ItemStack item) {
NBTItem.get(item).getType();
}
}

View File

@ -2,6 +2,7 @@ package ca.tweetzy.auctionhouse.api.events;
import ca.tweetzy.auctionhouse.auction.AuctionItem;
import ca.tweetzy.auctionhouse.auction.AuctionSaleType;
import ca.tweetzy.auctionhouse.auction.AuctionedItem;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.OfflinePlayer;
@ -25,10 +26,10 @@ public class AuctionEndEvent extends Event implements Cancellable {
private OfflinePlayer originalOwner;
private OfflinePlayer buyer;
private AuctionItem auctionItem;
private AuctionedItem auctionItem;
private AuctionSaleType saleType;
public AuctionEndEvent(OfflinePlayer originalOwner, OfflinePlayer buyer, AuctionItem auctionItem, AuctionSaleType saleType, boolean async) {
public AuctionEndEvent(OfflinePlayer originalOwner, OfflinePlayer buyer, AuctionedItem auctionItem, AuctionSaleType saleType, boolean async) {
super(async);
this.originalOwner = originalOwner;
this.buyer = buyer;
@ -36,7 +37,7 @@ public class AuctionEndEvent extends Event implements Cancellable {
this.saleType = saleType;
}
public AuctionEndEvent(OfflinePlayer originalOwner, OfflinePlayer buyer, AuctionItem auctionItem, AuctionSaleType saleType) {
public AuctionEndEvent(OfflinePlayer originalOwner, OfflinePlayer buyer, AuctionedItem auctionItem, AuctionSaleType saleType) {
this(originalOwner, buyer, auctionItem, saleType, true);
}

View File

@ -1,6 +1,7 @@
package ca.tweetzy.auctionhouse.api.events;
import ca.tweetzy.auctionhouse.auction.AuctionItem;
import ca.tweetzy.auctionhouse.auction.AuctionedItem;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
@ -18,9 +19,9 @@ public class AuctionStartEvent extends Event implements Cancellable {
private boolean cancelled;
private Player seller;
private AuctionItem auctionItem;
private AuctionedItem auctionItem;
public AuctionStartEvent(Player seller, AuctionItem auctionItem) {
public AuctionStartEvent(Player seller, AuctionedItem auctionItem) {
this.seller = seller;
this.auctionItem = auctionItem;
}
@ -29,7 +30,7 @@ public class AuctionStartEvent extends Event implements Cancellable {
return seller;
}
public AuctionItem getAuctionItem() {
public AuctionedItem getAuctionItem() {
return auctionItem;
}

View File

@ -0,0 +1,36 @@
package ca.tweetzy.auctionhouse.api.hook;
import ca.tweetzy.auctionhouse.api.AuctionAPI;
import io.lumine.mythic.lib.api.item.NBTItem;
import lombok.NonNull;
import lombok.experimental.UtilityClass;
import org.apache.commons.lang.WordUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.inventory.ItemStack;
/**
* The current file has been created by Kiran Hart
* Date Created: August 07 2021
* Time Created: 6:36 p.m.
* Usage of any code found within this class is prohibited unless given explicit permission otherwise
*/
@UtilityClass
public class MMOItems {
public boolean isEnabled() {
return Bukkit.getPluginManager().getPlugin("MMOItems") != null;
}
private boolean hasType(@NonNull final NBTItem itemStack) {
return itemStack.hasType();
}
public String getItemType(@NonNull final ItemStack itemStack) {
NBTItem nbtItem = NBTItem.get(itemStack);
if (nbtItem == null) return ChatColor.stripColor(AuctionAPI.getInstance().getItemName(itemStack));
if (!hasType(nbtItem)) return ChatColor.stripColor(AuctionAPI.getInstance().getItemName(itemStack));
return WordUtils.capitalize(nbtItem.getType().toLowerCase().replace("_", " "));
}
}

View File

@ -0,0 +1,67 @@
package ca.tweetzy.auctionhouse.api.hook;
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.auction.AuctionPlayer;
import io.lumine.mythic.lib.comp.PlaceholderAPIHook;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import org.bukkit.OfflinePlayer;
import org.jetbrains.annotations.NotNull;
/**
* The current file has been created by Kiran Hart
* Date Created: August 07 2021
* Time Created: 6:36 p.m.
* Usage of any code found within this class is prohibited unless given explicit permission otherwise
*/
public class PlaceholderAPI extends PlaceholderExpansion {
private final AuctionHouse plugin;
public PlaceholderAPI(AuctionHouse plugin) {
this.plugin = plugin;
}
@Override
public @NotNull String getIdentifier() {
return "auctionhouse";
}
@Override
public @NotNull String getAuthor() {
return "KiranHart";
}
@Override
public @NotNull String getVersion() {
return "1.0.0";
}
@Override
public boolean persist() {
return true;
}
@Override
public String onRequest(OfflinePlayer player, @NotNull String params) {
if (params.equalsIgnoreCase("name")) return player == null ? null : player.getName();
if (params.equalsIgnoreCase("active_auctions")) {
AuctionPlayer auctionPlayer = AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(player.getUniqueId());
if (auctionPlayer == null) return null;
return String.valueOf(auctionPlayer.getItems(false).size());
}
if (params.equalsIgnoreCase("expired_auctions")) {
AuctionPlayer auctionPlayer = AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(player.getUniqueId());
if (auctionPlayer == null) return null;
return String.valueOf(auctionPlayer.getItems(true).size());
}
if (params.equalsIgnoreCase("server_active_auctions")) {
return String.valueOf(AuctionHouse.getInstance().getAuctionItemManager().getItems().size());
}
return null;
}
}

View File

@ -1,6 +1,8 @@
package ca.tweetzy.auctionhouse.auction;
import ca.tweetzy.auctionhouse.api.AuctionAPI;
import ca.tweetzy.auctionhouse.auction.AuctionItemCategory;
import ca.tweetzy.auctionhouse.auction.AuctionStackType;
import ca.tweetzy.auctionhouse.settings.Settings;
import ca.tweetzy.core.compatibility.ServerVersion;
import ca.tweetzy.core.utils.TextUtils;
@ -29,6 +31,8 @@ import java.util.stream.Collectors;
@Setter
public class AuctionItem implements Serializable {
private static final long serialVersionUID = 5679289273658775560L;
private UUID owner;
private UUID highestBidder;
@ -44,6 +48,8 @@ public class AuctionItem implements Serializable {
private boolean expired;
private int remainingTime;
public AuctionItem() {}
public AuctionItem(UUID owner, UUID highestBidder, ItemStack originalItem, AuctionItemCategory category, UUID key, double basePrice, double bidStartPrice, double bidIncPrice, double currentPrice, int remainingTime, boolean expired) {
this.owner = owner;
this.highestBidder = highestBidder;
@ -79,41 +85,41 @@ public class AuctionItem implements Serializable {
String theSeller = (this.owner == null) ? "&eSeller Name???" : Bukkit.getOfflinePlayer(this.owner).getName();
String highestBidder = (this.bidStartPrice <= 0 || this.bidIncPrice <= 0) ? "" : (this.owner.equals(this.highestBidder)) ? Bukkit.getOfflinePlayer(this.owner).getName() : Bukkit.getOfflinePlayer(this.highestBidder).getName();
String basePrice = this.basePrice == -1 || !Settings.ALLOW_USAGE_OF_BUY_NOW_SYSTEM.getBoolean() && this.bidStartPrice >= 1 ? Settings.AUCTION_PURCHASE_CONTROLS_BUY_NOW_OFF_FOR_BID.getString() : Settings.USE_SHORT_NUMBERS_ON_ITEMS.getBoolean() ? AuctionAPI.getInstance().getFriendlyNumber(this.basePrice) : AuctionAPI.getInstance().formatNumber(this.basePrice);// base
String bidIncPrice = (this.bidStartPrice <= 0 || this.bidIncPrice <= 0) ? "0" : Settings.USE_SHORT_NUMBERS_ON_ITEMS.getBoolean() ? AuctionAPI.getInstance().getFriendlyNumber(this.bidIncPrice) : AuctionAPI.getInstance().formatNumber(this.bidIncPrice);
String currentPrice = (this.bidStartPrice <= 0 || this.bidIncPrice <= 0) ? "0" : Settings.USE_SHORT_NUMBERS_ON_ITEMS.getBoolean() ? AuctionAPI.getInstance().getFriendlyNumber(this.currentPrice) : AuctionAPI.getInstance().formatNumber(this.currentPrice);
long[] times = AuctionAPI.getInstance().getRemainingTimeValues(this.remainingTime);
List<String> preLore = type == AuctionStackType.MAIN_AUCTION_HOUSE ? this.bidStartPrice <= 0 || this.bidIncPrice <= 0 ? Settings.AUCTION_ITEM_AUCTION_STACK.getStringList() : Settings.AUCTION_ITEM_AUCTION_STACK_WITH_BID.getStringList() : this.bidStartPrice <= 0 ? Settings.AUCTION_ITEM_LISTING_STACK.getStringList() : Settings.AUCTION_ITEM_LISTING_STACK_WITH_BID.getStringList();
lore.addAll(preLore.stream().map(line -> TextUtils.formatText(line
.replace("%seller%", theSeller != null ? theSeller : "&eUnknown Seller")
.replace("%buynowprice%", basePrice)
.replace("%currentprice%", currentPrice)
.replace("%bidincrement%", bidIncPrice)
.replace("%highestbidder%", highestBidder != null ? highestBidder : "&eUnknown Bidder")
.replace("%remaining_days%", String.valueOf(times[0]))
.replace("%remaining_hours%", String.valueOf(times[1]))
.replace("%remaining_minutes%", String.valueOf(times[2]))
.replace("%remaining_seconds%", String.valueOf(times[3])))).collect(Collectors.toList()));
if (type == AuctionStackType.MAIN_AUCTION_HOUSE) {
lore.addAll(Settings.AUCTION_PURCHASE_CONTROL_HEADER.getStringList().stream().map(TextUtils::formatText).collect(Collectors.toList()));
lore.addAll(this.bidStartPrice <= 0 || this.bidIncPrice <= 0 || !Settings.ALLOW_USAGE_OF_BUY_NOW_SYSTEM.getBoolean() ? Settings.AUCTION_PURCHASE_CONTROLS_BID_OFF.getStringList().stream().map(TextUtils::formatText).collect(Collectors.toList()) : Settings.AUCTION_PURCHASE_CONTROLS_BID_ON.getStringList().stream().map(TextUtils::formatText).collect(Collectors.toList()));
if (NBTEditor.contains(itemStack, "AuctionBundleItem") || (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_11) && itemStack.getType().name().contains("SHULKER_BOX"))) {
lore.addAll(Settings.AUCTION_PURCHASE_CONTROLS_INSPECTION.getStringList().stream().map(TextUtils::formatText).collect(Collectors.toList()));
}
lore.addAll(Settings.AUCTION_PURCHASE_CONTROL_FOOTER.getStringList().stream().map(TextUtils::formatText).collect(Collectors.toList()));
} else {
if (Settings.ALLOW_PLAYERS_TO_ACCEPT_BID.getBoolean() && this.bidStartPrice >= 1 || this.bidIncPrice >= 1) {
if (!this.owner.equals(this.highestBidder)) {
lore.addAll(Settings.AUCTION_PURCHASE_CONTROLS_ACCEPT_BID.getStringList().stream().map(TextUtils::formatText).collect(Collectors.toList()));
}
}
}
// String basePrice = this.basePrice == -1 || !Settings.ALLOW_USAGE_OF_BUY_NOW_SYSTEM.getBoolean() && this.bidStartPrice >= 1 ? Settings.AUCTION_PURCHASE_CONTROLS_BUY_NOW_OFF_FOR_BID.getString() : Settings.USE_SHORT_NUMBERS_ON_ITEMS.getBoolean() ? AuctionAPI.getInstance().getFriendlyNumber(this.basePrice) : AuctionAPI.getInstance().formatNumber(this.basePrice);// base
//
// String bidIncPrice = (this.bidStartPrice <= 0 || this.bidIncPrice <= 0) ? "0" : Settings.USE_SHORT_NUMBERS_ON_ITEMS.getBoolean() ? AuctionAPI.getInstance().getFriendlyNumber(this.bidIncPrice) : AuctionAPI.getInstance().formatNumber(this.bidIncPrice);
// String currentPrice = (this.bidStartPrice <= 0 || this.bidIncPrice <= 0) ? "0" : Settings.USE_SHORT_NUMBERS_ON_ITEMS.getBoolean() ? AuctionAPI.getInstance().getFriendlyNumber(this.currentPrice) : AuctionAPI.getInstance().formatNumber(this.currentPrice);
//
// long[] times = AuctionAPI.getInstance().getRemainingTimeValues(this.remainingTime);
// List<String> preLore = type == AuctionStackType.MAIN_AUCTION_HOUSE ? this.bidStartPrice <= 0 || this.bidIncPrice <= 0 ? Settings.AUCTION_ITEM_AUCTION_STACK.getStringList() : Settings.AUCTION_ITEM_AUCTION_STACK_WITH_BID.getStringList() : this.bidStartPrice <= 0 ? Settings.AUCTION_ITEM_LISTING_STACK.getStringList() : Settings.AUCTION_ITEM_LISTING_STACK_WITH_BID.getStringList();
//
// lore.addAll(preLore.stream().map(line -> TextUtils.formatText(line
// .replace("%seller%", theSeller != null ? theSeller : "&eUnknown Seller")
// .replace("%buynowprice%", basePrice)
// .replace("%currentprice%", currentPrice)
// .replace("%bidincrement%", bidIncPrice)
// .replace("%highestbidder%", highestBidder != null ? highestBidder : "&eUnknown Bidder")
// .replace("%remaining_days%", String.valueOf(times[0]))
// .replace("%remaining_hours%", String.valueOf(times[1]))
// .replace("%remaining_minutes%", String.valueOf(times[2]))
// .replace("%remaining_seconds%", String.valueOf(times[3])))).collect(Collectors.toList()));
//
// if (type == AuctionStackType.MAIN_AUCTION_HOUSE) {
// lore.addAll(Settings.AUCTION_PURCHASE_CONTROL_HEADER.getStringList().stream().map(TextUtils::formatText).collect(Collectors.toList()));
// lore.addAll(this.bidStartPrice <= 0 || this.bidIncPrice <= 0 || !Settings.ALLOW_USAGE_OF_BUY_NOW_SYSTEM.getBoolean() ? Settings.AUCTION_PURCHASE_CONTROLS_BID_OFF.getStringList().stream().map(TextUtils::formatText).collect(Collectors.toList()) : Settings.AUCTION_PURCHASE_CONTROLS_BID_ON.getStringList().stream().map(TextUtils::formatText).collect(Collectors.toList()));
//
// if (NBTEditor.contains(itemStack, "AuctionBundleItem") || (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_11) && itemStack.getType().name().contains("SHULKER_BOX"))) {
// lore.addAll(Settings.AUCTION_PURCHASE_CONTROLS_INSPECTION.getStringList().stream().map(TextUtils::formatText).collect(Collectors.toList()));
// }
//
// lore.addAll(Settings.AUCTION_PURCHASE_CONTROL_FOOTER.getStringList().stream().map(TextUtils::formatText).collect(Collectors.toList()));
// } else {
// if (Settings.ALLOW_PLAYERS_TO_ACCEPT_BID.getBoolean() && this.bidStartPrice >= 1 || this.bidIncPrice >= 1) {
// if (!this.owner.equals(this.highestBidder)) {
// lore.addAll(Settings.AUCTION_PURCHASE_CONTROLS_ACCEPT_BID.getStringList().stream().map(TextUtils::formatText).collect(Collectors.toList()));
// }
// }
// }
meta.setLore(lore);
itemStack.setItemMeta(meta);

View File

@ -25,18 +25,19 @@ public class AuctionPlayer {
private AuctionItemCategory selectedFilter;
private AuctionSortType auctionSortType;
private String currentSearchPhrase;
private boolean showListingInfo = true;
public AuctionPlayer(Player player) {
this.player = player;
resetFilter();
}
public List<AuctionItem> getItems(boolean getExpired) {
List<AuctionItem> items = new ArrayList<>();
public List<AuctionedItem> getItems(boolean getExpired) {
List<AuctionedItem> items = new ArrayList<>();
for (Map.Entry<UUID, AuctionItem> entry : AuctionHouse.getInstance().getAuctionItemManager().getAuctionItems().entrySet()) {
AuctionItem auctionItem = entry.getValue();
if (auctionItem.getOwner().equals(this.player.getUniqueId()) && auctionItem.isExpired() == getExpired && !AuctionHouse.getInstance().getAuctionItemManager().getGarbageBin().containsKey(auctionItem.getKey())) {
for (Map.Entry<UUID, AuctionedItem> entry : AuctionHouse.getInstance().getAuctionItemManager().getItems().entrySet()) {
AuctionedItem auctionItem = entry.getValue();
if (auctionItem.getOwner().equals(this.player.getUniqueId()) && auctionItem.isExpired() == getExpired && !AuctionHouse.getInstance().getAuctionItemManager().getGarbageBin().containsKey(auctionItem.getId())) {
items.add(auctionItem);
}
}

View File

@ -0,0 +1,143 @@
package ca.tweetzy.auctionhouse.auction;
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.api.AuctionAPI;
import ca.tweetzy.auctionhouse.settings.Settings;
import ca.tweetzy.core.compatibility.ServerVersion;
import ca.tweetzy.core.utils.TextUtils;
import ca.tweetzy.core.utils.nms.NBTEditor;
import lombok.Getter;
import lombok.NonNull;
import lombok.Setter;
import org.bukkit.Bukkit;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
/**
* The current file has been created by Kiran Hart
* Date Created: July 29 2021
* Time Created: 6:58 p.m.
* Usage of any code found within this class is prohibited unless given explicit permission otherwise
*/
@Getter
@Setter
public class AuctionedItem {
private UUID id;
private UUID owner;
private UUID highestBidder;
private String ownerName;
private String highestBidderName;
private AuctionItemCategory category;
private ItemStack item;
private double basePrice;
private double bidStartingPrice;
private double bidIncrementPrice;
private double currentPrice;
private boolean isBidItem;
private boolean expired;
private long expiresAt;
public AuctionedItem() {}
public AuctionedItem(
@NonNull UUID id,
@NonNull UUID owner,
@NonNull UUID highestBidder,
@NonNull String ownerName,
@NonNull String highestBidderName,
@NonNull AuctionItemCategory category,
@NonNull ItemStack item,
double basePrice,
double bidStartingPrice,
double bidIncrementPrice,
double currentPrice,
boolean isBidItem,
boolean expired,
long expiresAt
) {
this.id = id;
this.owner = owner;
this.highestBidder = highestBidder;
this.ownerName = ownerName;
this.highestBidderName = highestBidderName;
this.category = category;
this.item = item;
this.basePrice = basePrice;
this.bidStartingPrice = bidStartingPrice;
this.bidIncrementPrice = bidIncrementPrice;
this.currentPrice = currentPrice;
this.isBidItem = isBidItem;
this.expired = expired;
this.expiresAt = expiresAt;
}
public ItemStack getDisplayStack(AuctionStackType type) {
ItemStack itemStack = this.item.clone();
itemStack.setAmount(Math.max(this.item.getAmount(), 1));
ItemMeta meta = itemStack.hasItemMeta() ? itemStack.getItemMeta() : Bukkit.getItemFactory().getItemMeta(itemStack.getType());
List<String> lore = (meta.hasLore()) ? meta.getLore() : new ArrayList<>();
lore.addAll(TextUtils.formatText(Settings.AUCTION_STACK_DETAILS_HEADER.getStringList()));
lore.addAll(TextUtils.formatText(Settings.AUCTION_STACK_DETAILS_SELLER.getStringList().stream().map(s -> s.replace("%seller%", this.ownerName)).collect(Collectors.toList())));
if (this.basePrice != -1) {
lore.addAll(TextUtils.formatText(Settings.AUCTION_STACK_DETAILS_BUY_NOW.getStringList().stream().filter(s -> this.isBidItem ? s.length() != 0 : s.length() >= 0).map(s -> s.replace("%buynowprice%", Settings.USE_SHORT_NUMBERS_ON_ITEMS.getBoolean() ? AuctionAPI.getInstance().getFriendlyNumber(this.basePrice) : AuctionAPI.getInstance().formatNumber(this.basePrice))).collect(Collectors.toList())));
}
if (this.isBidItem) {
lore.addAll(TextUtils.formatText(Settings.AUCTION_STACK_DETAILS_CURRENT_PRICE.getStringList().stream().map(s -> s.replace("%currentprice%", Settings.USE_SHORT_NUMBERS_ON_ITEMS.getBoolean() ? AuctionAPI.getInstance().getFriendlyNumber(this.currentPrice) : AuctionAPI.getInstance().formatNumber(this.currentPrice))).collect(Collectors.toList())));
lore.addAll(TextUtils.formatText(Settings.AUCTION_STACK_DETAILS_BID_INCREMENT.getStringList().stream().map(s -> s.replace("%bidincrement%", Settings.USE_SHORT_NUMBERS_ON_ITEMS.getBoolean() ? AuctionAPI.getInstance().getFriendlyNumber(this.bidIncrementPrice) : AuctionAPI.getInstance().formatNumber(this.bidIncrementPrice))).collect(Collectors.toList())));
lore.addAll(TextUtils.formatText(Settings.AUCTION_STACK_DETAILS_HIGHEST_BIDDER.getStringList().stream().map(s -> s.replace("%highestbidder%", this.highestBidder.equals(this.owner) ? AuctionHouse.getInstance().getLocale().getMessage("auction.nobids").getMessage() : this.highestBidderName)).collect(Collectors.toList())));
}
long[] times = AuctionAPI.getInstance().getRemainingTimeValues((this.expiresAt - System.currentTimeMillis()) / 1000);
lore.addAll(TextUtils.formatText(Settings.AUCTION_STACK_DETAILS_TIME_LEFT.getStringList().stream().map(s -> s
.replace("%remaining_days%", String.valueOf(times[0]))
.replace("%remaining_hours%", String.valueOf(times[1]))
.replace("%remaining_minutes%", String.valueOf(times[2]))
.replace("%remaining_seconds%", String.valueOf(times[3]))
).collect(Collectors.toList())));
lore.addAll(TextUtils.formatText(Settings.AUCTION_STACK_PURCHASE_CONTROL_HEADER.getStringList()));
if (type == AuctionStackType.MAIN_AUCTION_HOUSE) {
if (this.isBidItem) {
if (this.basePrice != -1) {
lore.addAll(TextUtils.formatText(Settings.AUCTION_STACK_PURCHASE_CONTROLS_BID_ON.getStringList()));
} else {
lore.addAll(TextUtils.formatText(Settings.AUCTION_STACK_PURCHASE_CONTROLS_BID_ON_NO_BUY_NOW.getStringList()));
}
} else {
lore.addAll(TextUtils.formatText(Settings.AUCTION_STACK_PURCHASE_CONTROLS_BID_OFF.getStringList()));
}
if (NBTEditor.contains(itemStack, "AuctionBundleItem") || (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_11) && itemStack.getType().name().contains("SHULKER_BOX"))) {
lore.addAll(TextUtils.formatText(Settings.AUCTION_STACK_PURCHASE_CONTROLS_INSPECTION.getStringList()));
}
} else {
lore.addAll(TextUtils.formatText(Settings.AUCTION_STACK_PURCHASE_CONTROLS_CANCEL_ITEM.getStringList()));
if (Settings.ALLOW_PLAYERS_TO_ACCEPT_BID.getBoolean() && this.bidStartingPrice >= 1 || this.bidIncrementPrice >= 1) {
if (!this.owner.equals(this.highestBidder)) {
lore.addAll(TextUtils.formatText(Settings.AUCTION_STACK_PURCHASE_CONTROLS_ACCEPT_BID.getStringList()));
}
}
}
lore.addAll(TextUtils.formatText(Settings.AUCTION_STACK_PURCHASE_CONTROL_FOOTER.getStringList()));
meta.setLore(lore);
itemStack.setItemMeta(meta);
itemStack = NBTEditor.set(itemStack, this.id.toString(), "AuctionItemKey");
return itemStack;
}
}

View File

@ -1,6 +1,7 @@
package ca.tweetzy.auctionhouse.commands;
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.api.AuctionAPI;
import ca.tweetzy.auctionhouse.auction.AuctionPlayer;
import ca.tweetzy.auctionhouse.guis.GUIActiveAuctions;
import ca.tweetzy.core.commands.AbstractCommand;
@ -28,6 +29,8 @@ public class CommandActive extends AbstractCommand {
protected ReturnType runCommand(CommandSender sender, String... args) {
Player player = (Player) sender;
if (AuctionAPI.tellMigrationStatus(player)) return ReturnType.FAILURE;
if (AuctionHouse.getInstance().getAuctionBanManager().checkAndHandleBan(player)) {
return ReturnType.FAILURE;
}

View File

@ -32,40 +32,28 @@ public class CommandAdmin extends AbstractCommand {
@Override
protected ReturnType runCommand(CommandSender sender, String... args) {
if (args.length < 1) return ReturnType.FAILURE;
if (AuctionAPI.tellMigrationStatus(sender)) return ReturnType.FAILURE;
switch (args[0].toLowerCase()) {
case "endall":
for (UUID id : AuctionHouse.getInstance().getAuctionItemManager().getAuctionItems().keySet()) {
AuctionHouse.getInstance().getAuctionItemManager().getAuctionItems().get(id).setExpired(true);
for (UUID id : AuctionHouse.getInstance().getAuctionItemManager().getItems().keySet()) {
AuctionHouse.getInstance().getAuctionItemManager().getItems().get(id).setExpired(true);
}
AuctionHouse.getInstance().getLocale().getMessage("general.endedallauctions").sendPrefixedMessage(sender);
break;
case "relistall":
int relistTime = args.length == 1 ? Settings.DEFAULT_AUCTION_TIME.getInt() : Integer.parseInt(args[1]);
for (UUID id : AuctionHouse.getInstance().getAuctionItemManager().getAuctionItems().keySet()) {
if (AuctionHouse.getInstance().getAuctionItemManager().getAuctionItems().get(id).isExpired()) {
AuctionHouse.getInstance().getAuctionItemManager().getAuctionItems().get(id).setRemainingTime(relistTime);
AuctionHouse.getInstance().getAuctionItemManager().getAuctionItems().get(id).setExpired(false);
for (UUID id : AuctionHouse.getInstance().getAuctionItemManager().getItems().keySet()) {
if (AuctionHouse.getInstance().getAuctionItemManager().getItems().get(id).isExpired()) {
AuctionHouse.getInstance().getAuctionItemManager().getItems().get(id).setExpiresAt(System.currentTimeMillis() + 1000L * relistTime);
AuctionHouse.getInstance().getAuctionItemManager().getItems().get(id).setExpired(false);
}
}
AuctionHouse.getInstance().getLocale().getMessage("general.relisteditems").sendPrefixedMessage(sender);
break;
case "cleanunknownusers":
// Don't tell ppl that this exists
AuctionHouse.getInstance().getAuctionItemManager().removeUnknownOwnerItems();
break;
case "clearall":
// Don't tell ppl that this exists
AuctionHouse.getInstance().getAuctionItemManager().getAuctionItems().clear();
case "clean":
// Don't tell ppl that this exists
for (UUID id : AuctionHouse.getInstance().getAuctionItemManager().getAuctionItems().keySet()) {
ItemStack deserialize = AuctionAPI.getInstance().deserializeItem(AuctionHouse.getInstance().getAuctionItemManager().getAuctionItems().get(id).getRawItem());
if (deserialize == null || XMaterial.isAir(XMaterial.matchXMaterial(deserialize))) {
AuctionHouse.getInstance().getAuctionItemManager().sendToGarbage(AuctionHouse.getInstance().getAuctionItemManager().getAuctionItems().get(id));
}
}
break;
AuctionHouse.getInstance().getAuctionItemManager().getItems().clear();
case "opensell":
if (args.length < 2) return ReturnType.FAILURE;
Player player = PlayerUtils.findPlayer(args[1]);

View File

@ -1,11 +1,12 @@
package ca.tweetzy.auctionhouse.commands;
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.api.AuctionAPI;
import ca.tweetzy.auctionhouse.auction.AuctionPlayer;
import ca.tweetzy.auctionhouse.guis.GUIAuctionHouse;
import ca.tweetzy.core.commands.AbstractCommand;
import ca.tweetzy.core.utils.TextUtils;
import ca.tweetzy.core.utils.TimeUtils;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -29,6 +30,7 @@ public class CommandAuctionHouse extends AbstractCommand {
protected ReturnType runCommand(CommandSender sender, String... args) {
if (sender instanceof Player) {
Player player = (Player) sender;
if (AuctionAPI.tellMigrationStatus(player)) return ReturnType.FAILURE;
if (AuctionHouse.getInstance().getAuctionBanManager().checkAndHandleBan(player)) {
return ReturnType.FAILURE;
@ -39,7 +41,14 @@ public class CommandAuctionHouse extends AbstractCommand {
AuctionHouse.getInstance().getAuctionPlayerManager().addPlayer(new AuctionPlayer(player));
}
AuctionHouse.getInstance().getGuiManager().showGUI(player, new GUIAuctionHouse(AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(player.getUniqueId())));
if (args.length == 0) {
AuctionHouse.getInstance().getGuiManager().showGUI(player, new GUIAuctionHouse(AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(player.getUniqueId())));
return ReturnType.SUCCESS;
}
if (args.length == 1 && AuctionHouse.getInstance().getCommandManager().getSubCommands("auctionhouse").stream().noneMatch(cmd -> cmd.equalsIgnoreCase(StringUtils.join(args, ' ').trim()))) {
AuctionHouse.getInstance().getGuiManager().showGUI(player, new GUIAuctionHouse(AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(player.getUniqueId()), StringUtils.join(args, ' ').trim()));
}
}
return ReturnType.SUCCESS;
}
@ -47,7 +56,7 @@ public class CommandAuctionHouse extends AbstractCommand {
@Override
protected List<String> onTab(CommandSender sender, String... args) {
Player player = (Player) sender;
return AuctionHouse.getInstance().getCommandManager().getAllCommands().stream().filter(cmd -> cmd.getPermissionNode() == null || player.hasPermission(cmd.getPermissionNode())).map(AbstractCommand::getSyntax).collect(Collectors.toList());
return AuctionHouse.getInstance().getCommandManager().getAllCommands().stream().filter(cmd -> cmd.getPermissionNode() == null || player.hasPermission(cmd.getPermissionNode())).map(AbstractCommand::getSyntax).collect(Collectors.toList());
}
@Override

View File

@ -31,6 +31,8 @@ public class CommandBan extends AbstractCommand {
@Override
protected ReturnType runCommand(CommandSender sender, String... args) {
Player player = (Player) sender;
if (AuctionAPI.tellMigrationStatus(player)) return ReturnType.FAILURE;
if (args.length == 0) {
// Open the bans menu
AuctionHouse.getInstance().getGuiManager().showGUI(player, new GUIBans());

View File

@ -1,111 +0,0 @@
package ca.tweetzy.auctionhouse.commands;
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.auction.AuctionItem;
import ca.tweetzy.auctionhouse.auction.AuctionItemCategory;
import ca.tweetzy.auctionhouse.helpers.MaterialCategorizer;
import ca.tweetzy.core.commands.AbstractCommand;
import ca.tweetzy.core.utils.TextUtils;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
/**
* The current file has been created by Kiran Hart
* Date Created: March 29 2021
* Time Created: 3:56 p.m.
* Usage of any code found within this class is prohibited unless given explicit permission otherwise
*/
public class CommandConvert extends AbstractCommand {
public CommandConvert() {
super(CommandType.CONSOLE_OK, "convert");
}
@Override
protected ReturnType runCommand(CommandSender sender, String... args) {
handleLegacyConversion(sender);
return ReturnType.SUCCESS;
}
@Override
public String getPermissionNode() {
return "auctionhouse.cmd.convert";
}
@Override
public String getSyntax() {
return AuctionHouse.getInstance().getLocale().getMessage("commands.syntax.convert").getMessage();
}
@Override
public String getDescription() {
return AuctionHouse.getInstance().getLocale().getMessage("commands.description.convert").getMessage();
}
@Override
protected List<String> onTab(CommandSender sender, String... args) {
return null;
}
private void handleLegacyConversion(CommandSender sender) {
AuctionHouse.getInstance().getLocale().newMessage(TextUtils.formatText("&4Beginning the ATTEMPTED conversion process, this may take some time.")).sendPrefixedMessage(sender);
long start = System.currentTimeMillis();
Bukkit.getServer().getScheduler().runTaskLater(AuctionHouse.getInstance(), () -> {
ConfigurationSection activeSection = AuctionHouse.getInstance().getData().getConfigurationSection("active");
ConfigurationSection expiredSection = AuctionHouse.getInstance().getData().getConfigurationSection("expired");
if (activeSection == null || expiredSection == null) {
AuctionHouse.getInstance().getLocale().newMessage(TextUtils.formatText("&4Active/Expired section(s) could not be found, have you ran the conversion command already?")).sendPrefixedMessage(sender);
return;
}
if (activeSection != null && activeSection.getKeys(false).size() != 0) {
activeSection.getKeys(false).forEach(key -> AuctionHouse.getInstance().getAuctionItemManager().addItem(new AuctionItem(
UUID.fromString(Objects.requireNonNull(AuctionHouse.getInstance().getData().getString("active." + key + ".owner"))),
UUID.fromString(Objects.requireNonNull(AuctionHouse.getInstance().getData().getString("active." + key + ".highestbidder"))),
AuctionHouse.getInstance().getData().getItemStack("active." + key + ".item"),
MaterialCategorizer.getMaterialCategory(Objects.requireNonNull(AuctionHouse.getInstance().getData().getItemStack("active." + key + ".item"))),
UUID.fromString(Objects.requireNonNull(AuctionHouse.getInstance().getData().getString("active." + key + ".key"))),
AuctionHouse.getInstance().getData().getDouble("active." + key + ".buynowprice"),
AuctionHouse.getInstance().getData().getDouble("active." + key + ".startprice"),
AuctionHouse.getInstance().getData().getDouble("active." + key + ".bidincrement"),
AuctionHouse.getInstance().getData().getDouble("active." + key + ".currentprice"),
AuctionHouse.getInstance().getData().getInt("active." + key + ".time"),
false
)));
AuctionHouse.getInstance().getData().set("active", null);
}
if (expiredSection != null && expiredSection.getKeys(false).size() != 0) {
expiredSection.getKeys(false).forEach(expiredItemOwner -> {
if (AuctionHouse.getInstance().getData().getConfigurationSection("expired." + expiredItemOwner) != null && AuctionHouse.getInstance().getData().getConfigurationSection("expired." + expiredItemOwner).getKeys(false).size() != 0) {
AuctionHouse.getInstance().getData().getConfigurationSection("expired." + expiredItemOwner).getKeys(false).forEach(ownedItem -> AuctionHouse.getInstance().getAuctionItemManager().addItem(new AuctionItem(
UUID.fromString(expiredItemOwner),
UUID.fromString(expiredItemOwner),
AuctionHouse.getInstance().getData().getItemStack("expired." + expiredItemOwner + "." + ownedItem + ".item"),
AuctionItemCategory.ALL,
UUID.fromString(ownedItem),
1D,
1D,
1D,
1D,
0,
true
)));
}
});
AuctionHouse.getInstance().getData().set("expired", null);
}
AuctionHouse.getInstance().getLocale().newMessage("&aFinished Conversion Process (" + (System.currentTimeMillis() - start) + "ms)").sendPrefixedMessage(sender);
AuctionHouse.getInstance().getData().save();
}, 1L);
}
}

View File

@ -1,6 +1,7 @@
package ca.tweetzy.auctionhouse.commands;
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.api.AuctionAPI;
import ca.tweetzy.auctionhouse.auction.AuctionPlayer;
import ca.tweetzy.auctionhouse.guis.GUIExpiredItems;
import ca.tweetzy.core.commands.AbstractCommand;
@ -27,6 +28,7 @@ public class CommandExpired extends AbstractCommand {
@Override
protected ReturnType runCommand(CommandSender sender, String... args) {
Player player = (Player) sender;
if (AuctionAPI.tellMigrationStatus(player)) return ReturnType.FAILURE;
if (AuctionHouse.getInstance().getAuctionBanManager().checkAndHandleBan(player)) {
return ReturnType.FAILURE;

View File

@ -32,6 +32,7 @@ public class CommandFilter extends AbstractCommand {
@Override
protected ReturnType runCommand(CommandSender sender, String... args) {
Player player = (Player) sender;
if (AuctionAPI.tellMigrationStatus(player)) return ReturnType.FAILURE;
if (args.length == 0) {
AuctionHouse.getInstance().getGuiManager().showGUI(player, new GUIFilterWhitelist());

View File

@ -0,0 +1,64 @@
package ca.tweetzy.auctionhouse.commands;
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.core.commands.AbstractCommand;
import ca.tweetzy.core.utils.TextUtils;
import org.bukkit.command.CommandSender;
import java.util.Collections;
import java.util.List;
/**
* The current file has been created by Kiran Hart
* Date Created: August 10 2021
* Time Created: 12:25 p.m.
* Usage of any code found within this class is prohibited unless given explicit permission otherwise
*/
public class CommandMigrate extends AbstractCommand {
public CommandMigrate() {
super(CommandType.CONSOLE_OK, "migrate");
}
@Override
protected ReturnType runCommand(CommandSender sender, String... args) {
if (args.length == 0) {
AuctionHouse.getInstance().getLocale().newMessage(TextUtils.formatText("&cUse '/ah migrate confirm' to confirm the migration, please sure that you have made a backup of your auction house data.yml / auction house database tables. Although everything should work fine, there is always a chance that something wil go wrong.")).sendPrefixedMessage(sender);
return ReturnType.FAILURE;
}
if (args.length == 1 && !args[0].equalsIgnoreCase("confirm")) return ReturnType.SYNTAX_ERROR;
// Begin migration
AuctionHouse.getInstance().getLocale().newMessage(TextUtils.formatText("&cMIGRATION STARTED")).sendPrefixedMessage(sender);
AuctionHouse.getInstance().getLocale().newMessage(TextUtils.formatText("&eAuction House usage will be disabled until it is finished, this may take some time depending on how many items you have stored.")).sendPrefixedMessage(sender);
AuctionHouse.getInstance().getDataManager().migrateFromSerializationFormat(items -> {
AuctionHouse.getInstance().getLocale().newMessage(TextUtils.formatText("&aMIGRATION FINISHED")).sendPrefixedMessage(sender);
AuctionHouse.getInstance().getLocale().newMessage(TextUtils.formatText("&eConverted a total of " + items.size() + " to new format")).sendPrefixedMessage(sender);
AuctionHouse.getInstance().getLocale().newMessage(TextUtils.formatText("&eYou can now use the auction house safely")).sendPrefixedMessage(sender);
});
return ReturnType.SUCCESS;
}
@Override
protected List<String> onTab(CommandSender sender, String... args) {
if (args.length == 1) return Collections.singletonList("confirm");
return null;
}
@Override
public String getPermissionNode() {
return "auctionhouse.cmd.migrate";
}
@Override
public String getSyntax() {
return "migrate <confirm>";
}
@Override
public String getDescription() {
return "Migrate from old data format to new format";
}
}

View File

@ -1,6 +1,7 @@
package ca.tweetzy.auctionhouse.commands;
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.api.AuctionAPI;
import ca.tweetzy.core.commands.AbstractCommand;
import ca.tweetzy.core.utils.TextUtils;
import org.bukkit.command.CommandSender;
@ -21,6 +22,7 @@ public class CommandReload extends AbstractCommand {
@Override
protected ReturnType runCommand(CommandSender sender, String... args) {
if (AuctionAPI.tellMigrationStatus(sender)) return ReturnType.FAILURE;
AuctionHouse.getInstance().reloadConfig();
AuctionHouse.getInstance().getLocale().newMessage(TextUtils.formatText("&aReloaded files")).sendPrefixedMessage(sender);
return ReturnType.SUCCESS;

View File

@ -1,6 +1,7 @@
package ca.tweetzy.auctionhouse.commands;
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.api.AuctionAPI;
import ca.tweetzy.auctionhouse.auction.AuctionPlayer;
import ca.tweetzy.auctionhouse.guis.GUIAuctionHouse;
import ca.tweetzy.core.commands.AbstractCommand;
@ -28,6 +29,7 @@ public class CommandSearch extends AbstractCommand {
protected ReturnType runCommand(CommandSender sender, String... args) {
if (args.length <= 0) return ReturnType.SYNTAX_ERROR;
Player player = (Player) sender;
if (AuctionAPI.tellMigrationStatus(player)) return ReturnType.FAILURE;
if (AuctionHouse.getInstance().getAuctionBanManager().checkAndHandleBan(player)) {
return ReturnType.FAILURE;
@ -42,6 +44,7 @@ public class CommandSearch extends AbstractCommand {
AuctionHouse.getInstance().getLocale().newMessage(TextUtils.formatText("&cCould not find auction player instance for&f: &e" + player.getName() + "&c creating one now.")).sendPrefixedMessage(Bukkit.getConsoleSender());
AuctionHouse.getInstance().getAuctionPlayerManager().addPlayer(new AuctionPlayer(player));
}
AuctionHouse.getInstance().getGuiManager().showGUI(player, new GUIAuctionHouse(AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(player.getUniqueId()), builder.toString().trim()));
return ReturnType.SUCCESS;
}

View File

@ -2,22 +2,16 @@ package ca.tweetzy.auctionhouse.commands;
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.api.AuctionAPI;
import ca.tweetzy.auctionhouse.api.events.AuctionStartEvent;
import ca.tweetzy.auctionhouse.auction.AuctionItem;
import ca.tweetzy.auctionhouse.auction.AuctionPlayer;
import ca.tweetzy.auctionhouse.guis.GUISellItem;
import ca.tweetzy.auctionhouse.helpers.MaterialCategorizer;
import ca.tweetzy.auctionhouse.helpers.PlayerHelper;
import ca.tweetzy.auctionhouse.managers.SoundManager;
import ca.tweetzy.auctionhouse.settings.Settings;
import ca.tweetzy.core.commands.AbstractCommand;
import ca.tweetzy.core.compatibility.CompatibleHand;
import ca.tweetzy.core.compatibility.XMaterial;
import ca.tweetzy.core.hooks.EconomyManager;
import ca.tweetzy.core.utils.NumberUtils;
import ca.tweetzy.core.utils.PlayerUtils;
import ca.tweetzy.core.utils.nms.NBTEditor;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -25,7 +19,6 @@ import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
/**
@ -43,6 +36,7 @@ public class CommandSell extends AbstractCommand {
@Override
protected ReturnType runCommand(CommandSender sender, String... args) {
Player player = (Player) sender;
if (AuctionAPI.tellMigrationStatus(player)) return ReturnType.FAILURE;
if (AuctionHouse.getInstance().getAuctionBanManager().checkAndHandleBan(player)) {
return ReturnType.FAILURE;
@ -227,71 +221,21 @@ public class CommandSell extends AbstractCommand {
isUsingBundle = true;
}
AuctionItem auctionItem = Settings.ALLOW_USAGE_OF_BUY_NOW_SYSTEM.getBoolean() && !Settings.FORCE_AUCTION_USAGE.getBoolean() ? new AuctionItem(
player.getUniqueId(),
player.getUniqueId(),
final boolean buyNowAllow = Settings.ALLOW_USAGE_OF_BUY_NOW_SYSTEM.getBoolean() && !Settings.FORCE_AUCTION_USAGE.getBoolean();
AuctionAPI.getInstance().listAuction(
player,
originalItem,
itemToSell,
MaterialCategorizer.getMaterialCategory(itemToSell),
UUID.randomUUID(),
isBiddingItem && listingPrices.get(0) <= -1 ? -1 : listingPrices.get(0),
isBiddingItem ? listingPrices.get(1) : 0,
isBiddingItem ? listingPrices.get(2) : 0,
isBiddingItem ? listingPrices.get(1) : listingPrices.get(0),
allowedTime,
false
) : new AuctionItem(
player.getUniqueId(),
player.getUniqueId(),
itemToSell,
MaterialCategorizer.getMaterialCategory(itemToSell),
UUID.randomUUID(),
isBiddingItem ? -1 : listingPrices.get(0),
isBiddingItem ? listingPrices.get(0) : 0,
isBiddingItem ? listingPrices.size() == 1 ? 1 : listingPrices.get(1) : 0,
listingPrices.get(0),
allowedTime,
false
buyNowAllow ? isBiddingItem && listingPrices.get(0) <= -1 ? -1 : listingPrices.get(0) : isBiddingItem ? -1 : listingPrices.get(0),
buyNowAllow ? isBiddingItem ? listingPrices.get(1) : 0 : isBiddingItem ? listingPrices.get(0) : 0,
buyNowAllow ? isBiddingItem ? listingPrices.get(2) : 0 : isBiddingItem ? listingPrices.size() == 1 ? 1 : listingPrices.get(1) : 0,
buyNowAllow ? isBiddingItem ? listingPrices.get(1) : listingPrices.get(0) : listingPrices.get(0),
isBiddingItem,
isUsingBundle
);
if (Settings.TAX_ENABLED.getBoolean() && Settings.TAX_CHARGE_LISTING_FEE.getBoolean()) {
if (!EconomyManager.hasBalance(player, Settings.TAX_LISTING_FEE.getDouble())) {
AuctionHouse.getInstance().getLocale().getMessage("auction.tax.cannotpaylistingfee").processPlaceholder("price", String.format("%,.2f", Settings.TAX_LISTING_FEE.getDouble())).sendPrefixedMessage(player);
return ReturnType.FAILURE;
}
EconomyManager.withdrawBalance(player, Settings.TAX_LISTING_FEE.getDouble());
AuctionHouse.getInstance().getLocale().getMessage("auction.tax.paidlistingfee").processPlaceholder("price", String.format("%,.2f", Settings.TAX_LISTING_FEE.getDouble())).sendPrefixedMessage(player);
AuctionHouse.getInstance().getLocale().getMessage("pricing.moneyremove").processPlaceholder("price", String.format("%,.2f", Settings.TAX_LISTING_FEE.getDouble())).sendPrefixedMessage(player);
}
AuctionStartEvent startEvent = new AuctionStartEvent(player, auctionItem);
Bukkit.getServer().getPluginManager().callEvent(startEvent);
if (startEvent.isCancelled()) return ReturnType.FAILURE;
AuctionHouse.getInstance().getAuctionItemManager().addItem(auctionItem);
if (isUsingBundle) {
AuctionAPI.getInstance().removeSpecificItemQuantityFromPlayer(player, originalItem, AuctionAPI.getInstance().getItemCountInPlayerInventory(player, originalItem));
} else {
PlayerUtils.takeActiveItem(player, CompatibleHand.MAIN_HAND, itemToSell.getAmount());
}
SoundManager.getInstance().playSound(player, Settings.SOUNDS_LISTED_ITEM_ON_AUCTION_HOUSE.getString(), 1.0F, 1.0F);
String NAX = AuctionHouse.getInstance().getLocale().getMessage("auction.biditemwithdisabledbuynow").getMessage();
String msg = AuctionHouse.getInstance().getLocale().getMessage(isBiddingItem ? "auction.listed.withbid" : "auction.listed.nobid")
.processPlaceholder("amount", itemToSell.getAmount())
.processPlaceholder("item", AuctionAPI.getInstance().getItemName(itemToSell))
.processPlaceholder("base_price", auctionItem.getBasePrice() <= -1 ? NAX : AuctionAPI.getInstance().formatNumber(auctionItem.getBasePrice()))
.processPlaceholder("start_price", AuctionAPI.getInstance().formatNumber(auctionItem.getBidStartPrice()))
.processPlaceholder("increment_price", AuctionAPI.getInstance().formatNumber(auctionItem.getBidIncPrice())).getMessage();
AuctionHouse.getInstance().getLocale().newMessage(msg).sendPrefixedMessage(player);
if (Settings.BROADCAST_AUCTION_LIST.getBoolean()) {
Bukkit.getOnlinePlayers().forEach(p -> AuctionHouse.getInstance().getLocale().newMessage(msg).processPlaceholder("player", p.getName()).sendPrefixedMessage(p));
}
return ReturnType.SUCCESS;
}

View File

@ -1,6 +1,7 @@
package ca.tweetzy.auctionhouse.commands;
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.api.AuctionAPI;
import ca.tweetzy.core.commands.AbstractCommand;
import ca.tweetzy.core.configuration.editor.PluginConfigGui;
import org.bukkit.command.CommandSender;
@ -23,6 +24,8 @@ public class CommandSettings extends AbstractCommand {
@Override
protected ReturnType runCommand(CommandSender sender, String... args) {
Player player = (Player) sender;
if (AuctionAPI.tellMigrationStatus(player)) return ReturnType.FAILURE;
AuctionHouse.getInstance().getGuiManager().showGUI(player, new PluginConfigGui(AuctionHouse.getInstance(), AuctionHouse.getInstance().getLocale().getMessage("general.prefix").getMessage()));
return ReturnType.SUCCESS;
}

View File

@ -1,10 +1,9 @@
package ca.tweetzy.auctionhouse.commands;
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.auction.AuctionItem;
import ca.tweetzy.auctionhouse.api.AuctionAPI;
import ca.tweetzy.core.commands.AbstractCommand;
import ca.tweetzy.core.utils.TextUtils;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.List;
@ -16,25 +15,16 @@ import java.util.List;
*/
public class CommandStatus extends AbstractCommand {
public CommandStatus() {
public CommandStatus() {
super(CommandType.CONSOLE_OK, "status");
}
@Override
protected ReturnType runCommand(CommandSender sender, String... args) {
AuctionHouse.newChain().async(() -> {
if (AuctionAPI.tellMigrationStatus(sender)) return ReturnType.FAILURE;
Player player = (Player) sender;
int totalItems = AuctionHouse.getInstance().getAuctionItemManager().getAuctionItems().size();
int activeItems = (int) AuctionHouse.getInstance().getAuctionItemManager().getAuctionItems().values().stream().filter(item -> !item.isExpired()).count();
int expiredItems = (int) AuctionHouse.getInstance().getAuctionItemManager().getAuctionItems().values().stream().filter(AuctionItem::isExpired).count();
int totalTransactions = AuctionHouse.getInstance().getTransactionManager().getTransactions().size();
sender.sendMessage(TextUtils.formatText("&eAuction House Statistics"));
sender.sendMessage(TextUtils.formatText(String.format("&eRunning version &a%s", AuctionHouse.getInstance().getDescription().getVersion())));
sender.sendMessage(TextUtils.formatText(""));
sender.sendMessage(TextUtils.formatText(String.format("&7Total Items&f: &e%d\n&7Total Transactions&f: &e%d\n&7Active Items&f: &e%d\n&7Expired Items&f: &e%d", totalItems, totalTransactions, activeItems, expiredItems)));
}).execute();
return ReturnType.SUCCESS;
}

View File

@ -0,0 +1,61 @@
package ca.tweetzy.auctionhouse.commands;
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.auction.AuctionPlayer;
import ca.tweetzy.core.commands.AbstractCommand;
import ca.tweetzy.core.utils.TextUtils;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.List;
/**
* The current file has been created by Kiran Hart
* Date Created: August 11 2021
* Time Created: 2:27 p.m.
* Usage of any code found within this class is prohibited unless given explicit permission otherwise
*/
public class CommandToggleListInfo extends AbstractCommand {
public CommandToggleListInfo() {
super(CommandType.PLAYER_ONLY, "togglelistinfo");
}
@Override
protected ReturnType runCommand(CommandSender sender, String... args) {
Player player = (Player) sender;
if (AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(player.getUniqueId()) == null) {
AuctionHouse.getInstance().getLocale().newMessage(TextUtils.formatText("&cCould not find auction player instance for&f: &e" + player.getName() + "&c creating one now.")).sendPrefixedMessage(Bukkit.getConsoleSender());
AuctionHouse.getInstance().getAuctionPlayerManager().addPlayer(new AuctionPlayer(player));
}
AuctionPlayer auctionPlayer = AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(player.getUniqueId());
auctionPlayer.setShowListingInfo(!auctionPlayer.isShowListingInfo());
AuctionHouse.getInstance().getLocale().getMessage("general.toggled listing." + (auctionPlayer.isShowListingInfo() ? "on" : "off")).sendPrefixedMessage(player);
return ReturnType.SUCCESS;
}
@Override
protected List<String> onTab(CommandSender sender, String... args) {
return null;
}
@Override
public String getPermissionNode() {
return "auctionhouse.cmds.togglelistinfo";
}
@Override
public String getSyntax() {
return AuctionHouse.getInstance().getLocale().getMessage("commands.syntax.togglelistinfo").getMessage();
}
@Override
public String getDescription() {
return AuctionHouse.getInstance().getLocale().getMessage("commands.description.togglelistinfo").getMessage();
}
}

View File

@ -1,6 +1,7 @@
package ca.tweetzy.auctionhouse.commands;
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.api.AuctionAPI;
import ca.tweetzy.auctionhouse.guis.transaction.GUITransactionList;
import ca.tweetzy.core.commands.AbstractCommand;
import ca.tweetzy.core.utils.TimeUtils;
@ -24,6 +25,7 @@ public class CommandTransactions extends AbstractCommand {
@Override
protected ReturnType runCommand(CommandSender sender, String... args) {
Player player = (Player) sender;
if (AuctionAPI.tellMigrationStatus(player)) return ReturnType.FAILURE;
if (AuctionHouse.getInstance().getAuctionBanManager().checkAndHandleBan(player)) {
return ReturnType.FAILURE;

View File

@ -1,6 +1,7 @@
package ca.tweetzy.auctionhouse.commands;
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.api.AuctionAPI;
import ca.tweetzy.core.commands.AbstractCommand;
import ca.tweetzy.core.utils.PlayerUtils;
import org.bukkit.command.CommandSender;
@ -23,6 +24,8 @@ public class CommandUnban extends AbstractCommand {
@Override
protected ReturnType runCommand(CommandSender sender, String... args) {
if (args.length != 1) return ReturnType.SYNTAX_ERROR;
if (AuctionAPI.tellMigrationStatus(sender)) return ReturnType.FAILURE;
Player target = PlayerUtils.findPlayer(args[0]);
if (target == null) {

View File

@ -1,75 +0,0 @@
package ca.tweetzy.auctionhouse.commands;
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.api.AuctionAPI;
import ca.tweetzy.auctionhouse.auction.AuctionItem;
import ca.tweetzy.auctionhouse.settings.Settings;
import ca.tweetzy.auctionhouse.transaction.Transaction;
import ca.tweetzy.core.commands.AbstractCommand;
import ca.tweetzy.core.utils.TextUtils;
import org.bukkit.command.CommandSender;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* The current file has been created by Kiran Hart
* Date Created: April 15 2021
* Time Created: 4:17 p.m.
* Usage of any code found within this class is prohibited unless given explicit permission otherwise
*/
public class CommandUpload extends AbstractCommand {
public CommandUpload() {
super(CommandType.CONSOLE_OK, "upload");
}
@Override
protected ReturnType runCommand(CommandSender sender, String... args) {
if (!Settings.DATABASE_USE.getBoolean()) {
AuctionHouse.getInstance().getLocale().newMessage(TextUtils.formatText("&cYou must be using a database to use this command")).sendPrefixedMessage(sender);
return ReturnType.FAILURE;
}
if (AuctionHouse.getInstance().getData().contains("auction items") && AuctionHouse.getInstance().getData().isList("auction items")) {
List<AuctionItem> items = AuctionHouse.getInstance().getData().getStringList("auction items").stream().map(AuctionAPI.getInstance()::convertBase64ToObject).map(object -> (AuctionItem) object).collect(Collectors.toList());
items.forEach(AuctionHouse.getInstance().getAuctionItemManager()::addItem);
}
if (AuctionHouse.getInstance().getData().contains("transactions") && AuctionHouse.getInstance().getData().isList("transactions")) {
List<Transaction> transactions = AuctionHouse.getInstance().getData().getStringList("transactions").stream().map(AuctionAPI.getInstance()::convertBase64ToObject).map(object -> (Transaction) object).collect(Collectors.toList());
transactions.forEach(AuctionHouse.getInstance().getTransactionManager()::addTransaction);
}
AuctionHouse.getInstance().getData().set("auction items", null);
AuctionHouse.getInstance().getData().set("transactions", null);
AuctionHouse.getInstance().getData().save();
AuctionHouse.getInstance().getDataManager().saveItems(new ArrayList<>(AuctionHouse.getInstance().getAuctionItemManager().getAuctionItems().values()), true);
AuctionHouse.getInstance().getDataManager().saveTransactions(new ArrayList<>(AuctionHouse.getInstance().getTransactionManager().getTransactions().values()), true);
AuctionHouse.getInstance().getLocale().newMessage(TextUtils.formatText("&aLoaded file items/transactions and saved them to the database.")).sendPrefixedMessage(sender);
return ReturnType.SUCCESS;
}
@Override
public String getPermissionNode() {
return "auctionhouse.cmd.upload";
}
@Override
public String getSyntax() {
return AuctionHouse.getInstance().getLocale().getMessage("commands.syntax.upload").getMessage();
}
@Override
public String getDescription() {
return AuctionHouse.getInstance().getLocale().getMessage("commands.description.upload").getMessage();
}
@Override
protected List<String> onTab(CommandSender sender, String... args) {
return null;
}
}

View File

@ -0,0 +1,14 @@
package ca.tweetzy.auctionhouse.database;
import org.jetbrains.annotations.Nullable;
/**
* The current file has been created by Kiran Hart
* Date Created: August 01 2021
* Time Created: 1:50 a.m.
* Usage of any code found within this class is prohibited unless given explicit permission otherwise
*/
public interface Callback<T> {
void accept(@Nullable Exception ex, T result);
}

View File

@ -1,22 +1,32 @@
package ca.tweetzy.auctionhouse.database;
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.api.AuctionAPI;
import ca.tweetzy.auctionhouse.auction.AuctionBan;
import ca.tweetzy.auctionhouse.auction.AuctionFilterItem;
import ca.tweetzy.auctionhouse.auction.AuctionItem;
import ca.tweetzy.auctionhouse.auction.*;
import ca.tweetzy.auctionhouse.settings.Settings;
import ca.tweetzy.auctionhouse.transaction.Transaction;
import ca.tweetzy.core.database.DataManagerAbstract;
import ca.tweetzy.core.database.DatabaseConnector;
import ca.tweetzy.core.database.MySQLConnector;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import java.util.stream.Collectors;
/**
* The current file has been created by Kiran Hart
@ -26,54 +36,36 @@ import java.util.function.Consumer;
*/
public class DataManager extends DataManagerAbstract {
private final ExecutorService thread = Executors.newSingleThreadExecutor();
public DataManager(DatabaseConnector databaseConnector, Plugin plugin) {
super(databaseConnector, plugin);
}
public void saveItems(List<AuctionItem> items, boolean async) {
if (async) {
this.async(() -> this.databaseConnector.connect(connection -> {
String saveItems = "INSERT IGNORE INTO " + this.getTablePrefix() + "items SET data = ?";
String truncate = "TRUNCATE TABLE " + this.getTablePrefix() + "items";
try (PreparedStatement statement = connection.prepareStatement(truncate)) {
statement.execute();
}
public void close() {
if (!this.thread.isShutdown()) {
this.thread.shutdown();
PreparedStatement statement = connection.prepareStatement(saveItems);
items.forEach(item -> {
try {
statement.setString(1, AuctionAPI.getInstance().convertToBase64(item));
statement.addBatch();
} catch (SQLException e) {
e.printStackTrace();
}
});
statement.executeBatch();
}));
} else {
this.databaseConnector.connect(connection -> {
String saveItems = "INSERT IGNORE INTO " + this.getTablePrefix() + "items SET data = ?";
String truncate = "TRUNCATE TABLE " + this.getTablePrefix() + "items";
connection.prepareStatement(truncate).executeUpdate();
PreparedStatement statement = connection.prepareStatement(saveItems);
items.forEach(item -> {
try {
statement.setString(1, AuctionAPI.getInstance().convertToBase64(item));
statement.addBatch();
} catch (SQLException e) {
e.printStackTrace();
}
});
statement.executeBatch();
});
try {
if (!this.thread.awaitTermination(60, TimeUnit.SECONDS)) {
// Try stopping the thread forcefully (there is basically no hope left for the data)
this.thread.shutdownNow();
}
} catch (InterruptedException ex) {
AuctionAPI.getInstance().logException(super.plugin, ex);
}
this.databaseConnector.closeConnection();
}
}
public void saveBans(List<AuctionBan> bans, boolean async) {
public void saveBans(List<AuctionBan> bans, boolean async) {;
String saveItems = "INSERT INTO " + this.getTablePrefix() + "bans(user, reason, time) VALUES(?, ?, ?)";
String truncate = AuctionHouse.getInstance().getDatabaseConnector() instanceof MySQLConnector ? "TRUNCATE TABLE " + this.getTablePrefix() + "bans" : "DELETE FROM " + this.getTablePrefix() + "bans";
if (async) {
this.async(() -> this.databaseConnector.connect(connection -> {
String saveItems = "INSERT IGNORE INTO " + this.getTablePrefix() + "bans SET user = ?, reason = ?, time = ?";
String truncate = "TRUNCATE TABLE " + this.getTablePrefix() + "bans";
try (PreparedStatement statement = connection.prepareStatement(truncate)) {
statement.execute();
}
@ -93,8 +85,6 @@ public class DataManager extends DataManagerAbstract {
}));
} else {
this.databaseConnector.connect(connection -> {
String saveItems = "INSERT IGNORE INTO " + this.getTablePrefix() + "bans SET user = ?, reason = ?, time = ?";
String truncate = "TRUNCATE TABLE " + this.getTablePrefix() + "bans";
try (PreparedStatement statement = connection.prepareStatement(truncate)) {
statement.execute();
}
@ -116,10 +106,11 @@ public class DataManager extends DataManagerAbstract {
}
public void saveFilterWhitelist(List<AuctionFilterItem> filterItems, boolean async) {
String saveItems = "INSERT INTO " + this.getTablePrefix() + "filter_whitelist(data) VALUES(?)";
String truncate = AuctionHouse.getInstance().getDatabaseConnector() instanceof MySQLConnector ? "TRUNCATE TABLE " + this.getTablePrefix() + "filter_whitelist" : "DELETE FROM " + this.getTablePrefix() + "filter_whitelist" ;
if (async) {
this.async(() -> this.databaseConnector.connect(connection -> {
String saveItems = "INSERT IGNORE INTO " + this.getTablePrefix() + "filter_whitelist SET data = ?";
String truncate = "TRUNCATE TABLE " + this.getTablePrefix() + "filter_whitelist";
try (PreparedStatement statement = connection.prepareStatement(truncate)) {
statement.execute();
}
@ -137,8 +128,6 @@ public class DataManager extends DataManagerAbstract {
}));
} else {
this.databaseConnector.connect(connection -> {
String saveItems = "INSERT IGNORE INTO " + this.getTablePrefix() + "filter_whitelist SET data = ?";
String truncate = "TRUNCATE TABLE " + this.getTablePrefix() + "filter_whitelist";
try (PreparedStatement statement = connection.prepareStatement(truncate)) {
statement.execute();
}
@ -157,48 +146,6 @@ public class DataManager extends DataManagerAbstract {
}
}
public void saveTransactions(List<Transaction> transactions, boolean async) {
if (async) {
this.async(() -> this.databaseConnector.connect(connection -> {
String saveItems = "INSERT IGNORE INTO " + this.getTablePrefix() + "transactions SET data = ?";
String truncate = "TRUNCATE TABLE " + this.getTablePrefix() + "transactions";
try (PreparedStatement statement = connection.prepareStatement(truncate)) {
statement.execute();
}
PreparedStatement statement = connection.prepareStatement(saveItems);
transactions.forEach(transaction -> {
try {
statement.setString(1, AuctionAPI.getInstance().convertToBase64(transaction));
statement.addBatch();
} catch (SQLException e) {
e.printStackTrace();
}
});
statement.executeBatch();
}));
} else {
this.databaseConnector.connect(connection -> {
String saveItems = "INSERT IGNORE INTO " + this.getTablePrefix() + "transactions SET data = ?";
String truncate = "TRUNCATE TABLE " + this.getTablePrefix() + "transactions";
try (PreparedStatement statement = connection.prepareStatement(truncate)) {
statement.execute();
}
PreparedStatement statement = connection.prepareStatement(saveItems);
transactions.forEach(transaction -> {
try {
statement.setString(1, AuctionAPI.getInstance().convertToBase64(transaction));
statement.addBatch();
} catch (SQLException e) {
e.printStackTrace();
}
});
statement.executeBatch();
});
}
}
public void getBans(Consumer<ArrayList<AuctionBan>> callback) {
ArrayList<AuctionBan> bans = new ArrayList<>();
this.async(() -> this.databaseConnector.connect(connection -> {
@ -218,21 +165,6 @@ public class DataManager extends DataManagerAbstract {
}));
}
public void getTransactions(Consumer<ArrayList<Transaction>> callback) {
ArrayList<Transaction> transactions = new ArrayList<>();
this.async(() -> this.databaseConnector.connect(connection -> {
String select = "SELECT * FROM " + this.getTablePrefix() + "transactions";
try (Statement statement = connection.createStatement()) {
ResultSet result = statement.executeQuery(select);
while (result.next()) {
transactions.add((Transaction) AuctionAPI.getInstance().convertBase64ToObject(result.getString("data")));
}
}
this.sync(() -> callback.accept(transactions));
}));
}
public void getFilterWhitelist(Consumer<ArrayList<AuctionFilterItem>> callback) {
ArrayList<AuctionFilterItem> filterItems = new ArrayList<>();
this.async(() -> this.databaseConnector.connect(connection -> {
@ -248,18 +180,286 @@ public class DataManager extends DataManagerAbstract {
}));
}
public void getItems(Consumer<ArrayList<AuctionItem>> callback) {
ArrayList<AuctionItem> items = new ArrayList<>();
this.async(() -> this.databaseConnector.connect(connection -> {
String select = "SELECT * FROM " + this.getTablePrefix() + "items";
public void getItems(Callback<ArrayList<AuctionedItem>> callback) {
ArrayList<AuctionedItem> items = new ArrayList<>();
this.databaseConnector.connect(connection -> {
try (PreparedStatement statement = connection.prepareStatement("SELECT * FROM " + this.getTablePrefix() + "auctions")) {
ResultSet resultSet = statement.executeQuery();
while (resultSet.next()) {
items.add(extractAuctionedItem(resultSet));
}
try (Statement statement = connection.createStatement()) {
ResultSet result = statement.executeQuery(select);
while (result.next()) {
items.add((AuctionItem) AuctionAPI.getInstance().convertBase64ToObject(result.getString("data")));
callback.accept(null, items);
} catch (Exception e) {
resolveCallback(callback, e);
}
});
}
public void getTransactions(Callback<ArrayList<Transaction>> callback) {
ArrayList<Transaction> transactions = new ArrayList<>();
this.databaseConnector.connect(connection -> {
try (PreparedStatement statement = connection.prepareStatement("SELECT * FROM " + this.getTablePrefix() + "transactions")) {
ResultSet resultSet = statement.executeQuery();
while (resultSet.next()) {
transactions.add(extractTransaction(resultSet));
}
callback.accept(null, transactions);
} catch (Exception e) {
resolveCallback(callback, e);
}
});
}
public void insertTransaction(Transaction transaction, Callback<Transaction> callback) {
this.databaseConnector.connect(connection -> {
try (PreparedStatement statement = connection.prepareStatement("INSERT INTO " + getTablePrefix() + "transactions (id, seller, seller_name, buyer, buyer_name, transaction_time, item, auction_sale_type, final_price) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)")) {
PreparedStatement fetch = connection.prepareStatement("SELECT * FROM " + this.getTablePrefix() + "transactions WHERE id = ?");
fetch.setString(1, transaction.getId().toString());
statement.setString(1, transaction.getId().toString());
statement.setString(2, transaction.getSeller().toString());
statement.setString(3, transaction.getSellerName());
statement.setString(4, transaction.getBuyer().toString());
statement.setString(5, transaction.getBuyerName());
statement.setLong(6, transaction.getTransactionTime());
statement.setString(7, AuctionAPI.encodeItem(transaction.getItem()));
statement.setString(8, transaction.getAuctionSaleType().name());
statement.setDouble(9, transaction.getFinalPrice());
statement.executeUpdate();
if (callback != null) {
ResultSet res = fetch.executeQuery();
res.next();
callback.accept(null, extractTransaction(res));
}
} catch (Exception e) {
e.printStackTrace();
resolveCallback(callback, e);
}
});
}
public void insertTransactionAsync(Transaction transaction, Callback<Transaction> callback) {
this.thread.execute(() -> insertTransaction(transaction, callback));
}
public void insertAuction(AuctionedItem item, Callback<AuctionedItem> callback) {
this.databaseConnector.connect(connection -> {
try (PreparedStatement statement = connection.prepareStatement("INSERT INTO " + this.getTablePrefix() + "auctions(id, owner, highest_bidder, owner_name, highest_bidder_name, category, base_price, bid_start_price, bid_increment_price, current_price, expired, expires_at, item_material, item_name, item_lore, item_enchants, item) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")) {
PreparedStatement fetch = connection.prepareStatement("SELECT * FROM " + this.getTablePrefix() + "auctions WHERE id = ?");
fetch.setString(1, item.getId().toString());
statement.setString(1, item.getId().toString());
statement.setString(2, item.getOwner().toString());
statement.setString(3, item.getHighestBidder().toString());
statement.setString(4, item.getOwnerName());
statement.setString(5, item.getHighestBidderName());
statement.setString(6, item.getCategory().name());
statement.setDouble(7, item.getBasePrice());
statement.setDouble(8, item.getBidStartingPrice());
statement.setDouble(9, item.getBidIncrementPrice());
statement.setDouble(10, item.getCurrentPrice());
statement.setBoolean(11, item.isExpired());
statement.setLong(12, item.getExpiresAt());
statement.setString(13, item.getItem().getType().name());
statement.setString(14, AuctionAPI.getInstance().getItemName(item.getItem()));
statement.setString(15, AuctionAPI.getInstance().serializeLines(AuctionAPI.getInstance().getItemLore(item.getItem())));
statement.setString(16, AuctionAPI.getInstance().serializeLines(AuctionAPI.getInstance().getItemEnchantments(item.getItem())));
statement.setString(17, AuctionAPI.encodeItem(item.getItem()));
statement.executeUpdate();
if (callback != null) {
ResultSet res = fetch.executeQuery();
res.next();
callback.accept(null, extractAuctionedItem(res));
}
} catch (Exception e) {
e.printStackTrace();
resolveCallback(callback, e);
}
});
}
public void insertAuctionAsync(AuctionedItem item, Callback<AuctionedItem> callback) {
this.thread.execute(() -> insertAuction(item, callback));
}
public void updateItems(Collection<AuctionedItem> items, UpdateCallback callback) {
this.databaseConnector.connect(connection -> {
connection.setAutoCommit(false);
SQLException err = null;
PreparedStatement statement = connection.prepareStatement("UPDATE " + this.getTablePrefix() + "auctions SET highest_bidder = ?, highest_bidder_name = ?, base_price = ?, bid_start_price = ?, bid_increment_price = ?, current_price = ?, expires_at = ?, expired = ? WHERE id = ?");
for (AuctionedItem item : items) {
try {
statement.setString(1, item.getHighestBidder().toString());
statement.setString(2, item.getHighestBidderName());
statement.setDouble(3, item.getBasePrice());
statement.setDouble(4, item.getBidStartingPrice());
statement.setDouble(5, item.getBidIncrementPrice());
statement.setDouble(6, item.getCurrentPrice());
statement.setLong(7, item.getExpiresAt());
statement.setBoolean(8, item.isExpired());
statement.setString(9, item.getId().toString());
statement.addBatch();
} catch (SQLException e) {
err = e;
break;
}
}
this.sync(() -> callback.accept(items));
statement.executeBatch();
if (err == null) {
connection.commit();
resolveUpdateCallback(callback, null);
} else {
connection.rollback();
resolveUpdateCallback(callback, err);
}
connection.setAutoCommit(true);
});
}
public void deleteItems(Collection<UUID> items) {
this.async(() -> this.databaseConnector.connect(connection -> {
PreparedStatement statement = connection.prepareStatement("DELETE FROM " + this.getTablePrefix() + "auctions WHERE id = ?");
for (UUID id : items) {
statement.setString(1, id.toString());
statement.addBatch();
}
statement.executeBatch();
}));
}
public void migrateFromSerializationFormat(Consumer<List<AuctionedItem>> callback) {
AuctionHouse.getInstance().setMigrating(true);
ArrayList<AuctionItem> items = new ArrayList<>();
this.async(() -> this.databaseConnector.connect(connection -> {
if (Settings.DATABASE_USE.getBoolean()) {
String select = "SELECT * FROM " + this.getTablePrefix() + "items";
try (Statement statement = connection.createStatement()) {
ResultSet result = statement.executeQuery(select);
while (result.next()) {
items.add((AuctionItem) AuctionAPI.getInstance().convertBase64ToObject(result.getString("data")));
}
}
} else {
if (AuctionHouse.getInstance().getData().contains("auction items") && AuctionHouse.getInstance().getData().isList("auction items")) {
items.addAll(AuctionHouse.getInstance().getData().getStringList("auction items").stream().map(AuctionAPI.getInstance()::convertBase64ToObject).map(object -> (AuctionItem) object).collect(Collectors.toList()));
AuctionHouse.getInstance().getData().set("auction items", null);
AuctionHouse.getInstance().getData().save();
}
}
List<AuctionedItem> newItems = new ArrayList<>();
items.forEach(item -> {
OfflinePlayer owner = Bukkit.getOfflinePlayer(item.getOwner());
OfflinePlayer highestBidder = Bukkit.getOfflinePlayer(item.getHighestBidder());
newItems.add(new AuctionedItem(
item.getKey(),
item.getOwner(),
item.getHighestBidder(),
owner.getName() != null ? owner.getName() : "Unknown",
highestBidder.getName() != null ? highestBidder.getName() : "Unknown",
item.getCategory(),
AuctionAPI.getInstance().deserializeItem(item.getRawItem()),
item.getBasePrice(),
item.getBidStartPrice(),
item.getBidIncPrice(),
item.getCurrentPrice(),
item.getBidStartPrice() >= 1 || item.getBidIncPrice() >= 1,
item.isExpired(),
System.currentTimeMillis() + 1000L * item.getRemainingTime()
));
});
String saveItems = "INSERT INTO " + this.getTablePrefix() + "auctions(id, owner, highest_bidder, owner_name, highest_bidder_name, category, base_price, bid_start_price, bid_increment_price, current_price, expired, expires_at, item_material, item_name, item_lore, item_enchants, item) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
PreparedStatement statement = connection.prepareStatement(saveItems);
newItems.forEach(item -> {
try {
statement.setString(1, item.getId().toString());
statement.setString(2, item.getOwner().toString());
statement.setString(3, item.getHighestBidder().toString());
statement.setString(4, item.getOwnerName());
statement.setString(5, item.getHighestBidderName());
statement.setString(6, item.getCategory().name());
statement.setDouble(7, item.getBasePrice());
statement.setDouble(8, item.getBidStartingPrice());
statement.setDouble(9, item.getBidIncrementPrice());
statement.setDouble(10, item.getCurrentPrice());
statement.setBoolean(11, item.isExpired());
statement.setLong(12, item.getExpiresAt());
statement.setString(13, item.getItem().getType().name());
statement.setString(14, AuctionAPI.getInstance().getItemName(item.getItem()));
statement.setString(15, AuctionAPI.getInstance().serializeLines(AuctionAPI.getInstance().getItemLore(item.getItem())));
statement.setString(16, AuctionAPI.getInstance().serializeLines(AuctionAPI.getInstance().getItemEnchantments(item.getItem())));
statement.setString(17, AuctionAPI.encodeItem(item.getItem()));
statement.addBatch();
} catch (SQLException e) {
e.printStackTrace();
}
});
statement.executeBatch();
this.sync(() -> {
AuctionHouse.getInstance().setMigrating(false);
newItems.forEach(item -> AuctionHouse.getInstance().getAuctionItemManager().addAuctionItem(item));
callback.accept(newItems);
});
}));
}
private AuctionedItem extractAuctionedItem(ResultSet resultSet) throws SQLException {
return new AuctionedItem(
UUID.fromString(resultSet.getString("id")),
UUID.fromString(resultSet.getString("owner")),
UUID.fromString(resultSet.getString("highest_bidder")),
resultSet.getString("owner_name"),
resultSet.getString("highest_bidder_name"),
AuctionItemCategory.valueOf(resultSet.getString("category")),
AuctionAPI.decodeItem(resultSet.getString("item")),
resultSet.getDouble("base_price"),
resultSet.getDouble("bid_start_price"),
resultSet.getDouble("bid_increment_price"),
resultSet.getDouble("current_price"),
resultSet.getDouble("bid_start_price") >= 1 || resultSet.getDouble("bid_increment_price") >= 1,
resultSet.getBoolean("expired"),
resultSet.getLong("expires_at")
);
}
private Transaction extractTransaction(ResultSet resultSet) throws SQLException {
return new Transaction(
UUID.fromString(resultSet.getString("id")),
UUID.fromString(resultSet.getString("seller")),
UUID.fromString(resultSet.getString("buyer")),
resultSet.getString("seller_name"),
resultSet.getString("buyer_name"),
resultSet.getLong("transaction_time"),
AuctionAPI.decodeItem(resultSet.getString("item")),
AuctionSaleType.valueOf(resultSet.getString("auction_sale_type")),
resultSet.getDouble("final_price")
);
}
private void resolveUpdateCallback(@Nullable UpdateCallback callback, @Nullable Exception ex) {
if (callback != null) {
callback.accept(ex);
} else if (ex != null) {
AuctionAPI.getInstance().logException(this.plugin, ex, "SQLite");
}
}
private void resolveCallback(@Nullable Callback<?> callback, @NotNull Exception ex) {
if (callback != null) {
callback.accept(ex, null);
} else {
AuctionAPI.getInstance().logException(this.plugin, ex, "SQLite");
}
}
}

View File

@ -0,0 +1,15 @@
package ca.tweetzy.auctionhouse.database;
import org.jetbrains.annotations.Nullable;
/**
* The current file has been created by Kiran Hart
* Date Created: August 01 2021
* Time Created: 1:50 a.m.
* Usage of any code found within this class is prohibited unless given explicit permission otherwise
*/
public interface UpdateCallback {
void accept(@Nullable Exception ex);
}

View File

@ -0,0 +1,48 @@
package ca.tweetzy.auctionhouse.database.migrations;
import ca.tweetzy.core.database.DataMigration;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
/**
* The current file has been created by Kiran Hart
* Date Created: July 29 2021
* Time Created: 2:31 p.m.
* Usage of any code found within this class is prohibited unless given explicit permission otherwise
*/
public class _4_ItemsChangeMigration extends DataMigration {
public _4_ItemsChangeMigration() {
super(4);
}
@Override
public void migrate(Connection connection, String tablePrefix) throws SQLException {
try (Statement statement = connection.createStatement()) {
statement.execute("CREATE TABLE " + tablePrefix + "auctions (" +
"id VARCHAR(36) PRIMARY KEY, " +
"owner VARCHAR(36) NOT NULL, " +
"owner_name VARCHAR(16) NOT NULL, " +
"highest_bidder VARCHAR(36) NOT NULL," +
"highest_bidder_name VARCHAR(16) NOT NULL," +
"category VARCHAR(48) NOT NULL, " +
"base_price DOUBLE NOT NULL, " +
"bid_start_price DOUBLE NOT NULL, " +
"bid_increment_price DOUBLE NOT NULL, " +
"current_price DOUBLE NOT NULL, " +
"expired BOOLEAN NOT NULL, " +
"expires_at BigInt(20) NOT NULL, " +
"item_material VARCHAR(48) NOT NULL, " +
"item_name TEXT NOT NULL, " +
"item_lore TEXT NULL, " +
"item_enchants TEXT NULL, " +
"item TEXT NOT NULL " +
" )");
// statement.execute("CREATE INDEX item_index ON " + tablePrefix + "auctions (id, owner)");
}
}
}

View File

@ -0,0 +1,38 @@
package ca.tweetzy.auctionhouse.database.migrations;
import ca.tweetzy.core.database.DataMigration;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
/**
* The current file has been created by Kiran Hart
* Date Created: August 08 2021
* Time Created: 1:06 a.m.
* Usage of any code found within this class is prohibited unless given explicit permission otherwise
*/
public class _5_TransactionChangeMigration extends DataMigration {
public _5_TransactionChangeMigration() {
super(5);
}
@Override
public void migrate(Connection connection, String tablePrefix) throws SQLException {
try (Statement statement = connection.createStatement()) {
statement.execute("DROP TABLE " + tablePrefix + "transactions");
statement.execute("CREATE TABLE " + tablePrefix + "transactions (" +
"id VARCHAR(36) PRIMARY KEY, " +
"seller VARCHAR(36) NOT NULL, " +
"seller_name VARCHAR(16) NOT NULL, " +
"buyer VARCHAR(36) NOT NULL," +
"buyer_name VARCHAR(16) NOT NULL," +
"transaction_time TinyInt NOT NULL, " +
"item TEXT NOT NULL, " +
"auction_sale_type VARCHAR(32) NOT NULL, " +
"final_price DOUBLE NOT NULL " +
" )");
}
}
}

View File

@ -0,0 +1,55 @@
package ca.tweetzy.auctionhouse.database.migrations;
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.core.database.DataMigration;
import ca.tweetzy.core.database.MySQLConnector;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
/**
* The current file has been created by Kiran Hart
* Date Created: August 12 2021
* Time Created: 11:58 a.m.
* Usage of any code found within this class is prohibited unless given explicit permission otherwise
*/
public class _6_BigIntMigration extends DataMigration {
public _6_BigIntMigration() {
super(6);
}
@Override
public void migrate(Connection connection, String tablePrefix) throws SQLException {
try (Statement statement = connection.createStatement()) {
if (AuctionHouse.getInstance().getDatabaseConnector() instanceof MySQLConnector) {
statement.execute("ALTER TABLE " + tablePrefix + "auctions MODIFY COLUMN expires_at BigInt(20)");
} else {
statement.execute("DROP TABLE " + tablePrefix + "auctions");
statement.execute("CREATE TABLE " + tablePrefix + "auctions (" +
"id VARCHAR(36) PRIMARY KEY, " +
"owner VARCHAR(36) NOT NULL, " +
"owner_name VARCHAR(16) NOT NULL, " +
"highest_bidder VARCHAR(36) NOT NULL," +
"highest_bidder_name VARCHAR(16) NOT NULL," +
"category VARCHAR(48) NOT NULL, " +
"base_price DOUBLE NOT NULL, " +
"bid_start_price DOUBLE NOT NULL, " +
"bid_increment_price DOUBLE NOT NULL, " +
"current_price DOUBLE NOT NULL, " +
"expired BOOLEAN NOT NULL, " +
"expires_at BigInt(20) NOT NULL, " +
"item_material VARCHAR(48) NOT NULL, " +
"item_name TEXT NOT NULL, " +
"item_lore TEXT NULL, " +
"item_enchants TEXT NULL, " +
"item TEXT NOT NULL " +
" )");
}
}
}
}

View File

@ -1,9 +1,9 @@
package ca.tweetzy.auctionhouse.guis;
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.auction.AuctionItem;
import ca.tweetzy.auctionhouse.auction.AuctionPlayer;
import ca.tweetzy.auctionhouse.auction.AuctionStackType;
import ca.tweetzy.auctionhouse.auction.AuctionedItem;
import ca.tweetzy.auctionhouse.guis.confirmation.GUIConfirmCancel;
import ca.tweetzy.auctionhouse.helpers.ConfigurationItemHelper;
import ca.tweetzy.auctionhouse.managers.SoundManager;
@ -30,7 +30,7 @@ public class GUIActiveAuctions extends Gui {
private final AuctionPlayer auctionPlayer;
private BukkitTask task;
private List<AuctionItem> items;
private List<AuctionedItem> items;
public GUIActiveAuctions(AuctionPlayer auctionPlayer) {
this.auctionPlayer = auctionPlayer;
@ -54,20 +54,20 @@ public class GUIActiveAuctions extends Gui {
private void drawItems() {
AuctionHouse.newChain().asyncFirst(() -> {
this.items = this.auctionPlayer.getItems(false);
return this.items.stream().sorted(Comparator.comparingInt(AuctionItem::getRemainingTime).reversed()).skip((page - 1) * 45L).limit(45).collect(Collectors.toList());
return this.items.stream().sorted(Comparator.comparingLong(AuctionedItem::getExpiresAt).reversed()).skip((page - 1) * 45L).limit(45).collect(Collectors.toList());
}).asyncLast((data) -> {
pages = (int) Math.max(1, Math.ceil(this.items.size() / (double) 45L));
drawPaginationButtons();
int slot = 0;
for (AuctionItem item : data) {
for (AuctionedItem item : data) {
setButton(slot++, item.getDisplayStack(AuctionStackType.ACTIVE_AUCTIONS_LIST), e -> {
switch (e.clickType) {
case LEFT:
if (((item.getBidStartPrice() > 0 || item.getBidIncPrice() > 0) && Settings.ASK_FOR_CANCEL_CONFIRM_ON_BID_ITEMS.getBoolean()) || Settings.ASK_FOR_CANCEL_CONFIRM_ON_NON_BID_ITEMS.getBoolean()) {
if (((item.getBidStartingPrice() > 0 || item.getBidIncrementPrice() > 0) && Settings.ASK_FOR_CANCEL_CONFIRM_ON_BID_ITEMS.getBoolean()) || Settings.ASK_FOR_CANCEL_CONFIRM_ON_NON_BID_ITEMS.getBoolean()) {
if (item.getHighestBidder().equals(e.player.getUniqueId())) {
item.setExpired(true);
item.setRemainingTime(0);
item.setExpiresAt(System.currentTimeMillis());
draw();
return;
}
@ -80,8 +80,9 @@ public class GUIActiveAuctions extends Gui {
draw();
break;
case RIGHT:
if (Settings.ALLOW_PLAYERS_TO_ACCEPT_BID.getBoolean() && item.getBidStartPrice() != 0 && !item.getHighestBidder().equals(e.player.getUniqueId())) {
item.setRemainingTime(0);
if (Settings.ALLOW_PLAYERS_TO_ACCEPT_BID.getBoolean() && item.getBidStartingPrice() != 0 && !item.getHighestBidder().equals(e.player.getUniqueId())) {
item.setExpired(true);
item.setExpiresAt(System.currentTimeMillis());
draw();
}
break;
@ -122,6 +123,6 @@ public class GUIActiveAuctions extends Gui {
}
private void cleanup() {
task.cancel();
if (task != null) task.cancel();
}
}

View File

@ -4,6 +4,7 @@ import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.api.AuctionAPI;
import ca.tweetzy.auctionhouse.auction.AuctionItem;
import ca.tweetzy.auctionhouse.auction.AuctionPlayer;
import ca.tweetzy.auctionhouse.auction.AuctionedItem;
import ca.tweetzy.auctionhouse.helpers.ConfigurationItemHelper;
import ca.tweetzy.auctionhouse.settings.Settings;
import ca.tweetzy.core.gui.Gui;
@ -20,9 +21,9 @@ import org.bukkit.inventory.ItemStack;
public class GUIAdminItem extends Gui {
private final AuctionPlayer auctionPlayer;
private final AuctionItem auctionItem;
private final AuctionedItem auctionItem;
public GUIAdminItem(AuctionPlayer auctionPlayer, AuctionItem auctionItem) {
public GUIAdminItem(AuctionPlayer auctionPlayer, AuctionedItem auctionItem) {
this.auctionPlayer = auctionPlayer;
this.auctionItem = auctionItem;
setTitle(TextUtils.formatText(Settings.GUI_ITEM_ADMIN_TITLE.getString()));
@ -37,14 +38,13 @@ public class GUIAdminItem extends Gui {
private void draw() {
setButton(1, 2, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_ITEM_ADMIN_ITEMS_RETURN_ITEM.getString(), Settings.GUI_ITEM_ADMIN_ITEMS_RETURN_NAME.getString(), Settings.GUI_ITEM_ADMIN_ITEMS_RETURN_LORE.getStringList(), null), e -> {
this.auctionItem.setRemainingTime(0);
this.auctionItem.setExpiresAt(System.currentTimeMillis());
this.auctionItem.setExpired(true);
e.gui.close();
});
setButton(1, 4, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_ITEM_ADMIN_ITEMS_CLAIM_ITEM.getString(), Settings.GUI_ITEM_ADMIN_ITEMS_CLAIM_NAME.getString(), Settings.GUI_ITEM_ADMIN_ITEMS_CLAIM_LORE.getStringList(), null), e -> {
ItemStack item = AuctionAPI.getInstance().deserializeItem(this.auctionItem.getRawItem());
PlayerUtils.giveItem(e.player, item);
PlayerUtils.giveItem(e.player, this.auctionItem.getItem());
AuctionHouse.getInstance().getAuctionItemManager().sendToGarbage(this.auctionItem);
e.gui.close();
});

View File

@ -3,25 +3,21 @@ package ca.tweetzy.auctionhouse.guis;
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.api.AuctionAPI;
import ca.tweetzy.auctionhouse.auction.*;
import ca.tweetzy.auctionhouse.guis.confirmation.GUIConfirmBid;
import ca.tweetzy.auctionhouse.guis.confirmation.GUIConfirmPurchase;
import ca.tweetzy.auctionhouse.guis.filter.GUIFilterSelection;
import ca.tweetzy.auctionhouse.guis.transaction.GUITransactionList;
import ca.tweetzy.auctionhouse.helpers.ConfigurationItemHelper;
import ca.tweetzy.auctionhouse.managers.SoundManager;
import ca.tweetzy.auctionhouse.settings.Settings;
import ca.tweetzy.core.commands.AbstractCommand;
import ca.tweetzy.core.compatibility.ServerVersion;
import ca.tweetzy.core.compatibility.XMaterial;
import ca.tweetzy.core.gui.Gui;
import ca.tweetzy.core.gui.events.GuiClickEvent;
import ca.tweetzy.core.hooks.EconomyManager;
import ca.tweetzy.core.utils.TextUtils;
import ca.tweetzy.core.utils.TimeUtils;
import ca.tweetzy.core.utils.items.TItemBuilder;
import ca.tweetzy.core.utils.nms.NBTEditor;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.block.ShulkerBox;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
@ -41,7 +37,7 @@ import java.util.stream.Collectors;
public class GUIAuctionHouse extends Gui {
final AuctionPlayer auctionPlayer;
private List<AuctionItem> items;
private List<AuctionedItem> items;
private BukkitTask task;
private String searchPhrase = "";
@ -65,9 +61,13 @@ public class GUIAuctionHouse extends Gui {
}
});
if (Settings.AUTO_REFRESH_AUCTION_PAGES.getBoolean()) {
setOnClose(e -> cleanup());
}
setOnClose(close -> {
this.items.clear();
if (Settings.AUTO_REFRESH_AUCTION_PAGES.getBoolean()) {
cleanup();
}
});
}
public GUIAuctionHouse(AuctionPlayer auctionPlayer, String phrase) {
@ -76,18 +76,22 @@ public class GUIAuctionHouse extends Gui {
}
public void draw() {
reset();
drawFixedButtons();
drawItems();
try {
reset();
drawFixedButtons();
drawItems();
} catch (Exception e) {
AuctionHouse.getInstance().getLogger().warning("Something stupid is happening during the draw process (Main Menu)");
}
}
private void drawItems() {
AuctionHouse.newChain().asyncFirst(() -> {
this.items = new ArrayList<>();
for (Map.Entry<UUID, AuctionItem> entry : AuctionHouse.getInstance().getAuctionItemManager().getAuctionItems().entrySet()) {
AuctionItem auctionItem = entry.getValue();
if (!auctionItem.isExpired() && auctionItem.getRemainingTime() >= 1 && !AuctionHouse.getInstance().getAuctionItemManager().getGarbageBin().containsKey(auctionItem.getKey())) {
for (Map.Entry<UUID, AuctionedItem> entry : AuctionHouse.getInstance().getAuctionItemManager().getItems().entrySet()) {
AuctionedItem auctionItem = entry.getValue();
if (!auctionItem.isExpired() && !AuctionHouse.getInstance().getAuctionItemManager().getGarbageBin().containsKey(auctionItem.getId())) {
this.items.add(auctionItem);
}
}
@ -105,36 +109,37 @@ public class GUIAuctionHouse extends Gui {
}
if (this.auctionPlayer.getSelectedSaleType() == AuctionSaleType.USED_BIDDING_SYSTEM) {
this.items = this.items.stream().filter(item -> item.getBidStartPrice() >= 1 && item.getBidIncPrice() >= 1).collect(Collectors.toList());
this.items = this.items.stream().filter(AuctionedItem::isBidItem).collect(Collectors.toList());
}
if (this.auctionPlayer.getSelectedSaleType() == AuctionSaleType.WITHOUT_BIDDING_SYSTEM) {
this.items = this.items.stream().filter(item -> item.getBidStartPrice() <= 0 && item.getBidIncPrice() <= 0).collect(Collectors.toList());
this.items = this.items.stream().filter(item -> !item.isBidItem()).collect(Collectors.toList());
}
if (this.auctionPlayer.getAuctionSortType() == AuctionSortType.PRICE) {
this.items = this.items.stream().sorted(Comparator.comparingDouble(AuctionItem::getCurrentPrice).reversed()).collect(Collectors.toList());
this.items = this.items.stream().sorted(Comparator.comparingDouble(AuctionedItem::getCurrentPrice).reversed()).collect(Collectors.toList());
}
if (this.auctionPlayer.getAuctionSortType() == AuctionSortType.RECENT) {
this.items = this.items.stream().sorted(Comparator.comparingDouble(AuctionItem::getRemainingTime).reversed()).collect(Collectors.toList());
this.items = this.items.stream().sorted(Comparator.comparingLong(AuctionedItem::getExpiresAt).reversed()).collect(Collectors.toList());
}
return this.items.stream().skip((page - 1) * 45L).limit(45L).collect(Collectors.toList());
}).asyncLast((data) -> {
pages = (int) Math.max(1, Math.ceil(this.items.size() / (double) 45L));
drawVariableButtons();
drawPaginationButtons();
placeItems(data);
}).execute();
}
private boolean checkFilterCriteria(AuctionItem auctionItem, AuctionItemCategory category) {
private boolean checkFilterCriteria(AuctionedItem auctionItem, AuctionItemCategory category) {
return auctionItem.getCategory() == category ||
AuctionHouse.getInstance().getFilterManager().getFilterWhitelist(category).stream().anyMatch(item -> item.isSimilar(AuctionAPI.getInstance().deserializeItem(auctionItem.getRawItem())));
AuctionHouse.getInstance().getFilterManager().getFilterWhitelist(category).stream().anyMatch(item -> item.isSimilar(auctionItem.getItem()));
}
private boolean checkSearchCriteria(String phrase, AuctionItem item) {
ItemStack stack = AuctionAPI.getInstance().deserializeItem(item.getRawItem());
private boolean checkSearchCriteria(String phrase, AuctionedItem item) {
ItemStack stack = item.getItem();
return AuctionAPI.getInstance().match(phrase, AuctionAPI.getInstance().getItemName(stack)) ||
AuctionAPI.getInstance().match(phrase, item.getCategory().getTranslatedType()) ||
AuctionAPI.getInstance().match(phrase, stack.getType().name()) ||
@ -146,7 +151,7 @@ public class GUIAuctionHouse extends Gui {
/*
====================== CLICK HANDLES ======================
*/
private void handleNonBidItem(AuctionItem auctionItem, GuiClickEvent e, boolean buyingQuantity) {
private void handleNonBidItem(AuctionedItem auctionItem, GuiClickEvent e, boolean buyingQuantity) {
if (e.player.getUniqueId().equals(auctionItem.getOwner()) && !Settings.OWNER_CAN_PURCHASE_OWN_ITEM.getBoolean()) {
AuctionHouse.getInstance().getLocale().getMessage("general.cantbuyown").sendPrefixedMessage(e.player);
return;
@ -158,19 +163,19 @@ public class GUIAuctionHouse extends Gui {
}
if (buyingQuantity) {
if (auctionItem.getBidStartPrice() <= 0 || !Settings.ALLOW_USAGE_OF_BID_SYSTEM.getBoolean()) {
if (auctionItem.getBidStartingPrice() <= 0 || !Settings.ALLOW_USAGE_OF_BID_SYSTEM.getBoolean()) {
if (!Settings.ALLOW_PURCHASE_OF_SPECIFIC_QUANTITIES.getBoolean()) return;
}
}
cleanup();
e.manager.showGUI(e.player, new GUIConfirmPurchase(this.auctionPlayer, auctionItem, buyingQuantity));
AuctionHouse.getInstance().getTransactionManager().addPrePurchase(e.player, auctionItem.getKey());
AuctionHouse.getInstance().getTransactionManager().addPrePurchase(e.player, auctionItem.getId());
}
private void handleBidItem(AuctionItem auctionItem, GuiClickEvent e, boolean buyNow) {
private void handleBidItem(AuctionedItem auctionItem, GuiClickEvent e, boolean buyNow) {
if (buyNow) {
if (auctionItem.getBidStartPrice() >= Settings.MIN_AUCTION_START_PRICE.getDouble()) {
if (auctionItem.getBidStartingPrice() >= Settings.MIN_AUCTION_START_PRICE.getDouble()) {
if (!Settings.ALLOW_USAGE_OF_BUY_NOW_SYSTEM.getBoolean()) return;
if (auctionItem.getBasePrice() <= -1) {
AuctionHouse.getInstance().getLocale().getMessage("general.buynowdisabledonitem").sendPrefixedMessage(e.player);
@ -179,7 +184,7 @@ public class GUIAuctionHouse extends Gui {
cleanup();
e.manager.showGUI(e.player, new GUIConfirmPurchase(this.auctionPlayer, auctionItem, false));
AuctionHouse.getInstance().getTransactionManager().addPrePurchase(e.player, auctionItem.getKey());
AuctionHouse.getInstance().getTransactionManager().addPrePurchase(e.player, auctionItem.getId());
}
return;
}
@ -189,62 +194,11 @@ public class GUIAuctionHouse extends Gui {
return;
}
if (Settings.PLAYER_NEEDS_TOTAL_PRICE_TO_BID.getBoolean() && !EconomyManager.hasBalance(e.player, auctionItem.getCurrentPrice() + auctionItem.getBidIncPrice())) {
AuctionHouse.getInstance().getLocale().getMessage("general.notenoughmoney").sendPrefixedMessage(e.player);
return;
}
if (Settings.ASK_FOR_BID_CONFIRMATION.getBoolean()) {
cleanup();
e.manager.showGUI(e.player, new GUIConfirmBid(this.auctionPlayer, auctionItem));
} else {
ItemStack itemStack = AuctionAPI.getInstance().deserializeItem(auctionItem.getRawItem());
OfflinePlayer oldBidder = Bukkit.getOfflinePlayer(auctionItem.getHighestBidder());
OfflinePlayer owner = Bukkit.getOfflinePlayer(auctionItem.getOwner());
auctionItem.setHighestBidder(e.player.getUniqueId());
auctionItem.setCurrentPrice(auctionItem.getCurrentPrice() + auctionItem.getBidIncPrice());
if (auctionItem.getBasePrice() != -1 && Settings.SYNC_BASE_PRICE_TO_HIGHEST_PRICE.getBoolean() && auctionItem.getCurrentPrice() > auctionItem.getBasePrice()) {
auctionItem.setBasePrice(auctionItem.getCurrentPrice());
}
if (Settings.INCREASE_TIME_ON_BID.getBoolean()) {
auctionItem.setRemainingTime(auctionItem.getRemainingTime() + Settings.TIME_TO_INCREASE_BY_ON_BID.getInt());
}
if (oldBidder.isOnline()) {
AuctionHouse.getInstance().getLocale().getMessage("auction.outbid")
.processPlaceholder("player", e.player.getName())
.processPlaceholder("item", AuctionAPI.getInstance().getItemName(itemStack))
.sendPrefixedMessage(oldBidder.getPlayer());
}
if (owner.isOnline()) {
AuctionHouse.getInstance().getLocale().getMessage("auction.placedbid")
.processPlaceholder("player", e.player.getName())
.processPlaceholder("amount", AuctionAPI.getInstance().formatNumber(auctionItem.getCurrentPrice()))
.processPlaceholder("item", AuctionAPI.getInstance().getItemName(itemStack))
.sendPrefixedMessage(owner.getPlayer());
}
if (Settings.BROADCAST_AUCTION_BID.getBoolean()) {
Bukkit.getOnlinePlayers().forEach(player -> AuctionHouse.getInstance().getLocale().getMessage("auction.broadcast.bid")
.processPlaceholder("player", e.player.getName())
.processPlaceholder("amount", AuctionAPI.getInstance().formatNumber(auctionItem.getCurrentPrice()))
.processPlaceholder("item", AuctionAPI.getInstance().getItemName(itemStack))
.sendPrefixedMessage(player));
}
if (Settings.REFRESH_GUI_WHEN_BID.getBoolean()) {
cleanup();
e.manager.showGUI(e.player, new GUIAuctionHouse(this.auctionPlayer));
}
}
cleanup();
e.manager.showGUI(e.player, new GUIBid(this.auctionPlayer, auctionItem));
}
private void handleItemRemove(AuctionItem auctionItem, GuiClickEvent e) {
private void handleItemRemove(AuctionedItem auctionItem, GuiClickEvent e) {
if (e.player.isOp() || e.player.hasPermission("auctionhouse.admin")) {
cleanup();
e.manager.showGUI(e.player, new GUIAdminItem(this.auctionPlayer, auctionItem));
@ -271,9 +225,9 @@ public class GUIAuctionHouse extends Gui {
}
}
private void placeItems(List<AuctionItem> data) {
private void placeItems(List<AuctionedItem> data) {
int slot = 0;
for (AuctionItem auctionItem : data) {
for (AuctionedItem auctionItem : data) {
setButton(slot++, auctionItem.getDisplayStack(AuctionStackType.MAIN_AUCTION_HOUSE), e -> {
// Non Type specific actions
if (e.clickType == ClickType.valueOf(Settings.CLICKS_INSPECT_CONTAINER.getString().toUpperCase())) {
@ -287,7 +241,7 @@ public class GUIAuctionHouse extends Gui {
}
// Non Biddable Items
if (auctionItem.getBidStartPrice() <= 0) {
if (!auctionItem.isBidItem()) {
if (e.clickType == ClickType.valueOf(Settings.CLICKS_NON_BID_ITEM_PURCHASE.getString().toUpperCase())) {
handleNonBidItem(auctionItem, e, false);
return;
@ -316,10 +270,37 @@ public class GUIAuctionHouse extends Gui {
/*
====================== FIXED BUTTONS ======================
*/
private void drawVariableButtons() {
if (Settings.GUI_AUCTION_HOUSE_ITEMS_YOUR_AUCTIONS_ENABLED.getBoolean()) {
setButton(Settings.GUI_AUCTION_HOUSE_ITEMS_YOUR_AUCTIONS_SLOT.getInt(), ConfigurationItemHelper.createConfigurationItem(Settings.GUI_AUCTION_HOUSE_ITEMS_YOUR_AUCTIONS_ITEM.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_YOUR_AUCTIONS_NAME.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_YOUR_AUCTIONS_LORE.getStringList(), new HashMap<String, Object>() {{
put("%active_player_auctions%", auctionPlayer.getItems(false).size());
put("%player_balance%", AuctionAPI.getInstance().formatNumber(EconomyManager.getBalance(auctionPlayer.getPlayer())));
}}), e -> {
cleanup();
e.manager.showGUI(e.player, new GUIActiveAuctions(this.auctionPlayer));
});
}
if (Settings.GUI_AUCTION_HOUSE_ITEMS_COLLECTION_BIN_ENABLED.getBoolean()) {
setButton(Settings.GUI_AUCTION_HOUSE_ITEMS_COLLECTION_BIN_SLOT.getInt(), ConfigurationItemHelper.createConfigurationItem(Settings.GUI_AUCTION_HOUSE_ITEMS_COLLECTION_BIN_ITEM.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_COLLECTION_BIN_NAME.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_COLLECTION_BIN_LORE.getStringList(), new HashMap<String, Object>() {{
put("%expired_player_auctions%", auctionPlayer.getItems(true).size());
}}), e -> {
cleanup();
e.manager.showGUI(e.player, new GUIExpiredItems(this.auctionPlayer));
});
}
if (Settings.GUI_AUCTION_HOUSE_ITEMS_TRANSACTIONS_ENABLED.getBoolean()) {
setButton(Settings.GUI_AUCTION_HOUSE_ITEMS_TRANSACTIONS_SLOT.getInt(), ConfigurationItemHelper.createConfigurationItem(Settings.GUI_AUCTION_HOUSE_ITEMS_TRANSACTIONS_ITEM.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_TRANSACTIONS_NAME.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_TRANSACTIONS_LORE.getStringList(), new HashMap<String, Object>() {{
put("%total_items_bought%", AuctionHouse.getInstance().getTransactionManager().getTotalItemsBought(auctionPlayer.getPlayer().getUniqueId()));
put("%total_items_sold%", AuctionHouse.getInstance().getTransactionManager().getTotalItemsSold(auctionPlayer.getPlayer().getUniqueId()));
}}), e -> e.manager.showGUI(e.player, new GUITransactionList(this.auctionPlayer)));
}
}
private void drawPaginationButtons() {
setPrevPage(5, 3, new TItemBuilder(Objects.requireNonNull(Settings.GUI_BACK_BTN_ITEM.getMaterial().parseMaterial())).setName(Settings.GUI_BACK_BTN_NAME.getString()).setLore(Settings.GUI_BACK_BTN_LORE.getStringList()).toItemStack());
setNextPage(5, 5, new TItemBuilder(Objects.requireNonNull(Settings.GUI_NEXT_BTN_ITEM.getMaterial().parseMaterial())).setName(Settings.GUI_NEXT_BTN_NAME.getString()).setLore(Settings.GUI_NEXT_BTN_LORE.getStringList()).toItemStack());
setPrevPage(Settings.GUI_BACK_BTN_SLOT.getInt(), new TItemBuilder(Objects.requireNonNull(Settings.GUI_BACK_BTN_ITEM.getMaterial().parseMaterial())).setName(Settings.GUI_BACK_BTN_NAME.getString()).setLore(Settings.GUI_BACK_BTN_LORE.getStringList()).toItemStack());
setNextPage(Settings.GUI_NEXT_BTN_SLOT.getInt(), new TItemBuilder(Objects.requireNonNull(Settings.GUI_NEXT_BTN_ITEM.getMaterial().parseMaterial())).setName(Settings.GUI_NEXT_BTN_NAME.getString()).setLore(Settings.GUI_NEXT_BTN_LORE.getStringList()).toItemStack());
setOnPage(e -> {
draw();
SoundManager.getInstance().playSound(this.auctionPlayer.getPlayer(), Settings.SOUNDS_NAVIGATE_GUI_PAGES.getString(), 1.0F, 1.0F);
@ -327,56 +308,43 @@ public class GUIAuctionHouse extends Gui {
}
private void drawFixedButtons() {
setButton(5, 0, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_AUCTION_HOUSE_ITEMS_YOUR_AUCTIONS_ITEM.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_YOUR_AUCTIONS_NAME.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_YOUR_AUCTIONS_LORE.getStringList(), new HashMap<String, Object>() {{
put("%active_player_auctions%", auctionPlayer.getItems(false).size());
put("%player_balance%", AuctionAPI.getInstance().formatNumber(EconomyManager.getBalance(auctionPlayer.getPlayer())));
}}), e -> {
cleanup();
e.manager.showGUI(e.player, new GUIActiveAuctions(this.auctionPlayer));
});
setButton(5, 1, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_AUCTION_HOUSE_ITEMS_COLLECTION_BIN_ITEM.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_COLLECTION_BIN_NAME.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_COLLECTION_BIN_LORE.getStringList(), new HashMap<String, Object>() {{
put("%expired_player_auctions%", auctionPlayer.getItems(true).size());
}}), e -> {
cleanup();
e.manager.showGUI(e.player, new GUIExpiredItems(this.auctionPlayer));
});
drawFilterButton();
setButton(5, 6, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_AUCTION_HOUSE_ITEMS_TRANSACTIONS_ITEM.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_TRANSACTIONS_NAME.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_TRANSACTIONS_LORE.getStringList(), new HashMap<String, Object>() {{
put("%total_items_bought%", AuctionHouse.getInstance().getTransactionManager().getTotalItemsBought(auctionPlayer.getPlayer().getUniqueId()));
put("%total_items_sold%", AuctionHouse.getInstance().getTransactionManager().getTotalItemsSold(auctionPlayer.getPlayer().getUniqueId()));
}}), e -> e.manager.showGUI(e.player, new GUITransactionList(this.auctionPlayer)));
if (Settings.REPLACE_HOW_TO_SELL_WITH_LIST_BUTTON.getBoolean()) {
setButton(5, 7, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_AUCTION_HOUSE_ITEMS_LIST_ITEM_ITEM.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_LIST_ITEM_NAME.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_LIST_ITEM_LORE.getStringList(), null), e -> {
// using this will ignore the "SELL_MENU_REQUIRES_USER_TO_HOLD_ITEM" setting
AuctionHouse.getInstance().getGuiManager().showGUI(e.player, new GUISellItem(auctionPlayer, XMaterial.AIR.parseItem()));
AuctionHouse.getInstance().getAuctionPlayerManager().addItemToSellHolding(e.player.getUniqueId(), XMaterial.AIR.parseItem());
});
if (Settings.GUI_AUCTION_HOUSE_ITEMS_LIST_ITEM_ENABLED.getBoolean()) {
setButton(Settings.GUI_AUCTION_HOUSE_ITEMS_LIST_ITEM_SLOT.getInt(), ConfigurationItemHelper.createConfigurationItem(Settings.GUI_AUCTION_HOUSE_ITEMS_LIST_ITEM_ITEM.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_LIST_ITEM_NAME.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_LIST_ITEM_LORE.getStringList(), null), e -> {
// using this will ignore the "SELL_MENU_REQUIRES_USER_TO_HOLD_ITEM" setting
AuctionHouse.getInstance().getGuiManager().showGUI(e.player, new GUISellItem(auctionPlayer, XMaterial.AIR.parseItem()));
AuctionHouse.getInstance().getAuctionPlayerManager().addItemToSellHolding(e.player.getUniqueId(), XMaterial.AIR.parseItem());
});
}
} else {
setButton(5, 7, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_AUCTION_HOUSE_ITEMS_HOW_TO_SELL_ITEM.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_HOW_TO_SELL_NAME.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_HOW_TO_SELL_LORE.getStringList(), null), null);
if (Settings.GUI_AUCTION_HOUSE_ITEMS_HOW_TO_SELL_ENABLED.getBoolean()) {
setButton(Settings.GUI_AUCTION_HOUSE_ITEMS_HOW_TO_SELL_SLOT.getInt(), ConfigurationItemHelper.createConfigurationItem(Settings.GUI_AUCTION_HOUSE_ITEMS_HOW_TO_SELL_ITEM.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_HOW_TO_SELL_NAME.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_HOW_TO_SELL_LORE.getStringList(), null), null);
}
}
setButton(5, 8, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_AUCTION_HOUSE_ITEMS_GUIDE_ITEM.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_GUIDE_NAME.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_GUIDE_LORE.getStringList(), null), null);
if (Settings.GUI_AUCTION_HOUSE_ITEMS_GUIDE_ENABLED.getBoolean()) {
setButton(Settings.GUI_AUCTION_HOUSE_ITEMS_GUIDE_SLOT.getInt(), ConfigurationItemHelper.createConfigurationItem(Settings.GUI_AUCTION_HOUSE_ITEMS_GUIDE_ITEM.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_GUIDE_NAME.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_GUIDE_LORE.getStringList(), null), null);
}
setButton(5, 4, new TItemBuilder(Objects.requireNonNull(Settings.GUI_REFRESH_BTN_ITEM.getMaterial().parseMaterial())).setName(Settings.GUI_REFRESH_BTN_NAME.getString()).setLore(Settings.GUI_REFRESH_BTN_LORE.getStringList()).toItemStack(), e -> {
if (Settings.USE_REFRESH_COOL_DOWN.getBoolean()) {
if (AuctionHouse.getInstance().getAuctionPlayerManager().getCooldowns().containsKey(this.auctionPlayer.getPlayer().getUniqueId())) {
if (AuctionHouse.getInstance().getAuctionPlayerManager().getCooldowns().get(this.auctionPlayer.getPlayer().getUniqueId()) > System.currentTimeMillis()) {
return;
if (Settings.GUI_REFRESH_BTN_ENABLED.getBoolean()) {
setButton(Settings.GUI_REFRESH_BTN_SLOT.getInt(), new TItemBuilder(Objects.requireNonNull(Settings.GUI_REFRESH_BTN_ITEM.getMaterial().parseMaterial())).setName(Settings.GUI_REFRESH_BTN_NAME.getString()).setLore(Settings.GUI_REFRESH_BTN_LORE.getStringList()).toItemStack(), e -> {
if (Settings.USE_REFRESH_COOL_DOWN.getBoolean()) {
if (AuctionHouse.getInstance().getAuctionPlayerManager().getCooldowns().containsKey(this.auctionPlayer.getPlayer().getUniqueId())) {
if (AuctionHouse.getInstance().getAuctionPlayerManager().getCooldowns().get(this.auctionPlayer.getPlayer().getUniqueId()) > System.currentTimeMillis()) {
return;
}
}
AuctionHouse.getInstance().getAuctionPlayerManager().addCooldown(this.auctionPlayer.getPlayer().getUniqueId());
}
AuctionHouse.getInstance().getAuctionPlayerManager().addCooldown(this.auctionPlayer.getPlayer().getUniqueId());
}
cleanup();
e.manager.showGUI(e.player, new GUIAuctionHouse(this.auctionPlayer));
});
cleanup();
e.manager.showGUI(e.player, new GUIAuctionHouse(this.auctionPlayer));
});
}
}
private void drawFilterButton() {
if (Settings.USE_SEPARATE_FILTER_MENU.getBoolean()) {
String materialToBeUsed = Settings.GUI_AUCTION_HOUSE_ITEMS_FILTER_MENU_ITEM.getString();
switch (auctionPlayer.getSelectedFilter()) {
@ -420,15 +388,45 @@ public class GUIAuctionHouse extends Gui {
ItemStack item = materialToBeUsed.equalsIgnoreCase("PLAYER_HEAD") ? ConfigurationItemHelper.createConfigurationItem(AuctionAPI.getInstance().getPlayerHead(this.auctionPlayer.getPlayer().getName()), Settings.GUI_AUCTION_HOUSE_ITEMS_FILTER_MENU_NAME.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_FILTER_MENU_LORE.getStringList(), replacements) : ConfigurationItemHelper.createConfigurationItem(materialToBeUsed, Settings.GUI_AUCTION_HOUSE_ITEMS_FILTER_MENU_NAME.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_FILTER_MENU_LORE.getStringList(), replacements);
setButton(5, 2, item, e -> {
if (Settings.GUI_AUCTION_HOUSE_ITEMS_FILTER_MENU_ENABLED.getBoolean()) {
setButton(Settings.GUI_AUCTION_HOUSE_ITEMS_FILTER_MENU_SLOT.getInt(), item, e -> {
switch (e.clickType) {
case LEFT:
e.manager.showGUI(e.player, new GUIFilterSelection(this.auctionPlayer));
break;
case MIDDLE:
this.auctionPlayer.resetFilter();
draw();
break;
case RIGHT:
this.auctionPlayer.setSelectedSaleType(this.auctionPlayer.getSelectedSaleType().next());
draw();
break;
case SHIFT_RIGHT:
this.auctionPlayer.setAuctionSortType(this.auctionPlayer.getAuctionSortType().next());
draw();
break;
}
});
}
return;
}
if (Settings.GUI_AUCTION_HOUSE_ITEMS_FILTER_ENABLED.getBoolean()) {
setButton(Settings.GUI_AUCTION_HOUSE_ITEMS_FILTER_SLOT.getInt(), ConfigurationItemHelper.createConfigurationItem(Settings.GUI_AUCTION_HOUSE_ITEMS_FILTER_ITEM.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_FILTER_NAME.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_FILTER_LORE.getStringList(), new HashMap<String, Object>() {{
put("%filter_category%", auctionPlayer.getSelectedFilter().getTranslatedType());
put("%filter_auction_type%", auctionPlayer.getSelectedSaleType().getTranslatedType());
put("%filter_sort_order%", auctionPlayer.getAuctionSortType().getTranslatedType());
}}), e -> {
switch (e.clickType) {
case LEFT:
e.manager.showGUI(e.player, new GUIFilterSelection(this.auctionPlayer));
break;
case MIDDLE:
this.auctionPlayer.resetFilter();
draw();
break;
case LEFT:
this.auctionPlayer.setSelectedFilter(this.auctionPlayer.getSelectedFilter().next());
draw();
break;
case RIGHT:
this.auctionPlayer.setSelectedSaleType(this.auctionPlayer.getSelectedSaleType().next());
draw();
@ -438,35 +436,8 @@ public class GUIAuctionHouse extends Gui {
draw();
break;
}
});
return;
}
setButton(5, 2, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_AUCTION_HOUSE_ITEMS_FILTER_ITEM.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_FILTER_NAME.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_FILTER_LORE.getStringList(), new HashMap<String, Object>() {{
put("%filter_category%", auctionPlayer.getSelectedFilter().getTranslatedType());
put("%filter_auction_type%", auctionPlayer.getSelectedSaleType().getTranslatedType());
put("%filter_sort_order%", auctionPlayer.getAuctionSortType().getTranslatedType());
}}), e -> {
switch (e.clickType) {
case MIDDLE:
this.auctionPlayer.resetFilter();
draw();
break;
case LEFT:
this.auctionPlayer.setSelectedFilter(this.auctionPlayer.getSelectedFilter().next());
draw();
break;
case RIGHT:
this.auctionPlayer.setSelectedSaleType(this.auctionPlayer.getSelectedSaleType().next());
draw();
break;
case SHIFT_RIGHT:
this.auctionPlayer.setAuctionSortType(this.auctionPlayer.getAuctionSortType().next());
draw();
break;
}
});
}
/*
@ -477,7 +448,9 @@ public class GUIAuctionHouse extends Gui {
}
private void cleanup() {
task.cancel();
if (task != null) {
task.cancel();
}
}
}

View File

@ -0,0 +1,121 @@
package ca.tweetzy.auctionhouse.guis;
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.api.AuctionAPI;
import ca.tweetzy.auctionhouse.auction.AuctionPlayer;
import ca.tweetzy.auctionhouse.auction.AuctionedItem;
import ca.tweetzy.auctionhouse.guis.confirmation.GUIConfirmBid;
import ca.tweetzy.auctionhouse.helpers.ConfigurationItemHelper;
import ca.tweetzy.auctionhouse.settings.Settings;
import ca.tweetzy.core.gui.Gui;
import ca.tweetzy.core.hooks.EconomyManager;
import ca.tweetzy.core.input.PlayerChatInput;
import ca.tweetzy.core.utils.NumberUtils;
import ca.tweetzy.core.utils.TextUtils;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.inventory.ItemStack;
/**
* The current file has been created by Kiran Hart
* Date Created: August 08 2021
* Time Created: 5:16 p.m.
* Usage of any code found within this class is prohibited unless given explicit permission otherwise
*/
public class GUIBid extends Gui {
private final AuctionPlayer auctionPlayer;
private final AuctionedItem auctionItem;
public GUIBid(AuctionPlayer auctionPlayer, AuctionedItem auctionItem) {
this.auctionPlayer = auctionPlayer;
this.auctionItem = auctionItem;
setTitle(TextUtils.formatText(Settings.GUI_BIDDING_TITLE.getString()));
setDefaultItem(Settings.GUI_BIDDING_BG_ITEM.getMaterial().parseItem());
setUseLockedCells(true);
setAcceptsItems(false);
setAllowDrops(false);
setRows(3);
draw();
setOnClose(close -> close.manager.showGUI(close.player, new GUIAuctionHouse(this.auctionPlayer)));
}
private void draw() {
setItem(1, 4, this.auctionItem.getItem());
setButton(1, 2, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_BIDDING_ITEMS_DEFAULT_ITEM.getString(), Settings.GUI_BIDDING_ITEMS_DEFAULT_NAME.getString(), Settings.GUI_BIDDING_ITEMS_DEFAULT_LORE.getStringList(), null), e -> {
if (Settings.PLAYER_NEEDS_TOTAL_PRICE_TO_BID.getBoolean() && !EconomyManager.hasBalance(e.player, auctionItem.getCurrentPrice() + auctionItem.getBidIncrementPrice())) {
AuctionHouse.getInstance().getLocale().getMessage("general.notenoughmoney").sendPrefixedMessage(e.player);
return;
}
e.gui.exit();
e.manager.showGUI(e.player, new GUIConfirmBid(this.auctionPlayer, auctionItem));
});
setButton(1, 6, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_BIDDING_ITEMS_CUSTOM_ITEM.getString(), Settings.GUI_BIDDING_ITEMS_CUSTOM_NAME.getString(), Settings.GUI_BIDDING_ITEMS_CUSTOM_LORE.getStringList(), null), e -> {
e.gui.exit();
PlayerChatInput.PlayerChatInputBuilder<Double> builder = new PlayerChatInput.PlayerChatInputBuilder<>(AuctionHouse.getInstance(), e.player);
builder.isValidInput((p, str) -> NumberUtils.isDouble(str) && Double.parseDouble(str) >= this.auctionItem.getBidIncrementPrice());
builder.sendValueMessage(TextUtils.formatText(AuctionHouse.getInstance().getLocale().getMessage("prompts.enter bid amount").getMessage()));
builder.toCancel("cancel");
builder.onCancel(p -> e.manager.showGUI(e.player, new GUIAuctionHouse(this.auctionPlayer)));
builder.setValue((p, value) -> Double.parseDouble(value));
builder.onFinish((p, value) -> {
if (Settings.PLAYER_NEEDS_TOTAL_PRICE_TO_BID.getBoolean() && !EconomyManager.hasBalance(e.player, auctionItem.getCurrentPrice() + value)) {
AuctionHouse.getInstance().getLocale().getMessage("general.notenoughmoney").sendPrefixedMessage(e.player);
return;
}
if (Settings.ASK_FOR_BID_CONFIRMATION.getBoolean()) {
e.manager.showGUI(e.player, new GUIConfirmBid(this.auctionPlayer, auctionItem, value));
return;
}
ItemStack itemStack = auctionItem.getItem();
OfflinePlayer oldBidder = Bukkit.getOfflinePlayer(auctionItem.getHighestBidder());
OfflinePlayer owner = Bukkit.getOfflinePlayer(auctionItem.getOwner());
auctionItem.setHighestBidder(e.player.getUniqueId());
auctionItem.setHighestBidderName(e.player.getName());
auctionItem.setCurrentPrice(auctionItem.getCurrentPrice() + value);
if (auctionItem.getBasePrice() != -1 && Settings.SYNC_BASE_PRICE_TO_HIGHEST_PRICE.getBoolean() && auctionItem.getCurrentPrice() > auctionItem.getBasePrice()) {
auctionItem.setBasePrice(auctionItem.getCurrentPrice());
}
if (Settings.INCREASE_TIME_ON_BID.getBoolean()) {
auctionItem.setExpiresAt(auctionItem.getExpiresAt() + 1000L * Settings.TIME_TO_INCREASE_BY_ON_BID.getInt());
}
if (oldBidder.isOnline()) {
AuctionHouse.getInstance().getLocale().getMessage("auction.outbid")
.processPlaceholder("player", e.player.getName())
.processPlaceholder("item", AuctionAPI.getInstance().getItemName(itemStack))
.sendPrefixedMessage(oldBidder.getPlayer());
}
if (owner.isOnline()) {
AuctionHouse.getInstance().getLocale().getMessage("auction.placedbid")
.processPlaceholder("player", e.player.getName())
.processPlaceholder("amount", AuctionAPI.getInstance().formatNumber(auctionItem.getCurrentPrice()))
.processPlaceholder("item", AuctionAPI.getInstance().getItemName(itemStack))
.sendPrefixedMessage(owner.getPlayer());
}
if (Settings.BROADCAST_AUCTION_BID.getBoolean()) {
Bukkit.getOnlinePlayers().forEach(player -> AuctionHouse.getInstance().getLocale().getMessage("auction.broadcast.bid")
.processPlaceholder("player", e.player.getName())
.processPlaceholder("amount", AuctionAPI.getInstance().formatNumber(auctionItem.getCurrentPrice()))
.processPlaceholder("item", AuctionAPI.getInstance().getItemName(itemStack))
.sendPrefixedMessage(player));
}
e.manager.showGUI(e.player, new GUIAuctionHouse(this.auctionPlayer));
});
PlayerChatInput<Double> input = builder.build();
input.start();
});
}
}

View File

@ -4,6 +4,7 @@ import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.api.AuctionAPI;
import ca.tweetzy.auctionhouse.auction.AuctionItem;
import ca.tweetzy.auctionhouse.auction.AuctionPlayer;
import ca.tweetzy.auctionhouse.auction.AuctionedItem;
import ca.tweetzy.auctionhouse.guis.confirmation.GUIConfirmPurchase;
import ca.tweetzy.auctionhouse.helpers.ConfigurationItemHelper;
import ca.tweetzy.auctionhouse.settings.Settings;
@ -34,7 +35,7 @@ public class GUIContainerInspect extends Gui {
private List<ItemStack> items;
private AuctionPlayer auctionPlayer;
private AuctionItem auctionItem;
private AuctionedItem auctionItem;
private boolean buyingSpecificQuantity;
private boolean fromPurchaseGUI;
@ -73,7 +74,7 @@ public class GUIContainerInspect extends Gui {
setOnClose(close -> close.manager.showGUI(close.player, new GUIAuctionHouse(AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(close.player.getUniqueId()))));
}
public GUIContainerInspect(ItemStack container, AuctionPlayer auctionPlayer, AuctionItem auctionItem, boolean buyingSpecificQuantity) {
public GUIContainerInspect(ItemStack container, AuctionPlayer auctionPlayer, AuctionedItem auctionItem, boolean buyingSpecificQuantity) {
this(container);
this.auctionPlayer = auctionPlayer;
this.auctionItem = auctionItem;
@ -82,7 +83,7 @@ public class GUIContainerInspect extends Gui {
// Overwrite the default close, since they are accessing the inspection from the purchase screen
setOnClose(close -> {
AuctionHouse.getInstance().getTransactionManager().addPrePurchase(close.player, auctionItem.getKey());
AuctionHouse.getInstance().getTransactionManager().addPrePurchase(close.player, auctionItem.getId());
close.manager.showGUI(close.player, new GUIConfirmPurchase(this.auctionPlayer, this.auctionItem, this.buyingSpecificQuantity));
});
}
@ -96,7 +97,7 @@ public class GUIContainerInspect extends Gui {
setPrevPage(5, 3, new TItemBuilder(Objects.requireNonNull(Settings.GUI_BACK_BTN_ITEM.getMaterial().parseMaterial())).setName(Settings.GUI_BACK_BTN_NAME.getString()).setLore(Settings.GUI_BACK_BTN_LORE.getStringList()).toItemStack());
setButton(5, 4, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_CLOSE_BTN_ITEM.getString(), Settings.GUI_CLOSE_BTN_NAME.getString(), Settings.GUI_CLOSE_BTN_LORE.getStringList(), null), e -> {
if (fromPurchaseGUI) {
AuctionHouse.getInstance().getTransactionManager().addPrePurchase(e.player, auctionItem.getKey());
AuctionHouse.getInstance().getTransactionManager().addPrePurchase(e.player, auctionItem.getId());
e.manager.showGUI(e.player, new GUIConfirmPurchase(this.auctionPlayer, this.auctionItem, this.buyingSpecificQuantity));
} else {
e.manager.showGUI(e.player, new GUIAuctionHouse(AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(e.player.getUniqueId())));

View File

@ -1,9 +1,8 @@
package ca.tweetzy.auctionhouse.guis;
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.api.AuctionAPI;
import ca.tweetzy.auctionhouse.auction.AuctionItem;
import ca.tweetzy.auctionhouse.auction.AuctionPlayer;
import ca.tweetzy.auctionhouse.auction.AuctionedItem;
import ca.tweetzy.auctionhouse.helpers.ConfigurationItemHelper;
import ca.tweetzy.auctionhouse.managers.SoundManager;
import ca.tweetzy.auctionhouse.settings.Settings;
@ -26,7 +25,8 @@ import java.util.stream.Collectors;
public class GUIExpiredItems extends Gui {
final AuctionPlayer auctionPlayer;
private List<AuctionItem> items;
private List<AuctionedItem> items;
public GUIExpiredItems(AuctionPlayer auctionPlayer) {
this.auctionPlayer = auctionPlayer;
@ -43,7 +43,7 @@ public class GUIExpiredItems extends Gui {
AuctionHouse.newChain().asyncFirst(() -> {
this.items = this.auctionPlayer.getItems(true);
return this.items.stream().sorted(Comparator.comparingInt(AuctionItem::getRemainingTime).reversed()).skip((page - 1) * 45L).limit(45).collect(Collectors.toList());
return this.items.stream().sorted(Comparator.comparingLong(AuctionedItem::getExpiresAt).reversed()).skip((page - 1) * 45L).limit(45).collect(Collectors.toList());
}).asyncLast((data) -> {
pages = (int) Math.max(1, Math.ceil(this.auctionPlayer.getItems(true).size() / (double) 45));
setPrevPage(5, 3, new TItemBuilder(Objects.requireNonNull(Settings.GUI_BACK_BTN_ITEM.getMaterial().parseMaterial())).setName(Settings.GUI_BACK_BTN_NAME.getString()).setLore(Settings.GUI_BACK_BTN_LORE.getStringList()).toItemStack());
@ -56,17 +56,18 @@ public class GUIExpiredItems extends Gui {
setButton(5, 1, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_EXPIRED_AUCTIONS_ITEM.getString(), Settings.GUI_EXPIRED_AUCTIONS_NAME.getString(), Settings.GUI_EXPIRED_AUCTIONS_LORE.getStringList(), null), e -> {
for (AuctionItem auctionItem : data) {
PlayerUtils.giveItem(e.player, AuctionAPI.getInstance().deserializeItem(auctionItem.getRawItem()));
for (AuctionedItem auctionItem : data) {
PlayerUtils.giveItem(e.player, auctionItem.getItem());
AuctionHouse.getInstance().getAuctionItemManager().sendToGarbage(auctionItem);
}
draw();
});
int slot = 0;
for (AuctionItem auctionItem : data) {
setButton(slot++, AuctionAPI.getInstance().deserializeItem(auctionItem.getRawItem()), e -> {
PlayerUtils.giveItem(e.player, AuctionAPI.getInstance().deserializeItem(auctionItem.getRawItem()));
for (AuctionedItem auctionItem : data) {
setButton(slot++, auctionItem.getItem(), e -> {
if (!Settings.ALLOW_INDIVIDUAL_ITEM_CLAIM.getBoolean()) return;
PlayerUtils.giveItem(e.player, auctionItem.getItem());
AuctionHouse.getInstance().getAuctionItemManager().sendToGarbage(auctionItem);
e.manager.showGUI(e.player, new GUIExpiredItems(this.auctionPlayer));
});

View File

@ -2,29 +2,20 @@ package ca.tweetzy.auctionhouse.guis;
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.api.AuctionAPI;
import ca.tweetzy.auctionhouse.api.events.AuctionStartEvent;
import ca.tweetzy.auctionhouse.auction.AuctionItem;
import ca.tweetzy.auctionhouse.auction.AuctionPlayer;
import ca.tweetzy.auctionhouse.helpers.ConfigurationItemHelper;
import ca.tweetzy.auctionhouse.helpers.MaterialCategorizer;
import ca.tweetzy.auctionhouse.managers.SoundManager;
import ca.tweetzy.auctionhouse.settings.Settings;
import ca.tweetzy.core.commands.AbstractCommand;
import ca.tweetzy.core.compatibility.XMaterial;
import ca.tweetzy.core.gui.Gui;
import ca.tweetzy.core.gui.events.GuiClickEvent;
import ca.tweetzy.core.hooks.EconomyManager;
import ca.tweetzy.core.input.ChatPrompt;
import ca.tweetzy.core.utils.NumberUtils;
import ca.tweetzy.core.utils.PlayerUtils;
import ca.tweetzy.core.utils.TextUtils;
import ca.tweetzy.core.utils.TimeUtils;
import org.bukkit.Bukkit;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import java.util.HashMap;
import java.util.UUID;
/**
* The current file has been created by Kiran Hart
@ -115,7 +106,7 @@ public class GUISellItem extends Gui {
// the draw item that is being listed
setButton(1, 4, this.itemToBeListed, e -> {
if (e.clickType == ClickType.RIGHT) e.event.setCancelled(true);
if (e.clickType == ClickType.RIGHT || e.clickType == ClickType.NUMBER_KEY) e.event.setCancelled(true);
// Is the user selling with an item in hand?
if (AuctionHouse.getInstance().getAuctionPlayerManager().getSellHolding().containsKey(e.player.getUniqueId())) {
if (AuctionHouse.getInstance().getAuctionPlayerManager().getSellHolding().get(e.player.getUniqueId()).getType() != XMaterial.AIR.parseMaterial()) {
@ -136,7 +127,7 @@ public class GUISellItem extends Gui {
ChatPrompt.showPrompt(AuctionHouse.getInstance(), this.auctionPlayer.getPlayer(), TextUtils.formatText(AuctionHouse.getInstance().getLocale().getMessage("prompts.enter new buy now price").getMessage()), chat -> {
String msg = chat.getMessage();
if (validateChatNumber(msg, Settings.MIN_AUCTION_PRICE.getDouble())) {
if (validateChatNumber(msg, Settings.MIN_AUCTION_PRICE.getDouble(), false) && validateChatNumber(msg, Settings.MAX_AUCTION_PRICE.getDouble(), true)) {
// check if the buy now price is higher than the bid start price
if (this.isAllowingBuyNow && this.isBiddingItem && Settings.BASE_PRICE_MUST_BE_HIGHER_THAN_BID_START.getBoolean() && Double.parseDouble(msg) < this.bidStartPrice) {
reopen(e);
@ -159,7 +150,7 @@ public class GUISellItem extends Gui {
e.gui.close();
ChatPrompt.showPrompt(AuctionHouse.getInstance(), this.auctionPlayer.getPlayer(), TextUtils.formatText(AuctionHouse.getInstance().getLocale().getMessage("prompts.enter new starting bid").getMessage()), chat -> {
String msg = chat.getMessage();
if (validateChatNumber(msg, Settings.MIN_AUCTION_START_PRICE.getDouble())) {
if (validateChatNumber(msg, Settings.MIN_AUCTION_START_PRICE.getDouble(), false) && validateChatNumber(msg, Settings.MAX_AUCTION_START_PRICE.getDouble(), true)) {
this.bidStartPrice = Double.parseDouble(msg);
}
reopen(e);
@ -174,7 +165,7 @@ public class GUISellItem extends Gui {
e.gui.close();
ChatPrompt.showPrompt(AuctionHouse.getInstance(), this.auctionPlayer.getPlayer(), TextUtils.formatText(AuctionHouse.getInstance().getLocale().getMessage("prompts.enter new bid increment").getMessage()), chat -> {
String msg = chat.getMessage();
if (validateChatNumber(msg, Settings.MIN_AUCTION_INCREMENT_PRICE.getDouble())) {
if (validateChatNumber(msg, Settings.MIN_AUCTION_INCREMENT_PRICE.getDouble(), false) && validateChatNumber(msg, Settings.MAX_AUCTION_INCREMENT_PRICE.getDouble(), true)) {
this.bidIncrementPrice = Double.parseDouble(msg);
}
reopen(e);
@ -217,66 +208,32 @@ public class GUISellItem extends Gui {
if (getItem(1, 4) == null || getItem(1, 4).getType() == XMaterial.AIR.parseMaterial()) return;
setTheItemToBeListed();
AuctionItem auctionItem = new AuctionItem(
e.player.getUniqueId(),
e.player.getUniqueId(),
AuctionAPI.getInstance().listAuction(
e.player,
this.itemToBeListed,
MaterialCategorizer.getMaterialCategory(itemToBeListed),
UUID.randomUUID(),
this.itemToBeListed,
this.auctionPlayer.getAllowedSellTime(),
this.isBiddingItem && !isAllowingBuyNow || !Settings.ALLOW_USAGE_OF_BUY_NOW_SYSTEM.getBoolean() ? -1 : buyNowPrice,
this.isBiddingItem ? bidStartPrice : 0,
this.isBiddingItem ? bidIncrementPrice : 0,
this.isBiddingItem ? bidStartPrice : buyNowPrice,
this.auctionPlayer.getAllowedSellTime(),
this.isBiddingItem,
false
);
AuctionStartEvent auctionStartEvent = new AuctionStartEvent(e.player, auctionItem);
Bukkit.getServer().getPluginManager().callEvent(auctionStartEvent);
if (auctionStartEvent.isCancelled()) return;
if (Settings.TAX_ENABLED.getBoolean() && Settings.TAX_CHARGE_LISTING_FEE.getBoolean()) {
if (!EconomyManager.hasBalance(e.player, Settings.TAX_LISTING_FEE.getDouble())) {
AuctionHouse.getInstance().getLocale().getMessage("auction.tax.cannotpaylistingfee").processPlaceholder("price", String.format("%,.2f", Settings.TAX_LISTING_FEE.getDouble())).sendPrefixedMessage(e.player);
return;
}
EconomyManager.withdrawBalance(e.player, Settings.TAX_LISTING_FEE.getDouble());
AuctionHouse.getInstance().getLocale().getMessage("auction.tax.paidlistingfee").processPlaceholder("price", String.format("%,.2f", Settings.TAX_LISTING_FEE.getDouble())).sendPrefixedMessage(e.player);
AuctionHouse.getInstance().getLocale().getMessage("pricing.moneyremove").processPlaceholder("price", String.format("%,.2f", Settings.TAX_LISTING_FEE.getDouble())).sendPrefixedMessage(e.player);
}
AuctionHouse.getInstance().getAuctionItemManager().addItem(auctionItem);
SoundManager.getInstance().playSound(e.player, Settings.SOUNDS_LISTED_ITEM_ON_AUCTION_HOUSE.getString(), 1.0F, 1.0F);
AuctionHouse.getInstance().getAuctionPlayerManager().removeItemFromSellHolding(e.player.getUniqueId());
AuctionHouse.getInstance().getAuctionPlayerManager().removeFromUsingSellGUI(e.player.getUniqueId());
setAllowClose(true);
e.gui.exit();
if (Settings.OPEN_MAIN_AUCTION_HOUSE_AFTER_MENU_LIST.getBoolean()) {
setAllowClose(true);
e.manager.showGUI(e.player, new GUIAuctionHouse(this.auctionPlayer));
} else {
setAllowClose(true);
e.gui.exit();
}
// TODO FIGURE OUT WHY THE HELL THIS IS NOT WORKING
String NAX = AuctionHouse.getInstance().getLocale().getMessage("auction.biditemwithdisabledbuynow").getMessage();
String msg = AuctionHouse.getInstance().getLocale().getMessage(isBiddingItem ? "auction.listed.withbid" : "auction.listed.nobid")
.processPlaceholder("amount", itemToBeListed.getAmount())
.processPlaceholder("item", AuctionAPI.getInstance().getItemName(itemToBeListed))
.processPlaceholder("base_price", auctionItem.getBasePrice() <= -1 ? NAX : AuctionAPI.getInstance().formatNumber(auctionItem.getBasePrice()))
.processPlaceholder("start_price", AuctionAPI.getInstance().formatNumber(auctionItem.getBidStartPrice()))
.processPlaceholder("increment_price", AuctionAPI.getInstance().formatNumber(auctionItem.getBidIncPrice())).getMessage();
AuctionHouse.getInstance().getLocale().newMessage(msg).sendPrefixedMessage(e.player);
if (Settings.BROADCAST_AUCTION_LIST.getBoolean()) {
Bukkit.getOnlinePlayers().forEach(p -> AuctionHouse.getInstance().getLocale().newMessage(msg).processPlaceholder("player", p.getName()).sendPrefixedMessage(p));
}
});
}
private boolean validateChatNumber(String input, double requirement) {
private boolean validateChatNumber(String input, double requirement, boolean checkMax) {
if (checkMax) return input != null && input.length() != 0 && NumberUtils.isDouble(input) && Double.parseDouble(input) <= requirement;
return input != null && input.length() != 0 && NumberUtils.isDouble(input) && Double.parseDouble(input) >= requirement;
}

View File

@ -2,8 +2,8 @@ package ca.tweetzy.auctionhouse.guis.confirmation;
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.api.AuctionAPI;
import ca.tweetzy.auctionhouse.auction.AuctionItem;
import ca.tweetzy.auctionhouse.auction.AuctionPlayer;
import ca.tweetzy.auctionhouse.auction.AuctionedItem;
import ca.tweetzy.auctionhouse.guis.GUIAuctionHouse;
import ca.tweetzy.auctionhouse.settings.Settings;
import ca.tweetzy.core.gui.Gui;
@ -26,11 +26,17 @@ import java.util.Objects;
public class GUIConfirmBid extends Gui {
final AuctionPlayer auctionPlayer;
final AuctionItem auctionItem;
final AuctionedItem auctionItem;
final double bidAmount;
public GUIConfirmBid(AuctionPlayer auctionPlayer, AuctionItem auctionItem) {
public GUIConfirmBid(AuctionPlayer auctionPlayer, AuctionedItem auctionItem) {
this(auctionPlayer, auctionItem, -1);
}
public GUIConfirmBid(AuctionPlayer auctionPlayer, AuctionedItem auctionItem, double bidAmount) {
this.auctionPlayer = auctionPlayer;
this.auctionItem = auctionItem;
this.bidAmount = bidAmount;
setTitle(TextUtils.formatText(Settings.GUI_CONFIRM_BID_TITLE.getString()));
setAcceptsItems(false);
setRows(1);
@ -39,36 +45,39 @@ public class GUIConfirmBid extends Gui {
private void draw() {
setItems(0, 3, new TItemBuilder(Objects.requireNonNull(Settings.GUI_CONFIRM_BID_YES_ITEM.getMaterial().parseMaterial())).setName(Settings.GUI_CONFIRM_BID_YES_NAME.getString()).setLore(Settings.GUI_CONFIRM_BID_YES_LORE.getStringList()).toItemStack());
setItem(0, 4, AuctionAPI.getInstance().deserializeItem(this.auctionItem.getRawItem()));
setItem(0, 4, this.auctionItem.getItem());
setItems(5, 8, new TItemBuilder(Objects.requireNonNull(Settings.GUI_CONFIRM_BID_NO_ITEM.getMaterial().parseMaterial())).setName(Settings.GUI_CONFIRM_BID_NO_NAME.getString()).setLore(Settings.GUI_CONFIRM_BID_NO_LORE.getStringList()).toItemStack());
setActionForRange(5, 8, ClickType.LEFT, e -> e.manager.showGUI(e.player, new GUIAuctionHouse(this.auctionPlayer)));
setActionForRange(0, 3, ClickType.LEFT, e -> {
// Re-select the item to ensure that it's available
AuctionItem located = AuctionHouse.getInstance().getAuctionItemManager().getItem(this.auctionItem.getKey());
AuctionedItem located = AuctionHouse.getInstance().getAuctionItemManager().getItem(this.auctionItem.getId());
if (located == null) {
e.manager.showGUI(e.player, new GUIAuctionHouse(this.auctionPlayer));
return;
}
if (Settings.PLAYER_NEEDS_TOTAL_PRICE_TO_BID.getBoolean() && !EconomyManager.hasBalance(e.player, auctionItem.getCurrentPrice() + auctionItem.getBidIncPrice())) {
double toIncrementBy = this.bidAmount == -1 ? auctionItem.getBidIncrementPrice() : this.bidAmount;
if (Settings.PLAYER_NEEDS_TOTAL_PRICE_TO_BID.getBoolean() && !EconomyManager.hasBalance(e.player, auctionItem.getCurrentPrice() + toIncrementBy)) {
AuctionHouse.getInstance().getLocale().getMessage("general.notenoughmoney").sendPrefixedMessage(e.player);
return;
}
ItemStack itemStack = AuctionAPI.getInstance().deserializeItem(auctionItem.getRawItem());
ItemStack itemStack = auctionItem.getItem();
OfflinePlayer oldBidder = Bukkit.getOfflinePlayer(auctionItem.getHighestBidder());
OfflinePlayer owner = Bukkit.getOfflinePlayer(auctionItem.getOwner());
auctionItem.setHighestBidder(e.player.getUniqueId());
auctionItem.setCurrentPrice(auctionItem.getCurrentPrice() + auctionItem.getBidIncPrice());
auctionItem.setHighestBidderName(e.player.getName());
auctionItem.setCurrentPrice(auctionItem.getCurrentPrice() + toIncrementBy);
if (auctionItem.getBasePrice() != -1 && Settings.SYNC_BASE_PRICE_TO_HIGHEST_PRICE.getBoolean() && Settings.ALLOW_USAGE_OF_BUY_NOW_SYSTEM.getBoolean() && auctionItem.getCurrentPrice() > auctionItem.getBasePrice()) {
auctionItem.setBasePrice(auctionItem.getCurrentPrice());
}
if (Settings.INCREASE_TIME_ON_BID.getBoolean()) {
auctionItem.setRemainingTime(auctionItem.getRemainingTime() + Settings.TIME_TO_INCREASE_BY_ON_BID.getInt());
auctionItem.setExpiresAt(auctionItem.getExpiresAt() + 1000L * Settings.TIME_TO_INCREASE_BY_ON_BID.getInt());
}
if (Settings.BROADCAST_AUCTION_BID.getBoolean()) {

View File

@ -1,9 +1,9 @@
package ca.tweetzy.auctionhouse.guis.confirmation;
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.auction.AuctionItem;
import ca.tweetzy.auctionhouse.auction.AuctionPlayer;
import ca.tweetzy.auctionhouse.auction.AuctionStackType;
import ca.tweetzy.auctionhouse.auction.AuctionedItem;
import ca.tweetzy.auctionhouse.guis.GUIActiveAuctions;
import ca.tweetzy.auctionhouse.settings.Settings;
import ca.tweetzy.core.gui.Gui;
@ -22,9 +22,9 @@ import java.util.Objects;
public class GUIConfirmCancel extends Gui {
final AuctionPlayer auctionPlayer;
final AuctionItem auctionItem;
final AuctionedItem auctionItem;
public GUIConfirmCancel(AuctionPlayer auctionPlayer, AuctionItem auctionItem) {
public GUIConfirmCancel(AuctionPlayer auctionPlayer, AuctionedItem auctionItem) {
this.auctionPlayer = auctionPlayer;
this.auctionItem = auctionItem;
setTitle(TextUtils.formatText(Settings.GUI_CONFIRM_CANCEL_TITLE.getString()));
@ -41,7 +41,7 @@ public class GUIConfirmCancel extends Gui {
setActionForRange(5, 8, ClickType.LEFT, e -> e.manager.showGUI(e.player, new GUIActiveAuctions(this.auctionPlayer)));
setActionForRange(0, 3, ClickType.LEFT, e -> {
// Re-select the item to ensure that it's available
AuctionItem located = AuctionHouse.getInstance().getAuctionItemManager().getItem(this.auctionItem.getKey());
AuctionedItem located = AuctionHouse.getInstance().getAuctionItemManager().getItem(this.auctionItem.getId());
if (located == null) {
e.manager.showGUI(e.player, new GUIActiveAuctions(this.auctionPlayer));
return;

View File

@ -3,9 +3,9 @@ package ca.tweetzy.auctionhouse.guis.confirmation;
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.api.AuctionAPI;
import ca.tweetzy.auctionhouse.api.events.AuctionEndEvent;
import ca.tweetzy.auctionhouse.auction.AuctionItem;
import ca.tweetzy.auctionhouse.auction.AuctionPlayer;
import ca.tweetzy.auctionhouse.auction.AuctionSaleType;
import ca.tweetzy.auctionhouse.auction.AuctionedItem;
import ca.tweetzy.auctionhouse.exception.ItemNotFoundException;
import ca.tweetzy.auctionhouse.guis.GUIAuctionHouse;
import ca.tweetzy.auctionhouse.guis.GUIContainerInspect;
@ -18,7 +18,6 @@ import ca.tweetzy.core.hooks.EconomyManager;
import ca.tweetzy.core.utils.PlayerUtils;
import ca.tweetzy.core.utils.TextUtils;
import ca.tweetzy.core.utils.items.TItemBuilder;
import org.apache.commons.lang.WordUtils;
import org.bukkit.Bukkit;
import org.bukkit.block.ShulkerBox;
import org.bukkit.entity.Player;
@ -38,21 +37,21 @@ import java.util.Objects;
public class GUIConfirmPurchase extends Gui {
final AuctionPlayer auctionPlayer;
final AuctionItem auctionItem;
final AuctionedItem auctionItem;
boolean buyingSpecificQuantity;
int purchaseQuantity = 0;
int maxStackSize = 0;
double pricePerItem = 0D;
public GUIConfirmPurchase(AuctionPlayer auctionPlayer, AuctionItem auctionItem, boolean buyingSpecificQuantity) {
public GUIConfirmPurchase(AuctionPlayer auctionPlayer, AuctionedItem auctionItem, boolean buyingSpecificQuantity) {
this.auctionPlayer = auctionPlayer;
this.auctionItem = auctionItem;
this.buyingSpecificQuantity = buyingSpecificQuantity;
setTitle(TextUtils.formatText(Settings.GUI_CONFIRM_BUY_TITLE.getString()));
setAcceptsItems(false);
int preAmount = AuctionAPI.getInstance().deserializeItem(auctionItem.getRawItem()).getAmount();
int preAmount = auctionItem.getItem().getAmount();
if (preAmount == 1) {
this.buyingSpecificQuantity = false;
}
@ -81,7 +80,7 @@ public class GUIConfirmPurchase extends Gui {
}
private void draw() {
ItemStack deserializeItem = AuctionAPI.getInstance().deserializeItem(this.auctionItem.getRawItem());
ItemStack deserializeItem = this.auctionItem.getItem();
setItems(this.buyingSpecificQuantity ? 9 : 0, this.buyingSpecificQuantity ? 12 : 3, new TItemBuilder(Objects.requireNonNull(Settings.GUI_CONFIRM_BUY_YES_ITEM.getMaterial().parseMaterial())).setName(Settings.GUI_CONFIRM_BUY_YES_NAME.getString()).setLore(Settings.GUI_CONFIRM_BUY_YES_LORE.getStringList()).toItemStack());
setItem(this.buyingSpecificQuantity ? 1 : 0, 4, deserializeItem);
@ -103,9 +102,9 @@ public class GUIConfirmPurchase extends Gui {
// Re-select the item to ensure that it's available
try {
// if the item is in the garbage then just don't continue
if (AuctionHouse.getInstance().getAuctionItemManager().getGarbageBin().containsKey(this.auctionItem.getKey()))
if (AuctionHouse.getInstance().getAuctionItemManager().getGarbageBin().containsKey(this.auctionItem.getId()))
return;
AuctionItem located = AuctionHouse.getInstance().getAuctionItemManager().getItem(this.auctionItem.getKey());
AuctionedItem located = AuctionHouse.getInstance().getAuctionItemManager().getItem(this.auctionItem.getId());
if (located == null || located.isExpired()) {
AuctionHouse.getInstance().getLocale().getMessage("auction.itemnotavailable").sendPrefixedMessage(e.player);
@ -134,11 +133,11 @@ public class GUIConfirmPurchase extends Gui {
}
if (this.buyingSpecificQuantity) {
ItemStack item = AuctionAPI.getInstance().deserializeItem(located.getRawItem());
ItemStack item = auctionItem.getItem();
if (item.getAmount() - this.purchaseQuantity >= 1) {
item.setAmount(item.getAmount() - this.purchaseQuantity);
located.setRawItem(AuctionAPI.getInstance().serializeItem(item));
located.setItem(item);
located.setBasePrice(located.getBasePrice() - buyNowPrice);
item.setAmount(this.purchaseQuantity);
transferFunds(e.player, buyNowPrice);
@ -153,12 +152,12 @@ public class GUIConfirmPurchase extends Gui {
} else {
transferFunds(e.player, buyNowPrice);
AuctionHouse.getInstance().getAuctionItemManager().sendToGarbage(located);
PlayerUtils.giveItem(e.player, AuctionAPI.getInstance().deserializeItem(located.getRawItem()));
PlayerUtils.giveItem(e.player, located.getItem());
sendMessages(e, located, false, 0);
}
AuctionHouse.getInstance().getTransactionManager().getPrePurchasePlayers(auctionItem.getKey()).forEach(player -> {
AuctionHouse.getInstance().getTransactionManager().removeAllRelatedPlayers(auctionItem.getKey());
AuctionHouse.getInstance().getTransactionManager().getPrePurchasePlayers(auctionItem.getId()).forEach(player -> {
AuctionHouse.getInstance().getTransactionManager().removeAllRelatedPlayers(auctionItem.getId());
player.closeInventory();
});
e.gui.close();
@ -193,14 +192,14 @@ public class GUIConfirmPurchase extends Gui {
EconomyManager.deposit(Bukkit.getOfflinePlayer(this.auctionItem.getOwner()), Settings.TAX_CHARGE_SALES_TAX_TO_BUYER.getBoolean() ? amount : amount - tax);
}
private void sendMessages(GuiClickEvent e, AuctionItem located, boolean overwritePrice, double price) {
private void sendMessages(GuiClickEvent e, AuctionedItem located, boolean overwritePrice, double price) {
double totalPrice = overwritePrice ? price : located.getBasePrice();
double tax = Settings.TAX_ENABLED.getBoolean() ? (Settings.TAX_SALES_TAX_BUY_NOW_PERCENTAGE.getDouble() / 100) * totalPrice : 0D;
AuctionHouse.getInstance().getLocale().getMessage("pricing.moneyremove").processPlaceholder("price", AuctionAPI.getInstance().formatNumber(Settings.TAX_CHARGE_SALES_TAX_TO_BUYER.getBoolean() ? totalPrice - tax : totalPrice)).sendPrefixedMessage(e.player);
if (Bukkit.getOfflinePlayer(located.getOwner()).isOnline()) {
AuctionHouse.getInstance().getLocale().getMessage("auction.itemsold")
.processPlaceholder("item", AuctionAPI.getInstance().getItemName(AuctionAPI.getInstance().deserializeItem(this.auctionItem.getRawItem())))
.processPlaceholder("item", AuctionAPI.getInstance().getItemName(this.auctionItem.getItem()))
.processPlaceholder("price", AuctionAPI.getInstance().formatNumber(Settings.TAX_CHARGE_SALES_TAX_TO_BUYER.getBoolean() ? totalPrice : totalPrice - tax))
.processPlaceholder("buyer_name", e.player.getName())
.sendPrefixedMessage(Bukkit.getOfflinePlayer(located.getOwner()).getPlayer());

View File

@ -75,7 +75,7 @@ public class GUITransactionList extends Gui {
put("%seller%", Bukkit.getOfflinePlayer(transaction.getSeller()).getName());
put("%buyer%", Bukkit.getOfflinePlayer(transaction.getBuyer()).getName());
put("%date%", AuctionAPI.getInstance().convertMillisToDate(transaction.getTransactionTime()));
put("%item_name%", AuctionAPI.getInstance().getItemName(AuctionAPI.getInstance().deserializeItem(transaction.getAuctionItem().getRawItem())));
put("%item_name%", AuctionAPI.getInstance().getItemName(transaction.getItem()));
}}), e -> e.manager.showGUI(e.player, new GUITransactionView(this.auctionPlayer, transaction)));
}
}

View File

@ -31,7 +31,7 @@ public class GUITransactionView extends Gui {
setUseLockedCells(Settings.GUI_TRANSACTION_VIEW_BACKGROUND_FILL.getBoolean());
setButton(5, 0, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_CLOSE_BTN_ITEM.getString(), Settings.GUI_CLOSE_BTN_NAME.getString(), Settings.GUI_CLOSE_BTN_LORE.getStringList(), null), e -> e.manager.showGUI(e.player, new GUITransactionList(auctionPlayer)));
setItem(1, 4, AuctionAPI.getInstance().deserializeItem(transaction.getAuctionItem().getRawItem()));
setItem(1, 4, transaction.getItem());
setItem(3, 2, GuiUtils.createButtonItem(AuctionAPI.getInstance().getPlayerHead(Bukkit.getOfflinePlayer(transaction.getSeller()).getName()), TextUtils.formatText(Settings.GUI_TRANSACTION_VIEW_ITEM_SELLER_NAME.getString().replace("%seller_name%", Bukkit.getOfflinePlayer(transaction.getSeller()).getName())),
Settings.GUI_TRANSACTION_VIEW_ITEM_SELLER_LORE.getStringList().stream().map(line -> line.replace("%seller_id%", transaction.getSeller().toString())).map(TextUtils::formatText).collect(Collectors.toList())));

View File

@ -33,7 +33,7 @@ public class AuctionListeners implements Listener {
e.getAuctionItem(),
AuctionSaleType.USED_BIDDING_SYSTEM,
true,
e.getAuctionItem().getBidStartPrice() >= Settings.MIN_AUCTION_START_PRICE.getDouble()
e.getAuctionItem().isBidItem()
);
});
}, 1L);
@ -44,15 +44,25 @@ public class AuctionListeners implements Listener {
public void onAuctionEnd(AuctionEndEvent e) {
Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(AuctionHouse.getInstance(), () -> {
if (Settings.RECORD_TRANSACTIONS.getBoolean()) {
AuctionHouse.getInstance().getTransactionManager().addTransaction(new Transaction(
AuctionHouse.getInstance().getDataManager().insertTransactionAsync(new Transaction(
UUID.randomUUID(),
e.getOriginalOwner().getUniqueId(),
e.getBuyer().getUniqueId(),
e.getAuctionItem().getOwnerName(),
e.getBuyer().getName(),
System.currentTimeMillis(),
e.getAuctionItem(),
e.getSaleType()
));
e.getAuctionItem().getItem(),
e.getSaleType(),
e.getAuctionItem().getCurrentPrice()
), (error, transaction) -> {
if (error == null) {
AuctionHouse.getInstance().getTransactionManager().addTransaction(transaction);
}
});
}
if (Settings.DISCORD_ENABLED.getBoolean() && Settings.DISCORD_ALERT_ON_AUCTION_FINISH.getBoolean()) {
Settings.DISCORD_WEBHOOKS.getStringList().forEach(hook -> AuctionAPI.getInstance().sendDiscordMessage(hook, e.getOriginalOwner(), e.getBuyer(), e.getAuctionItem(), e.getSaleType(), false, e.getSaleType() == AuctionSaleType.USED_BIDDING_SYSTEM));
}

View File

@ -57,7 +57,8 @@ public class PlayerListeners implements Listener {
Player player = e.getPlayer();
ItemStack heldItem = PlayerHelper.getHeldItem(player);
if (heldItem == null || (e.getAction() != Action.RIGHT_CLICK_AIR && e.getAction() != Action.RIGHT_CLICK_BLOCK)) return;
if (heldItem == null || (e.getAction() != Action.RIGHT_CLICK_AIR && e.getAction() != Action.RIGHT_CLICK_BLOCK))
return;
if (heldItem.getType() == XMaterial.AIR.parseMaterial()) return;
if (!NBTEditor.contains(heldItem, "AuctionBundleItem")) return;
e.setCancelled(true);
@ -68,7 +69,6 @@ public class PlayerListeners implements Listener {
items.add(AuctionAPI.getInstance().deserializeItem(NBTEditor.getByteArray(heldItem, "AuctionBundleItem-" + i)));
}
// TODO FIX THE TWEETY CORE TAKE ACTIVE ITEM METHOD, IN THE MEAN TIME DO IT LIKE THIS
if (heldItem.getAmount() >= 2) {
heldItem.setAmount(heldItem.getAmount() - 1);
} else {

View File

@ -51,25 +51,11 @@ public class AuctionBanManager {
return false;
}
public void loadBans(boolean useDatabase) {
if (useDatabase) {
AuctionHouse.getInstance().getDataManager().getBans(all -> all.forEach(this::addBan));
} else {
if (AuctionHouse.getInstance().getData().contains("auction bans") && AuctionHouse.getInstance().getData().isList("auction bans")) {
List<AuctionBan> auctionBans = AuctionHouse.getInstance().getData().getStringList("auction bans").stream().map(AuctionAPI.getInstance()::convertBase64ToObject).map(object -> (AuctionBan) object).collect(Collectors.toList());
long start = System.currentTimeMillis();
auctionBans.forEach(this::addBan);
AuctionHouse.getInstance().getLocale().newMessage(TextUtils.formatText(String.format("&aLoaded &2%d &abans(s) in &e%d&fms", auctionBans.size(), System.currentTimeMillis() - start))).sendPrefixedMessage(Bukkit.getConsoleSender());
}
}
public void loadBans() {
AuctionHouse.getInstance().getDataManager().getBans(all -> all.forEach(this::addBan));
}
public void saveBans(boolean useDatabase, boolean async) {
if (useDatabase) {
AuctionHouse.getInstance().getDataManager().saveBans(new ArrayList<>(getBans().values()), async);
} else {
AuctionHouse.getInstance().getData().set("auction bans", this.bans.values().stream().map(AuctionAPI.getInstance()::convertToBase64).collect(Collectors.toList()));
AuctionHouse.getInstance().getData().save();
}
public void saveBans( boolean async) {
AuctionHouse.getInstance().getDataManager().saveBans(new ArrayList<>(getBans().values()), async);
}
}

View File

@ -1,18 +1,17 @@
package ca.tweetzy.auctionhouse.managers;
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.api.AuctionAPI;
import ca.tweetzy.auctionhouse.auction.AuctionItem;
import ca.tweetzy.core.utils.TextUtils;
import ca.tweetzy.auctionhouse.auction.AuctionedItem;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import lombok.Getter;
import lombok.NonNull;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import java.util.concurrent.TimeUnit;
/**
* The current file has been created by Kiran Hart
@ -23,61 +22,45 @@ import java.util.stream.Collectors;
public class AuctionItemManager {
private final ConcurrentHashMap<UUID, AuctionItem> auctionItems = new ConcurrentHashMap<>();
private final ConcurrentHashMap<UUID, AuctionItem> garbageBin = new ConcurrentHashMap<>();
/*
* If not using usingDynamicLoad, items will be loaded into this map during initialization or when a new item is added
*/
@Getter
private final ConcurrentHashMap<UUID, AuctionedItem> items = new ConcurrentHashMap<>();
public void addItem(AuctionItem auctionItem) {
if (auctionItem == null) return;
this.auctionItems.put(auctionItem.getKey(), auctionItem);
}
@Getter
private final ConcurrentHashMap<AuctionedItem, Long> expiredItems = new ConcurrentHashMap<>();
public void sendToGarbage(AuctionItem auctionItem) {
if (auctionItem == null) return;
this.garbageBin.put(auctionItem.getKey(), auctionItem);
}
/**
* Items that are in the garbage bin are essentially marked for disposal
*/
@Getter
private final ConcurrentHashMap<UUID, AuctionedItem> garbageBin = new ConcurrentHashMap<>();
public void removeUnknownOwnerItems() {
List<UUID> knownOfflinePlayers = Arrays.stream(Bukkit.getOfflinePlayers()).map(OfflinePlayer::getUniqueId).collect(Collectors.toList());
this.auctionItems.keySet().removeIf(id -> !knownOfflinePlayers.contains(id));
}
public AuctionItem getItem(UUID uuid) {
return this.auctionItems.getOrDefault(uuid, null);
}
public ConcurrentHashMap<UUID, AuctionItem> getAuctionItems() {
return this.auctionItems;
}
public ConcurrentHashMap<UUID, AuctionItem> getGarbageBin() {
return this.garbageBin;
}
public void loadItems(boolean useDatabase) {
if (useDatabase) {
AuctionHouse.getInstance().getDataManager().getItems(all -> all.forEach(this::addItem));
} else {
if (AuctionHouse.getInstance().getData().contains("auction items") && AuctionHouse.getInstance().getData().isList("auction items")) {
List<AuctionItem> items = AuctionHouse.getInstance().getData().getStringList("auction items").stream().map(AuctionAPI.getInstance()::convertBase64ToObject).map(object -> (AuctionItem) object).collect(Collectors.toList());
long start = System.currentTimeMillis();
items.forEach(this::addItem);
AuctionHouse.getInstance().getLocale().newMessage(TextUtils.formatText(String.format("&aLoaded &2%d &aauction items(s) in &e%d&fms", items.size(), System.currentTimeMillis() - start))).sendPrefixedMessage(Bukkit.getConsoleSender());
AuctionHouse.getInstance().getData().set("auction items", null);
AuctionHouse.getInstance().getData().save();
public void start() {
// Attempt to convert from old serialization method
AuctionHouse.getInstance().getDataManager().getItems((error, results) -> {
if (error == null) {
for (AuctionedItem item : results) {
addAuctionItem(item);
}
}
}
});
}
public void saveItems(boolean useDatabase, boolean async) {
if (useDatabase) {
AuctionHouse.getInstance().getDataManager().saveItems(new ArrayList<>(this.getAuctionItems().values()), async);
} else {
this.adjustItemsInFile(new ArrayList<>(this.getAuctionItems().values()));
}
public void end() {
AuctionHouse.getInstance().getDataManager().updateItems(this.items.values(), null);
}
public void adjustItemsInFile(List<AuctionItem> items) {
AuctionHouse.getInstance().getData().set("auction items", items.stream().map(AuctionAPI.getInstance()::convertToBase64).collect(Collectors.toList()));
AuctionHouse.getInstance().getData().save();
public void addAuctionItem(@NonNull AuctionedItem auctionedItem) {
this.items.put(auctionedItem.getId(), auctionedItem);
}
public void sendToGarbage(@NonNull AuctionedItem auctionedItem) {
this.garbageBin.put(auctionedItem.getId(), auctionedItem);
}
public AuctionedItem getItem(@NonNull UUID id) {
return this.items.getOrDefault(id, null);
}
}

View File

@ -44,31 +44,11 @@ public class FilterManager {
return this.filterWhitelist.stream().filter(item -> item.getCategory() == category).map(item -> AuctionAPI.getInstance().deserializeItem(item.getRawItem())).collect(Collectors.toList());
}
public void loadItems(boolean useDatabase) {
if (useDatabase) {
AuctionHouse.getInstance().getDataManager().getFilterWhitelist(all -> all.forEach(this::addFilterItem));
} else {
if (AuctionHouse.getInstance().getData().contains("auction filter whitelist") && AuctionHouse.getInstance().getData().isList("auction filter whitelist")) {
List<AuctionFilterItem> items = AuctionHouse.getInstance().getData().getStringList("auction filter whitelist").stream().map(AuctionAPI.getInstance()::convertBase64ToObject).map(object -> (AuctionFilterItem) object).collect(Collectors.toList());
long start = System.currentTimeMillis();
items.forEach(this::addFilterItem);
AuctionHouse.getInstance().getLocale().newMessage(TextUtils.formatText(String.format("&aLoaded &2%d &aauction filter items(s) in &e%d&fms", items.size(), System.currentTimeMillis() - start))).sendPrefixedMessage(Bukkit.getConsoleSender());
AuctionHouse.getInstance().getData().set("auction filter whitelist", null);
AuctionHouse.getInstance().getData().save();
}
}
public void loadItems() {
AuctionHouse.getInstance().getDataManager().getFilterWhitelist(all -> all.forEach(this::addFilterItem));
}
public void saveFilterWhitelist(boolean useDatabase, boolean async) {
if (useDatabase) {
AuctionHouse.getInstance().getDataManager().saveFilterWhitelist(getFilterWhitelist(), async);
} else {
this.adjustItemsInFile(this.getFilterWhitelist());
}
}
public void adjustItemsInFile(List<AuctionFilterItem> items) {
AuctionHouse.getInstance().getData().set("auction filter whitelist", items.stream().map(AuctionAPI.getInstance()::convertToBase64).collect(Collectors.toList()));
AuctionHouse.getInstance().getData().save();
public void saveFilterWhitelist(boolean async) {
AuctionHouse.getInstance().getDataManager().saveFilterWhitelist(getFilterWhitelist(), async);
}
}

View File

@ -1,10 +1,7 @@
package ca.tweetzy.auctionhouse.managers;
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.api.AuctionAPI;
import ca.tweetzy.auctionhouse.transaction.Transaction;
import ca.tweetzy.core.utils.TextUtils;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.util.*;
@ -79,25 +76,13 @@ public class TransactionManager {
return this.prePurchaseHolding.keySet().stream().filter(p -> this.prePurchaseHolding.get(p).equals(uuid)).collect(Collectors.toList());
}
public void loadTransactions(boolean useDatabase) {
if (useDatabase) {
AuctionHouse.getInstance().getDataManager().getTransactions(all -> all.forEach(this::addTransaction));
} else {
if (AuctionHouse.getInstance().getData().contains("transactions") && AuctionHouse.getInstance().getData().isList("transactions")) {
List<Transaction> transactions = AuctionHouse.getInstance().getData().getStringList("transactions").stream().map(AuctionAPI.getInstance()::convertBase64ToObject).map(object -> (Transaction) object).collect(Collectors.toList());
long start = System.currentTimeMillis();
transactions.forEach(this::addTransaction);
AuctionHouse.getInstance().getLocale().newMessage(TextUtils.formatText(String.format("&aLoaded &2%d &atransaction(s) in &e%d&fms", transactions.size(), System.currentTimeMillis() - start))).sendPrefixedMessage(Bukkit.getConsoleSender());
public void loadTransactions() {
AuctionHouse.getInstance().getDataManager().getTransactions((error, results) -> {
if (error == null) {
for (Transaction transaction : results) {
addTransaction(transaction);
}
}
}
}
public void saveTransactions(boolean useDatabase, boolean async) {
if (useDatabase) {
AuctionHouse.getInstance().getDataManager().saveTransactions(new ArrayList<>(getTransactions().values()), async);
} else {
AuctionHouse.getInstance().getData().set("transactions", this.transactions.values().stream().map(AuctionAPI.getInstance()::convertToBase64).collect(Collectors.toList()));
AuctionHouse.getInstance().getData().save();
}
});
}
}

View File

@ -40,6 +40,9 @@ public class LocaleSettings {
languageNodes.put("general.addeditemtofilterwhitelist", "&aAdded &2%item_name%&a to the &2%filter_category%&a's whitelist");
languageNodes.put("general.finishenteringprice", "&cPlease finish entering the new price first.");
languageNodes.put("general.invalidtimestring", "&cInvalid time, use the following format, ex: 1d (valid suffixes: s,m,h,d,y)");
languageNodes.put("general.something_went_wrong_while_listing", "&cSomething went wrong while listing item.");
languageNodes.put("general.toggled listing.on", "&aYou turned on listing messages");
languageNodes.put("general.toggled listing.off", "&cYou turned off listing messages");
languageNodes.put("pricing.minbaseprice", "&cThe minimum base price must be &a$%price%");
@ -55,6 +58,7 @@ public class LocaleSettings {
languageNodes.put("prompts.enter new buy now price", "&aPlease enter the new buy now price in chat:");
languageNodes.put("prompts.enter new starting bid", "&aPlease enter the new starting bid in chat:");
languageNodes.put("prompts.enter new bid increment", "&aPlease enter the new bid increment in chat:");
languageNodes.put("prompts.enter bid amount", "&aPlease enter bid amount in chat:");
languageNodes.put("transaction.sale_type.bid_won", "Won Auction");
languageNodes.put("transaction.sale_type.immediate_buy", "Bought Immediately");
@ -105,8 +109,9 @@ public class LocaleSettings {
languageNodes.put("auction.itemsold", "&eYou sold &6%item% &eto &6%buyer_name% &efor &a%price%");
languageNodes.put("auction.itemnotavailable", "&cThat item is no longer available :(");
languageNodes.put("auction.biditemwithdisabledbuynow", "&CN/A");
languageNodes.put("auction.outbid", "&6%player &ehas out bid you for &6%item%");
languageNodes.put("auction.placedbid", "&6%player &eincreased the bid to &a$%amount% &eon &6%item%");
languageNodes.put("auction.outbid", "&6%player% &ehas out bid you for &6%item%");
languageNodes.put("auction.placedbid", "&6%player% &eincreased the bid to &a$%amount% &eon &6%item%");
languageNodes.put("auction.nobids", "&cNo Bids");
languageNodes.put("auction.tax.cannotpaylistingfee", "&cYou do not have enough money to pay the listing fee &f(&4$%price%&f)");
languageNodes.put("auction.tax.paidlistingfee", "&aPaid &2$%price%&a listing fee");
@ -128,6 +133,7 @@ public class LocaleSettings {
languageNodes.put("commands.syntax.filter", "filter [additem] [category]");
languageNodes.put("commands.syntax.ban", "ban [player] [time] [reason]");
languageNodes.put("commands.syntax.unban", "ban <player>");
languageNodes.put("commands.syntax.togglelistinfo", "togglelistinfo");
languageNodes.put("commands.description.active", "View all your auction listings");
languageNodes.put("commands.description.auctionhouse", "Main command for the plugin, it opens the auction window.");
@ -142,6 +148,7 @@ public class LocaleSettings {
languageNodes.put("commands.description.filter", "Edit the filter whitelist items");
languageNodes.put("commands.description.ban", "Ban a player from the auction house for a set amount of time.");
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");
}
public static void setup() {

View File

@ -42,9 +42,10 @@ public class Settings {
public static final ConfigSetting USE_SHORT_NUMBERS_ON_ITEMS = new ConfigSetting(config, "auction setting.use short numbers", false, "Should numbers be shortened into a prefixed form?");
public static final ConfigSetting INCREASE_TIME_ON_BID = new ConfigSetting(config, "auction setting.increase time on bid", true, "Should the remaining time be increased when a bid is placed?");
public static final ConfigSetting TIME_TO_INCREASE_BY_ON_BID = new ConfigSetting(config, "auction setting.time to increase by on the bid", 20, "How many seconds should be added to the remaining time?");
public static final ConfigSetting TICK_UPDATE_TIME = new ConfigSetting(config, "auction setting.tick auctions every", 1, "How many seconds should pass before the plugin updates all the times on items?");
public static final ConfigSetting TICK_UPDATE_GUI_TIME = new ConfigSetting(config, "auction setting.refresh gui every", 10, "How many seconds should pass before the auction gui auto refreshes?");
public static final ConfigSetting REFRESH_GUI_WHEN_BID = new ConfigSetting(config, "auction setting.refresh gui when bid", true, "Should the auction gui be re-opened (not redrawn) when a user places a bid, so they get the latest items?");
public static final ConfigSetting RECORD_TRANSACTIONS = new ConfigSetting(config, "auction setting.record transactions", true, "Should every transaction be recorded (everything an auction is won or an item is bought)");
public static final ConfigSetting BROADCAST_AUCTION_LIST = new ConfigSetting(config, "auction setting.broadcast auction list", false, "Should the entire server be alerted when a player lists an item?");
@ -65,6 +66,7 @@ public class Settings {
public static final ConfigSetting REPLACE_HOW_TO_SELL_WITH_LIST_BUTTON = new ConfigSetting(config, "auction setting.replace how to sell with list button", false, "This will replace the \"How to Sell\" button with a List Item button");
public static final ConfigSetting ALLOW_USAGE_OF_SELL_GUI = new ConfigSetting(config, "auction setting.allow usage of sell gui", true, "Should the sell menu be enabled?");
public static final ConfigSetting FORCE_AUCTION_USAGE = new ConfigSetting(config, "auction setting.force auction usage", false, "If enabled, all items sold on the auction house must be an auction (biddable) items");
public static final ConfigSetting ALLOW_INDIVIDUAL_ITEM_CLAIM = new ConfigSetting(config, "auction setting.allow individual item claim", true, "If enabled, you will be able to click individual items from the expiration menu to claim them back. Otherwise you will have to use the claim all button");
public static final ConfigSetting ASK_FOR_CANCEL_CONFIRM_ON_BID_ITEMS = new ConfigSetting(config, "auction setting.ask for cancel confirm on bid items", true, "Should Auction House ask the user if they want to cancel the item?");
public static final ConfigSetting ASK_FOR_CANCEL_CONFIRM_ON_NON_BID_ITEMS = new ConfigSetting(config, "auction setting.ask for cancel confirm on non bid items", false, "Should Auction House ask the user if they want to cancel the item?");
@ -183,6 +185,7 @@ public class Settings {
public static final ConfigSetting DATABASE_PASSWORD = new ConfigSetting(config, "database.password", "Password1.", "What is the password to the user connecting?");
public static final ConfigSetting DATABASE_USE_SSL = new ConfigSetting(config, "database.use ssl", true, "Should the database connection use ssl?");
/* ===============================
* DISCORD WEBHOOK
* ===============================*/
@ -254,6 +257,7 @@ public class Settings {
/* ===============================
* GLOBAL ITEMS
* ===============================*/
public static final ConfigSetting GUI_BACK_BTN_SLOT = new ConfigSetting(config, "gui.global items.back button.slot", 48, "Valid Slots: 45 - 53");
public static final ConfigSetting GUI_BACK_BTN_ITEM = new ConfigSetting(config, "gui.global items.back button.item", "ARROW", "Settings for the back button");
public static final ConfigSetting GUI_BACK_BTN_NAME = new ConfigSetting(config, "gui.global items.back button.name", "&e<< Back");
public static final ConfigSetting GUI_BACK_BTN_LORE = new ConfigSetting(config, "gui.global items.back button.lore", Arrays.asList("&7Click the button to go", "&7back to the previous page."));
@ -262,10 +266,13 @@ public class Settings {
public static final ConfigSetting GUI_CLOSE_BTN_NAME = new ConfigSetting(config, "gui.global items.close button.name", "&cClose");
public static final ConfigSetting GUI_CLOSE_BTN_LORE = new ConfigSetting(config, "gui.global items.close button.lore", Collections.singletonList("&7Click to close this menu."));
public static final ConfigSetting GUI_NEXT_BTN_SLOT = new ConfigSetting(config, "gui.global items.next button.slot", 50, "Valid Slots: 45 - 53");
public static final ConfigSetting GUI_NEXT_BTN_ITEM = new ConfigSetting(config, "gui.global items.next button.item", "ARROW", "Settings for the next button");
public static final ConfigSetting GUI_NEXT_BTN_NAME = new ConfigSetting(config, "gui.global items.next button.name", "&eNext >>");
public static final ConfigSetting GUI_NEXT_BTN_LORE = new ConfigSetting(config, "gui.global items.next button.lore", Arrays.asList("&7Click the button to go", "&7to the next page."));
public static final ConfigSetting GUI_REFRESH_BTN_ENABLED = new ConfigSetting(config, "gui.global items.refresh button.enabled", true);
public static final ConfigSetting GUI_REFRESH_BTN_SLOT = new ConfigSetting(config, "gui.global items.refresh button.slot", 49, "Valid Slots: 45 - 53");
public static final ConfigSetting GUI_REFRESH_BTN_ITEM = new ConfigSetting(config, "gui.global items.refresh button.item", "CHEST", "Settings for the refresh page");
public static final ConfigSetting GUI_REFRESH_BTN_NAME = new ConfigSetting(config, "gui.global items.refresh button.name", "&6&LRefresh Page");
public static final ConfigSetting GUI_REFRESH_BTN_LORE = new ConfigSetting(config, "gui.global items.refresh button.lore", Arrays.asList("&7Click to refresh the currently", "&7available auction listings."));
@ -276,6 +283,8 @@ public class Settings {
* ===============================*/
public static final ConfigSetting GUI_AUCTION_HOUSE_TITLE = new ConfigSetting(config, "gui.auction house.title", "&7Auction House");
public static final ConfigSetting GUI_AUCTION_HOUSE_ITEMS_GUIDE_ENABLED = new ConfigSetting(config, "gui.auction house.items.guide.enabled", true);
public static final ConfigSetting GUI_AUCTION_HOUSE_ITEMS_GUIDE_SLOT = new ConfigSetting(config, "gui.auction house.items.guide.slot", 53, "Valid Slots: 45 - 53");
public static final ConfigSetting GUI_AUCTION_HOUSE_ITEMS_GUIDE_ITEM = new ConfigSetting(config, "gui.auction house.items.guide.item", "BOOK");
public static final ConfigSetting GUI_AUCTION_HOUSE_ITEMS_GUIDE_NAME = new ConfigSetting(config, "gui.auction house.items.guide.name", "&e&lGuide");
public static final ConfigSetting GUI_AUCTION_HOUSE_ITEMS_GUIDE_LORE = new ConfigSetting(config, "gui.auction house.items.guide.lore", Arrays.asList(
@ -294,6 +303,8 @@ public class Settings {
"&7purchase it right away with a set price."
));
public static final ConfigSetting GUI_AUCTION_HOUSE_ITEMS_TRANSACTIONS_ENABLED = new ConfigSetting(config, "gui.auction house.items.transactions.enabled", true);
public static final ConfigSetting GUI_AUCTION_HOUSE_ITEMS_TRANSACTIONS_SLOT = new ConfigSetting(config, "gui.auction house.items.transactions.slot", 51, "Valid Slots: 45 - 53");
public static final ConfigSetting GUI_AUCTION_HOUSE_ITEMS_TRANSACTIONS_ITEM = new ConfigSetting(config, "gui.auction house.items.transactions.item", "PAPER");
public static final ConfigSetting GUI_AUCTION_HOUSE_ITEMS_TRANSACTIONS_NAME = new ConfigSetting(config, "gui.auction house.items.transactions.name", "&e&lTransactions");
public static final ConfigSetting GUI_AUCTION_HOUSE_ITEMS_TRANSACTIONS_LORE = new ConfigSetting(config, "gui.auction house.items.transactions.lore", Arrays.asList(
@ -303,6 +314,8 @@ public class Settings {
"&eTotal Items Sold&f: &a%total_items_sold%"
));
public static final ConfigSetting GUI_AUCTION_HOUSE_ITEMS_HOW_TO_SELL_ENABLED = new ConfigSetting(config, "gui.auction house.items.how to sell.enabled", true);
public static final ConfigSetting GUI_AUCTION_HOUSE_ITEMS_HOW_TO_SELL_SLOT = new ConfigSetting(config, "gui.auction house.items.how to sell.slot", 52, "Valid Slots: 45 - 53");
public static final ConfigSetting GUI_AUCTION_HOUSE_ITEMS_HOW_TO_SELL_ITEM = new ConfigSetting(config, "gui.auction house.items.how to sell.item", "GOLD_INGOT");
public static final ConfigSetting GUI_AUCTION_HOUSE_ITEMS_HOW_TO_SELL_NAME = new ConfigSetting(config, "gui.auction house.items.how to sell.name", "&e&lHow to Sell");
public static final ConfigSetting GUI_AUCTION_HOUSE_ITEMS_HOW_TO_SELL_LORE = new ConfigSetting(config, "gui.auction house.items.how to sell.lore", Arrays.asList(
@ -311,10 +324,14 @@ public class Settings {
"&e/ah sell <buyNowPrice> [startPrice] [bidIncrement]"
));
public static final ConfigSetting GUI_AUCTION_HOUSE_ITEMS_LIST_ITEM_ENABLED = new ConfigSetting(config, "gui.auction house.items.list new item.enabled", true);
public static final ConfigSetting GUI_AUCTION_HOUSE_ITEMS_LIST_ITEM_SLOT = new ConfigSetting(config, "gui.auction house.items.list new item.slot", 52, "Valid Slots: 45 - 53");
public static final ConfigSetting GUI_AUCTION_HOUSE_ITEMS_LIST_ITEM_ITEM = new ConfigSetting(config, "gui.auction house.items.list new item.item", "CLOCK");
public static final ConfigSetting GUI_AUCTION_HOUSE_ITEMS_LIST_ITEM_NAME = new ConfigSetting(config, "gui.auction house.items.list new item.name", "&e&lList Item");
public static final ConfigSetting GUI_AUCTION_HOUSE_ITEMS_LIST_ITEM_LORE = new ConfigSetting(config, "gui.auction house.items.list new item.lore", Collections.singletonList("&7Click to list an item on the auction house."));
public static final ConfigSetting GUI_AUCTION_HOUSE_ITEMS_YOUR_AUCTIONS_ENABLED = new ConfigSetting(config, "gui.auction house.items.your auctions.enabled", true);
public static final ConfigSetting GUI_AUCTION_HOUSE_ITEMS_YOUR_AUCTIONS_SLOT = new ConfigSetting(config, "gui.auction house.items.your auctions.slot", 45, "Valid Slots: 45 - 53");
public static final ConfigSetting GUI_AUCTION_HOUSE_ITEMS_YOUR_AUCTIONS_ITEM = new ConfigSetting(config, "gui.auction house.items.your auctions.item", "DIAMOND");
public static final ConfigSetting GUI_AUCTION_HOUSE_ITEMS_YOUR_AUCTIONS_NAME = new ConfigSetting(config, "gui.auction house.items.your auctions.name", "&e&lYour Auctions");
public static final ConfigSetting GUI_AUCTION_HOUSE_ITEMS_YOUR_AUCTIONS_LORE = new ConfigSetting(config, "gui.auction house.items.your auctions.lore", Arrays.asList(
@ -325,6 +342,8 @@ public class Settings {
"&e&lBalance &a$%player_balance%"
));
public static final ConfigSetting GUI_AUCTION_HOUSE_ITEMS_COLLECTION_BIN_ENABLED = new ConfigSetting(config, "gui.auction house.items.collection bin.enabled", true);
public static final ConfigSetting GUI_AUCTION_HOUSE_ITEMS_COLLECTION_BIN_SLOT = new ConfigSetting(config, "gui.auction house.items.collection bind.slot", 46, "Valid Slots: 45 - 53");
public static final ConfigSetting GUI_AUCTION_HOUSE_ITEMS_COLLECTION_BIN_ITEM = new ConfigSetting(config, "gui.auction house.items.collection bin.item", "ENDER_CHEST");
public static final ConfigSetting GUI_AUCTION_HOUSE_ITEMS_COLLECTION_BIN_NAME = new ConfigSetting(config, "gui.auction house.items.collection bin.name", "&e&lCollection Bin");
public static final ConfigSetting GUI_AUCTION_HOUSE_ITEMS_COLLECTION_BIN_LORE = new ConfigSetting(config, "gui.auction house.items.collection bin.lore", Arrays.asList(
@ -334,6 +353,8 @@ public class Settings {
"&e&l%expired_player_auctions% Item(s)"
));
public static final ConfigSetting GUI_AUCTION_HOUSE_ITEMS_FILTER_ENABLED = new ConfigSetting(config, "gui.auction house.items.filter.enabled", true);
public static final ConfigSetting GUI_AUCTION_HOUSE_ITEMS_FILTER_SLOT = new ConfigSetting(config, "gui.auction house.items.filter.slot", 47, "Valid Slots: 45 - 53");
public static final ConfigSetting GUI_AUCTION_HOUSE_ITEMS_FILTER_ITEM = new ConfigSetting(config, "gui.auction house.items.filter.item", "NETHER_STAR");
public static final ConfigSetting GUI_AUCTION_HOUSE_ITEMS_FILTER_NAME = new ConfigSetting(config, "gui.auction house.items.filter.name", "&e&lFilter Options");
public static final ConfigSetting GUI_AUCTION_HOUSE_ITEMS_FILTER_LORE = new ConfigSetting(config, "gui.auction house.items.filter.lore", Arrays.asList(
@ -347,6 +368,8 @@ public class Settings {
"&7Middle-Click to reset filters"
));
public static final ConfigSetting GUI_AUCTION_HOUSE_ITEMS_FILTER_MENU_ENABLED = new ConfigSetting(config, "gui.auction house.items.filter menu.enabled", true);
public static final ConfigSetting GUI_AUCTION_HOUSE_ITEMS_FILTER_MENU_SLOT = new ConfigSetting(config, "gui.auction house.items.filter menu.slot", 47, "Valid Slots: 45 - 53");
public static final ConfigSetting GUI_AUCTION_HOUSE_ITEMS_FILTER_MENU_ITEM = new ConfigSetting(config, "gui.auction house.items.filter menu.item", "HOPPER");
public static final ConfigSetting GUI_AUCTION_HOUSE_ITEMS_FILTER_MENU_NAME = new ConfigSetting(config, "gui.auction house.items.filter menu.name", "&e&lCurrent Filter&f: &6%filter_category%");
public static final ConfigSetting GUI_AUCTION_HOUSE_ITEMS_FILTER_MENU_LORE = new ConfigSetting(config, "gui.auction house.items.filter menu.lore", Arrays.asList(
@ -685,64 +708,73 @@ public class Settings {
public static final ConfigSetting GUI_ITEM_ADMIN_ITEMS_DELETE_NAME = new ConfigSetting(config, "gui.item admin.items.delete item.name", "&a&lDelete Item");
public static final ConfigSetting GUI_ITEM_ADMIN_ITEMS_DELETE_LORE = new ConfigSetting(config, "gui.item admin.items.delete item.lore", Collections.singletonList("&7Click to delete this item"));
/* ===============================
* BIDDING GUI
* ===============================*/
public static final ConfigSetting GUI_BIDDING_TITLE = new ConfigSetting(config, "gui.bidding.title", "&7Auction House - &eBidding");
public static final ConfigSetting GUI_BIDDING_BG_ITEM = new ConfigSetting(config, "gui.bidding.bg item", XMaterial.BLACK_STAINED_GLASS_PANE.name());
public static final ConfigSetting GUI_BIDDING_ITEMS_DEFAULT_ITEM = new ConfigSetting(config, "gui.bidding.items.default amount.item", XMaterial.SUNFLOWER.name());
public static final ConfigSetting GUI_BIDDING_ITEMS_DEFAULT_NAME = new ConfigSetting(config, "gui.bidding.items.default amount.name", "&a&LDefault Amount");
public static final ConfigSetting GUI_BIDDING_ITEMS_DEFAULT_LORE = new ConfigSetting(config, "gui.bidding.items.default amount.lore", Collections.singletonList("&7Click to bid default amount"));
public static final ConfigSetting GUI_BIDDING_ITEMS_CUSTOM_ITEM = new ConfigSetting(config, "gui.bidding.items.custom amount.item", XMaterial.OAK_SIGN.name());
public static final ConfigSetting GUI_BIDDING_ITEMS_CUSTOM_NAME = new ConfigSetting(config, "gui.bidding.items.custom amount.name", "&a&lCustom Amount");
public static final ConfigSetting GUI_BIDDING_ITEMS_CUSTOM_LORE = new ConfigSetting(config, "gui.bidding.items.custom amount.lore", Collections.singletonList("&7Click to bid a custom amount"));
/* ===============================
* AUCTION STACKS
* ===============================*/
public static final ConfigSetting AUCTION_ITEM_AUCTION_STACK = new ConfigSetting(config, "auction items.auction stack", Arrays.asList(
"&7-------------------------",
public static final ConfigSetting AUCTION_STACK_DETAILS_HEADER = new ConfigSetting(config, "auction stack.header", Collections.singletonList("&7&m-------------------------"));
public static final ConfigSetting AUCTION_STACK_DETAILS_SELLER = new ConfigSetting(config, "auction stack.seller lines", Arrays.asList(
"&eSeller&f: &b%seller%",
"",
""
));
public static final ConfigSetting AUCTION_STACK_DETAILS_BUY_NOW = new ConfigSetting(config, "auction stack.buy now lines", Arrays.asList(
"&eBuy Now: &a$%buynowprice%",
""
));
public static final ConfigSetting AUCTION_STACK_DETAILS_CURRENT_PRICE = new ConfigSetting(config, "auction stack.current price lines", Collections.singletonList(
"&eCurrent Price: &a$%currentprice%"
));
public static final ConfigSetting AUCTION_STACK_DETAILS_BID_INCREMENT = new ConfigSetting(config, "auction stack.bid increment lines", Collections.singletonList(
"&eBid Increment: &a$%bidincrement%"
));
public static final ConfigSetting AUCTION_STACK_DETAILS_HIGHEST_BIDDER = new ConfigSetting(config, "auction stack.highest bidder lines", Collections.singletonList(
"&eHighest Bidder: &a%highestbidder%"
));
public static final ConfigSetting AUCTION_STACK_DETAILS_TIME_LEFT = new ConfigSetting(config, "auction stack.time left lines", Arrays.asList(
"",
"&eTime Left: &b%remaining_days%&fd &b%remaining_hours%&fh &b%remaining_minutes%&fm &b%remaining_seconds%s"
), "This the item stack lore that will be appended to", "auction items in /ah (lore will be applied first, then these)");
));
public static final ConfigSetting AUCTION_ITEM_LISTING_STACK = new ConfigSetting(config, "auction items.listing stack", Arrays.asList(
"&7-------------------------",
"&eBuy Now: &a$%buynowprice%",
"&eTime Left: &b%remaining_days%&fd &b%remaining_hours%&fh &b%remaining_minutes%&fm &b%remaining_seconds%s"
), "This the item stack lore that will be appended to", "auction items in /ah listings (lore will be applied first, then these)");
public static final ConfigSetting AUCTION_STACK_PURCHASE_CONTROL_HEADER = new ConfigSetting(config, "auction stack.controls.header", Collections.singletonList("&7&m-------------------------"));
public static final ConfigSetting AUCTION_STACK_PURCHASE_CONTROL_FOOTER = new ConfigSetting(config, "auction stack.controls.footer", Collections.singletonList("&7&m-------------------------"));
public static final ConfigSetting AUCTION_STACK_PURCHASE_CONTROLS_INSPECTION = new ConfigSetting(config, "auction stack.controls.inspection", Collections.singletonList("&eShift Right-Click to inspect"), "This will only be added to the control lore if the item can be inspected (skulker box/bundled item)");
public static final ConfigSetting AUCTION_STACK_PURCHASE_CONTROLS_ACCEPT_BID = new ConfigSetting(config, "auction stack.controls.accept bid", Collections.singletonList("&eRight-Click to accept the current bid"), "This will only show on items within the active listings menu on biddable items.");
public static final ConfigSetting AUCTION_STACK_PURCHASE_CONTROLS_CANCEL_ITEM = new ConfigSetting(config, "auction stack.controls.cancel item", Collections.singletonList("&eLeft-Click to cancel this listing"));
public static final ConfigSetting AUCTION_ITEM_AUCTION_STACK_WITH_BID = new ConfigSetting(config, "auction items.auction stack with bid", Arrays.asList(
"&7-------------------------",
"&eSeller&f: &b%seller%",
"",
"&eBuy Now: &a$%buynowprice%",
"&eCurrent Price: &a$%currentprice%",
"&eBid Increment: &a$%bidincrement%",
"&eHighest Bidder: &a%highestbidder%",
"",
"&eTime Left: &b%remaining_days%&fd &b%remaining_hours%&fh &b%remaining_minutes%&fm &b%remaining_seconds%s"
), "This the item stack lore that will be appended to", "auction items in /ah (lore will be applied first, then these)");
public static final ConfigSetting AUCTION_ITEM_LISTING_STACK_WITH_BID = new ConfigSetting(config, "auction items.listing stack with bid", Arrays.asList(
"&7-------------------------",
"&eBuy Now: &a$%buynowprice%",
"&eCurrent Price: &a$%currentprice%",
"&eBid Increment: &a$%bidincrement%",
"&eHighest Bidder: &a%highestbidder%",
"&eTime Left: &b%remaining_days%&fd &b%remaining_hours%&fh &b%remaining_minutes%&fm &b%remaining_seconds%s"
), "This the item stack lore that will be appended to", "auction items in /ah listings (lore will be applied first, then these)");
public static final ConfigSetting AUCTION_PURCHASE_CONTROL_HEADER = new ConfigSetting(config, "auction items.controls.header", Collections.singletonList("&7-------------------------"));
public static final ConfigSetting AUCTION_PURCHASE_CONTROL_FOOTER = new ConfigSetting(config, "auction items.controls.footer", Collections.singletonList("&7-------------------------"));
public static final ConfigSetting AUCTION_PURCHASE_CONTROLS_BID_ON = new ConfigSetting(config, "auction items.controls.using bid", Arrays.asList(
public static final ConfigSetting AUCTION_STACK_PURCHASE_CONTROLS_BID_ON = new ConfigSetting(config, "auction stack.controls.using bid", Arrays.asList(
"&eLeft-Click&f: &bBid",
"&eRight-Click&f: &bBuy Now"
), "This will be appended at the end of the lore", "If the auction item is using a bid, this will show");
public static final ConfigSetting AUCTION_PURCHASE_CONTROLS_BID_OFF = new ConfigSetting(config, "auction items.controls.not using bid", Collections.singletonList(
public static final ConfigSetting AUCTION_STACK_PURCHASE_CONTROLS_BID_ON_NO_BUY_NOW = new ConfigSetting(config, "auction stack.controls.using bid without buy now", Collections.singletonList(
"&eLeft-Click&f: &bBid"
), "This will be appended at the end of the lore", "If the auction item is using a bid, this will show");
public static final ConfigSetting AUCTION_STACK_PURCHASE_CONTROLS_BID_OFF = new ConfigSetting(config, "auction stack.controls.not using bid", Collections.singletonList(
"&eLeft-Click&f: &bBuy Now"
), "This will be appended at the end of the lore", "If the auction item is not using a bid, this will show");
public static final ConfigSetting AUCTION_PURCHASE_CONTROLS_INSPECTION = new ConfigSetting(config, "auction items.controls.inspection", Collections.singletonList("&eShift Right-Click to inspect"), "This will only be added to the control lore if the item can be inspected (skulker box/bundled item)");
public static final ConfigSetting AUCTION_PURCHASE_CONTROLS_ACCEPT_BID = new ConfigSetting(config, "auction items.controls.accept bid", Collections.singletonList("&eRight-Click to accept the current bid"), "This will only show on items within the active listings menu on biddable items.");
public static final ConfigSetting AUCTION_PURCHASE_CONTROLS_BUY_NOW_OFF_FOR_BID = new ConfigSetting(config, "auction items.controls.buy now is off for bid", "&cN/A", "If they player sets the buy now price to -1 on a bid item, it will mean make the item", "a bid item, but users will not be able to use the buy now option on the item.");
/* ===============================
* AUCTION STACKS
* AUCTION SOUNDS
* ===============================*/
public static final ConfigSetting SOUNDS_LISTED_ITEM_ON_AUCTION_HOUSE = new ConfigSetting(config, "sounds.listed item on the auction house", XSound.ENTITY_EXPERIENCE_ORB_PICKUP.parseSound().name());
public static final ConfigSetting SOUNDS_NAVIGATE_GUI_PAGES = new ConfigSetting(config, "sounds.navigated between gui pages", XSound.ENTITY_BAT_TAKEOFF.parseSound().name());

View File

@ -26,9 +26,8 @@ public class AutoSaveTask extends BukkitRunnable {
@Override
public void run() {
AuctionHouse.getInstance().getAuctionItemManager().saveItems(Settings.DATABASE_USE.getBoolean(), true);
AuctionHouse.getInstance().getTransactionManager().saveTransactions(Settings.DATABASE_USE.getBoolean(), true);
AuctionHouse.getInstance().getFilterManager().saveFilterWhitelist(Settings.DATABASE_USE.getBoolean(), true);
AuctionHouse.getInstance().getDataManager().updateItems(AuctionHouse.getInstance().getAuctionItemManager().getItems().values(), null);
AuctionHouse.getInstance().getFilterManager().saveFilterWhitelist(true);
AuctionHouse.getInstance().getLocale().newMessage(TextUtils.formatText("&aAuto saved auction items & transactions")).sendPrefixedMessage(Bukkit.getConsoleSender());
}
}

View File

@ -3,21 +3,18 @@ package ca.tweetzy.auctionhouse.tasks;
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.api.AuctionAPI;
import ca.tweetzy.auctionhouse.api.events.AuctionEndEvent;
import ca.tweetzy.auctionhouse.auction.AuctionItem;
import ca.tweetzy.auctionhouse.auction.AuctionSaleType;
import ca.tweetzy.auctionhouse.auction.AuctionedItem;
import ca.tweetzy.auctionhouse.settings.Settings;
import ca.tweetzy.core.hooks.EconomyManager;
import ca.tweetzy.core.utils.PlayerUtils;
import org.apache.commons.lang.WordUtils;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.*;
import java.util.stream.Collectors;
/**
* The current file has been created by Kiran Hart
@ -32,7 +29,6 @@ public class TickAuctionsTask extends BukkitRunnable {
public static TickAuctionsTask startTask() {
if (instance == null) {
instance = new TickAuctionsTask();
// maybe to async
instance.runTaskTimerAsynchronously(AuctionHouse.getInstance(), 0, (long) 20 * Settings.TICK_UPDATE_TIME.getInt());
}
return instance;
@ -41,33 +37,38 @@ public class TickAuctionsTask extends BukkitRunnable {
@Override
public void run() {
Set<Map.Entry<UUID, AuctionItem>> entrySet = AuctionHouse.getInstance().getAuctionItemManager().getAuctionItems().entrySet();
Iterator<Map.Entry<UUID, AuctionItem>> auctionItemIterator = entrySet.iterator();
Set<Map.Entry<UUID, AuctionedItem>> entrySet = AuctionHouse.getInstance().getAuctionItemManager().getItems().entrySet();
Iterator<Map.Entry<UUID, AuctionedItem>> auctionItemIterator = entrySet.iterator();
while (auctionItemIterator.hasNext()) {
Map.Entry<UUID, AuctionItem> entry = auctionItemIterator.next();
AuctionItem auctionItem = entry.getValue();
ItemStack itemStack = AuctionAPI.getInstance().deserializeItem(auctionItem.getRawItem());
Map.Entry<UUID, AuctionedItem> entry = auctionItemIterator.next();
AuctionedItem auctionItem = entry.getValue();
ItemStack itemStack = auctionItem.getItem();
if (AuctionHouse.getInstance().getAuctionItemManager().getGarbageBin().containsKey(auctionItem.getKey())) {
AuctionHouse.getInstance().getAuctionItemManager().getGarbageBin().remove(auctionItem.getKey());
if (!AuctionHouse.getInstance().getAuctionItemManager().getGarbageBin().keySet().isEmpty()) {
AuctionHouse.getInstance().getDataManager().deleteItems(AuctionHouse.getInstance().getAuctionItemManager().getGarbageBin().values().stream().map(AuctionedItem::getId).collect(Collectors.toList()));
}
if (AuctionHouse.getInstance().getAuctionItemManager().getGarbageBin().containsKey(auctionItem.getId())) {
AuctionHouse.getInstance().getAuctionItemManager().getGarbageBin().remove(auctionItem.getId());
auctionItemIterator.remove();
continue;
}
long timeRemaining = (auctionItem.getExpiresAt() - System.currentTimeMillis()) / 1000;
if (!auctionItem.isExpired()) {
auctionItem.updateRemainingTime(Settings.TICK_UPDATE_TIME.getInt());
if (Settings.BROADCAST_AUCTION_ENDING.getBoolean()) {
if (auctionItem.getRemainingTime() <= Settings.BROADCAST_AUCTION_ENDING_AT_TIME.getInt() && auctionItem.getRemainingTime() % 10 == 0) {
if (timeRemaining <= Settings.BROADCAST_AUCTION_ENDING_AT_TIME.getInt() && timeRemaining % 10 == 0 && timeRemaining != 0) {
Bukkit.getOnlinePlayers().forEach(player -> AuctionHouse.getInstance().getLocale().getMessage("auction.broadcast.ending")
.processPlaceholder("item", AuctionAPI.getInstance().getItemName(itemStack))
.processPlaceholder("seconds", auctionItem.getRemainingTime())
.processPlaceholder("seconds", timeRemaining)
.sendPrefixedMessage(player));
}
}
}
if (auctionItem.getRemainingTime() <= 0) {
if (timeRemaining <= 0) {
if (auctionItem.getHighestBidder().equals(auctionItem.getOwner())) {
auctionItem.setExpired(true);
continue;
@ -89,46 +90,43 @@ public class TickAuctionsTask extends BukkitRunnable {
EconomyManager.withdrawBalance(auctionWinner, Settings.TAX_CHARGE_SALES_TAX_TO_BUYER.getBoolean() ? finalPrice + tax : finalPrice);
EconomyManager.deposit(Bukkit.getOfflinePlayer(auctionItem.getOwner()), Settings.TAX_CHARGE_SALES_TAX_TO_BUYER.getBoolean() ? finalPrice: finalPrice - tax);
EconomyManager.deposit(Bukkit.getOfflinePlayer(auctionItem.getOwner()), Settings.TAX_CHARGE_SALES_TAX_TO_BUYER.getBoolean() ? finalPrice : finalPrice - tax);
if (Bukkit.getOfflinePlayer(auctionItem.getOwner()).isOnline()) {
AuctionHouse.getInstance().getLocale().getMessage("auction.itemsold")
.processPlaceholder("item", AuctionAPI.getInstance().getItemName(AuctionAPI.getInstance().deserializeItem(auctionItem.getRawItem())))
.processPlaceholder("item", AuctionAPI.getInstance().getItemName(itemStack))
.processPlaceholder("price", AuctionAPI.getInstance().formatNumber(Settings.TAX_CHARGE_SALES_TAX_TO_BUYER.getBoolean() ? finalPrice : finalPrice - tax))
.processPlaceholder("buyer_name", Bukkit.getOfflinePlayer(auctionItem.getHighestBidder()).getName())
.sendPrefixedMessage(Bukkit.getOfflinePlayer(auctionItem.getOwner()).getPlayer());
AuctionHouse.getInstance().getLocale().getMessage("pricing.moneyadd").processPlaceholder("price", AuctionAPI.getInstance().formatNumber(Settings.TAX_CHARGE_SALES_TAX_TO_BUYER.getBoolean() ? finalPrice: finalPrice - tax)).sendPrefixedMessage(Bukkit.getOfflinePlayer(auctionItem.getOwner()).getPlayer());
AuctionHouse.getInstance().getLocale().getMessage("pricing.moneyadd").processPlaceholder("price", AuctionAPI.getInstance().formatNumber(Settings.TAX_CHARGE_SALES_TAX_TO_BUYER.getBoolean() ? finalPrice : finalPrice - tax)).sendPrefixedMessage(Bukkit.getOfflinePlayer(auctionItem.getOwner()).getPlayer());
}
if (auctionWinner.isOnline()) {
assert auctionWinner.getPlayer() != null;
AuctionHouse.getInstance().getLocale().getMessage("auction.bidwon")
.processPlaceholder("item", AuctionAPI.getInstance().getItemName(AuctionAPI.getInstance().deserializeItem(auctionItem.getRawItem())))
.processPlaceholder("amount", AuctionAPI.getInstance().deserializeItem(auctionItem.getRawItem()).getAmount())
.processPlaceholder("item", AuctionAPI.getInstance().getItemName(itemStack))
.processPlaceholder("amount", itemStack.getAmount())
.processPlaceholder("price", AuctionAPI.getInstance().formatNumber(Settings.TAX_CHARGE_SALES_TAX_TO_BUYER.getBoolean() ? finalPrice + tax : finalPrice))
.sendPrefixedMessage(auctionWinner.getPlayer());
AuctionHouse.getInstance().getLocale().getMessage("pricing.moneyremove").processPlaceholder("price", AuctionAPI.getInstance().formatNumber(Settings.TAX_CHARGE_SALES_TAX_TO_BUYER.getBoolean() ? finalPrice + tax : finalPrice)).sendPrefixedMessage(auctionWinner.getPlayer());
if (Settings.ALLOW_PURCHASE_IF_INVENTORY_FULL.getBoolean()) {
PlayerUtils.giveItem(auctionWinner.getPlayer(), AuctionAPI.getInstance().deserializeItem(auctionItem.getRawItem()));
PlayerUtils.giveItem(auctionWinner.getPlayer(), itemStack);
auctionItemIterator.remove();
continue;
}
if (auctionWinner.getPlayer().getInventory().firstEmpty() != -1) {
PlayerUtils.giveItem(auctionWinner.getPlayer(), AuctionAPI.getInstance().deserializeItem(auctionItem.getRawItem()));
PlayerUtils.giveItem(auctionWinner.getPlayer(), itemStack);
auctionItemIterator.remove();
continue;
}
auctionItem.setOwner(auctionWinner.getUniqueId());
auctionItem.setExpired(true);
} else {
auctionItem.setOwner(auctionWinner.getUniqueId());
auctionItem.setExpired(true);
}
auctionItem.setOwner(auctionWinner.getUniqueId());
auctionItem.setExpired(true);
}
}
}
}

View File

@ -1,11 +1,11 @@
package ca.tweetzy.auctionhouse.transaction;
import ca.tweetzy.auctionhouse.auction.AuctionItem;
import ca.tweetzy.auctionhouse.auction.AuctionSaleType;
import lombok.Getter;
import lombok.NonNull;
import lombok.Setter;
import org.bukkit.inventory.ItemStack;
import java.io.Serializable;
import java.util.UUID;
/**
@ -17,23 +17,37 @@ import java.util.UUID;
@Getter
@Setter
public class Transaction implements Serializable {
public class Transaction {
private final UUID id;
private final UUID seller;
private final UUID buyer;
private final long transactionTime;
private final AuctionItem auctionItem;
private final String sellerName;
private final String buyerName;
private final Long transactionTime;
private final ItemStack item;
private final AuctionSaleType auctionSaleType;
private final double finalPrice;
public Transaction(UUID id, UUID seller, UUID buyer, long transactionTime, AuctionItem auctionItem, AuctionSaleType auctionSaleType) {
public Transaction(
@NonNull UUID id,
@NonNull UUID seller,
@NonNull UUID buyer,
@NonNull String sellerName,
@NonNull String buyerName,
long transactionTime,
@NonNull ItemStack item,
@NonNull AuctionSaleType auctionSaleType,
double finalPrice
) {
this.id = id;
this.seller = seller;
this.buyer = buyer;
this.sellerName = sellerName;
this.buyerName = buyerName;
this.transactionTime = transactionTime;
this.auctionItem = auctionItem;
this.item = item;
this.auctionSaleType = auctionSaleType;
this.finalPrice = auctionSaleType == AuctionSaleType.USED_BIDDING_SYSTEM ? auctionItem.getCurrentPrice() : auctionItem.getBasePrice();
this.finalPrice = finalPrice;
}
}

View File

@ -5,7 +5,7 @@ main: ca.tweetzy.auctionhouse.AuctionHouse
description: Auction House is a premium auction solution for your server.
website: https://tweetzy.ca/
authors: [Kiran Hart]
softdepend: [Vault, PlayerPoints]
softdepend: [Vault, PlayerPoints, PlaceholderAPI, MMOItems]
commands:
auctionhouse:
@ -32,6 +32,7 @@ permissions:
auctionhouse.cmd.filter: true
auctionhouse.cmd.ban: true
auctionhouse.cmd.unban: true
auctionhouse.cmd.togglelistinfo: true
auctionhouse.cmd:
description: Allows the user to use /ah
default: op
@ -73,4 +74,7 @@ permissions:
default: op
auctionhouse.cmd.unban:
description: Allows the user to unban players from the auction house
default: op
default: op
auctionhouse.cmd.togglelistinfo:
description: Allows the user to turn off their listing messages
default: true

View File

@ -1,3 +1,8 @@
import org.apache.commons.lang.StringUtils;
import java.util.ArrayList;
import java.util.List;
/**
* The current file has been created by Kiran Hart
* Date Created: July 21 2021
@ -8,8 +13,12 @@ public class Test {
public static void main(String[] args) {
// System.out.println(TimeUtils.makeReadable(getSecondsFromString("2y")*1000));
List<String> enchants = new ArrayList<>();
enchants.add("Sharpness V");
enchants.add("Sharpness I");
enchants.add("Fire Aspect IV");
System.out.println(StringUtils.join(enchants, ";=;"));
}
public static long getSecondsFromString(String time) {