From b72aaf3df519b46d254167d1768cd33a24f6846d Mon Sep 17 00:00:00 2001 From: Boosik Date: Fri, 1 Aug 2014 20:57:33 +0200 Subject: [PATCH] Formated sources, fixed commands losing case --- .../boosCooldown/BoosConfigManager.java | 24 +- .../boosCooldown/BoosCoolDownListener.java | 55 +- .../boosCooldown/BoosCoolDownManager.java | 91 +- .../boosCooldown/BoosItemCostManager.java | 38 +- .../boosik/boosCooldown/BoosLimitManager.java | 62 +- .../boosik/boosCooldown/BoosPriceManager.java | 27 +- .../boosCooldown/BoosWarmUpManager.java | 121 ++- .../boosik/boosCooldown/BoosWarmUpTimer.java | 26 +- .../Listeners/BoosPlayerDeathListener.java | 45 +- src/main/java/org/mcstats/MetricsLite.java | 950 +++++++++--------- 10 files changed, 736 insertions(+), 703 deletions(-) diff --git a/src/main/java/cz/boosik/boosCooldown/BoosConfigManager.java b/src/main/java/cz/boosik/boosCooldown/BoosConfigManager.java index 7ec2120..d0d0d53 100644 --- a/src/main/java/cz/boosik/boosCooldown/BoosConfigManager.java +++ b/src/main/java/cz/boosik/boosCooldown/BoosConfigManager.java @@ -74,12 +74,10 @@ public class BoosConfigManager { */ public static void clearSomething(String co, UUID uuid) { ConfigurationSection userSection = confusers - .getConfigurationSection("users." - + uuid + "." + co); + .getConfigurationSection("users." + uuid + "." + co); if (userSection == null) return; - confusers.set("users." + uuid + "." + co, - null); + confusers.set("users." + uuid + "." + co, null); saveConfusers(); loadConfusers(); } @@ -97,8 +95,7 @@ public class BoosConfigManager { */ static void clearSomething(String co, UUID uuid, String command) { int pre2 = command.toLowerCase().hashCode(); - confusers.set("users." + uuid + "." + co - + "." + pre2, 0); + confusers.set("users." + uuid + "." + co + "." + pre2, 0); saveConfusers(); loadConfusers(); } @@ -119,6 +116,15 @@ public class BoosConfigManager { .getKeys(false); return aliases; } + + /** + * @return + */ + static Set getAliasesKeys() { + Set aliases = conf.getConfigurationSection("commands.aliases") + .getKeys(true); + return aliases; + } /** * @return @@ -725,10 +731,12 @@ public class BoosConfigManager { try { value2 = Integer.parseInt(value); reload(); - conf.set("commands.groups." + group + "." + command + "." + what, value2); + conf.set("commands.groups." + group + "." + command + "." + what, + value2); } catch (NumberFormatException e1) { reload(); - conf.set("commands.groups." + group + "." + command + "." + what, value); + conf.set("commands.groups." + group + "." + command + "." + what, + value); } try { conf.save(confFile); diff --git a/src/main/java/cz/boosik/boosCooldown/BoosCoolDownListener.java b/src/main/java/cz/boosik/boosCooldown/BoosCoolDownListener.java index ca9cda6..a54db8d 100644 --- a/src/main/java/cz/boosik/boosCooldown/BoosCoolDownListener.java +++ b/src/main/java/cz/boosik/boosCooldown/BoosCoolDownListener.java @@ -11,10 +11,9 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent; import util.boosChat; /** - * Hlavn� poslucha�, kter� naslouch� ud�losti pou�it� p��kazu - * hr��em. Kontroluje, jestli jsou pro p��kaz nastaveny omezen� a na - * z�klad� tohoto spou�t� �asova�e a vol� metody spojen� s - * poplatky a limity. + * Hlavn� poslucha�, kter� naslouch� ud�losti pou�it� p��kazu hr��em. + * Kontroluje, jestli jsou pro p��kaz nastaveny omezen� a na z�klad� tohoto + * spou�t� �asova�e a vol� metody spojen� s poplatky a limity. * * @author Jakub Kol�� * @@ -30,18 +29,17 @@ public class BoosCoolDownListener implements Listener { } /** - * Metoda zkontroluje pomoc� vol�n� dal��ch metod, jestli p�ikaz - * kter� hr�� pou�il je n�jak�m zp�sobem omezen� a na - * z�klad� toho je bu� ud�lost pou�it� p��kazu stornov�na, - * nebo ne. + * Metoda zkontroluje pomoc� vol�n� dal��ch metod, jestli p�ikaz kter� hr�� + * pou�il je n�jak�m zp�sobem omezen� a na z�klad� toho je bu� ud�lost + * pou�it� p��kazu stornov�na, nebo ne. * * @param event * ud�lost PlayerCommandPreprocessEvent * @param player * hr�� kter� spustil tuto ud�lost * @param regexCommad - * p��kaz z konfigura�n�ho souboru, kter� vyhovuje - * origin�ln�mu p��kazu + * p��kaz z konfigura�n�ho souboru, kter� vyhovuje origin�ln�mu + * p��kazu * @param originalCommand * origin�ln� p��kaz kter� hr�� pou�il * @param warmupTime @@ -105,8 +103,8 @@ public class BoosCoolDownListener implements Listener { BoosConfigManager.getInsufficientFundsMessage(), (price + " " + unit), BoosCoolDown.getEconomy().format( - BoosCoolDown.getEconomy().getBalance( - player))); + BoosCoolDown.getEconomy() + .getBalance(player))); msg = msg.replaceAll("&command&", originalCommand); boosChat.sendMessageToPlayer(player, msg); } @@ -154,14 +152,12 @@ public class BoosCoolDownListener implements Listener { } /** - * Poslucha�, kter� naslouch� ud�losti pou�it� p��kazu a - * spou�t� se je�t� p�ed t�m, ne� je vykon�n efekt tohto - * p��kazu. Metoda zji��uje, jestli p��kaz nen� alias jin�ho - * p��kazu a tak� jestli se p��kaz kter� hr�� pou�il - * shoduje s p��kazem nastaven�m v konfiguraci. Pokud se shoduje, pak - * jsou na�teny informace o warmup dob�, cooldown dob�, poplatku a - * limitu. Tyto hodnoty jsou pot� p�ed�ny metod� - * checkRestrictions();. + * Poslucha�, kter� naslouch� ud�losti pou�it� p��kazu a spou�t� se je�t� + * p�ed t�m, ne� je vykon�n efekt tohto p��kazu. Metoda zji��uje, jestli + * p��kaz nen� alias jin�ho p��kazu a tak� jestli se p��kaz kter� hr�� + * pou�il shoduje s p��kazem nastaven�m v konfiguraci. Pokud se shoduje, pak + * jsou na�teny informace o warmup dob�, cooldown dob�, poplatku a limitu. + * Tyto hodnoty jsou pot� p�ed�ny metod� checkRestrictions();. * * @param event * ud�lost PlayerCommandPreprocessEvent @@ -171,17 +167,16 @@ public class BoosCoolDownListener implements Listener { Player player = event.getPlayer(); String originalCommand = event.getMessage().replace("\\", "\\\\"); originalCommand = originalCommand.replace("$", "S"); - originalCommand = originalCommand.trim().replaceAll(" +", " ") - .toLowerCase(); + originalCommand = originalCommand.trim().replaceAll(" +", " "); String regexCommad = ""; Set aliases = null; try { aliases = BoosConfigManager.getAliases(); } catch (Exception e1) { BoosCoolDown - .getLog() - .warning( - "Aliases section in config.yml is missing! Please delete your config.yml, restart server and set it again!"); + .getLog() + .warning( + "Aliases section in config.yml is missing! Please delete your config.yml, restart server and set it again!"); } Set commands = BoosConfigManager.getCommands(player); boolean on = true; @@ -214,7 +209,7 @@ public class BoosCoolDownListener implements Listener { if (on) { for (String group : commands) { String group2 = group.replace("*", ".+"); - if (originalCommand.matches(group2)) { + if (originalCommand.matches("(?i)"+group2)) { regexCommad = group; if (BoosConfigManager.getWarmupEnabled()) { warmupTime = BoosConfigManager.getWarmUp(regexCommad, @@ -250,16 +245,16 @@ public class BoosCoolDownListener implements Listener { } /** - * Metoda spou�t� warmup a cooldown �asova�e, p��padn� je - * ukon�uje, pokud ji� tyto �asova�e skon�ili. + * Metoda spou�t� warmup a cooldown �asova�e, p��padn� je ukon�uje, pokud + * ji� tyto �asova�e skon�ili. * * @param event * ud�lost PlayerCommandPreprocessEvent * @param player * hr�� kter� spustil tuto ud�lost * @param regexCommad - * p��kaz z konfigura�n�ho souboru, kter� vyhovuje - * origin�ln�mu p��kazu + * p��kaz z konfigura�n�ho souboru, kter� vyhovuje origin�ln�mu + * p��kazu * @param originalCommand * origin�ln� p��kaz kter� hr�� pou�il * @param warmupTime diff --git a/src/main/java/cz/boosik/boosCooldown/BoosCoolDownManager.java b/src/main/java/cz/boosik/boosCooldown/BoosCoolDownManager.java index e378d0f..ec37db9 100644 --- a/src/main/java/cz/boosik/boosCooldown/BoosCoolDownManager.java +++ b/src/main/java/cz/boosik/boosCooldown/BoosCoolDownManager.java @@ -11,42 +11,41 @@ import org.bukkit.entity.Player; import util.boosChat; /** - * Tda obsahuje veker metody potebn k zen cooldown asova. Spoutn, - * ukonovn, zjiovn zda je cooldown asova ji aktivn. + * T��da obsahuje ve�ker� metody pot�ebn� k ��zen� cooldown �asova��. Spou�t�n�, + * ukon�ov�n�, zji��ov�n� zda je cooldown �asova� ji� aktivn�. * - * @author Jakub Kol + * @author Jakub Kol�� * */ public class BoosCoolDownManager { /** - * Metoda ukonuje specifikovan cooldown asova pro specifikovanho hre. + * Metoda ukon�uje specifikovan� cooldown �asova� pro specifikovan�ho hr��e. * * @param player - * specifick hr + * specifick� hr�� * @param regexCommand - * pkaz z konfigurace vyhovujc originlnmu pkazu + * p��kaz z konfigurace vyhovuj�c� origin�ln�mu p��kazu */ static void cancelCooldown(Player player, String regexCommand) { int pre2 = regexCommand.toLowerCase().hashCode(); BoosConfigManager.getConfusers().set( - "users." + player.getUniqueId() + ".cooldown." - + pre2, null); + "users." + player.getUniqueId() + ".cooldown." + pre2, null); } /** - * Metoda vrac hodnotu boolean na zklad toho, jestli m specifikovan - * pkaz aktivn cooldown asova. + * Metoda vrac� hodnotu boolean na z�klad� toho, jestli m� specifikovan� + * p��kaz aktivn� cooldown �asova�. * * @param player - * specifikovan hr + * specifikovan� hr�� * @param regexCommand - * pkaz z konfigurace vyhovujc originlnmu pkazu + * p��kaz z konfigurace vyhovuj�c� origin�ln�mu p��kazu * @param originalCommand - * originln pkaz pouit hrem + * origin�ln� p��kaz pou�it� hr��em * @param coolDownSeconds - * cooldown doba v sekundch, nastaven pro regexCommand v + * cooldown doba v sekund�ch, nastaven� pro regexCommand v * konfiguraci - * @return true pokud je pkaz na cooldown asovai, jinak false + * @return true pokud je p��kaz na cooldown �asova�i, jinak false */ static boolean cd(Player player, String regexCommand, String originalCommand, int coolDownSeconds) { @@ -110,21 +109,21 @@ public class BoosCoolDownManager { } /** - * Metoda kontroluje, jestli hr nedisponuje oprvnnmi, kter obchzej - * cooldown asovae. Pokud tmito oprvnnmi hr disponuje, pak metoda - * vrac false. Pokud hr nedisponuje tmito oprvnnmi, vrac hodnotu - * vrcenou metodou cd();. + * Metoda kontroluje, jestli hr�� nedisponuje opr�vn�n�mi, kter� obch�zej� + * cooldown �asova�e. Pokud t�mito opr�vn�n�mi hr�� disponuje, pak metoda + * vrac� false. Pokud hr�� nedisponuje t�mito opr�vn�n�mi, vrac� hodnotu + * vr�cenou metodou cd();. * * @param player - * specifikovan hr + * specifikovan� hr�� * @param regexCommand - * pkaz z konfigurace vyhovujc originlnmu pkazu + * p��kaz z konfigurace vyhovuj�c� origin�ln�mu p��kazu * @param originalCommand - * originln pkaz pouit hrem + * origin�ln� p��kaz pou�it� hr��em * @param time - * cooldown doba v sekundch, nastaven pro regexCommand v + * cooldown doba v sekund�ch, nastaven� pro regexCommand v * konfiguraci - * @return false pokud hr disponuje oprvnnmi, jinak hodnotu vrcenou + * @return false pokud hr�� disponuje opr�vn�n�mi, jinak hodnotu vr�cenou * metodou cd();. */ static boolean coolDown(Player player, String regexCommand, @@ -140,9 +139,9 @@ public class BoosCoolDownManager { } /** - * Metoda vrac souasn pesn datum a as. + * Metoda vrac� sou�asn� p�esn� datum a �as. * - * @return souasn as a datum + * @return sou�asn� �as a datum */ static Date getCurrTime() { String currTime = ""; @@ -160,13 +159,13 @@ public class BoosCoolDownManager { } /** - * Metoda vrac datum a as, kdy hr naposledy pouil dan pkaz. + * Metoda vrac� datum a �as, kdy hr�� naposledy pou�il dan� p��kaz. * * @param player - * specifikovan hr + * specifikovan� hr�� * @param regexCommand - * pkaz z konfigurace vyhovujc originlnmu pkazu - * @return datum a as kdy hr naposledy pouil dan pkaz + * p��kaz z konfigurace vyhovuj�c� origin�ln�mu p��kazu + * @return datum a �as kdy hr�� naposledy pou�il dan� p��kaz */ static Date getTime(Player player, String regexCommand) { int pre2 = regexCommand.toLowerCase().hashCode(); @@ -190,19 +189,19 @@ public class BoosCoolDownManager { } /** - * Metoda vrac hodnotu boolean na zklad toho, jestli m specifikovan - * pkaz aktivn cooldown asova. + * Metoda vrac� hodnotu boolean na z�klad� toho, jestli m� specifikovan� + * p��kaz aktivn� cooldown �asova�. * * @param player - * specifikovan hr + * specifikovan� hr�� * @param regexCommand - * pkaz z konfigurace vyhovujc originlnmu pkazu + * p��kaz z konfigurace vyhovuj�c� origin�ln�mu p��kazu * @param originalCommand - * originln pkaz pouit hrem + * origin�ln� p��kaz pou�it� hr��em * @param time - * cooldown doba v sekundch, nastaven pro regexCommand v + * cooldown doba v sekund�ch, nastaven� pro regexCommand v * konfiguraci - * @return false pokud m pkaz aktivn cooldown asova, jinak false + * @return false pokud m� p��kaz aktivn� cooldown �asova�, jinak false */ static boolean checkCoolDownOK(Player player, String regexCommand, String originalCommand, int time) { @@ -250,12 +249,12 @@ public class BoosCoolDownManager { } /** - * Metoda vrac hodnotu rozdlu v sekundch mezi dvmi hodnotami datumu a - * asu. + * Metoda vrac� hodnotu rozd�lu v sekund�ch mezi dv�mi hodnotami datumu a + * �asu. * * @param startDate * @param endDate - * @return rozdl v sekundch mezi startDate a endDate + * @return rozd�l v sekund�ch mezi startDate a endDate */ static long secondsBetween(Calendar startDate, Calendar endDate) { long secondsBetween = 0; @@ -268,13 +267,13 @@ public class BoosCoolDownManager { } /** - * Metoda ukld do databze datum a as kdy hr naposledy pouil dan - * pkaz. + * Metoda ukl�d� do datab�ze datum a �as kdy hr�� naposledy pou�il dan� + * p��kaz. * * @param player - * specifick hr + * specifick� hr�� * @param regexCommand - * pkaz z konfigurace vyhovujc originlnmu pkazu + * p��kaz z konfigurace vyhovuj�c� origin�ln�mu p��kazu */ static void setTime(Player player, String regexCommand) { int pre2 = regexCommand.toLowerCase().hashCode(); @@ -288,10 +287,10 @@ public class BoosCoolDownManager { } /** - * Metoda spout veker cooldown asovae pro specifickho hre. + * Metoda spou�t� ve�ker� cooldown �asova�e pro specifick�ho hr��e. * * @param player - * specifick hr + * specifick� hr�� * @param message */ public static void startAllCooldowns(Player player, String message) { diff --git a/src/main/java/cz/boosik/boosCooldown/BoosItemCostManager.java b/src/main/java/cz/boosik/boosCooldown/BoosItemCostManager.java index 4bb6e4b..c9c6ec9 100644 --- a/src/main/java/cz/boosik/boosCooldown/BoosItemCostManager.java +++ b/src/main/java/cz/boosik/boosCooldown/BoosItemCostManager.java @@ -9,32 +9,32 @@ import org.bukkit.inventory.ItemStack; import util.boosChat; /** - * Tda obsahuje veker metody potebn k zen poplatk za pkazy. + * T��da obsahuje ve�ker� metody pot�ebn� k ��zen� poplatk� za p��kazy. * - * @author Jakub Kol + * @author Jakub Kol�� * */ public class BoosItemCostManager { private static String msg = ""; /** - * Metoda zajiuje funkci platby za pkaz. Vrac hodnotu v zvislosti na - * spnosti platby. + * Metoda zaji��uje funkci platby za p��kaz. Vrac� hodnotu v z�vislosti na + * �sp�nosti platby. * * @param player - * specifikovan hr + * specifikovan� hr�� * @param regexCommand - * pkaz z konfigurace vyhovujc originlnmu pkazu + * p��kaz z konfigurace vyhovuj�c� origin�ln�mu p��kazu * @param originalCommand - * originln pkaz pouit hrem + * origin�ln� p��kaz pou�it� hr��em * @param item * @param price - * cena pouit pkazu + * cena pou�it� p��kazu * @param name - * jmno specifickho hre - * @return true pokud byl spn zaplacen poplatek, nebo pokud nebyl - * nalezen ekonomick plugin; false pokud dolo k chyb nebo hr - * neml dostatek financ + * jm�no specifick�ho hr��e + * @return true pokud byl �sp�n� zaplacen poplatek, nebo pokud nebyl nalezen + * ekonomick� plugin; false pokud do�lo k chyb� nebo hr�� nem�l + * dostatek financ� */ static boolean payItemForCommand(Player player, String regexCommand, String originalCommand, String item, int count, String name) { @@ -64,21 +64,21 @@ public class BoosItemCostManager { } /** - * Metoda ukonuje/neukonuje udlost pouit pkazu v zvislosti na tom, - * jakou hodnotu vrtila metoda payForCommand(Player player, String + * Metoda ukon�uje/neukon�uje ud�lost pou�it� p��kazu v z�vislosti na tom, + * jakou hodnotu vr�tila metoda payForCommand(Player player, String * regexCommand, String originalCommand, double price, String name);. * * @param event - * udlost PlayerCommandPreprocessEvent + * ud�lost PlayerCommandPreprocessEvent * @param player - * specifick hr + * specifick� hr�� * @param regexCommand - * pkaz z konfigurace vyhovujc originlnmu pkazu + * p��kaz z konfigurace vyhovuj�c� origin�ln�mu p��kazu * @param originalCommand - * originln pkaz pouit hrem + * origin�ln� p��kaz pou�it� hr��em * @param item * @param price - * cena pouit pkazu + * cena pou�it� p��kazu */ static void payItemForCommand(PlayerCommandPreprocessEvent event, Player player, String regexCommand, String originalCommand, diff --git a/src/main/java/cz/boosik/boosCooldown/BoosLimitManager.java b/src/main/java/cz/boosik/boosCooldown/BoosLimitManager.java index 24d6b9c..8fddd5e 100644 --- a/src/main/java/cz/boosik/boosCooldown/BoosLimitManager.java +++ b/src/main/java/cz/boosik/boosCooldown/BoosLimitManager.java @@ -5,27 +5,27 @@ import org.bukkit.entity.Player; import util.boosChat; /** - * Tda obsahuje veker metody potebn k zen limit. + * T��da obsahuje ve�ker� metody pot�ebn� k ��zen� limit�. * - * @author Jakub Kol + * @author Jakub Kol�� * */ public class BoosLimitManager { /** - * Metoda kontroluje zda je mon pout pkaz, nebo zda je pkaz ji - * zablokovan. + * Metoda kontroluje zda je mo�n� pou��t p��kaz, nebo zda je p��kaz ji� + * zablokovan�. * * @param player - * specifick hr + * specifick� hr�� * @param regexCommand - * pkaz z konfiguranho souboru, kter vyhovuje originlnmu - * pkazu + * p��kaz z konfigura�n�ho souboru, kter� vyhovuje origin�ln�mu + * p��kazu * @param originalCommand - * originln pkaz pouit hrem + * origin�ln� p��kaz pou�it� hr��em * @param limit - * limit nastaven pro regexCommand - * @return false pokud pkaz je mon pout, true pokud pkaz nen mon - * pout + * limit nastaven� pro regexCommand + * @return false pokud p��kaz je mo�n� pou��t, true pokud p��kaz nen� mo�n� + * pou��t */ static boolean blocked(Player player, String regexCommand, String originalCommand, int limit) { @@ -44,37 +44,37 @@ public class BoosLimitManager { } /** - * Metoda vrac hodnotu, kter je urena tm, kolikrt ji hr pouil - * specifikovan pkaz. + * Metoda vrac� hodnotu, kter� je ur�ena t�m, kolikr�t ji� hr�� pou�il + * specifikovan� p��kaz. * * @param player - * specifick hr + * specifick� hr�� * @param regexCommand - * pkaz z konfiguranho souboru, kter vyhovuje originlnmu - * pkazu - * @return hodnota pedstavujci poet pouit specifikovanho pkazu + * p��kaz z konfigura�n�ho souboru, kter� vyhovuje origin�ln�mu + * p��kazu + * @return hodnota p�edstavuj�ci po�et pou�it� specifikovan�ho p��kazu */ static int getUses(Player player, String regexCommand) { int regexCommand2 = regexCommand.toLowerCase().hashCode(); int uses = 0; uses = BoosConfigManager.getConfusers().getInt( - "users." + player.getUniqueId() + ".uses." - + regexCommand2, uses); + "users." + player.getUniqueId() + ".uses." + regexCommand2, + uses); return uses; } /** - * Metoda nastavuje poet pouit pkazu o jedna vt po kadm pouit - * pkazu hrem. Nasteven hodnoty probh jen pro pkazy, kter jsou - * definovny v konfiguraci. + * Metoda nastavuje po�et pou�it� p��kazu o jedna v�t�� po ka�d�m pou�it� + * p��kazu hr��em. Nasteven� hodnoty prob�h� jen pro p��kazy, kter� jsou + * definov�ny v konfiguraci. * * @param player - * specifick hr + * specifick� hr�� * @param regexCommand - * pkaz z konfiguranho souboru, kter vyhovuje originlnmu - * pkazu + * p��kaz z konfigura�n�ho souboru, kter� vyhovuje origin�ln�mu + * p��kazu * @param originalCommand - * originln pkaz pouit hrem + * origin�ln� p��kaz pou�it� hr��em */ static void setUses(Player player, String regexCommand, String originalCommand) { @@ -103,15 +103,15 @@ public class BoosLimitManager { } /** - * Metoda odesl hri zprvu o limitovanm pkazu, hodnotu tohoto limitu - * a kolikrt je jet mon limitovan pkaz pout. + * Metoda odes�l� hr��i zpr�vu o limitovan�m p��kazu, hodnotu tohoto limitu + * a kolikr�t je je�t� mo�n� limitovan� p��kaz pou��t. * * @param send - * hr ktermu bude odesln seznam + * hr�� kter�mu bude odesl�n seznam * @param comm - * pkaz o kterm si hr vydal informace + * p��kaz o kter�m si hr�� vy��dal informace * @param lim - * hodnota limitu na pkazu + * hodnota limitu na p��kazu */ static void getLimitListMessages(Player send, String comm, int lim) { if (lim != -1) { diff --git a/src/main/java/cz/boosik/boosCooldown/BoosPriceManager.java b/src/main/java/cz/boosik/boosCooldown/BoosPriceManager.java index 3aa7bb0..f909e69 100644 --- a/src/main/java/cz/boosik/boosCooldown/BoosPriceManager.java +++ b/src/main/java/cz/boosik/boosCooldown/BoosPriceManager.java @@ -9,8 +9,8 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent; import util.boosChat; /** - * T��da obsahuje ve�ker� metody pot�ebn� k ��zen� poplatk� - * pomoc� v�c� za p��kazy. + * T��da obsahuje ve�ker� metody pot�ebn� k ��zen� poplatk� pomoc� v�c� za + * p��kazy. * * @author Jakub Kol�� * @@ -20,23 +20,22 @@ public class BoosPriceManager { private static String msg = ""; /** - * Metoda zaji��uje funkci platby za p��kaz. Vrac� hodnotu v - * z�vislosti na �sp�nosti platby. + * Metoda zaji��uje funkci platby za p��kaz. Vrac� hodnotu v z�vislosti na + * �sp�nosti platby. * * @param player * specifikovan� hr�� * @param regexCommand - * p��kaz z konfigurace vyhovuj�c� origin�ln�mu - * p��kazu + * p��kaz z konfigurace vyhovuj�c� origin�ln�mu p��kazu * @param originalCommand * origin�ln� p��kaz pou�it� hr��em * @param price * cena pou�it� p��kazu * @param name * jm�no specifick�ho hr��e - * @return true pokud byl �sp�n� zaplacen poplatek, nebo pokud nebyl - * nalezen ekonomick� plugin; false pokud do�lo k chyb� nebo - * hr�� nem�l dostatek financ� + * @return true pokud byl �sp�n� zaplacen poplatek, nebo pokud nebyl nalezen + * ekonomick� plugin; false pokud do�lo k chyb� nebo hr�� nem�l + * dostatek financ� */ static boolean payForCommand(Player player, String regexCommand, String originalCommand, double price, String name) { @@ -72,18 +71,16 @@ public class BoosPriceManager { } /** - * Metoda ukon�uje/neukon�uje ud�lost pou�it� p��kazu v - * z�vislosti na tom, jakou hodnotu vr�tila metoda payForCommand(Player - * player, String regexCommand, String originalCommand, double price, String - * name);. + * Metoda ukon�uje/neukon�uje ud�lost pou�it� p��kazu v z�vislosti na tom, + * jakou hodnotu vr�tila metoda payForCommand(Player player, String + * regexCommand, String originalCommand, double price, String name);. * * @param event * ud�lost PlayerCommandPreprocessEvent * @param player * specifick� hr�� * @param regexCommand - * p��kaz z konfigurace vyhovuj�c� origin�ln�mu - * p��kazu + * p��kaz z konfigurace vyhovuj�c� origin�ln�mu p��kazu * @param originalCommand * origin�ln� p��kaz pou�it� hr��em * @param price diff --git a/src/main/java/cz/boosik/boosCooldown/BoosWarmUpManager.java b/src/main/java/cz/boosik/boosCooldown/BoosWarmUpManager.java index 93de057..5f6454a 100644 --- a/src/main/java/cz/boosik/boosCooldown/BoosWarmUpManager.java +++ b/src/main/java/cz/boosik/boosCooldown/BoosWarmUpManager.java @@ -11,10 +11,10 @@ import org.bukkit.potion.PotionEffectType; import util.boosChat; /** - * Tda obsahuje veker metody potebn k zen warmup asova. Spoutn, - * ukonovn a zjiovn zda je warmup asova ji aktivn. + * T��da obsahuje ve�ker� metody pot�ebn� k ��zen� warmup �asova��. Spou�t�n�, + * ukon�ov�n� a zji��ov�n� zda je warmup �asova� ji� aktivn�. * - * @author Jakub Kol + * @author Jakub Kol�� * */ public class BoosWarmUpManager { @@ -26,16 +26,16 @@ public class BoosWarmUpManager { private static Timer scheduler; /** - * Metoda aplikuje na hre magick efekt na dobu urenou parametrem + * Metoda aplikuje na hr��e magick� efekt na dobu ur�enou parametrem * warmUpSeconds. * * @param player - * specifick hr + * specifick� hr�� * @param regexCommand - * pkaz z konfiguranho souboru, kter vyhovuje originlnmu - * pkazu + * p��kaz z konfigura�n�ho souboru, kter� vyhovuje origin�ln�mu + * p��kazu * @param warmUpSeconds - * doba warmup v sekundch, nastaven pro regexCommand v + * doba warmup v sekund�ch, nastaven� pro regexCommand v * konfiguraci */ static void applyPotionEffect(Player player, String regexCommand, @@ -56,10 +56,10 @@ public class BoosWarmUpManager { } /** - * Metoda stornuje veker probhajc warmup asovae specifickho hre. + * Metoda stornuje ve�ker� prob�haj�c� warmup �asova�e specifick�ho hr��e. * * @param player - * specifick hr + * specifick� hr�� */ public static void cancelWarmUps(Player player) { Iterator iter = playercommands.keySet().iterator(); @@ -72,10 +72,10 @@ public class BoosWarmUpManager { } /** - * Metoda pro specifickho hre vymae uloenou pozici a svt. + * Metoda pro specifick�ho hr��e vyma�e ulo�enou pozici a sv�t. * * @param player - * specifick hr + * specifick� hr�� */ public static void clearLocWorld(Player player) { BoosWarmUpManager.playerloc.remove(player); @@ -83,12 +83,12 @@ public class BoosWarmUpManager { } /** - * Metoda vrac boolean hodnotu v zvislosti na tom jestli specifikovan - * hr m aktivn warmup asovae nebo ne. + * Metoda vrac� boolean hodnotu v z�vislosti na tom jestli specifikovan� + * hr�� m� aktivn� warmup �asova�e nebo ne. * * @param player - * specifick hr - * @return true pokud hr m aktivn warmup asovae, jinak false + * specifick� hr�� + * @return true pokud hr�� m� aktivn� warmup �asova�e, jinak false */ public static boolean hasWarmUps(Player player) { for (String key : playercommands.keySet()) { @@ -100,23 +100,22 @@ public class BoosWarmUpManager { } /** - * Metoda zjiuje, jestli je dan warmup asova oznaen jako ji probhl + * Metoda zji��uje, jestli je dan� warmup �asova� ozna�en� jako ji� prob�hl� * nebo ne. * * @param player - * specifick hr + * specifick� hr�� * @param regexCommand - * pkaz z konfiguranho souboru, kter vyhovuje originlnmu - * pkazu - * @return true pokud je warmup asova oznaen jako ji probhl, jinak + * p��kaz z konfigura�n�ho souboru, kter� vyhovuje origin�ln�mu + * p��kazu + * @return true pokud je warmup �asova� ozna�en jako ji� prob�hl�, jinak * false */ static boolean checkWarmUpOK(Player player, String regexCommand) { int pre2 = regexCommand.toLowerCase().hashCode(); int ok = 0; ok = BoosConfigManager.getConfusers().getInt( - "users." + player.getUniqueId() - + ".warmup." + pre2, ok); + "users." + player.getUniqueId() + ".warmup." + pre2, ok); if (ok == 1) { return true; } @@ -124,29 +123,30 @@ public class BoosWarmUpManager { } /** - * Metoda vrac boolean hodnotu na zklad toho jestli je pro specifikovan - * pkaz specifikovanho hre aktivn warmup asova. + * Metoda vrac� boolean hodnotu na z�klad� toho jestli je pro specifikovan� + * p��kaz specifikovan�ho hr��e aktivn� warmup �asova�. * * @param player - * specifick hr + * specifick� hr�� * @param regexCommand - * pkaz z konfiguranho souboru, kter vyhovuje originlnmu - * pkazu - * @return true pokud je warmup asova aktivn, jinak false + * p��kaz z konfigura�n�ho souboru, kter� vyhovuje origin�ln�mu + * p��kazu + * @return true pokud je warmup �asova� aktivn�, jinak false */ static boolean isWarmUpProcess(Player player, String regexCommand) { regexCommand = regexCommand.toLowerCase(); - if (playercommands.containsKey(player.getUniqueId() + "@" + regexCommand)) { + if (playercommands.containsKey(player.getUniqueId() + "@" + + regexCommand)) { return true; } return false; } /** - * Metoda odstran vechny asovae specifikovanho hre + * Metoda odstran� v�echny �asova�e specifikovan�ho hr��e * * @param player - * specifick hr + * specifick� hr�� */ static void killTimer(Player player) { for (String key : playercommands.keySet()) { @@ -157,80 +157,77 @@ public class BoosWarmUpManager { } /** - * Metoda odstran asovae na specifikovanm pkazu specifikovanho hre + * Metoda odstran� �asova�e na specifikovan�m p��kazu specifikovan�ho hr��e * * @param player - * specifick hr + * specifick� hr�� * @param regexCommand - * pkaz z konfiguranho souboru, kter vyhovuje originlnmu - * pkazu + * p��kaz z konfigura�n�ho souboru, kter� vyhovuje origin�ln�mu + * p��kazu */ static void removeWarmUp(Player player, String regexCommand) { int pre2 = regexCommand.toLowerCase().hashCode(); BoosConfigManager.getConfusers().set( - "users." + player.getUniqueId() - + ".warmup." + pre2, null); + "users." + player.getUniqueId() + ".warmup." + pre2, null); } /** - * Metoda odstran ukonen asovae na specifikovanm pkazu - * specifikovanho hre + * Metoda odstran� ukon�en� �asova�e na specifikovan�m p��kazu + * specifikovan�ho hr��e * * @param player - * specifick hr + * specifick� hr�� * @param regexCommand - * pkaz z konfiguranho souboru, kter vyhovuje originlnmu - * pkazu + * p��kaz z konfigura�n�ho souboru, kter� vyhovuje origin�ln�mu + * p��kazu */ static void removeWarmUpOK(Player player, String regexCommand) { int pre2 = regexCommand.toLowerCase().hashCode(); BoosConfigManager.getConfusers().set( - "users." + player.getUniqueId() - + ".warmup." + pre2, null); + "users." + player.getUniqueId() + ".warmup." + pre2, null); } /** - * Metoda odstrauje dan etzec z Hashmapy + * Metoda odstra�uje dan� �et�zec z Hashmapy * * @param tag - * etzec, kter se m odstranit z Hasmapy + * �et�zec, kter� se m� odstranit z Hasmapy */ static void removeWarmUpProcess(String tag) { BoosWarmUpManager.playercommands.remove(tag); } /** - * Metoda oznauje warmup asova specifikovanho pkazu specifikovanho - * hre jako ji ukonen. + * Metoda ozna�uje warmup �asova� specifikovan�ho p��kazu specifikovan�ho + * hr��e jako ji� ukon�en�. * * @param player - * specifick hr + * specifick� hr�� * @param regexCommand - * pkaz z konfiguranho souboru, kter vyhovuje originlnmu - * pkazu + * p��kaz z konfigura�n�ho souboru, kter� vyhovuje origin�ln�mu + * p��kazu */ static void setWarmUpOK(Player player, String regexCommand) { int pre2 = regexCommand.toLowerCase().hashCode(); BoosConfigManager.getConfusers().set( - "users." + player.getUniqueId() - + ".warmup." + pre2, 1); + "users." + player.getUniqueId() + ".warmup." + pre2, 1); } /** - * Metoda spout warmup asova na zklad parametr pomoc Timer(). Pokud - * je ji warmup aktivn, odele hri zprvu kter ho o tom informuje. + * Metoda spou�t� warmup �asova� na z�klad� parametr� pomoc� Timer(). Pokud + * je ji� warmup aktivn�, ode�le hr��i zpr�vu kter� ho o tom informuje. * * @param bCoolDown - * instance tdy BoosCooldown + * instance t��dy BoosCooldown * @param player - * specifick hr + * specifick� hr�� * @param regexCommand - * pkaz z konfiguranho souboru, kter vyhovuje originlnmu - * pkazu + * p��kaz z konfigura�n�ho souboru, kter� vyhovuje origin�ln�mu + * p��kazu * @param originalCommand - * originln pkaz pouit hrem + * origin�ln� p��kaz pou�it� hr��em * @param warmUpSeconds - * warmup doba nastaven pro pkaz v sekundch + * warmup doba nastaven� pro p��kaz v sekund�ch */ static void startWarmUp(BoosCoolDown bCoolDown, Player player, String regexCommand, String originalCommand, int warmUpSeconds) { diff --git a/src/main/java/cz/boosik/boosCooldown/BoosWarmUpTimer.java b/src/main/java/cz/boosik/boosCooldown/BoosWarmUpTimer.java index f544c2a..1ffebc9 100644 --- a/src/main/java/cz/boosik/boosCooldown/BoosWarmUpTimer.java +++ b/src/main/java/cz/boosik/boosCooldown/BoosWarmUpTimer.java @@ -6,9 +6,9 @@ import java.util.TimerTask; import org.bukkit.entity.Player; /** - * Tda starajc se o samotn asovae warmup pomoc TimerTask + * T��da staraj�c� se o samotn� �asova�e warmup� pomoc� TimerTask * - * @author Jakub Kol + * @author Jakub Kol�� * */ public class BoosWarmUpTimer extends TimerTask { @@ -20,15 +20,15 @@ public class BoosWarmUpTimer extends TimerTask { /** * @param bCoolDown - * instance tdy BoosCoolDown + * instance t��dy BoosCoolDown * @param timer * @param player - * specifick hr + * specifick� hr�� * @param regexCommand - * pkaz z konfiguranho souboru, kter vyhovuje originlnmu - * pkazu + * p��kaz z konfigura�n�ho souboru, kter� vyhovuje origin�ln�mu + * p��kazu * @param originalCommand - * originln pkaz kter hr pouil + * origin�ln� p��kaz kter� hr�� pou�il */ public BoosWarmUpTimer(BoosCoolDown bCoolDown, Timer timer, Player player, String regexCommand, String originalCommand) { @@ -60,21 +60,21 @@ public class BoosWarmUpTimer extends TimerTask { if (player.isOnline() && !player.isDead() && BoosWarmUpManager.hasWarmUps(player)) { BoosWarmUpManager.setWarmUpOK(player, regexCommand); - BoosWarmUpManager.removeWarmUpProcess(player.getUniqueId() + "@" - + regexCommand); + BoosWarmUpManager.removeWarmUpProcess(player.getUniqueId() + + "@" + regexCommand); BoosWarmUpManager.clearLocWorld(player); player.chat(originalCommand); } else if (player.isOnline() && player.isDead() && BoosWarmUpManager.hasWarmUps(player)) { BoosWarmUpManager.removeWarmUp(player, regexCommand); - BoosWarmUpManager.removeWarmUpProcess(player.getUniqueId() + "@" - + regexCommand); + BoosWarmUpManager.removeWarmUpProcess(player.getUniqueId() + + "@" + regexCommand); BoosWarmUpManager.clearLocWorld(player); } else if (!player.isOnline() && BoosWarmUpManager.hasWarmUps(player)) { BoosWarmUpManager.removeWarmUp(player, regexCommand); - BoosWarmUpManager.removeWarmUpProcess(player.getUniqueId() + "@" - + regexCommand); + BoosWarmUpManager.removeWarmUpProcess(player.getUniqueId() + + "@" + regexCommand); BoosWarmUpManager.clearLocWorld(player); } } diff --git a/src/main/java/cz/boosik/boosCooldown/Listeners/BoosPlayerDeathListener.java b/src/main/java/cz/boosik/boosCooldown/Listeners/BoosPlayerDeathListener.java index 2a7dd5d..2945da6 100644 --- a/src/main/java/cz/boosik/boosCooldown/Listeners/BoosPlayerDeathListener.java +++ b/src/main/java/cz/boosik/boosCooldown/Listeners/BoosPlayerDeathListener.java @@ -11,23 +11,23 @@ import cz.boosik.boosCooldown.BoosConfigManager; import cz.boosik.boosCooldown.BoosCoolDownManager; /** - * Poslucha naslouchajc udlosti, kter se spout v okamiku kdy hr zeme. - * V zvislosti na konfiguraci pluginu a oprvnnch hre mohou nastat ti - * rzn aktivity. Cooldown asovae mohou bt po smrti vymazny, nebo naopak - * mohou bt znovu sputny veker cooldown asovae pro veker nastaven - * pkazy. Tak mohou bt vymazny zznamy o pouitch pkazu a hr bude opt - * schopen pouvat limitovan pkazy a po hodnotu limitu. + * Poslucha� naslouchaj�c� ud�losti, kter� se spou�t� v okam�iku kdy hr�� zem�e. + * V z�vislosti na konfiguraci pluginu a opr�vn�n�ch hr��e mohou nastat t�i + * r�zn� aktivity. Cooldown �asova�e mohou b�t po smrti vymaz�ny, nebo naopak + * mohou b�t znovu spu�t�ny ve�ker� cooldown �asova�e pro ve�ker� nastaven� + * p��kazy. Tak� mohou b�t vymaz�ny z�znamy o pou�it�ch p��kazu a hr�� bude op�t + * schopen pou��vat limitovan� p��kazy a� po hodnotu limitu. * - * @author Jakub Kol + * @author Jakub Kol�� * */ public class BoosPlayerDeathListener implements Listener { /** - * Metoda zjiuje jestli je entita kter spustila tuto udlost hr a - * jestli nen null. Na zklad toho spout dal metody. + * Metoda zji��uje jestli je entita kter� spustila tuto ud�lost hr�� a + * jestli nen� null. Na z�klad� toho spou�t� dal�� metody. * * @param event - * udlost PlayerDeathEvent + * ud�lost PlayerDeathEvent */ @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) private void onPlayerDeath(PlayerDeathEvent event) { @@ -41,11 +41,11 @@ public class BoosPlayerDeathListener implements Listener { } /** - * Na zklad konfigurace metoda spout vechny cooldown asovae - * specifikovanho hre tm e spust medotu startAllCooldowns();. + * Na z�klad� konfigurace metoda spou�t� v�echny cooldown �asova�e + * specifikovan�ho hr��e t�m �e spust� medotu startAllCooldowns();. * * @param player - * hr, kter spustil udlost PlayerDeathEvent + * hr��, kter� spustil ud�lost PlayerDeathEvent */ private void startCooldownsOnDeath(Player player) { if (player != null) { @@ -56,13 +56,13 @@ public class BoosPlayerDeathListener implements Listener { } /** - * Na zklad konfigurace a toho jestli hr disponuje oprvnnm - * booscooldowns.clear.uses.death metoda vymae vechny zznamy o sputn - * vech pkaz specifikovanho hre tm e spust metodu + * Na z�klad� konfigurace a toho jestli hr�� disponuje opr�vn�n�m + * booscooldowns.clear.uses.death metoda vyma�e v�echny z�znamy o spu�t�n� + * v�ech p��kaz� specifikovan�ho hr��e t�m �e spust� metodu * clearSomething();. * * @param player - * hr, kter spustil udlost PlayerDeathEvent + * hr��, kter� spustil ud�lost PlayerDeathEvent */ private void clearUsesOnDeath(Player player) { if (player != null @@ -74,19 +74,20 @@ public class BoosPlayerDeathListener implements Listener { } /** - * Na zklad konfigurace a toho jestli hr disponuje oprvnnm - * booscooldowns.clear.cooldowns.death metoda vymae vechny cooldown - * asovae vech pkaz specifikovanho hre tm e spust metodu + * Na z�klad� konfigurace a toho jestli hr�� disponuje opr�vn�n�m + * booscooldowns.clear.cooldowns.death metoda vyma�e v�echny cooldown + * �asova�e v�ech p��kaz� specifikovan�ho hr��e t�m �e spust� metodu * clearSomething();. * * @param player - * hr, kter spustil udlost PlayerDeathEvent + * hr��, kter� spustil ud�lost PlayerDeathEvent */ private void clearCooldownsOnDeath(Player player) { if (player != null && player.hasPermission("booscooldowns.clear.cooldowns.death")) { if (BoosConfigManager.getCleanCooldownsOnDeath()) { - BoosConfigManager.clearSomething("cooldown", player.getUniqueId()); + BoosConfigManager.clearSomething("cooldown", + player.getUniqueId()); } } } diff --git a/src/main/java/org/mcstats/MetricsLite.java b/src/main/java/org/mcstats/MetricsLite.java index ff1281b..3b7c2ea 100644 --- a/src/main/java/org/mcstats/MetricsLite.java +++ b/src/main/java/org/mcstats/MetricsLite.java @@ -52,462 +52,498 @@ import java.util.zip.GZIPOutputStream; public class MetricsLite { - /** - * The current revision number - */ - private final static int REVISION = 7; - - /** - * The base url of the metrics domain - */ - private static final String BASE_URL = "http://report.mcstats.org"; - - /** - * The url used to report a server's status - */ - private static final String REPORT_URL = "/plugin/%s"; - - /** - * Interval of time to ping (in minutes) - */ - private final static int PING_INTERVAL = 15; - - /** - * The plugin this metrics submits for - */ - private final Plugin plugin; - - /** - * The plugin configuration file - */ - private final YamlConfiguration configuration; - - /** - * The plugin configuration file - */ - private final File configurationFile; - - /** - * Unique server id - */ - private final String guid; - - /** - * Debug mode - */ - private final boolean debug; - - /** - * Lock for synchronization - */ - private final Object optOutLock = new Object(); - - /** - * Id of the scheduled task - */ - private volatile BukkitTask task = null; - - public MetricsLite(Plugin plugin) throws IOException { - if (plugin == null) { - throw new IllegalArgumentException("Plugin cannot be null"); - } - - this.plugin = plugin; - - // load the config - configurationFile = getConfigFile(); - configuration = YamlConfiguration.loadConfiguration(configurationFile); - - // add some defaults - configuration.addDefault("opt-out", false); - configuration.addDefault("guid", UUID.randomUUID().toString()); - configuration.addDefault("debug", false); - - // Do we need to create the file? - if (configuration.get("guid", null) == null) { - configuration.options().header("http://mcstats.org").copyDefaults(true); - configuration.save(configurationFile); - } - - // Load the guid then - guid = configuration.getString("guid"); - debug = configuration.getBoolean("debug", false); - } - - /** - * 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. - */ - public boolean start() { - synchronized (optOutLock) { - // Did we opt out? - if (isOptOut()) { - return false; - } - - // Is metrics already running? - if (task != null) { - return true; - } - - // Begin hitting the server with glorious data - task = plugin.getServer().getScheduler().runTaskTimerAsynchronously(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() && task != null) { - task.cancel(); - task = null; - } - } - - // 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) { - if (debug) { - Bukkit.getLogger().log(Level.INFO, "[Metrics] " + e.getMessage()); - } - } - } - }, 0, PING_INTERVAL * 1200); - - return true; - } - } - - /** - * Has the server owner denied plugin metrics? - * - * @return true if metrics should be opted out of it - */ - public boolean isOptOut() { - synchronized (optOutLock) { - try { - // Reload the metrics file - configuration.load(getConfigFile()); - } catch (IOException ex) { - if (debug) { - Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage()); - } - return true; - } catch (InvalidConfigurationException ex) { - if (debug) { - 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 java.io.IOException - */ - public void enable() throws IOException { - // This has to be synchronized or it can collide with the check in the task. - synchronized (optOutLock) { - // Check if the server owner has already set opt-out, if not, set it. - if (isOptOut()) { - configuration.set("opt-out", false); - configuration.save(configurationFile); - } - - // Enable Task, if it is not running - if (task == null) { - start(); - } - } - } - - /** - * Disables metrics for the server by setting "opt-out" to true in the config file and canceling the metrics task. - * - * @throws java.io.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 (task != null) { - task.cancel(); - task = null; - } - } - } - - /** - * Gets the File object of the config file that should be used to store data such as the GUID and opt-out status - * - * @return the File object for the config file - */ - public File getConfigFile() { - // I believe the easiest way to get the base folder (e.g craftbukkit set via -P) for plugins to use - // is to abuse the plugin object we already have - // plugin.getDataFolder() => base/plugins/PluginA/ - // pluginsFolder => base/plugins/ - // The base is not necessarily relative to the startup directory. - File pluginsFolder = plugin.getDataFolder().getParentFile(); - - // return => base/plugins/PluginMetrics/config.yml - return new File(new File(pluginsFolder, "PluginMetrics"), "config.yml"); - } - - /** - * Generic method that posts a plugin to the metrics website - */ - private void postPlugin(boolean isPing) throws IOException { - // Server software specific section - PluginDescriptionFile description = plugin.getDescription(); - String pluginName = description.getName(); - boolean onlineMode = Bukkit.getServer().getOnlineMode(); // TRUE if online mode is enabled - String pluginVersion = description.getVersion(); - String serverVersion = Bukkit.getVersion(); - int playersOnline = Bukkit.getServer().getOnlinePlayers().size(); - - // END server software specific section -- all code below does not use any code outside of this class / Java - - // Construct the post data - StringBuilder json = new StringBuilder(1024); - json.append('{'); - - // The plugin's description file containg all of the plugin data such as name, version, author, etc - appendJSONPair(json, "guid", guid); - appendJSONPair(json, "plugin_version", pluginVersion); - appendJSONPair(json, "server_version", serverVersion); - appendJSONPair(json, "players_online", Integer.toString(playersOnline)); - - // New data as of R6 - String osname = System.getProperty("os.name"); - String osarch = System.getProperty("os.arch"); - String osversion = System.getProperty("os.version"); - String java_version = System.getProperty("java.version"); - int coreCount = Runtime.getRuntime().availableProcessors(); - - // normalize os arch .. amd64 -> x86_64 - if (osarch.equals("amd64")) { - osarch = "x86_64"; - } - - appendJSONPair(json, "osname", osname); - appendJSONPair(json, "osarch", osarch); - appendJSONPair(json, "osversion", osversion); - appendJSONPair(json, "cores", Integer.toString(coreCount)); - appendJSONPair(json, "auth_mode", onlineMode ? "1" : "0"); - appendJSONPair(json, "java_version", java_version); - - // If we're pinging, append it - if (isPing) { - appendJSONPair(json, "ping", "1"); - } - - // close json - json.append('}'); - - // Create the url - URL url = new URL(BASE_URL + String.format(REPORT_URL, urlEncode(pluginName))); - - // 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(); - } - - - byte[] uncompressed = json.toString().getBytes(); - byte[] compressed = gzip(json.toString()); - - // Headers - connection.addRequestProperty("User-Agent", "MCStats/" + REVISION); - connection.addRequestProperty("Content-Type", "application/json"); - connection.addRequestProperty("Content-Encoding", "gzip"); - connection.addRequestProperty("Content-Length", Integer.toString(compressed.length)); - connection.addRequestProperty("Accept", "application/json"); - connection.addRequestProperty("Connection", "close"); - - connection.setDoOutput(true); - - if (debug) { - System.out.println("[Metrics] Prepared request for " + pluginName + " uncompressed=" + uncompressed.length + " compressed=" + compressed.length); - } - - // Write the data - OutputStream os = connection.getOutputStream(); - os.write(compressed); - os.flush(); - - // Now read the response - final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); - String response = reader.readLine(); - - // close resources - os.close(); - reader.close(); - - if (response == null || response.startsWith("ERR") || response.startsWith("7")) { - if (response == null) { - response = "null"; - } else if (response.startsWith("7")) { - response = response.substring(response.startsWith("7,") ? 2 : 1); - } - - throw new IOException(response); - } - } - - /** - * GZip compress a string of bytes - * - * @param input - * @return - */ - public static byte[] gzip(String input) { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - GZIPOutputStream gzos = null; - - try { - gzos = new GZIPOutputStream(baos); - gzos.write(input.getBytes("UTF-8")); - } catch (IOException e) { - e.printStackTrace(); - } finally { - if (gzos != null) try { - gzos.close(); - } catch (IOException ignore) { - } - } - - return baos.toByteArray(); - } - - /** - * Check if mineshafter is present. If it is, we need to bypass it to send POST requests - * - * @return true if mineshafter is installed on the server - */ - private boolean isMineshafterPresent() { - try { - Class.forName("mineshafter.MineServer"); - return true; - } catch (Exception e) { - return false; - } - } - - /** - * Appends a json encoded key/value pair to the given string builder. - * - * @param json - * @param key - * @param value - * @throws UnsupportedEncodingException - */ - private static void appendJSONPair(StringBuilder json, String key, String value) throws UnsupportedEncodingException { - boolean isValueNumeric = false; - - try { - if (value.equals("0") || !value.endsWith("0")) { - Double.parseDouble(value); - isValueNumeric = true; - } - } catch (NumberFormatException e) { - isValueNumeric = false; - } - - if (json.charAt(json.length() - 1) != '{') { - json.append(','); - } - - json.append(escapeJSON(key)); - json.append(':'); - - if (isValueNumeric) { - json.append(value); - } else { - json.append(escapeJSON(value)); - } - } - - /** - * Escape a string to create a valid JSON string - * - * @param text - * @return - */ - private static String escapeJSON(String text) { - StringBuilder builder = new StringBuilder(); - - builder.append('"'); - for (int index = 0; index < text.length(); index++) { - char chr = text.charAt(index); - - switch (chr) { - case '"': - case '\\': - builder.append('\\'); - builder.append(chr); - break; - case '\b': - builder.append("\\b"); - break; - case '\t': - builder.append("\\t"); - break; - case '\n': - builder.append("\\n"); - break; - case '\r': - builder.append("\\r"); - break; - default: - if (chr < ' ') { - String t = "000" + Integer.toHexString(chr); - builder.append("\\u" + t.substring(t.length() - 4)); - } else { - builder.append(chr); - } - break; - } - } - builder.append('"'); - - return builder.toString(); - } - - /** - * Encode text as UTF-8 - * - * @param text the text to encode - * @return the encoded text, as UTF-8 - */ - private static String urlEncode(final String text) throws UnsupportedEncodingException { - return URLEncoder.encode(text, "UTF-8"); - } + /** + * The current revision number + */ + private final static int REVISION = 7; + + /** + * The base url of the metrics domain + */ + private static final String BASE_URL = "http://report.mcstats.org"; + + /** + * The url used to report a server's status + */ + private static final String REPORT_URL = "/plugin/%s"; + + /** + * Interval of time to ping (in minutes) + */ + private final static int PING_INTERVAL = 15; + + /** + * The plugin this metrics submits for + */ + private final Plugin plugin; + + /** + * The plugin configuration file + */ + private final YamlConfiguration configuration; + + /** + * The plugin configuration file + */ + private final File configurationFile; + + /** + * Unique server id + */ + private final String guid; + + /** + * Debug mode + */ + private final boolean debug; + + /** + * Lock for synchronization + */ + private final Object optOutLock = new Object(); + + /** + * Id of the scheduled task + */ + private volatile BukkitTask task = null; + + public MetricsLite(Plugin plugin) throws IOException { + if (plugin == null) { + throw new IllegalArgumentException("Plugin cannot be null"); + } + + this.plugin = plugin; + + // load the config + configurationFile = getConfigFile(); + configuration = YamlConfiguration.loadConfiguration(configurationFile); + + // add some defaults + configuration.addDefault("opt-out", false); + configuration.addDefault("guid", UUID.randomUUID().toString()); + configuration.addDefault("debug", false); + + // Do we need to create the file? + if (configuration.get("guid", null) == null) { + configuration.options().header("http://mcstats.org") + .copyDefaults(true); + configuration.save(configurationFile); + } + + // Load the guid then + guid = configuration.getString("guid"); + debug = configuration.getBoolean("debug", false); + } + + /** + * 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. + */ + public boolean start() { + synchronized (optOutLock) { + // Did we opt out? + if (isOptOut()) { + return false; + } + + // Is metrics already running? + if (task != null) { + return true; + } + + // Begin hitting the server with glorious data + task = plugin.getServer().getScheduler() + .runTaskTimerAsynchronously(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() && task != null) { + task.cancel(); + task = null; + } + } + + // 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) { + if (debug) { + Bukkit.getLogger().log(Level.INFO, + "[Metrics] " + e.getMessage()); + } + } + } + }, 0, PING_INTERVAL * 1200); + + return true; + } + } + + /** + * Has the server owner denied plugin metrics? + * + * @return true if metrics should be opted out of it + */ + public boolean isOptOut() { + synchronized (optOutLock) { + try { + // Reload the metrics file + configuration.load(getConfigFile()); + } catch (IOException ex) { + if (debug) { + Bukkit.getLogger().log(Level.INFO, + "[Metrics] " + ex.getMessage()); + } + return true; + } catch (InvalidConfigurationException ex) { + if (debug) { + 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 java.io.IOException + */ + public void enable() throws IOException { + // This has to be synchronized or it can collide with the check in the + // task. + synchronized (optOutLock) { + // Check if the server owner has already set opt-out, if not, set + // it. + if (isOptOut()) { + configuration.set("opt-out", false); + configuration.save(configurationFile); + } + + // Enable Task, if it is not running + if (task == null) { + start(); + } + } + } + + /** + * Disables metrics for the server by setting "opt-out" to true in the + * config file and canceling the metrics task. + * + * @throws java.io.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 (task != null) { + task.cancel(); + task = null; + } + } + } + + /** + * Gets the File object of the config file that should be used to store data + * such as the GUID and opt-out status + * + * @return the File object for the config file + */ + public File getConfigFile() { + // I believe the easiest way to get the base folder (e.g craftbukkit set + // via -P) for plugins to use + // is to abuse the plugin object we already have + // plugin.getDataFolder() => base/plugins/PluginA/ + // pluginsFolder => base/plugins/ + // The base is not necessarily relative to the startup directory. + File pluginsFolder = plugin.getDataFolder().getParentFile(); + + // return => base/plugins/PluginMetrics/config.yml + return new File(new File(pluginsFolder, "PluginMetrics"), "config.yml"); + } + + /** + * Generic method that posts a plugin to the metrics website + */ + private void postPlugin(boolean isPing) throws IOException { + // Server software specific section + PluginDescriptionFile description = plugin.getDescription(); + String pluginName = description.getName(); + boolean onlineMode = Bukkit.getServer().getOnlineMode(); // TRUE if + // online + // mode is + // enabled + String pluginVersion = description.getVersion(); + String serverVersion = Bukkit.getVersion(); + int playersOnline = Bukkit.getServer().getOnlinePlayers().size(); + + // END server software specific section -- all code below does not use + // any code outside of this class / Java + + // Construct the post data + StringBuilder json = new StringBuilder(1024); + json.append('{'); + + // The plugin's description file containg all of the plugin data such as + // name, version, author, etc + appendJSONPair(json, "guid", guid); + appendJSONPair(json, "plugin_version", pluginVersion); + appendJSONPair(json, "server_version", serverVersion); + appendJSONPair(json, "players_online", Integer.toString(playersOnline)); + + // New data as of R6 + String osname = System.getProperty("os.name"); + String osarch = System.getProperty("os.arch"); + String osversion = System.getProperty("os.version"); + String java_version = System.getProperty("java.version"); + int coreCount = Runtime.getRuntime().availableProcessors(); + + // normalize os arch .. amd64 -> x86_64 + if (osarch.equals("amd64")) { + osarch = "x86_64"; + } + + appendJSONPair(json, "osname", osname); + appendJSONPair(json, "osarch", osarch); + appendJSONPair(json, "osversion", osversion); + appendJSONPair(json, "cores", Integer.toString(coreCount)); + appendJSONPair(json, "auth_mode", onlineMode ? "1" : "0"); + appendJSONPair(json, "java_version", java_version); + + // If we're pinging, append it + if (isPing) { + appendJSONPair(json, "ping", "1"); + } + + // close json + json.append('}'); + + // Create the url + URL url = new URL(BASE_URL + + String.format(REPORT_URL, urlEncode(pluginName))); + + // 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(); + } + + byte[] uncompressed = json.toString().getBytes(); + byte[] compressed = gzip(json.toString()); + + // Headers + connection.addRequestProperty("User-Agent", "MCStats/" + REVISION); + connection.addRequestProperty("Content-Type", "application/json"); + connection.addRequestProperty("Content-Encoding", "gzip"); + connection.addRequestProperty("Content-Length", + Integer.toString(compressed.length)); + connection.addRequestProperty("Accept", "application/json"); + connection.addRequestProperty("Connection", "close"); + + connection.setDoOutput(true); + + if (debug) { + System.out.println("[Metrics] Prepared request for " + pluginName + + " uncompressed=" + uncompressed.length + " compressed=" + + compressed.length); + } + + // Write the data + OutputStream os = connection.getOutputStream(); + os.write(compressed); + os.flush(); + + // Now read the response + final BufferedReader reader = new BufferedReader(new InputStreamReader( + connection.getInputStream())); + String response = reader.readLine(); + + // close resources + os.close(); + reader.close(); + + if (response == null || response.startsWith("ERR") + || response.startsWith("7")) { + if (response == null) { + response = "null"; + } else if (response.startsWith("7")) { + response = response + .substring(response.startsWith("7,") ? 2 : 1); + } + + throw new IOException(response); + } + } + + /** + * GZip compress a string of bytes + * + * @param input + * @return + */ + public static byte[] gzip(String input) { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + GZIPOutputStream gzos = null; + + try { + gzos = new GZIPOutputStream(baos); + gzos.write(input.getBytes("UTF-8")); + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (gzos != null) + try { + gzos.close(); + } catch (IOException ignore) { + } + } + + return baos.toByteArray(); + } + + /** + * Check if mineshafter is present. If it is, we need to bypass it to send + * POST requests + * + * @return true if mineshafter is installed on the server + */ + private boolean isMineshafterPresent() { + try { + Class.forName("mineshafter.MineServer"); + return true; + } catch (Exception e) { + return false; + } + } + + /** + * Appends a json encoded key/value pair to the given string builder. + * + * @param json + * @param key + * @param value + * @throws UnsupportedEncodingException + */ + private static void appendJSONPair(StringBuilder json, String key, + String value) throws UnsupportedEncodingException { + boolean isValueNumeric = false; + + try { + if (value.equals("0") || !value.endsWith("0")) { + Double.parseDouble(value); + isValueNumeric = true; + } + } catch (NumberFormatException e) { + isValueNumeric = false; + } + + if (json.charAt(json.length() - 1) != '{') { + json.append(','); + } + + json.append(escapeJSON(key)); + json.append(':'); + + if (isValueNumeric) { + json.append(value); + } else { + json.append(escapeJSON(value)); + } + } + + /** + * Escape a string to create a valid JSON string + * + * @param text + * @return + */ + private static String escapeJSON(String text) { + StringBuilder builder = new StringBuilder(); + + builder.append('"'); + for (int index = 0; index < text.length(); index++) { + char chr = text.charAt(index); + + switch (chr) { + case '"': + case '\\': + builder.append('\\'); + builder.append(chr); + break; + case '\b': + builder.append("\\b"); + break; + case '\t': + builder.append("\\t"); + break; + case '\n': + builder.append("\\n"); + break; + case '\r': + builder.append("\\r"); + break; + default: + if (chr < ' ') { + String t = "000" + Integer.toHexString(chr); + builder.append("\\u" + t.substring(t.length() - 4)); + } else { + builder.append(chr); + } + break; + } + } + builder.append('"'); + + return builder.toString(); + } + + /** + * Encode text as UTF-8 + * + * @param text + * the text to encode + * @return the encoded text, as UTF-8 + */ + private static String urlEncode(final String text) + throws UnsupportedEncodingException { + return URLEncoder.encode(text, "UTF-8"); + } } \ No newline at end of file