From a709c220ee97ae8a79cb813aac407e9ac3b0a534 Mon Sep 17 00:00:00 2001 From: BadBones69 Date: Sat, 21 Jul 2018 22:06:23 -0400 Subject: [PATCH] v1.2.6 Update Added: - New options to disable and enable the Selling and Bidding features. - New messages in the Messages.yml. Changes: - Recoded how the whole messaging system works. - Recoded the file system and how all yml files are accessed and controlled. --- pom.xml | 12 +- .../me/badbones69/crazyauctions/Main.java | 154 +++--- .../me/badbones69/crazyauctions/Methods.java | 60 +-- .../crazyauctions/api/CrazyAuctions.java | 39 +- .../crazyauctions/api/FileManager.java | 465 ++++++++++++++++++ .../crazyauctions/api/Messages.java | 211 ++++++++ .../crazyauctions/api/SettingsManager.java | 140 ------ .../crazyauctions/api/ShopType.java | 10 +- .../{controlers => controllers}/GUI.java | 140 +++--- .../currency/CurrencyManager.java | 35 +- .../crazyauctions/currency/Vault.java | 5 +- src/main/resources/Messages.yml | 23 +- src/main/resources/config.yml | 3 + 13 files changed, 945 insertions(+), 352 deletions(-) create mode 100644 src/main/java/me/badbones69/crazyauctions/api/FileManager.java create mode 100644 src/main/java/me/badbones69/crazyauctions/api/Messages.java delete mode 100644 src/main/java/me/badbones69/crazyauctions/api/SettingsManager.java rename src/main/java/me/badbones69/crazyauctions/{controlers => controllers}/GUI.java (88%) diff --git a/pom.xml b/pom.xml index b360c42..39d3c27 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ me.badbones69 crazyauctions - 1.2.5.1 + 1.2.6 @@ -17,6 +17,10 @@ vault-repo http://nexus.hc.to/content/repositories/pub_releases + + reserve-repo + https://dl.bintray.com/theneweconomy/java/ + @@ -32,6 +36,12 @@ 1.6 provided + + net.tnemc + Reserve + 0.1.0.10 + provided + diff --git a/src/main/java/me/badbones69/crazyauctions/Main.java b/src/main/java/me/badbones69/crazyauctions/Main.java index 1b1b94f..31d2939 100644 --- a/src/main/java/me/badbones69/crazyauctions/Main.java +++ b/src/main/java/me/badbones69/crazyauctions/Main.java @@ -1,12 +1,10 @@ package me.badbones69.crazyauctions; import com.massivestats.MassiveStats; -import me.badbones69.crazyauctions.api.Category; -import me.badbones69.crazyauctions.api.CrazyAuctions; -import me.badbones69.crazyauctions.api.SettingsManager; -import me.badbones69.crazyauctions.api.ShopType; +import me.badbones69.crazyauctions.api.*; +import me.badbones69.crazyauctions.api.FileManager.Files; import me.badbones69.crazyauctions.api.events.AuctionListEvent; -import me.badbones69.crazyauctions.controlers.GUI; +import me.badbones69.crazyauctions.controllers.GUI; import me.badbones69.crazyauctions.currency.Vault; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -22,18 +20,19 @@ import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitRunnable; import java.util.ArrayList; +import java.util.HashMap; import java.util.Random; public class Main extends JavaPlugin implements Listener { - public static SettingsManager settings = SettingsManager.getInstance(); - public static CrazyAuctions auc = CrazyAuctions.getInstance(); + public static FileManager fileManager = FileManager.getInstance(); + public static CrazyAuctions crazyAuctions = CrazyAuctions.getInstance(); @Override public void onEnable() { saveDefaultConfig(); - settings.setup(this); - // Methods.hasUpdate(); + fileManager.logInfo(true).setup(this); + crazyAuctions.loadCrazyAuctions(); Bukkit.getServer().getPluginManager().registerEvents(this, this); Bukkit.getServer().getPluginManager().registerEvents(new GUI(), this); Methods.updateAuction(); @@ -45,13 +44,14 @@ public class Main extends JavaPlugin implements Listener { MassiveStats massiveStats = new MassiveStats(this); }catch(Exception e) { } + Messages.addMissingMessages(); } @Override public void onDisable() { int file = 0; Bukkit.getScheduler().cancelTask(file); - settings.saveData(); + Files.DATA.saveFile(); } public boolean onCommand(CommandSender sender, Command cmd, String commandLable, String[] args) { @@ -59,40 +59,42 @@ public class Main extends JavaPlugin implements Listener { if(args.length == 0) { if(!Methods.hasPermission(sender, "Access")) return true; if(!(sender instanceof Player)) { - sender.sendMessage(Methods.getPrefix() + Methods.color(settings.getMsg().getString("Messages.Players-Only"))); + sender.sendMessage(Messages.PLAYERS_ONLY.getMessage()); return true; } Player player = (Player) sender; - if(settings.getConfig().contains("Settings.Category-Page-Opens-First")) { - if(settings.getConfig().getBoolean("Settings.Category-Page-Opens-First")) { - GUI.openCateories(player, ShopType.SELL); + if(Files.CONFIG.getFile().contains("Settings.Category-Page-Opens-First")) { + if(Files.CONFIG.getFile().getBoolean("Settings.Category-Page-Opens-First")) { + GUI.openCategories(player, ShopType.SELL); return true; } } - GUI.openShop(player, ShopType.SELL, Category.NONE, 1); + if(crazyAuctions.isSellingEnabled()) { + GUI.openShop(player, ShopType.SELL, Category.NONE, 1); + }else if(crazyAuctions.isBiddingEnabled()) { + GUI.openShop(player, ShopType.BID, Category.NONE, 1); + }else { + player.sendMessage(Methods.getPrefix() + Methods.color("&cThe bidding and selling options are both disabled. Please contact the admin about this.")); + } return true; } if(args.length >= 1) { if(args[0].equalsIgnoreCase("Help")) {// CA Help if(!Methods.hasPermission(sender, "Access")) return true; - for(String msg : settings.getMsg().getStringList("Messages.Help-Menu")) { - sender.sendMessage(Methods.color(msg)); - } + sender.sendMessage(Messages.HELP.getMessage()); return true; } if(args[0].equalsIgnoreCase("Reload")) {// CA Reload if(!Methods.hasPermission(sender, "Admin")) return true; - settings.reloadConfig(); - settings.reloadData(); - settings.reloadMsg(); - settings.setup(this); - sender.sendMessage(Methods.getPrefix() + Methods.color(settings.getMsg().getString("Messages.Reload"))); + fileManager.logInfo(true).setup(this); + crazyAuctions.loadCrazyAuctions(); + sender.sendMessage(Messages.RELOAD.getMessage()); return true; } - if(args[0].equalsIgnoreCase("View")) {// CA Reload + if(args[0].equalsIgnoreCase("View")) {// CA View if(!Methods.hasPermission(sender, "View")) return true; if(!(sender instanceof Player)) { - sender.sendMessage(Methods.getPrefix() + Methods.color(settings.getMsg().getString("Messages.Players-Only"))); + sender.sendMessage(Messages.PLAYERS_ONLY.getMessage()); return true; } if(args.length >= 2) { @@ -100,13 +102,13 @@ public class Main extends JavaPlugin implements Listener { GUI.openViewer(player, args[1], 1); return true; } - sender.sendMessage(Methods.getPrefix() + Methods.color("&c/CA View ")); + sender.sendMessage(Messages.CRAZYAUCTIONS_VIEW.getMessage()); return true; } if(args[0].equalsIgnoreCase("Expired") || args[0].equalsIgnoreCase("Collect")) {// CA Expired if(!Methods.hasPermission(sender, "Access")) return true; if(!(sender instanceof Player)) { - sender.sendMessage(Methods.getPrefix() + Methods.color(settings.getMsg().getString("Messages.Players-Only"))); + sender.sendMessage(Messages.PLAYERS_ONLY.getMessage()); return true; } Player player = (Player) sender; @@ -116,7 +118,7 @@ public class Main extends JavaPlugin implements Listener { if(args[0].equalsIgnoreCase("Listed")) {// CA Listed if(!Methods.hasPermission(sender, "Access")) return true; if(!(sender instanceof Player)) { - sender.sendMessage(Methods.getPrefix() + Methods.color(settings.getMsg().getString("Messages.Players-Only"))); + sender.sendMessage(Messages.PLAYERS_ONLY.getMessage()); return true; } Player player = (Player) sender; @@ -125,22 +127,32 @@ public class Main extends JavaPlugin implements Listener { } if(args[0].equalsIgnoreCase("Sell") || args[0].equalsIgnoreCase("Bid")) {// /CA Sell/Bid [Amount of Items] if(!(sender instanceof Player)) { - sender.sendMessage(Methods.getPrefix() + Methods.color(settings.getMsg().getString("Messages.Players-Only"))); + sender.sendMessage(Messages.PLAYERS_ONLY.getMessage()); return true; } if(args.length >= 2) { Player player = (Player) sender; if(args[0].equalsIgnoreCase("Sell")) { + if(!crazyAuctions.isSellingEnabled()) { + player.sendMessage(Messages.SELLING_DISABLED.getMessage()); + return true; + } if(!Methods.hasPermission(player, "Sell")) return true; } if(args[0].equalsIgnoreCase("Bid")) { + if(!crazyAuctions.isBiddingEnabled()) { + player.sendMessage(Messages.BIDDING_DISABLED.getMessage()); + return true; + } if(!Methods.hasPermission(player, "Bid")) return true; } ItemStack item = Methods.getItemInHand(player); int amount = item.getAmount(); if(args.length >= 3) { if(!Methods.isInt(args[2])) { - player.sendMessage(Methods.getPrefix() + Methods.color(settings.getMsg().getString("Messages.Not-A-Number").replaceAll("%Arg%", args[2]).replaceAll("%arg%", args[2]))); + HashMap placeholders = new HashMap<>(); + placeholders.put("%Arg%", args[2]); + player.sendMessage(Messages.NOT_A_NUMBER.getMessage(placeholders)); return true; } amount = Integer.parseInt(args[2]); @@ -148,30 +160,32 @@ public class Main extends JavaPlugin implements Listener { if(amount > item.getAmount()) amount = item.getAmount(); } if(!Methods.isLong(args[1])) { - player.sendMessage(Methods.getPrefix() + Methods.color(settings.getMsg().getString("Messages.Not-A-Number").replaceAll("%Arg%", args[1]).replaceAll("%arg%", args[1]))); + HashMap placeholders = new HashMap<>(); + placeholders.put("%Arg%", args[1]); + player.sendMessage(Messages.NOT_A_NUMBER.getMessage(placeholders)); return true; } if(Methods.getItemInHand(player).getType() == Material.AIR) { - player.sendMessage(Methods.getPrefix() + Methods.color(settings.getMsg().getString("Messages.Doesnt-Have-Item-In-Hand"))); + player.sendMessage(Messages.DOSENT_HAVE_ITEM_IN_HAND.getMessage()); return false; } Long price = Long.parseLong(args[1]); if(args[0].equalsIgnoreCase("Bid")) { - if(price < settings.getConfig().getLong("Settings.Minimum-Bid-Price")) { - player.sendMessage(Methods.getPrefix() + Methods.color(settings.getMsg().getString("Messages.Bid-Price-To-Low"))); + if(price < Files.CONFIG.getFile().getLong("Settings.Minimum-Bid-Price")) { + player.sendMessage(Messages.BID_PRICE_TO_LOW.getMessage()); return true; } - if(price > settings.getConfig().getLong("Settings.Max-Beginning-Bid-Price")) { - player.sendMessage(Methods.getPrefix() + Methods.color(settings.getMsg().getString("Messages.Bid-Price-To-High"))); + if(price > Files.CONFIG.getFile().getLong("Settings.Max-Beginning-Bid-Price")) { + player.sendMessage(Messages.BID_PRICE_TO_HIGH.getMessage()); return true; } }else { - if(price < settings.getConfig().getLong("Settings.Minimum-Sell-Price")) { - player.sendMessage(Methods.getPrefix() + Methods.color(settings.getMsg().getString("Messages.Sell-Price-To-Low"))); + if(price < Files.CONFIG.getFile().getLong("Settings.Minimum-Sell-Price")) { + player.sendMessage(Messages.SELL_PRICE_TO_LOW.getMessage()); return true; } - if(price > settings.getConfig().getLong("Settings.Max-Beginning-Sell-Price")) { - player.sendMessage(Methods.getPrefix() + Methods.color(settings.getMsg().getString("Messages.Sell-Price-To-High"))); + if(price > Files.CONFIG.getFile().getLong("Settings.Max-Beginning-Sell-Price")) { + player.sendMessage(Messages.SELL_PRICE_TO_HIGH.getMessage()); return true; } } @@ -210,29 +224,29 @@ public class Main extends JavaPlugin implements Listener { } } if(args[0].equalsIgnoreCase("Sell")) { - if(auc.getItems(player, ShopType.SELL).size() >= SellLimit) { - player.sendMessage(Methods.getPrefix() + Methods.color(settings.getMsg().getString("Messages.Max-Items"))); + if(crazyAuctions.getItems(player, ShopType.SELL).size() >= SellLimit) { + player.sendMessage(Messages.MAX_ITEMS.getMessage()); return true; } } if(args[0].equalsIgnoreCase("Bid")) { - if(auc.getItems(player, ShopType.BID).size() >= BidLimit) { - player.sendMessage(Methods.getPrefix() + Methods.color(settings.getMsg().getString("Messages.Max-Items"))); + if(crazyAuctions.getItems(player, ShopType.BID).size() >= BidLimit) { + player.sendMessage(Messages.MAX_ITEMS.getMessage()); return true; } } } - for(String id : settings.getConfig().getStringList("Settings.BlackList")) { + for(String id : Files.CONFIG.getFile().getStringList("Settings.BlackList")) { if(item.getType() == Methods.makeItem(id, 1).getType()) { - player.sendMessage(Methods.getPrefix() + Methods.color(settings.getMsg().getString("Messages.Item-BlackListed"))); + player.sendMessage(Messages.ITEM_BLACKLISTED.getMessage()); return true; } } - if(!settings.getConfig().getBoolean("Settings.Allow-Damaged-Items")) { + if(!Files.CONFIG.getFile().getBoolean("Settings.Allow-Damaged-Items")) { for(Material i : getDamageableItems()) { if(item.getType() == i) { if(item.getDurability() > 0) { - player.sendMessage(Methods.getPrefix() + Methods.color(settings.getMsg().getString("Messages.Item-Damaged"))); + player.sendMessage(Messages.ITEM_DAMAGED.getMessage()); return true; } } @@ -241,38 +255,40 @@ public class Main extends JavaPlugin implements Listener { String seller = player.getName(); int num = 1; Random r = new Random(); - for(; settings.getData().contains("Items." + num); num++) ; - settings.getData().set("Items." + num + ".Price", price); - settings.getData().set("Items." + num + ".Seller", seller); + for(; Files.DATA.getFile().contains("Items." + num); num++) ; + Files.DATA.getFile().set("Items." + num + ".Price", price); + Files.DATA.getFile().set("Items." + num + ".Seller", seller); if(args[0].equalsIgnoreCase("Bid")) { - settings.getData().set("Items." + num + ".Time-Till-Expire", Methods.convertToMill(settings.getConfig().getString("Settings.Bid-Time"))); + Files.DATA.getFile().set("Items." + num + ".Time-Till-Expire", Methods.convertToMill(Files.CONFIG.getFile().getString("Settings.Bid-Time"))); }else { - settings.getData().set("Items." + num + ".Time-Till-Expire", Methods.convertToMill(settings.getConfig().getString("Settings.Sell-Time"))); + Files.DATA.getFile().set("Items." + num + ".Time-Till-Expire", Methods.convertToMill(Files.CONFIG.getFile().getString("Settings.Sell-Time"))); } - settings.getData().set("Items." + num + ".Full-Time", Methods.convertToMill(settings.getConfig().getString("Settings.Full-Expire-Time"))); + Files.DATA.getFile().set("Items." + num + ".Full-Time", Methods.convertToMill(Files.CONFIG.getFile().getString("Settings.Full-Expire-Time"))); int id = r.nextInt(999999); // Runs 3x to check for same ID. - for(String i : settings.getData().getConfigurationSection("Items").getKeys(false)) - if(settings.getData().getInt("Items." + i + ".StoreID") == id) id = r.nextInt(Integer.MAX_VALUE); - for(String i : settings.getData().getConfigurationSection("Items").getKeys(false)) - if(settings.getData().getInt("Items." + i + ".StoreID") == id) id = r.nextInt(Integer.MAX_VALUE); - for(String i : settings.getData().getConfigurationSection("Items").getKeys(false)) - if(settings.getData().getInt("Items." + i + ".StoreID") == id) id = r.nextInt(Integer.MAX_VALUE); - settings.getData().set("Items." + num + ".StoreID", id); + for(String i : Files.DATA.getFile().getConfigurationSection("Items").getKeys(false)) + if(Files.DATA.getFile().getInt("Items." + i + ".StoreID") == id) id = r.nextInt(Integer.MAX_VALUE); + for(String i : Files.DATA.getFile().getConfigurationSection("Items").getKeys(false)) + if(Files.DATA.getFile().getInt("Items." + i + ".StoreID") == id) id = r.nextInt(Integer.MAX_VALUE); + for(String i : Files.DATA.getFile().getConfigurationSection("Items").getKeys(false)) + if(Files.DATA.getFile().getInt("Items." + i + ".StoreID") == id) id = r.nextInt(Integer.MAX_VALUE); + Files.DATA.getFile().set("Items." + num + ".StoreID", id); ShopType type = ShopType.SELL; if(args[0].equalsIgnoreCase("Bid")) { - settings.getData().set("Items." + num + ".Biddable", true); + Files.DATA.getFile().set("Items." + num + ".Biddable", true); type = ShopType.BID; }else { - settings.getData().set("Items." + num + ".Biddable", false); + Files.DATA.getFile().set("Items." + num + ".Biddable", false); } - settings.getData().set("Items." + num + ".TopBidder", "None"); + Files.DATA.getFile().set("Items." + num + ".TopBidder", "None"); ItemStack I = item.clone(); I.setAmount(amount); - settings.getData().set("Items." + num + ".Item", I); - settings.saveData(); + Files.DATA.getFile().set("Items." + num + ".Item", I); + Files.DATA.saveFile(); Bukkit.getPluginManager().callEvent(new AuctionListEvent(player, type, I, price)); - player.sendMessage(Methods.getPrefix() + Methods.color(settings.getMsg().getString("Messages.Added-Item-To-Auction").replaceAll("%Price%", price + "").replaceAll("%price%", price + ""))); + HashMap placeholders = new HashMap<>(); + placeholders.put("%Price%", price + ""); + player.sendMessage(Messages.ADDED_ITEM_TO_AUCTION.getMessage(placeholders)); if(item.getAmount() <= 1 || (item.getAmount() - amount) <= 0) { Methods.setItemInHand(player, new ItemStack(Material.AIR)); }else { @@ -280,12 +296,12 @@ public class Main extends JavaPlugin implements Listener { } return false; } - sender.sendMessage(Methods.getPrefix() + Methods.color("/CA Sell/Bid [Amount of items]")); + sender.sendMessage(Messages.CRAZYAUCTIONS_SELL_BID.getMessage()); return true; } } } - sender.sendMessage(Methods.getPrefix() + Methods.color("/CA Help")); + sender.sendMessage(Messages.CRAZYAUCTIONS_HELP.getMessage()); return false; } diff --git a/src/main/java/me/badbones69/crazyauctions/Methods.java b/src/main/java/me/badbones69/crazyauctions/Methods.java index 94e6bb9..772b882 100644 --- a/src/main/java/me/badbones69/crazyauctions/Methods.java +++ b/src/main/java/me/badbones69/crazyauctions/Methods.java @@ -1,5 +1,8 @@ package me.badbones69.crazyauctions; +import me.badbones69.crazyauctions.api.FileManager; +import me.badbones69.crazyauctions.api.FileManager.Files; +import me.badbones69.crazyauctions.api.Messages; import me.badbones69.crazyauctions.api.events.AuctionWinBidEvent; import me.badbones69.crazyauctions.currency.CurrencyManager; import org.bukkit.*; @@ -12,25 +15,27 @@ import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.plugin.Plugin; import java.text.NumberFormat; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.List; -import java.util.Map; +import java.util.*; public class Methods { public static Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("CrazyAuctions"); + private static FileManager fileManager = FileManager.getInstance(); public static String color(String msg) { return ChatColor.translateAlternateColorCodes('&', msg); } - public static String removeColor(String msg) { - return ChatColor.stripColor(msg); + public static String getPrefix() { + return color(Files.CONFIG.getFile().getString("Settings.Prefix")); } - public static String getPrefix() { - return color(Main.settings.getConfig().getString("Settings.Prefix")); + public static String getPrefix(String msg) { + return color(Files.CONFIG.getFile().getString("Settings.Prefix") + msg); + } + + public static String removeColor(String msg) { + return ChatColor.stripColor(msg); } public static ItemStack makeItem(String type, int amount) { @@ -41,7 +46,7 @@ public class Methods { ty = Integer.parseInt(b[1]); } Material m = Material.matchMaterial(type); - ItemStack item = null; + ItemStack item; try { item = new ItemStack(m, amount, (short) ty); }catch(Exception e) { @@ -58,7 +63,7 @@ public class Methods { ty = Integer.parseInt(b[1]); } Material m = Material.matchMaterial(type); - ItemStack item = null; + ItemStack item; try { item = new ItemStack(m, amount, (short) ty); }catch(Exception e) { @@ -79,7 +84,7 @@ public class Methods { ty = Integer.parseInt(b[1]); } Material m = Material.matchMaterial(type); - ItemStack item = null; + ItemStack item; try { item = new ItemStack(m, amount, (short) ty); }catch(Exception e) { @@ -222,13 +227,13 @@ public class Methods { return true; } } - p.sendMessage(color(Main.settings.getMsg().getString("Messages.Not-Online"))); + p.sendMessage(Messages.NOT_ONLINE.getMessage()); return false; } public static boolean hasPermission(Player player, String perm) { if(!player.hasPermission("crazyauctions." + perm)) { - player.sendMessage(color(Main.settings.getMsg().getString("Messages.No-Permission"))); + player.sendMessage(Messages.NO_PERMISSION.getMessage()); return false; } return true; @@ -238,7 +243,7 @@ public class Methods { if(sender instanceof Player) { Player player = (Player) sender; if(!player.hasPermission("crazyauctions." + perm)) { - player.sendMessage(color(Main.settings.getMsg().getString("Messages.No-Permission"))); + player.sendMessage(Messages.NO_PERMISSION.getMessage()); return false; }else { return true; @@ -331,15 +336,11 @@ public class Methods { } public static boolean isInvFull(Player player) { - if(player.getInventory().firstEmpty() == -1) { - return true; - } - return false; + return player.getInventory().firstEmpty() == -1; } public static void updateAuction() { - FileConfiguration data = Main.settings.getData(); - FileConfiguration msg = Main.settings.getMsg(); + FileConfiguration data = Files.DATA.getFile(); Calendar cal = Calendar.getInstance(); Calendar expireTime = Calendar.getInstance(); Calendar fullExpireTime = Calendar.getInstance(); @@ -364,14 +365,17 @@ public class Methods { Long price = data.getLong("Items." + i + ".Price"); CurrencyManager.addMoney(Methods.getOfflinePlayer(seller), price); CurrencyManager.removeMoney(Methods.getOfflinePlayer(winner), price); + HashMap placeholders = new HashMap<>(); + placeholders.put("%Price%", getPrice(i, false)); + placeholders.put("%Player%", winner); if(Methods.isOnline(winner)) { Player player = Methods.getPlayer(winner); Bukkit.getPluginManager().callEvent(new AuctionWinBidEvent(player, data.getItemStack("Items." + i + ".Item"), price)); - player.sendMessage(Methods.getPrefix() + Methods.color(msg.getString("Messages.Win-Bidding").replaceAll("%Price%", getPrice(i, false)).replaceAll("%price%", getPrice(i, false)))); + player.sendMessage(Messages.WIN_BIDDING.getMessage(placeholders)); } if(Methods.isOnline(seller)) { Player player = Methods.getPlayer(seller); - player.sendMessage(Methods.getPrefix() + Methods.color(msg.getString("Messages.Someone-Won-Players-Bid").replaceAll("%Price%", getPrice(i, false)).replaceAll("%price%", getPrice(i, false)).replaceAll("%Player%", winner).replaceAll("%player%", winner))); + player.sendMessage(Messages.SOMEONE_WON_PLAYERS_BID.getMessage(placeholders)); } data.set("OutOfTime/Cancelled." + num + ".Seller", winner); data.set("OutOfTime/Cancelled." + num + ".Full-Time", fullExpireTime.getTimeInMillis()); @@ -381,7 +385,7 @@ public class Methods { String seller = data.getString("Items." + i + ".Seller"); if(Methods.isOnline(seller)) { Player player = Methods.getPlayer(seller); - player.sendMessage(Methods.getPrefix() + Methods.color(msg.getString("Messages.Item-Has-Expired"))); + player.sendMessage(Messages.ITEM_HAS_EXPIRED.getMessage()); } data.set("OutOfTime/Cancelled." + num + ".Seller", data.getString("Items." + i + ".Seller")); data.set("OutOfTime/Cancelled." + num + ".Full-Time", fullExpireTime.getTimeInMillis()); @@ -392,18 +396,18 @@ public class Methods { } } } - Main.settings.saveData(); + Files.DATA.saveFile(); } public static String getPrice(String ID, Boolean Expired) { Long price = 0L; if(Expired) { - if(Main.settings.getData().contains("OutOfTime/Cancelled." + ID + ".Price")) { - price = Main.settings.getData().getLong("OutOfTime/Cancelled." + ID + ".Price"); + if(Files.DATA.getFile().contains("OutOfTime/Cancelled." + ID + ".Price")) { + price = Files.DATA.getFile().getLong("OutOfTime/Cancelled." + ID + ".Price"); } }else { - if(Main.settings.getData().contains("Items." + ID + ".Price")) { - price = Main.settings.getData().getLong("Items." + ID + ".Price"); + if(Files.DATA.getFile().contains("Items." + ID + ".Price")) { + price = Files.DATA.getFile().getLong("Items." + ID + ".Price"); } } return NumberFormat.getNumberInstance().format(price); diff --git a/src/main/java/me/badbones69/crazyauctions/api/CrazyAuctions.java b/src/main/java/me/badbones69/crazyauctions/api/CrazyAuctions.java index ed670c3..ac45462 100644 --- a/src/main/java/me/badbones69/crazyauctions/api/CrazyAuctions.java +++ b/src/main/java/me/badbones69/crazyauctions/api/CrazyAuctions.java @@ -1,6 +1,6 @@ package me.badbones69.crazyauctions.api; -import me.badbones69.crazyauctions.Main; +import me.badbones69.crazyauctions.api.FileManager.Files; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -9,18 +9,39 @@ import java.util.ArrayList; public class CrazyAuctions { - public static CrazyAuctions instance; + private static CrazyAuctions instance = new CrazyAuctions(); + private FileManager fileManager = FileManager.getInstance(); + private Boolean sellingEnabled; + private Boolean biddingEnabled; public static CrazyAuctions getInstance() { - if(instance == null) { - instance = new CrazyAuctions(); - } return instance; } + public void loadCrazyAuctions() { + if(Files.CONFIG.getFile().contains("Settings.Feature-Toggle.Selling")) { + this.sellingEnabled = Files.CONFIG.getFile().getBoolean("Settings.Feature-Toggle.Selling"); + }else { + this.sellingEnabled = true; + } + if(Files.CONFIG.getFile().contains("Settings.Feature-Toggle.Bidding")) { + this.biddingEnabled = Files.CONFIG.getFile().getBoolean("Settings.Feature-Toggle.Bidding"); + }else { + this.biddingEnabled = true; + } + } + + public Boolean isSellingEnabled() { + return sellingEnabled; + } + + public Boolean isBiddingEnabled() { + return biddingEnabled; + } + public ArrayList getItems(Player player) { - FileConfiguration data = Main.settings.getData(); - ArrayList items = new ArrayList(); + FileConfiguration data = Files.DATA.getFile(); + ArrayList items = new ArrayList<>(); if(data.contains("Items")) { for(String i : data.getConfigurationSection("Items").getKeys(false)) { if(data.getString("Items." + i + ".Seller").equalsIgnoreCase(player.getName())) { @@ -32,8 +53,8 @@ public class CrazyAuctions { } public ArrayList getItems(Player player, ShopType type) { - FileConfiguration data = Main.settings.getData(); - ArrayList items = new ArrayList(); + FileConfiguration data = Files.DATA.getFile(); + ArrayList items = new ArrayList<>(); if(data.contains("Items")) { for(String i : data.getConfigurationSection("Items").getKeys(false)) { if(data.getString("Items." + i + ".Seller").equalsIgnoreCase(player.getName())) { diff --git a/src/main/java/me/badbones69/crazyauctions/api/FileManager.java b/src/main/java/me/badbones69/crazyauctions/api/FileManager.java new file mode 100644 index 0000000..ae118e7 --- /dev/null +++ b/src/main/java/me/badbones69/crazyauctions/api/FileManager.java @@ -0,0 +1,465 @@ +package me.badbones69.crazyauctions.api; + +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.plugin.Plugin; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.HashMap; + +/** + * + * @author BadBones69 + * @version v1.0 + * + */ +public class FileManager { + + private Plugin plugin; + private String prefix = ""; + private Boolean log = false; + private HashMap files = new HashMap<>(); + private ArrayList homeFolders = new ArrayList<>(); + private ArrayList customFiles = new ArrayList<>(); + private HashMap autoGenerateFiles = new HashMap<>(); + private HashMap configurations = new HashMap<>(); + + private static FileManager instance = new FileManager(); + + public static FileManager getInstance() { + return instance; + } + + /** + * Sets up the plugin and loads all necessary files. + * @param plugin The plugin this is getting loading for. + */ + public FileManager setup(Plugin plugin) { + prefix = "[" + plugin.getName() + "] "; + this.plugin = plugin; + if(!plugin.getDataFolder().exists()) { + plugin.getDataFolder().mkdirs(); + } + files.clear(); + customFiles.clear(); + //Loads all the normal static files. + for(Files file : Files.values()) { + File newFile = new File(plugin.getDataFolder(), file.getFileLocation()); + if(log) System.out.println(prefix + "Loading the " + file.getFileName()); + if(!newFile.exists()) { + try { + File serverFile = new File(plugin.getDataFolder(), "/" + file.getFileLocation()); + InputStream jarFile = getClass().getResourceAsStream("/" + file.getFileLocation()); + copyFile(jarFile, serverFile); + }catch(Exception e) { + if(log) System.out.println(prefix + "Failed to load " + file.getFileName()); + e.printStackTrace(); + continue; + } + } + files.put(file, newFile); + configurations.put(file, YamlConfiguration.loadConfiguration(newFile)); + if(log) System.out.println(prefix + "Successfully loaded " + file.getFileName()); + } + //Starts to load all the custom files. + if(homeFolders.size() > 0) { + if(log) System.out.println(prefix + "Loading custom files."); + for(String homeFolder : homeFolders) { + File homeFile = new File(plugin.getDataFolder(), "/" + homeFolder); + if(homeFile.exists()) { + String[] list = homeFile.list(); + if(list != null) { + for(String name : list) { + if(name.endsWith(".yml")) { + CustomFile file = new CustomFile(name, homeFolder, plugin); + if(file.exists()) { + customFiles.add(file); + if(log) System.out.println(prefix + "Loaded new custom file: " + homeFolder + "/" + name + "."); + } + } + } + } + + }else { + homeFile.mkdir(); + if(log) System.out.println(prefix + "The folder " + homeFolder + "/ was not found so it was created."); + for(String fileName : autoGenerateFiles.keySet()) { + if(autoGenerateFiles.get(fileName).equalsIgnoreCase(homeFolder)) { + homeFolder = autoGenerateFiles.get(fileName); + try { + File serverFile = new File(plugin.getDataFolder(), homeFolder + "/" + fileName); + InputStream jarFile = getClass().getResourceAsStream(homeFolder + "/" + fileName); + copyFile(jarFile, serverFile); + if(fileName.toLowerCase().endsWith(".yml")) { + customFiles.add(new CustomFile(fileName, homeFolder, plugin)); + } + if(log) System.out.println(prefix + "Created new default file: " + homeFolder + "/" + fileName + "."); + }catch(Exception e) { + if(log) System.out.println(prefix + "Failed to create new default file: " + homeFolder + "/" + fileName + "!"); + e.printStackTrace(); + } + } + } + } + } + if(log) System.out.println(prefix + "Finished loading custom files."); + } + return this; + } + + /** + * Turn on the logger system for the FileManager. + * @param log True to turn it on and false for it to be off. + */ + public FileManager logInfo(Boolean log) { + this.log = log; + return this; + } + + /** + * Check if the logger is logging in console. + * @return True if it is and false if it isn't. + */ + public Boolean isLogging() { + return log; + } + + /** + * Register a folder that has custom files in it. Make sure to have a "/" in front of the folder name. + * @param homeFolder The folder that has custom files in it. + */ + public FileManager registerCustomFilesFolder(String homeFolder) { + homeFolders.add(homeFolder); + return this; + } + + /** + * Unregister a folder that has custom files in it. Make sure to have a "/" in front of the folder name. + * @param homeFolder The folder with custom files in it. + */ + public FileManager unregisterCustomFilesFolder(String homeFolder) { + homeFolders.remove(homeFolder); + return this; + } + + /** + * Register a file that needs to be generated when it's home folder doesn't exist. Make sure to have a "/" in front of the home folder's name. + * @param fileName The name of the file you want to auto-generate when the folder doesn't exist. + * @param homeFolder The folder that has custom files in it. + */ + public FileManager registerDefaultGenerateFiles(String fileName, String homeFolder) { + autoGenerateFiles.put(fileName, homeFolder); + return this; + } + + /** + * Unregister a file that doesn't need to be generated when it's home folder doesn't exist. Make sure to have a "/" in front of the home folder's name. + * @param fileName The file that you want to remove from auto-generating. + */ + public FileManager unregisterDefaultGenerateFiles(String fileName) { + autoGenerateFiles.remove(fileName); + return this; + } + + /** + * Gets the file from the system. + * @return The file from the system. + */ + public FileConfiguration getFile(Files file) { + return configurations.get(file); + } + + /** + * Get a custom file from the loaded custom files instead of a hardcoded one. + * This allows you to get custom files like Per player data files. + * @param name Name of the crate you want. (Without the .yml) + * @return The custom file you wanted otherwise if not found will return null. + */ + public CustomFile getFile(String name) { + for(CustomFile file : customFiles) { + if(file.getName().toLowerCase().equalsIgnoreCase(name.toLowerCase())) { + return file; + } + } + return null; + } + + /** + * Saves the file from the loaded state to the file system. + */ + public void saveFile(Files file) { + try { + configurations.get(file).save(files.get(file)); + }catch(IOException e) { + System.out.println(prefix + "Could not save " + file.getFileName() + "!"); + e.printStackTrace(); + } + } + + /** + * Save a custom file. + * @param name The name of the custom file. + */ + public void saveFile(String name) { + CustomFile file = getFile(name); + if(file != null) { + try { + file.getFile().save(new File(plugin.getDataFolder(), file.getHomeFolder() + "/" + file.getFileName())); + if(log) System.out.println(prefix + "Successfuly saved the " + file.getFileName() + "."); + }catch(Exception e) { + System.out.println(prefix + "Could not save " + file.getFileName() + "!"); + e.printStackTrace(); + } + }else { + if(log) System.out.println(prefix + "The file " + name + ".yml could not be found!"); + } + } + + /** + * Save a custom file. + * @param file The custom file you are saving. + * @return True if the file saved correct and false if there was an error. + */ + public Boolean saveFile(CustomFile file) { + return file.saveFile(); + } + + /** + * Overrides the loaded state file and loads the file systems file. + */ + public void reloadFile(Files file) { + configurations.put(file, YamlConfiguration.loadConfiguration(files.get(file))); + } + + /** + * Overrides the loaded state file and loads the file systems file. + */ + public void reloadFile(String name) { + CustomFile file = getFile(name); + if(file != null) { + try { + file.file = YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder(), "/" + file.getHomeFolder() + "/" + file.getFileName())); + if(log) System.out.println(prefix + "Successfuly reload the " + file.getFileName() + "."); + }catch(Exception e) { + System.out.println(prefix + "Could not reload the " + file.getFileName() + "!"); + e.printStackTrace(); + } + }else { + if(log) System.out.println(prefix + "The file " + name + ".yml could not be found!"); + } + } + + /** + * Overrides the loaded state file and loads the filesystems file. + * @return True if it reloaded correct and false if the file wasn't found. + */ + public Boolean reloadFile(CustomFile file) { + return file.reloadFile(); + } + + /** + * Was found here: https://bukkit.org/threads/extracting-file-from-jar.16962 + */ + private void copyFile(InputStream in, File out) throws Exception { + try(FileOutputStream fos = new FileOutputStream(out)) { + byte[] buf = new byte[1024]; + int i; + while((i = in.read(buf)) != -1) { + fos.write(buf, 0, i); + } + }finally { + if(in != null) { + in.close(); + } + + } + } + + public enum Files { + + //ENUM_NAME("FileName.yml", "FilePath.yml"), + CONFIG("config.yml", "config.yml"), + DATA("Data.yml", "Data.yml"), + MESSAGES("Messages.yml", "Messages.yml"); + + private String fileName; + private String fileLocation; + + /** + * The files that the server will try and load. + * @param fileName The file name that will be in the plugin's folder. + * @param fileLocation The location the file is in while in the Jar. + */ + private Files(String fileName, String fileLocation) { + this.fileName = fileName; + this.fileLocation = fileLocation; + } + + /** + * Get the name of the file. + * @return The name of the file. + */ + public String getFileName() { + return fileName; + } + + /** + * The location the jar it is at. + * @return The location in the jar the file is in. + */ + public String getFileLocation() { + return fileLocation; + } + + /** + * Gets the file from the system. + * @return The file from the system. + */ + public FileConfiguration getFile() { + return getInstance().getFile(this); + } + + /** + * Saves the file from the loaded state to the file system. + */ + public void saveFile() { + getInstance().saveFile(this); + } + + /** + * Overrides the loaded state file and loads the file systems file. + */ + public void relaodFile() { + getInstance().reloadFile(this); + } + + } + + public class CustomFile { + + private String name; + private Plugin plugin; + private String fileName; + private String homeFolder; + private FileConfiguration file; + + /** + * A custom file that is being made. + * @param name Name of the file. + * @param homeFolder The home folder of the file. + * @param plugin The plugin the files belong to. + */ + public CustomFile(String name, String homeFolder, Plugin plugin) { + this.name = name.replace(".yml", ""); + this.plugin = plugin; + this.fileName = name; + this.homeFolder = homeFolder; + if(new File(plugin.getDataFolder(), "/" + homeFolder).exists()) { + if(new File(plugin.getDataFolder(), "/" + homeFolder + "/" + name).exists()) { + file = YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder(), "/" + homeFolder + "/" + name)); + }else { + file = null; + } + }else { + new File(plugin.getDataFolder(), "/" + homeFolder).mkdir(); + if(log) System.out.println(prefix + "The folder " + homeFolder + "/ was not found so it was created."); + file = null; + } + } + + /** + * Get the name of the file without the .yml part. + * @return The name of the file without the .yml. + */ + public String getName() { + return name; + } + + /** + * Get the full name of the file. + * @return Full name of the file. + */ + public String getFileName() { + return fileName; + } + + /** + * Get the name of the home folder of the file. + * @return The name of the home folder the files are in. + */ + public String getHomeFolder() { + return homeFolder; + } + + /** + * Get the plugin the file belongs to. + * @return The plugin the file belongs to. + */ + public Plugin getPlugin() { + return plugin; + } + + /** + * Get the ConfigurationFile. + * @return The ConfigurationFile of this file. + */ + public FileConfiguration getFile() { + return file; + } + + /** + * Check if the file actually exists in the file system. + * @return True if it does and false if it doesn't. + */ + public Boolean exists() { + return file != null; + } + + /** + * Save the custom file. + * @return True if it saved correct and false if something went wrong. + */ + public Boolean saveFile() { + if(file != null) { + try { + file.save(new File(plugin.getDataFolder(), homeFolder + "/" + fileName)); + if(log) System.out.println(prefix + "Successfuly saved the " + fileName + "."); + return true; + }catch(Exception e) { + System.out.println(prefix + "Could not save " + fileName + "!"); + e.printStackTrace(); + return false; + } + }else { + if(log) System.out.println(prefix + "There was a null custom file that could not be found!"); + } + return false; + } + + /** + * Overrides the loaded state file and loads the filesystems file. + * @return True if it reloaded correct and false if the file wasn't found or errored. + */ + public Boolean reloadFile() { + if(file != null) { + try { + file = YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder(), "/" + homeFolder + "/" + fileName)); + if(log) System.out.println(prefix + "Successfuly reload the " + fileName + "."); + return true; + }catch(Exception e) { + System.out.println(prefix + "Could not reload the " + fileName + "!"); + e.printStackTrace(); + } + }else { + if(log) System.out.println(prefix + "There was a null custom file that was not found!"); + } + return false; + } + + } + +} \ No newline at end of file diff --git a/src/main/java/me/badbones69/crazyauctions/api/Messages.java b/src/main/java/me/badbones69/crazyauctions/api/Messages.java new file mode 100644 index 0000000..55c1716 --- /dev/null +++ b/src/main/java/me/badbones69/crazyauctions/api/Messages.java @@ -0,0 +1,211 @@ +package me.badbones69.crazyauctions.api; + +import me.badbones69.crazyauctions.Methods; +import me.badbones69.crazyauctions.api.FileManager.Files; +import org.bukkit.configuration.file.FileConfiguration; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; + +public enum Messages { + + PLAYERS_ONLY("Players-Only", "&cOnly players can use this command."), + RELOAD("Reload", "&7You have just reloaded the Crazy Auctions Files."), + NEED_MORE_MONEY("Need-More-Money", "&cYou are in need of &a$%Money_Needed%&c."), + INVENTORY_FULL("Inventory-Full", "&cYour inventory is too full. Please open up some space to buy that."), + NO_PERMISSION("No-Permission", "&cYou do not have permission to use that command!"), + NOT_ONLINE("Not-Online", "&cThat player is not online at this time."), + DOSENT_HAVE_ITEM_IN_HAND("Doesnt-Have-Item-In-Hand", "&cYou must have an item in your hand."), + NOT_A_NUMBER("Not-A-Number", "&c%Arg% is not a number."), + GOT_ITEM_BACK("Got-Item-Back", "&7Your item has been returned."), + CANCELLED_ITEM("Cancelled-Item", "&7You have cancelled an item on the auction list, return your items with /ah expired."), + ITEM_HAS_EXPIRED("Item-Has-Expired", "&7An item you have in the Crazy Auctions has just expired."), + ADMIN_FORCE_CENCELLED("Admin-Force-Cancelled", "&7You have just force cancelled a sale."), + ADMIN_FORCE_CANCELLED_TO_PLAYER("Admin-Force-Cancelled-To-Player", "&cOne of your items was just force cancelled by an Admin."), + ITEM_DOESNT_EXIST("Item-Doesnt-Exist", "&cThat item isnt in the crazy auctions any more."), + MAX_ITEMS("Max-Items", "&cYou cant list any more items to the Crazy Auctions."), + ITEM_BLACKLISTED("Item-BlackListed", "&cThat item is not allowed to be sold here."), + ITEM_DAMAGED("Item-Damaged", "&cThat item is damaged and is not allowed to be sold here."), + SOLD_MESSAGE("Sold-Msg", "&7Thank you for buying this item."), + BID_MORE_MONEY("Bid-More-Money", "&cYour bid is to low, please bid more."), + NOT_A_CURRENCY("Not-A-Currency", "&cThat is not a currency. Please use Money or Tokens ."), + SELL_PRICE_TO_LOW("Sell-Price-To-Low", "&cYour sell price is to low the minimum is &a$10&c."), + SELL_PRICE_TO_HIGH("Sell-Price-To-High", "&cYour sell price is to high the maximum is &a$1000000&c."), + BID_PRICE_TO_LOW("Bid-Price-To-Low", "&cYour starting bid price is to low the minimum is &a$100&c."), + BID_PRICE_TO_HIGH("Bid-Price-To-High", "&cYour starting bid price is to high the maximum is &a$1000000&c."), + BOUGHT_ITEM("Bought-Item", "&7You have just bought a item for &a$%Price%&7."), + WIN_BIDDING("Win-Bidding", "&7You have just won a bid for &a$%Price%&7. Do /Ah Collect to collect your winnings."), + PLAYER_BOUGHT_ITEM("Player-Bought-Item", "&7%Player% has bought your item for &a$%Price%."), + SOMEONE_WON_PLAYERS_BID("Someone-Won-Players-Bid", "&7%Player% has won your item you from a bid for &a$%Price%."), + ADDED_ITEM_TO_AUCTION("Added-Item-To-Auction", "&7You have just added a item to the crazy auctions for &a$%Price%&7."), + BID_MESSAGE("Bid-Msg", "&7You have just bid &a$%Bid% &7on that item."), + SELLING_DISABLED("Selling-Disabled", "&cThe selling option is disabled."), + BIDDING_DISABLED("Bidding-Disabled", "&cThe bidding option is disabled."), + CRAZYAUCTIONS_HELP("CrazyAuctions-Help", "&c/ah help"), + CRAZYAUCTIONS_VIEW("CrazyAuctions-View", "&c/ah view "), + CRAZYAUCTIONS_SELL_BID("CrazyAuctions-Sell-Bid", "&c/ah sell/bid [amount of items]"), + HELP("Help-Menu", Arrays.asList( + "&e-- &6Crazy Auctions Help &e--", + "&9/Ah - &eOpens the crazy auction.", + "&9/Ah View - &eSee what a player is selling.", + "&9/Ah Sell/Bid [Amount of items] - &eList the item you are holding on the crazy auction.", + "&9/Ah Expired/Collect - &eView and manage your cancelled and expired items.", + "&9/Ah Listed - &eView and manage the items you are selling.", + "&9/Ah Help - &eView this help menu.")); + + private String path; + private String defaultMessage; + private List defaultListMessage; + private static FileManager fileManager = FileManager.getInstance(); + + private Messages(String path, String defaultMessage) { + this.path = path; + this.defaultMessage = defaultMessage; + } + + private Messages(String path, List defaultListMessage) { + this.path = path; + this.defaultListMessage = defaultListMessage; + } + + public String getMessage() { + if(isList()) { + if(exists()) { + return Methods.color(convertList(Files.MESSAGES.getFile().getStringList("Messages." + path))); + }else { + return Methods.color(convertList(getDefaultListMessage())); + } + }else { + if(exists()) { + return Methods.getPrefix(Files.MESSAGES.getFile().getString("Messages." + path)); + }else { + return Methods.getPrefix(getDefaultMessage()); + } + } + } + + public String getMessage(HashMap placeholders) { + String message; + if(isList()) { + if(exists()) { + message = Methods.color(convertList(Files.MESSAGES.getFile().getStringList("Messages." + path), placeholders)); + }else { + message = Methods.color(convertList(getDefaultListMessage(), placeholders)); + } + }else { + if(exists()) { + message = Methods.getPrefix(Files.MESSAGES.getFile().getString("Messages." + path)); + }else { + message = Methods.getPrefix(getDefaultMessage()); + } + for(String ph : placeholders.keySet()) { + if(message.contains(ph)) { + message = message.replaceAll(ph, placeholders.get(ph)).replaceAll(ph, placeholders.get(ph).toLowerCase()); + } + } + } + return message; + } + + public String getMessageNoPrefix() { + if(isList()) { + if(exists()) { + return Methods.color(convertList(Files.MESSAGES.getFile().getStringList("Messages." + path))); + }else { + return Methods.color(convertList(getDefaultListMessage())); + } + }else { + if(exists()) { + return Methods.color(Files.MESSAGES.getFile().getString("Messages." + path)); + }else { + return Methods.color(getDefaultMessage()); + } + } + } + + public String getMessageNoPrefix(HashMap placeholders) { + String message; + if(isList()) { + if(exists()) { + message = Methods.color(convertList(Files.MESSAGES.getFile().getStringList("Messages." + path), placeholders)); + }else { + message = Methods.color(convertList(getDefaultListMessage(), placeholders)); + } + }else { + if(exists()) { + message = Methods.color(Files.MESSAGES.getFile().getString("Messages." + path)); + }else { + message = Methods.color(getDefaultMessage()); + } + for(String ph : placeholders.keySet()) { + if(message.contains(ph)) { + message = message.replaceAll(ph, placeholders.get(ph)).replaceAll(ph, placeholders.get(ph).toLowerCase()); + } + } + } + return message; + } + + public static String convertList(List list) { + String message = ""; + for(String m : list) { + message += Methods.color(m) + "\n"; + } + return message; + } + + public static String convertList(List list, HashMap placeholders) { + String message = ""; + for(String m : list) { + message += Methods.color(m) + "\n"; + } + for(String ph : placeholders.keySet()) { + message = Methods.color(message.replaceAll(ph, placeholders.get(ph))).replaceAll(ph, placeholders.get(ph).toLowerCase()); + } + return message; + } + + public static void addMissingMessages() { + FileConfiguration messages = Files.MESSAGES.getFile(); + Boolean saveFile = false; + for(Messages message : values()) { + if(!messages.contains("Messages." + message.getPath())) { + saveFile = true; + if(message.getDefaultMessage() != null) { + messages.set("Messages." + message.getPath(), message.getDefaultMessage()); + }else { + messages.set("Messages." + message.getPath(), message.getDefaultListMessage()); + } + } + } + if(saveFile) { + Files.MESSAGES.saveFile(); + } + } + + private Boolean exists() { + return Files.MESSAGES.getFile().contains("Messages." + path); + } + + private Boolean isList() { + if(Files.MESSAGES.getFile().contains("Messages." + path)) { + return !Files.MESSAGES.getFile().getStringList("Messages." + path).isEmpty(); + }else { + return defaultMessage == null; + } + } + + private String getPath() { + return path; + } + + private String getDefaultMessage() { + return defaultMessage; + } + + private List getDefaultListMessage() { + return defaultListMessage; + } + +} \ No newline at end of file diff --git a/src/main/java/me/badbones69/crazyauctions/api/SettingsManager.java b/src/main/java/me/badbones69/crazyauctions/api/SettingsManager.java deleted file mode 100644 index 6d2886e..0000000 --- a/src/main/java/me/badbones69/crazyauctions/api/SettingsManager.java +++ /dev/null @@ -1,140 +0,0 @@ -package me.badbones69.crazyauctions.api; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.PluginDescriptionFile; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; - -public class SettingsManager { - - static SettingsManager instance = new SettingsManager(); - - public static SettingsManager getInstance() { - return instance; - } - - Plugin p; - - FileConfiguration config; - File cfile; - - FileConfiguration data; - File dfile; - - FileConfiguration msg; - File mfile; - - public void setup(Plugin p) { - if(!p.getDataFolder().exists()) { - p.getDataFolder().mkdir(); - } - - cfile = new File(p.getDataFolder(), "config.yml"); - if(!cfile.exists()) { - try { - File en = new File(p.getDataFolder(), "/config.yml"); - InputStream E = getClass().getResourceAsStream("/config.yml"); - copyFile(E, en); - }catch(Exception e) { - e.printStackTrace(); - } - } - config = YamlConfiguration.loadConfiguration(cfile); - - dfile = new File(p.getDataFolder(), "Data.yml"); - if(!dfile.exists()) { - try { - File en = new File(p.getDataFolder(), "/Data.yml"); - InputStream E = getClass().getResourceAsStream("/Data.yml"); - copyFile(E, en); - }catch(Exception e) { - e.printStackTrace(); - } - } - data = YamlConfiguration.loadConfiguration(dfile); - - mfile = new File(p.getDataFolder(), "Messages.yml"); - if(!mfile.exists()) { - try { - File en = new File(p.getDataFolder(), "/Messages.yml"); - InputStream E = getClass().getResourceAsStream("/Messages.yml"); - copyFile(E, en); - }catch(Exception e) { - e.printStackTrace(); - } - } - msg = YamlConfiguration.loadConfiguration(mfile); - } - public FileConfiguration getData() { - return data; - } - public FileConfiguration getMsg() { - return msg; - } - public void saveData() { - try { - data.save(dfile); - }catch(IOException e) { - Bukkit.getServer().getLogger().severe(ChatColor.RED + "Could not save Data.yml!"); - } - } - public void saveMsg() { - try { - msg.save(mfile); - }catch(IOException e) { - Bukkit.getServer().getLogger().severe(ChatColor.RED + "Could not save Messages.yml!"); - } - } - public void reloadData() { - data = YamlConfiguration.loadConfiguration(dfile); - } - public void reloadMsg() { - msg = YamlConfiguration.loadConfiguration(mfile); - } - public FileConfiguration getConfig() { - return config; - } - - public void saveConfig() { - try { - config.save(cfile); - }catch(IOException e) { - Bukkit.getServer().getLogger().severe(ChatColor.RED + "Could not save config.yml!"); - } - } - - public void reloadConfig() { - config = YamlConfiguration.loadConfiguration(cfile); - } - - public PluginDescriptionFile getDesc() { - return p.getDescription(); - } - public static void copyFile(InputStream in, File out) throws Exception { // https://bukkit.org/threads/extracting-file-from-jar.16962/ - InputStream fis = in; - FileOutputStream fos = new FileOutputStream(out); - try { - byte[] buf = new byte[1024]; - int i = 0; - while((i = fis.read(buf)) != -1) { - fos.write(buf, 0, i); - } - }catch(Exception e) { - throw e; - }finally { - if(fis != null) { - fis.close(); - } - if(fos != null) { - fos.close(); - } - } - } -} \ No newline at end of file diff --git a/src/main/java/me/badbones69/crazyauctions/api/ShopType.java b/src/main/java/me/badbones69/crazyauctions/api/ShopType.java index ec8d142..cd5ad76 100644 --- a/src/main/java/me/badbones69/crazyauctions/api/ShopType.java +++ b/src/main/java/me/badbones69/crazyauctions/api/ShopType.java @@ -4,24 +4,24 @@ public enum ShopType { SELL("Sell"), BID("Bid"); - String Name; + private String name; /** - * @param name Name of the Shop Type. + * @param name name of the Shop Type. */ private ShopType(String name) { - this.Name = name; + this.name = name; } /** * @return Returns the type name as a string. */ public String getName() { - return Name; + return name; } /** - * @param name Name of the Type you want. + * @param name name of the Type you want. * @return Returns the Type as a Enum. */ public static ShopType getFromName(String name) { diff --git a/src/main/java/me/badbones69/crazyauctions/controlers/GUI.java b/src/main/java/me/badbones69/crazyauctions/controllers/GUI.java similarity index 88% rename from src/main/java/me/badbones69/crazyauctions/controlers/GUI.java rename to src/main/java/me/badbones69/crazyauctions/controllers/GUI.java index 3f360e9..61e9d08 100644 --- a/src/main/java/me/badbones69/crazyauctions/controlers/GUI.java +++ b/src/main/java/me/badbones69/crazyauctions/controllers/GUI.java @@ -1,8 +1,10 @@ -package me.badbones69.crazyauctions.controlers; +package me.badbones69.crazyauctions.controllers; -import me.badbones69.crazyauctions.Main; import me.badbones69.crazyauctions.Methods; import me.badbones69.crazyauctions.api.Category; +import me.badbones69.crazyauctions.api.CrazyAuctions; +import me.badbones69.crazyauctions.api.FileManager.Files; +import me.badbones69.crazyauctions.api.Messages; import me.badbones69.crazyauctions.api.ShopType; import me.badbones69.crazyauctions.api.events.AuctionBuyEvent; import me.badbones69.crazyauctions.api.events.AuctionNewBidEvent; @@ -33,18 +35,18 @@ public class GUI implements Listener { private static HashMap Cat = new HashMap<>(); // Category Type private static HashMap> List = new HashMap<>(); private static HashMap IDs = new HashMap<>(); - - public static Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("CrazyAuctions"); + private static CrazyAuctions crazyAuctions = CrazyAuctions.getInstance(); + private static Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("CrazyAuctions"); public static void openShop(Player player, ShopType sell, Category cat, int page) { Methods.updateAuction(); - FileConfiguration config = Main.settings.getConfig(); - FileConfiguration data = Main.settings.getData(); + FileConfiguration config = Files.CONFIG.getFile(); + FileConfiguration data = Files.DATA.getFile(); List items = new ArrayList<>(); List ID = new ArrayList<>(); if(!data.contains("Items")) { data.set("Items.Clear", null); - Main.settings.saveData(); + Files.DATA.saveFile(); } if(cat != null) { Cat.put(player, cat); @@ -90,12 +92,16 @@ public class GUI implements Listener { options.add("Category2"); if(sell == ShopType.SELL) { Type.put(player, ShopType.SELL); - options.add("Bidding/Selling.Selling"); + if(crazyAuctions.isBiddingEnabled()) { + options.add("Bidding/Selling.Selling"); + } options.add("WhatIsThis.SellingShop"); } if(sell == ShopType.BID) { Type.put(player, ShopType.BID); - options.add("Bidding/Selling.Bidding"); + if(crazyAuctions.isSellingEnabled()) { + options.add("Bidding/Selling.Bidding"); + } options.add("WhatIsThis.BiddingShop"); } for(String o : options) { @@ -127,9 +133,9 @@ public class GUI implements Listener { player.openInventory(inv); } - public static void openCateories(Player player, ShopType shop) { + public static void openCategories(Player player, ShopType shop) { Methods.updateAuction(); - FileConfiguration config = Main.settings.getConfig(); + FileConfiguration config = Files.CONFIG.getFile(); Inventory inv = Bukkit.createInventory(null, 54, Methods.color(config.getString("Settings.Categories"))); List options = new ArrayList<>(); options.add("OtherSettings.Back"); @@ -163,8 +169,8 @@ public class GUI implements Listener { public static void openPlayersCurrentList(Player player, int page) { Methods.updateAuction(); - FileConfiguration config = Main.settings.getConfig(); - FileConfiguration data = Main.settings.getData(); + FileConfiguration config = Files.CONFIG.getFile(); + FileConfiguration data = Files.DATA.getFile(); List items = new ArrayList<>(); List ID = new ArrayList<>(); Inventory inv = Bukkit.createInventory(null, 54, Methods.color(config.getString("Settings.Players-Current-Items"))); @@ -209,8 +215,8 @@ public class GUI implements Listener { public static void openPlayersExpiredList(Player player, int page) { Methods.updateAuction(); - FileConfiguration config = Main.settings.getConfig(); - FileConfiguration data = Main.settings.getData(); + FileConfiguration config = Files.CONFIG.getFile(); + FileConfiguration data = Files.DATA.getFile(); List items = new ArrayList<>(); List ID = new ArrayList<>(); if(data.contains("OutOfTime/Cancelled")) { @@ -260,12 +266,11 @@ public class GUI implements Listener { public static void openBuying(Player player, String ID) { Methods.updateAuction(); - FileConfiguration config = Main.settings.getConfig(); - FileConfiguration data = Main.settings.getData(); - FileConfiguration msg = Main.settings.getMsg(); + FileConfiguration config = Files.CONFIG.getFile(); + FileConfiguration data = Files.DATA.getFile(); if(!data.contains("Items." + ID)) { openShop(player, ShopType.SELL, Cat.get(player), 1); - player.sendMessage(Methods.getPrefix() + Methods.color(msg.getString("Messages.Item-Doesnt-Exist"))); + player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage()); return; } Inventory inv = Bukkit.createInventory(null, 9, Methods.color(config.getString("Settings.Buying-Item"))); @@ -306,12 +311,11 @@ public class GUI implements Listener { public static void openBidding(Player player, String ID) { Methods.updateAuction(); - FileConfiguration config = Main.settings.getConfig(); - FileConfiguration data = Main.settings.getData(); - FileConfiguration msg = Main.settings.getMsg(); + FileConfiguration config = Files.CONFIG.getFile(); + FileConfiguration data = Files.DATA.getFile(); if(!data.contains("Items." + ID)) { openShop(player, ShopType.BID, Cat.get(player), 1); - player.sendMessage(Methods.getPrefix() + Methods.color(msg.getString("Messages.Item-Doesnt-Exist"))); + player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage()); return; } Inventory inv = Bukkit.createInventory(null, 27, Methods.color(config.getString("Settings.Bidding-On-Item"))); @@ -333,13 +337,13 @@ public class GUI implements Listener { public static void openViewer(Player player, String other, int page) { Methods.updateAuction(); - FileConfiguration config = Main.settings.getConfig(); - FileConfiguration data = Main.settings.getData(); + FileConfiguration config = Files.CONFIG.getFile(); + FileConfiguration data = Files.DATA.getFile(); List items = new ArrayList<>(); List ID = new ArrayList<>(); if(!data.contains("Items")) { data.set("Items.Clear", null); - Main.settings.saveData(); + Files.DATA.saveFile(); } if(data.contains("Items")) { for(String i : data.getConfigurationSection("Items").getKeys(false)) { @@ -392,7 +396,7 @@ public class GUI implements Listener { } public static ItemStack getBiddingGlass(Player player, String ID) { - FileConfiguration config = Main.settings.getConfig(); + FileConfiguration config = Files.CONFIG.getFile(); String id = config.getString("Settings.GUISettings.OtherSettings.Bidding.Item"); String name = config.getString("Settings.GUISettings.OtherSettings.Bidding.Name"); ItemStack item; @@ -410,8 +414,8 @@ public class GUI implements Listener { } public static ItemStack getBiddingItem(Player player, String ID) { - FileConfiguration config = Main.settings.getConfig(); - FileConfiguration data = Main.settings.getData(); + FileConfiguration config = Files.CONFIG.getFile(); + FileConfiguration data = Files.DATA.getFile(); String seller = data.getString("Items." + ID + ".Seller"); String topbidder = data.getString("Items." + ID + ".TopBidder"); ItemStack item = data.getItemStack("Items." + ID + ".Item"); @@ -424,7 +428,7 @@ public class GUI implements Listener { @EventHandler public void onInvClose(InventoryCloseEvent e) { - FileConfiguration config = Main.settings.getConfig(); + FileConfiguration config = Files.CONFIG.getFile(); Inventory inv = e.getInventory(); Player player = (Player) e.getPlayer(); if(inv != null) { @@ -436,9 +440,8 @@ public class GUI implements Listener { @EventHandler public void onInvClick(InventoryClickEvent e) { - FileConfiguration config = Main.settings.getConfig(); - FileConfiguration data = Main.settings.getData(); - FileConfiguration msg = Main.settings.getMsg(); + FileConfiguration config = Files.CONFIG.getFile(); + FileConfiguration data = Files.DATA.getFile(); Player player = (Player) e.getWhoClicked(); final Inventory inv = e.getInventory(); if(inv != null) { @@ -480,22 +483,26 @@ public class GUI implements Listener { int bid = bidding.get(player); String topBidder = data.getString("Items." + ID + ".TopBidder"); if(CurrencyManager.getMoney(player) < bid) { - player.sendMessage(Methods.getPrefix() + Methods.color(msg.getString("Messages.Need-More-Money").replaceAll("%Money_Needed%", (bid - CurrencyManager.getMoney(player)) + "").replaceAll("%money_needed%", (bid - CurrencyManager.getMoney(player)) + ""))); + HashMap placeholders = new HashMap<>(); + placeholders.put("%Money_Needed%", (bid - CurrencyManager.getMoney(player)) + ""); + player.sendMessage(Messages.NEED_MORE_MONEY.getMessage(placeholders)); return; } if(data.getLong("Items." + ID + ".Price") > bid) { - player.sendMessage(Methods.getPrefix() + Methods.color(msg.getString("Messages.Bid-More-Money"))); + player.sendMessage(Messages.BID_MORE_MONEY.getMessage()); return; } if(data.getLong("Items." + ID + ".Price") >= bid && !topBidder.equalsIgnoreCase("None")) { - player.sendMessage(Methods.getPrefix() + Methods.color(msg.getString("Messages.Bid-More-Money"))); + player.sendMessage(Messages.BID_MORE_MONEY.getMessage()); return; } Bukkit.getPluginManager().callEvent(new AuctionNewBidEvent(player, data.getItemStack("Items." + ID + ".Item"), bid)); data.set("Items." + ID + ".Price", bid); data.set("Items." + ID + ".TopBidder", player.getName()); - player.sendMessage(Methods.getPrefix() + Methods.color(msg.getString("Messages.Bid-Msg").replaceAll("%Bid%", bid + "").replaceAll("%bid%", bid + ""))); - Main.settings.saveData(); + HashMap placeholders = new HashMap<>(); + placeholders.put("%Bid%", bid + ""); + player.sendMessage(Messages.BID_MESSAGE.getMessage(placeholders)); + Files.DATA.saveFile(); bidding.put(player, 0); player.closeInventory(); playClick(player); @@ -520,7 +527,7 @@ public class GUI implements Listener { return; }catch(Exception ex) { player.closeInventory(); - player.sendMessage(Methods.getPrefix() + Methods.color(msg.getString("Messages.Item-Doesnt-Exist"))); + player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage()); return; } } @@ -581,12 +588,12 @@ public class GUI implements Listener { return; } if(item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Category1.Name")))) { - openCateories(player, Type.get(player)); + openCategories(player, Type.get(player)); playClick(player); return; } if(item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Category2.Name")))) { - openCateories(player, Type.get(player)); + openCategories(player, Type.get(player)); playClick(player); return; } @@ -614,15 +621,15 @@ public class GUI implements Listener { String seller = data.getString("Items." + i + ".Seller"); if(Methods.isOnline(seller)) { Player S = Methods.getPlayer(seller); - S.sendMessage(Methods.getPrefix() + Methods.color(msg.getString("Messages.Admin-Force-Cancelled-To-Player"))); + S.sendMessage(Messages.ADMIN_FORCE_CANCELLED_TO_PLAYER.getMessage()); } 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.getItemStack("Items." + i + ".Item")); data.set("Items." + i, null); - Main.settings.saveData(); - player.sendMessage(Methods.getPrefix() + Methods.color(msg.getString("Messages.Admin-Force-Cancelled"))); + Files.DATA.saveFile(); + player.sendMessage(Messages.ADMIN_FORCE_CENCELLED.getMessage()); playClick(player); int page = Integer.parseInt(inv.getName().split("#")[1]); openShop(player, Type.get(player), Cat.get(player), page); @@ -687,7 +694,7 @@ public class GUI implements Listener { if(!T) { playClick(player); openShop(player, Type.get(player), Cat.get(player), 1); - player.sendMessage(Methods.getPrefix() + Methods.color(msg.getString("Messages.Item-Doesnt-Exist"))); + player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage()); return; } } @@ -710,33 +717,38 @@ public class GUI implements Listener { if(!data.contains("Items." + ID)) { playClick(player); openShop(player, Type.get(player), Cat.get(player), 1); - player.sendMessage(Methods.getPrefix() + Methods.color(msg.getString("Messages.Item-Doesnt-Exist"))); + player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage()); return; } if(Methods.isInvFull(player)) { playClick(player); player.closeInventory(); - player.sendMessage(Methods.getPrefix() + Methods.color(msg.getString("Messages.Inventory-Full"))); + player.sendMessage(Messages.INVENTORY_FULL.getMessage()); return; } if(CurrencyManager.getMoney(player) < cost) { playClick(player); player.closeInventory(); - player.sendMessage(Methods.getPrefix() + Methods.color(msg.getString("Messages.Need-More-Money").replaceAll("%Money_Needed%", (cost - CurrencyManager.getMoney(player)) + "").replaceAll("%money_needed%", (cost - CurrencyManager.getMoney(player)) + ""))); + HashMap placeholders = new HashMap<>(); + placeholders.put("%Money_Needed%", (cost - CurrencyManager.getMoney(player)) + ""); + player.sendMessage(Messages.NEED_MORE_MONEY.getMessage(placeholders)); return; } ItemStack i = data.getItemStack("Items." + ID + ".Item"); Bukkit.getPluginManager().callEvent(new AuctionBuyEvent(player, i, cost)); CurrencyManager.removeMoney(player, cost); CurrencyManager.addMoney(Methods.getOfflinePlayer(seller), cost); - player.sendMessage(Methods.getPrefix() + Methods.color(msg.getString("Messages.Bought-Item").replaceAll("%Price%", Methods.getPrice(ID, false)).replaceAll("%price%", Methods.getPrice(ID, false)))); + HashMap placeholders = new HashMap<>(); + placeholders.put("%Price%", Methods.getPrice(ID, false)); + placeholders.put("%Player%", player.getName()); + player.sendMessage(Messages.BOUGHT_ITEM.getMessage(placeholders)); if(Methods.isOnline(seller)) { Player sell = Methods.getPlayer(seller); - sell.sendMessage(Methods.getPrefix() + Methods.color(msg.getString("Messages.Player-Bought-Item").replaceAll("%Price%", Methods.getPrice(ID, false)).replaceAll("%price%", Methods.getPrice(ID, false)).replaceAll("%Player%", player.getName()).replaceAll("%player%", player.getName()))); + sell.sendMessage(Messages.PLAYER_BOUGHT_ITEM.getMessage(placeholders)); } player.getInventory().addItem(i); data.set("Items." + ID, null); - Main.settings.saveData(); + Files.DATA.saveFile(); playClick(player); openShop(player, Type.get(player), Cat.get(player), 1); return; @@ -772,7 +784,7 @@ public class GUI implements Listener { for(String i : data.getConfigurationSection("Items").getKeys(false)) { int ID = data.getInt("Items." + i + ".StoreID"); if(id == ID) { - player.sendMessage(Methods.getPrefix() + Methods.color(msg.getString("Messages.Cancelled-Item"))); + player.sendMessage(Messages.CANCELLED_ITEM.getMessage()); int num = 1; for(; data.contains("OutOfTime/Cancelled." + num); num++) ; data.set("OutOfTime/Cancelled." + num + ".Seller", data.getString("Items." + i + ".Seller")); @@ -780,7 +792,7 @@ public class GUI implements Listener { data.set("OutOfTime/Cancelled." + num + ".StoreID", data.getInt("Items." + i + ".StoreID")); data.set("OutOfTime/Cancelled." + num + ".Item", data.getItemStack("Items." + i + ".Item")); data.set("Items." + i, null); - Main.settings.saveData(); + Files.DATA.saveFile(); playClick(player); openPlayersCurrentList(player, 1); return; @@ -790,7 +802,7 @@ public class GUI implements Listener { if(!T) { playClick(player); openShop(player, Type.get(player), Cat.get(player), 1); - player.sendMessage(Methods.getPrefix() + Methods.color(msg.getString("Messages.Item-Doesnt-Exist"))); + player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage()); return; } } @@ -827,7 +839,7 @@ public class GUI implements Listener { for(String i : data.getConfigurationSection("OutOfTime/Cancelled").getKeys(false)) { if(data.getString("OutOfTime/Cancelled." + i + ".Seller").equalsIgnoreCase(player.getName())) { if(Methods.isInvFull(player)) { - player.sendMessage(Methods.getPrefix() + Methods.color(Main.settings.getMsg().getString("Messages.Inventory-Full"))); + player.sendMessage(Messages.INVENTORY_FULL.getMessage()); break; }else { player.getInventory().addItem(data.getItemStack("OutOfTime/Cancelled." + i + ".Item")); @@ -836,8 +848,8 @@ public class GUI implements Listener { } } } - player.sendMessage(Methods.getPrefix() + Methods.color(msg.getString("Messages.Got-Item-Back"))); - Main.settings.saveData(); + player.sendMessage(Messages.GOT_ITEM_BACK.getMessage()); + Files.DATA.saveFile(); playClick(player); openPlayersExpiredList(player, page); return; @@ -858,16 +870,16 @@ public class GUI implements Listener { int ID = data.getInt("OutOfTime/Cancelled." + i + ".StoreID"); if(id == ID) { if(!Methods.isInvFull(player)) { - player.sendMessage(Methods.getPrefix() + Methods.color(msg.getString("Messages.Got-Item-Back"))); + player.sendMessage(Messages.GOT_ITEM_BACK.getMessage()); ItemStack IT = data.getItemStack("OutOfTime/Cancelled." + i + ".Item"); player.getInventory().addItem(IT); data.set("OutOfTime/Cancelled." + i, null); - Main.settings.saveData(); + Files.DATA.saveFile(); playClick(player); openPlayersExpiredList(player, 1); return; }else { - player.sendMessage(Methods.getPrefix() + Methods.color(msg.getString("Messages.Inventory-Full"))); + player.sendMessage(Messages.INVENTORY_FULL.getMessage()); return; } } @@ -876,7 +888,7 @@ public class GUI implements Listener { if(!T) { playClick(player); openShop(player, Type.get(player), Cat.get(player), 1); - player.sendMessage(Methods.getPrefix() + Methods.color(msg.getString("Messages.Item-Doesnt-Exist"))); + player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage()); } } } @@ -887,9 +899,9 @@ public class GUI implements Listener { } private static void playClick(Player player) { - if(Main.settings.getConfig().contains("Settings.Sounds.Toggle")) { - if(Main.settings.getConfig().getBoolean("Settings.Sounds.Toggle")) { - String sound = Main.settings.getConfig().getString("Settings.Sounds.Sound"); + if(Files.CONFIG.getFile().contains("Settings.Sounds.Toggle")) { + if(Files.CONFIG.getFile().getBoolean("Settings.Sounds.Toggle")) { + String sound = Files.CONFIG.getFile().getString("Settings.Sounds.Sound"); try { player.playSound(player.getLocation(), Sound.valueOf(sound), 1, 1); }catch(Exception e) { diff --git a/src/main/java/me/badbones69/crazyauctions/currency/CurrencyManager.java b/src/main/java/me/badbones69/crazyauctions/currency/CurrencyManager.java index af1c99e..9e495c7 100644 --- a/src/main/java/me/badbones69/crazyauctions/currency/CurrencyManager.java +++ b/src/main/java/me/badbones69/crazyauctions/currency/CurrencyManager.java @@ -1,6 +1,6 @@ package me.badbones69.crazyauctions.currency; -import me.badbones69.crazyauctions.Main; +import me.badbones69.crazyauctions.api.FileManager.Files; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; @@ -9,36 +9,36 @@ public enum CurrencyManager { // Currency Manager VAULT("Vault", "Money"); - String PluginName, Name; + private String pluginName, name; /** * @param pluginname - * Name of the Plugin. + * name of the Plugin. * @param name - * Name of the Currency. + * name of the Currency. */ private CurrencyManager(String pluginname, String name) { - this.PluginName = pluginname; - this.Name = name; + this.pluginName = pluginname; + this.name = name; } /** * @return Returns the Currency name as a string. */ public String getName() { - return Name; + return name; } /** * @return Returns the Currency name as a string. */ public String getPluginName() { - return PluginName; + return pluginName; } /** * @param name - * Name of the Type you want. + * name of the Type you want. * @return Returns the Currency as a Enum. */ public static CurrencyManager getFromName(String name) { @@ -55,10 +55,8 @@ public enum CurrencyManager { // Currency Manager * @return Returns true if the server has the plugin. */ public Boolean hasPlugin() { - if(Bukkit.getServer().getPluginManager().getPlugin(PluginName) != null) { - if(Main.settings.getConfig().getBoolean("Settings.Currencies." + PluginName + ".Enabled")) { - return true; - } + if(Bukkit.getServer().getPluginManager().getPlugin(pluginName) != null) { + return Files.CONFIG.getFile().getBoolean("Settings.Currencies." + pluginName + ".Enabled"); } return false; } @@ -67,8 +65,6 @@ public enum CurrencyManager { // Currency Manager * * @param player * Player you want the currency from. - * @param type - * Type of currency you want to get. * @return Returns the amount they have of the currency */ public static Long getMoney(Player player) { @@ -79,8 +75,6 @@ public enum CurrencyManager { // Currency Manager * * @param player * Player you want the currency from. - * @param type - * Type of currency you want to take from. * @param amount * The amount you want to take. */ @@ -92,8 +86,6 @@ public enum CurrencyManager { // Currency Manager * * @param player * Player you want the currency from. - * @param type - * Type of currency you want to take from. * @param amount * The amount you want to take. */ @@ -105,8 +97,6 @@ public enum CurrencyManager { // Currency Manager * * @param player * Player you want the currency from. - * @param type - * Type of currency you want to add to. * @param amount * The amount you want to add. */ @@ -118,12 +108,11 @@ public enum CurrencyManager { // Currency Manager * * @param player * Player you want the currency from. - * @param type - * Type of currency you want to add to. * @param amount * The amount you want to add. */ public static void addMoney(OfflinePlayer player, Long amount) { Vault.addMoney(player, amount); } + } \ No newline at end of file diff --git a/src/main/java/me/badbones69/crazyauctions/currency/Vault.java b/src/main/java/me/badbones69/crazyauctions/currency/Vault.java index 840e818..454dc41 100644 --- a/src/main/java/me/badbones69/crazyauctions/currency/Vault.java +++ b/src/main/java/me/badbones69/crazyauctions/currency/Vault.java @@ -13,10 +13,7 @@ public class Vault { public static EconomyResponse r; public static boolean hasVault() { - if(Bukkit.getServer().getPluginManager().getPlugin("Vault") != null) { - return true; - } - return false; + return Bukkit.getServer().getPluginManager().getPlugin("Vault") != null; } public static boolean setupEconomy() { diff --git a/src/main/resources/Messages.yml b/src/main/resources/Messages.yml index cb80b81..8e5461a 100644 --- a/src/main/resources/Messages.yml +++ b/src/main/resources/Messages.yml @@ -8,27 +8,32 @@ Messages: Doesnt-Have-Item-In-Hand: '&cYou must have an item in your hand.' Not-A-Number: '&c%Arg% is not a number.' Got-Item-Back: '&7Your item has been returned.' - Cancelled-Item: '&7You have cancelled an item on the auction list, return your items with /ah expired.' + Cancelled-Item: '&7You have canceled an item on the auction list, return your items with /ah expired.' Item-Has-Expired: '&7An item you have in the Crazy Auctions has just expired.' - Admin-Force-Cancelled: '&7You have just force cancelled a sale.' - Admin-Force-Cancelled-To-Player: '&cOne of your items was just force cancelled by an Admin.' - Item-Doesnt-Exist: '&cThat item isnt in the crazy auctions any more.' - Max-Items: '&cYou cant list any more items to the Crazy Auctions.' + Admin-Force-Cancelled: '&7You have just force canceled a sale.' + Admin-Force-Cancelled-To-Player: '&cOne of your items was just force canceled by an Admin.' + Item-Doesnt-Exist: '&cThat item isn''t in the crazy auctions any more.' + Max-Items: '&cYou can''t list any more items to the Crazy Auctions.' Item-BlackListed: '&cThat item is not allowed to be sold here.' Item-Damaged: '&cThat item is damaged and is not allowed to be sold here.' Sold-Msg: '&7Thank you for buying this item.' Bid-More-Money: '&cYour bid is to low, please bid more.' Not-A-Currency: '&cThat is not a currency. Please use Money or Tokens.' #Remove Tokens if you do not have TokenManager. Sell-Price-To-Low: '&cYour sell price is to low the minimum is &a$10&c.' - Sell-Price-To-High: '&cYour sell price is to high the maximum is &a$1000000&c.' + Sell-Price-To-High: '&cYour sell price is too high the maximum is &a$1000000&c.' Bid-Price-To-Low: '&cYour starting bid price is to low the minimum is &a$100&c.' - Bid-Price-To-High: '&cYour starting bid price is to high the maximum is &a$1000000&c.' - Bought-Item: '&7You have just bought a item for &a$%Price%&7.' + Bid-Price-To-High: '&cYour starting bid price is too high the maximum is &a$1000000&c.' + Bought-Item: '&7You have just bought an item for &a$%Price%&7.' Win-Bidding: '&7You have just won a bid for &a$%Price%&7. Do /Ah Collect to collect your winnings.' Player-Bought-Item: '&7%Player% has bought your item for &a$%Price%.' Someone-Won-Players-Bid: '&7%Player% has won your item you from a bid for &a$%Price%.' - Added-Item-To-Auction: '&7You have just added a item to the crazy auctions for &a$%Price%&7.' + Added-Item-To-Auction: '&7You have just added an item to the crazy auctions for &a$%Price%&7.' Bid-Msg: '&7You have just bid &a$%Bid% &7on that item.' + Selling-Disabled: '&cThe selling option is disabled.' + Bidding-Disabled: '&cThe bidding option is disabled.' + CrazyAuctions-Help: '&c/ah help' + CrazyAuctions-View: '&c/ah view ' + CrazyAuctions-Sell-Bid: '&c/ah sell/bid [amount of items]' Help-Menu: - '&e-- &6Crazy Auctions Help &e--' - '&9/Ah - &eOpens the crazy auction.' diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index b08a470..c9fd9c0 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -16,6 +16,9 @@ Settings: Max-Beginning-Bid-Price: 1000000 #Maximum starting bid. Allow-Damaged-Items: False #Allow items that have been damaged. Category-Page-Opens-First: False #If set to true the categories page will open when they do /CA. + Feature-Toggle: #Toggle if a feature is on or off. + Selling: true #Able to use the selling part of the auction house. + Bidding: true #Able to use the bidding part of the auction house. Sounds: Toggle: False #Disable the clicking sound. Sound: 'CLICK' #Make sure if you use 1.8 or lower you use the 1.8 sound and 1.9 and up use 1.9 sounds. The default sound is 1.8.