v1.2 Update

Hello, here is a small update that adds a couple requested things.

Changes:
  - Updated Metrics.

Added:
  - The help menu can now be changed in the Messages.yml.
  - Toggle: option to some of the items in the gui.
This commit is contained in:
BadBones69 2017-01-01 15:19:09 -05:00
parent 6f429b38f4
commit 3f2b71008c
12 changed files with 693 additions and 376 deletions

14
.classpath Normal file
View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="lib" path="/Users/Joe/Plugins/Spigot/Spigot 1.10.jar">
<attributes>
<attribute name="javadoc_location" value="jar:file:/Users/Joe/Desktop/Stuff/Spigot/Spigot%201.10%20JavaDoc.jar!/"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="/Users/Joe/Plugins/Spigot/Spigot 1.9.4.jar"/>
<classpathentry kind="lib" path="/Users/Joe/Plugins/Spigot/Spigot 1.8.8.jar"/>
<classpathentry kind="lib" path="/Users/Joe/Plugins/Vault.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

5
.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
*.prefs
*.class

17
.project Normal file
View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Crazy Auctions</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@ -28,4 +28,12 @@ Messages:
Player-Bought-Item: '&7%Player% has bought your item for &a$%Price%.'
Someone-Won-Players-Bid: '&7%Player% has won your item you from a bid for &a$%Price%.'
Added-Item-To-Auction: '&7You have just added a item to the crazy auctions for &a$%Price%&7.'
Bid-Msg: '&7You have just bid &a$%Bid% &7on that item.'
Bid-Msg: '&7You have just bid &a$%Bid% &7on that item.'
Help-Menu:
- '&e-- &6Crazy Auctions Help &e--'
- '&9/Ah - &eOpens the crazy auction.'
- '&9/Ah View <Player> - &eSee what a player is selling.'
- '&9/Ah Sell/Bid <Price> [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.'

10
Notes Normal file
View File

@ -0,0 +1,10 @@
Features:
(Request) Add it so you can sell more then just 64 of a stack.
(Request) Add a history purchase history.
(Bug) When you collect an item from the expired list with a fully inventory, the item gets lost.
Changes:
- Updated Metrics.
Added:
- The help menu can now be changed in the Messages.yml.

View File

@ -54,6 +54,7 @@ Settings:
Category-Settings:
Armor:
Item: '315'
Toggle: true
Slot: 11
Name: '&6&lArmor'
Lore:
@ -61,6 +62,7 @@ Settings:
- '&7armor that is currently being sold.'
Weapons:
Item: '283'
Toggle: true
Slot: 12
Name: '&6&lWeapons'
Lore:
@ -68,6 +70,7 @@ Settings:
- '&7weapons that is currently being sold.'
Tools:
Item: '285'
Toggle: true
Slot: 13
Name: '&6&lTools'
Lore:
@ -75,6 +78,7 @@ Settings:
- '&7tools that is currently being sold.'
Food:
Item: '322'
Toggle: true
Slot: 14
Name: '&6&lFood'
Lore:
@ -82,6 +86,7 @@ Settings:
- '&7food that is currently being sold.'
Potions:
Item: '373:8227'
Toggle: true
Slot: 15
Name: '&6&lPotions'
Lore:
@ -89,6 +94,7 @@ Settings:
- '&7potions that is currently being sold.'
Blocks:
Item: '2'
Toggle: true
Slot: 16
Name: '&6&lBlocks'
Lore:
@ -96,6 +102,7 @@ Settings:
- '&7blocks that is currently being sold.'
Other:
Item: '371'
Toggle: true
Slot: 17
Name: '&6&lOthers'
Lore:
@ -103,6 +110,7 @@ Settings:
- '&7other items currently being sold.'
None:
Item: '166'
Toggle: true
Slot: 23
Name: '&6&lNone'
Lore:
@ -111,6 +119,7 @@ Settings:
OtherSettings: #Other Settings for the GUIs.
SellingItems: #The button for your current items.
Item: '264' #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.
@ -118,6 +127,7 @@ Settings:
- '&aare currently selling on the auction.'
Cancelled/ExpiredItems: #The button for Cancelled/Expired Items.
Item: '394'
Toggle: true
Slot: 47
Name: '&6Collect Expired / Cancelled Items'
Lore:
@ -125,21 +135,25 @@ Settings:
- '&aitems you have cancelled or has expired.'
PreviousPage: #The button for Previous Page.
Item: '339'
Toggle: true
Slot: 49
Name: '&6Previous Page'
Lore: {}
Refesh: #The button for Refresh Page.
Item: '175'
Toggle: true
Slot: 50
Name: '&6Refresh Page'
Lore: {}
NextPage: #The button for Next Page.
Item: '339'
Toggle: true
Slot: 51
Name: '&6Next Page'
Lore: {}
Category1: #The button for Next Page.
Item: '54'
Toggle: true
Slot: 52
Name: '&6Categories'
Lore:
@ -148,6 +162,7 @@ Settings:
- '&aClick here to see all categories of items.'
Category2: #The button for Next Page.
Item: '54'
Toggle: true
Slot: 48
Name: '&6Categories'
Lore:
@ -157,6 +172,7 @@ Settings:
Bidding/Selling: #Switch between Bidding and Selling.
Selling:
Item: '341'
Toggle: true
Slot: 53
Name: '&6Currently looking at items being sold.'
Lore:
@ -164,6 +180,7 @@ Settings:
- '&7that you can be bidded on.'
Bidding:
Item: '378'
Toggle: true
Slot: 53
Name: '&6Currently looking at items that can be bid on.'
Lore:
@ -172,6 +189,7 @@ Settings:
WhatIsThis: #The info on all the Books buttons.
SellingShop: #The Book in the main shop.
Item: '340'
Toggle: true
Slot: 54
Name: '&6What Is This Page?'
Lore:
@ -184,6 +202,7 @@ Settings:
- '&amay be interested in buying.'
BiddingShop: #The Book in the main shop.
Item: '340'
Toggle: true
Slot: 54
Name: '&6What Is This Page?'
Lore:
@ -196,6 +215,7 @@ Settings:
- '&amay be interested in bidding on.'
CurrentItems: #The Book in the Current items GUI.
Item: '340'
Toggle: true
Slot: 54
Name: '&6What Is This Page?'
Lore:
@ -207,6 +227,7 @@ Settings:
- '&aexpire time here.'
Cancelled/ExpiredItems: #The Book in the Cancelled/Expired Items GUI.
Item: '340'
Toggle: true
Slot: 54
Name: '&6What Is This Page?'
Lore:
@ -219,6 +240,7 @@ Settings:
- '&ainventory space you will receive that item.'
Viewing: #The Book in the Viewing Items GUI.
Item: '340'
Toggle: true
Slot: 50
Name: '&6What Is This Page?'
Lore:
@ -228,6 +250,7 @@ Settings:
- '&awhat a specific player is selling.'
Categories: #The Book in the Viewing Items GUI.
Item: '340'
Toggle: true
Slot: 54
Name: '&6What Is This Page?'
Lore:

View File

@ -2,7 +2,7 @@ name: CrazyAuctions
author: BadBones69
main: me.badbones69.crazyauctions.Main
website: https://www.spigotmc.org/resources/authors/kicjow.9719/
version: 1.1.4
version: 1.2
depend: [Vault]
description: >
A plugin to auction off items globally.

View File

@ -10,8 +10,9 @@ public enum Category{
ARMOR("Armor", getArmor()), WEAPONS("Weapons", getWeapons()), TOOLS("Tools", getTools()),
FOOD("Food", getFood()), POTIONS("Potions", getPotions()), BLOCKS("Blocks", getBlocks());
String Name;
ArrayList<Material> Items;
private String Name;
private ArrayList<Material> Items;
/**
* @param name Name of the Shop Type.

View File

@ -33,7 +33,7 @@ public class GUI implements Listener{
public static Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("CrazyAuctions");
public static void openShop(Player player, Shop sell, Category cat, int page){
Api.updateAuction();
Methods.updateAuction();
FileConfiguration config = Main.settings.getConfig();
FileConfiguration data = Main.settings.getData();
List<ItemStack> items = new ArrayList<ItemStack>();
@ -57,30 +57,30 @@ public class GUI implements Listener{
String seller = data.getString("Items."+i+".Seller");
String topbidder = data.getString("Items."+i+".TopBidder");
for(String l : config.getStringList("Settings.GUISettings.Bidding")){
lore.add(l.replaceAll("%TopBid%", Api.getPrice(i, false)).replaceAll("%topbid%", Api.getPrice(i, false))
lore.add(l.replaceAll("%TopBid%", Methods.getPrice(i, false)).replaceAll("%topbid%", Methods.getPrice(i, false))
.replaceAll("%Seller%", seller).replaceAll("%seller%", seller)
.replaceAll("%TopBidder%", topbidder).replaceAll("%topbidder%", topbidder)
.replaceAll("%Time%", Api.convertToTime(data.getLong("Items."+i+".Time-Till-Expire"))).replaceAll("%time%", Api.convertToTime(data.getLong("Items."+i+".Time-Till-Expire"))));
.replaceAll("%Time%", Methods.convertToTime(data.getLong("Items."+i+".Time-Till-Expire"))).replaceAll("%time%", Methods.convertToTime(data.getLong("Items."+i+".Time-Till-Expire"))));
}
items.add(Api.addLore(data.getItemStack("Items."+i+".Item").clone(), lore));
items.add(Methods.addLore(data.getItemStack("Items."+i+".Item").clone(), lore));
ID.add(data.getInt("Items."+i+".StoreID"));
}
}else{
if(sell==Shop.SELL){
for(String l : config.getStringList("Settings.GUISettings.SellingItemLore")){
lore.add(l.replaceAll("%Price%", Api.getPrice(i, false)).replaceAll("%price%", Api.getPrice(i, false))
lore.add(l.replaceAll("%Price%", Methods.getPrice(i, false)).replaceAll("%price%", Methods.getPrice(i, false))
.replaceAll("%Seller%", data.getString("Items."+i+".Seller")).replaceAll("%seller%", data.getString("Items."+i+".Seller")));
}
items.add(Api.addLore(data.getItemStack("Items."+i+".Item").clone(), lore));
items.add(Methods.addLore(data.getItemStack("Items."+i+".Item").clone(), lore));
ID.add(data.getInt("Items."+i+".StoreID"));
}
}
}
}
}
int maxPage = Api.getMaxPage(items);
int maxPage = Methods.getMaxPage(items);
for(;page>maxPage;page--);
Inventory inv = Bukkit.createInventory(null, 54, Api.color(config.getString("Settings.GUIName")+" #"+page));
Inventory inv = Bukkit.createInventory(null, 54, Methods.color(config.getString("Settings.GUIName")+" #"+page));
List<String> options = new ArrayList<String>();
options.add("SellingItems");options.add("Cancelled/ExpiredItems");
options.add("PreviousPage");options.add("Refesh");options.add("NextPage");
@ -96,25 +96,30 @@ public class GUI implements Listener{
options.add("WhatIsThis.BiddingShop");
}
for(String o : options){
if(config.contains("Settings.GUISettings.OtherSettings."+o+".Toggle")){
if(!config.getBoolean("Settings.GUISettings.OtherSettings."+o+".Toggle")){
continue;
}
}
String id = config.getString("Settings.GUISettings.OtherSettings."+o+".Item");
String name = config.getString("Settings.GUISettings.OtherSettings."+o+".Name");
List<String> lore = new ArrayList<String>();
int slot = config.getInt("Settings.GUISettings.OtherSettings."+o+".Slot");
String cName = Api.color(config.getString("Settings.GUISettings.Category-Settings." + Cat.get(player).getName() + ".Name"));
String cName = Methods.color(config.getString("Settings.GUISettings.Category-Settings." + Cat.get(player).getName() + ".Name"));
if(config.contains("Settings.GUISettings.OtherSettings."+o+".Lore")){
for(String l : config.getStringList("Settings.GUISettings.OtherSettings."+o+".Lore")){
lore.add(l.replaceAll("%Category%", cName).replaceAll("%category%", cName));
}
inv.setItem(slot-1, Api.makeItem(id, 1, name, lore));
inv.setItem(slot-1, Methods.makeItem(id, 1, name, lore));
}else{
inv.setItem(slot-1, Api.makeItem(id, 1, name));
inv.setItem(slot-1, Methods.makeItem(id, 1, name));
}
}
for(ItemStack item : Api.getPage(items, page)){
for(ItemStack item : Methods.getPage(items, page)){
int slot = inv.firstEmpty();
inv.setItem(slot, item);
}
for(int id : Api.getPageInts(ID, page)){
for(int id : Methods.getPageInts(ID, page)){
Id.add(id);
}
List.put(player, Id);
@ -122,9 +127,9 @@ public class GUI implements Listener{
}
public static void openCateories(Player player, Shop shop){
Api.updateAuction();
Methods.updateAuction();
FileConfiguration config = Main.settings.getConfig();
Inventory inv = Bukkit.createInventory(null, 54, Api.color(config.getString("Settings.Categories")));
Inventory inv = Bukkit.createInventory(null, 54, Methods.color(config.getString("Settings.Categories")));
List<String> options = new ArrayList<String>();
options.add("OtherSettings.Back");options.add("OtherSettings.WhatIsThis.Categories");
options.add("Category-Settings.Armor");options.add("Category-Settings.Weapons");
@ -132,13 +137,18 @@ public class GUI implements Listener{
options.add("Category-Settings.Potions");options.add("Category-Settings.Blocks");
options.add("Category-Settings.Other");options.add("Category-Settings.None");
for(String o : options){
if(config.contains("Settings.GUISettings."+o+".Toggle")){
if(!config.getBoolean("Settings.GUISettings."+o+".Toggle")){
continue;
}
}
String id = config.getString("Settings.GUISettings."+o+".Item");
String name = config.getString("Settings.GUISettings."+o+".Name");
int slot = config.getInt("Settings.GUISettings."+o+".Slot");
if(config.contains("Settings.GUISettings."+o+".Lore")){
inv.setItem(slot-1, Api.makeItem(id, 1, name, config.getStringList("Settings.GUISettings."+o+".Lore")));
inv.setItem(slot-1, Methods.makeItem(id, 1, name, config.getStringList("Settings.GUISettings."+o+".Lore")));
}else{
inv.setItem(slot-1, Api.makeItem(id, 1, name));
inv.setItem(slot-1, Methods.makeItem(id, 1, name));
}
}
Type.put(player, shop);
@ -146,23 +156,28 @@ public class GUI implements Listener{
}
public static void openPlayersCurrentList(Player player, int page){
Api.updateAuction();
Methods.updateAuction();
FileConfiguration config = Main.settings.getConfig();
FileConfiguration data = Main.settings.getData();
List<ItemStack> items = new ArrayList<ItemStack>();
List<Integer> ID = new ArrayList<Integer>();
List<Integer> Id = new ArrayList<Integer>();
Inventory inv = Bukkit.createInventory(null, 54, Api.color(config.getString("Settings.Players-Current-Items")));
Inventory inv = Bukkit.createInventory(null, 54, Methods.color(config.getString("Settings.Players-Current-Items")));
List<String> options = new ArrayList<String>();
options.add("Back");options.add("WhatIsThis.CurrentItems");
for(String o : options){
if(config.contains("Settings.GUISettings.OtherSettings."+o+".Toggle")){
if(!config.getBoolean("Settings.GUISettings.OtherSettings."+o+".Toggle")){
continue;
}
}
String id = config.getString("Settings.GUISettings.OtherSettings."+o+".Item");
String name = config.getString("Settings.GUISettings.OtherSettings."+o+".Name");
int slot = config.getInt("Settings.GUISettings.OtherSettings."+o+".Slot");
if(config.contains("Settings.GUISettings.OtherSettings."+o+".Lore")){
inv.setItem(slot-1, Api.makeItem(id, 1, name, config.getStringList("Settings.GUISettings.OtherSettings."+o+".Lore")));
inv.setItem(slot-1, Methods.makeItem(id, 1, name, config.getStringList("Settings.GUISettings.OtherSettings."+o+".Lore")));
}else{
inv.setItem(slot-1, Api.makeItem(id, 1, name));
inv.setItem(slot-1, Methods.makeItem(id, 1, name));
}
}
if(data.contains("Items")){
@ -170,19 +185,19 @@ public class GUI implements Listener{
if(data.getString("Items."+i+".Seller").equalsIgnoreCase(player.getName())){
List<String> lore = new ArrayList<String>();
for(String l : config.getStringList("Settings.GUISettings.CurrentLore")){
lore.add(l.replaceAll("%Price%", Api.getPrice(i, false)).replaceAll("%price%", Api.getPrice(i, false))
.replaceAll("%Time%", Api.convertToTime(data.getLong("Items."+i+".Time-Till-Expire"))).replaceAll("%time%", Api.convertToTime(data.getLong("Items."+i+".Time-Till-Expire"))));
lore.add(l.replaceAll("%Price%", Methods.getPrice(i, false)).replaceAll("%price%", Methods.getPrice(i, false))
.replaceAll("%Time%", Methods.convertToTime(data.getLong("Items."+i+".Time-Till-Expire"))).replaceAll("%time%", Methods.convertToTime(data.getLong("Items."+i+".Time-Till-Expire"))));
}
items.add(Api.addLore(data.getItemStack("Items."+i+".Item").clone(), lore));
items.add(Methods.addLore(data.getItemStack("Items."+i+".Item").clone(), lore));
ID.add(data.getInt("Items."+i+".StoreID"));
}
}
}
for(ItemStack item : Api.getPage(items, page)){
for(ItemStack item : Methods.getPage(items, page)){
int slot = inv.firstEmpty();
inv.setItem(slot, item);
}
for(int id : Api.getPageInts(ID, page)){
for(int id : Methods.getPageInts(ID, page)){
Id.add(id);
}
List.put(player, Id);
@ -190,7 +205,7 @@ public class GUI implements Listener{
}
public static void openPlayersExpiredList(Player player, int page){
Api.updateAuction();
Methods.updateAuction();
FileConfiguration config = Main.settings.getConfig();
FileConfiguration data = Main.settings.getData();
List<ItemStack> items = new ArrayList<ItemStack>();
@ -201,36 +216,41 @@ public class GUI implements Listener{
if(data.getString("OutOfTime/Cancelled."+i+".Seller").equalsIgnoreCase(player.getName())){
List<String> lore = new ArrayList<String>();
for(String l : config.getStringList("Settings.GUISettings.Cancelled/ExpiredLore")){
lore.add(l.replaceAll("%Price%", Api.getPrice(i, true)).replaceAll("%price%", Api.getPrice(i, true))
.replaceAll("%Time%", Api.convertToTime(data.getLong("OutOfTime/Cancelled."+i+".Full-Time"))).replaceAll("%time%", Api.convertToTime(data.getLong("OutOfTime/Cancelled."+i+".Full-Time"))));
lore.add(l.replaceAll("%Price%", Methods.getPrice(i, true)).replaceAll("%price%", Methods.getPrice(i, true))
.replaceAll("%Time%", Methods.convertToTime(data.getLong("OutOfTime/Cancelled."+i+".Full-Time"))).replaceAll("%time%", Methods.convertToTime(data.getLong("OutOfTime/Cancelled."+i+".Full-Time"))));
}
items.add(Api.addLore(data.getItemStack("OutOfTime/Cancelled."+i+".Item").clone(), lore));
items.add(Methods.addLore(data.getItemStack("OutOfTime/Cancelled."+i+".Item").clone(), lore));
ID.add(data.getInt("OutOfTime/Cancelled."+i+".StoreID"));
}
}
}
int maxPage = Api.getMaxPage(items);
int maxPage = Methods.getMaxPage(items);
for(;page>maxPage;page--);
Inventory inv = Bukkit.createInventory(null, 54, Api.color(config.getString("Settings.Cancelled/Expired-Items")+" #"+page));
Inventory inv = Bukkit.createInventory(null, 54, Methods.color(config.getString("Settings.Cancelled/Expired-Items")+" #"+page));
List<String> options = new ArrayList<String>();
options.add("Back");
options.add("PreviousPage");options.add("Return");options.add("NextPage");
options.add("WhatIsThis.Cancelled/ExpiredItems");
for(String o : options){
if(config.contains("Settings.GUISettings.OtherSettings."+o+".Toggle")){
if(!config.getBoolean("Settings.GUISettings.OtherSettings."+o+".Toggle")){
continue;
}
}
String id = config.getString("Settings.GUISettings.OtherSettings."+o+".Item");
String name = config.getString("Settings.GUISettings.OtherSettings."+o+".Name");
int slot = config.getInt("Settings.GUISettings.OtherSettings."+o+".Slot");
if(config.contains("Settings.GUISettings.OtherSettings."+o+".Lore")){
inv.setItem(slot-1, Api.makeItem(id, 1, name, config.getStringList("Settings.GUISettings.OtherSettings."+o+".Lore")));
inv.setItem(slot-1, Methods.makeItem(id, 1, name, config.getStringList("Settings.GUISettings.OtherSettings."+o+".Lore")));
}else{
inv.setItem(slot-1, Api.makeItem(id, 1, name));
inv.setItem(slot-1, Methods.makeItem(id, 1, name));
}
}
for(ItemStack item : Api.getPage(items, page)){
for(ItemStack item : Methods.getPage(items, page)){
int slot = inv.firstEmpty();
inv.setItem(slot, item);
}
for(int id : Api.getPageInts(ID, page)){
for(int id : Methods.getPageInts(ID, page)){
Id.add(id);
}
List.put(player, Id);
@ -238,16 +258,16 @@ public class GUI implements Listener{
}
public static void openBuying(Player player, String ID){
Api.updateAuction();
Methods.updateAuction();
FileConfiguration config = Main.settings.getConfig();
FileConfiguration data = Main.settings.getData();
FileConfiguration msg = Main.settings.getMsg();
if(!data.contains("Items."+ID)){
openShop(player, Shop.SELL, Cat.get(player), 1);
player.sendMessage(Api.getPrefix()+Api.color(msg.getString("Messages.Item-Doesnt-Exist")));
player.sendMessage(Methods.getPrefix()+Methods.color(msg.getString("Messages.Item-Doesnt-Exist")));
return;
}
Inventory inv = Bukkit.createInventory(null, 9, Api.color(config.getString("Settings.Buying-Item")));
Inventory inv = Bukkit.createInventory(null, 9, Methods.color(config.getString("Settings.Buying-Item")));
List<String> options = new ArrayList<String>();
options.add("Confirm");options.add("Cancel");
for(String o : options){
@ -255,9 +275,9 @@ public class GUI implements Listener{
String name = config.getString("Settings.GUISettings.OtherSettings."+o+".Name");
ItemStack item = new ItemStack(Material.AIR);
if(config.contains("Settings.GUISettings.OtherSettings."+o+".Lore")){
item = Api.makeItem(id, 1, name, config.getStringList("Settings.GUISettings.OtherSettings."+o+".Lore"));
item = Methods.makeItem(id, 1, name, config.getStringList("Settings.GUISettings.OtherSettings."+o+".Lore"));
}else{
item = Api.makeItem(id, 1, name);
item = Methods.makeItem(id, 1, name);
}
if(o.equals("Confirm")){
inv.setItem(0, item);
@ -275,36 +295,36 @@ public class GUI implements Listener{
ItemStack item = data.getItemStack("Items."+ID+".Item");
List<String> lore = new ArrayList<String>();
for(String l : config.getStringList("Settings.GUISettings.SellingLore")){
lore.add(l.replaceAll("%Price%", Api.getPrice(ID, false)).replaceAll("%price%", Api.getPrice(ID, false))
lore.add(l.replaceAll("%Price%", Methods.getPrice(ID, false)).replaceAll("%price%", Methods.getPrice(ID, false))
.replaceAll("%Seller%", data.getString("Items."+ID+".Seller")).replaceAll("%seller%", data.getString("Items."+ID+".Seller")));
}
inv.setItem(4, Api.addLore(item.clone(), lore));
inv.setItem(4, Methods.addLore(item.clone(), lore));
IDs.put(player, ID);
player.openInventory(inv);
}
public static void openBidding(Player player, String ID){
Api.updateAuction();
Methods.updateAuction();
FileConfiguration config = Main.settings.getConfig();
FileConfiguration data = Main.settings.getData();
FileConfiguration msg = Main.settings.getMsg();
if(!data.contains("Items."+ID)){
openShop(player, Shop.BID, Cat.get(player), 1);
player.sendMessage(Api.getPrefix()+Api.color(msg.getString("Messages.Item-Doesnt-Exist")));
player.sendMessage(Methods.getPrefix()+Methods.color(msg.getString("Messages.Item-Doesnt-Exist")));
return;
}
Inventory inv = Bukkit.createInventory(null, 27, Api.color(config.getString("Settings.Bidding-On-Item")));
Inventory inv = Bukkit.createInventory(null, 27, Methods.color(config.getString("Settings.Bidding-On-Item")));
if(!Bidding.containsKey(player))Bidding.put(player, 0);
inv.setItem(9, Api.makeItem("160:5", 1, "&a+1"));
inv.setItem(10, Api.makeItem("160:5", 1, "&a+10"));
inv.setItem(11, Api.makeItem("160:5", 1, "&a+100"));
inv.setItem(12, Api.makeItem("160:5", 1, "&a+1000"));
inv.setItem(9, Methods.makeItem("160:5", 1, "&a+1"));
inv.setItem(10, Methods.makeItem("160:5", 1, "&a+10"));
inv.setItem(11, Methods.makeItem("160:5", 1, "&a+100"));
inv.setItem(12, Methods.makeItem("160:5", 1, "&a+1000"));
inv.setItem(13, getBiddingGlass(player, ID));
inv.setItem(14, Api.makeItem("160:14", 1, "&c-1000"));
inv.setItem(15, Api.makeItem("160:14", 1, "&c-100"));
inv.setItem(16, Api.makeItem("160:14", 1, "&c-10"));
inv.setItem(17, Api.makeItem("160:14", 1, "&c-1"));
inv.setItem(22, Api.makeItem(config.getString("Settings.GUISettings.OtherSettings.Bid.Item"), 1, config.getString("Settings.GUISettings.OtherSettings.Bid.Name"),
inv.setItem(14, Methods.makeItem("160:14", 1, "&c-1000"));
inv.setItem(15, Methods.makeItem("160:14", 1, "&c-100"));
inv.setItem(16, Methods.makeItem("160:14", 1, "&c-10"));
inv.setItem(17, Methods.makeItem("160:14", 1, "&c-1"));
inv.setItem(22, Methods.makeItem(config.getString("Settings.GUISettings.OtherSettings.Bid.Item"), 1, config.getString("Settings.GUISettings.OtherSettings.Bid.Name"),
config.getStringList("Settings.GUISettings.OtherSettings.Bid.Lore")));
inv.setItem(4, getBiddingItem(player, ID));
@ -312,7 +332,7 @@ public class GUI implements Listener{
}
public static void openViewer(Player player, String other, int page){
Api.updateAuction();
Methods.updateAuction();
FileConfiguration config = Main.settings.getConfig();
FileConfiguration data = Main.settings.getData();
List<ItemStack> items = new ArrayList<ItemStack>();
@ -330,44 +350,49 @@ public class GUI implements Listener{
String seller = data.getString("Items."+i+".Seller");
String topbidder = data.getString("Items."+i+".TopBidder");
for(String l : config.getStringList("Settings.GUISettings.Bidding")){
lore.add(l.replaceAll("%TopBid%", Api.getPrice(i, false)).replaceAll("%topbid%", Api.getPrice(i, false))
lore.add(l.replaceAll("%TopBid%", Methods.getPrice(i, false)).replaceAll("%topbid%", Methods.getPrice(i, false))
.replaceAll("%Seller%", seller).replaceAll("%seller%", seller)
.replaceAll("%TopBidder%", topbidder).replaceAll("%topbidder%", topbidder)
.replaceAll("%Time%", Api.convertToTime(data.getLong("Items."+i+".Time-Till-Expire"))).replaceAll("%time%", Api.convertToTime(data.getLong("Items."+i+".Time-Till-Expire"))));
.replaceAll("%Time%", Methods.convertToTime(data.getLong("Items."+i+".Time-Till-Expire"))).replaceAll("%time%", Methods.convertToTime(data.getLong("Items."+i+".Time-Till-Expire"))));
}
items.add(Api.addLore(data.getItemStack("Items."+i+".Item").clone(), lore));
items.add(Methods.addLore(data.getItemStack("Items."+i+".Item").clone(), lore));
ID.add(data.getInt("Items."+i+".StoreID"));
}else{
for(String l : config.getStringList("Settings.GUISettings.SellingItemLore")){
lore.add(l.replaceAll("%Price%", Api.getPrice(i, false)).replaceAll("%price%", Api.getPrice(i, false))
lore.add(l.replaceAll("%Price%", Methods.getPrice(i, false)).replaceAll("%price%", Methods.getPrice(i, false))
.replaceAll("%Seller%", data.getString("Items."+i+".Seller")).replaceAll("%seller%", data.getString("Items."+i+".Seller")));
}
items.add(Api.addLore(data.getItemStack("Items."+i+".Item").clone(), lore));
items.add(Methods.addLore(data.getItemStack("Items."+i+".Item").clone(), lore));
ID.add(data.getInt("Items."+i+".StoreID"));
}
}
}
}
int maxPage = Api.getMaxPage(items);
int maxPage = Methods.getMaxPage(items);
for(;page>maxPage;page--);
Inventory inv = Bukkit.createInventory(null, 54, Api.color(config.getString("Settings.GUIName")+" #"+page));
Inventory inv = Bukkit.createInventory(null, 54, Methods.color(config.getString("Settings.GUIName")+" #"+page));
List<String> options = new ArrayList<String>();
options.add("WhatIsThis.Viewing");
for(String o : options){
if(config.contains("Settings.GUISettings.OtherSettings."+o+".Toggle")){
if(!config.getBoolean("Settings.GUISettings.OtherSettings."+o+".Toggle")){
continue;
}
}
String id = config.getString("Settings.GUISettings.OtherSettings."+o+".Item");
String name = config.getString("Settings.GUISettings.OtherSettings."+o+".Name");
int slot = config.getInt("Settings.GUISettings.OtherSettings."+o+".Slot");
if(config.contains("Settings.GUISettings.OtherSettings."+o+".Lore")){
inv.setItem(slot-1, Api.makeItem(id, 1, name, config.getStringList("Settings.GUISettings.OtherSettings."+o+".Lore")));
inv.setItem(slot-1, Methods.makeItem(id, 1, name, config.getStringList("Settings.GUISettings.OtherSettings."+o+".Lore")));
}else{
inv.setItem(slot-1, Api.makeItem(id, 1, name));
inv.setItem(slot-1, Methods.makeItem(id, 1, name));
}
}
for(ItemStack item : Api.getPage(items, page)){
for(ItemStack item : Methods.getPage(items, page)){
int slot = inv.firstEmpty();
inv.setItem(slot, item);
}
for(int id : Api.getPageInts(ID, page)){
for(int id : Methods.getPageInts(ID, page)){
Id.add(id);
}
List.put(player, Id);
@ -384,11 +409,11 @@ public class GUI implements Listener{
List<String> lore = new ArrayList<String>();
for(String l : config.getStringList("Settings.GUISettings.OtherSettings.Bidding.Lore")){
lore.add(l.replaceAll("%Bid%", bid+"").replaceAll("%bid%", bid+"")
.replaceAll("%TopBid%", Api.getPrice(ID, false)).replaceAll("%topbid%", Api.getPrice(ID, false)));
.replaceAll("%TopBid%", Methods.getPrice(ID, false)).replaceAll("%topbid%", Methods.getPrice(ID, false)));
}
item = Api.makeItem(id, 1, name, lore);
item = Methods.makeItem(id, 1, name, lore);
}else{
item = Api.makeItem(id, 1, name);
item = Methods.makeItem(id, 1, name);
}
return item;
}
@ -401,12 +426,12 @@ public class GUI implements Listener{
ItemStack item = data.getItemStack("Items."+ID+".Item");
List<String> lore = new ArrayList<String>();
for(String l : config.getStringList("Settings.GUISettings.Bidding")){
lore.add(l.replaceAll("%TopBid%", Api.getPrice(ID, false)).replaceAll("%topbid%", Api.getPrice(ID, false))
lore.add(l.replaceAll("%TopBid%", Methods.getPrice(ID, false)).replaceAll("%topbid%", Methods.getPrice(ID, false))
.replaceAll("%Seller%", seller).replaceAll("%seller%", seller)
.replaceAll("%TopBidder%", topbidder).replaceAll("%topbidder%", topbidder)
.replaceAll("%Time%", Api.convertToTime(data.getLong("Items."+ID+".Time-Till-Expire"))).replaceAll("%time%", Api.convertToTime(data.getLong("Items."+ID+".Time-Till-Expire"))));
.replaceAll("%Time%", Methods.convertToTime(data.getLong("Items."+ID+".Time-Till-Expire"))).replaceAll("%time%", Methods.convertToTime(data.getLong("Items."+ID+".Time-Till-Expire"))));
}
return Api.addLore(item.clone(), lore);
return Methods.addLore(item.clone(), lore);
}
@EventHandler
@ -415,7 +440,7 @@ public class GUI implements Listener{
Inventory inv = e.getInventory();
Player player = (Player) e.getPlayer();
if(inv!=null){
if(inv.getName().contains(Api.color(config.getString("Settings.Bidding-On-Item")))){
if(inv.getName().contains(Methods.color(config.getString("Settings.Bidding-On-Item")))){
if(Bidding.containsKey(player)){
Bidding.remove(player);
}
@ -431,7 +456,7 @@ public class GUI implements Listener{
Player player = (Player)e.getWhoClicked();
final Inventory inv = e.getInventory();
if(inv!=null){
if(inv.getName().contains(Api.color(config.getString("Settings.Categories")))){
if(inv.getName().contains(Methods.color(config.getString("Settings.Categories")))){
e.setCancelled(true);
int slot = e.getRawSlot();
if(slot<=inv.getSize()){
@ -440,12 +465,12 @@ public class GUI implements Listener{
if(item.hasItemMeta()){
if(item.getItemMeta().hasDisplayName()){
for(Category cat : Category.values()){
if(item.getItemMeta().getDisplayName().equals(Api.color(config.getString("Settings.GUISettings.Category-Settings."+cat.getName()+".Name")))){
if(item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.Category-Settings."+cat.getName()+".Name")))){
openShop(player, Type.get(player), cat, 1);
playClick(player);
return;
}
if(item.getItemMeta().getDisplayName().equals(Api.color(config.getString("Settings.GUISettings.OtherSettings.Back.Name")))){
if(item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Back.Name")))){
openShop(player, Type.get(player), Cat.get(player), 1);
playClick(player);
return;
@ -456,7 +481,7 @@ public class GUI implements Listener{
}
}
}
if(inv.getName().contains(Api.color(config.getString("Settings.Bidding-On-Item")))){
if(inv.getName().contains(Methods.color(config.getString("Settings.Bidding-On-Item")))){
e.setCancelled(true);
int slot = e.getRawSlot();
if(slot<=inv.getSize()){
@ -464,26 +489,26 @@ public class GUI implements Listener{
ItemStack item = e.getCurrentItem();
if(item.hasItemMeta()){
if(item.getItemMeta().hasDisplayName()){
if(item.getItemMeta().getDisplayName().equals(Api.color(config.getString("Settings.GUISettings.OtherSettings.Bid.Name")))){
if(item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Bid.Name")))){
String ID = BiddingID.get(player);
int bid = Bidding.get(player);
String topBidder = data.getString("Items."+ID+".TopBidder");
if(CM.getMoney(player)<bid){
player.sendMessage(Api.getPrefix()+Api.color(msg.getString("Messages.Need-More-Money")
player.sendMessage(Methods.getPrefix()+Methods.color(msg.getString("Messages.Need-More-Money")
.replaceAll("%Money_Needed%", (bid-CM.getMoney(player))+"").replaceAll("%money_needed%", (bid-CM.getMoney(player))+"")));
return;
}
if(data.getLong("Items."+ID+".Price")>bid){
player.sendMessage(Api.getPrefix()+Api.color(msg.getString("Messages.Bid-More-Money")));
player.sendMessage(Methods.getPrefix()+Methods.color(msg.getString("Messages.Bid-More-Money")));
return;
}
if(data.getLong("Items."+ID+".Price")>=bid&&!topBidder.equalsIgnoreCase("None")){
player.sendMessage(Api.getPrefix()+Api.color(msg.getString("Messages.Bid-More-Money")));
player.sendMessage(Methods.getPrefix()+Methods.color(msg.getString("Messages.Bid-More-Money")));
return;
}
data.set("Items."+ID+".Price", bid);
data.set("Items."+ID+".TopBidder", player.getName());
player.sendMessage(Api.getPrefix()+Api.color(msg.getString("Messages.Bid-Msg")
player.sendMessage(Methods.getPrefix()+Methods.color(msg.getString("Messages.Bid-Msg")
.replaceAll("%Bid%", bid+"").replaceAll("%bid%", bid+"")));
Main.settings.saveData();
Bidding.put(player, 0);
@ -491,35 +516,35 @@ public class GUI implements Listener{
playClick(player);
return;
}
if(item.getItemMeta().getDisplayName().equals(Api.color("&a+1"))){
if(item.getItemMeta().getDisplayName().equals(Methods.color("&a+1"))){
Bidding.put(player, (Bidding.get(player)+1));
inv.setItem(4, getBiddingItem(player, BiddingID.get(player)));
inv.setItem(13, getBiddingGlass(player, BiddingID.get(player)));
playClick(player);
return;
}
if(item.getItemMeta().getDisplayName().equals(Api.color("&a+10"))){
if(item.getItemMeta().getDisplayName().equals(Methods.color("&a+10"))){
Bidding.put(player, (Bidding.get(player)+10));
inv.setItem(4, getBiddingItem(player, BiddingID.get(player)));
inv.setItem(13, getBiddingGlass(player, BiddingID.get(player)));
playClick(player);
return;
}
if(item.getItemMeta().getDisplayName().equals(Api.color("&a+100"))){
if(item.getItemMeta().getDisplayName().equals(Methods.color("&a+100"))){
Bidding.put(player, (Bidding.get(player)+100));
inv.setItem(4, getBiddingItem(player, BiddingID.get(player)));
inv.setItem(13, getBiddingGlass(player, BiddingID.get(player)));
playClick(player);
return;
}
if(item.getItemMeta().getDisplayName().equals(Api.color("&a+1000"))){
if(item.getItemMeta().getDisplayName().equals(Methods.color("&a+1000"))){
Bidding.put(player, (Bidding.get(player)+1000));
inv.setItem(4, getBiddingItem(player, BiddingID.get(player)));
inv.setItem(13, getBiddingGlass(player, BiddingID.get(player)));
playClick(player);
return;
}
if(item.getItemMeta().getDisplayName().equals(Api.color("&c-1"))){
if(item.getItemMeta().getDisplayName().equals(Methods.color("&c-1"))){
int bid = Bidding.get(player)-1;
if(bid<0)bid=0;
Bidding.put(player, bid);
@ -528,7 +553,7 @@ public class GUI implements Listener{
playClick(player);
return;
}
if(item.getItemMeta().getDisplayName().equals(Api.color("&c-10"))){
if(item.getItemMeta().getDisplayName().equals(Methods.color("&c-10"))){
int bid = Bidding.get(player)-10;
if(bid<0)bid=0;
Bidding.put(player, bid);
@ -537,7 +562,7 @@ public class GUI implements Listener{
playClick(player);
return;
}
if(item.getItemMeta().getDisplayName().equals(Api.color("&c-100"))){
if(item.getItemMeta().getDisplayName().equals(Methods.color("&c-100"))){
int bid = Bidding.get(player)-100;
if(bid<0)bid=0;
Bidding.put(player, bid);
@ -546,7 +571,7 @@ public class GUI implements Listener{
playClick(player);
return;
}
if(item.getItemMeta().getDisplayName().equals(Api.color("&c-1000"))){
if(item.getItemMeta().getDisplayName().equals(Methods.color("&c-1000"))){
int bid = Bidding.get(player)-1000;
if(bid<0)bid=0;
Bidding.put(player, bid);
@ -560,7 +585,7 @@ public class GUI implements Listener{
}
}
}
if(inv.getName().contains(Api.color(config.getString("Settings.GUIName")))){
if(inv.getName().contains(Methods.color(config.getString("Settings.GUIName")))){
e.setCancelled(true);
final int slot = e.getRawSlot();
if(slot<=inv.getSize()){
@ -568,65 +593,65 @@ public class GUI implements Listener{
final ItemStack item = e.getCurrentItem();
if(item.hasItemMeta()){
if(item.getItemMeta().hasDisplayName()){
if(item.getItemMeta().getDisplayName().equals(Api.color(config.getString("Settings.GUISettings.OtherSettings.NextPage.Name")))){
Api.updateAuction();
if(item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.NextPage.Name")))){
Methods.updateAuction();
int page = Integer.parseInt(inv.getName().split("#")[1]);
openShop(player, Type.get(player), Cat.get(player), page+1);
playClick(player);
return;
}
if(item.getItemMeta().getDisplayName().equals(Api.color(config.getString("Settings.GUISettings.OtherSettings.PreviousPage.Name")))){
Api.updateAuction();
if(item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.PreviousPage.Name")))){
Methods.updateAuction();
int page = Integer.parseInt(inv.getName().split("#")[1]);
if(page==1)page++;
openShop(player, Type.get(player), Cat.get(player), page-1);
playClick(player);
return;
}
if(item.getItemMeta().getDisplayName().equals(Api.color(config.getString("Settings.GUISettings.OtherSettings.Refesh.Name")))){
Api.updateAuction();
if(item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Refesh.Name")))){
Methods.updateAuction();
int page = Integer.parseInt(inv.getName().split("#")[1]);
openShop(player, Type.get(player), Cat.get(player), page);
playClick(player);
return;
}
if(item.getItemMeta().getDisplayName().equals(Api.color(config.getString("Settings.GUISettings.OtherSettings.Bidding/Selling.Selling.Name")))){
if(item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Bidding/Selling.Selling.Name")))){
openShop(player, Shop.BID, Cat.get(player), 1);
playClick(player);
return;
}
if(item.getItemMeta().getDisplayName().equals(Api.color(config.getString("Settings.GUISettings.OtherSettings.Bidding/Selling.Bidding.Name")))){
if(item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Bidding/Selling.Bidding.Name")))){
openShop(player, Shop.SELL, Cat.get(player), 1);
playClick(player);
return;
}
if(item.getItemMeta().getDisplayName().equals(Api.color(config.getString("Settings.GUISettings.OtherSettings.Cancelled/ExpiredItems.Name")))){
if(item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Cancelled/ExpiredItems.Name")))){
openPlayersExpiredList(player, 1);
playClick(player);
return;
}
if(item.getItemMeta().getDisplayName().equals(Api.color(config.getString("Settings.GUISettings.OtherSettings.SellingItems.Name")))){
if(item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.SellingItems.Name")))){
openPlayersCurrentList(player, 1);
playClick(player);
return;
}
if(item.getItemMeta().getDisplayName().equals(Api.color(config.getString("Settings.GUISettings.OtherSettings.Category1.Name")))){
if(item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Category1.Name")))){
openCateories(player, Type.get(player));
playClick(player);
return;
}
if(item.getItemMeta().getDisplayName().equals(Api.color(config.getString("Settings.GUISettings.OtherSettings.Category2.Name")))){
if(item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Category2.Name")))){
openCateories(player, Type.get(player));
playClick(player);
return;
}
if(item.getItemMeta().getDisplayName().equals(Api.color(config.getString("Settings.GUISettings.OtherSettings.Your-Item.Name")))){
if(item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Your-Item.Name")))){
return;
}
if(item.getItemMeta().getDisplayName().equals(Api.color(config.getString("Settings.GUISettings.OtherSettings.Cant-Afford.Name")))){
if(item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Cant-Afford.Name")))){
return;
}
if(item.getItemMeta().getDisplayName().equals(Api.color(config.getString("Settings.GUISettings.OtherSettings.Top-Bidder.Name")))){
if(item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Top-Bidder.Name")))){
return;
}
}
@ -643,9 +668,9 @@ public class GUI implements Listener{
int num = 1;
for(;data.contains("OutOfTime/Cancelled."+num);num++);
String seller = data.getString("Items."+i+".Seller");
if(Api.isOnline(seller)){
Player S = Api.getPlayer(seller);
S.sendMessage(Api.getPrefix()+Api.color(msg.getString("Messages.Admin-Force-Cancelled-To-Player")));
if(Methods.isOnline(seller)){
Player S = Methods.getPlayer(seller);
S.sendMessage(Methods.getPrefix()+Methods.color(msg.getString("Messages.Admin-Force-Cancelled-To-Player")));
}
data.set("OutOfTime/Cancelled."+num+".Seller", data.getString("Items."+i+".Seller"));
data.set("OutOfTime/Cancelled."+num+".Full-Time", data.getLong("Items."+i+".Full-Time"));
@ -653,7 +678,7 @@ public class GUI implements Listener{
data.set("OutOfTime/Cancelled."+num+".Item", data.getItemStack("Items."+i+".Item"));
data.set("Items."+i, null);
Main.settings.saveData();
player.sendMessage(Api.getPrefix()+Api.color(msg.getString("Messages.Admin-Force-Cancelled")));
player.sendMessage(Methods.getPrefix()+Methods.color(msg.getString("Messages.Admin-Force-Cancelled")));
playClick(player);
int page = Integer.parseInt(inv.getName().split("#")[1]);
openShop(player, Type.get(player), Cat.get(player), page);
@ -665,9 +690,9 @@ public class GUI implements Listener{
String name = config.getString("Settings.GUISettings.OtherSettings.Your-Item.Name");
ItemStack I = new ItemStack(Material.AIR);
if(config.contains("Settings.GUISettings.OtherSettings.Your-Item.Lore")){
I = Api.makeItem(it, 1, name, config.getStringList("Settings.GUISettings.OtherSettings.Your-Item.Lore"));
I = Methods.makeItem(it, 1, name, config.getStringList("Settings.GUISettings.OtherSettings.Your-Item.Lore"));
}else{
I = Api.makeItem(it, 1, name);
I = Methods.makeItem(it, 1, name);
}
inv.setItem(slot, I);
playClick(player);
@ -685,9 +710,9 @@ public class GUI implements Listener{
String name = config.getString("Settings.GUISettings.OtherSettings.Cant-Afford.Name");
ItemStack I = new ItemStack(Material.AIR);
if(config.contains("Settings.GUISettings.OtherSettings.Cant-Afford.Lore")){
I = Api.makeItem(it, 1, name, config.getStringList("Settings.GUISettings.OtherSettings.Cant-Afford.Lore"));
I = Methods.makeItem(it, 1, name, config.getStringList("Settings.GUISettings.OtherSettings.Cant-Afford.Lore"));
}else{
I = Api.makeItem(it, 1, name);
I = Methods.makeItem(it, 1, name);
}
inv.setItem(slot, I);
playClick(player);
@ -705,9 +730,9 @@ public class GUI implements Listener{
String name = config.getString("Settings.GUISettings.OtherSettings.Top-Bidder.Name");
ItemStack I = new ItemStack(Material.AIR);
if(config.contains("Settings.GUISettings.OtherSettings.Top-Bidder.Lore")){
I = Api.makeItem(it, 1, name, config.getStringList("Settings.GUISettings.OtherSettings.Top-Bidder.Lore"));
I = Methods.makeItem(it, 1, name, config.getStringList("Settings.GUISettings.OtherSettings.Top-Bidder.Lore"));
}else{
I = Api.makeItem(it, 1, name);
I = Methods.makeItem(it, 1, name);
}
inv.setItem(slot, I);
playClick(player);
@ -733,7 +758,7 @@ public class GUI implements Listener{
if(!T){
playClick(player);
openShop(player, Type.get(player), Cat.get(player), 1);
player.sendMessage(Api.getPrefix()+Api.color(msg.getString("Messages.Item-Doesnt-Exist")));
player.sendMessage(Methods.getPrefix()+Methods.color(msg.getString("Messages.Item-Doesnt-Exist")));
return;
}
}
@ -741,7 +766,7 @@ public class GUI implements Listener{
}
}
}
if(inv.getName().contains(Api.color(config.getString("Settings.Buying-Item")))){
if(inv.getName().contains(Methods.color(config.getString("Settings.Buying-Item")))){
e.setCancelled(true);
int slot = e.getRawSlot();
if(slot<=inv.getSize()){
@ -749,37 +774,37 @@ public class GUI implements Listener{
ItemStack item = e.getCurrentItem();
if(item.hasItemMeta()){
if(item.getItemMeta().hasDisplayName()){
if(item.getItemMeta().getDisplayName().equals(Api.color(config.getString("Settings.GUISettings.OtherSettings.Confirm.Name")))){
if(item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Confirm.Name")))){
String ID = IDs.get(player);
long cost = data.getLong("Items."+ID+".Price");
String seller = data.getString("Items."+ID+".Seller");
if(!data.contains("Items."+ID)){
playClick(player);
openShop(player, Type.get(player), Cat.get(player), 1);
player.sendMessage(Api.getPrefix()+Api.color(msg.getString("Messages.Item-Doesnt-Exist")));
player.sendMessage(Methods.getPrefix()+Methods.color(msg.getString("Messages.Item-Doesnt-Exist")));
return;
}
if(Api.isInvFull(player)){
if(Methods.isInvFull(player)){
playClick(player);
player.closeInventory();
player.sendMessage(Api.getPrefix()+Api.color(msg.getString("Messages.Inventory-Full")));
player.sendMessage(Methods.getPrefix()+Methods.color(msg.getString("Messages.Inventory-Full")));
return;
}
if(CM.getMoney(player)<cost){
playClick(player);
player.closeInventory();
player.sendMessage(Api.getPrefix()+Api.color(msg.getString("Messages.Need-More-Money")
player.sendMessage(Methods.getPrefix()+Methods.color(msg.getString("Messages.Need-More-Money")
.replaceAll("%Money_Needed%", (cost-CM.getMoney(player))+"").replaceAll("%money_needed%", (cost-CM.getMoney(player))+"")));
return;
}
CM.removeMoney(player, cost);
CM.addMoney(Api.getOfflinePlayer(seller), cost);
player.sendMessage(Api.getPrefix()+Api.color(msg.getString("Messages.Bought-Item")
.replaceAll("%Price%", Api.getPrice(ID, false)).replaceAll("%price%", Api.getPrice(ID, false))));
if(Api.isOnline(seller)){
Player sell = Api.getPlayer(seller);
sell.sendMessage(Api.getPrefix()+Api.color(msg.getString("Messages.Player-Bought-Item")
.replaceAll("%Price%", Api.getPrice(ID, false)).replaceAll("%price%", Api.getPrice(ID, false))
CM.addMoney(Methods.getOfflinePlayer(seller), cost);
player.sendMessage(Methods.getPrefix()+Methods.color(msg.getString("Messages.Bought-Item")
.replaceAll("%Price%", Methods.getPrice(ID, false)).replaceAll("%price%", Methods.getPrice(ID, false))));
if(Methods.isOnline(seller)){
Player sell = Methods.getPlayer(seller);
sell.sendMessage(Methods.getPrefix()+Methods.color(msg.getString("Messages.Player-Bought-Item")
.replaceAll("%Price%", Methods.getPrice(ID, false)).replaceAll("%price%", Methods.getPrice(ID, false))
.replaceAll("%Player%", player.getName()).replaceAll("%player%", player.getName())));
}
ItemStack i = data.getItemStack("Items."+ID+".Item");
@ -790,7 +815,7 @@ public class GUI implements Listener{
openShop(player, Type.get(player), Cat.get(player), 1);
return;
}
if(item.getItemMeta().getDisplayName().equals(Api.color(config.getString("Settings.GUISettings.OtherSettings.Cancel.Name")))){
if(item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Cancel.Name")))){
openShop(player, Type.get(player), Cat.get(player), 1);
playClick(player);
return;
@ -800,7 +825,7 @@ public class GUI implements Listener{
}
}
}
if(inv.getName().contains(Api.color(config.getString("Settings.Players-Current-Items")))){
if(inv.getName().contains(Methods.color(config.getString("Settings.Players-Current-Items")))){
e.setCancelled(true);
int slot = e.getRawSlot();
if(slot<=inv.getSize()){
@ -808,7 +833,7 @@ public class GUI implements Listener{
ItemStack item = e.getCurrentItem();
if(item.hasItemMeta()){
if(item.getItemMeta().hasDisplayName()){
if(item.getItemMeta().getDisplayName().equals(Api.color(config.getString("Settings.GUISettings.OtherSettings.Back.Name")))){
if(item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Back.Name")))){
openShop(player, Type.get(player), Cat.get(player), 1);
playClick(player);
return;
@ -822,7 +847,7 @@ public class GUI implements Listener{
int ID = data.getInt("Items."+i+".StoreID");
if(id==ID){
T=true;
player.sendMessage(Api.getPrefix()+Api.color(msg.getString("Messages.Cancelled-Item")));
player.sendMessage(Methods.getPrefix()+Methods.color(msg.getString("Messages.Cancelled-Item")));
int num = 1;
for(;data.contains("OutOfTime/Cancelled."+num);num++);
data.set("OutOfTime/Cancelled."+num+".Seller", data.getString("Items."+i+".Seller"));
@ -840,7 +865,7 @@ public class GUI implements Listener{
if(!T){
playClick(player);
openShop(player, Type.get(player), Cat.get(player), 1);
player.sendMessage(Api.getPrefix()+Api.color(msg.getString("Messages.Item-Doesnt-Exist")));
player.sendMessage(Methods.getPrefix()+Methods.color(msg.getString("Messages.Item-Doesnt-Exist")));
return;
}
}
@ -848,7 +873,7 @@ public class GUI implements Listener{
}
}
}
if(inv.getName().contains(Api.color(config.getString("Settings.Cancelled/Expired-Items")))){
if(inv.getName().contains(Methods.color(config.getString("Settings.Cancelled/Expired-Items")))){
e.setCancelled(true);
final int slot = e.getRawSlot();
if(slot<=inv.getSize()){
@ -856,28 +881,29 @@ public class GUI implements Listener{
final ItemStack item = e.getCurrentItem();
if(item.hasItemMeta()){
if(item.getItemMeta().hasDisplayName()){
if(item.getItemMeta().getDisplayName().equals(Api.color(config.getString("Settings.GUISettings.OtherSettings.Back.Name")))){
Api.updateAuction();
if(item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Back.Name")))){
Methods.updateAuction();
playClick(player);
openShop(player, Type.get(player), Cat.get(player), 1);
return;
}
if(item.getItemMeta().getDisplayName().equals(Api.color(config.getString("Settings.GUISettings.OtherSettings.PreviousPage.Name")))){
Api.updateAuction();
if(item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.PreviousPage.Name")))){
Methods.updateAuction();
int page = Integer.parseInt(inv.getName().split("#")[1]);
if(page==1)page++;
playClick(player);
openPlayersExpiredList(player, (page-1));
return;
}
if(item.getItemMeta().getDisplayName().equals(Api.color(config.getString("Settings.GUISettings.OtherSettings.Return.Name")))){
Api.updateAuction();
if(item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Return.Name")))){
Methods.updateAuction();
int page = Integer.parseInt(inv.getName().split("#")[1]);
if(data.contains("OutOfTime/Cancelled")){
for(String i : data.getConfigurationSection("OutOfTime/Cancelled").getKeys(false)){
if(data.getString("OutOfTime/Cancelled."+i+".Seller").equalsIgnoreCase(player.getName())){
if(Api.isInvFull(player)){
player.sendMessage(Api.getPrefix()+Api.color(Main.settings.getMsg().getString("Messages.Inventory-Full")));
if(Methods.isInvFull(player)){
player.sendMessage(Methods.getPrefix()+Methods.color(Main.settings.getMsg().getString("Messages.Inventory-Full")));
break;
}else{
player.getInventory().addItem(data.getItemStack("OutOfTime/Cancelled."+i+".Item"));
data.set("OutOfTime/Cancelled."+i, null);
@ -885,14 +911,14 @@ public class GUI implements Listener{
}
}
}
player.sendMessage(Api.getPrefix()+Api.color(msg.getString("Messages.Got-Item-Back")));
player.sendMessage(Methods.getPrefix()+Methods.color(msg.getString("Messages.Got-Item-Back")));
Main.settings.saveData();
playClick(player);
openPlayersExpiredList(player, page);
return;
}
if(item.getItemMeta().getDisplayName().equals(Api.color(config.getString("Settings.GUISettings.OtherSettings.NextPage.Name")))){
Api.updateAuction();
if(item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.NextPage.Name")))){
Methods.updateAuction();
int page = Integer.parseInt(inv.getName().split("#")[1]);
playClick(player);
openPlayersExpiredList(player, (page+1));
@ -906,9 +932,9 @@ public class GUI implements Listener{
for(String i : data.getConfigurationSection("OutOfTime/Cancelled").getKeys(false)){
int ID = data.getInt("OutOfTime/Cancelled."+i+".StoreID");
if(id==ID){
if(!Api.isInvFull(player)){
if(!Methods.isInvFull(player)){
T=true;
player.sendMessage(Api.getPrefix()+Api.color(msg.getString("Messages.Got-Item-Back")));
player.sendMessage(Methods.getPrefix()+Methods.color(msg.getString("Messages.Got-Item-Back")));
ItemStack IT = data.getItemStack("OutOfTime/Cancelled."+i+".Item");
player.getInventory().addItem(IT);
data.set("OutOfTime/Cancelled."+i, null);
@ -917,7 +943,7 @@ public class GUI implements Listener{
openPlayersExpiredList(player, 1);
return;
}else{
player.sendMessage(Api.getPrefix() + Api.color(msg.getString("Messages.Inventory-Full")));
player.sendMessage(Methods.getPrefix() + Methods.color(msg.getString("Messages.Inventory-Full")));
return;
}
}
@ -926,7 +952,7 @@ public class GUI implements Listener{
if(!T){
playClick(player);
openShop(player, Type.get(player), Cat.get(player), 1);
player.sendMessage(Api.getPrefix()+Api.color(msg.getString("Messages.Item-Doesnt-Exist")));
player.sendMessage(Methods.getPrefix()+Methods.color(msg.getString("Messages.Item-Doesnt-Exist")));
return;
}
}
@ -944,7 +970,7 @@ public class GUI implements Listener{
try{
player.playSound(player.getLocation(), Sound.valueOf(sound), 1, 1);
}catch(Exception e){
if(Api.getVersion()>=191){
if(Methods.getVersion()>=191){
player.playSound(player.getLocation(), Sound.valueOf("UI_BUTTON_CLICK"), 1, 1);
}else{
player.playSound(player.getLocation(), Sound.valueOf("CLICK"), 1, 1);
@ -954,7 +980,7 @@ public class GUI implements Listener{
}
}
}else{
if(Api.getVersion()>=191){
if(Methods.getVersion()>=191){
player.playSound(player.getLocation(), Sound.valueOf("UI_BUTTON_CLICK"), 1, 1);
}else{
player.playSound(player.getLocation(), Sound.valueOf("CLICK"), 1, 1);

View File

@ -34,17 +34,17 @@ public class Main extends JavaPlugin implements Listener{
public void onEnable(){
saveDefaultConfig();
settings.setup(this);
Api.hasUpdate();
Methods.hasUpdate();
Bukkit.getServer().getPluginManager().registerEvents(this, this);
Bukkit.getServer().getPluginManager().registerEvents(new GUI(), this);
Api.updateAuction();
Methods.updateAuction();
startCheck();
if (!Vault.setupEconomy()){
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(Methods.getPrefix()+
Methods.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);
}
@ -60,9 +60,9 @@ public class Main extends JavaPlugin implements Listener{
|| commandLable.equalsIgnoreCase("CA") || commandLable.equalsIgnoreCase("AH")
|| commandLable.equalsIgnoreCase("HDV")){
if(args.length == 0){
if(!Api.hasPermission(sender, "Access"))return true;
if(!Methods.hasPermission(sender, "Access"))return true;
if(!(sender instanceof Player)){
sender.sendMessage(Api.getPrefix()+Api.color(settings.getMsg().getString("Messages.Players-Only")));
sender.sendMessage(Methods.getPrefix()+Methods.color(settings.getMsg().getString("Messages.Players-Only")));
return true;
}
Player player = (Player) sender;
@ -77,29 +77,25 @@ public class Main extends JavaPlugin implements Listener{
}
if(args.length >= 1){
if(args[0].equalsIgnoreCase("Help")){// CA Help
if(!Api.hasPermission(sender, "Access"))return true;
sender.sendMessage(Api.color("&e-- &6Crazy Auctions Help &e--"));
sender.sendMessage(Api.color("&9/CA - &eOpens the crazy auction."));
sender.sendMessage(Api.color("&9/CA View <Player> - &eSee what a player is selling."));
sender.sendMessage(Api.color("&9/CA Sell/Bid <Price> [Amount of items] - &eList the item you are holding on the crazy auction."));
sender.sendMessage(Api.color("&9/CA Expired/Collect - &eView and manage your cancelled and expired items."));
sender.sendMessage(Api.color("&9/CA Listed - &eView and manage the items you are selling."));
sender.sendMessage(Api.color("&9/CA Help - &eView this help menu."));
if(!Methods.hasPermission(sender, "Access"))return true;
for(String msg : settings.getMsg().getStringList("Messages.Help-Menu")){
sender.sendMessage(Methods.color(msg));
}
return true;
}
if(args[0].equalsIgnoreCase("Reload")){// CA Reload
if(!Api.hasPermission(sender, "Admin"))return true;
if(!Methods.hasPermission(sender, "Admin"))return true;
settings.reloadConfig();
settings.reloadData();
settings.reloadMsg();
settings.setup(this);
sender.sendMessage(Api.getPrefix()+Api.color(settings.getMsg().getString("Messages.Reload")));
sender.sendMessage(Methods.getPrefix()+Methods.color(settings.getMsg().getString("Messages.Reload")));
return true;
}
if(args[0].equalsIgnoreCase("View")){// CA Reload
if(!Api.hasPermission(sender, "View"))return true;
if(!Methods.hasPermission(sender, "View"))return true;
if(!(sender instanceof Player)){
sender.sendMessage(Api.getPrefix()+Api.color(settings.getMsg().getString("Messages.Players-Only")));
sender.sendMessage(Methods.getPrefix()+Methods.color(settings.getMsg().getString("Messages.Players-Only")));
return true;
}
if(args.length>=2){
@ -107,13 +103,13 @@ public class Main extends JavaPlugin implements Listener{
GUI.openViewer(player, args[1], 1);
return true;
}
sender.sendMessage(Api.getPrefix()+Api.color("&c/CA View <Player>"));
sender.sendMessage(Methods.getPrefix()+Methods.color("&c/CA View <Player>"));
return true;
}
if(args[0].equalsIgnoreCase("Expired")||args[0].equalsIgnoreCase("Collect")){// CA Expired
if(!Api.hasPermission(sender, "Access"))return true;
if(!Methods.hasPermission(sender, "Access"))return true;
if(!(sender instanceof Player)){
sender.sendMessage(Api.getPrefix()+Api.color(settings.getMsg().getString("Messages.Players-Only")));
sender.sendMessage(Methods.getPrefix()+Methods.color(settings.getMsg().getString("Messages.Players-Only")));
return true;
}
Player player = (Player) sender;
@ -121,9 +117,9 @@ public class Main extends JavaPlugin implements Listener{
return true;
}
if(args[0].equalsIgnoreCase("Listed")){// CA Listed
if(!Api.hasPermission(sender, "Access"))return true;
if(!Methods.hasPermission(sender, "Access"))return true;
if(!(sender instanceof Player)){
sender.sendMessage(Api.getPrefix()+Api.color(settings.getMsg().getString("Messages.Players-Only")));
sender.sendMessage(Methods.getPrefix()+Methods.color(settings.getMsg().getString("Messages.Players-Only")));
return true;
}
Player player = (Player) sender;
@ -132,22 +128,22 @@ public class Main extends JavaPlugin implements Listener{
}
if(args[0].equalsIgnoreCase("Sell")||args[0].equalsIgnoreCase("Bid")){// /CA Sell/Bid <Price> [Amount of Items]
if(!(sender instanceof Player)){
sender.sendMessage(Api.getPrefix()+Api.color(settings.getMsg().getString("Messages.Players-Only")));
sender.sendMessage(Methods.getPrefix()+Methods.color(settings.getMsg().getString("Messages.Players-Only")));
return true;
}
if(args.length >= 2){
Player player = (Player) sender;
if(args[0].equalsIgnoreCase("Sell")){
if(!Api.hasPermission(player, "Sell"))return true;
if(!Methods.hasPermission(player, "Sell"))return true;
}
if(args[0].equalsIgnoreCase("Bid")){
if(!Api.hasPermission(player, "Bid"))return true;
if(!Methods.hasPermission(player, "Bid"))return true;
}
ItemStack item = Api.getItemInHand(player);
ItemStack item = Methods.getItemInHand(player);
int amount = item.getAmount();
if(args.length >= 3){
if(!Api.isInt(args[2])){
player.sendMessage(Api.getPrefix()+Api.color(settings.getMsg().getString("Messages.Not-A-Number")
if(!Methods.isInt(args[2])){
player.sendMessage(Methods.getPrefix()+Methods.color(settings.getMsg().getString("Messages.Not-A-Number")
.replaceAll("%Arg%", args[2]).replaceAll("%arg%", args[2])));
return true;
}
@ -155,32 +151,32 @@ public class Main extends JavaPlugin implements Listener{
if(amount<=0)amount=1;
if(amount>item.getAmount())amount=item.getAmount();
}
if(!Api.isLong(args[1])){
player.sendMessage(Api.getPrefix()+Api.color(settings.getMsg().getString("Messages.Not-A-Number")
if(!Methods.isLong(args[1])){
player.sendMessage(Methods.getPrefix()+Methods.color(settings.getMsg().getString("Messages.Not-A-Number")
.replaceAll("%Arg%", args[1]).replaceAll("%arg%", args[1])));
return true;
}
if(Api.getItemInHand(player).getType() == Material.AIR){
player.sendMessage(Api.getPrefix()+Api.color(settings.getMsg().getString("Messages.Doesnt-Have-Item-In-Hand")));
if(Methods.getItemInHand(player).getType() == Material.AIR){
player.sendMessage(Methods.getPrefix()+Methods.color(settings.getMsg().getString("Messages.Doesnt-Have-Item-In-Hand")));
return false;
}
Long price = Long.parseLong(args[1]);
if(args[0].equalsIgnoreCase("Bid")){
if(price<settings.getConfig().getLong("Settings.Minimum-Bid-Price")){
player.sendMessage(Api.getPrefix()+Api.color(settings.getMsg().getString("Messages.Bid-Price-To-Low")));
player.sendMessage(Methods.getPrefix()+Methods.color(settings.getMsg().getString("Messages.Bid-Price-To-Low")));
return true;
}
if(price>settings.getConfig().getLong("Settings.Max-Beginning-Bid-Price")){
player.sendMessage(Api.getPrefix()+Api.color(settings.getMsg().getString("Messages.Bid-Price-To-High")));
player.sendMessage(Methods.getPrefix()+Methods.color(settings.getMsg().getString("Messages.Bid-Price-To-High")));
return true;
}
}else{
if(price<settings.getConfig().getLong("Settings.Minimum-Sell-Price")){
player.sendMessage(Api.getPrefix()+Api.color(settings.getMsg().getString("Messages.Sell-Price-To-Low")));
player.sendMessage(Methods.getPrefix()+Methods.color(settings.getMsg().getString("Messages.Sell-Price-To-Low")));
return true;
}
if(price>settings.getConfig().getLong("Settings.Max-Beginning-Sell-Price")){
player.sendMessage(Api.getPrefix()+Api.color(settings.getMsg().getString("Messages.Sell-Price-To-High")));
player.sendMessage(Methods.getPrefix()+Methods.color(settings.getMsg().getString("Messages.Sell-Price-To-High")));
return true;
}
}
@ -191,7 +187,7 @@ public class Main extends JavaPlugin implements Listener{
String perm = permission.getPermission();
if(perm.startsWith("crazyauctions.sell.")){
perm=perm.replace("crazyauctions.sell.", "");
if(Api.isInt(perm)){
if(Methods.isInt(perm)){
if(Integer.parseInt(perm) > SellLimit){
SellLimit = Integer.parseInt(perm);
}
@ -199,7 +195,7 @@ public class Main extends JavaPlugin implements Listener{
}
if(perm.startsWith("crazyauctions.bid.")){
perm=perm.replace("crazyauctions.bid.", "");
if(Api.isInt(perm)){
if(Methods.isInt(perm)){
if(Integer.parseInt(perm) > BidLimit){
BidLimit = Integer.parseInt(perm);
}
@ -208,20 +204,20 @@ public class Main extends JavaPlugin implements Listener{
}
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")));
player.sendMessage(Methods.getPrefix()+Methods.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")));
player.sendMessage(Methods.getPrefix()+Methods.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()){
player.sendMessage(Api.getPrefix()+Api.color(settings.getMsg().getString("Messages.Item-BlackListed")));
if(item.getType()==Methods.makeItem(id, 1).getType()){
player.sendMessage(Methods.getPrefix()+Methods.color(settings.getMsg().getString("Messages.Item-BlackListed")));
return true;
}
}
@ -229,7 +225,7 @@ public class Main extends JavaPlugin implements Listener{
for(Material i : getDamageableItems()){
if(item.getType()==i){
if(item.getDurability()>0){
player.sendMessage(Api.getPrefix()+Api.color(settings.getMsg().getString("Messages.Item-Damaged")));
player.sendMessage(Methods.getPrefix()+Methods.color(settings.getMsg().getString("Messages.Item-Damaged")));
return true;
}
}
@ -242,11 +238,11 @@ public class Main extends JavaPlugin implements Listener{
settings.getData().set("Items."+num+".Price", price);
settings.getData().set("Items."+num+".Seller", seller);
if(args[0].equalsIgnoreCase("Bid")){
settings.getData().set("Items."+num+".Time-Till-Expire", Api.convertToMill(settings.getConfig().getString("Settings.Bid-Time")));
settings.getData().set("Items."+num+".Time-Till-Expire", Methods.convertToMill(settings.getConfig().getString("Settings.Bid-Time")));
}else{
settings.getData().set("Items."+num+".Time-Till-Expire", Api.convertToMill(settings.getConfig().getString("Settings.Sell-Time")));
settings.getData().set("Items."+num+".Time-Till-Expire", Methods.convertToMill(settings.getConfig().getString("Settings.Sell-Time")));
}
settings.getData().set("Items."+num+".Full-Time", Api.convertToMill(settings.getConfig().getString("Settings.Full-Expire-Time")));
settings.getData().set("Items."+num+".Full-Time", Methods.convertToMill(settings.getConfig().getString("Settings.Full-Expire-Time")));
int id = r.nextInt(999999);
// Runs 3x to check for same ID.
for(String i : settings.getData().getConfigurationSection("Items").getKeys(false))if(settings.getData().getInt("Items."+i+".StoreID")==id)id=r.nextInt(999999);
@ -263,21 +259,21 @@ public class Main extends JavaPlugin implements Listener{
I.setAmount(amount);
settings.getData().set("Items."+num+".Item", I);
settings.saveData();
player.sendMessage(Api.getPrefix()+Api.color(settings.getMsg().getString("Messages.Added-Item-To-Auction")
player.sendMessage(Methods.getPrefix()+Methods.color(settings.getMsg().getString("Messages.Added-Item-To-Auction")
.replaceAll("%Price%", price+"").replaceAll("%price%", price+"")));
if(item.getAmount()<=1||(item.getAmount()-amount)<=0){
Api.setItemInHand(player, new ItemStack(Material.AIR));
Methods.setItemInHand(player, new ItemStack(Material.AIR));
}else{
item.setAmount(item.getAmount()-amount);
}
return false;
}
sender.sendMessage(Api.getPrefix()+Api.color("/CA Sell/Bid <Price> [Amount of items]"));
sender.sendMessage(Methods.getPrefix()+Methods.color("/CA Sell/Bid <Price> [Amount of items]"));
return true;
}
}
}
sender.sendMessage(Api.getPrefix()+Api.color("/CA Help"));
sender.sendMessage(Methods.getPrefix()+Methods.color("/CA Help"));
return false;
}
@ -288,11 +284,11 @@ public class Main extends JavaPlugin implements Listener{
@Override
public void run() {
if(player.getName().equals("BadBones69")){
player.sendMessage(Api.getPrefix()+Api.color("&7This server is running your Crazy Auctions Plugin. "
player.sendMessage(Methods.getPrefix()+Methods.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);
Methods.hasUpdate(player);
}
}
}, 40);
@ -302,7 +298,7 @@ public class Main extends JavaPlugin implements Listener{
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){
@Override
public void run() {
Api.updateAuction();
Methods.updateAuction();
}
}, 20, 5*20);
}

View File

@ -1,15 +1,54 @@
/*
* Copyright 2011-2013 Tyler Blair. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and contributors and should not be interpreted as representing official policies,
* either expressed or implied, of anybody else.
*/
package me.badbones69.crazyauctions;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.scheduler.BukkitTask;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Method;
import java.net.Proxy;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
@ -17,58 +56,29 @@ import java.util.LinkedHashSet;
import java.util.Set;
import java.util.UUID;
import java.util.logging.Level;
import java.util.zip.GZIPOutputStream;
import org.bukkit.Bukkit;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
/**
* <p>
* The metrics class obtains data about a plugin and submits statistics about it to the metrics backend.
* </p>
* <p>
* Public methods provided by this class:
* </p>
* <code>
* Graph createGraph(String name); <br/>
* void addCustomData(Metrics.Plotter plotter); <br/>
* void start(); <br/>
* </code>
*/
public class Metrics {
/**
* The current revision number
*/
private final static int REVISION = 5;
private final static int REVISION = 7;
/**
* The base url of the metrics domain
*/
private static final String BASE_URL = "http://mcstats.org";
private static final String BASE_URL = "http://report.mcstats.org";
/**
* The url used to report a server's status
*/
private static final String REPORT_URL = "/report/%s";
/**
* The file where guid and opt out is stored in
*/
private static final String CONFIG_FILE = "plugins/PluginMetrics/config.yml";
/**
* The separator to use for custom data. This MUST NOT change unless you are hosting your own
* version of metrics and want to change it.
*/
private static final String CUSTOM_DATA_SEPARATOR = "~~";
private static final String REPORT_URL = "/plugin/%s";
/**
* Interval of time to ping (in minutes)
*/
private static final int PING_INTERVAL = 10;
private static final int PING_INTERVAL = 15;
/**
* The plugin this metrics submits for
@ -80,16 +90,11 @@ public class Metrics {
*/
private final Set<Graph> graphs = Collections.synchronizedSet(new HashSet<Graph>());
/**
* The default graph, used for addCustomData when you don't want a specific graph
*/
private final Graph defaultGraph = new Graph("Default");
/**
* The plugin configuration file
*/
private final YamlConfiguration configuration;
/**
* The plugin configuration file
*/
@ -100,15 +105,20 @@ public class Metrics {
*/
private final String guid;
/**
* Debug mode
*/
private final boolean debug;
/**
* Lock for synchronization
*/
private final Object optOutLock = new Object();
/**
* Id of the scheduled task
* The scheduled task
*/
private volatile int taskId = -1;
private volatile BukkitTask task = null;
public Metrics(final Plugin plugin) throws IOException {
if (plugin == null) {
@ -118,12 +128,13 @@ public class Metrics {
this.plugin = plugin;
// load the config
configurationFile = new File(CONFIG_FILE);
configurationFile = getConfigFile();
configuration = YamlConfiguration.loadConfiguration(configurationFile);
// add some defaults
configuration.addDefault("opt-out", false);
configuration.addDefault("guid", UUID.randomUUID().toString());
configuration.addDefault("debug", false);
// Do we need to create the file?
if (configuration.get("guid", null) == null) {
@ -133,13 +144,14 @@ public class Metrics {
// Load the guid then
guid = configuration.getString("guid");
debug = configuration.getBoolean("debug", false);
}
/**
* Construct and create a Graph that can be used to separate specific plotters to their own graphs
* on the metrics website. Plotters can be added to the graph object returned.
* Construct and create a Graph that can be used to separate specific plotters to their own graphs on the metrics
* website. Plotters can be added to the graph object returned.
*
* @param name
* @param name The name of the graph
* @return Graph object created. Will never return NULL under normal circumstances unless bad parameters are given
*/
public Graph createGraph(final String name) {
@ -158,31 +170,26 @@ public class Metrics {
}
/**
* Adds a custom data plotter to the default graph
* Add a Graph object to BukkitMetrics that represents data for the plugin that should be sent to the backend
*
* @param plotter
* @param graph The name of the graph
*/
public void addCustomData(final Plotter plotter) {
if (plotter == null) {
throw new IllegalArgumentException("Plotter cannot be null");
public void addGraph(final Graph graph) {
if (graph == null) {
throw new IllegalArgumentException("Graph cannot be null");
}
// Add the plotter to the graph o/
defaultGraph.addPlotter(plotter);
// Ensure the default graph is included in the submitted graphs
graphs.add(defaultGraph);
graphs.add(graph);
}
/**
* Start measuring statistics. This will immediately create an async repeating task as the plugin and send
* the initial data to the metrics backend, and then after that it will post in increments of
* PING_INTERVAL * 1200 ticks.
* Start measuring statistics. This will immediately create an async repeating task as the plugin and send the
* initial data to the metrics backend, and then after that it will post in increments of PING_INTERVAL * 1200
* ticks.
*
* @return True if statistics measuring is running, otherwise false.
*/
@SuppressWarnings("deprecation")
public boolean start() {
public boolean start() {
synchronized (optOutLock) {
// Did we opt out?
if (isOptOut()) {
@ -190,12 +197,12 @@ public class Metrics {
}
// Is metrics already running?
if (taskId >= 0) {
if (task != null) {
return true;
}
// Begin hitting the server with glorious data
taskId = plugin.getServer().getScheduler().scheduleAsyncRepeatingTask(plugin, new Runnable() {
task = plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, new Runnable() {
private boolean firstPost = true;
@ -204,9 +211,13 @@ public class Metrics {
// This has to be synchronized or it can collide with the disable method.
synchronized (optOutLock) {
// Disable Task, if it is running and the server owner decided to opt-out
if (isOptOut() && taskId > 0) {
plugin.getServer().getScheduler().cancelTask(taskId);
taskId = -1;
if (isOptOut() && task != null) {
task.cancel();
task = null;
// Tell all plotters to stop gathering information.
for (Graph graph : graphs) {
graph.onOptOut();
}
}
}
@ -219,7 +230,9 @@ public class Metrics {
// Each post thereafter will be a ping
firstPost = false;
} catch (IOException e) {
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + e.getMessage());
if (debug) {
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + e.getMessage());
}
}
}
}, 0, PING_INTERVAL * 1200);
@ -231,18 +244,22 @@ public class Metrics {
/**
* Has the server owner denied plugin metrics?
*
* @return
* @return true if metrics should be opted out of it
*/
public boolean isOptOut() {
synchronized(optOutLock) {
synchronized (optOutLock) {
try {
// Reload the metrics file
configuration.load(CONFIG_FILE);
configuration.load(getConfigFile());
} catch (IOException ex) {
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
if (debug) {
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
}
return true;
} catch (InvalidConfigurationException ex) {
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
if (debug) {
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
}
return true;
}
return configuration.getBoolean("opt-out", false);
@ -250,30 +267,30 @@ public class Metrics {
}
/**
* Enables metrics for the server by setting "opt-out" to false in the config file and starting the metrics task.
*
* @throws IOException
*/
* Enables metrics for the server by setting "opt-out" to false in the config file and starting the metrics task.
*
* @throws java.io.IOException
*/
public void enable() throws IOException {
// This has to be synchronized or it can collide with the check in the task.
synchronized (optOutLock) {
// Check if the server owner has already set opt-out, if not, set it.
if (isOptOut()) {
configuration.set("opt-out", false);
configuration.save(configurationFile);
}
// Check if the server owner has already set opt-out, if not, set it.
if (isOptOut()) {
configuration.set("opt-out", false);
configuration.save(configurationFile);
}
// Enable Task, if it is not running
if (taskId < 0) {
start();
}
// Enable Task, if it is not running
if (task == null) {
start();
}
}
}
/**
* Disables metrics for the server by setting "opt-out" to true in the config file and canceling the metrics task.
*
* @throws IOException
* @throws java.io.IOException
*/
public void disable() throws IOException {
// This has to be synchronized or it can collide with the check in the task.
@ -285,59 +302,145 @@ public class Metrics {
}
// Disable Task, if it is running
if (taskId > 0) {
this.plugin.getServer().getScheduler().cancelTask(taskId);
taskId = -1;
if (task != null) {
task.cancel();
task = null;
}
}
}
/**
* Gets the File object of the config file that should be used to store data such as the GUID and opt-out status
*
* @return the File object for the config file
*/
public File getConfigFile() {
// I believe the easiest way to get the base folder (e.g craftbukkit set via -P) for plugins to use
// is to abuse the plugin object we already have
// plugin.getDataFolder() => base/plugins/PluginA/
// pluginsFolder => base/plugins/
// The base is not necessarily relative to the startup directory.
File pluginsFolder = plugin.getDataFolder().getParentFile();
// return => base/plugins/PluginMetrics/config.yml
return new File(new File(pluginsFolder, "PluginMetrics"), "config.yml");
}
/**
* Gets the online player (backwards compatibility)
*
* @return online player amount
*/
private int getOnlinePlayers() {
try {
Method onlinePlayerMethod = Server.class.getMethod("getOnlinePlayers");
if(onlinePlayerMethod.getReturnType().equals(Collection.class)) {
return ((Collection<?>)onlinePlayerMethod.invoke(Bukkit.getServer())).size();
} else {
return ((Player[])onlinePlayerMethod.invoke(Bukkit.getServer())).length;
}
} catch (Exception ex) {
if (debug) {
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
}
}
return 0;
}
/**
* Generic method that posts a plugin to the metrics website
*/
private void postPlugin(final boolean isPing) throws IOException {
// The plugin's description file containg all of the plugin data such as name, version, author, etc
final PluginDescriptionFile description = plugin.getDescription();
// Server software specific section
PluginDescriptionFile description = plugin.getDescription();
String pluginName = description.getName();
boolean onlineMode = Bukkit.getServer().getOnlineMode(); // TRUE if online mode is enabled
String pluginVersion = description.getVersion();
String serverVersion = Bukkit.getVersion();
int playersOnline = this.getOnlinePlayers();
// END server software specific section -- all code below does not use any code outside of this class / Java
// Construct the post data
final StringBuilder data = new StringBuilder();
data.append(encode("guid")).append('=').append(encode(guid));
encodeDataPair(data, "version", description.getVersion());
encodeDataPair(data, "server", Bukkit.getVersion());
encodeDataPair(data, "players", Integer.toString(Bukkit.getServer().getOnlinePlayers().size()));
encodeDataPair(data, "revision", String.valueOf(REVISION));
StringBuilder json = new StringBuilder(1024);
json.append('{');
// The plugin's description file containg all of the plugin data such as name, version, author, etc
appendJSONPair(json, "guid", guid);
appendJSONPair(json, "plugin_version", pluginVersion);
appendJSONPair(json, "server_version", serverVersion);
appendJSONPair(json, "players_online", Integer.toString(playersOnline));
// New data as of R6
String osname = System.getProperty("os.name");
String osarch = System.getProperty("os.arch");
String osversion = System.getProperty("os.version");
String java_version = System.getProperty("java.version");
int coreCount = Runtime.getRuntime().availableProcessors();
// normalize os arch .. amd64 -> x86_64
if (osarch.equals("amd64")) {
osarch = "x86_64";
}
appendJSONPair(json, "osname", osname);
appendJSONPair(json, "osarch", osarch);
appendJSONPair(json, "osversion", osversion);
appendJSONPair(json, "cores", Integer.toString(coreCount));
appendJSONPair(json, "auth_mode", onlineMode ? "1" : "0");
appendJSONPair(json, "java_version", java_version);
// If we're pinging, append it
if (isPing) {
encodeDataPair(data, "ping", "true");
appendJSONPair(json, "ping", "1");
}
// Acquire a lock on the graphs, which lets us make the assumption we also lock everything
// inside of the graph (e.g plotters)
synchronized (graphs) {
final Iterator<Graph> iter = graphs.iterator();
if (graphs.size() > 0) {
synchronized (graphs) {
json.append(',');
json.append('"');
json.append("graphs");
json.append('"');
json.append(':');
json.append('{');
while (iter.hasNext()) {
final Graph graph = iter.next();
boolean firstGraph = true;
for (Plotter plotter : graph.getPlotters()) {
// The key name to send to the metrics server
// The format is C-GRAPHNAME-PLOTTERNAME where separator - is defined at the top
// Legacy (R4) submitters use the format Custom%s, or CustomPLOTTERNAME
final String key = String.format("C%s%s%s%s", CUSTOM_DATA_SEPARATOR, graph.getName(), CUSTOM_DATA_SEPARATOR, plotter.getColumnName());
final Iterator<Graph> iter = graphs.iterator();
// The value to send, which for the foreseeable future is just the string
// value of plotter.getValue()
final String value = Integer.toString(plotter.getValue());
while (iter.hasNext()) {
Graph graph = iter.next();
// Add it to the http post data :)
encodeDataPair(data, key, value);
StringBuilder graphJson = new StringBuilder();
graphJson.append('{');
for (Plotter plotter : graph.getPlotters()) {
appendJSONPair(graphJson, plotter.getColumnName(), Integer.toString(plotter.getValue()));
}
graphJson.append('}');
if (!firstGraph) {
json.append(',');
}
json.append(escapeJSON(graph.getName()));
json.append(':');
json.append(graphJson);
firstGraph = false;
}
json.append('}');
}
}
// close json
json.append('}');
// Create the url
URL url = new URL(BASE_URL + String.format(REPORT_URL, encode(plugin.getDescription().getName())));
URL url = new URL(BASE_URL + String.format(REPORT_URL, urlEncode(pluginName)));
// Connect to the website
URLConnection connection;
@ -350,26 +453,48 @@ public class Metrics {
connection = url.openConnection();
}
byte[] uncompressed = json.toString().getBytes();
byte[] compressed = gzip(json.toString());
// Headers
connection.addRequestProperty("User-Agent", "MCStats/" + REVISION);
connection.addRequestProperty("Content-Type", "application/json");
connection.addRequestProperty("Content-Encoding", "gzip");
connection.addRequestProperty("Content-Length", Integer.toString(compressed.length));
connection.addRequestProperty("Accept", "application/json");
connection.addRequestProperty("Connection", "close");
connection.setDoOutput(true);
if (debug) {
System.out.println("[Metrics] Prepared request for " + pluginName + " uncompressed=" + uncompressed.length + " compressed=" + compressed.length);
}
// Write the data
final OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());
writer.write(data.toString());
writer.flush();
OutputStream os = connection.getOutputStream();
os.write(compressed);
os.flush();
// Now read the response
final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
final String response = reader.readLine();
String response = reader.readLine();
// close resources
writer.close();
os.close();
reader.close();
if (response == null || response.startsWith("ERR")) {
throw new IOException(response); //Throw the exception
if (response == null || response.startsWith("ERR") || response.startsWith("7")) {
if (response == null) {
response = "null";
} else if (response.startsWith("7")) {
response = response.substring(response.startsWith("7,") ? 2 : 1);
}
throw new IOException(response);
} else {
// Is this the first update this hour?
if (response.contains("OK This is your first update this hour")) {
if (response.equals("1") || response.contains("This is your first update this hour")) {
synchronized (graphs) {
final Iterator<Graph> iter = graphs.iterator();
@ -385,10 +510,35 @@ public class Metrics {
}
}
/**
* GZip compress a string of bytes
*
* @param input
* @return
*/
public static byte[] gzip(String input) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream gzos = null;
try {
gzos = new GZIPOutputStream(baos);
gzos.write(input.getBytes("UTF-8"));
} catch (IOException e) {
e.printStackTrace();
} finally {
if (gzos != null) try {
gzos.close();
} catch (IOException ignore) {
}
}
return baos.toByteArray();
}
/**
* Check if mineshafter is present. If it is, we need to bypass it to send POST requests
*
* @return
* @return true if mineshafter is installed on the server
*/
private boolean isMineshafterPresent() {
try {
@ -400,30 +550,92 @@ public class Metrics {
}
/**
* <p>Encode a key/value data pair to be used in a HTTP post request. This INCLUDES a & so the first
* key/value pair MUST be included manually, e.g:</p>
* <code>
* StringBuffer data = new StringBuffer();
* data.append(encode("guid")).append('=').append(encode(guid));
* encodeDataPair(data, "version", description.getVersion());
* </code>
* Appends a json encoded key/value pair to the given string builder.
*
* @param buffer
* @param json
* @param key
* @param value
* @throws UnsupportedEncodingException
*/
private static void appendJSONPair(StringBuilder json, String key, String value) throws UnsupportedEncodingException {
boolean isValueNumeric = false;
try {
if (value.equals("0") || !value.endsWith("0")) {
Double.parseDouble(value);
isValueNumeric = true;
}
} catch (NumberFormatException e) {
isValueNumeric = false;
}
if (json.charAt(json.length() - 1) != '{') {
json.append(',');
}
json.append(escapeJSON(key));
json.append(':');
if (isValueNumeric) {
json.append(value);
} else {
json.append(escapeJSON(value));
}
}
/**
* Escape a string to create a valid JSON string
*
* @param text
* @return
*/
private static void encodeDataPair(final StringBuilder buffer, final String key, final String value) throws UnsupportedEncodingException {
buffer.append('&').append(encode(key)).append('=').append(encode(value));
private static String escapeJSON(String text) {
StringBuilder builder = new StringBuilder();
builder.append('"');
for (int index = 0; index < text.length(); index++) {
char chr = text.charAt(index);
switch (chr) {
case '"':
case '\\':
builder.append('\\');
builder.append(chr);
break;
case '\b':
builder.append("\\b");
break;
case '\t':
builder.append("\\t");
break;
case '\n':
builder.append("\\n");
break;
case '\r':
builder.append("\\r");
break;
default:
if (chr < ' ') {
String t = "000" + Integer.toHexString(chr);
builder.append("\\u" + t.substring(t.length() - 4));
} else {
builder.append(chr);
}
break;
}
}
builder.append('"');
return builder.toString();
}
/**
* Encode text as UTF-8
*
* @param text
* @return
* @param text the text to encode
* @return the encoded text, as UTF-8
*/
private static String encode(final String text) throws UnsupportedEncodingException {
private static String urlEncode(final String text) throws UnsupportedEncodingException {
return URLEncoder.encode(text, "UTF-8");
}
@ -433,8 +645,8 @@ public class Metrics {
public static class Graph {
/**
* The graph's name, alphanumeric and spaces only :)
* If it does not comply to the above when submitted, it is rejected
* The graph's name, alphanumeric and spaces only :) If it does not comply to the above when submitted, it is
* rejected
*/
private final String name;
@ -450,7 +662,7 @@ public class Metrics {
/**
* Gets the graph's name
*
* @return
* @return the Graph's name
*/
public String getName() {
return name;
@ -459,7 +671,7 @@ public class Metrics {
/**
* Add a plotter to the graph, which will be used to plot entries
*
* @param plotter
* @param plotter the plotter to add to the graph
*/
public void addPlotter(final Plotter plotter) {
plotters.add(plotter);
@ -468,7 +680,7 @@ public class Metrics {
/**
* Remove a plotter from the graph
*
* @param plotter
* @param plotter the plotter to remove from the graph
*/
public void removePlotter(final Plotter plotter) {
plotters.remove(plotter);
@ -477,7 +689,7 @@ public class Metrics {
/**
* Gets an <b>unmodifiable</b> set of the plotter objects in the graph
*
* @return
* @return an unmodifiable {@link java.util.Set} of the plotter objects
*/
public Set<Plotter> getPlotters() {
return Collections.unmodifiableSet(plotters);
@ -498,6 +710,11 @@ public class Metrics {
return graph.name.equals(name);
}
/**
* Called when the server owner decides to opt-out of BukkitMetrics while the server is running.
*/
protected void onOptOut() {
}
}
/**
@ -520,16 +737,18 @@ public class Metrics {
/**
* Construct a plotter with a specific plot name
*
* @param name
* @param name the name of the plotter to use, which will show up on the website
*/
public Plotter(final String name) {
this.name = name;
}
/**
* Get the current value for the plotted point
* Get the current value for the plotted point. Since this function defers to an external function it may or may
* not return immediately thus cannot be guaranteed to be thread friendly or safe. This function can be called
* from any thread so care should be taken when accessing resources that need to be synchronized.
*
* @return
* @return the current value for the point to be plotted.
*/
public abstract int getValue();
@ -550,7 +769,7 @@ public class Metrics {
@Override
public int hashCode() {
return getColumnName().hashCode() + getValue();
return getColumnName().hashCode();
}
@Override
@ -562,7 +781,5 @@ public class Metrics {
final Plotter plotter = (Plotter) object;
return plotter.name.equals(name) && plotter.getValue() == getValue();
}
}
}

View File

@ -25,7 +25,7 @@ import org.bukkit.plugin.Plugin;
import me.badbones69.crazyauctions.currency.CM;
public class Api {
public class Methods {
public static Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("CrazyAuctions");
@ -172,7 +172,7 @@ public class Api {
@SuppressWarnings("deprecation")
public static void setItemInHand(Player player, ItemStack item){
if(Api.getVersion()>=191){
if(Methods.getVersion()>=191){
player.getInventory().setItemInMainHand(item);
}else{
player.setItemInHand(item);
@ -399,20 +399,20 @@ public class Api {
if(cal.after(expireTime)){
int num = 1;
for(;data.contains("OutOfTime/Cancelled."+num);num++);
if(data.getBoolean("Items."+i+".Biddable")&&!data.getString("Items."+i+".TopBidder").equalsIgnoreCase("None")&&CM.getMoney(Api.getPlayer(data.getString("Items."+i+".TopBidder")))>=data.getInt("Items."+i+".Price")){
if(data.getBoolean("Items."+i+".Biddable")&&!data.getString("Items."+i+".TopBidder").equalsIgnoreCase("None")&&CM.getMoney(Methods.getPlayer(data.getString("Items."+i+".TopBidder")))>=data.getInt("Items."+i+".Price")){
String winner = data.getString("Items."+i+".TopBidder");
String seller = data.getString("Items."+i+".Seller");
Long price = data.getLong("Items."+i+".Price");
CM.addMoney(Api.getOfflinePlayer(seller), price);
CM.removeMoney(Api.getOfflinePlayer(winner), price);
if(Api.isOnline(winner)){
Player player = Api.getPlayer(winner);
player.sendMessage(Api.getPrefix()+Api.color(msg.getString("Messages.Win-Bidding")
CM.addMoney(Methods.getOfflinePlayer(seller), price);
CM.removeMoney(Methods.getOfflinePlayer(winner), price);
if(Methods.isOnline(winner)){
Player player = Methods.getPlayer(winner);
player.sendMessage(Methods.getPrefix()+Methods.color(msg.getString("Messages.Win-Bidding")
.replaceAll("%Price%", getPrice(i, false)).replaceAll("%price%", getPrice(i, false))));
}
if(Api.isOnline(seller)){
Player player = Api.getPlayer(seller);
player.sendMessage(Api.getPrefix()+Api.color(msg.getString("Messages.Someone-Won-Players-Bid")
if(Methods.isOnline(seller)){
Player player = Methods.getPlayer(seller);
player.sendMessage(Methods.getPrefix()+Methods.color(msg.getString("Messages.Someone-Won-Players-Bid")
.replaceAll("%Price%", getPrice(i, false)).replaceAll("%price%", getPrice(i, false))
.replaceAll("%Player%", winner).replaceAll("%player%", winner)));
}
@ -422,9 +422,9 @@ public class Api {
data.set("OutOfTime/Cancelled."+num+".Item", data.getItemStack("Items."+i+".Item"));
}else{
String seller = data.getString("Items."+i+".Seller");
if(Api.isOnline(seller)){
Player player = Api.getPlayer(seller);
player.sendMessage(Api.getPrefix()+Api.color(msg.getString("Messages.Item-Has-Expired")));
if(Methods.isOnline(seller)){
Player player = Methods.getPlayer(seller);
player.sendMessage(Methods.getPrefix()+Methods.color(msg.getString("Messages.Item-Has-Expired")));
}
data.set("OutOfTime/Cancelled."+num+".Seller", data.getString("Items."+i+".Seller"));
data.set("OutOfTime/Cancelled."+num+".Full-Time", fullExpireTime.getTimeInMillis());