v0.4 Update

Recoded how the Time works. It now doesn’t edit the Data.yml file every
second but uses Milliseconds.
This commit is contained in:
BadBones69 2016-06-10 00:26:37 -04:00
commit dea4391603
14 changed files with 2984 additions and 0 deletions

2
Data.yml Normal file
View File

@ -0,0 +1,2 @@
Items: {}
OutOfTime/Cancelled: {}

31
Messages.yml Normal file
View File

@ -0,0 +1,31 @@
Messages:
Players-Only: '&cOnly players can use this command.'
Reload: '&7You have just reloaded the Crazy Auctions Files.'
Need-More-Money: '&cYou are in need of &a$%Money_Needed%&c.'
Inventory-Full: '&cYour inventory is to full. Please open up some space to buy that.'
No-Permission: '&cYou do not have permission to use that command!'
Not-Online: '&cThat player is not online at this time.'
Doesnt-Have-Item-In-Hand: '&cYou must have an item in your hand.'
Not-A-Number: '&c%Arg% is not a number.'
Got-Item-Back: '&7Your item has been returned.'
Cancelled-Item: '&7You have cancelled an item on the auction list, return your items with /ah expired.'
Item-Has-Expired: '&7An item you have in the Crazy Auctions has just expired.'
Admin-Force-Cancelled: '&7You have just force cancelled a sale.'
Admin-Force-Cancelled-To-Player: '&cOne of your items was just force cancelled by an Admin.'
Item-Doesnt-Exist: '&cThat item isnt in the crazy auctions any more.'
Max-Items: '&cYou cant list any more items to the Crazy Auctions.'
Item-BlackListed: '&cThat item is not allowed to be sold here.'
Item-Damaged: '&cThat item is damaged and is not allowed to be sold here.'
Sold-Msg: '&7Thank you for buying this item.'
Bid-More-Money: '&cYour bid is to low, please bid more.'
Not-A-Currency: '&cThat is not a currency. Please use Money or Tokens.' #Remove Tokens if you do not have TokenManager.
Sell-Price-To-Low: '&cYour sell price is to low the minimum is &a$10&c.'
Sell-Price-To-High: '&cYour sell price is to high the maximum is &a$1000000&c.'
Bid-Price-To-Low: '&cYour starting bid price is to low the minimum is &a$100&c.'
Bid-Price-To-High: '&cYour starting bid price is to high the maximum is &a$1000000&c.'
Bought-Item: '&7You have just bought a item for &a$%Price%&7.'
Win-Bidding: '&7You have just won a bid for &a$%Price%&7. Do /Ah Collect to collect your winnings.'
Player-Bought-Item: '&7%Player% has bought your item for &a$%Price%.'
Someone-Won-Players-Bid: '&7%Player% has won your item you from a bid for &a$%Price%.'
Added-Item-To-Auction: '&7You have just added a item to the crazy auctions for &a$%Price%&7.'
Bid-Msg: '&7You have just bid &a$%Bid% &7on that item.'

269
config.yml Normal file
View File

@ -0,0 +1,269 @@
Settings:
Prefix: '&7[&4Crazy &bAuctions&7]: ' #Prefix of when you get Crazy Auctions Messages.
GUIName: '&4Crazy &bAuctions&8' #Name of the Main GUI.
Players-Current-Items: '&8Your Current Listings' #The Name of the Player Current Items GUI.
Cancelled/Expired-Items: '&8Cancelled/Expired Listings' #Name of the Cancelled/Expired GUI.
Buying-Item: '&8Purchase Item: Are You Sure?' #Name of the Buying GUI.
Bidding-On-Item: '&8You Are Bidding On This Item.' #Name of the Budding GUI.
Categories: '&8Categories' #Name of the Category GUI.
Sell-Time: 2d #The time that each item will sell for.
Bid-Time: 2m 30s #Time for each item that is biddable.
Full-Expire-Time: 10d #The full time the item is in the crazy auctions.
Bid-Winner-Time: 20d #The time the winner of a bid has to claim there prize.
Minimum-Sell-Price: 10 #Minimum amount you can sell a item for.
Max-Beginning-Sell-Price: 1000000 #Max amount you can sell a item for.
Minimum-Bid-Price: 100 #Minimum starting bid.
Max-Beginning-Bid-Price: 1000000 #Maximum starting bid.
Allow-Damaged-Items: False
GUISettings: #Settings for things in the gui.
SellingItemLore: #The lore on items that are being sold.
- '&7-------------------------'
- '&aClick here to purchase.'
- ''
- '&9Price: &e$%Price%'
- '&9Seller: &e%Seller%'
- '&7-------------------------'
CurrentLore: #Lore on items that are in your current items GUI.
- '&7-------------------------'
- '&aClick here to cancel.'
- ''
- '&9Price: &e$%Price%'
- '&9Expire: &e%Time%'
- '&7-------------------------'
Cancelled/ExpiredLore: #Lore on items that are in your cancelled/expired GUI.
- '&7-------------------------'
- '&aClick here to return to you.'
- ''
- '&9Full Expire: &e%Time%'
- '&7-------------------------'
Bidding: #Lore on Bidding Items.
- '&7-------------------------'
- '&aClick here to bid.'
- ''
- '&9Seller: &e%Seller%'
- '&9Current Bid: &e$%TopBid%'
- '&9Top Bidder: &e%TopBidder%'
- '&9Time Left: &e%Time%'
- '&7-------------------------'
Category-Settings:
Armor:
Item: '315'
Slot: 11
Name: '&6&lArmor'
Lore:
- '&7This category contains all'
- '&7armor that is currently being sold.'
Weapons:
Item: '283'
Slot: 12
Name: '&6&lWeapons'
Lore:
- '&7This category contains all'
- '&7weapons that is currently being sold.'
Tools:
Item: '285'
Slot: 13
Name: '&6&lTools'
Lore:
- '&7This category contains all'
- '&7tools that is currently being sold.'
Food:
Item: '322'
Slot: 14
Name: '&6&lFood'
Lore:
- '&7This category contains all'
- '&7food that is currently being sold.'
Potions:
Item: '373:8227'
Slot: 15
Name: '&6&lPotions'
Lore:
- '&7This category contains all'
- '&7potions that is currently being sold.'
Blocks:
Item: '2'
Slot: 16
Name: '&6&lBlocks'
Lore:
- '&7This category contains all'
- '&7blocks that is currently being sold.'
Other:
Item: '371'
Slot: 17
Name: '&6&lOthers'
Lore:
- '&7This category contains all the'
- '&7other items currently being sold.'
None:
Item: '166'
Slot: 23
Name: '&6&lNone'
Lore:
- '&7This category contains all'
- '&7items currently being sold.'
OtherSettings: #Other Settings for the GUIs.
SellingItems: #The button for your current items.
Item: '264' #The item that this button is.
Slot: 46 #The slot it is in. I recommend not changing these. If you do make sure they are still in the bottom row.
Name: '&6Items You are Selling' #Name of the item.
Lore: #Lore of the item.
- '&aClick here to view all the items you'
- '&aare currently selling on the auction.'
Cancelled/ExpiredItems: #The button for Cancelled/Expired Items.
Item: '394'
Slot: 47
Name: '&6Collect Expired / Cancelled Items'
Lore:
- '&aClick here to view and collect all of the'
- '&aitems you have cancelled or has expired.'
PreviousPage: #The button for Previous Page.
Item: '339'
Slot: 49
Name: '&6Previous Page'
Refesh: #The button for Refresh Page.
Item: '175'
Slot: 50
Name: '&6Refresh Page'
NextPage: #The button for Next Page.
Item: '339'
Slot: 51
Name: '&6Next Page'
Category1: #The button for Next Page.
Item: '54'
Slot: 52
Name: '&6Categories'
Lore:
- '&bCurrent Category: &6%Category%'
- '&aWant see items in specific categories?'
- '&aClick here to see all categories of items.'
Category2: #The button for Next Page.
Item: '54'
Slot: 48
Name: '&6Categories'
Lore:
- '&bCurrent Category: &6%Category%'
- '&aWant see items in specific categories?'
- '&aClick here to see all categories of items.'
Bidding/Selling: #Switch between Bidding and Selling.
Selling:
Item: '341'
Slot: 53
Name: '&6Currently looking at items being sold.'
Lore:
- '&7&l(&6&l!&7&l) &7Click here to see items'
- '&7that you can be bidded on.'
Bidding:
Item: '378'
Slot: 53
Name: '&6Currently looking at items that can be bid on.'
Lore:
- '&7&l(&6&l!&7&l) &7Click here to see items'
- '&7that you can buy at a price.'
WhatIsThis: #The info on all the Books buttons.
SellingShop: #The Book in the main shop.
Item: '340'
Slot: 54
Name: '&6What Is This Page?'
Lore:
- '&aThis is the crazy auctions, here you can'
- '&aput items for sale, and buy items'
- '&athat others have put for sale.'
- ''
- '&aThe auction is also a great place to make'
- '&amoney by selling items that others'
- '&amay be interested in buying.'
BiddingShop: #The Book in the main shop.
Item: '340'
Slot: 54
Name: '&6What Is This Page?'
Lore:
- '&aThis is the crazy auctions, here you can'
- '&aput items for sale, and bid on items'
- '&athat others have put for sale.'
- ''
- '&aThe bidding auction is also a great place to'
- '&amake money by bidding off items that others'
- '&amay be interested in bidding on.'
CurrentItems: #The Book in the Current items GUI.
Item: '340'
Slot: 54
Name: '&6What Is This Page?'
Lore:
- '&aThese are your current listings, all of'
- '&athe items you currenty have listed on'
- '&acrazy auctions are displayed here.'
- ''
- '&aYou can cancel and view your listings'
- '&aexpire time here.'
Cancelled/ExpiredItems: #The Book in the Cancelled/Expired Items GUI.
Item: '340'
Slot: 54
Name: '&6What Is This Page?'
Lore:
- '&aThis page houses all of your cancelled and'
- '&aexpired items, when a listings is cancelled'
- '&aor expires you will be able to return that'
- '&aitem back to you from this menu.'
- ''
- '&aJust click on the item and if you have enough'
- '&ainventory space you will receive that item.'
Viewing: #The Book in the Viewing Items GUI.
Item: '340'
Slot: 50
Name: '&6What Is This Page?'
Lore:
- '&aThis page shows all the items that'
- '&aa player has currently on the bidding'
- '&aand selling market. You can quickly see'
- '&awhat a specific player is selling.'
Categories: #The Book in the Viewing Items GUI.
Item: '340'
Slot: 54
Name: '&6What Is This Page?'
Lore:
- '&aThis page shows all the categories'
- '&athat you can choose from. When you click'
- '&aa category it will open the gui with only'
- '&aitems that belong to that category.'
Back: #The Back Buttons.
Item: '339'
Slot: 46
Name: '&6Back'
Return: #The Return Buttons.
Item: '390'
Slot: 50
Name: '&6Return All'
Lore:
- '&aClick here to return all cancelled'
- '&aand expired items to your inventory.'
Confirm: #The Confirm Buttons.
Item: '160:5'
Name: '&aConfirm'
Cancel: #The Cancel Buttons.
Item: '160:14'
Name: '&cCancel'
Your-Item: #The item that shows when you try to buy/bid on your item.
Item: '166'
Name: '&cYou Cant Purchase Your Own Item.'
Cant-Afford: #The item that shows when you cant afford this item.
Item: '166'
Name: '&cYou Cant Afford This Item.'
Top-Bidder: #The item for when a player is already the top bidder.
Item: '166'
Name: '&cYou are already the top bidder.'
Bidding: #The item in the middle when bidding on an item.
Item: '160:15'
Name: '&7Bidding'
Lore:
- '&7<--&aAdd &cRemove&7-->'
- '&9Your Current Bid: &e$%Bid%'
- '&9Current Top Bid: &e$%TopBid%'
Bid: #The button for when you want to confirm your bid.
Item: '160:3'
Name: '&bBid Now'
Lore:
- '&7Click here to Bid Now.'
BlackList:
- '7'
- '120'

11
plugin.yml Normal file
View File

@ -0,0 +1,11 @@
name: CrazyAuctions
author: BadBones69
main: me.BadBones69.CrazyAuctions.Main
website: https://www.spigotmc.org/resources/authors/kicjow.9719/
version: 1.0
description: >
A plugin to auction off items globally.
commands:
CA:
description: Opens the Crazy Auctions GUI.
aliases: [crazyauction, crazyauctions, ah]

View File

@ -0,0 +1,359 @@
package me.BadBones69.CrazyAuctions;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Map;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import me.BadBones69.CrazyAuctions.Currency.CM;
public class Api {
public static String color(String msg){
msg = ChatColor.translateAlternateColorCodes('&', msg);
return msg;
}
public static String removeColor(String msg){
msg = ChatColor.stripColor(msg);
return msg;
}
public static String getPrefix(){
return color(Main.settings.getConfig().getString("Settings.Prefix"));
}
public static ItemStack makeItem(String type, int amount){
int ty = 0;
if(type.contains(":")){
String[] b = type.split(":");
type = b[0];
ty = Integer.parseInt(b[1]);
}
Material m = Material.matchMaterial(type);
ItemStack item = null;
try{
item = new ItemStack(m, amount, (short) ty);
}catch(Exception e){
item = new ItemStack(Material.STAINED_CLAY, 1, (short)14);
}
return item;
}
public static ItemStack makeItem(String type, int amount, String name){
int ty = 0;
if(type.contains(":")){
String[] b = type.split(":");
type = b[0];
ty = Integer.parseInt(b[1]);
}
Material m = Material.matchMaterial(type);
ItemStack item = null;
try{
item = new ItemStack(m, amount, (short) ty);
}catch(Exception e){
item = new ItemStack(Material.STAINED_CLAY, 1, (short)14);
}
ItemMeta me = item.getItemMeta();
me.setDisplayName(color(name));
item.setItemMeta(me);
return item;
}
public static ItemStack makeItem(String type, int amount, String name, List<String> lore){
ArrayList<String> l = new ArrayList<String>();
int ty = 0;
if(type.contains(":")){
String[] b = type.split(":");
type = b[0];
ty = Integer.parseInt(b[1]);
}
Material m = Material.matchMaterial(type);
ItemStack item = null;
try{
item = new ItemStack(m, amount, (short) ty);
}catch(Exception e){
item = new ItemStack(Material.STAINED_CLAY, 1, (short)14);
}
ItemMeta me = item.getItemMeta();
me.setDisplayName(color(name));
for(String L:lore)l.add(color(L));
me.setLore(l);
item.setItemMeta(me);
return item;
}
public static ItemStack makeItem(Material material, int amount, int type, String name){
ItemStack item = new ItemStack(material, amount, (short) type);
ItemMeta m = item.getItemMeta();
m.setDisplayName(color(name));
item.setItemMeta(m);
return item;
}
public static ItemStack makeItem(Material material, int amount, int type, String name, List<String> lore){
ArrayList<String> l = new ArrayList<String>();
ItemStack item = new ItemStack(material, amount, (short) type);
ItemMeta m = item.getItemMeta();
m.setDisplayName(color(name));
for(String L:lore)l.add(color(L));
m.setLore(l);
item.setItemMeta(m);
return item;
}
public static ItemStack makeItem(Material material, int amount, int type, String name, List<String> lore, Map<Enchantment, Integer> enchants){
ItemStack item = new ItemStack(material, amount, (short) type);
ItemMeta m = item.getItemMeta();
m.setDisplayName(name);
m.setLore(lore);
item.setItemMeta(m);
item.addUnsafeEnchantments(enchants);
return item;
}
public static ItemStack addLore(ItemStack item, String i){
ArrayList<String> lore = new ArrayList<String>();
ItemMeta m = item.getItemMeta();
if(item.getItemMeta().hasLore()){
lore.addAll(item.getItemMeta().getLore());
}
lore.add(i);
m.setLore(lore);
item.setItemMeta(m);
return item;
}
public static ItemStack addLore(ItemStack item, List<String> list){
ArrayList<String> lore = new ArrayList<String>();
ItemMeta m = item.getItemMeta();
if(item.getItemMeta().hasLore())lore.addAll(item.getItemMeta().getLore());
for(String i : list)lore.add(color(i));
m.setLore(lore);
item.setItemMeta(m);
return item;
}
public static Integer getVersion(){
String ver = Bukkit.getServer().getClass().getPackage().getName();
ver = ver.substring(ver.lastIndexOf('.')+1);
ver=ver.replaceAll("_", "").replaceAll("R", "").replaceAll("v", "");
return Integer.parseInt(ver);
}
@SuppressWarnings("deprecation")
public static ItemStack getItemInHand(Player player){
if(getVersion()>=191){
return player.getInventory().getItemInMainHand();
}else{
return player.getItemInHand();
}
}
@SuppressWarnings("deprecation")
public static void setItemInHand(Player player, ItemStack item){
if(Api.getVersion()>=191){
player.getInventory().setItemInMainHand(item);
}else{
player.setItemInHand(item);
}
}
public static boolean isInt(String s) {
try {
Integer.parseInt(s);
} catch (NumberFormatException nfe) {
return false;
}
return true;
}
public static Player getPlayer(String name){
return Bukkit.getServer().getPlayer(name);
}
@SuppressWarnings("deprecation")
public static OfflinePlayer getOfflinePlayer(String name){
return Bukkit.getServer().getOfflinePlayer(name);
}
public static Location getLoc(Player player){
return player.getLocation();
}
public static void runCMD(Player player, String CMD){
player.performCommand(CMD);
}
public static boolean isOnline(String name){
for(Player player : Bukkit.getServer().getOnlinePlayers()){
if(player.getName().equalsIgnoreCase(name)){
return true;
}
}
return false;
}
public static boolean isOnline(String name, CommandSender p){
for(Player player : Bukkit.getServer().getOnlinePlayers()){
if(player.getName().equalsIgnoreCase(name)){
return true;
}
}
p.sendMessage(color(Main.settings.getMsg().getString("Messages.Not-Online")));
return false;
}
public static boolean hasPermission(Player player, String perm){
if(!player.hasPermission("CrazyAuctions." + perm)){
player.sendMessage(color(Main.settings.getMsg().getString("Messages.No-Permission")));
return false;
}
return true;
}
public static boolean hasPermission(CommandSender sender, String perm){
if(sender instanceof Player){
Player player = (Player) sender;
if(!player.hasPermission("CrazyAuctions." + perm)){
player.sendMessage(color(Main.settings.getConfig().getString("Messages.No-Permission")));
return false;
}else{
return true;
}
}else{
return true;
}
}
public static List<ItemStack> getPage(List<ItemStack> list, Integer page){
List<ItemStack> items = new ArrayList<ItemStack>();
if(page<=0)page=1;
int max=45;
int index = page*max-max;
int endIndex=index>=list.size() ? list.size()-1 : index+max;
for (; index<endIndex;index++){
if(index<list.size())items.add(list.get(index));
}
for(;items.size()==0;page--){
if(page<=0)break;
index = page*max-max;
endIndex=index>=list.size() ? list.size()-1 : index+max;
for (; index<endIndex;index++){
if(index<list.size())items.add(list.get(index));
}
}
return items;
}
public static List<Integer> getPageInts(List<Integer> list, Integer page){
List<Integer> items = new ArrayList<Integer>();
if(page<=0)page=1;
int max=45;
int index = page*max-max;
int endIndex=index>=list.size() ? list.size()-1 : index+max;
for (; index<endIndex;index++){
if(index<list.size())items.add(list.get(index));
}
for(;items.size()==0;page--){
if(page<=0)break;
index = page*max-max;
endIndex=index>=list.size() ? list.size()-1 : index+max;
for (; index<endIndex;index++){
if(index<list.size())items.add(list.get(index));
}
}
return items;
}
public static int getMaxPage(List<ItemStack> list){
int maxPage = 1;
int amount = list.size();
for(;amount>45;amount-=45,maxPage++);
return maxPage;
}
public static String convertToTime(long time){
Calendar C = Calendar.getInstance();
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(time);
int total = ((int) (cal.getTimeInMillis()/1000)-(int) (C.getTimeInMillis()/1000));
int D = 0;
int H = 0;
int M = 0;
int S = 0;
for(;total>86400;total-=86400,D++);
for(;total>3600;total-=3600,H++);
for(;total>60;total-=60,M++);
S+=total;
return D+"d "+H+"h "+M+"m "+S+"s ";
}
public static long convertToMill(String time){
Calendar cal = Calendar.getInstance();
for(String i : time.split(" ")){
if(i.contains("D")||i.contains("d")){
cal.add(Calendar.DATE, Integer.parseInt(i.replaceAll("D", "").replaceAll("d", "")));
}
if(i.contains("H")||i.contains("h")){
cal.add(Calendar.HOUR, Integer.parseInt(i.replaceAll("H", "").replaceAll("h", "")));
}
if(i.contains("M")||i.contains("m")){
cal.add(Calendar.MINUTE, Integer.parseInt(i.replaceAll("M", "").replaceAll("m", "")));
}
if(i.contains("S")||i.contains("s")){
cal.add(Calendar.SECOND, Integer.parseInt(i.replaceAll("S", "").replaceAll("s", "")));
}
}
return cal.getTimeInMillis();
}
public static boolean isInvFull(Player player){
if(player.getInventory().firstEmpty()==-1){
return true;
}
return false;
}
public static void updateAuction(){
FileConfiguration data = Main.settings.getData();
FileConfiguration msg = Main.settings.getMsg();
Calendar cal = Calendar.getInstance();
Calendar expireTime = Calendar.getInstance();
Calendar fullExpireTime = Calendar.getInstance();
if(data.contains("OutOfTime/Cancelled")){
for(String i : data.getConfigurationSection("OutOfTime/Cancelled").getKeys(false)){
fullExpireTime.setTimeInMillis(data.getLong("OutOfTime/Cancelled."+i+".Full-Time"));
if(cal.after(fullExpireTime)){
data.set("OutOfTime/Cancelled."+i, null);
}
}
}
if(data.contains("Items")){
for(String i : data.getConfigurationSection("Items").getKeys(false)){
expireTime.setTimeInMillis(data.getLong("Items."+i+".Time-Till-Expire"));
fullExpireTime.setTimeInMillis(data.getLong("Items."+i+".Full-Time"));
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")){
String winner = data.getString("Items."+i+".TopBidder");
String seller = data.getString("Items."+i+".Seller");
int price = data.getInt("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")
.replaceAll("%Price%", price+"").replaceAll("%price%", price+"")));
}
if(Api.isOnline(seller)){
Player player = Api.getPlayer(seller);
player.sendMessage(Api.getPrefix()+Api.color(msg.getString("Messages.Someone-Won-Players-Bid")
.replaceAll("%Price%", price+"").replaceAll("%price%", price+"")
.replaceAll("%Player%", winner).replaceAll("%player%", winner)));
}
data.set("OutOfTime/Cancelled."+num+".Seller", winner);
data.set("OutOfTime/Cancelled."+num+".Full-Time", fullExpireTime.getTimeInMillis());
data.set("OutOfTime/Cancelled."+num+".StoreID", data.getInt("Items."+i+".StoreID"));
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")));
}
data.set("OutOfTime/Cancelled."+num+".Seller", data.getString("Items."+i+".Seller"));
data.set("OutOfTime/Cancelled."+num+".Full-Time", fullExpireTime.getTimeInMillis());
data.set("OutOfTime/Cancelled."+num+".StoreID", data.getInt("Items."+i+".StoreID"));
data.set("OutOfTime/Cancelled."+num+".Item", data.getItemStack("Items."+i+".Item"));
}
data.set("Items."+i, null);
}
}
}
Main.settings.saveData();
}
}

View File

@ -0,0 +1,137 @@
package me.BadBones69.CrazyAuctions;
import java.util.ArrayList;
import org.bukkit.Material;
public enum Category{
NONE("None", new ArrayList<Material>()), OTHER("Other", getOthers()),
ARMOR("Armor", getArmor()), WEAPONS("Weapons", getWeapons()), TOOLS("Tools", getTools()),
FOOD("Food", getFood()), POTIONS("Potions", getPotions()), BLOCKS("Blocks", getBlocks());
String Name;
ArrayList<Material> Items;
/**
* @param name Name of the Shop Type.
*/
private Category(String name, ArrayList<Material> items){
this.Name=name;
this.Items=items;
}
/**
* @return Returns the type name as a string.
*/
public String getName(){
return Name;
}
/**
* @param name Name of the Type you want.
* @return Returns the Type as a Enum.
*/
public static Category getFromName(String name){
for(Category type : Category.values()){
if(type.getName().equalsIgnoreCase(name)){
return type;
}
}
return null;
}
public ArrayList<Material> getItems(){
return Items;
}
private static ArrayList<Material> getArmor(){
ArrayList<Material> ma = new ArrayList<Material>();
ma.add(Material.DIAMOND_HELMET);
ma.add(Material.DIAMOND_CHESTPLATE);
ma.add(Material.DIAMOND_LEGGINGS);
ma.add(Material.DIAMOND_BOOTS);
ma.add(Material.CHAINMAIL_HELMET);
ma.add(Material.CHAINMAIL_CHESTPLATE);
ma.add(Material.CHAINMAIL_LEGGINGS);
ma.add(Material.CHAINMAIL_BOOTS);
ma.add(Material.GOLD_HELMET);
ma.add(Material.GOLD_CHESTPLATE);
ma.add(Material.GOLD_LEGGINGS);
ma.add(Material.GOLD_BOOTS);
ma.add(Material.IRON_HELMET);
ma.add(Material.IRON_CHESTPLATE);
ma.add(Material.IRON_LEGGINGS);
ma.add(Material.IRON_BOOTS);
ma.add(Material.DIAMOND_HELMET);
ma.add(Material.DIAMOND_CHESTPLATE);
ma.add(Material.DIAMOND_LEGGINGS);
ma.add(Material.DIAMOND_BOOTS);
return ma;
}
private static ArrayList<Material> getTools(){
ArrayList<Material> ma = new ArrayList<Material>();
ma.add(Material.WOOD_PICKAXE);
ma.add(Material.STONE_PICKAXE);
ma.add(Material.IRON_PICKAXE);
ma.add(Material.DIAMOND_PICKAXE);
ma.add(Material.WOOD_AXE);
ma.add(Material.STONE_AXE);
ma.add(Material.IRON_AXE);
ma.add(Material.DIAMOND_AXE);
ma.add(Material.WOOD_SPADE);
ma.add(Material.STONE_SPADE);
ma.add(Material.IRON_SPADE);
ma.add(Material.DIAMOND_SPADE);
ma.add(Material.WOOD_HOE);
ma.add(Material.STONE_HOE);
ma.add(Material.IRON_HOE);
ma.add(Material.DIAMOND_HOE);
return ma;
}
private static ArrayList<Material> getWeapons(){
ArrayList<Material> ma = new ArrayList<Material>();
ma.add(Material.WOOD_SWORD);
ma.add(Material.STONE_SWORD);
ma.add(Material.IRON_SWORD);
ma.add(Material.DIAMOND_SWORD);
ma.add(Material.WOOD_AXE);
ma.add(Material.STONE_AXE);
ma.add(Material.IRON_AXE);
ma.add(Material.DIAMOND_AXE);
ma.add(Material.BOW);
return ma;
}
private static ArrayList<Material> getFood(){
ArrayList<Material> ma = new ArrayList<Material>();
for(Material m : Material.values()){
if(m.isEdible()){
if(m!=Material.POTION)ma.add(m);
}
}
return ma;
}
private static ArrayList<Material> getPotions(){
ArrayList<Material> ma = new ArrayList<Material>();
ma.add(Material.POTION);
return ma;
}
private static ArrayList<Material> getBlocks(){
ArrayList<Material> ma = new ArrayList<Material>();
for(Material m : Material.values()){
if(m.isBlock()){
ma.add(m);
}
}
return ma;
}
private static ArrayList<Material> getOthers(){
ArrayList<Material> ma = new ArrayList<Material>();
for(Material m : Material.values()){
if(!(getArmor().contains(m)||getTools().contains(m)||getWeapons().contains(m)||
getFood().contains(m)||getPotions().contains(m)||getBlocks().contains(m))){
ma.add(m);
}
}
return ma;
}
}

View File

@ -0,0 +1,45 @@
package me.BadBones69.CrazyAuctions;
import java.util.ArrayList;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public class CrazyAuctions {
static CrazyAuctions instance = new CrazyAuctions();
public static CrazyAuctions getInstance() {
return instance;
}
public ArrayList<ItemStack> getItems(Player player){
FileConfiguration data = Main.settings.getData();
ArrayList<ItemStack> items = new ArrayList<ItemStack>();
if(data.contains("Items")){
for(String i : data.getConfigurationSection("Items").getKeys(false)){
items.add(data.getItemStack("Items."+i+".Item").clone());
}
}
return items;
}
public ArrayList<ItemStack> getItems(Player player, Shop type){
FileConfiguration data = Main.settings.getData();
ArrayList<ItemStack> items = new ArrayList<ItemStack>();
if(data.contains("Items")){
for(String i : data.getConfigurationSection("Items").getKeys(false)){
if(data.getBoolean("Items."+i+".Biddable")){
if(type==Shop.BID){
items.add(data.getItemStack("Items."+i+".Item").clone());
}
}else{
if(type==Shop.SELL){
items.add(data.getItemStack("Items."+i+".Item").clone());
}
}
}
}
return items;
}
}

View File

@ -0,0 +1,129 @@
package me.BadBones69.CrazyAuctions.Currency;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import me.BadBones69.CrazyAuctions.Main;
public enum CM { // Currency Manager
VAULT("Vault", "Money");
String PluginName, Name;
/**
* @param pluginname
* Name of the Plugin.
* @param name
* Name of the Currency.
*/
private CM(String pluginname, String name) {
this.PluginName = pluginname;
this.Name = name;
}
/**
* @return Returns the Currency name as a string.
*/
public String getName() {
return Name;
}
/**
* @return Returns the Currency name as a string.
*/
public String getPluginName() {
return PluginName;
}
/**
* @param name
* Name of the Type you want.
* @return Returns the Currency as a Enum.
*/
public static CM getFromName(String name) {
for (CM type : CM.values()) {
if (type.getPluginName().equalsIgnoreCase(name)) {
return type;
}
}
return null;
}
/**
*
* @return Returns true if the server has the plugin.
*/
public Boolean hasPlugin() {
if (Bukkit.getServer().getPluginManager().getPlugin(PluginName) != null) {
if (Main.settings.getConfig().getBoolean("Settings.Currencies." + PluginName + ".Enabled")) {
return true;
}
}
return false;
}
/**
*
* @param player
* Player you want the currency from.
* @param type
* Type of currency you want to get.
* @return Returns the amount they have of the currency
*/
public static int getMoney(Player player) {
return Vault.getMoney(player);
}
/**
*
* @param player
* Player you want the currency from.
* @param type
* Type of currency you want to take from.
* @param amount
* The amount you want to take.
*/
public static void removeMoney(Player player, Integer amount) {
Vault.removeMoney(player, amount);
}
/**
*
* @param player
* Player you want the currency from.
* @param type
* Type of currency you want to take from.
* @param amount
* The amount you want to take.
*/
public static void removeMoney(OfflinePlayer player, Integer amount) {
Vault.removeMoney(player, amount);
}
/**
*
* @param player
* Player you want the currency from.
* @param type
* Type of currency you want to add to.
* @param amount
* The amount you want to add.
*/
public static void addMoney(Player player, Integer amount) {
Vault.addMoney(player, amount);
}
/**
*
* @param player
* Player you want the currency from.
* @param type
* Type of currency you want to add to.
* @param amount
* The amount you want to add.
*/
public static void addMoney(OfflinePlayer player, Integer amount) {
Vault.addMoney(player, amount);
}
}

View File

@ -0,0 +1,46 @@
package me.BadBones69.CrazyAuctions.Currency;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.plugin.RegisteredServiceProvider;
import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.economy.EconomyResponse;
public class Vault {
public static Economy econ = null;
public static EconomyResponse r;
public static boolean hasVault(){
if(Bukkit.getServer().getPluginManager().getPlugin("Vault")!=null){
return true;
}
return false;
}
public static boolean setupEconomy(){
if (Bukkit.getServer().getPluginManager().getPlugin("Vault") == null){
return false;
}
RegisteredServiceProvider<Economy> rsp = Bukkit.getServer().getServicesManager().getRegistration(Economy.class);
if (rsp == null){
return false;
}
econ = rsp.getProvider();
return econ != null;
}
public static Integer getMoney(Player player){
return (int) econ.getBalance(player);
}
public static void removeMoney(Player player, int amount){
econ.withdrawPlayer(player, amount);
}
public static void removeMoney(OfflinePlayer player, int amount){
econ.withdrawPlayer(player, amount);
}
public static void addMoney(Player player, int amount){
econ.depositPlayer(player, amount);
}
public static void addMoney(OfflinePlayer player, int amount){
econ.depositPlayer(player, amount);
}
}

View File

@ -0,0 +1,878 @@
package me.BadBones69.CrazyAuctions;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryAction;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin;
import me.BadBones69.CrazyAuctions.Currency.CM;
public class GUI implements Listener{
private static HashMap<Player, Integer> Bidding = new HashMap<Player, Integer>();
private static HashMap<Player, String> BiddingID = new HashMap<Player, String>();
private static HashMap<Player, Shop> Type = new HashMap<Player, Shop>(); // Shop Type
private static HashMap<Player, Category> Cat = new HashMap<Player, Category>(); // Category Type
private static HashMap<Player, List<Integer>> List = new HashMap<Player, List<Integer>>();
private static HashMap<Player, String> IDs = new HashMap<Player, String>();
public static Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("CrazyAuctions");
@SuppressWarnings("static-access")
public GUI(Plugin plugin){
this.plugin = plugin;
}
public static void openShop(Player player, Shop sell, Category cat, int page){
Api.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>();
if(!data.contains("Items")){
data.set("Items.Clear", null);
Main.settings.saveData();
}
Cat.put(player, cat);
if(data.contains("Items")){
for(String i : data.getConfigurationSection("Items").getKeys(false)){
List<String> lore = new ArrayList<String>();
if(cat.getItems().contains(data.getItemStack("Items."+i+".Item").getType())||cat==Category.NONE){
if(data.getBoolean("Items."+i+".Biddable")){
if(sell==Shop.BID){
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%", data.getInt("Items."+i+".Price")+"").replaceAll("%topbid%", data.getInt("Items."+i+".Price")+"")
.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"))));
}
items.add(Api.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%", data.getString("Items."+i+".Price")).replaceAll("%price%", data.getString("Items."+i+".Price"))
.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));
ID.add(data.getInt("Items."+i+".StoreID"));
}
}
}
}
}
int maxPage = Api.getMaxPage(items);
for(;page>maxPage;page--);
Inventory inv = Bukkit.createInventory(null, 54, Api.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");
options.add("Category1");options.add("Category2");
if(sell==Shop.SELL){
Type.put(player, Shop.SELL);
options.add("Bidding/Selling.Selling");
options.add("WhatIsThis.SellingShop");
}
if(sell==Shop.BID){
Type.put(player, Shop.BID);
options.add("Bidding/Selling.Bidding");
options.add("WhatIsThis.BiddingShop");
}
for(String o : options){
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");
if(config.contains("Settings.GUISettings.OtherSettings."+o+".Lore")){
for(String l : config.getStringList("Settings.GUISettings.OtherSettings."+o+".Lore")){
lore.add(l.replaceAll("%Category%", Cat.get(player).getName()).replaceAll("%category%", Cat.get(player).getName()));
}
inv.setItem(slot-1, Api.makeItem(id, 1, name, lore));
}else{
inv.setItem(slot-1, Api.makeItem(id, 1, name));
}
}
for(ItemStack item : Api.getPage(items, page)){
int slot = inv.firstEmpty();
inv.setItem(slot, item);
}
for(int id : Api.getPageInts(ID, page)){
Id.add(id);
}
List.put(player, Id);
player.openInventory(inv);
}
public static void openCateories(Player player){
Api.updateAuction();
FileConfiguration config = Main.settings.getConfig();
Inventory inv = Bukkit.createInventory(null, 54, Api.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");
options.add("Category-Settings.Tools");options.add("Category-Settings.Food");
options.add("Category-Settings.Potions");options.add("Category-Settings.Blocks");
options.add("Category-Settings.Other");options.add("Category-Settings.None");
for(String o : options){
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")));
}else{
inv.setItem(slot-1, Api.makeItem(id, 1, name));
}
}
player.openInventory(inv);
}
public static void openPlayersCurrentList(Player player, int page){
Api.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")));
List<String> options = new ArrayList<String>();
options.add("Back");options.add("WhatIsThis.CurrentItems");
for(String o : options){
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")));
}else{
inv.setItem(slot-1, Api.makeItem(id, 1, name));
}
}
if(data.contains("Items")){
for(String i : data.getConfigurationSection("Items").getKeys(false)){
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%", data.getString("Items."+i+".Price")).replaceAll("%price%", data.getString("Items."+i+".Price"))
.replaceAll("%Time%", Api.convertToTime(data.getLong("Items."+i+".Time-Till-Expire"))).replaceAll("%time%", Api.convertToTime(data.getLong("Items."+i+".Time-Till-Expire"))));
}
items.add(Api.addLore(data.getItemStack("Items."+i+".Item").clone(), lore));
ID.add(data.getInt("Items."+i+".StoreID"));
}
}
}
for(ItemStack item : Api.getPage(items, page)){
int slot = inv.firstEmpty();
inv.setItem(slot, item);
}
for(int id : Api.getPageInts(ID, page)){
Id.add(id);
}
List.put(player, Id);
player.openInventory(inv);
}
public static void openPlayersExpiredList(Player player, int page){
Api.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>();
if(data.contains("OutOfTime/Cancelled")){
for(String i : data.getConfigurationSection("OutOfTime/Cancelled").getKeys(false)){
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%", data.getString("OutOfTime/Cancelled."+i+".Price")).replaceAll("%price%", data.getString("OutOfTime/Cancelled."+i+".Price"))
.replaceAll("%Time%", Api.convertToTime(data.getLong("OutOfTime/Cancelled."+i+".Full-Time"))).replaceAll("%time%", Api.convertToTime(data.getLong("OutOfTime/Cancelled."+i+".Full-Time"))));
}
items.add(Api.addLore(data.getItemStack("OutOfTime/Cancelled."+i+".Item").clone(), lore));
ID.add(data.getInt("OutOfTime/Cancelled."+i+".StoreID"));
}
}
}
int maxPage = Api.getMaxPage(items);
for(;page>maxPage;page--);
Inventory inv = Bukkit.createInventory(null, 54, Api.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){
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")));
}else{
inv.setItem(slot-1, Api.makeItem(id, 1, name));
}
}
for(ItemStack item : Api.getPage(items, page)){
int slot = inv.firstEmpty();
inv.setItem(slot, item);
}
for(int id : Api.getPageInts(ID, page)){
Id.add(id);
}
List.put(player, Id);
player.openInventory(inv);
}
public static void openBuying(Player player, String ID){
Api.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")));
return;
}
Inventory inv = Bukkit.createInventory(null, 9, Api.color(config.getString("Settings.Buying-Item")));
List<String> options = new ArrayList<String>();
options.add("Confirm");options.add("Cancel");
for(String o : options){
String id = config.getString("Settings.GUISettings.OtherSettings."+o+".Item");
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"));
}else{
item = Api.makeItem(id, 1, name);
}
if(o.equals("Confirm")){
inv.setItem(0, item);
inv.setItem(1, item);
inv.setItem(2, item);
inv.setItem(3, item);
}
if(o.equals("Cancel")){
inv.setItem(5, item);
inv.setItem(6, item);
inv.setItem(7, item);
inv.setItem(8, item);
}
}
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%", data.getString("Items."+ID+".Price")).replaceAll("%price%", data.getString("Items."+ID+".Price"))
.replaceAll("%Seller%", data.getString("Items."+ID+".Seller")).replaceAll("%seller%", data.getString("Items."+ID+".Seller")));
}
inv.setItem(4, Api.addLore(item.clone(), lore));
IDs.put(player, ID);
player.openInventory(inv);
}
public static void openBidding(Player player, String ID){
Api.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")));
return;
}
Inventory inv = Bukkit.createInventory(null, 27, Api.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(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"),
config.getStringList("Settings.GUISettings.OtherSettings.Bid.Lore")));
inv.setItem(4, getBiddingItem(player, ID));
player.openInventory(inv);
}
public static void openViewer(Player player, String other, int page){
Api.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>();
if(!data.contains("Items")){
data.set("Items.Clear", null);
Main.settings.saveData();
}
if(data.contains("Items")){
for(String i : data.getConfigurationSection("Items").getKeys(false)){
if(data.getString("Items."+i+".Seller").equalsIgnoreCase(other)){
List<String> lore = new ArrayList<String>();
if(data.getBoolean("Items."+i+".Biddable")){
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%", data.getInt("Items."+i+".Price")+"").replaceAll("%topbid%", data.getInt("Items."+i+".Price")+"")
.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"))));
}
items.add(Api.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%", data.getString("Items."+i+".Price")).replaceAll("%price%", data.getString("Items."+i+".Price"))
.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));
ID.add(data.getInt("Items."+i+".StoreID"));
}
}
}
}
int maxPage = Api.getMaxPage(items);
for(;page>maxPage;page--);
Inventory inv = Bukkit.createInventory(null, 54, Api.color(config.getString("Settings.GUIName")+" #"+page));
List<String> options = new ArrayList<String>();
options.add("WhatIsThis.Viewing");
for(String o : options){
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")));
}else{
inv.setItem(slot-1, Api.makeItem(id, 1, name));
}
}
for(ItemStack item : Api.getPage(items, page)){
int slot = inv.firstEmpty();
inv.setItem(slot, item);
}
for(int id : Api.getPageInts(ID, page)){
Id.add(id);
}
List.put(player, Id);
player.openInventory(inv);
}
public static ItemStack getBiddingGlass(Player player, String ID){
FileConfiguration config = Main.settings.getConfig();
FileConfiguration data = Main.settings.getData();
String id = config.getString("Settings.GUISettings.OtherSettings.Bidding.Item");
String name = config.getString("Settings.GUISettings.OtherSettings.Bidding.Name");
ItemStack item = new ItemStack(Material.AIR);
int bid = Bidding.get(player);
int topbid = data.getInt("Items."+ID+".Price");
if(config.contains("Settings.GUISettings.OtherSettings.Bidding.Lore")){
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%", topbid+"").replaceAll("%topbid%", topbid+""));
}
item = Api.makeItem(id, 1, name, lore);
}else{
item = Api.makeItem(id, 1, name);
}
return item;
}
public static ItemStack getBiddingItem(Player player, String ID){
FileConfiguration config = Main.settings.getConfig();
FileConfiguration data = Main.settings.getData();
String seller = data.getString("Items."+ID+".Seller");
String topbidder = data.getString("Items."+ID+".TopBidder");
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%", data.getInt("Items."+ID+".Price")+"").replaceAll("%topbid%", data.getInt("Items."+ID+".Price")+"")
.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"))));
}
return Api.addLore(item.clone(), lore);
}
@EventHandler
public void onInvClose(InventoryCloseEvent e){
FileConfiguration config = Main.settings.getConfig();
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(Bidding.containsKey(player)){
Bidding.remove(player);
}
}
}
}
@EventHandler
public void onInvClick(InventoryClickEvent e){
FileConfiguration config = Main.settings.getConfig();
FileConfiguration data = Main.settings.getData();
FileConfiguration msg = Main.settings.getMsg();
Player player = (Player)e.getWhoClicked();
final Inventory inv = e.getInventory();
if(inv!=null){
if(inv.getName().contains(Api.color(config.getString("Settings.Categories")))){
e.setCancelled(true);
int slot = e.getRawSlot();
if(slot<=inv.getSize()){
if(e.getCurrentItem()!=null){
ItemStack item = e.getCurrentItem();
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")))){
openShop(player, Type.get(player), cat, 1);
return;
}
if(item.getItemMeta().getDisplayName().equals(Api.color(config.getString("Settings.GUISettings.OtherSettings.Back.Name")))){
openShop(player, Type.get(player), Cat.get(player), 1);
return;
}
}
}
}
}
}
}
if(inv.getName().contains(Api.color(config.getString("Settings.Bidding-On-Item")))){
e.setCancelled(true);
int slot = e.getRawSlot();
if(slot<=inv.getSize()){
if(e.getCurrentItem()!=null){
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")))){
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")
.replaceAll("%Money_Needed%", (bid-CM.getMoney(player))+"").replaceAll("%money_needed%", (bid-CM.getMoney(player))+"")));
return;
}
if(data.getInt("Items."+ID+".Price")>bid){
player.sendMessage(Api.getPrefix()+Api.color(msg.getString("Messages.Bid-More-Money")));
return;
}
if(data.getInt("Items."+ID+".Price")>=bid&&!topBidder.equalsIgnoreCase("None")){
player.sendMessage(Api.getPrefix()+Api.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")
.replaceAll("%Bid%", bid+"").replaceAll("%bid%", bid+"")));
Main.settings.saveData();
Bidding.put(player, 0);
player.closeInventory();
return;
}
if(item.getItemMeta().getDisplayName().equals(Api.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)));
return;
}
if(item.getItemMeta().getDisplayName().equals(Api.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)));
return;
}
if(item.getItemMeta().getDisplayName().equals(Api.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)));
return;
}
if(item.getItemMeta().getDisplayName().equals(Api.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)));
return;
}
if(item.getItemMeta().getDisplayName().equals(Api.color("&c-1"))){
int bid = Bidding.get(player)-1;
if(bid<0)bid=0;
Bidding.put(player, bid);
inv.setItem(4, getBiddingItem(player, BiddingID.get(player)));
inv.setItem(13, getBiddingGlass(player, BiddingID.get(player)));
return;
}
if(item.getItemMeta().getDisplayName().equals(Api.color("&c-10"))){
int bid = Bidding.get(player)-10;
if(bid<0)bid=0;
Bidding.put(player, bid);
inv.setItem(4, getBiddingItem(player, BiddingID.get(player)));
inv.setItem(13, getBiddingGlass(player, BiddingID.get(player)));
return;
}
if(item.getItemMeta().getDisplayName().equals(Api.color("&c-100"))){
int bid = Bidding.get(player)-100;
if(bid<0)bid=0;
Bidding.put(player, bid);
inv.setItem(4, getBiddingItem(player, BiddingID.get(player)));
inv.setItem(13, getBiddingGlass(player, BiddingID.get(player)));
return;
}
if(item.getItemMeta().getDisplayName().equals(Api.color("&c-1000"))){
int bid = Bidding.get(player)-1000;
if(bid<0)bid=0;
Bidding.put(player, bid);
inv.setItem(4, getBiddingItem(player, BiddingID.get(player)));
inv.setItem(13, getBiddingGlass(player, BiddingID.get(player)));
return;
}
}
}
}
}
}
if(inv.getName().contains(Api.color(config.getString("Settings.GUIName")))){
e.setCancelled(true);
final int slot = e.getRawSlot();
if(slot<=inv.getSize()){
if(e.getCurrentItem()!=null){
final ItemStack item = e.getCurrentItem();
if(item.hasItemMeta()){
if(item.getItemMeta().hasDisplayName()){
if(item.getItemMeta().getDisplayName().equals(Api.color(config.getString("Settings.GUISettings.OtherSettings.NextPage.Name")))){
Api.updateAuction();
int page = Integer.parseInt(inv.getName().split("#")[1]);
openShop(player, Type.get(player), Cat.get(player), page+1);
return;
}
if(item.getItemMeta().getDisplayName().equals(Api.color(config.getString("Settings.GUISettings.OtherSettings.PreviousPage.Name")))){
Api.updateAuction();
int page = Integer.parseInt(inv.getName().split("#")[1]);
if(page==1)page++;
openShop(player, Type.get(player), Cat.get(player), page-1);
return;
}
if(item.getItemMeta().getDisplayName().equals(Api.color(config.getString("Settings.GUISettings.OtherSettings.Refesh.Name")))){
Api.updateAuction();
int page = Integer.parseInt(inv.getName().split("#")[1]);
openShop(player, Type.get(player), Cat.get(player), page);
return;
}
if(item.getItemMeta().getDisplayName().equals(Api.color(config.getString("Settings.GUISettings.OtherSettings.Bidding/Selling.Selling.Name")))){
openShop(player, Shop.BID, Cat.get(player), 1);
return;
}
if(item.getItemMeta().getDisplayName().equals(Api.color(config.getString("Settings.GUISettings.OtherSettings.Bidding/Selling.Bidding.Name")))){
openShop(player, Shop.SELL, Cat.get(player), 1);
return;
}
if(item.getItemMeta().getDisplayName().equals(Api.color(config.getString("Settings.GUISettings.OtherSettings.Cancelled/ExpiredItems.Name")))){
openPlayersExpiredList(player, 1);
return;
}
if(item.getItemMeta().getDisplayName().equals(Api.color(config.getString("Settings.GUISettings.OtherSettings.SellingItems.Name")))){
openPlayersCurrentList(player, 1);
return;
}
if(item.getItemMeta().getDisplayName().equals(Api.color(config.getString("Settings.GUISettings.OtherSettings.Category1.Name")))){
openCateories(player);
return;
}
if(item.getItemMeta().getDisplayName().equals(Api.color(config.getString("Settings.GUISettings.OtherSettings.Category2.Name")))){
openCateories(player);
return;
}
if(item.getItemMeta().getDisplayName().equals(Api.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")))){
return;
}
if(item.getItemMeta().getDisplayName().equals(Api.color(config.getString("Settings.GUISettings.OtherSettings.Top-Bidder.Name")))){
return;
}
}
if(List.get(player).size()>=slot){
int id = List.get(player).get(slot);
boolean T=false;
if(data.contains("Items")){
for(String i : data.getConfigurationSection("Items").getKeys(false)){
int ID = data.getInt("Items."+i+".StoreID");
if(id==ID){
T=true;
if(player.hasPermission("CrazyAuctions.Admin")){
if(e.getAction()==InventoryAction.MOVE_TO_OTHER_INVENTORY){
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")));
}
data.set("OutOfTime/Cancelled."+num+".Seller", data.getString("Items."+i+".Seller"));
data.set("OutOfTime/Cancelled."+num+".Full-Time", data.getLong("Items."+i+".Full-Time"));
data.set("OutOfTime/Cancelled."+num+".StoreID", data.getInt("Items."+i+".StoreID"));
data.set("OutOfTime/Cancelled."+num+".Item", data.getItemStack("Items."+i+".Item"));
data.set("Items."+i, null);
Main.settings.saveData();
player.sendMessage(Api.getPrefix()+Api.color(msg.getString("Messages.Admin-Force-Cancelled")));
int page = Integer.parseInt(inv.getName().split("#")[1]);
openShop(player, Type.get(player), Cat.get(player), page);
return;
}
}
if(data.getString("Items."+i+".Seller").equalsIgnoreCase(player.getName())){
String it = config.getString("Settings.GUISettings.OtherSettings.Your-Item.Item");
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"));
}else{
I = Api.makeItem(it, 1, name);
}
inv.setItem(slot, I);
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){
@Override
public void run() {
inv.setItem(slot, item);
}
}, 3*20);
return;
}
int cost = data.getInt("Items."+i+".Price");
if(CM.getMoney(player)<cost){
String it = config.getString("Settings.GUISettings.OtherSettings.Cant-Afford.Item");
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"));
}else{
I = Api.makeItem(it, 1, name);
}
inv.setItem(slot, I);
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){
@Override
public void run() {
inv.setItem(slot, item);
}
}, 3*20);
return;
}
if(data.getBoolean("Items."+i+".Biddable")){
if(player.getName().equalsIgnoreCase(data.getString("Items."+i+".TopBidder"))){
String it = config.getString("Settings.GUISettings.OtherSettings.Top-Bidder.Item");
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"));
}else{
I = Api.makeItem(it, 1, name);
}
inv.setItem(slot, I);
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){
@Override
public void run() {
inv.setItem(slot, item);
}
}, 3*20);
return;
}
openBidding(player, i);
BiddingID.put(player, i);
}else{
openBuying(player, i);
}
return;
}
}
}
if(!T){
openShop(player, Type.get(player), Cat.get(player), 1);
player.sendMessage(Api.getPrefix()+Api.color(msg.getString("Messages.Item-Doesnt-Exist")));
return;
}
}
}
}
}
}
if(inv.getName().contains(Api.color(config.getString("Settings.Buying-Item")))){
e.setCancelled(true);
int slot = e.getRawSlot();
if(slot<=inv.getSize()){
if(e.getCurrentItem()!=null){
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")))){
String ID = IDs.get(player);
int cost = data.getInt("Items."+ID+".Price");
String seller = data.getString("Items."+ID+".Seller");
if(!data.contains("Items."+ID)){
openShop(player, Type.get(player), Cat.get(player), 1);
player.sendMessage(Api.getPrefix()+Api.color(msg.getString("Messages.Item-Doesnt-Exist")));
return;
}
if(Api.isInvFull(player)){
player.closeInventory();
player.sendMessage(Api.getPrefix()+Api.color(msg.getString("Messages.Inventory-Full")));
return;
}
if(CM.getMoney(player)<cost){
player.closeInventory();
player.sendMessage(Api.getPrefix()+Api.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%", cost+"").replaceAll("%price%", cost+"")));
if(Api.isOnline(seller)){
Player sell = Api.getPlayer(seller);
sell.sendMessage(Api.getPrefix()+Api.color(msg.getString("Messages.Player-Bought-Item")
.replaceAll("%Price%", cost+"").replaceAll("%price%", cost+"")
.replaceAll("%Player%", player.getName()).replaceAll("%player%", player.getName())));
}
ItemStack i = data.getItemStack("Items."+ID+".Item");
player.getInventory().addItem(i);
data.set("Items."+ID, null);
Main.settings.saveData();
openShop(player, Type.get(player), Cat.get(player), 1);
return;
}
if(item.getItemMeta().getDisplayName().equals(Api.color(config.getString("Settings.GUISettings.OtherSettings.Cancel.Name")))){
openShop(player, Type.get(player), Cat.get(player), 1);
return;
}
}
}
}
}
}
if(inv.getName().contains(Api.color(config.getString("Settings.Players-Current-Items")))){
e.setCancelled(true);
int slot = e.getRawSlot();
if(slot<=inv.getSize()){
if(e.getCurrentItem()!=null){
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")))){
openShop(player, Type.get(player), Cat.get(player), 1);
return;
}
}
if(List.get(player).size()>=slot){
int id = List.get(player).get(slot);
boolean T=false;
if(data.contains("Items")){
for(String i : data.getConfigurationSection("Items").getKeys(false)){
int ID = data.getInt("Items."+i+".StoreID");
if(id==ID){
T=true;
player.sendMessage(Api.getPrefix()+Api.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"));
data.set("OutOfTime/Cancelled."+num+".Full-Time", data.getLong("Items."+i+".Full-Time"));
data.set("OutOfTime/Cancelled."+num+".StoreID", data.getInt("Items."+i+".StoreID"));
data.set("OutOfTime/Cancelled."+num+".Item", data.getItemStack("Items."+i+".Item"));
data.set("Items."+i, null);
Main.settings.saveData();
openPlayersCurrentList(player, 1);
return;
}
}
}
if(!T){
openShop(player, Type.get(player), Cat.get(player), 1);
player.sendMessage(Api.getPrefix()+Api.color(msg.getString("Messages.Item-Doesnt-Exist")));
return;
}
}
}
}
}
}
if(inv.getName().contains(Api.color(config.getString("Settings.Cancelled/Expired-Items")))){
e.setCancelled(true);
final int slot = e.getRawSlot();
if(slot<=inv.getSize()){
if(e.getCurrentItem()!=null){
final ItemStack item = e.getCurrentItem();
if(item.hasItemMeta()){
if(item.getItemMeta().hasDisplayName()){
if(item.getItemMeta().getDisplayName().equals(Api.color(config.getString("Settings.GUISettings.OtherSettings.Back.Name")))){
Api.updateAuction();
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();
int page = Integer.parseInt(inv.getName().split("#")[1]);
if(page==1)page++;
openPlayersExpiredList(player, (page-1));
return;
}
if(item.getItemMeta().getDisplayName().equals(Api.color(config.getString("Settings.GUISettings.OtherSettings.Return.Name")))){
Api.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")));
}else{
player.getInventory().addItem(data.getItemStack("OutOfTime/Cancelled."+i+".Item"));
data.set("OutOfTime/Cancelled."+i, null);
}
}
}
}
player.sendMessage(Api.getPrefix()+Api.color(msg.getString("Messages.Got-Item-Back")));
Main.settings.saveData();
openPlayersExpiredList(player, page);
return;
}
if(item.getItemMeta().getDisplayName().equals(Api.color(config.getString("Settings.GUISettings.OtherSettings.NextPage.Name")))){
Api.updateAuction();
int page = Integer.parseInt(inv.getName().split("#")[1]);
openPlayersExpiredList(player, (page+1));
return;
}
}
if(List.get(player).size()>=slot){
int id = List.get(player).get(slot);
boolean T=false;
if(data.contains("OutOfTime/Cancelled")){
for(String i : data.getConfigurationSection("OutOfTime/Cancelled").getKeys(false)){
int ID = data.getInt("OutOfTime/Cancelled."+i+".StoreID");
if(id==ID){
T=true;
player.sendMessage(Api.getPrefix()+Api.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);
Main.settings.saveData();
openPlayersExpiredList(player, 1);
return;
}
}
}
if(!T){
openShop(player, Type.get(player), Cat.get(player), 1);
player.sendMessage(Api.getPrefix()+Api.color(msg.getString("Messages.Item-Doesnt-Exist")));
return;
}
}
}
}
}
}
}
}
}

View File

@ -0,0 +1,332 @@
package me.BadBones69.CrazyAuctions;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Random;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.permissions.PermissionAttachmentInfo;
import org.bukkit.plugin.java.JavaPlugin;
import me.BadBones69.CrazyAuctions.Currency.Vault;
public class Main extends JavaPlugin implements Listener{
public static SettingsManager settings = SettingsManager.getInstance();
public static CrazyAuctions auc = CrazyAuctions.getInstance();
int file = 0;
@Override
public void onDisable(){
Bukkit.getScheduler().cancelTask(file);
settings.saveData();
}
@Override
public void onEnable(){
saveDefaultConfig();
settings.setup(this);
Bukkit.getServer().getPluginManager().registerEvents(this, this);
Bukkit.getServer().getPluginManager().registerEvents(new GUI(this), this);
Api.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."
+ " &cPlease add Vault to continue using this."));
Bukkit.getServer().getPluginManager().disablePlugin(this);
}
try {
Metrics metrics = new Metrics(this); metrics.start();
} catch (IOException e) {
System.out.println("Error Submitting stats!");
}
}
public boolean onCommand(CommandSender sender, Command cmd, String commandLable, String[] args){
if(commandLable.equalsIgnoreCase("CrazyAuctions")||commandLable.equalsIgnoreCase("CrazyAuction")
||commandLable.equalsIgnoreCase("CA")||commandLable.equalsIgnoreCase("AH")){
if(args.length==0){
if(!(sender instanceof Player)){
sender.sendMessage(Api.getPrefix()+Api.color(settings.getMsg().getString("Messages.Players-Only")));
return true;
}
Player player = (Player) sender;
GUI.openShop(player, Shop.SELL, Category.NONE, 1);
return true;
}
if(args.length>=1){
if(args[0].equalsIgnoreCase("Help")){// CA Help
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."));
return true;
}
if(args[0].equalsIgnoreCase("Reload")){// CA Reload
if(!Api.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")));
return true;
}
if(args[0].equalsIgnoreCase("View")){// CA Reload
if(!(sender instanceof Player)){
sender.sendMessage(Api.getPrefix()+Api.color(settings.getMsg().getString("Messages.Players-Only")));
return true;
}
if(args.length>=2){
Player player = (Player) sender;
GUI.openViewer(player, args[1], 1);
return true;
}
sender.sendMessage(Api.getPrefix()+Api.color("&c/CA View <Player>"));
return true;
}
if(args[0].equalsIgnoreCase("Expired")||args[0].equalsIgnoreCase("Collect")){// CA Expired
if(!(sender instanceof Player)){
sender.sendMessage(Api.getPrefix()+Api.color(settings.getMsg().getString("Messages.Players-Only")));
return true;
}
Player player = (Player) sender;
GUI.openPlayersExpiredList(player, 1);
return true;
}
if(args[0].equalsIgnoreCase("Listed")){// CA Listed
if(!(sender instanceof Player)){
sender.sendMessage(Api.getPrefix()+Api.color(settings.getMsg().getString("Messages.Players-Only")));
return true;
}
Player player = (Player) sender;
GUI.openPlayersCurrentList(player, 1);
return true;
}
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")));
return true;
}
if(args.length>=2){
Player player = (Player) sender;
if(args[0].equalsIgnoreCase("Sell")){
if(!Api.hasPermission(player, "Sell"))return true;
}
if(args[0].equalsIgnoreCase("Bid")){
if(!Api.hasPermission(player, "Bid"))return true;
}
ItemStack item = Api.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")
.replaceAll("%Arg%", args[2]).replaceAll("%arg%", args[2])));
return true;
}
amount=Integer.parseInt(args[2]);
if(amount<=0)amount=1;
if(amount>item.getAmount())amount=item.getAmount();
}
if(!Api.isInt(args[1])){
player.sendMessage(Api.getPrefix()+Api.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")));
return false;
}
int price = Integer.parseInt(args[1]);
if(args[0].equalsIgnoreCase("Bid")){
if(price<settings.getConfig().getInt("Settings.Minimum-Bid-Price")){
player.sendMessage(Api.getPrefix()+Api.color(settings.getMsg().getString("Messages.Bid-Price-To-Low")));
return true;
}
if(price>settings.getConfig().getInt("Settings.Max-Beginning-Bid-Price")){
player.sendMessage(Api.getPrefix()+Api.color(settings.getMsg().getString("Messages.Bid-Price-To-High")));
return true;
}
}else{
if(price<settings.getConfig().getInt("Settings.Minimum-Sell-Price")){
player.sendMessage(Api.getPrefix()+Api.color(settings.getMsg().getString("Messages.Sell-Price-To-Low")));
return true;
}
if(price>settings.getConfig().getInt("Settings.Max-Beginning-Sell-Price")){
player.sendMessage(Api.getPrefix()+Api.color(settings.getMsg().getString("Messages.Sell-Price-To-High")));
return true;
}
}
int SellLimit = 1;
int BidLimit = 1;
for(PermissionAttachmentInfo permission : player.getEffectivePermissions()){
String perm = permission.getPermission();
if(perm.startsWith("crazyauctions.sell.")){
perm=perm.replace("crazyauctions.sell.", "");
if(Api.isInt(perm)){
if(Integer.parseInt(perm)>SellLimit){
SellLimit = Integer.parseInt(perm);
}
}
}
if(perm.startsWith("crazyauctions.bid.")){
perm=perm.replace("crazyauctions.bid.", "");
if(Api.isInt(perm)){
if(Integer.parseInt(perm)>SellLimit){
BidLimit = Integer.parseInt(perm);
}
}
}
}
if(auc.getItems(player, Shop.SELL).size()>=SellLimit){
player.sendMessage(Api.getPrefix()+Api.color(settings.getMsg().getString("Messages.Max-Items")));
return true;
}
if(auc.getItems(player, Shop.BID).size()>=BidLimit){
player.sendMessage(Api.getPrefix()+Api.color(settings.getMsg().getString("Messages.Max-Items")));
return true;
}
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")));
return true;
}
}
if(!settings.getConfig().getBoolean("Settings.Allow-Damaged-Items")){
for(Material i : getDamageableItems()){
if(item.getType()==i){
if(item.getDurability()>0){
player.sendMessage(Api.getPrefix()+Api.color(settings.getMsg().getString("Messages.Item-Damaged")));
return true;
}
}
}
}
String seller = player.getName();
int num = 1;
Random r = new Random();
for(;settings.getData().contains("Items."+num);num++);
settings.getData().set("Items."+num+".Price", price);
settings.getData().set("Items."+num+".Seller", seller);
if(args[0].equalsIgnoreCase("Bid")){
settings.getData().set("Items."+num+".Time-Till-Expire", Api.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+".Full-Time", Api.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);
for(String i : settings.getData().getConfigurationSection("Items").getKeys(false))if(settings.getData().getInt("Items."+i+".StoreID")==id)id=r.nextInt(999999);
for(String i : settings.getData().getConfigurationSection("Items").getKeys(false))if(settings.getData().getInt("Items."+i+".StoreID")==id)id=r.nextInt(999999);
settings.getData().set("Items."+num+".StoreID", id);
if(args[0].equalsIgnoreCase("Bid")){
settings.getData().set("Items."+num+".Biddable", true);
}else{
settings.getData().set("Items."+num+".Biddable", false);
}
settings.getData().set("Items."+num+".TopBidder", "None");
ItemStack I = item.clone();
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")
.replaceAll("%Price%", price+"").replaceAll("%price%", price+"")));
if(item.getAmount()<=1||(item.getAmount()-amount)<=0){
Api.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]"));
return true;
}
}
}
sender.sendMessage(Api.getPrefix()+Api.color("/CA Help"));
return false;
}
@EventHandler
public void onJoin(PlayerJoinEvent e){
final Player player = e.getPlayer();
Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
@Override
public void run() {
if(player.getName().equals("BadBones69")){
player.sendMessage(Api.getPrefix()+Api.color("&7This server is running your Crazy Auctions Plugin. "
+ "&7It is running version &av"+Bukkit.getServer().getPluginManager().getPlugin("CrazyAuctions").getDescription().getVersion()+"&7."));
}
}
}, 40);
}
void startCheck(){
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){
@Override
public void run() {
Api.updateAuction();
}
}, 20, 5*20);
}
ArrayList<Material> getDamageableItems(){
ArrayList<Material> ma = new ArrayList<Material>();
ma.add(Material.DIAMOND_HELMET);
ma.add(Material.DIAMOND_CHESTPLATE);
ma.add(Material.DIAMOND_LEGGINGS);
ma.add(Material.DIAMOND_BOOTS);
ma.add(Material.CHAINMAIL_HELMET);
ma.add(Material.CHAINMAIL_CHESTPLATE);
ma.add(Material.CHAINMAIL_LEGGINGS);
ma.add(Material.CHAINMAIL_BOOTS);
ma.add(Material.GOLD_HELMET);
ma.add(Material.GOLD_CHESTPLATE);
ma.add(Material.GOLD_LEGGINGS);
ma.add(Material.GOLD_BOOTS);
ma.add(Material.IRON_HELMET);
ma.add(Material.IRON_CHESTPLATE);
ma.add(Material.IRON_LEGGINGS);
ma.add(Material.IRON_BOOTS);
ma.add(Material.DIAMOND_HELMET);
ma.add(Material.DIAMOND_CHESTPLATE);
ma.add(Material.DIAMOND_LEGGINGS);
ma.add(Material.DIAMOND_BOOTS);
ma.add(Material.BOW);
ma.add(Material.WOOD_SWORD);
ma.add(Material.STONE_SWORD);
ma.add(Material.IRON_SWORD);
ma.add(Material.DIAMOND_SWORD);
ma.add(Material.WOOD_AXE);
ma.add(Material.STONE_AXE);
ma.add(Material.IRON_AXE);
ma.add(Material.DIAMOND_AXE);
ma.add(Material.WOOD_PICKAXE);
ma.add(Material.STONE_PICKAXE);
ma.add(Material.IRON_PICKAXE);
ma.add(Material.DIAMOND_PICKAXE);
ma.add(Material.WOOD_AXE);
ma.add(Material.STONE_AXE);
ma.add(Material.IRON_AXE);
ma.add(Material.DIAMOND_AXE);
ma.add(Material.WOOD_SPADE);
ma.add(Material.STONE_SPADE);
ma.add(Material.IRON_SPADE);
ma.add(Material.DIAMOND_SPADE);
ma.add(Material.WOOD_HOE);
ma.add(Material.STONE_HOE);
ma.add(Material.IRON_HOE);
ma.add(Material.DIAMOND_HOE);
ma.add(Material.FLINT_AND_STEEL);
ma.add(Material.ANVIL);
ma.add(Material.FISHING_ROD);
return ma;
}
}

View File

@ -0,0 +1,568 @@
package me.BadBones69.CrazyAuctions;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.net.Proxy;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.UUID;
import java.util.logging.Level;
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;
/**
* The base url of the metrics domain
*/
private static final String BASE_URL = "http://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 = "~~";
/**
* Interval of time to ping (in minutes)
*/
private static final int PING_INTERVAL = 10;
/**
* The plugin this metrics submits for
*/
private final Plugin plugin;
/**
* All of the custom graphs to submit to 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
*/
private final File configurationFile;
/**
* Unique server id
*/
private final String guid;
/**
* Lock for synchronization
*/
private final Object optOutLock = new Object();
/**
* Id of the scheduled task
*/
private volatile int taskId = -1;
public Metrics(final Plugin plugin) throws IOException {
if (plugin == null) {
throw new IllegalArgumentException("Plugin cannot be null");
}
this.plugin = plugin;
// load the config
configurationFile = new File(CONFIG_FILE);
configuration = YamlConfiguration.loadConfiguration(configurationFile);
// add some defaults
configuration.addDefault("opt-out", false);
configuration.addDefault("guid", UUID.randomUUID().toString());
// Do we need to create the file?
if (configuration.get("guid", null) == null) {
configuration.options().header("http://mcstats.org").copyDefaults(true);
configuration.save(configurationFile);
}
// Load the guid then
guid = configuration.getString("guid");
}
/**
* 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
* @return Graph object created. Will never return NULL under normal circumstances unless bad parameters are given
*/
public Graph createGraph(final String name) {
if (name == null) {
throw new IllegalArgumentException("Graph name cannot be null");
}
// Construct the graph object
final Graph graph = new Graph(name);
// Now we can add our graph
graphs.add(graph);
// and return back
return graph;
}
/**
* Adds a custom data plotter to the default graph
*
* @param plotter
*/
public void addCustomData(final Plotter plotter) {
if (plotter == null) {
throw new IllegalArgumentException("Plotter 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);
}
/**
* 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() {
synchronized (optOutLock) {
// Did we opt out?
if (isOptOut()) {
return false;
}
// Is metrics already running?
if (taskId >= 0) {
return true;
}
// Begin hitting the server with glorious data
taskId = plugin.getServer().getScheduler().scheduleAsyncRepeatingTask(plugin, new Runnable() {
private boolean firstPost = true;
public void run() {
try {
// 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;
}
}
// We use the inverse of firstPost because if it is the first time we are posting,
// it is not a interval ping, so it evaluates to FALSE
// Each time thereafter it will evaluate to TRUE, i.e PING!
postPlugin(!firstPost);
// After the first post we set firstPost to false
// Each post thereafter will be a ping
firstPost = false;
} catch (IOException e) {
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + e.getMessage());
}
}
}, 0, PING_INTERVAL * 1200);
return true;
}
}
/**
* Has the server owner denied plugin metrics?
*
* @return
*/
public boolean isOptOut() {
synchronized(optOutLock) {
try {
// Reload the metrics file
configuration.load(CONFIG_FILE);
} catch (IOException ex) {
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
return true;
} catch (InvalidConfigurationException ex) {
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
return true;
}
return configuration.getBoolean("opt-out", false);
}
}
/**
* Enables metrics for the server by setting "opt-out" to false in the config file and starting the metrics task.
*
* @throws 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);
}
// Enable Task, if it is not running
if (taskId < 0) {
start();
}
}
}
/**
* Disables metrics for the server by setting "opt-out" to true in the config file and canceling the metrics task.
*
* @throws IOException
*/
public void disable() 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", true);
configuration.save(configurationFile);
}
// Disable Task, if it is running
if (taskId > 0) {
this.plugin.getServer().getScheduler().cancelTask(taskId);
taskId = -1;
}
}
}
/**
* 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();
// 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));
// If we're pinging, append it
if (isPing) {
encodeDataPair(data, "ping", "true");
}
// 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();
while (iter.hasNext()) {
final Graph graph = iter.next();
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());
// The value to send, which for the foreseeable future is just the string
// value of plotter.getValue()
final String value = Integer.toString(plotter.getValue());
// Add it to the http post data :)
encodeDataPair(data, key, value);
}
}
}
// Create the url
URL url = new URL(BASE_URL + String.format(REPORT_URL, encode(plugin.getDescription().getName())));
// Connect to the website
URLConnection connection;
// Mineshafter creates a socks proxy, so we can safely bypass it
// It does not reroute POST requests so we need to go around it
if (isMineshafterPresent()) {
connection = url.openConnection(Proxy.NO_PROXY);
} else {
connection = url.openConnection();
}
connection.setDoOutput(true);
// Write the data
final OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());
writer.write(data.toString());
writer.flush();
// Now read the response
final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
final String response = reader.readLine();
// close resources
writer.close();
reader.close();
if (response == null || response.startsWith("ERR")) {
throw new IOException(response); //Throw the exception
} else {
// Is this the first update this hour?
if (response.contains("OK This is your first update this hour")) {
synchronized (graphs) {
final Iterator<Graph> iter = graphs.iterator();
while (iter.hasNext()) {
final Graph graph = iter.next();
for (Plotter plotter : graph.getPlotters()) {
plotter.reset();
}
}
}
}
}
}
/**
* Check if mineshafter is present. If it is, we need to bypass it to send POST requests
*
* @return
*/
private boolean isMineshafterPresent() {
try {
Class.forName("mineshafter.MineServer");
return true;
} catch (Exception e) {
return false;
}
}
/**
* <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>
*
* @param buffer
* @param key
* @param value
* @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));
}
/**
* Encode text as UTF-8
*
* @param text
* @return
*/
private static String encode(final String text) throws UnsupportedEncodingException {
return URLEncoder.encode(text, "UTF-8");
}
/**
* Represents a custom graph on the website
*/
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
*/
private final String name;
/**
* The set of plotters that are contained within this graph
*/
private final Set<Plotter> plotters = new LinkedHashSet<Plotter>();
private Graph(final String name) {
this.name = name;
}
/**
* Gets the graph's name
*
* @return
*/
public String getName() {
return name;
}
/**
* Add a plotter to the graph, which will be used to plot entries
*
* @param plotter
*/
public void addPlotter(final Plotter plotter) {
plotters.add(plotter);
}
/**
* Remove a plotter from the graph
*
* @param plotter
*/
public void removePlotter(final Plotter plotter) {
plotters.remove(plotter);
}
/**
* Gets an <b>unmodifiable</b> set of the plotter objects in the graph
*
* @return
*/
public Set<Plotter> getPlotters() {
return Collections.unmodifiableSet(plotters);
}
@Override
public int hashCode() {
return name.hashCode();
}
@Override
public boolean equals(final Object object) {
if (!(object instanceof Graph)) {
return false;
}
final Graph graph = (Graph) object;
return graph.name.equals(name);
}
}
/**
* Interface used to collect custom data for a plugin
*/
public static abstract class Plotter {
/**
* The plot's name
*/
private final String name;
/**
* Construct a plotter with the default plot name
*/
public Plotter() {
this("Default");
}
/**
* Construct a plotter with a specific plot name
*
* @param name
*/
public Plotter(final String name) {
this.name = name;
}
/**
* Get the current value for the plotted point
*
* @return
*/
public abstract int getValue();
/**
* Get the column name for the plotted point
*
* @return the plotted point's column name
*/
public String getColumnName() {
return name;
}
/**
* Called after the website graphs have been updated
*/
public void reset() {
}
@Override
public int hashCode() {
return getColumnName().hashCode() + getValue();
}
@Override
public boolean equals(final Object object) {
if (!(object instanceof Plotter)) {
return false;
}
final Plotter plotter = (Plotter) object;
return plotter.name.equals(name) && plotter.getValue() == getValue();
}
}
}

View File

@ -0,0 +1,143 @@
package me.BadBones69.CrazyAuctions;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
public class SettingsManager {
static SettingsManager instance = new SettingsManager();
public static SettingsManager getInstance() {
return instance;
}
Plugin p;
FileConfiguration config;
File cfile;
FileConfiguration data;
File dfile;
FileConfiguration msg;
File mfile;
public void setup(Plugin p) {
if (!p.getDataFolder().exists()) {
p.getDataFolder().mkdir();
}
cfile = new File(p.getDataFolder(), "config.yml");
if (!cfile.exists()) {
try{
File en = new File(p.getDataFolder(), "/config.yml");
InputStream E = getClass().getResourceAsStream("/config.yml");
copyFile(E, en);
}catch (Exception e) {
e.printStackTrace();
}
}
config = YamlConfiguration.loadConfiguration(cfile);
dfile = new File(p.getDataFolder(), "Data.yml");
if (!dfile.exists()) {
try{
File en = new File(p.getDataFolder(), "/Data.yml");
InputStream E = getClass().getResourceAsStream("/Data.yml");
copyFile(E, en);
}catch (Exception e) {
e.printStackTrace();
}
}
data = YamlConfiguration.loadConfiguration(dfile);
mfile = new File(p.getDataFolder(), "Messages.yml");
if (!mfile.exists()) {
try{
File en = new File(p.getDataFolder(), "/Messages.yml");
InputStream E = getClass().getResourceAsStream("/Messages.yml");
copyFile(E, en);
}catch (Exception e) {
e.printStackTrace();
}
}
msg = YamlConfiguration.loadConfiguration(mfile);
}
public FileConfiguration getData() {
return data;
}
public FileConfiguration getMsg() {
return msg;
}
public void saveData() {
try {
data.save(dfile);
} catch (IOException e) {
Bukkit.getServer().getLogger()
.severe(ChatColor.RED + "Could not save Data.yml!");
}
}
public void saveMsg() {
try {
msg.save(mfile);
} catch (IOException e) {
Bukkit.getServer().getLogger()
.severe(ChatColor.RED + "Could not save Messages.yml!");
}
}
public void reloadData() {
data = YamlConfiguration.loadConfiguration(dfile);
}
public void reloadMsg() {
msg = YamlConfiguration.loadConfiguration(mfile);
}
public FileConfiguration getConfig() {
return config;
}
public void saveConfig() {
try {
config.save(cfile);
} catch (IOException e) {
Bukkit.getServer().getLogger()
.severe(ChatColor.RED + "Could not save config.yml!");
}
}
public void reloadConfig() {
config = YamlConfiguration.loadConfiguration(cfile);
}
public PluginDescriptionFile getDesc() {
return p.getDescription();
}
public static void copyFile(InputStream in, File out) throws Exception { // https://bukkit.org/threads/extracting-file-from-jar.16962/
InputStream fis = in;
FileOutputStream fos = new FileOutputStream(out);
try {
byte[] buf = new byte[1024];
int i = 0;
while ((i = fis.read(buf)) != -1) {
fos.write(buf, 0, i);
}
} catch (Exception e) {
throw e;
} finally {
if (fis != null) {
fis.close();
}
if (fos != null) {
fos.close();
}
}
}
}

View File

@ -0,0 +1,34 @@
package me.BadBones69.CrazyAuctions;
public enum Shop{
SELL("Sell"), BID("Bid");
String Name;
/**
* @param name Name of the Shop Type.
*/
private Shop(String name){
this.Name=name;
}
/**
* @return Returns the type name as a string.
*/
public String getName(){
return Name;
}
/**
* @param name Name of the Type you want.
* @return Returns the Type as a Enum.
*/
public static Shop getFromName(String name){
for(Shop type : Shop.values()){
if(type.getName().equalsIgnoreCase(name)){
return type;
}
}
return null;
}
}