diff --git a/config.yml b/config.yml index ecef4c7..e95a910 100644 --- a/config.yml +++ b/config.yml @@ -15,6 +15,7 @@ Settings: 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. GUISettings: #Settings for things in the gui. SellingItemLore: #The lore on items that are being sold. - '&7-------------------------' diff --git a/plugin.yml b/plugin.yml index 6012eda..5fbfad1 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,12 +1,12 @@ name: CrazyAuctions author: BadBones69 -main: me.BadBones69.CrazyAuctions.Main +main: me.badbones69.crazyauctions.Main website: https://www.spigotmc.org/resources/authors/kicjow.9719/ -version: 1.0 +version: 1.0.1 depend: [Vault] description: > A plugin to auction off items globally. commands: - CA: + ca: description: Opens the Crazy Auctions GUI. aliases: [crazyauction, crazyauctions, ah] \ No newline at end of file diff --git a/src/me/BadBones69/CrazyAuctions/Api.java b/src/me/BadBones69/CrazyAuctions/Api.java index cd6cc5d..0b8c691 100644 --- a/src/me/BadBones69/CrazyAuctions/Api.java +++ b/src/me/BadBones69/CrazyAuctions/Api.java @@ -1,5 +1,9 @@ -package me.BadBones69.CrazyAuctions; +package me.badbones69.crazyauctions; +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; import java.text.NumberFormat; import java.util.ArrayList; import java.util.Calendar; @@ -17,10 +21,16 @@ import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.plugin.Plugin; -import me.BadBones69.CrazyAuctions.Currency.CM; +import me.badbones69.crazyauctions.currency.CM; public class Api { + public static Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("CrazyAuctions"); + @SuppressWarnings("static-access") + public Api(Plugin plugin){ + this.plugin = plugin; + } public static String color(String msg){ msg = ChatColor.translateAlternateColorCodes('&', msg); return msg; @@ -215,6 +225,38 @@ public class Api { return true; } } + public static void hasUpdate(){ + try { + HttpURLConnection c = (HttpURLConnection)new URL("http://www.spigotmc.org/api/general.php").openConnection(); + c.setDoOutput(true); + c.setRequestMethod("POST"); + c.getOutputStream().write(("key=98BE0FE67F88AB82B4C197FAF1DC3B69206EFDCC4D3B80FC83A00037510B99B4&resource=25219").getBytes("UTF-8")); + String oldVersion = plugin.getDescription().getVersion(); + String newVersion = new BufferedReader(new InputStreamReader(c.getInputStream())).readLine().replaceAll("[a-zA-Z ]", ""); + if(!newVersion.equals(oldVersion)) { + Bukkit.getConsoleSender().sendMessage(getPrefix()+color("&cYour server is running &7v"+oldVersion+"&c and the newest is &7v"+newVersion+"&c.")); + } + } + catch(Exception e) { + return; + } + } + public static void hasUpdate(Player player){ + try { + HttpURLConnection c = (HttpURLConnection)new URL("http://www.spigotmc.org/api/general.php").openConnection(); + c.setDoOutput(true); + c.setRequestMethod("POST"); + c.getOutputStream().write(("key=98BE0FE67F88AB82B4C197FAF1DC3B69206EFDCC4D3B80FC83A00037510B99B4&resource=25219").getBytes("UTF-8")); + String oldVersion = plugin.getDescription().getVersion(); + String newVersion = new BufferedReader(new InputStreamReader(c.getInputStream())).readLine().replaceAll("[a-zA-Z ]", ""); + if(!newVersion.equals(oldVersion)) { + player.sendMessage(getPrefix()+color("&cYour server is running &7v"+oldVersion+"&c and the newest is &7v"+newVersion+"&c.")); + } + } + catch(Exception e) { + return; + } + } public static List getPage(List list, Integer page){ List items = new ArrayList(); if(page<=0)page=1; diff --git a/src/me/BadBones69/CrazyAuctions/Category.java b/src/me/BadBones69/CrazyAuctions/Category.java index 502a574..e3e8043 100644 --- a/src/me/BadBones69/CrazyAuctions/Category.java +++ b/src/me/BadBones69/CrazyAuctions/Category.java @@ -1,4 +1,4 @@ -package me.BadBones69.CrazyAuctions; +package me.badbones69.crazyauctions; import java.util.ArrayList; diff --git a/src/me/BadBones69/CrazyAuctions/CrazyAuctions.java b/src/me/BadBones69/CrazyAuctions/CrazyAuctions.java index fa7c93a..1460362 100644 --- a/src/me/BadBones69/CrazyAuctions/CrazyAuctions.java +++ b/src/me/BadBones69/CrazyAuctions/CrazyAuctions.java @@ -1,4 +1,4 @@ -package me.BadBones69.CrazyAuctions; +package me.badbones69.crazyauctions; import java.util.ArrayList; diff --git a/src/me/BadBones69/CrazyAuctions/Currency/CM.java b/src/me/BadBones69/CrazyAuctions/Currency/CM.java index 124b018..bd6aef3 100644 --- a/src/me/BadBones69/CrazyAuctions/Currency/CM.java +++ b/src/me/BadBones69/CrazyAuctions/Currency/CM.java @@ -1,10 +1,10 @@ -package me.BadBones69.CrazyAuctions.Currency; +package me.badbones69.crazyauctions.currency; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; -import me.BadBones69.CrazyAuctions.Main; +import me.badbones69.crazyauctions.Main; public enum CM { // Currency Manager VAULT("Vault", "Money"); diff --git a/src/me/BadBones69/CrazyAuctions/Currency/Vault.java b/src/me/BadBones69/CrazyAuctions/Currency/Vault.java index 0860f13..5d1c07d 100644 --- a/src/me/BadBones69/CrazyAuctions/Currency/Vault.java +++ b/src/me/BadBones69/CrazyAuctions/Currency/Vault.java @@ -1,4 +1,4 @@ -package me.BadBones69.CrazyAuctions.Currency; +package me.badbones69.crazyauctions.currency; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; diff --git a/src/me/BadBones69/CrazyAuctions/GUI.java b/src/me/BadBones69/CrazyAuctions/GUI.java index 656dafa..da3e1a0 100644 --- a/src/me/BadBones69/CrazyAuctions/GUI.java +++ b/src/me/BadBones69/CrazyAuctions/GUI.java @@ -1,4 +1,4 @@ -package me.BadBones69.CrazyAuctions; +package me.badbones69.crazyauctions; import java.util.ArrayList; import java.util.HashMap; @@ -18,7 +18,7 @@ import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.Plugin; -import me.BadBones69.CrazyAuctions.Currency.CM; +import me.badbones69.crazyauctions.currency.CM; public class GUI implements Listener{ private static HashMap Bidding = new HashMap(); @@ -43,7 +43,11 @@ public class GUI implements Listener{ data.set("Items.Clear", null); Main.settings.saveData(); } - Cat.put(player, cat); + if(cat!=null){ + Cat.put(player, cat); + }else{ + Cat.put(player, Category.NONE); + } if(data.contains("Items")){ for(String i : data.getConfigurationSection("Items").getKeys(false)){ List lore = new ArrayList(); @@ -115,7 +119,7 @@ public class GUI implements Listener{ List.put(player, Id); player.openInventory(inv); } - public static void openCateories(Player player){ + public static void openCateories(Player player, Shop shop){ Api.updateAuction(); FileConfiguration config = Main.settings.getConfig(); Inventory inv = Bukkit.createInventory(null, 54, Api.color(config.getString("Settings.Categories"))); @@ -135,6 +139,7 @@ public class GUI implements Listener{ inv.setItem(slot-1, Api.makeItem(id, 1, name)); } } + Type.put(player, shop); player.openInventory(inv); } public static void openPlayersCurrentList(Player player, int page){ @@ -595,12 +600,12 @@ public class GUI implements Listener{ return; } if(item.getItemMeta().getDisplayName().equals(Api.color(config.getString("Settings.GUISettings.OtherSettings.Category1.Name")))){ - openCateories(player); + openCateories(player, Type.get(player)); playClick(player); return; } if(item.getItemMeta().getDisplayName().equals(Api.color(config.getString("Settings.GUISettings.OtherSettings.Category2.Name")))){ - openCateories(player); + openCateories(player, Type.get(player)); playClick(player); return; } diff --git a/src/me/BadBones69/CrazyAuctions/Main.java b/src/me/BadBones69/CrazyAuctions/Main.java index cdfdcb7..65f8492 100644 --- a/src/me/BadBones69/CrazyAuctions/Main.java +++ b/src/me/BadBones69/CrazyAuctions/Main.java @@ -1,4 +1,4 @@ -package me.BadBones69.CrazyAuctions; +package me.badbones69.crazyauctions; import java.io.IOException; import java.util.ArrayList; @@ -16,7 +16,7 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.permissions.PermissionAttachmentInfo; import org.bukkit.plugin.java.JavaPlugin; -import me.BadBones69.CrazyAuctions.Currency.Vault; +import me.badbones69.crazyauctions.currency.Vault; public class Main extends JavaPlugin implements Listener{ public static SettingsManager settings = SettingsManager.getInstance(); @@ -31,6 +31,7 @@ public class Main extends JavaPlugin implements Listener{ public void onEnable(){ saveDefaultConfig(); settings.setup(this); + Api.hasUpdate(); Bukkit.getServer().getPluginManager().registerEvents(this, this); Bukkit.getServer().getPluginManager().registerEvents(new GUI(this), this); Api.updateAuction(); @@ -39,7 +40,8 @@ public class Main extends JavaPlugin implements Listener{ saveDefaultConfig(); } if(Bukkit.getPluginManager().getPlugin("Vault")==null){ - Bukkit.getConsoleSender().sendMessage(Api.getPrefix()+Api.color("&cThis plugin is shutting down. This plugin requires a compatable currency plugin." + Bukkit.getConsoleSender().sendMessage(Api.getPrefix()+ + Api.color("&cThis plugin is shutting down. This plugin requires a compatable currency plugin." + " &cPlease add Vault to continue using this.")); Bukkit.getServer().getPluginManager().disablePlugin(this); } @@ -59,6 +61,12 @@ public class Main extends JavaPlugin implements Listener{ return true; } Player player = (Player) sender; + if(settings.getConfig().contains("Settings.Category-Page-Opens-First")){ + if(settings.getConfig().getBoolean("Settings.Category-Page-Opens-First")){ + GUI.openCateories(player, Shop.SELL); + return true; + } + } GUI.openShop(player, Shop.SELL, Category.NONE, 1); return true; } @@ -192,13 +200,17 @@ public class Main extends JavaPlugin implements Listener{ } } } - if(auc.getItems(player, Shop.SELL).size()>=SellLimit){ - player.sendMessage(Api.getPrefix()+Api.color(settings.getMsg().getString("Messages.Max-Items"))); - return true; + if(args[0].equalsIgnoreCase("Sell")){ + if(auc.getItems(player, Shop.SELL).size()>=SellLimit){ + player.sendMessage(Api.getPrefix()+Api.color(settings.getMsg().getString("Messages.Max-Items"))); + return true; + } } - if(auc.getItems(player, Shop.BID).size()>=BidLimit){ - player.sendMessage(Api.getPrefix()+Api.color(settings.getMsg().getString("Messages.Max-Items"))); - return true; + if(args[0].equalsIgnoreCase("Bid")){ + if(auc.getItems(player, Shop.BID).size()>=BidLimit){ + player.sendMessage(Api.getPrefix()+Api.color(settings.getMsg().getString("Messages.Max-Items"))); + return true; + } } for(String id : settings.getConfig().getStringList("Settings.BlackList")){ if(item.getType()==Api.makeItem(id, 1).getType()){ @@ -271,6 +283,9 @@ public class Main extends JavaPlugin implements Listener{ player.sendMessage(Api.getPrefix()+Api.color("&7This server is running your Crazy Auctions Plugin. " + "&7It is running version &av"+Bukkit.getServer().getPluginManager().getPlugin("CrazyAuctions").getDescription().getVersion()+"&7.")); } + if(player.isOp()){ + Api.hasUpdate(player); + } } }, 40); } diff --git a/src/me/BadBones69/CrazyAuctions/Metrics.java b/src/me/BadBones69/CrazyAuctions/Metrics.java index 5b83729..6faecf3 100644 --- a/src/me/BadBones69/CrazyAuctions/Metrics.java +++ b/src/me/BadBones69/CrazyAuctions/Metrics.java @@ -1,4 +1,4 @@ -package me.BadBones69.CrazyAuctions; +package me.badbones69.crazyauctions; import java.io.BufferedReader; import java.io.File; diff --git a/src/me/BadBones69/CrazyAuctions/SettingsManager.java b/src/me/BadBones69/CrazyAuctions/SettingsManager.java index 9e178e3..8550950 100644 --- a/src/me/BadBones69/CrazyAuctions/SettingsManager.java +++ b/src/me/BadBones69/CrazyAuctions/SettingsManager.java @@ -1,4 +1,4 @@ -package me.BadBones69.CrazyAuctions; +package me.badbones69.crazyauctions; import java.io.File; import java.io.FileOutputStream; diff --git a/src/me/BadBones69/CrazyAuctions/Shop.java b/src/me/BadBones69/CrazyAuctions/Shop.java index 5052712..50efba6 100644 --- a/src/me/BadBones69/CrazyAuctions/Shop.java +++ b/src/me/BadBones69/CrazyAuctions/Shop.java @@ -1,4 +1,4 @@ -package me.BadBones69.CrazyAuctions; +package me.badbones69.crazyauctions; public enum Shop{ SELL("Sell"), BID("Bid");