diff --git a/.idea/artifacts/AuctionHouse_jar.xml b/.idea/artifacts/AuctionHouse_jar.xml index 4e49fbc..3257448 100644 --- a/.idea/artifacts/AuctionHouse_jar.xml +++ b/.idea/artifacts/AuctionHouse_jar.xml @@ -1,9 +1,9 @@ - + \ No newline at end of file diff --git a/.idea/libraries/Maven__com_zaxxer_HikariCP_3_2_0.xml b/.idea/libraries/Maven__com_zaxxer_HikariCP_3_2_0.xml new file mode 100644 index 0000000..8f760a2 --- /dev/null +++ b/.idea/libraries/Maven__com_zaxxer_HikariCP_3_2_0.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_slf4j_slf4j_api_1_7_25.xml b/.idea/libraries/Maven__org_slf4j_slf4j_api_1_7_25.xml new file mode 100644 index 0000000..20e8163 --- /dev/null +++ b/.idea/libraries/Maven__org_slf4j_slf4j_api_1_7_25.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/auctionhouse.iml b/auctionhouse.iml index d989abc..3631e06 100644 --- a/auctionhouse.iml +++ b/auctionhouse.iml @@ -37,5 +37,7 @@ + + \ No newline at end of file diff --git a/dependency-reduced-pom.xml b/dependency-reduced-pom.xml new file mode 100644 index 0000000..e90d63e --- /dev/null +++ b/dependency-reduced-pom.xml @@ -0,0 +1,114 @@ + + + 4.0.0 + com.shadebyte + auctionhouse + AuctionHouse + 1.0-SNAPSHOT + A premium auction house plugin + https://www.shadebyte.com + + clean package + + + true + src/main/resources + + + + + maven-compiler-plugin + 3.7.0 + + 1.8 + 1.8 + + + + maven-shade-plugin + 3.1.0 + + + package + + shade + + + true + + + + + + + + + spigotmc-repo + https://hub.spigotmc.org/nexus/content/groups/public/ + + + sonatype + https://oss.sonatype.org/content/groups/public/ + + + vault-repo + http://nexus.hc.to/content/repositories/pub_releases + + + + + org.spigotmc + spigot-api + 1.12.2-R0.1-SNAPSHOT + provided + + + commons-lang + commons-lang + + + json-simple + com.googlecode.json-simple + + + guava + com.google.guava + + + gson + com.google.code.gson + + + snakeyaml + org.yaml + + + bungeecord-chat + net.md-5 + + + + + net.milkbowl.vault + VaultAPI + 1.6 + provided + + + bukkit + org.bukkit + + + + + org.projectlombok + lombok + 1.16.12 + provided + + + + UTF-8 + + + diff --git a/src/main/java/com/shadebyte/auctionhouse/Core.java b/src/main/java/com/shadebyte/auctionhouse/Core.java index 68120f4..300f02f 100644 --- a/src/main/java/com/shadebyte/auctionhouse/Core.java +++ b/src/main/java/com/shadebyte/auctionhouse/Core.java @@ -11,6 +11,7 @@ import com.shadebyte.auctionhouse.auction.Transaction; import com.shadebyte.auctionhouse.cmds.CommandManager; import com.shadebyte.auctionhouse.events.AGUIListener; import com.shadebyte.auctionhouse.events.TransactionListener; +import com.shadebyte.auctionhouse.inventory.AGUI; import com.shadebyte.auctionhouse.util.Debugger; import com.shadebyte.auctionhouse.util.Locale; import com.shadebyte.auctionhouse.util.storage.ConfigWrapper; @@ -113,12 +114,17 @@ public final class Core extends JavaPlugin { } loadAuctions(); + Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', "&bFound a total of &6" + Transaction.getTotalTransactions() + " &brecorded transactions")); Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', "&bAuction House finished loading, took " + (System.currentTimeMillis() - startTime) + " ms")); tickAuctions(); } @Override public void onDisable() { + Bukkit.getOnlinePlayers().forEach(p -> { + if(p.getOpenInventory().getTopInventory().getHolder() instanceof AGUI) p.closeInventory(); + }); + saveAuctions(); if (hikari != null) hikari.close(); diff --git a/src/main/java/com/shadebyte/auctionhouse/api/AuctionAPI.java b/src/main/java/com/shadebyte/auctionhouse/api/AuctionAPI.java index 8e68371..c09383d 100644 --- a/src/main/java/com/shadebyte/auctionhouse/api/AuctionAPI.java +++ b/src/main/java/com/shadebyte/auctionhouse/api/AuctionAPI.java @@ -149,9 +149,7 @@ public class AuctionAPI { } public String getDate(long milli) { - Date date = new Date(milli); - SimpleDateFormat df2 = new SimpleDateFormat("dd/MM/yy"); - return df2.format(date); + return new SimpleDateFormat("MMMM dd yyyy").format(new Date(milli)); } public String friendlyNumber(double value) { diff --git a/src/main/java/com/shadebyte/auctionhouse/api/enums/Permissions.java b/src/main/java/com/shadebyte/auctionhouse/api/enums/Permissions.java index d7a7917..22bfa3b 100644 --- a/src/main/java/com/shadebyte/auctionhouse/api/enums/Permissions.java +++ b/src/main/java/com/shadebyte/auctionhouse/api/enums/Permissions.java @@ -13,6 +13,7 @@ public enum Permissions { HELP_CMD(BASE.getNode() + ".cmd.help"), SELL_CMD(BASE.getNode() + ".cmd.sell"), EXPIRED_CMD(BASE.getNode() + ".cmd.expired"), + TRANSACTIONS_CMD(BASE.getNode() + ".cmd.transactions"), LISTINGS_CMD(BASE.getNode() + ".cmd.listings"), MAX_AUCTIONS(BASE.getNode() + ".maxauctions"), ; diff --git a/src/main/java/com/shadebyte/auctionhouse/auction/Transaction.java b/src/main/java/com/shadebyte/auctionhouse/auction/Transaction.java index 0460c4f..accaef0 100644 --- a/src/main/java/com/shadebyte/auctionhouse/auction/Transaction.java +++ b/src/main/java/com/shadebyte/auctionhouse/auction/Transaction.java @@ -1,6 +1,16 @@ package com.shadebyte.auctionhouse.auction; import com.shadebyte.auctionhouse.Core; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; /** * The current file has been created by Kiran Hart @@ -53,6 +63,40 @@ public class Transaction { Core.getInstance().getTransactions().saveConfig(); } + public static int getTotalTransactions() { + return (Core.getInstance().getTransactions().getConfig().getConfigurationSection("transactions") != null && Core.getInstance().getTransactions().getConfig().getConfigurationSection("transactions").getKeys(false).size() > 0) ? Core.getInstance().getTransactions().getConfig().getConfigurationSection("transactions").getKeys(false).size() : 0; + } + + public static int getTotalTransactionsByPlayer(Player p) { + if (getTotalTransactions() == 0) return 0; + int total = 0; + for (String transactions : Core.getInstance().getTransactions().getConfig().getConfigurationSection("transactions").getKeys(false)) { + if (Core.getInstance().getTransactions().getConfig().getString("transactions." + transactions + ".seller").equalsIgnoreCase(p.getUniqueId().toString()) || Core.getInstance().getTransactions().getConfig().getString("transactions." + transactions + ".buyer").equalsIgnoreCase(p.getUniqueId().toString())) { + total++; + } + } + return total; + } + + private static ItemStack getTransactionItem(String node) { + String[] stack = Core.getInstance().getConfig().getString("transaction.item").split(":"); + ItemStack item = new ItemStack(Material.valueOf(stack[0].toUpperCase()), 1, Short.parseShort(stack[1])); + ItemMeta meta = item.getItemMeta(); + meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', Core.getInstance().getConfig().getString("transaction.name").replace("{transaction_id}", Core.getInstance().getTransactions().getConfig().getString("transactions." + node + ".auction-id")))); + List lore = new ArrayList<>(); + Core.getInstance().getConfig().getStringList("transaction.lore").forEach(e-> lore.add(ChatColor.translateAlternateColorCodes('&', e.replace("{buyer}", Bukkit.getOfflinePlayer(UUID.fromString(Core.getInstance().getTransactions().getConfig().getString("transactions." + node + ".buyer"))).getName()).replace("{seller}", Bukkit.getOfflinePlayer(UUID.fromString(Core.getInstance().getTransactions().getConfig().getString("transactions." + node + ".seller"))).getName())))); + meta.setLore(lore); + item.setItemMeta(meta); + return item; + } + + public static List getAllRecordedTransactions() { + List items = new ArrayList<>(); + if (getTotalTransactions() == 0) return items; + Core.getInstance().getTransactions().getConfig().getConfigurationSection("transactions").getKeys(false).forEach(node -> items.add(getTransactionItem(node))); + return items; + } + public TransactionType getTransactionType() { return transactionType; } diff --git a/src/main/java/com/shadebyte/auctionhouse/cmds/CommandManager.java b/src/main/java/com/shadebyte/auctionhouse/cmds/CommandManager.java index 64b645e..81b9c00 100644 --- a/src/main/java/com/shadebyte/auctionhouse/cmds/CommandManager.java +++ b/src/main/java/com/shadebyte/auctionhouse/cmds/CommandManager.java @@ -3,10 +3,7 @@ package com.shadebyte.auctionhouse.cmds; import com.shadebyte.auctionhouse.Core; import com.shadebyte.auctionhouse.api.enums.Lang; import com.shadebyte.auctionhouse.api.enums.Permissions; -import com.shadebyte.auctionhouse.cmds.subcmds.ExpiredCommand; -import com.shadebyte.auctionhouse.cmds.subcmds.ListedCommand; -import com.shadebyte.auctionhouse.cmds.subcmds.ReloadCommand; -import com.shadebyte.auctionhouse.cmds.subcmds.SellCommand; +import com.shadebyte.auctionhouse.cmds.subcmds.*; import com.shadebyte.auctionhouse.inventory.inventories.AuctionGUI; import com.shadebyte.auctionhouse.inventory.inventories.ListingsGUI; import com.shadebyte.auctionhouse.util.Debugger; @@ -40,6 +37,7 @@ public class CommandManager implements CommandExecutor { public final String listed = "listed"; public final String reload = "reload"; public final String sell = "sell"; + public final String transactions = "transactions"; public void initialize() { Core.getInstance().getCommand(main).setExecutor(this); @@ -47,6 +45,7 @@ public class CommandManager implements CommandExecutor { this.commands.add(new ReloadCommand()); this.commands.add(new ListedCommand()); this.commands.add(new ExpiredCommand()); + this.commands.add(new TransactionsCommand()); } @Override diff --git a/src/main/java/com/shadebyte/auctionhouse/cmds/subcmds/TransactionsCommand.java b/src/main/java/com/shadebyte/auctionhouse/cmds/subcmds/TransactionsCommand.java new file mode 100644 index 0000000..732fc58 --- /dev/null +++ b/src/main/java/com/shadebyte/auctionhouse/cmds/subcmds/TransactionsCommand.java @@ -0,0 +1,52 @@ +package com.shadebyte.auctionhouse.cmds.subcmds; + +import com.shadebyte.auctionhouse.Core; +import com.shadebyte.auctionhouse.api.enums.Lang; +import com.shadebyte.auctionhouse.api.enums.Permissions; +import com.shadebyte.auctionhouse.cmds.SubCommand; +import com.shadebyte.auctionhouse.inventory.inventories.AllTransactionsGUI; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +/** + * The current file has been created by Kiran Hart + * Date Created: 7/6/2018 + * Time Created: 11:51 AM + * Usage of any code found within this class is prohibited unless given explicit permission otherwise. + */ +public class TransactionsCommand extends SubCommand { + + @Override + public void onCommand(CommandSender sender, String[] args) { + + if (!sender.hasPermission(Permissions.RELOAD_CMD.getNode())) { + sender.sendMessage(Core.getInstance().getSettings().getPrefix() + Core.getInstance().getLocale().getMessage(Lang.NO_PERMISSION.getNode())); + return; + } + + if (!(sender instanceof Player)) { + sender.sendMessage(Core.getInstance().getSettings().getPrefix() + Core.getInstance().getLocale().getMessage(Lang.PLAYERS_ONLY.getNode())); + return; + } + + Player p = (Player) sender; + p.openInventory(new AllTransactionsGUI(p).getInventory()); + } + + @Override + public String name() { + return Core.getInstance().getCommandManager().transactions; + } + + @Override + public String info() { + return null; + } + + @Override + public String[] aliases() { + return new String[0]; + } +} diff --git a/src/main/java/com/shadebyte/auctionhouse/inventory/inventories/AllTransactionsGUI.java b/src/main/java/com/shadebyte/auctionhouse/inventory/inventories/AllTransactionsGUI.java new file mode 100644 index 0000000..e4e221b --- /dev/null +++ b/src/main/java/com/shadebyte/auctionhouse/inventory/inventories/AllTransactionsGUI.java @@ -0,0 +1,92 @@ +package com.shadebyte.auctionhouse.inventory.inventories; + +import com.google.common.collect.Lists; +import com.shadebyte.auctionhouse.Core; +import com.shadebyte.auctionhouse.api.AuctionAPI; +import com.shadebyte.auctionhouse.auction.AuctionPlayer; +import com.shadebyte.auctionhouse.auction.Transaction; +import com.shadebyte.auctionhouse.inventory.AGUI; +import com.shadebyte.auctionhouse.util.NBTEditor; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryCloseEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; + +import java.util.List; + +/** + * The current file has been created by Kiran Hart + * Date Created: 7/6/2018 + * Time Created: 11:56 AM + * Usage of any code found within this class is prohibited unless given explicit permission otherwise. + */ +public class AllTransactionsGUI implements AGUI { + + private Player p; + private List> chunks; + private int page = 1; + + public AllTransactionsGUI(Player p) { + this.p = p; + chunks = Lists.partition(Transaction.getAllRecordedTransactions(), 45); + } + + @Override + public void click(InventoryClickEvent e, ItemStack clicked, int slot) { + e.setCancelled(true); + + try { + if (page >= 1 && slot == 48) p.openInventory(this.setPage(this.getPage() - 1).getInventory()); + if (page >= 1 && slot == 50) p.openInventory(this.setPage(this.getPage() + 1).getInventory()); + } catch (Exception e1) { + } + + if (slot >= 0 & slot <= 44) { + if (clicked == null || clicked.getType() == Material.AIR) { + return; + } + + } + + } + + @Override + public void close(InventoryCloseEvent e) { + + } + + @Override + public Inventory getInventory() { + Inventory inventory = Bukkit.createInventory(this, 54, ChatColor.translateAlternateColorCodes('&', Core.getInstance().getConfig().getString("gui.collection.title"))); + + //Bottom Row + inventory.setItem(48, AuctionAPI.getInstance().createConfigItem("gui.alltransactions.items.previouspage", 0, 0)); + inventory.setItem(49, AuctionAPI.getInstance().createConfigItem("gui.alltransactions.items.close", 0, 0)); + inventory.setItem(50, AuctionAPI.getInstance().createConfigItem("gui.alltransactions.items.nextpage", 0, 0)); + + if (Transaction.getTotalTransactions() == 0) { + return inventory; + } + + if (chunks.size() != 0) + chunks.get(getPage() - 1).forEach(item -> inventory.setItem(inventory.firstEmpty(), item)); + + return inventory; + } + + public AllTransactionsGUI setPage(int page) { + if (page <= 0) + this.page = 1; + else + this.page = page; + return this; + } + + public int getPage() { + return page; + } +} diff --git a/src/main/java/com/shadebyte/auctionhouse/inventory/inventories/SingleTransactionGUI.java b/src/main/java/com/shadebyte/auctionhouse/inventory/inventories/SingleTransactionGUI.java new file mode 100644 index 0000000..31e46c4 --- /dev/null +++ b/src/main/java/com/shadebyte/auctionhouse/inventory/inventories/SingleTransactionGUI.java @@ -0,0 +1,51 @@ +package com.shadebyte.auctionhouse.inventory.inventories; + +import com.shadebyte.auctionhouse.Core; +import com.shadebyte.auctionhouse.api.AuctionAPI; +import com.shadebyte.auctionhouse.auction.Transaction; +import com.shadebyte.auctionhouse.inventory.AGUI; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryCloseEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; + +/** + * The current file has been created by Kiran Hart + * Date Created: 8/7/2018 + * Time Created: 4:32 PM + * Usage of any code found within this class is prohibited unless given explicit permission otherwise. + */ +public class SingleTransactionGUI implements AGUI { + + private Transaction transaction; + + public SingleTransactionGUI(Transaction transaction) { + this.transaction = transaction; + } + + @Override + public void click(InventoryClickEvent e, ItemStack clicked, int slot) { + e.setCancelled(true); + } + + @Override + public void close(InventoryCloseEvent e) { + + } + + @Override + public Inventory getInventory() { + Inventory inventory = Bukkit.createInventory(this, 54, ChatColor.translateAlternateColorCodes('&', Core.getInstance().getConfig().getString("gui.singletransaction.title"))); + //Fill Inventory + for (int i = 0; i < inventory.getSize(); i++) inventory.setItem(i, AuctionAPI.getInstance().createConfigItem("gui.singletransaction.items.background", 0, 0)); + + inventory.setItem(13, transaction.getAuctionItem().getItem()); + inventory.setItem(48, AuctionAPI.getInstance().createConfigItem("gui.singletransaction.items.back", 0, 0)); + inventory.setItem(49, AuctionAPI.getInstance().createConfigItem("gui.singletransaction.items.you", 0, 0)); + inventory.setItem(50, AuctionAPI.getInstance().createConfigItem("gui.singletransaction.items.auctionhouse", 0, 0)); + + return inventory; + } +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 60f3568..4dce1e8 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -23,9 +23,9 @@ database: enabled: true host: 162.241.217.18 port: 3306 - database: "" - username: "" - password: "" + database: "kiranhar_auctionhouse" + username: "kiranhar_admin" + password: "TweetyHart1." discord: enabled: true @@ -47,7 +47,103 @@ receipt: - "&bPrice&f: &a${price}" - "&ePurchased on&f: &a{date} &fat &A{time}" +transaction: + item: "PAPER:0" + name: "&b{transaction_id}" + lore: + - "&7Seller&f: &b{seller}" + - "&7Buyer&f: &b{buyer}" + gui: + alltransactions: + title: "&E&lAll Transactions" + items: + previouspage: + item: "PAPER:0" + name: "&e&l<- Previous Page" + lore: + - "&7Go back" + close: + item: "NETHER_STAR:0" + name: "&e&lClose" + lore: + - "&7Click to exit this window" + nextpage: + item: "PAPER:0" + name: "&e&lNext Page ->" + lore: + - "&7Next Page" + playertransactions: + previouspage: + item: "PAPER:0" + name: "&e&l<- Previous Page" + lore: + - "&7Go back" + close: + item: "NETHER_STAR:0" + name: "&e&lClose" + lore: + - "&7Click to exit this window" + nextpage: + item: "PAPER:0" + name: "&e&lNext Page ->" + lore: + - "&7Next Page" + singletransaction: + title: "&6&lViewing Transaction" + items: + background: + item: "STAINED_GLASS_PANE:15" + name: "&0*" + lore: + - "&0*" + seller: + name: "&6&lSeller" + lore: + - "&7Name&f: &b{seller}" + - "" + - "&7Click to view all the" + - "&7transactions by this player." + buyer: + name: "&6&lBuyer" + lore: + - "&7Name&f: &b{seller}" + - "" + - "&7Click to view all the" + - "&7transactions by this player." + you: + item: "DOUBLE_PLANT:0" + name: "&6&lView Your Transactions" + lore: + - "&7Click to view all the" + - "&7transactions you've done." + back: + item: "NETHER_STAR:0" + name: "&6&LGo Back" + lore: + - "&7Go back to main transactions" + - "&7window selection menu." + auctionhouse: + item: "CHEST:0" + name: "&e&lReturn to Auction House" + lore: + - "&7Click here to return to the" + - "&7auction house main menu." + startprice: + item: "STAINED_GLASS_PANE:5" + name: "&6&lStart Price" + lore: + - "&7Auction started at &a${startprice}" + increment: + item: "STAINED_GLASS_PANE:5" + name: "&6&lBid Increment" + lore: + - "&7Bid increment set at &a${bidincrement}" + buynowprice: + item: "STAINED_GLASS_PANE:5" + name: "&6&lBuy Now Price" + lore: + - "&7Buy now price set at &a${buynowprice}" active: title: "&7Your Current Listings" items: @@ -64,7 +160,7 @@ gui: - "&7Go back" nextpage: item: "PAPER:0" - name: "&e&lPrevious Page ->" + name: "&e&lNext Page ->" lore: - "&7Next Page" tutorial: