v1.2.3 Update

Bug Fix:
  - Error when MCUpdate goes down.
  - Error from a method that was running async when it shouldn't have been.

Changes:
  - Cleaned up some code for easier reading.
This commit is contained in:
BadBones69 2017-07-07 16:30:35 -04:00
parent aa9c00dbbf
commit 2ab7a86802
12 changed files with 333 additions and 173 deletions

View File

@ -2,6 +2,16 @@
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="lib" path="/Users/Joe/Plugins/Spigot/Spigot 1.12.jar">
<attributes>
<attribute name="javadoc_location" value="jar:file:/Users/Joe/Plugins/Spigot/Spigot%201.12%20JavaDoc.jar!/"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="/Users/Joe/Plugins/Spigot/Spigot 1.11.2.jar">
<attributes>
<attribute name="javadoc_location" value="jar:file:/Users/Joe/Plugins/Spigot/Spigot%201.11.2%20JavaDoc.jar!/"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="/Users/Joe/Plugins/Spigot/Spigot 1.10.jar">
<attributes>
<attribute name="javadoc_location" value="jar:file:/Users/Joe/Desktop/Stuff/Spigot/Spigot%201.10%20JavaDoc.jar!/"/>

2
.gitignore vendored
View File

@ -3,3 +3,5 @@
*.prefs
*.class
bin/

21
Notes
View File

@ -1,7 +1,18 @@
Features:
(Request) Add it so you can sell more then just 64 of a stack.
(Request) Add a history purchase history.
(Bug) When you collect an item from the expired list with a fully inventory, the item gets lost.
Feature Requests:
- Add it so you can sell more then just 64 of a stack.
- Add a history purchase history.
- Add a taxation option.
- Add an option to broadcast a message when a player adds a new item.
- Add a black list to block names and lores.
- Add an option to set Bidding as the 1st GUI.
- Add the command translation for Spanish and Portugees.
- Add MySQL support.
- Make the command messages all configurable.
- Add a tax system for when a player buys an item.
- Add an option to search for items by ID.
Reports:
- When you collect an item from the expired list with a fully inventory, the item gets lost.
Bug Fixes:
-
@ -13,4 +24,4 @@ Changes:
-
Removed:
- MCStats metrics has been removed due to it being dead.
-

View File

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

View File

@ -6,9 +6,14 @@ 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());
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());
private String Name;
private ArrayList<Material> Items;
@ -70,6 +75,7 @@ public enum Category{
ma.add(Material.DIAMOND_BOOTS);
return ma;
}
private static ArrayList<Material> getTools(){
ArrayList<Material> ma = new ArrayList<Material>();
ma.add(Material.WOOD_PICKAXE);
@ -90,6 +96,7 @@ public enum Category{
ma.add(Material.DIAMOND_HOE);
return ma;
}
private static ArrayList<Material> getWeapons(){
ArrayList<Material> ma = new ArrayList<Material>();
ma.add(Material.WOOD_SWORD);
@ -103,6 +110,7 @@ public enum Category{
ma.add(Material.BOW);
return ma;
}
private static ArrayList<Material> getFood(){
ArrayList<Material> ma = new ArrayList<Material>();
for(Material m : Material.values()){
@ -112,11 +120,13 @@ public enum Category{
}
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()){
@ -126,6 +136,7 @@ public enum Category{
}
return ma;
}
private static ArrayList<Material> getOthers(){
ArrayList<Material> ma = new ArrayList<Material>();
for(Material m : Material.values()){
@ -136,4 +147,5 @@ public enum Category{
}
return ma;
}
}

View File

@ -8,9 +8,12 @@ import org.bukkit.inventory.ItemStack;
public class CrazyAuctions {
static CrazyAuctions instance = new CrazyAuctions();
public static CrazyAuctions instance;
public static CrazyAuctions getInstance() {
if(instance == null){
instance = new CrazyAuctions();
}
return instance;
}

View File

@ -19,7 +19,7 @@ import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin;
import me.badbones69.crazyauctions.currency.CM;
import me.badbones69.crazyauctions.currency.CurrencyManager;
public class GUI implements Listener{
@ -493,9 +493,9 @@ public class GUI implements Listener{
String ID = BiddingID.get(player);
int bid = Bidding.get(player);
String topBidder = data.getString("Items."+ID+".TopBidder");
if(CM.getMoney(player)<bid){
if(CurrencyManager.getMoney(player)<bid){
player.sendMessage(Methods.getPrefix()+Methods.color(msg.getString("Messages.Need-More-Money")
.replaceAll("%Money_Needed%", (bid-CM.getMoney(player))+"").replaceAll("%money_needed%", (bid-CM.getMoney(player))+"")));
.replaceAll("%Money_Needed%", (bid-CurrencyManager.getMoney(player))+"").replaceAll("%money_needed%", (bid-CurrencyManager.getMoney(player))+"")));
return;
}
if(data.getLong("Items."+ID+".Price")>bid){
@ -705,7 +705,7 @@ public class GUI implements Listener{
return;
}
Long cost = data.getLong("Items."+i+".Price");
if(CM.getMoney(player)<cost){
if(CurrencyManager.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);
@ -790,15 +790,15 @@ public class GUI implements Listener{
player.sendMessage(Methods.getPrefix()+Methods.color(msg.getString("Messages.Inventory-Full")));
return;
}
if(CM.getMoney(player)<cost){
if(CurrencyManager.getMoney(player)<cost){
playClick(player);
player.closeInventory();
player.sendMessage(Methods.getPrefix()+Methods.color(msg.getString("Messages.Need-More-Money")
.replaceAll("%Money_Needed%", (cost-CM.getMoney(player))+"").replaceAll("%money_needed%", (cost-CM.getMoney(player))+"")));
.replaceAll("%Money_Needed%", (cost-CurrencyManager.getMoney(player))+"").replaceAll("%money_needed%", (cost-CurrencyManager.getMoney(player))+"")));
return;
}
CM.removeMoney(player, cost);
CM.addMoney(Methods.getOfflinePlayer(seller), cost);
CurrencyManager.removeMoney(player, cost);
CurrencyManager.addMoney(Methods.getOfflinePlayer(seller), cost);
player.sendMessage(Methods.getPrefix()+Methods.color(msg.getString("Messages.Bought-Item")
.replaceAll("%Price%", Methods.getPrice(ID, false)).replaceAll("%price%", Methods.getPrice(ID, false))));
if(Methods.isOnline(seller)){

View File

@ -15,13 +15,15 @@ import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitTask;
public class MCUpdate implements Listener {
private final static String VERSION = "1.0";
private final static String VERSION = "1.1";
private static final String BASE_URL = "http://report.mcupdate.org";
@ -30,6 +32,7 @@ public class MCUpdate implements Listener {
*/
private static String updateMessage = "";
private static boolean upToDate = true;
private boolean checkUpdate = true;
private Plugin pl;
@ -43,35 +46,141 @@ public class MCUpdate implements Listener {
*/
private volatile BukkitTask task = null;
public MCUpdate(Plugin plugin, boolean startTask) throws IOException
{
if (plugin != null)
{
/**
* Start up the MCUpdater.
*
* @param plugin
* The plugin using this.
* @throws IOException
*/
public MCUpdate(Plugin plugin) throws IOException {
if (plugin != null) {
this.pl = plugin;
// I should add a custom configuration for MCUpdate itself
Bukkit.getPluginManager().registerEvents(this, plugin);
setPingInterval(900);
if (startTask)
{
start();
}
}
/**
*
* Start up the MCUpdater.
*
* @param plugin
* The plugin using this.
* @param activate
* Toggle if it starts the MCUpdater when used.
* @throws IOException
*/
public MCUpdate(Plugin plugin, Boolean activate) throws IOException {
if (plugin != null) {
this.pl = plugin;
// I should add a custom configuration for MCUpdate itself
Bukkit.getPluginManager().registerEvents(this, plugin);
setPingInterval(900);
if (activate) {
startLogging();
}
}
}
private boolean start() {
/**
* Call when you wan't to start the updater.
*
* @return True if everything starts and false if it doesn't start.
*/
public boolean startLogging() {
// Is MCUpdate already running?
if (task == null) {
// Begin hitting the server with glorious data
task = pl.getServer().getScheduler().runTaskTimerAsynchronously(pl, () -> {
report();
if (!upToDate) {
if (checkUpdate) {
pl.getServer().getConsoleSender().sendMessage(format(updateMessage));
}
}
}, 0, PING_INTERVAL * 20);
}
return true;
}
/**
* Call when you want to stop the updater.
*
* @return True if it successfully stoped and false if couldn't.
*/
public boolean stopLogging() {
if (task != null) {
try {
task.cancel();
return true;
} catch (Exception e) {
}
} else {
return true;
}
return false;
}
/**
* Check if MCUpdate is logging information.
*
* @return True if it is logging info and false if not.
*/
public Boolean isLogging() {
return task != null;
}
/**
* Set if the updater uses the internal update checker.
*
* @param checkUpdate
* True if you want to use the internal update checker and false
* if not.
*/
public void checkUpdate(Boolean checkUpdate) {
this.checkUpdate = checkUpdate;
}
/**
* Checks if the internal updater is active.
*
* @return True if the internal updater is activated and false if not.
*/
public Boolean needsUpdated() {
return checkUpdate;
}
/**
* Set the rate the information is sent to MCUpdate.org.
*
* @param PING_INTERVAL
* The rate at which the data is sent in seconds.
*/
public void setPingInterval(int PING_INTERVAL) {
this.PING_INTERVAL = PING_INTERVAL;
}
/**
* Get the rate which the data is sent to MCUpdate.org.
*
* @return The rate the data is sent in seconds.
*/
public int getPingInterval() {
return PING_INTERVAL;
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent e) {
Player p = e.getPlayer();
if (p.isOp() && !upToDate) {
if (checkUpdate) {
p.sendMessage(format(updateMessage));
}
}
}
private int getOnlinePlayers() {
try {
Method onlinePlayerMethod = Server.class.getMethod("getOnlinePlayers");
@ -141,14 +250,18 @@ public class MCUpdate implements Listener {
String cVersion = getString(endData, "pl_Version");
updateMessage = getString(endData, "update_Message");
if (serverMessage != null) {
if (!serverMessage.equals("ERROR")) {
if (cVersion != null) {
if (!ver.equals(cVersion)) {
upToDate = false;
}
}
}
}
br.close();
} catch (IOException ignored) {
} catch (Exception ignored) {
}
}
@ -163,7 +276,7 @@ public class MCUpdate implements Listener {
return list2.get(1);
}
}
return null;
return "";
}
private static String toJson(String key, String value) {
@ -171,10 +284,11 @@ public class MCUpdate implements Listener {
}
private static String format(String format) {
if (format != null) {
return ChatColor.translateAlternateColorCodes('&', format);
} else {
return "";
}
}
public void setPingInterval(int PING_INTERVAL) {
this.PING_INTERVAL = PING_INTERVAL;
}
}

View File

@ -23,13 +23,7 @@ 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();
}
private int file = 0;
@Override
public void onEnable(){
@ -54,6 +48,12 @@ public class Main extends JavaPlugin implements Listener{
} catch (IOException e) {}
}
@Override
public void onDisable(){
Bukkit.getScheduler().cancelTask(file);
settings.saveData();
}
public boolean onCommand(CommandSender sender, Command cmd, String commandLable, String[] args){
if(commandLable.equalsIgnoreCase("CrazyAuctions") || commandLable.equalsIgnoreCase("CrazyAuction")
|| commandLable.equalsIgnoreCase("CA") || commandLable.equalsIgnoreCase("AH")
@ -299,7 +299,7 @@ public class Main extends JavaPlugin implements Listener{
public void run() {
Methods.updateAuction();
}
}.runTaskTimerAsynchronously(this, 20, 5*20);
}.runTaskTimer(this, 20, 5*20);
}
private ArrayList<Material> getDamageableItems(){

View File

@ -23,20 +23,18 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.Plugin;
import me.badbones69.crazyauctions.currency.CM;
import me.badbones69.crazyauctions.currency.CurrencyManager;
public class Methods {
public static Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("CrazyAuctions");
public static String color(String msg){
msg = ChatColor.translateAlternateColorCodes('&', msg);
return msg;
return ChatColor.translateAlternateColorCodes('&', msg);
}
public static String removeColor(String msg){
msg = ChatColor.stripColor(msg);
return msg;
return ChatColor.stripColor(msg);
}
public static String getPrefix(){
@ -399,12 +397,12 @@ public class Methods {
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(Methods.getPlayer(data.getString("Items."+i+".TopBidder")))>=data.getInt("Items."+i+".Price")){
if(data.getBoolean("Items."+i+".Biddable")&&!data.getString("Items."+i+".TopBidder").equalsIgnoreCase("None")&&CurrencyManager.getMoney(Methods.getPlayer(data.getString("Items."+i+".TopBidder")))>=data.getInt("Items."+i+".Price")){
String winner = data.getString("Items."+i+".TopBidder");
String seller = data.getString("Items."+i+".Seller");
Long price = data.getLong("Items."+i+".Price");
CM.addMoney(Methods.getOfflinePlayer(seller), price);
CM.removeMoney(Methods.getOfflinePlayer(winner), price);
CurrencyManager.addMoney(Methods.getOfflinePlayer(seller), price);
CurrencyManager.removeMoney(Methods.getOfflinePlayer(winner), price);
if(Methods.isOnline(winner)){
Player player = Methods.getPlayer(winner);
player.sendMessage(Methods.getPrefix()+Methods.color(msg.getString("Messages.Win-Bidding")

View File

@ -6,7 +6,8 @@ import org.bukkit.entity.Player;
import me.badbones69.crazyauctions.Main;
public enum CM { // Currency Manager
public enum CurrencyManager { // Currency Manager
VAULT("Vault", "Money");
String PluginName, Name;
@ -17,7 +18,7 @@ public enum CM { // Currency Manager
* @param name
* Name of the Currency.
*/
private CM(String pluginname, String name) {
private CurrencyManager(String pluginname, String name) {
this.PluginName = pluginname;
this.Name = name;
}
@ -41,8 +42,8 @@ public enum CM { // Currency Manager
* Name of the Type you want.
* @return Returns the Currency as a Enum.
*/
public static CM getFromName(String name) {
for (CM type : CM.values()) {
public static CurrencyManager getFromName(String name) {
for (CurrencyManager type : CurrencyManager.values()) {
if (type.getPluginName().equalsIgnoreCase(name)) {
return type;
}

View File

@ -9,14 +9,17 @@ 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;
@ -28,22 +31,28 @@ public class Vault {
econ = rsp.getProvider();
return econ != null;
}
public static Long getMoney(Player player){
if(player != null){
return (long) econ.getBalance(player);
}
return 0L;
}
public static void removeMoney(Player player, Long amount){
econ.withdrawPlayer(player, amount);
}
public static void removeMoney(OfflinePlayer player, Long amount){
econ.withdrawPlayer(player, amount);
}
public static void addMoney(Player player, Long amount){
econ.depositPlayer(player, amount);
}
public static void addMoney(OfflinePlayer player, Long amount){
econ.depositPlayer(player, amount);
}
}