diff --git a/src/main/java/com/badbones69/crazyauctions/Methods.java b/src/main/java/com/badbones69/crazyauctions/Methods.java index 1408317..09780f8 100644 --- a/src/main/java/com/badbones69/crazyauctions/Methods.java +++ b/src/main/java/com/badbones69/crazyauctions/Methods.java @@ -69,7 +69,7 @@ public class Methods { public static Player getPlayer(String name) { try { - return Bukkit.getServer().getPlayer(UUID.fromString(name)); + return plugin.getServer().getPlayer(UUID.fromString(name)); } catch (Exception e) { return null; } @@ -84,11 +84,11 @@ public class Methods { } public static OfflinePlayer getOfflinePlayer(String name) { - return Bukkit.getServer().getOfflinePlayer(UUID.fromString(name)); + return plugin.getServer().getOfflinePlayer(UUID.fromString(name)); } public static boolean isOnline(String name) { - for (Player player : Bukkit.getServer().getOnlinePlayers()) { + for (Player player : plugin.getServer().getOnlinePlayers()) { if (player.getName().equalsIgnoreCase(name)) { return true; } @@ -98,7 +98,7 @@ public class Methods { } public static boolean isOnline(String name, CommandSender p) { - for (Player player : Bukkit.getServer().getOnlinePlayers()) { + for (Player player : plugin.getServer().getOnlinePlayers()) { if (player.getName().equalsIgnoreCase(name)) { return true; } @@ -111,6 +111,7 @@ public class Methods { public static boolean hasPermission(Player player, String perm) { if (!player.hasPermission("crazyauctions." + perm)) { player.sendMessage(Messages.NO_PERMISSION.getMessage(player)); + return false; } @@ -121,6 +122,7 @@ public class Methods { if (sender instanceof Player player) { if (!player.hasPermission("crazyauctions." + perm)) { player.sendMessage(Messages.NO_PERMISSION.getMessage(player)); + return false; } @@ -132,10 +134,13 @@ public class Methods { public static List getPage(List list, Integer page) { List items = new ArrayList<>(); + if (page <= 0) page = 1; + int max = 45; int index = page * max - max; int endIndex = index >= list.size() ? list.size() - 1 : index + max; + for (; index < endIndex; index++) { if (index < list.size()) items.add(list.get(index)); } @@ -154,7 +159,9 @@ public class Methods { public static List getPageInts(List list, Integer page) { List items = new ArrayList<>(); + if (page <= 0) page = 1; + int max = 45; int index = page * max - max; int endIndex = index >= list.size() ? list.size() - 1 : index + max; @@ -163,10 +170,12 @@ public class Methods { if (index < list.size()) items.add(list.get(index)); } - for (; items.size() == 0; page--) { + for (; items.isEmpty(); page--) { if (page <= 0) break; + index = page * max - max; endIndex = index >= list.size() ? list.size() - 1 : index + max; + for (; index < endIndex; index++) { if (index < list.size()) items.add(list.get(index)); } @@ -178,23 +187,30 @@ public class Methods { public static int getMaxPage(List list) { int maxPage = 1; int amount = list.size(); + for (; amount > 45; amount -= 45, maxPage++) ; + return maxPage; } public static String convertToTime(long time) { Calendar C = Calendar.getInstance(); Calendar cal = Calendar.getInstance(); + cal.setTimeInMillis(time); + int total = ((int) (cal.getTimeInMillis() / 1000) - (int) (C.getTimeInMillis() / 1000)); int D = 0; int H = 0; int M = 0; int S = 0; + for (; total > 86400; total -= 86400, D++) ; for (; total > 3600; total -= 3600, H++) ; for (; total > 60; total -= 60, M++) ; + S += total; + return D + "d " + H + "h " + M + "m " + S + "s "; } @@ -205,12 +221,15 @@ public class Methods { if (i.contains("D") || i.contains("d")) { cal.add(Calendar.DATE, Integer.parseInt(i.replace("D", "").replace("d", ""))); } + if (i.contains("H") || i.contains("h")) { cal.add(Calendar.HOUR, Integer.parseInt(i.replace("H", "").replace("h", ""))); } + if (i.contains("M") || i.contains("m")) { cal.add(Calendar.MINUTE, Integer.parseInt(i.replace("M", "").replace("m", ""))); } + if (i.contains("S") || i.contains("s")) { cal.add(Calendar.SECOND, Integer.parseInt(i.replace("S", "").replace("s", ""))); } @@ -225,16 +244,20 @@ public class Methods { public static void updateAuction() { FileConfiguration data = Files.data.getConfiguration(); + Calendar cal = Calendar.getInstance(); Calendar expireTime = Calendar.getInstance(); Calendar fullExpireTime = Calendar.getInstance(); + boolean shouldSave = false; if (data.contains("OutOfTime/Cancelled")) { for (String i : data.getConfigurationSection("OutOfTime/Cancelled").getKeys(false)) { fullExpireTime.setTimeInMillis(data.getLong("OutOfTime/Cancelled." + i + ".Full-Time")); + if (cal.after(fullExpireTime)) { data.set("OutOfTime/Cancelled." + i, null); + shouldSave = true; } } @@ -247,12 +270,13 @@ public class Methods { if (cal.after(expireTime)) { int num = 1; + for (; data.contains("OutOfTime/Cancelled." + num); num++) ; if (data.getBoolean("Items." + i + ".Biddable") && !data.getString("Items." + i + ".TopBidder").equalsIgnoreCase("None") && plugin.getSupport().getMoney(getPlayer(data.getString("Items." + i + ".TopBidder"))) >= data.getInt("Items." + i + ".Price")) { String winner = data.getString("Items." + i + ".TopBidder"); String seller = data.getString("Items." + i + ".Seller"); - Long price = data.getLong("Items." + i + ".Price"); + long price = data.getLong("Items." + i + ".Price"); plugin.getSupport().addMoney(getOfflinePlayer(seller), price); plugin.getSupport().removeMoney(getOfflinePlayer(winner), price); @@ -265,7 +289,9 @@ public class Methods { if (isOnline(winner) && getPlayer(winner) != null) { Player player = getPlayer(winner); - Bukkit.getPluginManager().callEvent(new AuctionWinBidEvent(player, Methods.fromBase64(data.getString("Items." + i + ".Item")), price)); + + plugin.getServer().getPluginManager().callEvent(new AuctionWinBidEvent(player, Methods.fromBase64(data.getString("Items." + i + ".Item")), price)); + if (player != null) { player.sendMessage(Messages.WIN_BIDDING.getMessage(player, placeholders)); } @@ -273,6 +299,7 @@ public class Methods { if (isOnline(seller) && getPlayer(seller) != null) { Player player = getPlayer(seller); + if (player != null) { player.sendMessage(Messages.SOMEONE_WON_PLAYERS_BID.getMessage(player, placeholders)); } @@ -291,7 +318,8 @@ public class Methods { } AuctionExpireEvent event = new AuctionExpireEvent(player, Methods.fromBase64(data.getString("Items." + i + ".Item"))); - Bukkit.getPluginManager().callEvent(event); + plugin.getServer().getPluginManager().callEvent(event); + data.set("OutOfTime/Cancelled." + num + ".Seller", data.getString("Items." + i + ".Seller")); data.set("OutOfTime/Cancelled." + num + ".Full-Time", fullExpireTime.getTimeInMillis()); data.set("OutOfTime/Cancelled." + num + ".StoreID", data.getInt("Items." + i + ".StoreID")); @@ -310,15 +338,13 @@ public class Methods { public static String getPrice(String ID, Boolean Expired) { long price = 0L; - if (Expired) { - FileConfiguration configuration = Files.data.getConfiguration(); + FileConfiguration configuration = Files.data.getConfiguration(); + if (Expired) { if (configuration.contains("OutOfTime/Cancelled." + ID + ".Price")) { price = configuration.getLong("OutOfTime/Cancelled." + ID + ".Price"); } } else { - FileConfiguration configuration = Files.data.getConfiguration(); - if (configuration.contains("Items." + ID + ".Price")) { price = configuration.getLong("Items." + ID + ".Price"); } diff --git a/src/main/java/com/badbones69/crazyauctions/api/CrazyManager.java b/src/main/java/com/badbones69/crazyauctions/api/CrazyManager.java index f09a8dd..b2661bc 100644 --- a/src/main/java/com/badbones69/crazyauctions/api/CrazyManager.java +++ b/src/main/java/com/badbones69/crazyauctions/api/CrazyManager.java @@ -24,11 +24,11 @@ public class CrazyManager { } public boolean isSellingEnabled() { - return sellingEnabled; + return this.sellingEnabled; } public boolean isBiddingEnabled() { - return biddingEnabled; + return this.biddingEnabled; } public ArrayList getItems(Player player, ShopType type) { diff --git a/src/main/java/com/badbones69/crazyauctions/api/enums/Category.java b/src/main/java/com/badbones69/crazyauctions/api/enums/Category.java index b546e78..524c7f6 100644 --- a/src/main/java/com/badbones69/crazyauctions/api/enums/Category.java +++ b/src/main/java/com/badbones69/crazyauctions/api/enums/Category.java @@ -41,6 +41,7 @@ public enum Category { private static ArrayList getArmor() { ArrayList ma = new ArrayList<>(); + ma.add(Material.GOLDEN_HELMET); ma.add(Material.GOLDEN_CHESTPLATE); ma.add(Material.GOLDEN_LEGGINGS); @@ -71,6 +72,7 @@ public enum Category { private static ArrayList getTools() { ArrayList ma = new ArrayList<>(); + ma.add(Material.WOODEN_PICKAXE); ma.add(Material.WOODEN_AXE); ma.add(Material.WOODEN_SHOVEL); @@ -95,11 +97,13 @@ public enum Category { ma.add(Material.NETHERITE_AXE); ma.add(Material.NETHERITE_HOE); ma.add(Material.NETHERITE_SHOVEL); + return ma; } private static ArrayList getWeapons() { ArrayList ma = new ArrayList<>(); + ma.add(Material.GOLDEN_PICKAXE); ma.add(Material.GOLDEN_AXE); ma.add(Material.GOLDEN_SHOVEL); @@ -113,44 +117,53 @@ public enum Category { ma.add(Material.BOW); ma.add(Material.NETHERITE_SWORD); ma.add(Material.NETHERITE_AXE); + return ma; } private static ArrayList getFood() { ArrayList ma = new ArrayList<>(); + for (Material m : Material.values()) { if (m.isEdible()) { if (m != Material.POTION) ma.add(m); } } + return ma; } private static ArrayList getPotions() { ArrayList ma = new ArrayList<>(); + ma.add(Material.POTION); ma.add(Material.SPLASH_POTION); ma.add(Material.LINGERING_POTION); + return ma; } private static ArrayList getBlocks() { ArrayList ma = new ArrayList<>(); + for (Material m : Material.values()) { if (m.isBlock()) { ma.add(m); } } + return ma; } private static ArrayList getOthers() { ArrayList ma = new ArrayList<>(); + for (Material m : Material.values()) { if (!(getArmor().contains(m) || getTools().contains(m) || getWeapons().contains(m) || getFood().contains(m) || getPotions().contains(m) || getBlocks().contains(m))) { ma.add(m); } } + return ma; } @@ -158,10 +171,10 @@ public enum Category { * @return Returns the type name as a string. */ public String getName() { - return name; + return this.name; } public ArrayList getItems() { - return items; + return this.items; } } \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazyauctions/api/enums/ShopType.java b/src/main/java/com/badbones69/crazyauctions/api/enums/ShopType.java index f0e1666..697662c 100644 --- a/src/main/java/com/badbones69/crazyauctions/api/enums/ShopType.java +++ b/src/main/java/com/badbones69/crazyauctions/api/enums/ShopType.java @@ -31,6 +31,6 @@ public enum ShopType { * @return Returns the type name as a string. */ public String getName() { - return name; + return this.name; } } \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazyauctions/api/events/AuctionBuyEvent.java b/src/main/java/com/badbones69/crazyauctions/api/events/AuctionBuyEvent.java index 0298b88..67770c9 100644 --- a/src/main/java/com/badbones69/crazyauctions/api/events/AuctionBuyEvent.java +++ b/src/main/java/com/badbones69/crazyauctions/api/events/AuctionBuyEvent.java @@ -42,14 +42,14 @@ public class AuctionBuyEvent extends Event { } public Player getPlayer() { - return player; + return this.player; } public ItemStack getItem() { - return item; + return this.item; } public long getPrice() { - return price; + return this.price; } } \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazyauctions/api/events/AuctionCancelledEvent.java b/src/main/java/com/badbones69/crazyauctions/api/events/AuctionCancelledEvent.java index 70e065b..faee1dd 100644 --- a/src/main/java/com/badbones69/crazyauctions/api/events/AuctionCancelledEvent.java +++ b/src/main/java/com/badbones69/crazyauctions/api/events/AuctionCancelledEvent.java @@ -59,22 +59,22 @@ public class AuctionCancelledEvent extends Event { } public OfflinePlayer getOfflinePlayer() { - return offlinePlayer; + return this.offlinePlayer; } public Player getOnlinePlayer() { - return onlinePlayer; + return this.onlinePlayer; } public boolean isOnline() { - return isOnline; + return this.isOnline; } public ItemStack getItem() { - return item; + return this.item; } public Reasons getReason() { - return reason; + return this.reason; } } \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazyauctions/api/events/AuctionExpireEvent.java b/src/main/java/com/badbones69/crazyauctions/api/events/AuctionExpireEvent.java index a05804a..729e852 100644 --- a/src/main/java/com/badbones69/crazyauctions/api/events/AuctionExpireEvent.java +++ b/src/main/java/com/badbones69/crazyauctions/api/events/AuctionExpireEvent.java @@ -55,18 +55,18 @@ public class AuctionExpireEvent extends Event { } public OfflinePlayer getOfflinePlayer() { - return offlinePlayer; + return this.offlinePlayer; } public Player getOnlinePlayer() { - return onlinePlayer; + return this.onlinePlayer; } public boolean isOnline() { - return isOnline; + return this.isOnline; } public ItemStack getItem() { - return item; + return this.item; } } \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazyauctions/api/events/AuctionListEvent.java b/src/main/java/com/badbones69/crazyauctions/api/events/AuctionListEvent.java index 0995361..4a1aab2 100644 --- a/src/main/java/com/badbones69/crazyauctions/api/events/AuctionListEvent.java +++ b/src/main/java/com/badbones69/crazyauctions/api/events/AuctionListEvent.java @@ -45,18 +45,18 @@ public class AuctionListEvent extends Event { } public Player getPlayer() { - return player; + return this.player; } public ShopType getShopType() { - return shop; + return this.shop; } public ItemStack getItem() { - return item; + return this.item; } public long getPrice() { - return price; + return this.price; } } \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazyauctions/api/events/AuctionNewBidEvent.java b/src/main/java/com/badbones69/crazyauctions/api/events/AuctionNewBidEvent.java index a2a6735..1b59ec8 100644 --- a/src/main/java/com/badbones69/crazyauctions/api/events/AuctionNewBidEvent.java +++ b/src/main/java/com/badbones69/crazyauctions/api/events/AuctionNewBidEvent.java @@ -38,14 +38,14 @@ public class AuctionNewBidEvent extends Event { } public Player getPlayer() { - return player; + return this.player; } public ItemStack getItem() { - return item; + return this.item; } public long getBid() { - return bid; + return this.bid; } } \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazyauctions/api/events/AuctionWinBidEvent.java b/src/main/java/com/badbones69/crazyauctions/api/events/AuctionWinBidEvent.java index e1e053f..391d90f 100644 --- a/src/main/java/com/badbones69/crazyauctions/api/events/AuctionWinBidEvent.java +++ b/src/main/java/com/badbones69/crazyauctions/api/events/AuctionWinBidEvent.java @@ -41,14 +41,14 @@ public class AuctionWinBidEvent extends Event { } public Player getPlayer() { - return player; + return this.player; } public ItemStack getItem() { - return item; + return this.item; } public long getBid() { - return bid; + return this.bid; } } \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazyauctions/commands/AuctionCommand.java b/src/main/java/com/badbones69/crazyauctions/commands/AuctionCommand.java index c91151b..56e0aad 100644 --- a/src/main/java/com/badbones69/crazyauctions/commands/AuctionCommand.java +++ b/src/main/java/com/badbones69/crazyauctions/commands/AuctionCommand.java @@ -43,6 +43,7 @@ public class AuctionCommand implements CommandExecutor { if (args.length == 0) { if (!(sender instanceof Player player)) { sender.sendMessage(Messages.PLAYERS_ONLY.getMessage(sender)); + return true; } @@ -53,6 +54,7 @@ public class AuctionCommand implements CommandExecutor { if (config.contains("Settings.Category-Page-Opens-First")) { if (config.getBoolean("Settings.Category-Page-Opens-First")) { GuiListener.openCategories(player, ShopType.SELL); + return true; } } @@ -74,6 +76,7 @@ public class AuctionCommand implements CommandExecutor { } sender.sendMessage(Messages.HELP.getMessage(sender)); + return true; } @@ -88,6 +91,7 @@ public class AuctionCommand implements CommandExecutor { this.crazyManager.load(); sender.sendMessage(Messages.RELOAD.getMessage(sender)); + return true; } @@ -98,15 +102,18 @@ public class AuctionCommand implements CommandExecutor { if (!(sender instanceof Player player)) { sender.sendMessage(Messages.PLAYERS_ONLY.getMessage(sender)); + return true; } if (args.length >= 2) { GuiListener.openViewer(player, args[1], 1); + return true; } sender.sendMessage(Messages.CRAZYAUCTIONS_VIEW.getMessage(sender)); + return true; } @@ -117,10 +124,12 @@ public class AuctionCommand implements CommandExecutor { if (!(sender instanceof Player player)) { sender.sendMessage(Messages.PLAYERS_ONLY.getMessage(sender)); + return true; } GuiListener.openPlayersExpiredList(player, 1); + return true; } @@ -129,16 +138,19 @@ public class AuctionCommand implements CommandExecutor { if (!(sender instanceof Player player)) { sender.sendMessage(Messages.PLAYERS_ONLY.getMessage(sender)); + return true; } GuiListener.openPlayersCurrentList(player, 1); + return true; } case "sell", "bid" -> { if (!(sender instanceof Player player)) { sender.sendMessage(Messages.PLAYERS_ONLY.getMessage(sender)); + return true; } @@ -146,6 +158,7 @@ public class AuctionCommand implements CommandExecutor { if (args[0].equalsIgnoreCase("sell")) { if (!crazyManager.isSellingEnabled()) { player.sendMessage(Messages.SELLING_DISABLED.getMessage(sender)); + return true; } @@ -155,6 +168,7 @@ public class AuctionCommand implements CommandExecutor { if (args[0].equalsIgnoreCase("bid")) { if (!crazyManager.isBiddingEnabled()) { player.sendMessage(Messages.BIDDING_DISABLED.getMessage(sender)); + return true; } @@ -166,28 +180,34 @@ public class AuctionCommand implements CommandExecutor { if (args.length >= 3) { if (!Methods.isInt(args[2])) { - HashMap placeholders = new HashMap<>(); + Map placeholders = new HashMap<>(); placeholders.put("%Arg%", args[2]); placeholders.put("%arg%", args[2]); + player.sendMessage(Messages.NOT_A_NUMBER.getMessage(sender, placeholders)); + return true; } amount = Integer.parseInt(args[2]); + if (amount <= 0) amount = 1; if (amount > item.getAmount()) amount = item.getAmount(); } if (!Methods.isLong(args[1])) { - HashMap placeholders = new HashMap<>(); + Map placeholders = new HashMap<>(); placeholders.put("%Arg%", args[1]); placeholders.put("%arg%", args[1]); + player.sendMessage(Messages.NOT_A_NUMBER.getMessage(sender, placeholders)); + return true; } if (Methods.getItemInHand(player).getType() == Material.AIR) { player.sendMessage(Messages.DOESNT_HAVE_ITEM_IN_HAND.getMessage(sender)); + return false; } @@ -196,20 +216,24 @@ public class AuctionCommand implements CommandExecutor { if (args[0].equalsIgnoreCase("bid")) { if (price < config.getLong("Settings.Minimum-Bid-Price", 100)) { player.sendMessage(Messages.BID_PRICE_TO_LOW.getMessage(sender)); + return true; } if (price > config.getLong("Settings.Max-Beginning-Bid-Price", 1000000)) { player.sendMessage(Messages.BID_PRICE_TO_HIGH.getMessage(sender)); + return true; } } else { if (price < config.getLong("Settings.Minimum-Sell-Price", 10)) { player.sendMessage(Messages.SELL_PRICE_TO_LOW.getMessage(sender)); + return true; } if (price > config.getLong("Settings.Max-Beginning-Sell-Price", 1000000)) { player.sendMessage(Messages.SELL_PRICE_TO_HIGH.getMessage(sender)); + return true; } } @@ -233,6 +257,7 @@ public class AuctionCommand implements CommandExecutor { if (perm.startsWith("crazyauctions.bid.")) { perm = perm.replace("crazyauctions.bid.", ""); + if (Methods.isInt(perm)) { if (Integer.parseInt(perm) > BidLimit) { BidLimit = Integer.parseInt(perm); @@ -258,6 +283,7 @@ public class AuctionCommand implements CommandExecutor { if (args[0].equalsIgnoreCase("sell")) { if (crazyManager.getItems(player, ShopType.SELL).size() >= SellLimit) { player.sendMessage(Messages.MAX_ITEMS.getMessage(sender)); + return true; } } @@ -265,6 +291,7 @@ public class AuctionCommand implements CommandExecutor { if (args[0].equalsIgnoreCase("bid")) { if (crazyManager.getItems(player, ShopType.BID).size() >= BidLimit) { player.sendMessage(Messages.MAX_ITEMS.getMessage(sender)); + return true; } } @@ -272,6 +299,7 @@ public class AuctionCommand implements CommandExecutor { if (config.getStringList("Settings.BlackList").contains(item.getType().getKey().getKey())) { player.sendMessage(Messages.ITEM_BLACKLISTED.getMessage(sender)); + return true; } @@ -338,10 +366,10 @@ public class AuctionCommand implements CommandExecutor { this.plugin.getServer().getPluginManager().callEvent(new AuctionListEvent(player, type, stack, price)); - HashMap placeholders = new HashMap<>(); - + Map placeholders = new HashMap<>(); placeholders.put("%Price%", String.valueOf(price)); placeholders.put("%price%", String.valueOf(price)); + player.sendMessage(Messages.ADDED_ITEM_TO_AUCTION.getMessage(sender, placeholders)); if (item.getAmount() <= 1 || (item.getAmount() - amount) <= 0) { @@ -358,6 +386,7 @@ public class AuctionCommand implements CommandExecutor { default -> { sender.sendMessage(Methods.getPrefix("&cPlease do /crazyauctions help for more information.")); + return true; } } @@ -368,6 +397,7 @@ public class AuctionCommand implements CommandExecutor { private ArrayList getDamageableItems() { ArrayList ma = new ArrayList<>(); + ma.add(Material.GOLDEN_HELMET); ma.add(Material.GOLDEN_CHESTPLATE); ma.add(Material.GOLDEN_LEGGINGS); diff --git a/src/main/java/com/badbones69/crazyauctions/commands/AuctionTab.java b/src/main/java/com/badbones69/crazyauctions/commands/AuctionTab.java index df809b3..22590d1 100644 --- a/src/main/java/com/badbones69/crazyauctions/commands/AuctionTab.java +++ b/src/main/java/com/badbones69/crazyauctions/commands/AuctionTab.java @@ -18,6 +18,7 @@ public class AuctionTab implements TabCompleter { @Override public List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String commandLabel, String[] args) { List completions = new ArrayList<>(); + if (args.length == 1) { // /voucher if (hasPermission(sender, "access")) { completions.add("help"); @@ -25,17 +26,20 @@ public class AuctionTab implements TabCompleter { completions.add("expired"); completions.add("listed"); } + if (hasPermission(sender, "test")) completions.add("test"); if (hasPermission(sender, "admin")) completions.add("reload"); if (hasPermission(sender, "view")) completions.add("view"); if (hasPermission(sender, "sell")) completions.add("sell"); if (hasPermission(sender, "bid")) completions.add("bid"); + return StringUtil.copyPartialMatches(args[0], completions, new ArrayList<>()); } else if (args.length == 2) { // /crazyauctions arg0 switch (args[0].toLowerCase()) { case "bid", "sell" -> completions.addAll(Arrays.asList("50", "100", "250", "500", "1000", "2500", "5000", "10000")); case "view" -> completions.addAll(this.plugin.getServer().getOnlinePlayers().stream().map(Player::getName).toList()); } + return StringUtil.copyPartialMatches(args[1], completions, new ArrayList<>()); } else if (args.length == 3) { // /crazyauctions arg0 arg1 switch (args[0].toLowerCase()) { diff --git a/src/main/java/com/badbones69/crazyauctions/controllers/GuiListener.java b/src/main/java/com/badbones69/crazyauctions/controllers/GuiListener.java index 3842e40..1871189 100644 --- a/src/main/java/com/badbones69/crazyauctions/controllers/GuiListener.java +++ b/src/main/java/com/badbones69/crazyauctions/controllers/GuiListener.java @@ -12,7 +12,6 @@ import com.badbones69.crazyauctions.api.enums.ShopType; import com.badbones69.crazyauctions.api.events.AuctionBuyEvent; import com.badbones69.crazyauctions.api.events.AuctionCancelledEvent; import com.badbones69.crazyauctions.api.events.AuctionNewBidEvent; -import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.OfflinePlayer; import org.bukkit.Sound; @@ -39,15 +38,16 @@ public class GuiListener implements Listener { private static final CrazyAuctions plugin = CrazyAuctions.get(); private static final CrazyManager crazyManager = plugin.getCrazyManager(); - private static final HashMap bidding = new HashMap<>(); - private static final HashMap biddingID = new HashMap<>(); - private static final HashMap shopType = new HashMap<>(); // Shop Type - private static final HashMap shopCategory = new HashMap<>(); // Category Type - private static final HashMap> List = new HashMap<>(); - private static final HashMap IDs = new HashMap<>(); + private static final Map bidding = new HashMap<>(); + private static final Map biddingID = new HashMap<>(); + private static final Map shopType = new HashMap<>(); // Shop Type + private static final Map shopCategory = new HashMap<>(); // Category Type + private static final Map> List = new HashMap<>(); + private static final Map IDs = new HashMap<>(); public static void openShop(Player player, ShopType sell, Category cat, int page) { Methods.updateAuction(); + FileConfiguration config = Files.config.getConfiguration(); FileConfiguration data = Files.data.getConfiguration(); List items = new ArrayList<>(); @@ -55,6 +55,7 @@ public class GuiListener implements Listener { if (!data.contains("Items")) { data.set("Items.Clear", null); + Files.data.save(); } @@ -202,11 +203,13 @@ public class GuiListener implements Listener { for (ItemStack item : Methods.getPage(items, page)) { int slot = inv.firstEmpty(); + inv.setItem(slot, item); } List Id = new ArrayList<>(Methods.getPageInts(ID, page)); List.put(player.getUniqueId(), Id); + player.openInventory(inv); } @@ -215,6 +218,7 @@ public class GuiListener implements Listener { FileConfiguration config = Files.config.getConfiguration(); Inventory inv = plugin.getServer().createInventory(null, 54, Methods.color(config.getString("Settings.Categories"))); + List options = new ArrayList<>(); options.add("OtherSettings.Back"); @@ -254,14 +258,17 @@ public class GuiListener implements Listener { public static void openPlayersCurrentList(Player player, int page) { Methods.updateAuction(); + FileConfiguration config = Files.config.getConfiguration(); FileConfiguration data = Files.data.getConfiguration(); + List items = new ArrayList<>(); List ID = new ArrayList<>(); Inventory inv = plugin.getServer().createInventory(null, 54, Methods.color(config.getString("Settings.Players-Current-Items"))); List options = new ArrayList<>(); + options.add("Back"); options.add("WhatIsThis.CurrentItems"); @@ -317,14 +324,18 @@ public class GuiListener implements Listener { } List Id = new ArrayList<>(Methods.getPageInts(ID, page)); + List.put(player.getUniqueId(), Id); + player.openInventory(inv); } public static void openPlayersExpiredList(Player player, int page) { Methods.updateAuction(); + FileConfiguration config = Files.config.getConfiguration(); FileConfiguration data = Files.data.getConfiguration(); + List items = new ArrayList<>(); List ID = new ArrayList<>(); @@ -357,11 +368,12 @@ public class GuiListener implements Listener { } int maxPage = Methods.getMaxPage(items); + for (; page > maxPage; page--); Inventory inv = plugin.getServer().createInventory(null, 54, Methods.color(config.getString("Settings.Cancelled/Expired-Items") + " #" + page)); - List options = new ArrayList<>(); + List options = new ArrayList<>(); options.add("Back"); options.add("PreviousPage"); options.add("Return"); @@ -390,11 +402,14 @@ public class GuiListener implements Listener { for (ItemStack item : Methods.getPage(items, page)) { int slot = inv.firstEmpty(); + inv.setItem(slot, item); } List Id = new ArrayList<>(Methods.getPageInts(ID, page)); + List.put(player.getUniqueId(), Id); + player.openInventory(inv); } @@ -406,13 +421,16 @@ public class GuiListener implements Listener { if (!data.contains("Items." + ID)) { openShop(player, ShopType.SELL, shopCategory.get(player.getUniqueId()), 1); + player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage(player)); + return; } - Inventory inv = Bukkit.createInventory(null, 9, Methods.color(config.getString("Settings.Buying-Item"))); + Inventory inv = plugin.getServer().createInventory(null, 9, Methods.color(config.getString("Settings.Buying-Item"))); List options = new ArrayList<>(); + options.add("Confirm"); options.add("Cancel"); @@ -472,21 +490,26 @@ public class GuiListener implements Listener { inv.setItem(4, itemBuilder.build()); IDs.put(player.getUniqueId(), ID); + player.openInventory(inv); } public static void openBidding(Player player, String ID) { Methods.updateAuction(); + FileConfiguration config = Files.config.getConfiguration(); FileConfiguration data = Files.data.getConfiguration(); if (!data.contains("Items." + ID)) { openShop(player, ShopType.BID, shopCategory.get(player.getUniqueId()), 1); + player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage(player)); + return; } Inventory inv = plugin.getServer().createInventory(null, 27, Methods.color(config.getString("Settings.Bidding-On-Item"))); + if (!bidding.containsKey(player.getUniqueId())) bidding.put(player.getUniqueId(), 0); inv.setItem(9, new ItemBuilder().setMaterial(Material.LIME_STAINED_GLASS_PANE).setName("&a+1").setAmount(1).build()); @@ -512,11 +535,13 @@ public class GuiListener implements Listener { FileConfiguration config = Files.config.getConfiguration(); FileConfiguration data = Files.data.getConfiguration(); + List items = new ArrayList<>(); List ID = new ArrayList<>(); if (!data.contains("Items")) { data.set("Items.Clear", null); + Files.data.save(); } @@ -578,11 +603,13 @@ public class GuiListener implements Listener { } int maxPage = Methods.getMaxPage(items); + for (; page > maxPage; page--); Inventory inv = plugin.getServer().createInventory(null, 54, Methods.color(config.getString("Settings.GUIName") + " #" + page)); List options = new ArrayList<>(); + options.add("WhatIsThis.Viewing"); for (String o : options) { @@ -607,10 +634,12 @@ public class GuiListener implements Listener { for (ItemStack item : Methods.getPage(items, page)) { int slot = inv.firstEmpty(); + inv.setItem(slot, item); } List.put(player.getUniqueId(), new ArrayList<>(Methods.getPageInts(ID, page))); + player.openInventory(inv); } @@ -628,6 +657,7 @@ public class GuiListener implements Listener { if (config.contains("Settings.GUISettings.OtherSettings.Bidding.Lore")) { List lore = new ArrayList<>(); + for (String l : config.getStringList("Settings.GUISettings.OtherSettings.Bidding.Lore")) { lore.add(l.replace("%Bid%", String.valueOf(bid)) .replace("%bid%", String.valueOf(bid)) @@ -644,7 +674,9 @@ public class GuiListener implements Listener { private static ItemStack getBiddingItem(String ID) { FileConfiguration config = Files.config.getConfiguration(); FileConfiguration data = Files.data.getConfiguration(); + ItemStack item = Methods.fromBase64(data.getString("Items." + ID + ".Item")); + List lore = new ArrayList<>(); String price = Methods.getPrice(ID, false); @@ -698,7 +730,9 @@ public class GuiListener implements Listener { private void playSoldSound(@NotNull Player player) { FileConfiguration config = Files.config.getConfiguration(); + String sound = config.getString("Settings.Sold-Item-Sound", ""); + if (sound.isEmpty()) return; try { @@ -709,6 +743,7 @@ public class GuiListener implements Listener { @EventHandler public void onInvClose(InventoryCloseEvent e) { FileConfiguration config = Files.config.getConfiguration(); + Player player = (Player) e.getPlayer(); if (e.getView().getTitle().contains(Methods.color(config.getString("Settings.Bidding-On-Item")))) bidding.remove(player); @@ -718,6 +753,7 @@ public class GuiListener implements Listener { public void onInvClick(InventoryClickEvent e) { FileConfiguration config = Files.config.getConfiguration(); FileConfiguration data = Files.data.getConfiguration(); + Player player = (Player) e.getWhoClicked(); final Inventory inv = e.getClickedInventory(); @@ -735,13 +771,17 @@ public class GuiListener implements Listener { for (Category cat : Category.values()) { if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.Category-Settings." + cat.getName() + ".Name")))) { openShop(player, shopType.get(player.getUniqueId()), cat, 1); + playClick(player); + return; } if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Back.Name")))) { openShop(player, shopType.get(player.getUniqueId()), shopCategory.get(player.getUniqueId()), 1); + playClick(player); + return; } } @@ -767,24 +807,30 @@ public class GuiListener implements Listener { String topBidder = data.getString("Items." + ID + ".TopBidder"); if (plugin.getSupport().getMoney(player) < bid) { - HashMap placeholders = new HashMap<>(); + Map placeholders = new HashMap<>(); + placeholders.put("%Money_Needed%", (bid - plugin.getSupport().getMoney(player)) + ""); placeholders.put("%money_needed%", (bid - plugin.getSupport().getMoney(player)) + ""); + player.sendMessage(Messages.NEED_MORE_MONEY.getMessage(player, placeholders)); + return; } if (data.getLong("Items." + ID + ".Price") > bid) { player.sendMessage(Messages.BID_MORE_MONEY.getMessage(player)); + return; } if (data.getLong("Items." + ID + ".Price") >= bid && !topBidder.equalsIgnoreCase("None")) { player.sendMessage(Messages.BID_MORE_MONEY.getMessage(player)); + return; } - Bukkit.getPluginManager().callEvent(new AuctionNewBidEvent(player, Methods.fromBase64(data.getString("Items." + ID + ".Item")), bid)); + plugin.getServer().getPluginManager().callEvent(new AuctionNewBidEvent(player, Methods.fromBase64(data.getString("Items." + ID + ".Item")), bid)); + data.set("Items." + ID + ".Price", bid); data.set("Items." + ID + ".TopBidder", player.getUniqueId().toString()); @@ -815,13 +861,19 @@ public class GuiListener implements Listener { if (item.getItemMeta().getDisplayName().equals(Methods.color(price))) { try { bidding.put(player.getUniqueId(), (bidding.get(player.getUniqueId()) + priceEdits.get(price))); + inv.setItem(4, getBiddingItem(biddingID.get(player.getUniqueId()))); + inv.setItem(13, getBiddingGlass(player, biddingID.get(player.getUniqueId()))); + playClick(player); + return; } catch (Exception ex) { player.closeInventory(); + player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage(player)); + return; } } @@ -844,62 +896,87 @@ public class GuiListener implements Listener { if (item.getItemMeta().hasDisplayName()) { if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.NextPage.Name")))) { Methods.updateAuction(); + int page = Integer.parseInt(e.getView().getTitle().split("#")[1]); + openShop(player, shopType.get(player.getUniqueId()), shopCategory.get(player.getUniqueId()), page + 1); + playClick(player); + return; } if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.PreviousPage.Name")))) { Methods.updateAuction(); + int page = Integer.parseInt(e.getView().getTitle().split("#")[1]); + if (page == 1) page++; + openShop(player, shopType.get(player.getUniqueId()), shopCategory.get(player.getUniqueId()), page - 1); + playClick(player); + return; } if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Refesh.Name")))) { Methods.updateAuction(); + int page = Integer.parseInt(e.getView().getTitle().split("#")[1]); + openShop(player, shopType.get(player.getUniqueId()), shopCategory.get(player.getUniqueId()), page); + playClick(player); + return; } if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Bidding/Selling.Selling.Name")))) { openShop(player, ShopType.BID, shopCategory.get(player.getUniqueId()), 1); + playClick(player); + return; } if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Bidding/Selling.Bidding.Name")))) { openShop(player, ShopType.SELL, shopCategory.get(player.getUniqueId()), 1); + playClick(player); + return; } if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Cancelled/ExpiredItems.Name")))) { openPlayersExpiredList(player, 1); + playClick(player); + return; } if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.SellingItems.Name")))) { openPlayersCurrentList(player, 1); + playClick(player); + return; } if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Category1.Name")))) { openCategories(player, shopType.get(player.getUniqueId())); + playClick(player); + return; } if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Category2.Name")))) { openCategories(player, shopType.get(player.getUniqueId())); + playClick(player); + return; } @@ -929,7 +1006,8 @@ public class GuiListener implements Listener { if (player.hasPermission("crazyauctions.admin") || player.hasPermission("crazyauctions.force-end")) { if (e.getAction() == InventoryAction.MOVE_TO_OTHER_INVENTORY) { int num = 1; - for (; data.contains("OutOfTime/Cancelled." + num); num++) ; + for (; data.contains("OutOfTime/Cancelled." + num); num++); + String seller = data.getString("Items." + i + ".Seller"); Player sellerPlayer = Methods.getPlayer(seller); @@ -938,17 +1016,24 @@ public class GuiListener implements Listener { } AuctionCancelledEvent event = new AuctionCancelledEvent((sellerPlayer != null ? sellerPlayer : Methods.getOfflinePlayer(seller)), Methods.fromBase64(data.getString("Items." + ID + ".Item")), Reasons.ADMIN_FORCE_CANCEL); - Bukkit.getPluginManager().callEvent(event); + plugin.getServer().getPluginManager().callEvent(event); + data.set("OutOfTime/Cancelled." + num + ".Seller", data.getString("Items." + i + ".Seller")); data.set("OutOfTime/Cancelled." + num + ".Full-Time", data.getLong("Items." + i + ".Full-Time")); data.set("OutOfTime/Cancelled." + num + ".StoreID", data.getInt("Items." + i + ".StoreID")); data.set("OutOfTime/Cancelled." + num + ".Item", data.getString("Items." + ID + ".Item")); data.set("Items." + i, null); + Files.data.save(); + player.sendMessage(Messages.ADMIN_FORCE_CANCELLED.getMessage(player)); + playClick(player); + int page = Integer.parseInt(e.getView().getTitle().split("#")[1]); + openShop(player, shopType.get(player.getUniqueId()), shopCategory.get(player.getUniqueId()), page); + return; } } @@ -966,8 +1051,11 @@ public class GuiListener implements Listener { } inv.setItem(slot, itemBuilder.build()); + playClick(player); - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, runnable, 3 * 20); + + plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, runnable, 3 * 20); + return; } @@ -985,7 +1073,9 @@ public class GuiListener implements Listener { inv.setItem(slot, itemBuilder.build()); playClick(player); - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, runnable, 3 * 20); + + plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, runnable, 3 * 20); + return; } @@ -1001,16 +1091,21 @@ public class GuiListener implements Listener { } inv.setItem(slot, itemBuilder.build()); + playClick(player); - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, runnable, 3 * 20); + + plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, runnable, 3 * 20); return; } playClick(player); + openBidding(player, i); + biddingID.put(player.getUniqueId(), i); } else { playClick(player); + openBuying(player, i); } @@ -1021,8 +1116,11 @@ public class GuiListener implements Listener { if (!T) { playClick(player); + openShop(player, shopType.get(player.getUniqueId()), shopCategory.get(player.getUniqueId()), 1); + player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage(player)); + return; } } @@ -1049,25 +1147,33 @@ public class GuiListener implements Listener { if (!data.contains("Items." + ID)) { playClick(player); + openShop(player, shopType.get(player.getUniqueId()), shopCategory.get(player.getUniqueId()), 1); + player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage(player)); + return; } if (Methods.isInvFull(player)) { playClick(player); + player.closeInventory(); player.sendMessage(Messages.INVENTORY_FULL.getMessage(player)); + return; } if (plugin.getSupport().getMoney(player) < cost) { playClick(player); player.closeInventory(); - HashMap placeholders = new HashMap<>(); + + Map placeholders = new HashMap<>(); placeholders.put("%Money_Needed%", (cost - plugin.getSupport().getMoney(player)) + ""); placeholders.put("%money_needed%", (cost - plugin.getSupport().getMoney(player)) + ""); + player.sendMessage(Messages.NEED_MORE_MONEY.getMessage(player, placeholders)); + return; } @@ -1077,7 +1183,7 @@ public class GuiListener implements Listener { plugin.getSupport().removeMoney(player, cost); plugin.getSupport().addMoney(Methods.getOfflinePlayer(seller), cost); - HashMap placeholders = new HashMap<>(); + Map placeholders = new HashMap<>(); String price = Methods.getPrice(ID, false); @@ -1098,16 +1204,22 @@ public class GuiListener implements Listener { } player.getInventory().addItem(i); + data.set("Items." + ID, null); Files.data.save(); + playClick(player); + openShop(player, shopType.get(player.getUniqueId()), shopCategory.get(player.getUniqueId()), 1); + return; } if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Cancel.Name")))) { openShop(player, shopType.get(player.getUniqueId()), shopCategory.get(player.getUniqueId()), 1); + playClick(player); + return; } } @@ -1118,6 +1230,7 @@ public class GuiListener implements Listener { if (e.getView().getTitle().contains(Methods.color(config.getString("Settings.Players-Current-Items")))) { e.setCancelled(true); + int slot = e.getRawSlot(); if (slot <= inv.getSize()) { @@ -1128,7 +1241,9 @@ public class GuiListener implements Listener { if (item.getItemMeta().hasDisplayName()) { if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Back.Name")))) { openShop(player, shopType.get(player.getUniqueId()), shopCategory.get(player.getUniqueId()), 1); + playClick(player); + return; } } @@ -1142,18 +1257,26 @@ public class GuiListener implements Listener { int ID = data.getInt("Items." + i + ".StoreID"); if (id == ID) { player.sendMessage(Messages.CANCELLED_ITEM.getMessage(player)); + AuctionCancelledEvent event = new AuctionCancelledEvent(player, Methods.fromBase64(data.getString("Items." + i + ".Item")), Reasons.PLAYER_FORCE_CANCEL); - Bukkit.getPluginManager().callEvent(event); + plugin.getServer().getPluginManager().callEvent(event); + int num = 1; for (; data.contains("OutOfTime/Cancelled." + num); num++) ; + data.set("OutOfTime/Cancelled." + num + ".Seller", data.getString("Items." + i + ".Seller")); data.set("OutOfTime/Cancelled." + num + ".Full-Time", data.getLong("Items." + i + ".Full-Time")); data.set("OutOfTime/Cancelled." + num + ".StoreID", data.getInt("Items." + i + ".StoreID")); data.set("OutOfTime/Cancelled." + num + ".Item", data.getString("Items." + i + ".Item")); + data.set("Items." + i, null); + Files.data.save(); + playClick(player); + openPlayersCurrentList(player, 1); + return; } } @@ -1161,8 +1284,11 @@ public class GuiListener implements Listener { if (!T) { playClick(player); + openShop(player, shopType.get(player.getUniqueId()), shopCategory.get(player.getUniqueId()), 1); + player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage(player)); + return; } } @@ -1174,39 +1300,54 @@ public class GuiListener implements Listener { if (e.getView().getTitle().contains(Methods.color(config.getString("Settings.Cancelled/Expired-Items")))) { e.setCancelled(true); + final int slot = e.getRawSlot(); + if (slot <= inv.getSize()) { if (e.getCurrentItem() != null) { final ItemStack item = e.getCurrentItem(); + if (item.hasItemMeta()) { if (item.getItemMeta().hasDisplayName()) { if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Back.Name")))) { Methods.updateAuction(); + playClick(player); + openShop(player, shopType.get(player.getUniqueId()), shopCategory.get(player.getUniqueId()), 1); + return; } if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.PreviousPage.Name")))) { Methods.updateAuction(); + int page = Integer.parseInt(e.getView().getTitle().split("#")[1]); + if (page == 1) page++; + playClick(player); + openPlayersExpiredList(player, (page - 1)); + return; } if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Return.Name")))) { Methods.updateAuction(); + int page = Integer.parseInt(e.getView().getTitle().split("#")[1]); + if (data.contains("OutOfTime/Cancelled")) { for (String i : data.getConfigurationSection("OutOfTime/Cancelled").getKeys(false)) { if (data.getString("OutOfTime/Cancelled." + i + ".Seller").equalsIgnoreCase(player.getUniqueId().toString())) { if (Methods.isInvFull(player)) { player.sendMessage(Messages.INVENTORY_FULL.getMessage(player)); + break; } else { player.getInventory().addItem(Methods.fromBase64(data.getString("OutOfTime/Cancelled." + i + ".Item"))); + data.set("OutOfTime/Cancelled." + i, null); } } @@ -1214,17 +1355,25 @@ public class GuiListener implements Listener { } player.sendMessage(Messages.GOT_ITEM_BACK.getMessage(player)); + Files.data.save(); + playClick(player); + openPlayersExpiredList(player, page); + return; } if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.NextPage.Name")))) { Methods.updateAuction(); + int page = Integer.parseInt(e.getView().getTitle().split("#")[1]); + playClick(player); + openPlayersExpiredList(player, (page + 1)); + return; } } @@ -1232,21 +1381,30 @@ public class GuiListener implements Listener { if (List.containsKey(player.getUniqueId())) { if (List.get(player.getUniqueId()).size() >= slot) { int id = List.get(player.getUniqueId()).get(slot); + boolean T = false; + if (data.contains("OutOfTime/Cancelled")) { for (String i : data.getConfigurationSection("OutOfTime/Cancelled").getKeys(false)) { int ID = data.getInt("OutOfTime/Cancelled." + i + ".StoreID"); + if (id == ID) { if (!Methods.isInvFull(player)) { player.sendMessage(Messages.GOT_ITEM_BACK.getMessage(player)); + player.getInventory().addItem(Methods.fromBase64(data.getString("OutOfTime/Cancelled." + i + ".Item"))); + data.set("OutOfTime/Cancelled." + i, null); + Files.data.save(); + playClick(player); + openPlayersExpiredList(player, 1); } else { player.sendMessage(Messages.INVENTORY_FULL.getMessage(player)); } + return; } } @@ -1254,7 +1412,9 @@ public class GuiListener implements Listener { if (!T) { playClick(player); + openShop(player, shopType.get(player.getUniqueId()), shopCategory.get(player.getUniqueId()), 1); + player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage(player)); } } diff --git a/src/main/java/com/badbones69/crazyauctions/currency/VaultSupport.java b/src/main/java/com/badbones69/crazyauctions/currency/VaultSupport.java index 599aaca..99fc12e 100644 --- a/src/main/java/com/badbones69/crazyauctions/currency/VaultSupport.java +++ b/src/main/java/com/badbones69/crazyauctions/currency/VaultSupport.java @@ -14,32 +14,32 @@ public class VaultSupport { private Economy vault = null; public Economy getVault() { - return vault; + return this.vault; } public void loadVault() { RegisteredServiceProvider serviceProvider = this.plugin.getServer().getServicesManager().getRegistration(Economy.class); - if (serviceProvider != null) vault = serviceProvider.getProvider(); + if (serviceProvider != null) this.vault = serviceProvider.getProvider(); } - public Long getMoney(@NotNull Player player) { - return (long) vault.getBalance(player); + public long getMoney(@NotNull Player player) { + return (long) this.vault.getBalance(player); } - public void removeMoney(@NotNull Player player, Long amount) { - vault.withdrawPlayer(player, amount); + public void removeMoney(@NotNull Player player, long amount) { + this.vault.withdrawPlayer(player, amount); } - public void removeMoney(@NotNull OfflinePlayer player, Long amount) { - vault.withdrawPlayer(player, amount); + public void removeMoney(@NotNull OfflinePlayer player, long amount) { + this.vault.withdrawPlayer(player, amount); } - public void addMoney(Player player, Long amount) { - vault.depositPlayer(player, amount); + public void addMoney(Player player, long amount) { + this.vault.depositPlayer(player, amount); } - public void addMoney(OfflinePlayer player, Long amount) { - vault.depositPlayer(player, amount); + public void addMoney(OfflinePlayer player, long amount) { + this.vault.depositPlayer(player, amount); } } \ No newline at end of file