diff --git a/src/main/java/com/badbones69/crazyauctions/CrazyAuctions.java b/src/main/java/com/badbones69/crazyauctions/CrazyAuctions.java deleted file mode 100644 index 1980b26..0000000 --- a/src/main/java/com/badbones69/crazyauctions/CrazyAuctions.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.badbones69.crazyauctions; - -import com.badbones69.crazyauctions.api.CrazyManager; -import com.badbones69.crazyauctions.api.FileManager; -import com.badbones69.crazyauctions.api.FileManager.Files; -import org.bukkit.event.Listener; -import org.bukkit.plugin.java.JavaPlugin; - -public class CrazyAuctions extends JavaPlugin implements Listener { - - private static CrazyAuctions plugin; - - private Starter starter; - - private final FileManager fileManager = getStarter().getFileManager(); - - private final CrazyManager crazyManager = getStarter().getCrazyManager(); - - private final Methods methods = getStarter().getMethods(); - - private boolean isEnabled = false; - - @Override - public void onEnable() { - try { - plugin = this; - - starter = new Starter(); - - starter.run(); - - fileManager.setup(); - - crazyManager.load(); - - // methods.updateAuction(); - } catch (Exception e) { - e.printStackTrace(); - - isEnabled = false; - - return; - } - - isEnabled = true; - - enable(); - } - - @Override - public void onDisable() { - if (!isEnabled) return; - - disable(); - } - - private void enable() { - - } - - private void disable() { - Files.DATA.saveFile(); - } - - public static CrazyAuctions getPlugin() { - return plugin; - } - - public Starter getStarter() { - return starter; - } -} \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazyauctions/Methods.java b/src/main/java/com/badbones69/crazyauctions/Methods.java deleted file mode 100644 index e298339..0000000 --- a/src/main/java/com/badbones69/crazyauctions/Methods.java +++ /dev/null @@ -1,129 +0,0 @@ -package com.badbones69.crazyauctions; - -import com.badbones69.crazyauctions.api.FileManager.Files; -import com.badbones69.crazyauctions.api.enums.Messages; -import com.badbones69.crazyauctions.utils.ItemBuilder; -import com.badbones69.crazyauctions.utils.func.ServerProtocol; -import net.md_5.bungee.api.chat.TextComponent; -import org.bukkit.*; -import org.bukkit.command.CommandSender; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import java.util.*; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -@SuppressWarnings("deprecation") -public class Methods { - - private final CrazyAuctions plugin = CrazyAuctions.getPlugin(); - - public final Pattern HEX_PATTERN = Pattern.compile("#[a-fA-F0-9]{6}"); - - public String color(String message) { - if (ServerProtocol.isNewer(ServerProtocol.v1_15_R1)) { - Matcher matcher = HEX_PATTERN.matcher(message); - StringBuilder buffer = new StringBuilder(); - - while (matcher.find()) { - matcher.appendReplacement(buffer, net.md_5.bungee.api.ChatColor.of(matcher.group()).toString()); - } - - return ChatColor.translateAlternateColorCodes('&', matcher.appendTail(buffer).toString()); - } - - return ChatColor.translateAlternateColorCodes('&', message); - } - - public String getPrefix() { - return color(Files.CONFIG.getFile().getString("Settings.Prefix", "")); - } - - public String getPrefix(String msg) { - return color(Files.CONFIG.getFile().getString("Settings.Prefix", "") + msg); - } - - public String sanitizeColor(String msg) { - return sanitizeFormat(color(msg)); - } - - public String removeColor(String msg) { - return ChatColor.stripColor(msg); - } - - public static String sanitizeFormat(String string) { - return TextComponent.toLegacyText(TextComponent.fromLegacyText(string)); - } - - public ItemStack makeItem(Material material, int amount, String name, List lore, HashMap enchants) { - ItemBuilder newItem = new ItemBuilder().setMaterial(material).setAmount(amount).setName(name).setLore(lore).setEnchantments(enchants); - return newItem.build(); - } - - public ItemStack getItemInHand(Player player) { - return player.getInventory().getItemInMainHand(); - } - - public void setItemInHand(Player player, ItemStack item) { - player.getInventory().setItemInMainHand(item); - } - - public Player getPlayer(String name) { - try { - return plugin.getServer().getPlayer(name); - } catch (Exception e) { - return null; - } - } - - @SuppressWarnings("deprecation") - public OfflinePlayer getOfflinePlayer(String name) { - return plugin.getServer().getOfflinePlayer(name); - } - - public boolean isOnline(String name) { - for (Player player : plugin.getServer().getOnlinePlayers()) { - if (player.getName().equalsIgnoreCase(name)) return true; - } - - return false; - } - - public boolean isOnline(String name, CommandSender commandSender) { - for (Player player : plugin.getServer().getOnlinePlayers()) { - if (player.getName().equalsIgnoreCase(name)) return true; - } - - commandSender.sendMessage(Messages.NOT_ONLINE.getMessage()); - return false; - } - - public boolean hasPermission(Player player, String perm) { - if (!player.hasPermission("crazyauctions." + perm)) { - player.sendMessage(Messages.NO_PERMISSION.getMessage()); - return false; - } - - return true; - } - - public boolean hasPermission(CommandSender sender, String perm) { - if (sender instanceof Player) { - Player player = (Player) sender; - - if (!player.hasPermission("crazyauctions." + perm)) { - player.sendMessage(Messages.NO_PERMISSION.getMessage()); - return false; - } else { - return true; - } - } else { - return true; - } - } - - public boolean isInvFull(Player player) { - return player.getInventory().firstEmpty() == -1; - } -} \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazyauctions/Starter.java b/src/main/java/com/badbones69/crazyauctions/Starter.java deleted file mode 100644 index 24d59db..0000000 --- a/src/main/java/com/badbones69/crazyauctions/Starter.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.badbones69.crazyauctions; - -import com.badbones69.crazyauctions.api.CrazyManager; -import com.badbones69.crazyauctions.api.FileManager; -import com.badbones69.crazyauctions.api.economy.vault.VaultSupport; -import com.badbones69.crazyauctions.utils.SkullCreator; - -public class Starter { - - private FileManager fileManager; - - private CrazyManager crazyManager; - - private VaultSupport vaultSupport; - - private Methods methods; - - private SkullCreator skullCreator; - - public void run() { - fileManager = new FileManager(); - crazyManager = new CrazyManager(); - - vaultSupport = new VaultSupport(); - - methods = new Methods(); - - skullCreator = new SkullCreator(); - } - - public FileManager getFileManager() { - return fileManager; - } - - public CrazyManager getCrazyManager() { - return crazyManager; - } - - public VaultSupport getVaultSupport() { - return vaultSupport; - } - - public Methods getMethods() { - return methods; - } - - public SkullCreator getSkullCreator() { - return skullCreator; - } -} \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazyauctions/api/CrazyManager.java b/src/main/java/com/badbones69/crazyauctions/api/CrazyManager.java deleted file mode 100644 index 230f201..0000000 --- a/src/main/java/com/badbones69/crazyauctions/api/CrazyManager.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.badbones69.crazyauctions.api; - -import com.badbones69.crazyauctions.api.FileManager.Files; -import com.badbones69.crazyauctions.api.enums.ShopCategories; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import java.util.ArrayList; - -public class CrazyManager { - - private Boolean sellingEnabled; - private Boolean biddingEnabled; - - public void load() { - 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 = 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())) items.add(data.getItemStack("Items." + i + ".Item").clone()); - } - } - - return items; - } - - public ArrayList getItems(Player player, ShopCategories type) { - 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())) { - if (data.getBoolean("Items." + i + ".Biddable")) { - if (type == ShopCategories.BID) items.add(data.getItemStack("Items." + i + ".Item").clone()); - } else { - if (type == ShopCategories.SELL) items.add(data.getItemStack("Items." + i + ".Item").clone()); - } - } - } - } - - return items; - } -} \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazyauctions/api/FileManager.java b/src/main/java/com/badbones69/crazyauctions/api/FileManager.java deleted file mode 100644 index 8e1691d..0000000 --- a/src/main/java/com/badbones69/crazyauctions/api/FileManager.java +++ /dev/null @@ -1,502 +0,0 @@ -package com.badbones69.crazyauctions.api; - -import com.badbones69.crazyauctions.CrazyAuctions; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; -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 final CrazyAuctions plugin = CrazyAuctions.getPlugin(); - - private boolean log = false; - - private final HashMap files = new HashMap<>(); - private final ArrayList homeFolders = new ArrayList<>(); - private final ArrayList customFiles = new ArrayList<>(); - private final HashMap jarHomeFolders = new HashMap<>(); - private final HashMap autoGenerateFiles = new HashMap<>(); - private final HashMap configurations = new HashMap<>(); - - /** - * Loads all necessary files. - */ - public FileManager setup() { - 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 (isLogging()) plugin.getLogger().info("Loading the " + file.getFileName()); - - if (!newFile.exists()) { - try { - File serverFile = new File(plugin.getDataFolder(), "/" + file.getFileLocation()); - InputStream jarFile = getClass().getResourceAsStream("/" + file.getFileJar()); - copyFile(jarFile, serverFile); - } catch (Exception e) { - if (isLogging()) plugin.getLogger().info("Failed to load " + file.getFileName()); - - e.printStackTrace(); - continue; - } - } - - files.put(file, newFile); - configurations.put(file, YamlConfiguration.loadConfiguration(newFile)); - - if (isLogging()) plugin.getLogger().info("Successfully loaded " + file.getFileName()); - } - - // Starts to load all the custom files. - if (homeFolders.size() > 0) { - if (isLogging()) plugin.getLogger().info("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); - - if (file.exists()) { - customFiles.add(file); - - if (isLogging()) plugin.getLogger().info("Loaded new custom file: " + homeFolder + "/" + name + "."); - } - } - } - } - } else { - homeFile.mkdir(); - if (isLogging()) plugin.getLogger().info("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)); - - if (isLogging()) plugin.getLogger().info("Created new default file: " + homeFolder + "/" + fileName + "."); - } catch (Exception e) { - if (isLogging()) plugin.getLogger().info("Failed to create new default file: " + homeFolder + "/" + fileName + "!"); - e.printStackTrace(); - } - } - } - } - } - - if (isLogging()) plugin.getLogger().info("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 setLog(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().equalsIgnoreCase(name)) 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) { - plugin.getLogger().warning("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 (isLogging()) plugin.getLogger().info("Successfully saved the " + file.getFileName() + "."); - } catch (Exception e) { - plugin.getLogger().warning("Could not save " + file.getFileName() + "!"); - e.printStackTrace(); - } - } else { - if (isLogging()) plugin.getLogger().warning("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 (isLogging()) plugin.getLogger().info("Successfully reloaded the " + file.getFileName() + "."); - } catch (Exception e) { - plugin.getLogger().warning("Could not reload the " + file.getFileName() + "!"); - e.printStackTrace(); - } - } else { - if (isLogging()) plugin.getLogger().warning("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: ... - */ - private void copyFile(InputStream in, File out) throws Exception { - try (InputStream fis = in; FileOutputStream fos = new FileOutputStream(out)) { - byte[] buf = new byte[1024]; - int i; - - while ((i = fis.read(buf)) != -1) { - fos.write(buf, 0, i); - } - } - } - - public void reloadAllFiles() { - for (Files file : Files.values()) { - file.reloadFile(); - } - - for (CustomFile file : customFiles) { - file.reloadFile(); - } - } - - public enum Files { - - // ENUM_NAME("fileName.yml", "fileLocation.yml"), - // ENUM_NAME("fileName.yml", "newFileLocation.yml", "oldFileLocation.yml"), - CONFIG("config.yml", "config.yml"), - DATA("data.yml", "data.yml"), - MESSAGES("messages.yml", "messages.yml"), - TEST_FILE("test-file.yml", "test-file.yml"); - - private final String fileName; - private final String fileJar; - private final String fileLocation; - - private final CrazyAuctions plugin = CrazyAuctions.getPlugin(); - - private final FileManager fileManager = plugin.getStarter().getFileManager(); - - /** - * 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 in the plugin's folder. - */ - Files(String fileName, String fileLocation) { - this(fileName, fileLocation, 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 of the file will be in the plugin's folder. - * @param fileJar The location of the file in the jar. - */ - Files(String fileName, String fileLocation, String fileJar) { - this.fileName = fileName; - this.fileLocation = fileLocation; - this.fileJar = fileJar; - } - - /** - * 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; - } - - /** - * Get the location of the file in the jar. - * @return The location of the file in the jar. - */ - public String getFileJar() { - return fileJar; - } - - /** - * Gets the file from the system. - * @return The file from the system. - */ - public FileConfiguration getFile() { - return fileManager.getFile(this); - } - - /** - * Saves the file from the loaded state to the file system. - */ - public void saveFile() { - fileManager.saveFile(this); - } - - /** - * Overrides the loaded state file and loads the file systems file. - */ - public void reloadFile() { - fileManager.reloadFile(this); - } - } - - public class CustomFile { - - private final String name; - private final String fileName; - private final String homeFolder; - private FileConfiguration file; - - private final CrazyAuctions plugin = CrazyAuctions.getPlugin(); - - /** - * A custom file that is being made. - * @param name Name of the file. - * @param homeFolder The home folder of the file. - */ - public CustomFile(String name, String homeFolder) { - this.name = name.replace(".yml", ""); - 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 (isLogging()) plugin.getLogger().info("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 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 (isLogging()) plugin.getLogger().info("Successfully saved the " + fileName + "."); - - return true; - } catch (Exception e) { - plugin.getLogger().warning("Could not save " + fileName + "!"); - e.printStackTrace(); - return false; - } - } else { - if (isLogging()) plugin.getLogger().warning("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 error. - */ - public Boolean reloadFile() { - if (file != null) { - try { - file = YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder(), "/" + homeFolder + "/" + fileName)); - - if (isLogging()) plugin.getLogger().info("Successfully reloaded the " + fileName + "."); - - return true; - } catch (Exception e) { - plugin.getLogger().warning("Could not reload the " + fileName + "!"); - e.printStackTrace(); - } - } else { - if (isLogging()) plugin.getLogger().warning("There was a null custom file that was not found!"); - } - - return false; - } - } -} \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazyauctions/api/economy/Currency.java b/src/main/java/com/badbones69/crazyauctions/api/economy/Currency.java deleted file mode 100644 index dadec63..0000000 --- a/src/main/java/com/badbones69/crazyauctions/api/economy/Currency.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.badbones69.crazyauctions.api.economy; - -public enum Currency { - - VAULT("Vault"), - XP_LEVEL("XP_Level"), - XP_TOTAL("XP_Total"); - - private final String name; - - Currency(String name) { - this.name = name; - } - - /** - * Checks if it is a compatible currency. - * @param currency The currency name you are checking. - * @return True if it is supported and false if not. - */ - public static boolean isCurrency(String currency) { - for (Currency value : Currency.values()) { - if (currency.equalsIgnoreCase(value.getName())) return true; - } - - return false; - } - - /** - * Get a currency enum. - * @param currency The currency you want. - * @return The currency enum. - */ - public static Currency getCurrency(String currency) { - for (Currency value : Currency.values()) { - if (currency.equalsIgnoreCase(value.getName())) return value; - } - - return null; - } - - /** - * Get the name of the currency. - * @return The name of the currency. - */ - public String getName() { - return name; - } -} \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazyauctions/api/economy/CurrencyAPI.java b/src/main/java/com/badbones69/crazyauctions/api/economy/CurrencyAPI.java deleted file mode 100644 index cf760bc..0000000 --- a/src/main/java/com/badbones69/crazyauctions/api/economy/CurrencyAPI.java +++ /dev/null @@ -1,158 +0,0 @@ -package com.badbones69.crazyauctions.api.economy; - -import com.badbones69.crazyauctions.CrazyAuctions; -import com.badbones69.crazyauctions.api.economy.vault.VaultSupport; -import com.badbones69.crazyauctions.api.enums.ShopCategories; -import org.bukkit.entity.Player; - -public class CurrencyAPI { - - private final CrazyAuctions plugin = CrazyAuctions.getPlugin(); - - private final VaultSupport vaultSupport = plugin.getStarter().getVaultSupport(); - - /** - * Get the amount that a player has from a specific currency. - * @param player The player you wish to get the amount from. - * @param currency The currency you wish to get from. - * @return The amount that the player has of that currency. - */ - public int getCurrency(Player player, Currency currency) { - try { - switch (currency) { - case VAULT: - vaultSupport.getVault().getBalance(player); - break; - case XP_LEVEL: - player.getLevel(); - break; - case XP_TOTAL: - getTotalExperience(player); - break; - } - } catch (Exception | NoClassDefFoundError ignored) {} - return 0; - } - - /** - * Take an amount from a player's currency. - * @param player The player you wish to take from. - * @param option The ShopOption you wish to use. - */ - public void takeCurrency(Player player, ShopCategories option) { - // takeCurrency(player, option.getCurrency(), option.getCost()); - } - - /** - * Take an amount from a player's currency. - * @param player The player you wish to take from. - * @param currency The currency you wish to use. - * @param amount The amount you want to take. - */ - public void takeCurrency(Player player, Currency currency, int amount) { - try { - switch (currency) { - case VAULT: - vaultSupport.getVault().withdrawPlayer(player, amount); - break; - case XP_LEVEL: - player.setLevel(player.getLevel() - amount); - break; - case XP_TOTAL: - takeTotalExperience(player, amount); - break; - } - } catch (Exception | NoClassDefFoundError ignored) {} - } - - /** - * Give an amount to a player's currency. - * @param player The player you are giving to. - * @param currency The currency you want to use. - * @param amount The amount you are giving to the player. - */ - public void giveCurrency(Player player, Currency currency, int amount) { - try { - switch (currency) { - case VAULT: - vaultSupport.getVault().depositPlayer(player, amount); - break; - case XP_LEVEL: - player.setLevel(player.getLevel() + amount); - break; - case XP_TOTAL: - takeTotalExperience(player, -amount); - break; - } - } catch (Exception | NoClassDefFoundError ignored) {} - } - - /** - * Checks if the player has enough of a currency. - * @param player The player you are checking. - * @param option The ShopOption you wish to check. - * @return True if they have enough to buy it or false if they don't. - */ - public boolean canBuy(Player player, ShopCategories option) { - return canBuy(player, option.getCurrency(), option.getCost()); - } - - /** - * Checks if the player has enough of a currency. - * @param player The player you are checking. - * @param currency The currency you wish to check. - * @param cost The cost of the item you are checking. - * @return True if they have enough to buy it or false if they don't. - */ - public boolean canBuy(Player player, Currency currency, int cost) { - return getCurrency(player, currency) >= cost; - } - - private void takeTotalExperience(Player player, int amount) { - int total = getTotalExperience(player) - amount; - player.setTotalExperience(0); - player.setTotalExperience(total); - player.setLevel(0); - player.setExp(0); - - while (total > player.getExpToLevel()) { - total -= player.getExpToLevel(); - player.setLevel(player.getLevel() + 1); - } - - float xp = (float) total / (float) player.getExpToLevel(); - player.setExp(xp); - } - - private int getTotalExperience(Player player) { // https://www.spigotmc.org/threads/72804 - int experience; - int level = player.getLevel(); - - if (level >= 0 && level <= 15) { - experience = (int) Math.ceil(Math.pow(level, 2) + (6 * level)); - int requiredExperience = 2 * level + 7; - double currentExp = Double.parseDouble(Float.toString(player.getExp())); - experience += Math.ceil(currentExp * requiredExperience); - return experience; - } else if (level > 15 && level <= 30) { - experience = (int) Math.ceil((2.5 * Math.pow(level, 2) - (40.5 * level) + 360)); - int requiredExperience = 5 * level - 38; - double currentExp = Double.parseDouble(Float.toString(player.getExp())); - experience += Math.ceil(currentExp * requiredExperience); - return experience; - } else { - experience = (int) Math.ceil((4.5 * Math.pow(level, 2) - (162.5 * level) + 2220)); - int requiredExperience = 9 * level - 158; - double currentExp = Double.parseDouble(Float.toString(player.getExp())); - experience += Math.ceil(currentExp * requiredExperience); - return experience; - } - } - - /** - * Loads the vault currency if it is on the server. - */ - public void loadCurrency() { - vaultSupport.loadVault(); - } -} \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazyauctions/api/economy/vault/VaultSupport.java b/src/main/java/com/badbones69/crazyauctions/api/economy/vault/VaultSupport.java deleted file mode 100644 index b5d80f1..0000000 --- a/src/main/java/com/badbones69/crazyauctions/api/economy/vault/VaultSupport.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.badbones69.crazyauctions.api.economy.vault; - -import com.badbones69.crazyauctions.CrazyAuctions; -import com.badbones69.crazyauctions.utils.func.PluginSupport; -import net.milkbowl.vault.economy.Economy; -import org.bukkit.plugin.RegisteredServiceProvider; - -public class VaultSupport { - - private final CrazyAuctions plugin = CrazyAuctions.getPlugin(); - - private Economy vault = null; - - public Economy getVault() { - return vault; - } - - public void loadVault() { - if (PluginSupport.VAULT.isPluginLoaded()) { - RegisteredServiceProvider rsp = plugin.getServer().getServicesManager().getRegistration(Economy.class); - - if (rsp != null) vault = rsp.getProvider(); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazyauctions/api/enums/AuctionCategories.java b/src/main/java/com/badbones69/crazyauctions/api/enums/AuctionCategories.java deleted file mode 100644 index 0de5742..0000000 --- a/src/main/java/com/badbones69/crazyauctions/api/enums/AuctionCategories.java +++ /dev/null @@ -1,207 +0,0 @@ -package com.badbones69.crazyauctions.api.enums; - -import com.badbones69.crazyauctions.utils.func.ServerProtocol; -import org.bukkit.Material; -import java.util.ArrayList; - -public enum AuctionCategories { - - NONE("None", new ArrayList<>()), - OTHER("Other", getOthers()), - ARMOR("Armor", getArmor()), - WEAPONS("Weapons", getWeapons()), - TOOLS("Tools", getTools()), - FOOD("Food", getFood()), - POTIONS("Potions", getPotions()), - BLOCKS("Blocks", getBlocks()); - - private final String name; - private final ArrayList items; - - /** - * @param name Name of the Shop Type. - */ - AuctionCategories(String name, ArrayList items) { - this.name = name; - this.items = items; - } - - /** - * @param name Name of the Type you want. - * @return Returns the Type as an Enum. - */ - public static AuctionCategories getFromName(String name) { - for (AuctionCategories type : AuctionCategories.values()) { - if (type.getName().equalsIgnoreCase(name)) return type; - } - - return null; - } - - private static ArrayList getArmor() { - ArrayList ma = new ArrayList<>(); - - ma.add(Material.LEATHER_HELMET); - ma.add(Material.LEATHER_CHESTPLATE); - ma.add(Material.LEATHER_LEGGINGS); - ma.add(Material.LEATHER_BOOTS); - - ma.add(Material.GOLDEN_HELMET); - ma.add(Material.GOLDEN_CHESTPLATE); - ma.add(Material.GOLDEN_LEGGINGS); - ma.add(Material.GOLDEN_BOOTS); - - ma.add(Material.CHAINMAIL_HELMET); - ma.add(Material.CHAINMAIL_CHESTPLATE); - ma.add(Material.CHAINMAIL_LEGGINGS); - ma.add(Material.CHAINMAIL_BOOTS); - - ma.add(Material.IRON_HELMET); - ma.add(Material.IRON_CHESTPLATE); - ma.add(Material.IRON_LEGGINGS); - ma.add(Material.IRON_BOOTS); - - ma.add(Material.DIAMOND_HELMET); - ma.add(Material.DIAMOND_CHESTPLATE); - ma.add(Material.DIAMOND_LEGGINGS); - ma.add(Material.DIAMOND_BOOTS); - - ma.add(Material.TURTLE_HELMET); - - if (ServerProtocol.isNewer(ServerProtocol.v1_15_R1)) { - ma.add(Material.NETHERITE_HELMET); - ma.add(Material.NETHERITE_CHESTPLATE); - ma.add(Material.NETHERITE_LEGGINGS); - ma.add(Material.NETHERITE_BOOTS); - } - - return ma; - } - - private static ArrayList getTools() { - ArrayList ma = new ArrayList<>(); - - ma.add(Material.WOODEN_PICKAXE); - ma.add(Material.WOODEN_AXE); - ma.add(Material.WOODEN_SHOVEL); - ma.add(Material.WOODEN_HOE); - - ma.add(Material.STONE_PICKAXE); - ma.add(Material.STONE_AXE); - ma.add(Material.STONE_SHOVEL); - ma.add(Material.STONE_HOE); - - ma.add(Material.GOLDEN_PICKAXE); - ma.add(Material.GOLDEN_AXE); - ma.add(Material.GOLDEN_SHOVEL); - ma.add(Material.GOLDEN_HOE); - - ma.add(Material.IRON_PICKAXE); - ma.add(Material.IRON_AXE); - ma.add(Material.IRON_SHOVEL); - ma.add(Material.IRON_HOE); - - ma.add(Material.DIAMOND_PICKAXE); - ma.add(Material.DIAMOND_AXE); - ma.add(Material.DIAMOND_SHOVEL); - ma.add(Material.DIAMOND_HOE); - - ma.add(Material.SHEARS); - ma.add(Material.FISHING_ROD); - ma.add(Material.FLINT_AND_STEEL); - ma.add(Material.SPYGLASS); - - if (ServerProtocol.isNewer(ServerProtocol.v1_15_R1)) { - ma.add(Material.NETHERITE_PICKAXE); - 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.WOODEN_SWORD); - ma.add(Material.WOODEN_AXE); - - ma.add(Material.STONE_SWORD); - ma.add(Material.STONE_AXE); - - ma.add(Material.GOLDEN_SWORD); - ma.add(Material.GOLDEN_AXE); - - ma.add(Material.IRON_SWORD); - ma.add(Material.IRON_AXE); - - ma.add(Material.DIAMOND_SWORD); - ma.add(Material.DIAMOND_AXE); - - ma.add(Material.BOW); - ma.add(Material.CROSSBOW); - ma.add(Material.TRIDENT); - - if (ServerProtocol.isNewer(ServerProtocol.v1_15_R1)) { - 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); - - if (Material.matchMaterial("SPLASH_POTION") != null) ma.add(Material.matchMaterial("SPLASH_POTION")); - - if (Material.matchMaterial("LINGERING_POTION") != null) ma.add(Material.matchMaterial("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; - } - - /** - * @return Returns the type name as a string. - */ - public String getName() { - return name; - } - - public ArrayList getItems() { - return items; - } -} \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazyauctions/api/enums/CancelledReason.java b/src/main/java/com/badbones69/crazyauctions/api/enums/CancelledReason.java deleted file mode 100644 index 12da0b2..0000000 --- a/src/main/java/com/badbones69/crazyauctions/api/enums/CancelledReason.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.badbones69.crazyauctions.api.enums; - -public enum CancelledReason { - - /** - * Cancelled by an administrator. - */ - ADMIN_FORCE_CANCEL(), - /** - * Cancelled by the player them self. - */ - PLAYER_FORCE_CANCEL() -} \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazyauctions/api/enums/Messages.java b/src/main/java/com/badbones69/crazyauctions/api/enums/Messages.java deleted file mode 100644 index 2bfe4ce..0000000 --- a/src/main/java/com/badbones69/crazyauctions/api/enums/Messages.java +++ /dev/null @@ -1,215 +0,0 @@ -package com.badbones69.crazyauctions.api.enums; - -import com.badbones69.crazyauctions.CrazyAuctions; -import com.badbones69.crazyauctions.Methods; -import com.badbones69.crazyauctions.api.FileManager; -import com.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]"), - BOOK_NOT_ALLOWED("Book-Not-Allowed", "&cThat book is not able to be sold in this auction house!"), - 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 final String path; - private String defaultMessage; - private List defaultListMessage; - - private static final CrazyAuctions plugin = CrazyAuctions.getPlugin(); - - private static final Methods methods = plugin.getStarter().getMethods(); - - Messages(String path, String defaultMessage) { - this.path = path; - this.defaultMessage = defaultMessage; - } - - Messages(String path, List defaultListMessage) { - this.path = path; - this.defaultListMessage = defaultListMessage; - } - - public static String convertList(List list) { - StringBuilder message = new StringBuilder(); - - for (String m : list) { - message.append(methods.color(m)).append("\n"); - } - - return message.toString(); - } - - public static String convertList(List list, HashMap placeholders) { - StringBuilder message = new StringBuilder(); - for (String m : list) { - message.append(methods.color(m)).append("\n"); - } - - for (String ph : placeholders.keySet()) { - message = new StringBuilder(methods.color(message.toString().replace(ph, placeholders.get(ph))).replace(ph, placeholders.get(ph).toLowerCase())); - } - return message.toString(); - } - - 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(); - } - - 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.replace(ph, placeholders.get(ph)).replace(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.replace(ph, placeholders.get(ph)).replace(ph, placeholders.get(ph).toLowerCase()); - } - } - return message; - } - - 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/com/badbones69/crazyauctions/api/enums/ShopCategories.java b/src/main/java/com/badbones69/crazyauctions/api/enums/ShopCategories.java deleted file mode 100644 index e2d84d3..0000000 --- a/src/main/java/com/badbones69/crazyauctions/api/enums/ShopCategories.java +++ /dev/null @@ -1,92 +0,0 @@ -package com.badbones69.crazyauctions.api.enums; - -import com.badbones69.crazyauctions.api.economy.Currency; -import com.badbones69.crazyauctions.utils.ItemBuilder; - -import java.util.HashMap; - -public enum ShopCategories { - - SELL("Sell"), - BID("Bid"); - - private final String name; - - private final HashMap shopCategories = new HashMap<>(); - - /** - * @param name name of the Shop Type. - */ - ShopCategories(String name) { - this.name = name; - } - - /** - * @param name name of the Type you want. - * @return Returns the Type as an Enum. - */ - public static ShopCategories getFromName(String name) { - for (ShopCategories type : ShopCategories.values()) { - if (type.getName().equalsIgnoreCase(name)) return type; - } - - return null; - } - - public Currency getCurrency() { - return shopCategories.get(this).currency; - } - - public int getCost() { - return shopCategories.get(this).cost; - } - - /** - * @return Returns the type name as a string. - */ - public String getName() { - return name; - } - - private static class Options { - - private final ItemBuilder itemBuilder; - - private final int slot; - private final boolean inMenu; - private int cost; - private final Currency currency; - - public Options(ItemBuilder itemBuilder, int slot, boolean inMenu, int cost, Currency currency) { - this.itemBuilder = itemBuilder; - this.slot = slot; - this.inMenu = inMenu; - this.cost = cost; - this.currency = currency; - } - - public ItemBuilder getItemBuilder() { - return itemBuilder; - } - - public int getSlot() { - return slot; - } - - public int getCost() { - return cost; - } - - public Currency getCurrency() { - return currency; - } - - public boolean isInMenu() { - return inMenu; - } - - public void setCost(int cost) { - this.cost = cost; - } - } -} \ 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 deleted file mode 100644 index 4da1a46..0000000 --- a/src/main/java/com/badbones69/crazyauctions/api/events/AuctionBuyEvent.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.badbones69.crazyauctions.api.events; - -import org.bukkit.entity.Player; -import org.bukkit.event.Event; -import org.bukkit.event.HandlerList; -import org.bukkit.inventory.ItemStack; - -/** - * @author BadBones69 - * - * This event is fired when a player buys something from the selling auction house. - */ -public class AuctionBuyEvent extends Event { - - private final HandlerList handlers = new HandlerList(); - private final Player player; - private final long price; - private final ItemStack item; - - /** - * @param player The player who bought the item. - * @param item The item that was bought. - * @param price The price of the item. - */ - public AuctionBuyEvent(Player player, ItemStack item, long price) { - this.player = player; - this.item = item; - this.price = price; - } - - public HandlerList getHandlers() { - return handlers; - } - - public Player getPlayer() { - return player; - } - - public ItemStack getItem() { - return item; - } - - public long getPrice() { - return 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 deleted file mode 100644 index fe13b63..0000000 --- a/src/main/java/com/badbones69/crazyauctions/api/events/AuctionCancelledEvent.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.badbones69.crazyauctions.api.events; - -import com.badbones69.crazyauctions.api.enums.CancelledReason; -import org.bukkit.OfflinePlayer; -import org.bukkit.entity.Player; -import org.bukkit.event.Event; -import org.bukkit.event.HandlerList; -import org.bukkit.inventory.ItemStack; - -/** - * @author BadBones69 - * - * This event is fired when a player's item is cancelled. - */ -public class AuctionCancelledEvent extends Event { - - private final HandlerList handlers = new HandlerList(); - private OfflinePlayer offlinePlayer; - private Player onlinePlayer; - private final boolean isOnline; - private final ItemStack item; - private final CancelledReason reason; - - /** - * @param offlinePlayer The player whose item is cancelled. - * @param item The item that is cancelled. - */ - public AuctionCancelledEvent(OfflinePlayer offlinePlayer, ItemStack item, CancelledReason reason) { - this.offlinePlayer = offlinePlayer; - this.item = item; - this.isOnline = false; - this.reason = reason; - } - - /** - * @param onlinePlayer The player whose item is cancelled. - * @param item The item that is cancelled. - */ - public AuctionCancelledEvent(Player onlinePlayer, ItemStack item, CancelledReason reason) { - this.onlinePlayer = onlinePlayer; - this.item = item; - this.isOnline = true; - this.reason = reason; - } - - public HandlerList getHandlers() { - return handlers; - } - - public OfflinePlayer getOfflinePlayer() { - return offlinePlayer; - } - - public Player getOnlinePlayer() { - return onlinePlayer; - } - - public boolean isOnline() { - return isOnline; - } - - public ItemStack getItem() { - return item; - } - - public CancelledReason getReason() { - return 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 deleted file mode 100644 index 5102904..0000000 --- a/src/main/java/com/badbones69/crazyauctions/api/events/AuctionExpireEvent.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.badbones69.crazyauctions.api.events; - -import org.bukkit.OfflinePlayer; -import org.bukkit.entity.Player; -import org.bukkit.event.Event; -import org.bukkit.event.HandlerList; -import org.bukkit.inventory.ItemStack; - -/** - * @author BadBones69 - * - * This event is fired when a player item expires. - */ -public class AuctionExpireEvent extends Event { - - private final HandlerList handlers = new HandlerList(); - private OfflinePlayer offlinePlayer; - private Player onlinePlayer; - private final boolean isOnline; - private final ItemStack item; - - /** - * @param offlinePlayer The player whose item is expiring. - * @param item The item that is expiring. - */ - public AuctionExpireEvent(OfflinePlayer offlinePlayer, ItemStack item) { - this.offlinePlayer = offlinePlayer; - this.item = item; - this.isOnline = false; - } - - /** - * @param onlinePlayer The player whose item is expiring. - * @param item The item that is expiring. - */ - public AuctionExpireEvent(Player onlinePlayer, ItemStack item) { - this.onlinePlayer = onlinePlayer; - this.item = item; - this.isOnline = true; - } - - public HandlerList getHandlers() { - return handlers; - } - - public OfflinePlayer getOfflinePlayer() { - return offlinePlayer; - } - - public Player getOnlinePlayer() { - return onlinePlayer; - } - - public boolean isOnline() { - return isOnline; - } - - public ItemStack getItem() { - return 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 deleted file mode 100644 index 2d7895f..0000000 --- a/src/main/java/com/badbones69/crazyauctions/api/events/AuctionListEvent.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.badbones69.crazyauctions.api.events; - -import com.badbones69.crazyauctions.api.enums.ShopCategories; -import org.bukkit.entity.Player; -import org.bukkit.event.Event; -import org.bukkit.event.HandlerList; -import org.bukkit.inventory.ItemStack; - -/** - * @author BadBones69 - * - * This event is fired when a new item is listed onto the auction house. - */ -public class AuctionListEvent extends Event { - - private final HandlerList handlers = new HandlerList(); - private final Player player; - private final long price; - private final ShopCategories shop; - private final ItemStack item; - - /** - * @param player The player who is listing the item. - * @param shop The shop type the item is being listed to. - * @param item The item being listed. - * @param price The price the item is being listed for. - */ - public AuctionListEvent(Player player, ShopCategories shop, ItemStack item, long price) { - this.player = player; - this.shop = shop; - this.item = item; - this.price = price; - } - - public HandlerList getHandlers() { - return handlers; - } - - public Player getPlayer() { - return player; - } - - public ShopCategories getShopType() { - return shop; - } - - public ItemStack getItem() { - return item; - } - - public long getPrice() { - return 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 deleted file mode 100644 index 5c5bb99..0000000 --- a/src/main/java/com/badbones69/crazyauctions/api/events/AuctionNewBidEvent.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.badbones69.crazyauctions.api.events; - -import org.bukkit.entity.Player; -import org.bukkit.event.Event; -import org.bukkit.event.HandlerList; -import org.bukkit.inventory.ItemStack; - -/** - * This event is fired when a player places a new bid onto an item in the auction house. - */ -public class AuctionNewBidEvent extends Event { - - private final HandlerList handlers = new HandlerList(); - private final Player player; - private final long bid; - private final ItemStack item; - - /** - * @param player The player who placed the bid. - * @param item The item that was bid on. - * @param bid The amount of money that was bid. - */ - public AuctionNewBidEvent(Player player, ItemStack item, long bid) { - this.player = player; - this.item = item; - this.bid = bid; - } - - public HandlerList getHandlers() { - return handlers; - } - - public Player getPlayer() { - return player; - } - - public ItemStack getItem() { - return item; - } - - public long getBid() { - return 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 deleted file mode 100644 index 0f3da3e..0000000 --- a/src/main/java/com/badbones69/crazyauctions/api/events/AuctionWinBidEvent.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.badbones69.crazyauctions.api.events; - -import org.bukkit.entity.Player; -import org.bukkit.event.Event; -import org.bukkit.event.HandlerList; -import org.bukkit.inventory.ItemStack; - -/** - * @author BadBones69 - * - * This event is fired when a bidding item's time has run out and so a player wins the item. - */ -public class AuctionWinBidEvent extends Event { - - private final HandlerList handlers = new HandlerList(); - private final Player player; - private final long bid; - private final ItemStack item; - - /** - * @param player The player who won the item. - * @param item The item that was won. - * @param bid The bid that was placed on the item. - */ - public AuctionWinBidEvent(Player player, ItemStack item, long bid) { - this.player = player; - this.item = item; - this.bid = bid; - } - - public HandlerList getHandlers() { - return handlers; - } - - public Player getPlayer() { - return player; - } - - public ItemStack getItem() { - return item; - } - - public long getBid() { - return bid; - } -} \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazyauctions/utils/ItemBuilder.java b/src/main/java/com/badbones69/crazyauctions/utils/ItemBuilder.java deleted file mode 100644 index 8b2a8fc..0000000 --- a/src/main/java/com/badbones69/crazyauctions/utils/ItemBuilder.java +++ /dev/null @@ -1,1261 +0,0 @@ -package com.badbones69.crazyauctions.utils; - -import com.badbones69.crazyauctions.CrazyAuctions; -import com.badbones69.crazyauctions.Methods; -import de.tr7zw.changeme.nbtapi.NBTItem; -import org.bukkit.Color; -import org.bukkit.DyeColor; -import org.bukkit.Material; -import org.bukkit.block.Banner; -import org.bukkit.block.banner.Pattern; -import org.bukkit.block.banner.PatternType; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.EntityType; -import org.bukkit.inventory.ItemFlag; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.*; -import org.bukkit.potion.PotionData; -import org.bukkit.potion.PotionEffectType; -import org.bukkit.potion.PotionType; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.UUID; -import java.util.stream.Collectors; - -public class ItemBuilder { - - private NBTItem nbtItem; - - // Item Data - private Material material; - private int damage; - private String itemName; - private final List itemLore; - private int itemAmount; - - // Player - private String player; - - // Skulls - private boolean isHash; - private boolean isURL; - private boolean isHead; - - // Enchantments/Flags - private boolean unbreakable; - private boolean hideItemFlags; - private boolean glowing; - - // Entities - private final boolean isMobEgg; - private EntityType entityType; - - // Potions - private PotionType potionType; - private Color potionColor; - private boolean isPotion; - - // Armor - private Color armorColor; - private boolean isLeatherArmor; - - // Enchantments - private HashMap enchantments; - - // Shields - private boolean isShield; - - // Banners - private boolean isBanner; - private List patterns; - - // Placeholders - private HashMap namePlaceholders; - private HashMap lorePlaceholders; - - // Misc - private ItemStack referenceItem; - private List itemFlags; - - // Custom Data - private int customModelData; - private boolean useCustomModelData; - - private final CrazyAuctions plugin = CrazyAuctions.getPlugin(); - - private final Methods methods = plugin.getStarter().getMethods(); - - private final SkullCreator skullCreator = plugin.getStarter().getSkullCreator(); - - /** - * Create a blank item builder. - */ - public ItemBuilder() { - this.nbtItem = null; - this.material = Material.STONE; - this.damage = 0; - this.itemName = ""; - this.itemLore = new ArrayList<>(); - this.itemAmount = 1; - this.player = ""; - - this.isHash = false; - this.isURL = false; - this.isHead = false; - - this.unbreakable = false; - this.hideItemFlags = false; - this.glowing = false; - - this.isMobEgg = false; - this.entityType = EntityType.BAT; - - this.potionType = null; - this.potionColor = null; - this.isPotion = false; - - this.armorColor = null; - this.isLeatherArmor = false; - - this.enchantments = new HashMap<>(); - - this.isShield = false; - - this.isBanner = false; - this.patterns = new ArrayList<>(); - - this.namePlaceholders = new HashMap<>(); - this.lorePlaceholders = new HashMap<>(); - - this.itemFlags = new ArrayList<>(); - } - - /** - * Deduplicate an item builder. - * - * @param itemBuilder The item builder to deduplicate. - */ - public ItemBuilder(ItemBuilder itemBuilder) { - this.nbtItem = itemBuilder.nbtItem; - this.material = itemBuilder.material; - this.damage = itemBuilder.damage; - this.itemName = itemBuilder.itemName; - this.itemLore = new ArrayList<>(itemBuilder.itemLore); - this.itemAmount = itemBuilder.itemAmount; - this.player = itemBuilder.player; - - this.referenceItem = itemBuilder.referenceItem; - this.customModelData = itemBuilder.customModelData; - this.useCustomModelData = itemBuilder.useCustomModelData; - - this.enchantments = new HashMap<>(itemBuilder.enchantments); - - this.isHash = itemBuilder.isHash; - this.isURL = itemBuilder.isURL; - this.isHead = itemBuilder.isHead; - - this.unbreakable = itemBuilder.unbreakable; - this.hideItemFlags = itemBuilder.hideItemFlags; - this.glowing = itemBuilder.glowing; - - this.isMobEgg = itemBuilder.isMobEgg; - this.entityType = itemBuilder.entityType; - - this.potionType = itemBuilder.potionType; - this.potionColor = itemBuilder.potionColor; - this.isPotion = itemBuilder.isPotion; - - this.armorColor = itemBuilder.armorColor; - this.isLeatherArmor = itemBuilder.isLeatherArmor; - - this.isShield = itemBuilder.isShield; - - this.isBanner = itemBuilder.isBanner; - this.patterns = new ArrayList<>(itemBuilder.patterns); - - this.namePlaceholders = new HashMap<>(itemBuilder.namePlaceholders); - this.lorePlaceholders = new HashMap<>(itemBuilder.lorePlaceholders); - this.itemFlags = new ArrayList<>(itemBuilder.itemFlags); - } - - /** - * Gets the nbt item. - */ - public NBTItem getNBTItem() { - nbtItem = new NBTItem(build()); - return nbtItem; - } - - /** - * Gets the material. - */ - public Material getMaterial() { - return material; - } - - /** - * Checks if the item is a banner. - */ - public boolean isBanner() { - return isBanner; - } - - /** - * Checks if an item is a shield. - */ - public boolean isShield() { - return isShield; - } - - /** - * Checks if the item is a spawn mob egg. - */ - public boolean isMobEgg() { - return isMobEgg; - } - - /** - * Returns the player name. - */ - public String getPlayerName() { - return player; - } - - /** - * Get the entity type of the spawn mob egg. - */ - public EntityType getEntityType() { - return entityType; - } - - /** - * Get the name of the item. - */ - public String getName() { - return itemName; - } - - /** - * Get the lore on the item. - */ - public List getLore() { - return itemLore; - } - - /** - * Returns the enchantments on the Item. - */ - public HashMap getEnchantments() { - return enchantments; - } - - /** - * Return a list of Item Flags. - */ - public List getItemFlags() { - return itemFlags; - } - - /** - * Checks if flags are hidden. - */ - public boolean isItemFlagsHidden() { - return hideItemFlags; - } - - /** - * Check if item is Leather Armor - */ - public boolean isLeatherArmor() { - return isLeatherArmor; - } - - /** - * Checks if item is glowing. - */ - public boolean isGlowing() { - return glowing; - } - - /** - * Checks if the item is unbreakable. - */ - public boolean isUnbreakable() { - return unbreakable; - } - - /** - * Returns the amount of the item stack. - */ - public Integer getAmount() { - return itemAmount; - } - - /** - * Get the patterns on the banners. - */ - public List getPatterns() { - return patterns; - } - - /** - * Get the item's name with all the placeholders added to it. - * - * @return The name with all the placeholders in it. - */ - public String getUpdatedName() { - String newName = itemName; - - for (String placeholder : namePlaceholders.keySet()) { - newName = newName.replace(placeholder, namePlaceholders.get(placeholder)).replace(placeholder.toLowerCase(), namePlaceholders.get(placeholder)); - } - - return newName; - } - - /** - * Builder the item from all the information that was given to the builder. - * - * @return The result of all the info that was given to the builder as an ItemStack. - */ - public ItemStack build() { - - if (nbtItem != null) referenceItem = nbtItem.getItem(); - - ItemStack item = referenceItem != null ? referenceItem : new ItemStack(material); - - if (item.getType() != Material.AIR) { - if (isHead) { // Has to go 1st due to it removing all data when finished. - if (isHash) { // Sauce: https://github.com/deanveloper/SkullCreator - if (isURL) { - skullCreator.itemWithUrl(item, player); - } else { - skullCreator.itemWithBase64(item, player); - } - } - } - - item.setAmount(itemAmount); - ItemMeta itemMeta = item.getItemMeta(); - assert itemMeta != null; - itemMeta.setDisplayName(getUpdatedName()); - itemMeta.setLore(getUpdatedLore()); - - if (itemMeta instanceof org.bukkit.inventory.meta.Damageable) ((org.bukkit.inventory.meta.Damageable) itemMeta).setDamage(damage); - - if (isPotion && (potionType != null || potionColor != null)) { - PotionMeta potionMeta = (PotionMeta) itemMeta; - - if (potionType != null) potionMeta.setBasePotionData(new PotionData(potionType)); - - if (potionColor != null) potionMeta.setColor(potionColor); - } - - if (material == Material.TIPPED_ARROW && potionType != null) { - PotionMeta potionMeta = (PotionMeta) itemMeta; - potionMeta.setBasePotionData(new PotionData(potionType)); - } - - if (isLeatherArmor && armorColor != null) { - LeatherArmorMeta leatherMeta = (LeatherArmorMeta) itemMeta; - leatherMeta.setColor(armorColor); - } - - if (isBanner && !patterns.isEmpty()) { - BannerMeta bannerMeta = (BannerMeta) itemMeta; - bannerMeta.setPatterns(patterns); - } - - if (isShield && !patterns.isEmpty()) { - BlockStateMeta shieldMeta = (BlockStateMeta) itemMeta; - Banner banner = (Banner) shieldMeta.getBlockState(); - banner.setPatterns(patterns); - banner.update(); - shieldMeta.setBlockState(banner); - } - - if (useCustomModelData) itemMeta.setCustomModelData(customModelData); - - itemFlags.forEach(itemMeta :: addItemFlags); - item.setItemMeta(itemMeta); - hideItemFlags(item); - item.addUnsafeEnchantments(enchantments); - addGlow(item); - NBTItem nbt = new NBTItem(item); - - if (isHead && !isHash) nbt.setString("SkullOwner", player); - - if (isMobEgg) { - if (entityType != null) nbt.addCompound("EntityTag").setString("id", "minecraft:" + entityType.name()); - } - - return nbt.getItem(); - } else { - return item; - } - } - - /* - Class based extensions. - */ - - /** - * Set the type of item the builder is set to. - * - * @param material The material you wish to set. - * @return The ItemBuilder with updated info. - */ - public ItemBuilder setMaterial(Material material) { - this.material = material; - this.isHead = material == Material.PLAYER_HEAD; - return this; - } - - /** - * Set the type of item and its metadata in the builder. - * - * @param material The string must be in this form: %Material% or %Material%:%MetaData% - * @return The ItemBuilder with updated info. - */ - public ItemBuilder setMaterial(String material) { - String metaData; - - if (material.contains(":")) { // Sets the durability or another value option. - String[] b = material.split(":"); - material = b[0]; - metaData = b[1]; - - if (metaData.contains("#")) { // :# - String modelData = metaData.split("#")[1]; - - if (isInt(modelData)) { // Value is a number. - this.useCustomModelData = true; - this.customModelData = Integer.parseInt(modelData); - } - } - - metaData = metaData.replace("#" + customModelData, ""); - - if (isInt(metaData)) { // Value is durability. - this.damage = Integer.parseInt(metaData); - } else { // Value is something else. - this.potionType = getPotionType(PotionEffectType.getByName(metaData)); - this.potionColor = getColor(metaData); - this.armorColor = getColor(metaData); - } - - } else if (material.contains("#")) { - String[] b = material.split("#"); - material = b[0]; - - if (isInt(b[1])) { // Value is a number. - this.useCustomModelData = true; - this.customModelData = Integer.parseInt(b[1]); - } - } - - Material matchedMaterial = Material.matchMaterial(material); - - if (matchedMaterial != null) this.material = matchedMaterial; - - switch (this.material.name()) { - case "PLAYER_HEAD": - case "SKULL_ITEM": - this.isHead = true; - break; - case "POTION": - case "SPLASH_POTION": - this.isPotion = true; - break; - case "LEATHER_HELMET": - case "LEATHER_CHESTPLATE": - case "LEATHER_LEGGINGS": - case "LEATHER_BOOTS": - case "LEATHER_HORSE_ARMOR": - this.isLeatherArmor = true; - break; - case "BANNER": - this.isBanner = true; - break; - case "SHIELD": - this.isShield = true; - break; - } - - if (this.material.name().contains("BANNER")) this.isBanner = true; - - return this; - } - - /** - * @param damage The damage value of the item. - * @return The ItemBuilder with an updated damage value. - */ - public ItemBuilder setDamage(int damage) { - this.damage = damage; - return this; - } - - /** - * @param itemName The name of the item. - * @return The ItemBuilder with an updated name. - */ - public ItemBuilder setName(String itemName) { - if (itemName != null) this.itemName = methods.color(itemName); - - return this; - } - - /** - * @param placeholders The placeholders that will be used. - * @return The ItemBuilder with updated placeholders. - */ - public ItemBuilder setNamePlaceholders(HashMap placeholders) { - this.namePlaceholders = placeholders; - return this; - } - - /** - * Add a placeholder to the name of the item. - * - * @param placeholder The placeholder that will be replaced. - * @param argument The argument you wish to replace the placeholder with. - * @return The ItemBuilder with updated info. - */ - public ItemBuilder addNamePlaceholder(String placeholder, String argument) { - this.namePlaceholders.put(placeholder, argument); - return this; - } - - /** - * Remove a placeholder from the list. - * - * @param placeholder The placeholder you wish to remove. - * @return The ItemBuilder with updated info. - */ - public ItemBuilder removeNamePlaceholder(String placeholder) { - this.namePlaceholders.remove(placeholder); - return this; - } - - /** - * Set the lore of the item in the builder. This will auto force color in all the lores that contains color code. (&a, &c, &7, etc...) - * - * @param lore The lore of the item in the builder. - * @return The ItemBuilder with updated info. - */ - public ItemBuilder setLore(List lore) { - if (lore != null) { - this.itemLore.clear(); - - for (String line : lore) { - this.itemLore.add(methods.color(line)); - } - } - - return this; - } - - /** - * Add a line to the current lore of the item. This will auto force color in the lore that contains color code. (&a, &c, &7, etc...) - * - * @param lore The new line you wish to add. - * @return The ItemBuilder with updated info. - */ - public ItemBuilder addLore(String lore) { - if (lore != null) this.itemLore.add(methods.color(lore)); - - return this; - } - - /** - * Set the placeholders that are in the lore of the item. - * - * @param placeholders The placeholders that you wish to use. - * @return The ItemBuilder with updated info. - */ - public ItemBuilder setLorePlaceholders(HashMap placeholders) { - this.lorePlaceholders = placeholders; - return this; - } - - /** - * Add a placeholder to the lore of the item. - * - * @param placeholder The placeholder you wish to replace. - * @param argument The argument that will replace the placeholder. - * @return The ItemBuilder with updated info. - */ - public ItemBuilder addLorePlaceholder(String placeholder, String argument) { - this.lorePlaceholders.put(placeholder, argument); - return this; - } - - /** - * Get the lore with all the placeholders added to it. - * - * @return The lore with all placeholders in it. - */ - public List getUpdatedLore() { - List newLore = new ArrayList<>(); - - for (String item : itemLore) { - for (String placeholder : lorePlaceholders.keySet()) { - item = item.replace(placeholder, lorePlaceholders.get(placeholder)).replace(placeholder.toLowerCase(), lorePlaceholders.get(placeholder)); - } - - newLore.add(item); - } - - return newLore; - } - - /** - * Remove a placeholder from the lore. - * - * @param placeholder The placeholder you wish to remove. - * @return The ItemBuilder with updated info. - */ - public ItemBuilder removeLorePlaceholder(String placeholder) { - this.lorePlaceholders.remove(placeholder); - return this; - } - - /** - * @param entityType The entity type the mob spawn egg will be. - * @return The ItemBuilder with an updated mob spawn egg. - */ - public ItemBuilder setEntityType(EntityType entityType) { - this.entityType = entityType; - return this; - } - - /** - * Add patterns to the item. - * - * @param stringPattern The pattern you wish to add. - */ - private void addPatterns(String stringPattern) { - try { - String[] split = stringPattern.split(":"); - - for (PatternType pattern : PatternType.values()) { - - if (split[0].equalsIgnoreCase(pattern.name()) || split[0].equalsIgnoreCase(pattern.getIdentifier())) { - DyeColor color = getDyeColor(split[1]); - - if (color != null) addPattern(new Pattern(color, pattern)); - - break; - } - } - } catch (Exception ignored) {} - } - - /** - * @param patterns The list of Patterns to add. - * @return The ItemBuilder with updated patterns. - */ - public ItemBuilder addPatterns(List patterns) { - patterns.forEach(this :: addPatterns); - return this; - } - - /** - * @param pattern A pattern to add. - * @return The ItemBuilder with an updated pattern. - */ - public ItemBuilder addPattern(Pattern pattern) { - patterns.add(pattern); - return this; - } - - /** - * @param patterns Set a list of Patterns. - * @return The ItemBuilder with an updated list of patterns. - */ - public ItemBuilder setPattern(List patterns) { - this.patterns = patterns; - return this; - } - - /** - * @param amount The amount of the item stack. - * @return The ItemBuilder with an updated item count. - */ - public ItemBuilder setAmount(Integer amount) { - this.itemAmount = amount; - return this; - } - - /** - * Set the player that will be displayed on the head. - * - * @param playerName The player being displayed on the head. - * @return The ItemBuilder with an updated Player Name. - */ - public ItemBuilder setPlayerName(String playerName) { - this.player = playerName; - - if (player != null && player.length() > 16) { - this.isHash = true; - this.isURL = player.startsWith("http"); - } - - return this; - } - - /** - * It will override any enchantments used in ItemBuilder.addEnchantment() below. - * - * @param enchantment A list of enchantments to add to the item. - * @return The ItemBuilder with a list of updated enchantments. - */ - public ItemBuilder setEnchantments(HashMap enchantment) { - if (enchantment != null) this.enchantments = enchantment; - - return this; - } - - /** - * Adds an enchantment to the item. - * - * @param enchantment The enchantment you wish to add. - * @param level The level of the enchantment ( Unsafe levels included ) - * @return The ItemBuilder with updated enchantments. - */ - public ItemBuilder addEnchantments(Enchantment enchantment, int level) { - this.enchantments.put(enchantment, level); - return this; - } - - /** - * Remove an enchantment from the item. - * - * @param enchantment The enchantment you wish to remove. - * @return The ItemBuilder with updated enchantments. - */ - public ItemBuilder removeEnchantments(Enchantment enchantment) { - this.enchantments.remove(enchantment); - return this; - } - - /** - * Set the flags that will be on the item in the builder. - * - * @param flagStrings The flag names as string you wish to add to the item in the builder. - * @return The ItemBuilder with updated info. - */ - public ItemBuilder setFlagsFromStrings(List flagStrings) { - itemFlags.clear(); - - for (String flagString : flagStrings) { - ItemFlag flag = getFlag(flagString); - - if (flag != null) itemFlags.add(flag); - } - - return this; - } - - // Used for multiple Item Flags - public ItemBuilder addItemFlags(List flagStrings) { - for (String flagString : flagStrings) { - try { - ItemFlag itemFlag = ItemFlag.valueOf(flagString.toUpperCase()); - - if (itemFlag != null) addItemFlag(itemFlag); - } catch (Exception ignored) {} - } - - return this; - } - - /** - * Add a flag to the item in the builder. - * - * @param flagString The name of the flag you wish to add. - * @return The ItemBuilder with updated info. - */ - public ItemBuilder addFlags(String flagString) { - ItemFlag flag = getFlag(flagString); - - if (flag != null) itemFlags.add(flag); - return this; - } - - /** - * Adds an ItemFlag to a map which is added to an item. - * - * @param itemFlag The flag to add. - * @return The ItemBuilder with an updated ItemFlag. - */ - public ItemBuilder addItemFlag(ItemFlag itemFlag) { - if (itemFlag != null) itemFlags.add(itemFlag); - - return this; - } - - /** - * Adds multiple ItemFlags in a list to a map which get added to an item. - * - * @param itemFlags The list of flags to add. - * @return The ItemBuilder with a list of ItemFlags. - */ - public ItemBuilder setItemFlags(List itemFlags) { - this.itemFlags = itemFlags; - return this; - } - - /** - * @param hideItemFlags Hide item flags based on a boolean. - * @return The ItemBuilder with an updated Boolean. - */ - public ItemBuilder hideItemFlags(boolean hideItemFlags) { - this.hideItemFlags = hideItemFlags; - return this; - } - - /** - * @param item The item to hide flags on. - * @return The ItemBuilder with an updated Item. - */ - public ItemStack hideItemFlags(ItemStack item) { - if (hideItemFlags) { - if (item != null && item.hasItemMeta() && item.getItemMeta() != null) { - ItemMeta itemMeta = item.getItemMeta(); - itemMeta.addItemFlags(ItemFlag.values()); - item.setItemMeta(itemMeta); - return item; - } - } - - return item; - } - - /** - * Sets the converted item as a reference to try and save NBT tags and stuff. - * - * @param referenceItem The item that is being referenced. - * @return The ItemBuilder with updated info. - */ - private ItemBuilder setReferenceItem(ItemStack referenceItem) { - this.referenceItem = referenceItem; - return this; - } - - /** - * @param unbreakable Sets the item to be unbreakable. - * @return The ItemBuilder with an updated Boolean. - */ - public ItemBuilder setUnbreakable(boolean unbreakable) { - this.unbreakable = unbreakable; - return this; - } - - /** - * @param glow Sets whether to make an item to glow or not. - * @return The ItemBuilder with an updated Boolean. - */ - public ItemBuilder setGlow(boolean glow) { - this.glowing = glow; - return this; - } - - /** - * The text that will be displayed on the item. - * - * @param texture The skull texture. - * @param profileUUID The uuid of the profile. - * @return The ItemBuilder. - */ - public ItemBuilder texture(String texture, UUID profileUUID) { - return this; - } - - /** - * @param texture The skull texture. - * @return The ItemBuilder. - */ - public ItemBuilder texture(String texture) { - return this; - } - - /** - * @param texture The owner of the skull. - * @return The ItemBuilder. - */ - public ItemBuilder owner(String texture) { - return this; - } - - // Other misc shit - - /** - * Convert an ItemStack to an ItemBuilder to allow easier editing of the ItemStack. - * - * @param item The ItemStack you wish to convert into an ItemBuilder. - * @return The ItemStack as an ItemBuilder with all the info from the item. - */ - public static ItemBuilder convertItemStack(ItemStack item) { - ItemBuilder itemBuilder = new ItemBuilder().setReferenceItem(item).setAmount(item.getAmount()).setMaterial(item.getType()).setEnchantments(new HashMap<>(item.getEnchantments())); - - if (item.hasItemMeta() && item.getItemMeta() != null) { - ItemMeta itemMeta = item.getItemMeta(); - itemBuilder.setName(itemMeta.getDisplayName()).setLore(itemMeta.getLore()); - NBTItem nbt = new NBTItem(item); - - if (nbt.hasKey("Unbreakable")) itemBuilder.setUnbreakable(nbt.getBoolean("Unbreakable")); - - if (itemMeta instanceof org.bukkit.inventory.meta.Damageable) itemBuilder.setDamage(((org.bukkit.inventory.meta.Damageable) itemMeta).getDamage()); - } - - return itemBuilder; - } - - /** - * Converts a String to an ItemBuilder. - * - * @param itemString The String you wish to convert. - * @return The String as an ItemBuilder. - */ - public static ItemBuilder convertString(String itemString) { - return convertString(itemString, null); - } - - /** - * Converts a string to an ItemBuilder with a placeholder for errors. - * - * @param itemString The String you wish to convert. - * @param placeHolder The placeholder to use if there is an error. - * @return The String as an ItemBuilder. - */ - public static ItemBuilder convertString(String itemString, String placeHolder) { - ItemBuilder itemBuilder = new ItemBuilder(); - - try { - for (String optionString : itemString.split(", ")) { - String option = optionString.split(":")[0]; - String value = optionString.replace(option + ":", "").replace(option, ""); - - switch (option.toLowerCase()) { - case "item": - itemBuilder.setMaterial(value); - break; - case "name": - itemBuilder.setName(value); - break; - case "amount": - try { - itemBuilder.setAmount(Integer.parseInt(value)); - } catch (NumberFormatException e) { - itemBuilder.setAmount(1); - } - break; - case "lore": - itemBuilder.setLore(Arrays.asList(value.split(","))); - break; - case "player": - itemBuilder.setPlayerName(value); - break; - case "unbreakable-item": - if (value.isEmpty() || value.equalsIgnoreCase("true")) itemBuilder.setUnbreakable(true); - break; - default: - Enchantment enchantment = getEnchantment(option); - - if (enchantment != null && enchantment.getName() != null) { - try { - itemBuilder.addEnchantments(enchantment, Integer.parseInt(value)); - } catch (NumberFormatException e) { - itemBuilder.addEnchantments(enchantment, 1); - } - - break; - } - - for (ItemFlag itemFlag : ItemFlag.values()) { - if (itemFlag.name().equalsIgnoreCase(option)) { - itemBuilder.addItemFlag(itemFlag); - break; - } - } - - try { - for (PatternType pattern : PatternType.values()) { - if (option.equalsIgnoreCase(pattern.name()) || value.equalsIgnoreCase(pattern.getIdentifier())) { - DyeColor color = getDyeColor(value); - if (color != null) itemBuilder.addPattern(new Pattern(color, pattern)); - break; - } - } - } catch (Exception ignored) {} - break; - } - } - } catch (Exception e) { - itemBuilder.setMaterial(Material.RED_TERRACOTTA).setName("&c&lERROR").setLore(Arrays.asList("&cThere is an error", "&cFor : &c" + (placeHolder != null ? placeHolder : ""))); - e.printStackTrace(); - } - - return itemBuilder; - } - - /** - * Converts a list of Strings to a list of ItemBuilders. - * - * @param itemStrings The list of Strings. - * @return The list of ItemBuilders. - */ - public static List convertStringList(List itemStrings) { - return convertStringList(itemStrings, null); - } - - /** - * Converts a list of Strings to a list of ItemBuilders with a placeholder for errors. - * - * @param itemStrings The list of Strings. - * @param placeholder The placeholder for errors. - * @return The list of ItemBuilders. - */ - public static List convertStringList(List itemStrings, String placeholder) { - return itemStrings.stream().map(itemString -> convertString(itemString, placeholder)).collect(Collectors.toList()); - } - - /** - * Add glow to an item. - * - * @param item The item to add glow to. - */ - private void addGlow(ItemStack item) { - if (glowing) { - try { - if (item != null && item.getItemMeta() != null) { - if (item.hasItemMeta()) { - if (item.getItemMeta().hasEnchants()) return; - } - - item.addUnsafeEnchantment(Enchantment.LUCK, 1); - ItemMeta meta = item.getItemMeta(); - meta.addItemFlags(ItemFlag.HIDE_ENCHANTS); - item.setItemMeta(meta); - } - } catch (NoClassDefFoundError ignored) {} - } - } - - /** - * Get the PotionEffect from a PotionEffectType. - * - * @param type The type of the potion effect. - * @return The potion type. - */ - private PotionType getPotionType(PotionEffectType type) { - if (type != null) { - if (type.equals(PotionEffectType.FIRE_RESISTANCE)) { - return PotionType.FIRE_RESISTANCE; - } else if (type.equals(PotionEffectType.HARM)) { - return PotionType.INSTANT_DAMAGE; - } else if (type.equals(PotionEffectType.HEAL)) { - return PotionType.INSTANT_HEAL; - } else if (type.equals(PotionEffectType.INVISIBILITY)) { - return PotionType.INVISIBILITY; - } else if (type.equals(PotionEffectType.JUMP)) { - return PotionType.JUMP; - } else if (type.equals(PotionEffectType.getByName("LUCK"))) { - return PotionType.valueOf("LUCK"); - } else if (type.equals(PotionEffectType.NIGHT_VISION)) { - return PotionType.NIGHT_VISION; - } else if (type.equals(PotionEffectType.POISON)) { - return PotionType.POISON; - } else if (type.equals(PotionEffectType.REGENERATION)) { - return PotionType.REGEN; - } else if (type.equals(PotionEffectType.SLOW)) { - return PotionType.SLOWNESS; - } else if (type.equals(PotionEffectType.SPEED)) { - return PotionType.SPEED; - } else if (type.equals(PotionEffectType.INCREASE_DAMAGE)) { - return PotionType.STRENGTH; - } else if (type.equals(PotionEffectType.WATER_BREATHING)) { - return PotionType.WATER_BREATHING; - } else if (type.equals(PotionEffectType.WEAKNESS)) { - return PotionType.WEAKNESS; - } - } - - return null; - } - - /** - * Get the Color from a string. - * - * @param color The string of the color. - * @return The color from the string. - */ - private static Color getColor(String color) { - if (color != null) { - switch (color.toUpperCase()) { - case "AQUA": - return Color.AQUA; - case "BLACK": - return Color.BLACK; - case "BLUE": - return Color.BLUE; - case "FUCHSIA": - return Color.FUCHSIA; - case "GRAY": - return Color.GRAY; - case "GREEN": - return Color.GREEN; - case "LIME": - return Color.LIME; - case "MAROON": - return Color.MAROON; - case "NAVY": - return Color.NAVY; - case "OLIVE": - return Color.OLIVE; - case "ORANGE": - return Color.ORANGE; - case "PURPLE": - return Color.PURPLE; - case "RED": - return Color.RED; - case "SILVER": - return Color.SILVER; - case "TEAL": - return Color.TEAL; - case "WHITE": - return Color.WHITE; - case "YELLOW": - return Color.YELLOW; - } - - try { - String[] rgb = color.split(","); - return Color.fromRGB(Integer.parseInt(rgb[0]), Integer.parseInt(rgb[1]), Integer.parseInt(rgb[2])); - } catch (Exception ignore) {} - } - - return null; - } - - /** - * Get the dye color from a string. - * - * @param color The string of the color. - * @return The dye color from the string. - */ - public static DyeColor getDyeColor(String color) { - if (color != null) { - try { - return DyeColor.valueOf(color.toUpperCase()); - } catch (Exception e) { - try { - String[] rgb = color.split(","); - return DyeColor.getByColor(Color.fromRGB(Integer.parseInt(rgb[0]), Integer.parseInt(rgb[1]), Integer.parseInt(rgb[2]))); - } catch (Exception ignore) {} - } - } - - return null; - } - - /** - * Get the enchantment from a string. - * - * @param enchantmentName The string of the enchantment. - * @return The enchantment from the string. - */ - private static Enchantment getEnchantment(String enchantmentName) { - enchantmentName = stripEnchantmentName(enchantmentName); - for (Enchantment enchantment : Enchantment.values()) { - try { - if (stripEnchantmentName(enchantment.getKey().getKey()).equalsIgnoreCase(enchantmentName)) return enchantment; - - HashMap enchantments = getEnchantmentList(); - - if (stripEnchantmentName(enchantment.getName()).equalsIgnoreCase(enchantmentName) || (enchantments.get(enchantment.getName()) != null && - stripEnchantmentName(enchantments.get(enchantment.getName())).equalsIgnoreCase(enchantmentName))) return enchantment; - } catch (Exception ignore) {} - } - - return null; - } - - /** - * Strip extra characters from an enchantment name. - * - * @param enchantmentName The enchantment name. - * @return The stripped enchantment name. - */ - private static String stripEnchantmentName(String enchantmentName) { - return enchantmentName != null ? enchantmentName.replace("-", "").replace("_", "").replace(" ", "") : null; - } - - /** - * Get the list of enchantments and their in-Game names. - * - * @return The list of enchantments and their in-Game names. - */ - private static HashMap getEnchantmentList() { - HashMap enchantments = new HashMap<>(); - - enchantments.put("ARROW_DAMAGE", "Power"); - enchantments.put("ARROW_FIRE", "Flame"); - enchantments.put("ARROW_INFINITE", "Infinity"); - enchantments.put("ARROW_KNOCKBACK", "Punch"); - enchantments.put("DAMAGE_ALL", "Sharpness"); - enchantments.put("DAMAGE_ARTHROPODS", "Bane_Of_Arthropods"); - enchantments.put("DAMAGE_UNDEAD", "Smite"); - enchantments.put("DEPTH_STRIDER", "Depth_Strider"); - enchantments.put("DIG_SPEED", "Efficiency"); - enchantments.put("DURABILITY", "Unbreaking"); - enchantments.put("FIRE_ASPECT", "Fire_Aspect"); - enchantments.put("KNOCKBACK", "KnockBack"); - enchantments.put("LOOT_BONUS_BLOCKS", "Fortune"); - enchantments.put("LOOT_BONUS_MOBS", "Looting"); - enchantments.put("LUCK", "Luck_Of_The_Sea"); - enchantments.put("LURE", "Lure"); - enchantments.put("OXYGEN", "Respiration"); - enchantments.put("PROTECTION_ENVIRONMENTAL", "Protection"); - enchantments.put("PROTECTION_EXPLOSIONS", "Blast_Protection"); - enchantments.put("PROTECTION_FALL", "Feather_Falling"); - enchantments.put("PROTECTION_FIRE", "Fire_Protection"); - enchantments.put("PROTECTION_PROJECTILE", "Projectile_Protection"); - enchantments.put("SILK_TOUCH", "Silk_Touch"); - enchantments.put("THORNS", "Thorns"); - enchantments.put("WATER_WORKER", "Aqua_Affinity"); - enchantments.put("BINDING_CURSE", "Curse_Of_Binding"); - enchantments.put("MENDING", "Mending"); - enchantments.put("FROST_WALKER", "Frost_Walker"); - enchantments.put("VANISHING_CURSE", "Curse_Of_Vanishing"); - enchantments.put("SWEEPING_EDGE", "Sweeping_Edge"); - enchantments.put("RIPTIDE", "Riptide"); - enchantments.put("CHANNELING", "Channeling"); - enchantments.put("IMPALING", "Impaling"); - enchantments.put("LOYALTY", "Loyalty"); - - return enchantments; - } - - private boolean isInt(String s) { - try { - Integer.parseInt(s); - } catch (NumberFormatException nfe) { - return false; - } - - return true; - } - - private ItemFlag getFlag(String flagString) { - for (ItemFlag flag : ItemFlag.values()) { - if (flag.name().equalsIgnoreCase(flagString)) return flag; - } - - return null; - } -} \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazyauctions/utils/SkullCreator.java b/src/main/java/com/badbones69/crazyauctions/utils/SkullCreator.java deleted file mode 100644 index 736e772..0000000 --- a/src/main/java/com/badbones69/crazyauctions/utils/SkullCreator.java +++ /dev/null @@ -1,275 +0,0 @@ -package com.badbones69.crazyauctions.utils; - -import com.badbones69.crazyauctions.CrazyAuctions; -import org.bukkit.Bukkit; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.block.Skull; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.SkullMeta; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.Base64; -import java.util.UUID; - -/** - * A library for the Bukkit API to create player skulls - * from names, base64 strings, and texture URLs. - * Does not use any NMS code, and should work across all versions. - * - * @author Dean B on 12/28/2016. - */ -public class SkullCreator { - - private final CrazyAuctions plugin = CrazyAuctions.getPlugin(); - - /** - * Creates a player skull based on a player's name. - * - * @param name The Player's name - * @return The head of the Player - * - * @deprecated names don't make for good identifiers - */ - @Deprecated - public ItemStack itemFromName(String name) { - ItemStack item = getPlayerSkullItem(); - - return itemWithName(item, name); - } - - /** - * Creates a player skull based on a player's name. - * - * @param item The item to apply the name to - * @param name The Player's name - * @return The head of the Player - * - * @deprecated names don't make for good identifiers - */ - @Deprecated - public ItemStack itemWithName(ItemStack item, String name) { - notNull(item, "item"); - notNull(name, "name"); - - return plugin.getServer().getUnsafe().modifyItemStack(item, "{SkullOwner:\"" + name + "\"}"); - } - - /** - * Creates a player skull with a UUID. 1.13 only. - * - * @param id The Player's UUID - * @return The head of the Player - */ - public ItemStack itemFromUuid(UUID id) { - ItemStack item = getPlayerSkullItem(); - - return itemWithUuid(item, id); - } - - /** - * Creates a player skull based on a UUID. 1.13 only. - * - * @param item The item to apply the name to - * @param id The Player's UUID - * @return The head of the Player - */ - public ItemStack itemWithUuid(ItemStack item, UUID id) { - notNull(item, "item"); - notNull(id, "id"); - - SkullMeta meta = (SkullMeta) item.getItemMeta(); - meta.setOwningPlayer(plugin.getServer().getOfflinePlayer(id)); - item.setItemMeta(meta); - - return item; - } - - /** - * Creates a player skull based on a Mojang server URL. - * - * @param url The URL of the Mojang skin - * @return The head associated with the URL - */ - public ItemStack itemFromUrl(String url) { - ItemStack item = getPlayerSkullItem(); - - return itemWithUrl(item, url); - } - - /** - * Creates a player skull based on a Mojang server URL. - * - * @param item The item to apply the skin to - * @param url The URL of the Mojang skin - * @return The head associated with the URL - */ - public ItemStack itemWithUrl(ItemStack item, String url) { - notNull(item, "item"); - notNull(url, "url"); - - return itemWithBase64(item, urlToBase64(url)); - } - - /** - * Creates a player skull based on a base64 string containing the link to the skin. - * - * @param base64 The base64 string containing the texture - * @return The head with a custom texture - */ - public ItemStack itemFromBase64(String base64) { - ItemStack item = getPlayerSkullItem(); - - return itemWithBase64(item, base64); - } - - /** - * Applies the base64 string to the ItemStack. - * - * @param item The ItemStack to put the base64 onto - * @param base64 The base64 string containing the texture - * @return The head with a custom texture - */ - public ItemStack itemWithBase64(ItemStack item, String base64) { - notNull(item, "item"); - notNull(base64, "base64"); - - UUID hashAsId = new UUID(base64.hashCode(), base64.hashCode()); - return plugin.getServer().getUnsafe().modifyItemStack(item, - "{SkullOwner:{Id:\"" + hashAsId + "\",Properties:{textures:[{Value:\"" + base64 + "\"}]}}}" - ); - } - - /** - * Sets the block to a skull with the given name. - * - * @param block The block to set - * @param name The player to set it to - * - * @deprecated names don't make for good identifiers - */ - @Deprecated - public void blockWithName(Block block, String name) { - notNull(block, "block"); - notNull(name, "name"); - - setBlockType(block); - ((Skull) block.getState()).setOwningPlayer(Bukkit.getOfflinePlayer(name)); - } - - /** - * Sets the block to a skull with the given UUID. - * - * @param block The block to set - * @param id The player to set it to - */ - public void blockWithUuid(Block block, UUID id) { - notNull(block, "block"); - notNull(id, "id"); - - setBlockType(block); - ((Skull) block.getState()).setOwningPlayer(Bukkit.getOfflinePlayer(id)); - } - - /** - * Sets the block to a skull with the given UUID. - * - * @param block The block to set - * @param url The mojang URL to set it to use - */ - public void blockWithUrl(Block block, String url) { - notNull(block, "block"); - notNull(url, "url"); - - blockWithBase64(block, urlToBase64(url)); - } - - /** - * Sets the block to a skull with the given UUID. - * - * @param block The block to set - * @param base64 The base64 to set it to use - */ - public void blockWithBase64(Block block, String base64) { - notNull(block, "block"); - notNull(base64, "base64"); - - UUID hashAsId = new UUID(base64.hashCode(), base64.hashCode()); - - String args = String.format( - "%d %d %d %s", - block.getX(), - block.getY(), - block.getZ(), - "{Owner:{Id:\"" + hashAsId + "\",Properties:{textures:[{Value:\"" + base64 + "\"}]}}}" - ); - - if (newerApi()) { - plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), "data merge block " + args); - } else { - plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), "blockdata " + args); - } - } - - private boolean newerApi() { - try { - Material.valueOf("PLAYER_HEAD"); - return true; - } catch (IllegalArgumentException e) { - return false; - } - } - - private ItemStack getPlayerSkullItem() { - if (newerApi()) { - return new ItemStack(Material.valueOf("PLAYER_HEAD")); - } else { - return new ItemStack(Material.valueOf("SKULL_ITEM"), 1, (byte) 3); - } - } - - private void setBlockType(Block block) { - try { - block.setType(Material.valueOf("PLAYER_HEAD"), false); - } catch (IllegalArgumentException e) { - block.setType(Material.valueOf("SKULL"), false); - } - } - - private void notNull(Object o, String name) { - if (o == null) { - throw new NullPointerException(name + " should not be null!"); - } - } - - private String urlToBase64(String url) { - - URI actualUrl; - - try { - actualUrl = new URI(url); - } catch (URISyntaxException e) { - throw new RuntimeException(e); - } - - String toEncode = "{\"textures\":{\"SKIN\":{\"url\":\"" + actualUrl + "\"}}}"; - return Base64.getEncoder().encodeToString(toEncode.getBytes()); - } -} - -/* Format for skull -{ - display:{ - Name:"Cheese" - }, - SkullOwner:{ - Id:"9c919b83-f3fe-456f-a824-7d1d08cc8bd2", - Properties:{ - textures:[ - { - Value:"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvOTU1ZDYxMWE4NzhlODIxMjMxNzQ5YjI5NjU3MDhjYWQ5NDI2NTA2NzJkYjA5ZTI2ODQ3YTg4ZTJmYWMyOTQ2In19fQ==" - } - ] - } - } -}*/ \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazyauctions/utils/func/PluginSupport.java b/src/main/java/com/badbones69/crazyauctions/utils/func/PluginSupport.java deleted file mode 100644 index ad345dd..0000000 --- a/src/main/java/com/badbones69/crazyauctions/utils/func/PluginSupport.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.badbones69.crazyauctions.utils.func; - -import com.badbones69.crazyauctions.CrazyAuctions; - -public enum PluginSupport { - - PLACEHOLDERAPI("PlaceholderAPI"), - HOLOGRAPHIC_DISPLAYS("HolographicDisplays"), - DECENT_HOLOGRAMS("DecentHolograms"), - VAULT("Vault"); - - private final String name; - - private final CrazyAuctions plugin = CrazyAuctions.getPlugin(); - - PluginSupport(String name) { - this.name = name; - } - - public String getName() { - return name; - } - - public boolean isPluginLoaded() { - return plugin.getServer().getPluginManager().getPlugin(name) != null; - } -} \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazyauctions/utils/func/ServerProtocol.java b/src/main/java/com/badbones69/crazyauctions/utils/func/ServerProtocol.java deleted file mode 100644 index c0277a0..0000000 --- a/src/main/java/com/badbones69/crazyauctions/utils/func/ServerProtocol.java +++ /dev/null @@ -1,120 +0,0 @@ -package com.badbones69.crazyauctions.utils.func; - -import com.badbones69.crazyauctions.CrazyAuctions; - -/** - * @author Badbones69 - */ -public enum ServerProtocol { - - TOO_OLD(-1), - v1_7_R1(171), v1_7_R2(172), v1_7_R3(173), v1_7_R4(174), - v1_8_R1(181), v1_8_R2(182), v1_8_R3(183), - v1_9_R1(191), v1_9_R2(192), - v1_10_R1(1101), - v1_11_R1(1111), - v1_12_R1(1121), - v1_13_R2(1132), - v1_14_R1(1141), - v1_15_R1(1151), - v1_16_R1(1161), v1_16_R2(1162), v1_16_R3(1163), - v1_17_R1(1171), - v1_18_R1(1181), - v1_18_R2(1182), - v1_19(1191), - TOO_NEW(-2); - - private static ServerProtocol currentProtocol; - private static ServerProtocol latest; - - private final int versionProtocol; - - private static final CrazyAuctions plugin = CrazyAuctions.getPlugin(); - - ServerProtocol(int versionProtocol) { - this.versionProtocol = versionProtocol; - } - - public static ServerProtocol getCurrentProtocol() { - - String serVer = plugin.getServer().getClass().getPackage().getName(); - - int serProt = Integer.parseInt( - serVer.substring( - serVer.lastIndexOf('.') + 1 - ).replace("_", "").replace("R", "").replace("v", "") - ); - - for (ServerProtocol protocol : values()) { - if (protocol.versionProtocol == serProt) { - currentProtocol = protocol; - break; - } - } - - if (currentProtocol == null) currentProtocol = ServerProtocol.TOO_NEW; - - return currentProtocol; - } - - public static boolean isLegacy() { - return isOlder(ServerProtocol.v1_18_R1); - } - - public static ServerProtocol getLatestProtocol() { - - if (latest != null) return latest; - - ServerProtocol old = ServerProtocol.TOO_OLD; - - for (ServerProtocol protocol : values()) { - if (protocol.compare(old) == 1) { - old = protocol; - } - } - - return old; - } - - public static boolean isAtLeast(ServerProtocol protocol) { - if (currentProtocol == null) getCurrentProtocol(); - - int proto = currentProtocol.versionProtocol; - - return proto >= protocol.versionProtocol || proto == -2; - } - - public static boolean isNewer(ServerProtocol protocol) { - if (currentProtocol == null) getCurrentProtocol(); - - return currentProtocol.versionProtocol > protocol.versionProtocol || currentProtocol.versionProtocol == -2; - } - - public static boolean isSame(ServerProtocol protocol) { - if (currentProtocol == null) getCurrentProtocol(); - - return currentProtocol.versionProtocol == protocol.versionProtocol; - } - - public static boolean isOlder(ServerProtocol protocol) { - if (currentProtocol == null) getCurrentProtocol(); - - int proto = currentProtocol.versionProtocol; - - return proto < protocol.versionProtocol || proto == -1; - } - - public int compare(ServerProtocol protocol) { - int result = -1; - int current = versionProtocol; - int check = protocol.versionProtocol; - - if (current > check || check == -2) { - result = 1; - } else if (current == check) { - result = 0; - } - - return result; - } -} \ No newline at end of file diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml deleted file mode 100644 index ebaf756..0000000 --- a/src/main/resources/config.yml +++ /dev/null @@ -1,303 +0,0 @@ -Settings: - Prefix: '&7[&4Crazy &bAuctions&7]: ' #Prefix of when you get Crazy Auctions Messages. - GUIName: '&4Crazy &bAuctions&8' #Name of the Main GUI. - Players-Current-Items: '&8Your Current Listings' #The Name of the Player Current Items GUI. - Cancelled/Expired-Items: '&8Canceled/Expired Listings' #Name of the Cancelled/Expired GUI. - Buying-Item: '&8Purchase Item: Are You Sure?' #Name of the Buying GUI. - Bidding-On-Item: '&8You Are Bidding On This Item.' #Name of the Bidding GUI. - Categories: '&8Categories' #Name of the Category GUI. - Sell-Time: 2d #The time that each item will sell for. - Bid-Time: 2m 30s #Time for each item that is biddable. - Full-Expire-Time: 10d #The full time the item is in the crazy auctions. - Bid-Winner-Time: 20d #The time the winner of a bid has to claim their prize. - Minimum-Sell-Price: 10 #Minimum amount you can sell an item for. - Max-Beginning-Sell-Price: 1000000 #Max amount you can sell an item for. - Minimum-Bid-Price: 100 #Minimum starting bid. - 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. - #Sounds are found here: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Sound.html - GUISettings: #Settings for things in the gui. - SellingItemLore: #The lore on items that are being sold. - - '&7-------------------------' - - '&aClick here to purchase.' - - '' - - '&9Price: &e$%price%' - - '&9Seller: &e%seller%' - - '&7-------------------------' - CurrentLore: #Lore on items that are in your current items GUI. - - '&7-------------------------' - - '&aClick here to cancel.' - - '' - - '&9Price: &e$%price%' - - '&9Expire: &e%time%' - - '&7-------------------------' - Cancelled/ExpiredLore: #Lore on items that are in your canceled/expired GUI. - - '&7-------------------------' - - '&aClick here to return to you.' - - '' - - '&9Full Expire: &e%time%' - - '&7-------------------------' - Bidding: #Lore on Bidding Items. - - '&7-------------------------' - - '&aClick here to bid.' - - '' - - '&9Seller: &e%seller%' - - '&9Current Bid: &e$%topbid%' - - '&9Top Bidder: &e%topbidder%' - - '&9Time Left: &e%time%' - - '&7-------------------------' - Category-Settings: - Armor: - Item: 'GOLDEN_CHESTPLATE' - Toggle: true - Slot: 11 - Name: '&6&lArmor' - Lore: - - '&7This category contains all' - - '&7armor that is currently being sold.' - Weapons: - Item: 'GOLDEN_SWORD' - Toggle: true - Slot: 12 - Name: '&6&lWeapons' - Lore: - - '&7This category contains all' - - '&7weapons that are currently being sold.' - Tools: - Item: 'GOLDEN_PICKAXE' - Toggle: true - Slot: 13 - Name: '&6&lTools' - Lore: - - '&7This category contains all' - - '&7tools that are currently being sold.' - Food: - Item: 'GOLDEN_APPLE' - Toggle: true - Slot: 14 - Name: '&6&lFood' - Lore: - - '&7This category contains all' - - '&7food that is currently being sold.' - Potions: - Item: 'POTION' - Toggle: true - Slot: 15 - Name: '&6&lPotions' - Lore: - - '&7This category contains all' - - '&7potions that are currently being sold.' - Blocks: - Item: 'GRASS_BLOCK' - Toggle: true - Slot: 16 - Name: '&6&lBlocks' - Lore: - - '&7This category contains all' - - '&7blocks that are currently being sold.' - Other: - Item: 'GOLD_NUGGET' - Toggle: true - Slot: 17 - Name: '&6&lOthers' - Lore: - - '&7This category contains all the' - - '&7other items currently being sold.' - None: - Item: 'BARRIER' - Toggle: true - Slot: 23 - Name: '&6&lNone' - Lore: - - '&7This category contains all' - - '&7items currently being sold.' - OtherSettings: #Other Settings for the GUIs. - SellingItems: #The button for your current items. - Item: 'DIAMOND' #The item that this button is. - Toggle: true #If the item is in the gui or not. - Slot: 46 #The slot it is in. I recommend not changing these. If you do make sure they are still in the bottom row. - Name: '&6Items You are Selling' #Name of the item. - Lore: #Lore of the item. - - '&aClick here to view all the items you' - - '&aare currently selling on the auction.' - Cancelled/ExpiredItems: #The button for Cancelled/Expired Items. - Item: 'POISONOUS_POTATO' - Toggle: true - Slot: 47 - Name: '&6Collect Expired / Canceled Items' - Lore: - - '&aClick here to view and collect all of the' - - '&aitems you have canceled or has expired.' - PreviousPage: #The button for Previous Page. - Item: 'PAPER' - Toggle: true - Slot: 49 - Name: '&6Previous Page' - Lore: { } - Refesh: #The button for Refresh Page. - Item: 'SUNFLOWER' - Toggle: true - Slot: 50 - Name: '&6Refresh Page' - Lore: { } - NextPage: #The button for Next Page. - Item: 'PAPER' - Toggle: true - Slot: 51 - Name: '&6Next Page' - Lore: { } - Category1: #The button for Next Page. - Item: 'CHEST' - Toggle: true - Slot: 52 - Name: '&6Categories' - Lore: - - '&bCurrent Category: &6%category%' - - '&aWant to see items in specific categories?' - - '&aClick here to see all categories of items.' - Category2: #The button for Next Page. - Item: 'CHEST' - Toggle: true - Slot: 48 - Name: '&6Categories' - Lore: - - '&bCurrent Category: &6%category%' - - '&aWant to see items in specific categories?' - - '&aClick here to see all categories of items.' - Bidding/Selling: #Switch between Bidding and Selling. - Selling: - Item: 'SLIME_BALL' - Toggle: true - Slot: 53 - Name: '&6Currently looking at items being sold.' - Lore: - - '&7&l(&6&l!&7&l) &7Click here to see items' - - '&7that you can bid on.' - Bidding: - Item: 'MAGMA_CREAM' - Toggle: true - Slot: 53 - Name: '&6Currently looking at items that can be bid on.' - Lore: - - '&7&l(&6&l!&7&l) &7Click here to see items' - - '&7that you can buy at a price.' - WhatIsThis: #The info on all the Books buttons. - SellingShop: #The Book in the main shop. - Item: 'BOOK' - Toggle: true - Slot: 54 - Name: '&6What Is This Page?' - Lore: - - '&aThis is the crazy auctions, here you can' - - '&aput items for sale, and buy items' - - '&athat others have put for sale.' - - '' - - '&aThe auction is also a great place to make' - - '&amoney by selling items that others' - - '&amay be interested in buying.' - BiddingShop: #The Book in the main shop. - Item: 'BOOK' - Toggle: true - Slot: 54 - Name: '&6What Is This Page?' - Lore: - - '&aThis is the crazy auctions, here you can' - - '&aput items for sale, and bid on items' - - '&athat others have put for sale.' - - '' - - '&aThe bidding auction is also a great place to' - - '&amake money by bidding off items that others' - - '&amay be interested in bidding on.' - CurrentItems: #The Book in the Current items GUI. - Item: 'BOOK' - Toggle: true - Slot: 54 - Name: '&6What Is This Page?' - Lore: - - '&aThese are your current listings, all of' - - '&athe items you currently have listed on' - - '&acrazy auctions are displayed here.' - - '' - - '&aYou can cancel and view your listings' - - '&aexpire time here.' - Cancelled/ExpiredItems: #The Book in the Canceled/Expired Items GUI. - Item: 'BOOK' - Toggle: true - Slot: 54 - Name: '&6What Is This Page?' - Lore: - - '&aThis page houses all of your cancelled and' - - '&aexpired items, when a listings is cancelled' - - '&aor expires you will be able to return that' - - '&aitem back to you from this menu.' - - '' - - '&aJust click on the item and if you have enough' - - '&ainventory space you will receive that item.' - Viewing: #The Book in the Viewing Items GUI. - Item: 'BOOK' - Toggle: true - Slot: 50 - Name: '&6What Is This Page?' - Lore: - - '&aThis page shows all the items that' - - '&aa player has currently on the bidding' - - '&aand selling market. You can quickly see' - - '&awhat a specific player is selling.' - Categories: #The Book in the Viewing Items GUI. - Item: 'BOOK' - Toggle: true - Slot: 54 - Name: '&6What Is This Page?' - Lore: - - '&aThis page shows all the categories' - - '&athat you can choose from. When you click' - - '&aa category it will open the gui with only' - - '&aitems that belong to that category.' - Back: #The Back Buttons. - Item: 'PAPER' - Slot: 46 - Name: '&6Back' - Return: #The Return Buttons. - Item: 'FLOWER_POT' - Slot: 50 - Name: '&6Return All' - Lore: - - '&aClick here to return all cancelled' - - '&aand expired items to your inventory.' - Confirm: #The Confirm Buttons. - Item: 'LIME_STAINED_GLASS_PANE' - Name: '&aConfirm' - Cancel: #The Cancel Buttons. - Item: 'RED_STAINED_GLASS_PANE' - Name: '&cCancel' - Your-Item: #The item that shows when you try to buy/bid on your item. - Item: 'BARRIER' - Name: '&cYou Can''t Purchase Your Own Item.' - Cant-Afford: #The item that shows when you can't afford this item. - Item: 'BARRIER' - Name: '&cYou Can''t Afford This Item.' - Top-Bidder: #The item for when a player is already the top bidder. - Item: 'BARRIER' - Name: '&cYou are already the top bidder.' - Bidding: #The item in the middle when bidding on an item. - Item: 'BLACK_STAINED_GLASS_PANE' - Name: '&7Bidding' - Lore: - - '&7<--&aAdd &cRemove&7-->' - - '&9Your Current Bid: &e$%Bid%' - - '&9Current Top Bid: &e$%topbid%' - Bid: #The button for when you want to confirm your bid. - Item: 'LIGHT_BLUE_STAINED_GLASS_PANE' - Name: '&bBid Now' - Lore: - - '&7Click here to Bid Now.' - BlackList: - - 'BEDROCK' - - 'END_PORTAL_FRAME' \ No newline at end of file diff --git a/src/main/resources/data.yml b/src/main/resources/data.yml deleted file mode 100644 index d495e91..0000000 --- a/src/main/resources/data.yml +++ /dev/null @@ -1,2 +0,0 @@ -Items: {} -OutOfTime/Cancelled: {} \ No newline at end of file diff --git a/src/main/resources/messages.yml b/src/main/resources/messages.yml deleted file mode 100644 index 7f58e74..0000000 --- a/src/main/resources/messages.yml +++ /dev/null @@ -1,45 +0,0 @@ -Messages: - Players-Only: '&cOnly players can use this command.' - Reload: '&7You have just reloaded the Crazy Auctions Files.' - Need-More-Money: '&cYou are in need of &a$%money_needed%&c.' - Inventory-Full: '&cYour inventory is too full. Please open up some space to buy that.' - No-Permission: '&cYou do not have permission to use that command!' - Not-Online: '&cThat player is not online.' - 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 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 expired.' - Admin-Force-Cancelled: '&7You have force canceled a sale.' - Admin-Force-Cancelled-To-Player: '&cOne of your items was 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 too 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 too low the minimum is &a$10&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 too low the minimum is &a$100&c.' - 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 with a bid of &a$%price%.' - 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]' - Book-Not-Allowed: '&cThat book is not able to be sold in this auction house!' - Help-Menu: - - '&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 canceled and expired items.' - - '&9/Ah Listed - &eView and manage the items you are selling.' - - '&9/Ah Help - &eView this help menu.' \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 3150de6..39087c0 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -4,7 +4,7 @@ main: "${group}.CrazyAuctions" authors: [BadBones69, RyderBelserion] version: ${version} -api-version: "1.13" +api-version: "1.19" description: ${description} softdepend: [Vault] diff --git a/src/main/resources/test-file.yml b/src/main/resources/test-file.yml deleted file mode 100644 index 5f1a472..0000000 --- a/src/main/resources/test-file.yml +++ /dev/null @@ -1,2 +0,0 @@ -#!!DO NOT DELETE!! -#Used for unicode checking in books. \ No newline at end of file