Formated sources, fixed commands losing case

This commit is contained in:
Boosik 2014-08-01 20:57:33 +02:00
parent bf47381423
commit b72aaf3df5
10 changed files with 736 additions and 703 deletions

View File

@ -74,12 +74,10 @@ public class BoosConfigManager {
*/ */
public static void clearSomething(String co, UUID uuid) { public static void clearSomething(String co, UUID uuid) {
ConfigurationSection userSection = confusers ConfigurationSection userSection = confusers
.getConfigurationSection("users." .getConfigurationSection("users." + uuid + "." + co);
+ uuid + "." + co);
if (userSection == null) if (userSection == null)
return; return;
confusers.set("users." + uuid + "." + co, confusers.set("users." + uuid + "." + co, null);
null);
saveConfusers(); saveConfusers();
loadConfusers(); loadConfusers();
} }
@ -97,8 +95,7 @@ public class BoosConfigManager {
*/ */
static void clearSomething(String co, UUID uuid, String command) { static void clearSomething(String co, UUID uuid, String command) {
int pre2 = command.toLowerCase().hashCode(); int pre2 = command.toLowerCase().hashCode();
confusers.set("users." + uuid + "." + co confusers.set("users." + uuid + "." + co + "." + pre2, 0);
+ "." + pre2, 0);
saveConfusers(); saveConfusers();
loadConfusers(); loadConfusers();
} }
@ -119,6 +116,15 @@ public class BoosConfigManager {
.getKeys(false); .getKeys(false);
return aliases; return aliases;
} }
/**
* @return
*/
static Set<String> getAliasesKeys() {
Set<String> aliases = conf.getConfigurationSection("commands.aliases")
.getKeys(true);
return aliases;
}
/** /**
* @return * @return
@ -725,10 +731,12 @@ public class BoosConfigManager {
try { try {
value2 = Integer.parseInt(value); value2 = Integer.parseInt(value);
reload(); reload();
conf.set("commands.groups." + group + "." + command + "." + what, value2); conf.set("commands.groups." + group + "." + command + "." + what,
value2);
} catch (NumberFormatException e1) { } catch (NumberFormatException e1) {
reload(); reload();
conf.set("commands.groups." + group + "." + command + "." + what, value); conf.set("commands.groups." + group + "." + command + "." + what,
value);
} }
try { try {
conf.save(confFile); conf.save(confFile);

View File

@ -11,10 +11,9 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import util.boosChat; import util.boosChat;
/** /**
* Hlavn<EFBFBD> poslucha<EFBFBD>, kter<EFBFBD> naslouch<EFBFBD> ud<EFBFBD>losti pou<EFBFBD>it<EFBFBD> p<EFBFBD><EFBFBD>kazu * Hlavn<EFBFBD> poslucha<EFBFBD>, kter<EFBFBD> naslouch<EFBFBD> ud<EFBFBD>losti pou<EFBFBD>it<EFBFBD> p<EFBFBD><EFBFBD>kazu hr<EFBFBD><EFBFBD>em.
* hr<EFBFBD><EFBFBD>em. Kontroluje, jestli jsou pro p<EFBFBD><EFBFBD>kaz nastaveny omezen<EFBFBD> a na * Kontroluje, jestli jsou pro p<EFBFBD><EFBFBD>kaz nastaveny omezen<EFBFBD> a na z<EFBFBD>klad<EFBFBD> tohoto
* z<EFBFBD>klad<EFBFBD> tohoto spou<EFBFBD>t<EFBFBD> <EFBFBD>asova<EFBFBD>e a vol<EFBFBD> metody spojen<EFBFBD> s * spou<EFBFBD>t<EFBFBD> <EFBFBD>asova<EFBFBD>e a vol<EFBFBD> metody spojen<EFBFBD> s poplatky a limity.
* poplatky a limity.
* *
* @author Jakub Kol<EFBFBD><EFBFBD> * @author Jakub Kol<EFBFBD><EFBFBD>
* *
@ -30,18 +29,17 @@ public class BoosCoolDownListener implements Listener {
} }
/** /**
* Metoda zkontroluje pomoc<EFBFBD> vol<EFBFBD>n<EFBFBD> dal<EFBFBD><EFBFBD>ch metod, jestli p<EFBFBD>ikaz * Metoda zkontroluje pomoc<EFBFBD> vol<EFBFBD>n<EFBFBD> dal<EFBFBD><EFBFBD>ch metod, jestli p<EFBFBD>ikaz kter<EFBFBD> hr<EFBFBD><EFBFBD>
* kter<EFBFBD> hr<EFBFBD><EFBFBD> pou<EFBFBD>il je n<EFBFBD>jak<EFBFBD>m zp<EFBFBD>sobem omezen<EFBFBD> a na * pou<EFBFBD>il je n<EFBFBD>jak<EFBFBD>m zp<EFBFBD>sobem omezen<EFBFBD> a na z<EFBFBD>klad<EFBFBD> toho je bu<EFBFBD> ud<EFBFBD>lost
* z<EFBFBD>klad<EFBFBD> toho je bu<EFBFBD> ud<EFBFBD>lost pou<EFBFBD>it<EFBFBD> p<EFBFBD><EFBFBD>kazu stornov<EFBFBD>na, * pou<EFBFBD>it<EFBFBD> p<EFBFBD><EFBFBD>kazu stornov<EFBFBD>na, nebo ne.
* nebo ne.
* *
* @param event * @param event
* ud<EFBFBD>lost PlayerCommandPreprocessEvent * ud<EFBFBD>lost PlayerCommandPreprocessEvent
* @param player * @param player
* hr<EFBFBD><EFBFBD> kter<EFBFBD> spustil tuto ud<EFBFBD>lost * hr<EFBFBD><EFBFBD> kter<EFBFBD> spustil tuto ud<EFBFBD>lost
* @param regexCommad * @param regexCommad
* p<EFBFBD><EFBFBD>kaz z konfigura<EFBFBD>n<EFBFBD>ho souboru, kter<EFBFBD> vyhovuje * p<EFBFBD><EFBFBD>kaz z konfigura<EFBFBD>n<EFBFBD>ho souboru, kter<EFBFBD> vyhovuje origin<EFBFBD>ln<EFBFBD>mu
* origin<EFBFBD>ln<EFBFBD>mu p<EFBFBD><EFBFBD>kazu * p<EFBFBD><EFBFBD>kazu
* @param originalCommand * @param originalCommand
* origin<EFBFBD>ln<EFBFBD> p<EFBFBD><EFBFBD>kaz kter<EFBFBD> hr<EFBFBD><EFBFBD> pou<EFBFBD>il * origin<EFBFBD>ln<EFBFBD> p<EFBFBD><EFBFBD>kaz kter<EFBFBD> hr<EFBFBD><EFBFBD> pou<EFBFBD>il
* @param warmupTime * @param warmupTime
@ -105,8 +103,8 @@ public class BoosCoolDownListener implements Listener {
BoosConfigManager.getInsufficientFundsMessage(), BoosConfigManager.getInsufficientFundsMessage(),
(price + " " + unit), (price + " " + unit),
BoosCoolDown.getEconomy().format( BoosCoolDown.getEconomy().format(
BoosCoolDown.getEconomy().getBalance( BoosCoolDown.getEconomy()
player))); .getBalance(player)));
msg = msg.replaceAll("&command&", originalCommand); msg = msg.replaceAll("&command&", originalCommand);
boosChat.sendMessageToPlayer(player, msg); boosChat.sendMessageToPlayer(player, msg);
} }
@ -154,14 +152,12 @@ public class BoosCoolDownListener implements Listener {
} }
/** /**
* Poslucha<EFBFBD>, kter<EFBFBD> naslouch<EFBFBD> ud<EFBFBD>losti pou<EFBFBD>it<EFBFBD> p<EFBFBD><EFBFBD>kazu a * Poslucha<EFBFBD>, kter<EFBFBD> naslouch<EFBFBD> ud<EFBFBD>losti pou<EFBFBD>it<EFBFBD> p<EFBFBD><EFBFBD>kazu a spou<EFBFBD>t<EFBFBD> se je<EFBFBD>t<EFBFBD>
* spou<EFBFBD>t<EFBFBD> se je<EFBFBD>t<EFBFBD> p<EFBFBD>ed t<EFBFBD>m, ne<EFBFBD> je vykon<EFBFBD>n efekt tohto * p<EFBFBD>ed t<EFBFBD>m, ne<EFBFBD> je vykon<EFBFBD>n efekt tohto p<EFBFBD><EFBFBD>kazu. Metoda zji<EFBFBD><EFBFBD>uje, jestli
* p<EFBFBD><EFBFBD>kazu. Metoda zji<EFBFBD><EFBFBD>uje, jestli p<EFBFBD><EFBFBD>kaz nen<EFBFBD> alias jin<EFBFBD>ho * p<EFBFBD><EFBFBD>kaz nen<EFBFBD> alias jin<EFBFBD>ho p<EFBFBD><EFBFBD>kazu a tak<EFBFBD> jestli se p<EFBFBD><EFBFBD>kaz kter<EFBFBD> hr<EFBFBD><EFBFBD>
* p<EFBFBD><EFBFBD>kazu a tak<EFBFBD> jestli se p<EFBFBD><EFBFBD>kaz kter<EFBFBD> hr<EFBFBD><EFBFBD> pou<EFBFBD>il * pou<EFBFBD>il shoduje s p<EFBFBD><EFBFBD>kazem nastaven<EFBFBD>m v konfiguraci. Pokud se shoduje, pak
* shoduje s p<EFBFBD><EFBFBD>kazem nastaven<EFBFBD>m v konfiguraci. Pokud se shoduje, pak * jsou na<EFBFBD>teny informace o warmup dob<EFBFBD>, cooldown dob<EFBFBD>, poplatku a limitu.
* jsou na<EFBFBD>teny informace o warmup dob<EFBFBD>, cooldown dob<EFBFBD>, poplatku a * Tyto hodnoty jsou pot<EFBFBD> p<EFBFBD>ed<EFBFBD>ny metod<EFBFBD> checkRestrictions();.
* limitu. Tyto hodnoty jsou pot<EFBFBD> p<EFBFBD>ed<EFBFBD>ny metod<EFBFBD>
* checkRestrictions();.
* *
* @param event * @param event
* ud<EFBFBD>lost PlayerCommandPreprocessEvent * ud<EFBFBD>lost PlayerCommandPreprocessEvent
@ -171,17 +167,16 @@ public class BoosCoolDownListener implements Listener {
Player player = event.getPlayer(); Player player = event.getPlayer();
String originalCommand = event.getMessage().replace("\\", "\\\\"); String originalCommand = event.getMessage().replace("\\", "\\\\");
originalCommand = originalCommand.replace("$", "S"); originalCommand = originalCommand.replace("$", "S");
originalCommand = originalCommand.trim().replaceAll(" +", " ") originalCommand = originalCommand.trim().replaceAll(" +", " ");
.toLowerCase();
String regexCommad = ""; String regexCommad = "";
Set<String> aliases = null; Set<String> aliases = null;
try { try {
aliases = BoosConfigManager.getAliases(); aliases = BoosConfigManager.getAliases();
} catch (Exception e1) { } catch (Exception e1) {
BoosCoolDown BoosCoolDown
.getLog() .getLog()
.warning( .warning(
"Aliases section in config.yml is missing! Please delete your config.yml, restart server and set it again!"); "Aliases section in config.yml is missing! Please delete your config.yml, restart server and set it again!");
} }
Set<String> commands = BoosConfigManager.getCommands(player); Set<String> commands = BoosConfigManager.getCommands(player);
boolean on = true; boolean on = true;
@ -214,7 +209,7 @@ public class BoosCoolDownListener implements Listener {
if (on) { if (on) {
for (String group : commands) { for (String group : commands) {
String group2 = group.replace("*", ".+"); String group2 = group.replace("*", ".+");
if (originalCommand.matches(group2)) { if (originalCommand.matches("(?i)"+group2)) {
regexCommad = group; regexCommad = group;
if (BoosConfigManager.getWarmupEnabled()) { if (BoosConfigManager.getWarmupEnabled()) {
warmupTime = BoosConfigManager.getWarmUp(regexCommad, warmupTime = BoosConfigManager.getWarmUp(regexCommad,
@ -250,16 +245,16 @@ public class BoosCoolDownListener implements Listener {
} }
/** /**
* Metoda spou<EFBFBD>t<EFBFBD> warmup a cooldown <EFBFBD>asova<EFBFBD>e, p<EFBFBD><EFBFBD>padn<EFBFBD> je * Metoda spou<EFBFBD>t<EFBFBD> warmup a cooldown <EFBFBD>asova<EFBFBD>e, p<EFBFBD><EFBFBD>padn<EFBFBD> je ukon<EFBFBD>uje, pokud
* ukon<EFBFBD>uje, pokud ji<EFBFBD> tyto <EFBFBD>asova<EFBFBD>e skon<EFBFBD>ili. * ji<EFBFBD> tyto <EFBFBD>asova<EFBFBD>e skon<EFBFBD>ili.
* *
* @param event * @param event
* ud<EFBFBD>lost PlayerCommandPreprocessEvent * ud<EFBFBD>lost PlayerCommandPreprocessEvent
* @param player * @param player
* hr<EFBFBD><EFBFBD> kter<EFBFBD> spustil tuto ud<EFBFBD>lost * hr<EFBFBD><EFBFBD> kter<EFBFBD> spustil tuto ud<EFBFBD>lost
* @param regexCommad * @param regexCommad
* p<EFBFBD><EFBFBD>kaz z konfigura<EFBFBD>n<EFBFBD>ho souboru, kter<EFBFBD> vyhovuje * p<EFBFBD><EFBFBD>kaz z konfigura<EFBFBD>n<EFBFBD>ho souboru, kter<EFBFBD> vyhovuje origin<EFBFBD>ln<EFBFBD>mu
* origin<EFBFBD>ln<EFBFBD>mu p<EFBFBD><EFBFBD>kazu * p<EFBFBD><EFBFBD>kazu
* @param originalCommand * @param originalCommand
* origin<EFBFBD>ln<EFBFBD> p<EFBFBD><EFBFBD>kaz kter<EFBFBD> hr<EFBFBD><EFBFBD> pou<EFBFBD>il * origin<EFBFBD>ln<EFBFBD> p<EFBFBD><EFBFBD>kaz kter<EFBFBD> hr<EFBFBD><EFBFBD> pou<EFBFBD>il
* @param warmupTime * @param warmupTime

View File

@ -11,42 +11,41 @@ import org.bukkit.entity.Player;
import util.boosChat; import util.boosChat;
/** /**
* Třída obsahuje veškeré metody potřebné k řízení cooldown časovačů. Spouštění, * T<EFBFBD><EFBFBD>da obsahuje ve<EFBFBD>ker<EFBFBD> metody pot<EFBFBD>ebn<EFBFBD> k <EFBFBD><EFBFBD>zen<EFBFBD> cooldown <EFBFBD>asova<EFBFBD><EFBFBD>. Spou<EFBFBD>t<EFBFBD>n<EFBFBD>,
* ukončování, zjišťování zda je cooldown časovač již aktivní. * ukon<EFBFBD>ov<EFBFBD>n<EFBFBD>, zji<EFBFBD><EFBFBD>ov<EFBFBD>n<EFBFBD> zda je cooldown <EFBFBD>asova<EFBFBD> ji<EFBFBD> aktivn<EFBFBD>.
* *
* @author Jakub Kolář * @author Jakub Kol<EFBFBD><EFBFBD>
* *
*/ */
public class BoosCoolDownManager { public class BoosCoolDownManager {
/** /**
* Metoda ukončuje specifikovaný cooldown časovač pro specifikovaného hráče. * Metoda ukon<EFBFBD>uje specifikovan<EFBFBD> cooldown <EFBFBD>asova<EFBFBD> pro specifikovan<EFBFBD>ho hr<EFBFBD><EFBFBD>e.
* *
* @param player * @param player
* specifický hráč * specifick<EFBFBD> hr<EFBFBD><EFBFBD>
* @param regexCommand * @param regexCommand
* příkaz z konfigurace vyhovující originálnímu příkazu * p<EFBFBD><EFBFBD>kaz z konfigurace vyhovuj<EFBFBD>c<EFBFBD> origin<EFBFBD>ln<EFBFBD>mu p<EFBFBD><EFBFBD>kazu
*/ */
static void cancelCooldown(Player player, String regexCommand) { static void cancelCooldown(Player player, String regexCommand) {
int pre2 = regexCommand.toLowerCase().hashCode(); int pre2 = regexCommand.toLowerCase().hashCode();
BoosConfigManager.getConfusers().set( BoosConfigManager.getConfusers().set(
"users." + player.getUniqueId() + ".cooldown." "users." + player.getUniqueId() + ".cooldown." + pre2, null);
+ pre2, null);
} }
/** /**
* Metoda vrací hodnotu boolean na základě toho, jestli specifikovaný * Metoda vrac<EFBFBD> hodnotu boolean na z<EFBFBD>klad<EFBFBD> toho, jestli m<EFBFBD> specifikovan<EFBFBD>
* příkaz aktivní cooldown časovač. * p<EFBFBD><EFBFBD>kaz aktivn<EFBFBD> cooldown <EFBFBD>asova<EFBFBD>.
* *
* @param player * @param player
* specifikovaný hráč * specifikovan<EFBFBD> hr<EFBFBD><EFBFBD>
* @param regexCommand * @param regexCommand
* příkaz z konfigurace vyhovující originálnímu příkazu * p<EFBFBD><EFBFBD>kaz z konfigurace vyhovuj<EFBFBD>c<EFBFBD> origin<EFBFBD>ln<EFBFBD>mu p<EFBFBD><EFBFBD>kazu
* @param originalCommand * @param originalCommand
* originální příkaz použitý hráčem * origin<EFBFBD>ln<EFBFBD> p<EFBFBD><EFBFBD>kaz pou<EFBFBD>it<EFBFBD> hr<EFBFBD><EFBFBD>em
* @param coolDownSeconds * @param coolDownSeconds
* cooldown doba v sekundách, nastavená pro regexCommand v * cooldown doba v sekund<EFBFBD>ch, nastaven<EFBFBD> pro regexCommand v
* konfiguraci * konfiguraci
* @return true pokud je příkaz na cooldown časovači, jinak false * @return true pokud je p<EFBFBD><EFBFBD>kaz na cooldown <EFBFBD>asova<EFBFBD>i, jinak false
*/ */
static boolean cd(Player player, String regexCommand, static boolean cd(Player player, String regexCommand,
String originalCommand, int coolDownSeconds) { String originalCommand, int coolDownSeconds) {
@ -110,21 +109,21 @@ public class BoosCoolDownManager {
} }
/** /**
* Metoda kontroluje, jestli hráč nedisponuje oprávněními, která obcházejí * Metoda kontroluje, jestli hr<EFBFBD><EFBFBD> nedisponuje opr<EFBFBD>vn<EFBFBD>n<EFBFBD>mi, kter<EFBFBD> obch<EFBFBD>zej<EFBFBD>
* cooldown časovače. Pokud těmito oprávněními hráč disponuje, pak metoda * cooldown <EFBFBD>asova<EFBFBD>e. Pokud t<EFBFBD>mito opr<EFBFBD>vn<EFBFBD>n<EFBFBD>mi hr<EFBFBD><EFBFBD> disponuje, pak metoda
* vrací false. Pokud hráč nedisponuje těmito oprávněními, vrací hodnotu * vrac<EFBFBD> false. Pokud hr<EFBFBD><EFBFBD> nedisponuje t<EFBFBD>mito opr<EFBFBD>vn<EFBFBD>n<EFBFBD>mi, vrac<EFBFBD> hodnotu
* vrácenou metodou cd();. * vr<EFBFBD>cenou metodou cd();.
* *
* @param player * @param player
* specifikovaný hráč * specifikovan<EFBFBD> hr<EFBFBD><EFBFBD>
* @param regexCommand * @param regexCommand
* příkaz z konfigurace vyhovující originálnímu příkazu * p<EFBFBD><EFBFBD>kaz z konfigurace vyhovuj<EFBFBD>c<EFBFBD> origin<EFBFBD>ln<EFBFBD>mu p<EFBFBD><EFBFBD>kazu
* @param originalCommand * @param originalCommand
* originální příkaz použitý hráčem * origin<EFBFBD>ln<EFBFBD> p<EFBFBD><EFBFBD>kaz pou<EFBFBD>it<EFBFBD> hr<EFBFBD><EFBFBD>em
* @param time * @param time
* cooldown doba v sekundách, nastavená pro regexCommand v * cooldown doba v sekund<EFBFBD>ch, nastaven<EFBFBD> pro regexCommand v
* konfiguraci * konfiguraci
* @return false pokud hráč disponuje oprávněními, jinak hodnotu vrácenou * @return false pokud hr<EFBFBD><EFBFBD> disponuje opr<EFBFBD>vn<EFBFBD>n<EFBFBD>mi, jinak hodnotu vr<EFBFBD>cenou
* metodou cd();. * metodou cd();.
*/ */
static boolean coolDown(Player player, String regexCommand, static boolean coolDown(Player player, String regexCommand,
@ -140,9 +139,9 @@ public class BoosCoolDownManager {
} }
/** /**
* Metoda vrací současný přesný datum a čas. * Metoda vrac<EFBFBD> sou<EFBFBD>asn<EFBFBD> p<EFBFBD>esn<EFBFBD> datum a <EFBFBD>as.
* *
* @return současný čas a datum * @return sou<EFBFBD>asn<EFBFBD> <EFBFBD>as a datum
*/ */
static Date getCurrTime() { static Date getCurrTime() {
String currTime = ""; String currTime = "";
@ -160,13 +159,13 @@ public class BoosCoolDownManager {
} }
/** /**
* Metoda vrací datum a čas, kdy hráč naposledy použil daný příkaz. * Metoda vrac<EFBFBD> datum a <EFBFBD>as, kdy hr<EFBFBD><EFBFBD> naposledy pou<EFBFBD>il dan<EFBFBD> p<EFBFBD><EFBFBD>kaz.
* *
* @param player * @param player
* specifikovaný hráč * specifikovan<EFBFBD> hr<EFBFBD><EFBFBD>
* @param regexCommand * @param regexCommand
* příkaz z konfigurace vyhovující originálnímu příkazu * p<EFBFBD><EFBFBD>kaz z konfigurace vyhovuj<EFBFBD>c<EFBFBD> origin<EFBFBD>ln<EFBFBD>mu p<EFBFBD><EFBFBD>kazu
* @return datum a čas kdy hráč naposledy použil daný příkaz * @return datum a <EFBFBD>as kdy hr<EFBFBD><EFBFBD> naposledy pou<EFBFBD>il dan<EFBFBD> p<EFBFBD><EFBFBD>kaz
*/ */
static Date getTime(Player player, String regexCommand) { static Date getTime(Player player, String regexCommand) {
int pre2 = regexCommand.toLowerCase().hashCode(); int pre2 = regexCommand.toLowerCase().hashCode();
@ -190,19 +189,19 @@ public class BoosCoolDownManager {
} }
/** /**
* Metoda vrací hodnotu boolean na základě toho, jestli specifikovaný * Metoda vrac<EFBFBD> hodnotu boolean na z<EFBFBD>klad<EFBFBD> toho, jestli m<EFBFBD> specifikovan<EFBFBD>
* příkaz aktivní cooldown časovač. * p<EFBFBD><EFBFBD>kaz aktivn<EFBFBD> cooldown <EFBFBD>asova<EFBFBD>.
* *
* @param player * @param player
* specifikovaný hráč * specifikovan<EFBFBD> hr<EFBFBD><EFBFBD>
* @param regexCommand * @param regexCommand
* příkaz z konfigurace vyhovující originálnímu příkazu * p<EFBFBD><EFBFBD>kaz z konfigurace vyhovuj<EFBFBD>c<EFBFBD> origin<EFBFBD>ln<EFBFBD>mu p<EFBFBD><EFBFBD>kazu
* @param originalCommand * @param originalCommand
* originální příkaz použitý hráčem * origin<EFBFBD>ln<EFBFBD> p<EFBFBD><EFBFBD>kaz pou<EFBFBD>it<EFBFBD> hr<EFBFBD><EFBFBD>em
* @param time * @param time
* cooldown doba v sekundách, nastavená pro regexCommand v * cooldown doba v sekund<EFBFBD>ch, nastaven<EFBFBD> pro regexCommand v
* konfiguraci * konfiguraci
* @return false pokud má příkaz aktivní cooldown časovač, jinak false * @return false pokud m<EFBFBD> p<EFBFBD><EFBFBD>kaz aktivn<EFBFBD> cooldown <EFBFBD>asova<EFBFBD>, jinak false
*/ */
static boolean checkCoolDownOK(Player player, String regexCommand, static boolean checkCoolDownOK(Player player, String regexCommand,
String originalCommand, int time) { String originalCommand, int time) {
@ -250,12 +249,12 @@ public class BoosCoolDownManager {
} }
/** /**
* Metoda vrací hodnotu rozdílu v sekundách mezi dvěmi hodnotami datumu a * Metoda vrac<EFBFBD> hodnotu rozd<EFBFBD>lu v sekund<EFBFBD>ch mezi dv<EFBFBD>mi hodnotami datumu a
* času. * <EFBFBD>asu.
* *
* @param startDate * @param startDate
* @param endDate * @param endDate
* @return rozdíl v sekundách mezi startDate a endDate * @return rozd<EFBFBD>l v sekund<EFBFBD>ch mezi startDate a endDate
*/ */
static long secondsBetween(Calendar startDate, Calendar endDate) { static long secondsBetween(Calendar startDate, Calendar endDate) {
long secondsBetween = 0; long secondsBetween = 0;
@ -268,13 +267,13 @@ public class BoosCoolDownManager {
} }
/** /**
* Metoda ukládá do databáze datum a čas kdy hráč naposledy použil daný * Metoda ukl<EFBFBD>d<EFBFBD> do datab<EFBFBD>ze datum a <EFBFBD>as kdy hr<EFBFBD><EFBFBD> naposledy pou<EFBFBD>il dan<EFBFBD>
* příkaz. * p<EFBFBD><EFBFBD>kaz.
* *
* @param player * @param player
* specifický hráč * specifick<EFBFBD> hr<EFBFBD><EFBFBD>
* @param regexCommand * @param regexCommand
* příkaz z konfigurace vyhovující originálnímu příkazu * p<EFBFBD><EFBFBD>kaz z konfigurace vyhovuj<EFBFBD>c<EFBFBD> origin<EFBFBD>ln<EFBFBD>mu p<EFBFBD><EFBFBD>kazu
*/ */
static void setTime(Player player, String regexCommand) { static void setTime(Player player, String regexCommand) {
int pre2 = regexCommand.toLowerCase().hashCode(); int pre2 = regexCommand.toLowerCase().hashCode();
@ -288,10 +287,10 @@ public class BoosCoolDownManager {
} }
/** /**
* Metoda spouští veškeré cooldown časovače pro specifického hráče. * Metoda spou<EFBFBD>t<EFBFBD> ve<EFBFBD>ker<EFBFBD> cooldown <EFBFBD>asova<EFBFBD>e pro specifick<EFBFBD>ho hr<EFBFBD><EFBFBD>e.
* *
* @param player * @param player
* specifický hráč * specifick<EFBFBD> hr<EFBFBD><EFBFBD>
* @param message * @param message
*/ */
public static void startAllCooldowns(Player player, String message) { public static void startAllCooldowns(Player player, String message) {

View File

@ -9,32 +9,32 @@ import org.bukkit.inventory.ItemStack;
import util.boosChat; import util.boosChat;
/** /**
* Třída obsahuje veškeré metody potřebné k řízení poplatků za příkazy. * T<EFBFBD><EFBFBD>da obsahuje ve<EFBFBD>ker<EFBFBD> metody pot<EFBFBD>ebn<EFBFBD> k <EFBFBD><EFBFBD>zen<EFBFBD> poplatk<EFBFBD> za p<EFBFBD><EFBFBD>kazy.
* *
* @author Jakub Kolář * @author Jakub Kol<EFBFBD><EFBFBD>
* *
*/ */
public class BoosItemCostManager { public class BoosItemCostManager {
private static String msg = ""; private static String msg = "";
/** /**
* Metoda zajišťuje funkci platby za příkaz. Vrací hodnotu v vislosti na * Metoda zaji<EFBFBD><EFBFBD>uje funkci platby za p<EFBFBD><EFBFBD>kaz. Vrac<EFBFBD> hodnotu v z<EFBFBD>vislosti na
* úspěšnosti platby. * <EFBFBD>sp<EFBFBD>nosti platby.
* *
* @param player * @param player
* specifikovaný hráč * specifikovan<EFBFBD> hr<EFBFBD><EFBFBD>
* @param regexCommand * @param regexCommand
* příkaz z konfigurace vyhovující originálnímu příkazu * p<EFBFBD><EFBFBD>kaz z konfigurace vyhovuj<EFBFBD>c<EFBFBD> origin<EFBFBD>ln<EFBFBD>mu p<EFBFBD><EFBFBD>kazu
* @param originalCommand * @param originalCommand
* originální příkaz použitý hráčem * origin<EFBFBD>ln<EFBFBD> p<EFBFBD><EFBFBD>kaz pou<EFBFBD>it<EFBFBD> hr<EFBFBD><EFBFBD>em
* @param item * @param item
* @param price * @param price
* cena použití příkazu * cena pou<EFBFBD>it<EFBFBD> p<EFBFBD><EFBFBD>kazu
* @param name * @param name
* jméno specifického hráče * jm<EFBFBD>no specifick<EFBFBD>ho hr<EFBFBD><EFBFBD>e
* @return true pokud byl úspěšně zaplacen poplatek, nebo pokud nebyl * @return true pokud byl <EFBFBD>sp<EFBFBD>n<EFBFBD> zaplacen poplatek, nebo pokud nebyl nalezen
* nalezen ekonomický plugin; false pokud došlo k chybě nebo hráč * ekonomick<EFBFBD> plugin; false pokud do<EFBFBD>lo k chyb<EFBFBD> nebo hr<EFBFBD><EFBFBD> nem<EFBFBD>l
* neměl dostatek financí * dostatek financ<EFBFBD>
*/ */
static boolean payItemForCommand(Player player, String regexCommand, static boolean payItemForCommand(Player player, String regexCommand,
String originalCommand, String item, int count, String name) { String originalCommand, String item, int count, String name) {
@ -64,21 +64,21 @@ public class BoosItemCostManager {
} }
/** /**
* Metoda ukončuje/neukončuje událost použití příkazu v vislosti na tom, * Metoda ukon<EFBFBD>uje/neukon<EFBFBD>uje ud<EFBFBD>lost pou<EFBFBD>it<EFBFBD> p<EFBFBD><EFBFBD>kazu v z<EFBFBD>vislosti na tom,
* jakou hodnotu vrátila metoda payForCommand(Player player, String * jakou hodnotu vr<EFBFBD>tila metoda payForCommand(Player player, String
* regexCommand, String originalCommand, double price, String name);. * regexCommand, String originalCommand, double price, String name);.
* *
* @param event * @param event
* událost PlayerCommandPreprocessEvent * ud<EFBFBD>lost PlayerCommandPreprocessEvent
* @param player * @param player
* specifický hráč * specifick<EFBFBD> hr<EFBFBD><EFBFBD>
* @param regexCommand * @param regexCommand
* příkaz z konfigurace vyhovující originálnímu příkazu * p<EFBFBD><EFBFBD>kaz z konfigurace vyhovuj<EFBFBD>c<EFBFBD> origin<EFBFBD>ln<EFBFBD>mu p<EFBFBD><EFBFBD>kazu
* @param originalCommand * @param originalCommand
* originální příkaz použitý hráčem * origin<EFBFBD>ln<EFBFBD> p<EFBFBD><EFBFBD>kaz pou<EFBFBD>it<EFBFBD> hr<EFBFBD><EFBFBD>em
* @param item * @param item
* @param price * @param price
* cena použití příkazu * cena pou<EFBFBD>it<EFBFBD> p<EFBFBD><EFBFBD>kazu
*/ */
static void payItemForCommand(PlayerCommandPreprocessEvent event, static void payItemForCommand(PlayerCommandPreprocessEvent event,
Player player, String regexCommand, String originalCommand, Player player, String regexCommand, String originalCommand,

View File

@ -5,27 +5,27 @@ import org.bukkit.entity.Player;
import util.boosChat; import util.boosChat;
/** /**
* Třída obsahuje veškeré metody potřebné k řízení limitů. * T<EFBFBD><EFBFBD>da obsahuje ve<EFBFBD>ker<EFBFBD> metody pot<EFBFBD>ebn<EFBFBD> k <EFBFBD><EFBFBD>zen<EFBFBD> limit<EFBFBD>.
* *
* @author Jakub Kolář * @author Jakub Kol<EFBFBD><EFBFBD>
* *
*/ */
public class BoosLimitManager { public class BoosLimitManager {
/** /**
* Metoda kontroluje zda je možné použít příkaz, nebo zda je příkaz již * Metoda kontroluje zda je mo<EFBFBD>n<EFBFBD> pou<EFBFBD><EFBFBD>t p<EFBFBD><EFBFBD>kaz, nebo zda je p<EFBFBD><EFBFBD>kaz ji<EFBFBD>
* zablokovaný. * zablokovan<EFBFBD>.
* *
* @param player * @param player
* specifická hráč * specifick<EFBFBD> hr<EFBFBD><EFBFBD>
* @param regexCommand * @param regexCommand
* příkaz z konfiguračního souboru, který vyhovuje originálnímu * p<EFBFBD><EFBFBD>kaz z konfigura<EFBFBD>n<EFBFBD>ho souboru, kter<EFBFBD> vyhovuje origin<EFBFBD>ln<EFBFBD>mu
* příkazu * p<EFBFBD><EFBFBD>kazu
* @param originalCommand * @param originalCommand
* originální příkaz použitý hráčem * origin<EFBFBD>ln<EFBFBD> p<EFBFBD><EFBFBD>kaz pou<EFBFBD>it<EFBFBD> hr<EFBFBD><EFBFBD>em
* @param limit * @param limit
* limit nastavený pro regexCommand * limit nastaven<EFBFBD> pro regexCommand
* @return false pokud příkaz je možné použít, true pokud příkaz není možné * @return false pokud p<EFBFBD><EFBFBD>kaz je mo<EFBFBD>n<EFBFBD> pou<EFBFBD><EFBFBD>t, true pokud p<EFBFBD><EFBFBD>kaz nen<EFBFBD> mo<EFBFBD>n<EFBFBD>
* použít * pou<EFBFBD><EFBFBD>t
*/ */
static boolean blocked(Player player, String regexCommand, static boolean blocked(Player player, String regexCommand,
String originalCommand, int limit) { String originalCommand, int limit) {
@ -44,37 +44,37 @@ public class BoosLimitManager {
} }
/** /**
* Metoda vrací hodnotu, která je určena tím, kolikrát již hráč použil * Metoda vrac<EFBFBD> hodnotu, kter<EFBFBD> je ur<EFBFBD>ena t<EFBFBD>m, kolikr<EFBFBD>t ji<EFBFBD> hr<EFBFBD><EFBFBD> pou<EFBFBD>il
* specifikovaný příkaz. * specifikovan<EFBFBD> p<EFBFBD><EFBFBD>kaz.
* *
* @param player * @param player
* specifická hráč * specifick<EFBFBD> hr<EFBFBD><EFBFBD>
* @param regexCommand * @param regexCommand
* příkaz z konfiguračního souboru, který vyhovuje originálnímu * p<EFBFBD><EFBFBD>kaz z konfigura<EFBFBD>n<EFBFBD>ho souboru, kter<EFBFBD> vyhovuje origin<EFBFBD>ln<EFBFBD>mu
* příkazu * p<EFBFBD><EFBFBD>kazu
* @return hodnota představujíci počet použití specifikovaného příkazu * @return hodnota p<EFBFBD>edstavuj<EFBFBD>ci po<EFBFBD>et pou<EFBFBD>it<EFBFBD> specifikovan<EFBFBD>ho p<EFBFBD><EFBFBD>kazu
*/ */
static int getUses(Player player, String regexCommand) { static int getUses(Player player, String regexCommand) {
int regexCommand2 = regexCommand.toLowerCase().hashCode(); int regexCommand2 = regexCommand.toLowerCase().hashCode();
int uses = 0; int uses = 0;
uses = BoosConfigManager.getConfusers().getInt( uses = BoosConfigManager.getConfusers().getInt(
"users." + player.getUniqueId() + ".uses." "users." + player.getUniqueId() + ".uses." + regexCommand2,
+ regexCommand2, uses); uses);
return uses; return uses;
} }
/** /**
* Metoda nastavuje počet použití příkazu o jedna větší po každém použití * Metoda nastavuje po<EFBFBD>et pou<EFBFBD>it<EFBFBD> p<EFBFBD><EFBFBD>kazu o jedna v<EFBFBD>t<EFBFBD><EFBFBD> po ka<EFBFBD>d<EFBFBD>m pou<EFBFBD>it<EFBFBD>
* příkazu hráčem. Nastevení hodnoty probíhá jen pro příkazy, které jsou * p<EFBFBD><EFBFBD>kazu hr<EFBFBD><EFBFBD>em. Nasteven<EFBFBD> hodnoty prob<EFBFBD>h<EFBFBD> jen pro p<EFBFBD><EFBFBD>kazy, kter<EFBFBD> jsou
* definovány v konfiguraci. * definov<EFBFBD>ny v konfiguraci.
* *
* @param player * @param player
* specifická hráč * specifick<EFBFBD> hr<EFBFBD><EFBFBD>
* @param regexCommand * @param regexCommand
* příkaz z konfiguračního souboru, který vyhovuje originálnímu * p<EFBFBD><EFBFBD>kaz z konfigura<EFBFBD>n<EFBFBD>ho souboru, kter<EFBFBD> vyhovuje origin<EFBFBD>ln<EFBFBD>mu
* příkazu * p<EFBFBD><EFBFBD>kazu
* @param originalCommand * @param originalCommand
* originální příkaz použitý hráčem * origin<EFBFBD>ln<EFBFBD> p<EFBFBD><EFBFBD>kaz pou<EFBFBD>it<EFBFBD> hr<EFBFBD><EFBFBD>em
*/ */
static void setUses(Player player, String regexCommand, static void setUses(Player player, String regexCommand,
String originalCommand) { String originalCommand) {
@ -103,15 +103,15 @@ public class BoosLimitManager {
} }
/** /**
* Metoda odesílá hráči zprávu o limitovaném příkazu, hodnotu tohoto limitu * Metoda odes<EFBFBD>l<EFBFBD> hr<EFBFBD><EFBFBD>i zpr<EFBFBD>vu o limitovan<EFBFBD>m p<EFBFBD><EFBFBD>kazu, hodnotu tohoto limitu
* a kolikrát je ještě možné limitovaný příkaz použít. * a kolikr<EFBFBD>t je je<EFBFBD>t<EFBFBD> mo<EFBFBD>n<EFBFBD> limitovan<EFBFBD> p<EFBFBD><EFBFBD>kaz pou<EFBFBD><EFBFBD>t.
* *
* @param send * @param send
* hráč kterému bude odeslán seznam * hr<EFBFBD><EFBFBD> kter<EFBFBD>mu bude odesl<EFBFBD>n seznam
* @param comm * @param comm
* příkaz o kterém si hráč vyžádal informace * p<EFBFBD><EFBFBD>kaz o kter<EFBFBD>m si hr<EFBFBD><EFBFBD> vy<EFBFBD><EFBFBD>dal informace
* @param lim * @param lim
* hodnota limitu na příkazu * hodnota limitu na p<EFBFBD><EFBFBD>kazu
*/ */
static void getLimitListMessages(Player send, String comm, int lim) { static void getLimitListMessages(Player send, String comm, int lim) {
if (lim != -1) { if (lim != -1) {

View File

@ -9,8 +9,8 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import util.boosChat; import util.boosChat;
/** /**
* T<EFBFBD><EFBFBD>da obsahuje ve<EFBFBD>ker<EFBFBD> metody pot<EFBFBD>ebn<EFBFBD> k <EFBFBD><EFBFBD>zen<EFBFBD> poplatk<EFBFBD> * T<EFBFBD><EFBFBD>da obsahuje ve<EFBFBD>ker<EFBFBD> metody pot<EFBFBD>ebn<EFBFBD> k <EFBFBD><EFBFBD>zen<EFBFBD> poplatk<EFBFBD> pomoc<EFBFBD> v<EFBFBD>c<EFBFBD> za
* pomoc<EFBFBD> v<EFBFBD>c<EFBFBD> za p<EFBFBD><EFBFBD>kazy. * p<EFBFBD><EFBFBD>kazy.
* *
* @author Jakub Kol<EFBFBD><EFBFBD> * @author Jakub Kol<EFBFBD><EFBFBD>
* *
@ -20,23 +20,22 @@ public class BoosPriceManager {
private static String msg = ""; private static String msg = "";
/** /**
* Metoda zaji<EFBFBD><EFBFBD>uje funkci platby za p<EFBFBD><EFBFBD>kaz. Vrac<EFBFBD> hodnotu v * Metoda zaji<EFBFBD><EFBFBD>uje funkci platby za p<EFBFBD><EFBFBD>kaz. Vrac<EFBFBD> hodnotu v z<EFBFBD>vislosti na
* z<EFBFBD>vislosti na <EFBFBD>sp<EFBFBD>nosti platby. * <EFBFBD>sp<EFBFBD>nosti platby.
* *
* @param player * @param player
* specifikovan<EFBFBD> hr<EFBFBD><EFBFBD> * specifikovan<EFBFBD> hr<EFBFBD><EFBFBD>
* @param regexCommand * @param regexCommand
* p<EFBFBD><EFBFBD>kaz z konfigurace vyhovuj<EFBFBD>c<EFBFBD> origin<EFBFBD>ln<EFBFBD>mu * p<EFBFBD><EFBFBD>kaz z konfigurace vyhovuj<EFBFBD>c<EFBFBD> origin<EFBFBD>ln<EFBFBD>mu p<EFBFBD><EFBFBD>kazu
* p<EFBFBD><EFBFBD>kazu
* @param originalCommand * @param originalCommand
* origin<EFBFBD>ln<EFBFBD> p<EFBFBD><EFBFBD>kaz pou<EFBFBD>it<EFBFBD> hr<EFBFBD><EFBFBD>em * origin<EFBFBD>ln<EFBFBD> p<EFBFBD><EFBFBD>kaz pou<EFBFBD>it<EFBFBD> hr<EFBFBD><EFBFBD>em
* @param price * @param price
* cena pou<EFBFBD>it<EFBFBD> p<EFBFBD><EFBFBD>kazu * cena pou<EFBFBD>it<EFBFBD> p<EFBFBD><EFBFBD>kazu
* @param name * @param name
* jm<EFBFBD>no specifick<EFBFBD>ho hr<EFBFBD><EFBFBD>e * jm<EFBFBD>no specifick<EFBFBD>ho hr<EFBFBD><EFBFBD>e
* @return true pokud byl <EFBFBD>sp<EFBFBD>n<EFBFBD> zaplacen poplatek, nebo pokud nebyl * @return true pokud byl <EFBFBD>sp<EFBFBD>n<EFBFBD> zaplacen poplatek, nebo pokud nebyl nalezen
* nalezen ekonomick<EFBFBD> plugin; false pokud do<EFBFBD>lo k chyb<EFBFBD> nebo * ekonomick<EFBFBD> plugin; false pokud do<EFBFBD>lo k chyb<EFBFBD> nebo hr<EFBFBD><EFBFBD> nem<EFBFBD>l
* hr<EFBFBD><EFBFBD> nem<EFBFBD>l dostatek financ<EFBFBD> * dostatek financ<EFBFBD>
*/ */
static boolean payForCommand(Player player, String regexCommand, static boolean payForCommand(Player player, String regexCommand,
String originalCommand, double price, String name) { String originalCommand, double price, String name) {
@ -72,18 +71,16 @@ public class BoosPriceManager {
} }
/** /**
* Metoda ukon<EFBFBD>uje/neukon<EFBFBD>uje ud<EFBFBD>lost pou<EFBFBD>it<EFBFBD> p<EFBFBD><EFBFBD>kazu v * Metoda ukon<EFBFBD>uje/neukon<EFBFBD>uje ud<EFBFBD>lost pou<EFBFBD>it<EFBFBD> p<EFBFBD><EFBFBD>kazu v z<EFBFBD>vislosti na tom,
* z<EFBFBD>vislosti na tom, jakou hodnotu vr<EFBFBD>tila metoda payForCommand(Player * jakou hodnotu vr<EFBFBD>tila metoda payForCommand(Player player, String
* player, String regexCommand, String originalCommand, double price, String * regexCommand, String originalCommand, double price, String name);.
* name);.
* *
* @param event * @param event
* ud<EFBFBD>lost PlayerCommandPreprocessEvent * ud<EFBFBD>lost PlayerCommandPreprocessEvent
* @param player * @param player
* specifick<EFBFBD> hr<EFBFBD><EFBFBD> * specifick<EFBFBD> hr<EFBFBD><EFBFBD>
* @param regexCommand * @param regexCommand
* p<EFBFBD><EFBFBD>kaz z konfigurace vyhovuj<EFBFBD>c<EFBFBD> origin<EFBFBD>ln<EFBFBD>mu * p<EFBFBD><EFBFBD>kaz z konfigurace vyhovuj<EFBFBD>c<EFBFBD> origin<EFBFBD>ln<EFBFBD>mu p<EFBFBD><EFBFBD>kazu
* p<EFBFBD><EFBFBD>kazu
* @param originalCommand * @param originalCommand
* origin<EFBFBD>ln<EFBFBD> p<EFBFBD><EFBFBD>kaz pou<EFBFBD>it<EFBFBD> hr<EFBFBD><EFBFBD>em * origin<EFBFBD>ln<EFBFBD> p<EFBFBD><EFBFBD>kaz pou<EFBFBD>it<EFBFBD> hr<EFBFBD><EFBFBD>em
* @param price * @param price

View File

@ -11,10 +11,10 @@ import org.bukkit.potion.PotionEffectType;
import util.boosChat; import util.boosChat;
/** /**
* Třída obsahuje veškeré metody potřebné k řízení warmup časovačů. Spouštění, * T<EFBFBD><EFBFBD>da obsahuje ve<EFBFBD>ker<EFBFBD> metody pot<EFBFBD>ebn<EFBFBD> k <EFBFBD><EFBFBD>zen<EFBFBD> warmup <EFBFBD>asova<EFBFBD><EFBFBD>. Spou<EFBFBD>t<EFBFBD>n<EFBFBD>,
* ukončování a zjišťování zda je warmup časovač již aktivní. * ukon<EFBFBD>ov<EFBFBD>n<EFBFBD> a zji<EFBFBD><EFBFBD>ov<EFBFBD>n<EFBFBD> zda je warmup <EFBFBD>asova<EFBFBD> ji<EFBFBD> aktivn<EFBFBD>.
* *
* @author Jakub Kolář * @author Jakub Kol<EFBFBD><EFBFBD>
* *
*/ */
public class BoosWarmUpManager { public class BoosWarmUpManager {
@ -26,16 +26,16 @@ public class BoosWarmUpManager {
private static Timer scheduler; private static Timer scheduler;
/** /**
* Metoda aplikuje na hráče magický efekt na dobu určenou parametrem * Metoda aplikuje na hr<EFBFBD><EFBFBD>e magick<EFBFBD> efekt na dobu ur<EFBFBD>enou parametrem
* warmUpSeconds. * warmUpSeconds.
* *
* @param player * @param player
* specifický hráč * specifick<EFBFBD> hr<EFBFBD><EFBFBD>
* @param regexCommand * @param regexCommand
* příkaz z konfiguračního souboru, který vyhovuje originálnímu * p<EFBFBD><EFBFBD>kaz z konfigura<EFBFBD>n<EFBFBD>ho souboru, kter<EFBFBD> vyhovuje origin<EFBFBD>ln<EFBFBD>mu
* příkazu * p<EFBFBD><EFBFBD>kazu
* @param warmUpSeconds * @param warmUpSeconds
* doba warmup v sekundách, nastavená pro regexCommand v * doba warmup v sekund<EFBFBD>ch, nastaven<EFBFBD> pro regexCommand v
* konfiguraci * konfiguraci
*/ */
static void applyPotionEffect(Player player, String regexCommand, static void applyPotionEffect(Player player, String regexCommand,
@ -56,10 +56,10 @@ public class BoosWarmUpManager {
} }
/** /**
* Metoda stornuje veškeré probíhající warmup časovače specifického hráče. * Metoda stornuje ve<EFBFBD>ker<EFBFBD> prob<EFBFBD>haj<EFBFBD>c<EFBFBD> warmup <EFBFBD>asova<EFBFBD>e specifick<EFBFBD>ho hr<EFBFBD><EFBFBD>e.
* *
* @param player * @param player
* specifický hráč * specifick<EFBFBD> hr<EFBFBD><EFBFBD>
*/ */
public static void cancelWarmUps(Player player) { public static void cancelWarmUps(Player player) {
Iterator<String> iter = playercommands.keySet().iterator(); Iterator<String> iter = playercommands.keySet().iterator();
@ -72,10 +72,10 @@ public class BoosWarmUpManager {
} }
/** /**
* Metoda pro specifického hráče vymaže uloženou pozici a svět. * Metoda pro specifick<EFBFBD>ho hr<EFBFBD><EFBFBD>e vyma<EFBFBD>e ulo<EFBFBD>enou pozici a sv<EFBFBD>t.
* *
* @param player * @param player
* specifický hráč * specifick<EFBFBD> hr<EFBFBD><EFBFBD>
*/ */
public static void clearLocWorld(Player player) { public static void clearLocWorld(Player player) {
BoosWarmUpManager.playerloc.remove(player); BoosWarmUpManager.playerloc.remove(player);
@ -83,12 +83,12 @@ public class BoosWarmUpManager {
} }
/** /**
* Metoda vrací boolean hodnotu v závislosti na tom jestli specifikovaný * Metoda vrac<EFBFBD> boolean hodnotu v z<EFBFBD>vislosti na tom jestli specifikovan<EFBFBD>
* hráč aktivní warmup časovače nebo ne. * hr<EFBFBD><EFBFBD> m<EFBFBD> aktivn<EFBFBD> warmup <EFBFBD>asova<EFBFBD>e nebo ne.
* *
* @param player * @param player
* specifický hráč * specifick<EFBFBD> hr<EFBFBD><EFBFBD>
* @return true pokud hráč aktivní warmup časovače, jinak false * @return true pokud hr<EFBFBD><EFBFBD> m<EFBFBD> aktivn<EFBFBD> warmup <EFBFBD>asova<EFBFBD>e, jinak false
*/ */
public static boolean hasWarmUps(Player player) { public static boolean hasWarmUps(Player player) {
for (String key : playercommands.keySet()) { for (String key : playercommands.keySet()) {
@ -100,23 +100,22 @@ public class BoosWarmUpManager {
} }
/** /**
* Metoda zjišťuje, jestli je daný warmup časovač označený jako již proběhlý * Metoda zji<EFBFBD><EFBFBD>uje, jestli je dan<EFBFBD> warmup <EFBFBD>asova<EFBFBD> ozna<EFBFBD>en<EFBFBD> jako ji<EFBFBD> prob<EFBFBD>hl<EFBFBD>
* nebo ne. * nebo ne.
* *
* @param player * @param player
* specifický hráč * specifick<EFBFBD> hr<EFBFBD><EFBFBD>
* @param regexCommand * @param regexCommand
* příkaz z konfiguračního souboru, který vyhovuje originálnímu * p<EFBFBD><EFBFBD>kaz z konfigura<EFBFBD>n<EFBFBD>ho souboru, kter<EFBFBD> vyhovuje origin<EFBFBD>ln<EFBFBD>mu
* příkazu * p<EFBFBD><EFBFBD>kazu
* @return true pokud je warmup časovač označen jako již proběhlý, jinak * @return true pokud je warmup <EFBFBD>asova<EFBFBD> ozna<EFBFBD>en jako ji<EFBFBD> prob<EFBFBD>hl<EFBFBD>, jinak
* false * false
*/ */
static boolean checkWarmUpOK(Player player, String regexCommand) { static boolean checkWarmUpOK(Player player, String regexCommand) {
int pre2 = regexCommand.toLowerCase().hashCode(); int pre2 = regexCommand.toLowerCase().hashCode();
int ok = 0; int ok = 0;
ok = BoosConfigManager.getConfusers().getInt( ok = BoosConfigManager.getConfusers().getInt(
"users." + player.getUniqueId() "users." + player.getUniqueId() + ".warmup." + pre2, ok);
+ ".warmup." + pre2, ok);
if (ok == 1) { if (ok == 1) {
return true; return true;
} }
@ -124,29 +123,30 @@ public class BoosWarmUpManager {
} }
/** /**
* Metoda vrací boolean hodnotu na základě toho jestli je pro specifikovaný * Metoda vrac<EFBFBD> boolean hodnotu na z<EFBFBD>klad<EFBFBD> toho jestli je pro specifikovan<EFBFBD>
* příkaz specifikovaného hráče aktivní warmup časovač. * p<EFBFBD><EFBFBD>kaz specifikovan<EFBFBD>ho hr<EFBFBD><EFBFBD>e aktivn<EFBFBD> warmup <EFBFBD>asova<EFBFBD>.
* *
* @param player * @param player
* specifický hráč * specifick<EFBFBD> hr<EFBFBD><EFBFBD>
* @param regexCommand * @param regexCommand
* příkaz z konfiguračního souboru, který vyhovuje originálnímu * p<EFBFBD><EFBFBD>kaz z konfigura<EFBFBD>n<EFBFBD>ho souboru, kter<EFBFBD> vyhovuje origin<EFBFBD>ln<EFBFBD>mu
* příkazu * p<EFBFBD><EFBFBD>kazu
* @return true pokud je warmup časovač aktivní, jinak false * @return true pokud je warmup <EFBFBD>asova<EFBFBD> aktivn<EFBFBD>, jinak false
*/ */
static boolean isWarmUpProcess(Player player, String regexCommand) { static boolean isWarmUpProcess(Player player, String regexCommand) {
regexCommand = regexCommand.toLowerCase(); regexCommand = regexCommand.toLowerCase();
if (playercommands.containsKey(player.getUniqueId() + "@" + regexCommand)) { if (playercommands.containsKey(player.getUniqueId() + "@"
+ regexCommand)) {
return true; return true;
} }
return false; return false;
} }
/** /**
* Metoda odstraní všechny časovače specifikovaného hráče * Metoda odstran<EFBFBD> v<EFBFBD>echny <EFBFBD>asova<EFBFBD>e specifikovan<EFBFBD>ho hr<EFBFBD><EFBFBD>e
* *
* @param player * @param player
* specifický hráč * specifick<EFBFBD> hr<EFBFBD><EFBFBD>
*/ */
static void killTimer(Player player) { static void killTimer(Player player) {
for (String key : playercommands.keySet()) { for (String key : playercommands.keySet()) {
@ -157,80 +157,77 @@ public class BoosWarmUpManager {
} }
/** /**
* Metoda odstraní časovače na specifikovaném příkazu specifikovaného hráče * Metoda odstran<EFBFBD> <EFBFBD>asova<EFBFBD>e na specifikovan<EFBFBD>m p<EFBFBD><EFBFBD>kazu specifikovan<EFBFBD>ho hr<EFBFBD><EFBFBD>e
* *
* @param player * @param player
* specifický hráč * specifick<EFBFBD> hr<EFBFBD><EFBFBD>
* @param regexCommand * @param regexCommand
* příkaz z konfiguračního souboru, který vyhovuje originálnímu * p<EFBFBD><EFBFBD>kaz z konfigura<EFBFBD>n<EFBFBD>ho souboru, kter<EFBFBD> vyhovuje origin<EFBFBD>ln<EFBFBD>mu
* příkazu * p<EFBFBD><EFBFBD>kazu
*/ */
static void removeWarmUp(Player player, String regexCommand) { static void removeWarmUp(Player player, String regexCommand) {
int pre2 = regexCommand.toLowerCase().hashCode(); int pre2 = regexCommand.toLowerCase().hashCode();
BoosConfigManager.getConfusers().set( BoosConfigManager.getConfusers().set(
"users." + player.getUniqueId() "users." + player.getUniqueId() + ".warmup." + pre2, null);
+ ".warmup." + pre2, null);
} }
/** /**
* Metoda odstraní ukončené časovače na specifikovaném příkazu * Metoda odstran<EFBFBD> ukon<EFBFBD>en<EFBFBD> <EFBFBD>asova<EFBFBD>e na specifikovan<EFBFBD>m p<EFBFBD><EFBFBD>kazu
* specifikovaného hráče * specifikovan<EFBFBD>ho hr<EFBFBD><EFBFBD>e
* *
* @param player * @param player
* specifický hráč * specifick<EFBFBD> hr<EFBFBD><EFBFBD>
* @param regexCommand * @param regexCommand
* příkaz z konfiguračního souboru, který vyhovuje originálnímu * p<EFBFBD><EFBFBD>kaz z konfigura<EFBFBD>n<EFBFBD>ho souboru, kter<EFBFBD> vyhovuje origin<EFBFBD>ln<EFBFBD>mu
* příkazu * p<EFBFBD><EFBFBD>kazu
*/ */
static void removeWarmUpOK(Player player, String regexCommand) { static void removeWarmUpOK(Player player, String regexCommand) {
int pre2 = regexCommand.toLowerCase().hashCode(); int pre2 = regexCommand.toLowerCase().hashCode();
BoosConfigManager.getConfusers().set( BoosConfigManager.getConfusers().set(
"users." + player.getUniqueId() "users." + player.getUniqueId() + ".warmup." + pre2, null);
+ ".warmup." + pre2, null);
} }
/** /**
* Metoda odstraňuje daný řetězec z Hashmapy * Metoda odstra<EFBFBD>uje dan<EFBFBD> <EFBFBD>et<EFBFBD>zec z Hashmapy
* *
* @param tag * @param tag
* řetězec, který se odstranit z Hasmapy * <EFBFBD>et<EFBFBD>zec, kter<EFBFBD> se m<EFBFBD> odstranit z Hasmapy
*/ */
static void removeWarmUpProcess(String tag) { static void removeWarmUpProcess(String tag) {
BoosWarmUpManager.playercommands.remove(tag); BoosWarmUpManager.playercommands.remove(tag);
} }
/** /**
* Metoda označuje warmup časovač specifikovaného příkazu specifikovaného * Metoda ozna<EFBFBD>uje warmup <EFBFBD>asova<EFBFBD> specifikovan<EFBFBD>ho p<EFBFBD><EFBFBD>kazu specifikovan<EFBFBD>ho
* hráče jako již ukončený. * hr<EFBFBD><EFBFBD>e jako ji<EFBFBD> ukon<EFBFBD>en<EFBFBD>.
* *
* @param player * @param player
* specifický hráč * specifick<EFBFBD> hr<EFBFBD><EFBFBD>
* @param regexCommand * @param regexCommand
* příkaz z konfiguračního souboru, který vyhovuje originálnímu * p<EFBFBD><EFBFBD>kaz z konfigura<EFBFBD>n<EFBFBD>ho souboru, kter<EFBFBD> vyhovuje origin<EFBFBD>ln<EFBFBD>mu
* příkazu * p<EFBFBD><EFBFBD>kazu
*/ */
static void setWarmUpOK(Player player, String regexCommand) { static void setWarmUpOK(Player player, String regexCommand) {
int pre2 = regexCommand.toLowerCase().hashCode(); int pre2 = regexCommand.toLowerCase().hashCode();
BoosConfigManager.getConfusers().set( BoosConfigManager.getConfusers().set(
"users." + player.getUniqueId() "users." + player.getUniqueId() + ".warmup." + pre2, 1);
+ ".warmup." + pre2, 1);
} }
/** /**
* Metoda spouští warmup časovač na základě parametrů pomocí Timer(). Pokud * Metoda spou<EFBFBD>t<EFBFBD> warmup <EFBFBD>asova<EFBFBD> na z<EFBFBD>klad<EFBFBD> parametr<EFBFBD> pomoc<EFBFBD> Timer(). Pokud
* je již warmup aktivní, odešle hráči zprávu která ho o tom informuje. * je ji<EFBFBD> warmup aktivn<EFBFBD>, ode<EFBFBD>le hr<EFBFBD><EFBFBD>i zpr<EFBFBD>vu kter<EFBFBD> ho o tom informuje.
* *
* @param bCoolDown * @param bCoolDown
* instance třídy BoosCooldown * instance t<EFBFBD><EFBFBD>dy BoosCooldown
* @param player * @param player
* specifický hráč * specifick<EFBFBD> hr<EFBFBD><EFBFBD>
* @param regexCommand * @param regexCommand
* příkaz z konfiguračního souboru, který vyhovuje originálnímu * p<EFBFBD><EFBFBD>kaz z konfigura<EFBFBD>n<EFBFBD>ho souboru, kter<EFBFBD> vyhovuje origin<EFBFBD>ln<EFBFBD>mu
* příkazu * p<EFBFBD><EFBFBD>kazu
* @param originalCommand * @param originalCommand
* originální příkaz použitý hráčem * origin<EFBFBD>ln<EFBFBD> p<EFBFBD><EFBFBD>kaz pou<EFBFBD>it<EFBFBD> hr<EFBFBD><EFBFBD>em
* @param warmUpSeconds * @param warmUpSeconds
* warmup doba nastavená pro příkaz v sekundách * warmup doba nastaven<EFBFBD> pro p<EFBFBD><EFBFBD>kaz v sekund<EFBFBD>ch
*/ */
static void startWarmUp(BoosCoolDown bCoolDown, Player player, static void startWarmUp(BoosCoolDown bCoolDown, Player player,
String regexCommand, String originalCommand, int warmUpSeconds) { String regexCommand, String originalCommand, int warmUpSeconds) {

View File

@ -6,9 +6,9 @@ import java.util.TimerTask;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
/** /**
* Třída starající se o samotné časovače warmupů pomocí TimerTask * T<EFBFBD><EFBFBD>da staraj<EFBFBD>c<EFBFBD> se o samotn<EFBFBD> <EFBFBD>asova<EFBFBD>e warmup<EFBFBD> pomoc<EFBFBD> TimerTask
* *
* @author Jakub Kolář * @author Jakub Kol<EFBFBD><EFBFBD>
* *
*/ */
public class BoosWarmUpTimer extends TimerTask { public class BoosWarmUpTimer extends TimerTask {
@ -20,15 +20,15 @@ public class BoosWarmUpTimer extends TimerTask {
/** /**
* @param bCoolDown * @param bCoolDown
* instance třídy BoosCoolDown * instance t<EFBFBD><EFBFBD>dy BoosCoolDown
* @param timer * @param timer
* @param player * @param player
* specifický hráč * specifick<EFBFBD> hr<EFBFBD><EFBFBD>
* @param regexCommand * @param regexCommand
* příkaz z konfiguračního souboru, který vyhovuje originálnímu * p<EFBFBD><EFBFBD>kaz z konfigura<EFBFBD>n<EFBFBD>ho souboru, kter<EFBFBD> vyhovuje origin<EFBFBD>ln<EFBFBD>mu
* příkazu * p<EFBFBD><EFBFBD>kazu
* @param originalCommand * @param originalCommand
* originální příkaz který hráč použil * origin<EFBFBD>ln<EFBFBD> p<EFBFBD><EFBFBD>kaz kter<EFBFBD> hr<EFBFBD><EFBFBD> pou<EFBFBD>il
*/ */
public BoosWarmUpTimer(BoosCoolDown bCoolDown, Timer timer, Player player, public BoosWarmUpTimer(BoosCoolDown bCoolDown, Timer timer, Player player,
String regexCommand, String originalCommand) { String regexCommand, String originalCommand) {
@ -60,21 +60,21 @@ public class BoosWarmUpTimer extends TimerTask {
if (player.isOnline() && !player.isDead() if (player.isOnline() && !player.isDead()
&& BoosWarmUpManager.hasWarmUps(player)) { && BoosWarmUpManager.hasWarmUps(player)) {
BoosWarmUpManager.setWarmUpOK(player, regexCommand); BoosWarmUpManager.setWarmUpOK(player, regexCommand);
BoosWarmUpManager.removeWarmUpProcess(player.getUniqueId() + "@" BoosWarmUpManager.removeWarmUpProcess(player.getUniqueId()
+ regexCommand); + "@" + regexCommand);
BoosWarmUpManager.clearLocWorld(player); BoosWarmUpManager.clearLocWorld(player);
player.chat(originalCommand); player.chat(originalCommand);
} else if (player.isOnline() && player.isDead() } else if (player.isOnline() && player.isDead()
&& BoosWarmUpManager.hasWarmUps(player)) { && BoosWarmUpManager.hasWarmUps(player)) {
BoosWarmUpManager.removeWarmUp(player, regexCommand); BoosWarmUpManager.removeWarmUp(player, regexCommand);
BoosWarmUpManager.removeWarmUpProcess(player.getUniqueId() + "@" BoosWarmUpManager.removeWarmUpProcess(player.getUniqueId()
+ regexCommand); + "@" + regexCommand);
BoosWarmUpManager.clearLocWorld(player); BoosWarmUpManager.clearLocWorld(player);
} else if (!player.isOnline() } else if (!player.isOnline()
&& BoosWarmUpManager.hasWarmUps(player)) { && BoosWarmUpManager.hasWarmUps(player)) {
BoosWarmUpManager.removeWarmUp(player, regexCommand); BoosWarmUpManager.removeWarmUp(player, regexCommand);
BoosWarmUpManager.removeWarmUpProcess(player.getUniqueId() + "@" BoosWarmUpManager.removeWarmUpProcess(player.getUniqueId()
+ regexCommand); + "@" + regexCommand);
BoosWarmUpManager.clearLocWorld(player); BoosWarmUpManager.clearLocWorld(player);
} }
} }

View File

@ -11,23 +11,23 @@ import cz.boosik.boosCooldown.BoosConfigManager;
import cz.boosik.boosCooldown.BoosCoolDownManager; import cz.boosik.boosCooldown.BoosCoolDownManager;
/** /**
* Posluchač naslouchající události, která se spouští v okamžiku kdy hráč zemře. * Poslucha<EFBFBD> naslouchaj<EFBFBD>c<EFBFBD> ud<EFBFBD>losti, kter<EFBFBD> se spou<EFBFBD>t<EFBFBD> v okam<EFBFBD>iku kdy hr<EFBFBD><EFBFBD> zem<EFBFBD>e.
* V závislosti na konfiguraci pluginu a oprávněních hráče mohou nastat i * V z<EFBFBD>vislosti na konfiguraci pluginu a opr<EFBFBD>vn<EFBFBD>n<EFBFBD>ch hr<EFBFBD><EFBFBD>e mohou nastat t<EFBFBD>i
* různé aktivity. Cooldown časovače mohou být po smrti vymazány, nebo naopak * r<EFBFBD>zn<EFBFBD> aktivity. Cooldown <EFBFBD>asova<EFBFBD>e mohou b<EFBFBD>t po smrti vymaz<EFBFBD>ny, nebo naopak
* mohou být znovu spuštěny veškeré cooldown časovače pro veškeré nastavené * mohou b<EFBFBD>t znovu spu<EFBFBD>t<EFBFBD>ny ve<EFBFBD>ker<EFBFBD> cooldown <EFBFBD>asova<EFBFBD>e pro ve<EFBFBD>ker<EFBFBD> nastaven<EFBFBD>
* příkazy. Také mohou být vymazány záznamy o použitích příkazu a hráč bude opět * p<EFBFBD><EFBFBD>kazy. Tak<EFBFBD> mohou b<EFBFBD>t vymaz<EFBFBD>ny z<EFBFBD>znamy o pou<EFBFBD>it<EFBFBD>ch p<EFBFBD><EFBFBD>kazu a hr<EFBFBD><EFBFBD> bude op<EFBFBD>t
* schopen používat limitované příkazy po hodnotu limitu. * schopen pou<EFBFBD><EFBFBD>vat limitovan<EFBFBD> p<EFBFBD><EFBFBD>kazy a<EFBFBD> po hodnotu limitu.
* *
* @author Jakub Kolář * @author Jakub Kol<EFBFBD><EFBFBD>
* *
*/ */
public class BoosPlayerDeathListener implements Listener { public class BoosPlayerDeathListener implements Listener {
/** /**
* Metoda zjišťuje jestli je entita která spustila tuto událost hráč a * Metoda zji<EFBFBD><EFBFBD>uje jestli je entita kter<EFBFBD> spustila tuto ud<EFBFBD>lost hr<EFBFBD><EFBFBD> a
* jestli není null. Na základě toho spouští další metody. * jestli nen<EFBFBD> null. Na z<EFBFBD>klad<EFBFBD> toho spou<EFBFBD>t<EFBFBD> dal<EFBFBD><EFBFBD> metody.
* *
* @param event * @param event
* událost PlayerDeathEvent * ud<EFBFBD>lost PlayerDeathEvent
*/ */
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
private void onPlayerDeath(PlayerDeathEvent event) { private void onPlayerDeath(PlayerDeathEvent event) {
@ -41,11 +41,11 @@ public class BoosPlayerDeathListener implements Listener {
} }
/** /**
* Na základě konfigurace metoda spouští všechny cooldown časovače * Na z<EFBFBD>klad<EFBFBD> konfigurace metoda spou<EFBFBD>t<EFBFBD> v<EFBFBD>echny cooldown <EFBFBD>asova<EFBFBD>e
* specifikovaného hráče tím že spustí medotu startAllCooldowns();. * specifikovan<EFBFBD>ho hr<EFBFBD><EFBFBD>e t<EFBFBD>m <EFBFBD>e spust<EFBFBD> medotu startAllCooldowns();.
* *
* @param player * @param player
* hráč, který spustil událost PlayerDeathEvent * hr<EFBFBD><EFBFBD>, kter<EFBFBD> spustil ud<EFBFBD>lost PlayerDeathEvent
*/ */
private void startCooldownsOnDeath(Player player) { private void startCooldownsOnDeath(Player player) {
if (player != null) { if (player != null) {
@ -56,13 +56,13 @@ public class BoosPlayerDeathListener implements Listener {
} }
/** /**
* Na základě konfigurace a toho jestli hráč disponuje oprávněním * Na z<EFBFBD>klad<EFBFBD> konfigurace a toho jestli hr<EFBFBD><EFBFBD> disponuje opr<EFBFBD>vn<EFBFBD>n<EFBFBD>m
* booscooldowns.clear.uses.death metoda vymaže všechny záznamy o spuštění * booscooldowns.clear.uses.death metoda vyma<EFBFBD>e v<EFBFBD>echny z<EFBFBD>znamy o spu<EFBFBD>t<EFBFBD>n<EFBFBD>
* všech příkazů specifikovaného hráče tím že spustí metodu * v<EFBFBD>ech p<EFBFBD><EFBFBD>kaz<EFBFBD> specifikovan<EFBFBD>ho hr<EFBFBD><EFBFBD>e t<EFBFBD>m <EFBFBD>e spust<EFBFBD> metodu
* clearSomething();. * clearSomething();.
* *
* @param player * @param player
* hráč, který spustil událost PlayerDeathEvent * hr<EFBFBD><EFBFBD>, kter<EFBFBD> spustil ud<EFBFBD>lost PlayerDeathEvent
*/ */
private void clearUsesOnDeath(Player player) { private void clearUsesOnDeath(Player player) {
if (player != null if (player != null
@ -74,19 +74,20 @@ public class BoosPlayerDeathListener implements Listener {
} }
/** /**
* Na základě konfigurace a toho jestli hráč disponuje oprávněním * Na z<EFBFBD>klad<EFBFBD> konfigurace a toho jestli hr<EFBFBD><EFBFBD> disponuje opr<EFBFBD>vn<EFBFBD>n<EFBFBD>m
* booscooldowns.clear.cooldowns.death metoda vymaže echny cooldown * booscooldowns.clear.cooldowns.death metoda vyma<EFBFBD>e v<EFBFBD>echny cooldown
* časovače všech příkazů specifikovaného hráče tím že spustí metodu * <EFBFBD>asova<EFBFBD>e v<EFBFBD>ech p<EFBFBD><EFBFBD>kaz<EFBFBD> specifikovan<EFBFBD>ho hr<EFBFBD><EFBFBD>e t<EFBFBD>m <EFBFBD>e spust<EFBFBD> metodu
* clearSomething();. * clearSomething();.
* *
* @param player * @param player
* hráč, který spustil událost PlayerDeathEvent * hr<EFBFBD><EFBFBD>, kter<EFBFBD> spustil ud<EFBFBD>lost PlayerDeathEvent
*/ */
private void clearCooldownsOnDeath(Player player) { private void clearCooldownsOnDeath(Player player) {
if (player != null if (player != null
&& player.hasPermission("booscooldowns.clear.cooldowns.death")) { && player.hasPermission("booscooldowns.clear.cooldowns.death")) {
if (BoosConfigManager.getCleanCooldownsOnDeath()) { if (BoosConfigManager.getCleanCooldownsOnDeath()) {
BoosConfigManager.clearSomething("cooldown", player.getUniqueId()); BoosConfigManager.clearSomething("cooldown",
player.getUniqueId());
} }
} }
} }

View File

@ -52,462 +52,498 @@ import java.util.zip.GZIPOutputStream;
public class MetricsLite { public class MetricsLite {
/** /**
* The current revision number * The current revision number
*/ */
private final static int REVISION = 7; private final static int REVISION = 7;
/** /**
* The base url of the metrics domain * The base url of the metrics domain
*/ */
private static final String BASE_URL = "http://report.mcstats.org"; private static final String BASE_URL = "http://report.mcstats.org";
/** /**
* The url used to report a server's status * The url used to report a server's status
*/ */
private static final String REPORT_URL = "/plugin/%s"; private static final String REPORT_URL = "/plugin/%s";
/** /**
* Interval of time to ping (in minutes) * Interval of time to ping (in minutes)
*/ */
private final static int PING_INTERVAL = 15; private final static int PING_INTERVAL = 15;
/** /**
* The plugin this metrics submits for * The plugin this metrics submits for
*/ */
private final Plugin plugin; private final Plugin plugin;
/** /**
* The plugin configuration file * The plugin configuration file
*/ */
private final YamlConfiguration configuration; private final YamlConfiguration configuration;
/** /**
* The plugin configuration file * The plugin configuration file
*/ */
private final File configurationFile; private final File configurationFile;
/** /**
* Unique server id * Unique server id
*/ */
private final String guid; private final String guid;
/** /**
* Debug mode * Debug mode
*/ */
private final boolean debug; private final boolean debug;
/** /**
* Lock for synchronization * Lock for synchronization
*/ */
private final Object optOutLock = new Object(); private final Object optOutLock = new Object();
/** /**
* Id of the scheduled task * Id of the scheduled task
*/ */
private volatile BukkitTask task = null; private volatile BukkitTask task = null;
public MetricsLite(Plugin plugin) throws IOException { public MetricsLite(Plugin plugin) throws IOException {
if (plugin == null) { if (plugin == null) {
throw new IllegalArgumentException("Plugin cannot be null"); throw new IllegalArgumentException("Plugin cannot be null");
} }
this.plugin = plugin; this.plugin = plugin;
// load the config // load the config
configurationFile = getConfigFile(); configurationFile = getConfigFile();
configuration = YamlConfiguration.loadConfiguration(configurationFile); configuration = YamlConfiguration.loadConfiguration(configurationFile);
// add some defaults // add some defaults
configuration.addDefault("opt-out", false); configuration.addDefault("opt-out", false);
configuration.addDefault("guid", UUID.randomUUID().toString()); configuration.addDefault("guid", UUID.randomUUID().toString());
configuration.addDefault("debug", false); configuration.addDefault("debug", false);
// Do we need to create the file? // Do we need to create the file?
if (configuration.get("guid", null) == null) { if (configuration.get("guid", null) == null) {
configuration.options().header("http://mcstats.org").copyDefaults(true); configuration.options().header("http://mcstats.org")
configuration.save(configurationFile); .copyDefaults(true);
} configuration.save(configurationFile);
}
// Load the guid then
guid = configuration.getString("guid"); // Load the guid then
debug = configuration.getBoolean("debug", false); 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 * Start measuring statistics. This will immediately create an async
* PING_INTERVAL * 1200 ticks. * 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
* @return True if statistics measuring is running, otherwise false. * * 1200 ticks.
*/ *
public boolean start() { * @return True if statistics measuring is running, otherwise false.
synchronized (optOutLock) { */
// Did we opt out? public boolean start() {
if (isOptOut()) { synchronized (optOutLock) {
return false; // Did we opt out?
} if (isOptOut()) {
return false;
// Is metrics already running? }
if (task != null) {
return true; // Is metrics already running?
} if (task != null) {
return true;
// Begin hitting the server with glorious data }
task = plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, new Runnable() {
// Begin hitting the server with glorious data
private boolean firstPost = true; task = plugin.getServer().getScheduler()
.runTaskTimerAsynchronously(plugin, new Runnable() {
public void run() {
try { private boolean firstPost = true;
// This has to be synchronized or it can collide with the disable method.
synchronized (optOutLock) { public void run() {
// Disable Task, if it is running and the server owner decided to opt-out try {
if (isOptOut() && task != null) { // This has to be synchronized or it can collide
task.cancel(); // with the disable method.
task = null; synchronized (optOutLock) {
} // Disable Task, if it is running and the
} // server owner decided to opt-out
if (isOptOut() && task != null) {
// We use the inverse of firstPost because if it is the first time we are posting, task.cancel();
// it is not a interval ping, so it evaluates to FALSE task = null;
// Each time thereafter it will evaluate to TRUE, i.e PING! }
postPlugin(!firstPost); }
// After the first post we set firstPost to false // We use the inverse of firstPost because if it
// Each post thereafter will be a ping // is the first time we are posting,
firstPost = false; // it is not a interval ping, so it evaluates to
} catch (IOException e) { // FALSE
if (debug) { // Each time thereafter it will evaluate to
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + e.getMessage()); // TRUE, i.e PING!
} postPlugin(!firstPost);
}
} // After the first post we set firstPost to
}, 0, PING_INTERVAL * 1200); // false
// Each post thereafter will be a ping
return true; firstPost = false;
} } catch (IOException e) {
} if (debug) {
Bukkit.getLogger().log(Level.INFO,
/** "[Metrics] " + e.getMessage());
* Has the server owner denied plugin metrics? }
* }
* @return true if metrics should be opted out of it }
*/ }, 0, PING_INTERVAL * 1200);
public boolean isOptOut() {
synchronized (optOutLock) { return true;
try { }
// Reload the metrics file }
configuration.load(getConfigFile());
} catch (IOException ex) { /**
if (debug) { * Has the server owner denied plugin metrics?
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage()); *
} * @return true if metrics should be opted out of it
return true; */
} catch (InvalidConfigurationException ex) { public boolean isOptOut() {
if (debug) { synchronized (optOutLock) {
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage()); try {
} // Reload the metrics file
return true; configuration.load(getConfigFile());
} } catch (IOException ex) {
return configuration.getBoolean("opt-out", false); if (debug) {
} Bukkit.getLogger().log(Level.INFO,
} "[Metrics] " + ex.getMessage());
}
/** return true;
* Enables metrics for the server by setting "opt-out" to false in the config file and starting the metrics task. } catch (InvalidConfigurationException ex) {
* if (debug) {
* @throws java.io.IOException Bukkit.getLogger().log(Level.INFO,
*/ "[Metrics] " + ex.getMessage());
public void enable() throws IOException { }
// This has to be synchronized or it can collide with the check in the task. return true;
synchronized (optOutLock) { }
// Check if the server owner has already set opt-out, if not, set it. return configuration.getBoolean("opt-out", false);
if (isOptOut()) { }
configuration.set("opt-out", false); }
configuration.save(configurationFile);
} /**
* Enables metrics for the server by setting "opt-out" to false in the
// Enable Task, if it is not running * config file and starting the metrics task.
if (task == null) { *
start(); * @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) {
* Disables metrics for the server by setting "opt-out" to true in the config file and canceling the metrics task. // Check if the server owner has already set opt-out, if not, set
* // it.
* @throws java.io.IOException if (isOptOut()) {
*/ configuration.set("opt-out", false);
public void disable() throws IOException { configuration.save(configurationFile);
// 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. // Enable Task, if it is not running
if (!isOptOut()) { if (task == null) {
configuration.set("opt-out", true); start();
configuration.save(configurationFile); }
} }
}
// Disable Task, if it is running
if (task != null) { /**
task.cancel(); * Disables metrics for the server by setting "opt-out" to true in the
task = null; * 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
* Gets the File object of the config file that should be used to store data such as the GUID and opt-out status // task.
* synchronized (optOutLock) {
* @return the File object for the config file // Check if the server owner has already set opt-out, if not, set
*/ // it.
public File getConfigFile() { if (!isOptOut()) {
// I believe the easiest way to get the base folder (e.g craftbukkit set via -P) for plugins to use configuration.set("opt-out", true);
// is to abuse the plugin object we already have configuration.save(configurationFile);
// plugin.getDataFolder() => base/plugins/PluginA/ }
// pluginsFolder => base/plugins/
// The base is not necessarily relative to the startup directory. // Disable Task, if it is running
File pluginsFolder = plugin.getDataFolder().getParentFile(); if (task != null) {
task.cancel();
// return => base/plugins/PluginMetrics/config.yml task = null;
return new File(new File(pluginsFolder, "PluginMetrics"), "config.yml"); }
} }
}
/**
* Generic method that posts a plugin to the metrics website /**
*/ * Gets the File object of the config file that should be used to store data
private void postPlugin(boolean isPing) throws IOException { * such as the GUID and opt-out status
// Server software specific section *
PluginDescriptionFile description = plugin.getDescription(); * @return the File object for the config file
String pluginName = description.getName(); */
boolean onlineMode = Bukkit.getServer().getOnlineMode(); // TRUE if online mode is enabled public File getConfigFile() {
String pluginVersion = description.getVersion(); // I believe the easiest way to get the base folder (e.g craftbukkit set
String serverVersion = Bukkit.getVersion(); // via -P) for plugins to use
int playersOnline = Bukkit.getServer().getOnlinePlayers().size(); // is to abuse the plugin object we already have
// plugin.getDataFolder() => base/plugins/PluginA/
// END server software specific section -- all code below does not use any code outside of this class / Java // pluginsFolder => base/plugins/
// The base is not necessarily relative to the startup directory.
// Construct the post data File pluginsFolder = plugin.getDataFolder().getParentFile();
StringBuilder json = new StringBuilder(1024);
json.append('{'); // return => base/plugins/PluginMetrics/config.yml
return new File(new File(pluginsFolder, "PluginMetrics"), "config.yml");
// 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); * Generic method that posts a plugin to the metrics website
appendJSONPair(json, "players_online", Integer.toString(playersOnline)); */
private void postPlugin(boolean isPing) throws IOException {
// New data as of R6 // Server software specific section
String osname = System.getProperty("os.name"); PluginDescriptionFile description = plugin.getDescription();
String osarch = System.getProperty("os.arch"); String pluginName = description.getName();
String osversion = System.getProperty("os.version"); boolean onlineMode = Bukkit.getServer().getOnlineMode(); // TRUE if
String java_version = System.getProperty("java.version"); // online
int coreCount = Runtime.getRuntime().availableProcessors(); // mode is
// enabled
// normalize os arch .. amd64 -> x86_64 String pluginVersion = description.getVersion();
if (osarch.equals("amd64")) { String serverVersion = Bukkit.getVersion();
osarch = "x86_64"; int playersOnline = Bukkit.getServer().getOnlinePlayers().size();
}
// END server software specific section -- all code below does not use
appendJSONPair(json, "osname", osname); // any code outside of this class / Java
appendJSONPair(json, "osarch", osarch);
appendJSONPair(json, "osversion", osversion); // Construct the post data
appendJSONPair(json, "cores", Integer.toString(coreCount)); StringBuilder json = new StringBuilder(1024);
appendJSONPair(json, "auth_mode", onlineMode ? "1" : "0"); json.append('{');
appendJSONPair(json, "java_version", java_version);
// The plugin's description file containg all of the plugin data such as
// If we're pinging, append it // name, version, author, etc
if (isPing) { appendJSONPair(json, "guid", guid);
appendJSONPair(json, "ping", "1"); appendJSONPair(json, "plugin_version", pluginVersion);
} appendJSONPair(json, "server_version", serverVersion);
appendJSONPair(json, "players_online", Integer.toString(playersOnline));
// close json
json.append('}'); // New data as of R6
String osname = System.getProperty("os.name");
// Create the url String osarch = System.getProperty("os.arch");
URL url = new URL(BASE_URL + String.format(REPORT_URL, urlEncode(pluginName))); String osversion = System.getProperty("os.version");
String java_version = System.getProperty("java.version");
// Connect to the website int coreCount = Runtime.getRuntime().availableProcessors();
URLConnection connection;
// normalize os arch .. amd64 -> x86_64
// Mineshafter creates a socks proxy, so we can safely bypass it if (osarch.equals("amd64")) {
// It does not reroute POST requests so we need to go around it osarch = "x86_64";
if (isMineshafterPresent()) { }
connection = url.openConnection(Proxy.NO_PROXY);
} else { appendJSONPair(json, "osname", osname);
connection = url.openConnection(); appendJSONPair(json, "osarch", osarch);
} appendJSONPair(json, "osversion", osversion);
appendJSONPair(json, "cores", Integer.toString(coreCount));
appendJSONPair(json, "auth_mode", onlineMode ? "1" : "0");
byte[] uncompressed = json.toString().getBytes(); appendJSONPair(json, "java_version", java_version);
byte[] compressed = gzip(json.toString());
// If we're pinging, append it
// Headers if (isPing) {
connection.addRequestProperty("User-Agent", "MCStats/" + REVISION); appendJSONPair(json, "ping", "1");
connection.addRequestProperty("Content-Type", "application/json"); }
connection.addRequestProperty("Content-Encoding", "gzip");
connection.addRequestProperty("Content-Length", Integer.toString(compressed.length)); // close json
connection.addRequestProperty("Accept", "application/json"); json.append('}');
connection.addRequestProperty("Connection", "close");
// Create the url
connection.setDoOutput(true); URL url = new URL(BASE_URL
+ String.format(REPORT_URL, urlEncode(pluginName)));
if (debug) {
System.out.println("[Metrics] Prepared request for " + pluginName + " uncompressed=" + uncompressed.length + " compressed=" + compressed.length); // Connect to the website
} URLConnection connection;
// Write the data // Mineshafter creates a socks proxy, so we can safely bypass it
OutputStream os = connection.getOutputStream(); // It does not reroute POST requests so we need to go around it
os.write(compressed); if (isMineshafterPresent()) {
os.flush(); connection = url.openConnection(Proxy.NO_PROXY);
} else {
// Now read the response connection = url.openConnection();
final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); }
String response = reader.readLine();
byte[] uncompressed = json.toString().getBytes();
// close resources byte[] compressed = gzip(json.toString());
os.close();
reader.close(); // Headers
connection.addRequestProperty("User-Agent", "MCStats/" + REVISION);
if (response == null || response.startsWith("ERR") || response.startsWith("7")) { connection.addRequestProperty("Content-Type", "application/json");
if (response == null) { connection.addRequestProperty("Content-Encoding", "gzip");
response = "null"; connection.addRequestProperty("Content-Length",
} else if (response.startsWith("7")) { Integer.toString(compressed.length));
response = response.substring(response.startsWith("7,") ? 2 : 1); connection.addRequestProperty("Accept", "application/json");
} connection.addRequestProperty("Connection", "close");
throw new IOException(response); connection.setDoOutput(true);
}
} if (debug) {
System.out.println("[Metrics] Prepared request for " + pluginName
/** + " uncompressed=" + uncompressed.length + " compressed="
* GZip compress a string of bytes + compressed.length);
* }
* @param input
* @return // Write the data
*/ OutputStream os = connection.getOutputStream();
public static byte[] gzip(String input) { os.write(compressed);
ByteArrayOutputStream baos = new ByteArrayOutputStream(); os.flush();
GZIPOutputStream gzos = null;
// Now read the response
try { final BufferedReader reader = new BufferedReader(new InputStreamReader(
gzos = new GZIPOutputStream(baos); connection.getInputStream()));
gzos.write(input.getBytes("UTF-8")); String response = reader.readLine();
} catch (IOException e) {
e.printStackTrace(); // close resources
} finally { os.close();
if (gzos != null) try { reader.close();
gzos.close();
} catch (IOException ignore) { if (response == null || response.startsWith("ERR")
} || response.startsWith("7")) {
} if (response == null) {
response = "null";
return baos.toByteArray(); } else if (response.startsWith("7")) {
} response = response
.substring(response.startsWith("7,") ? 2 : 1);
/** }
* Check if mineshafter is present. If it is, we need to bypass it to send POST requests
* throw new IOException(response);
* @return true if mineshafter is installed on the server }
*/ }
private boolean isMineshafterPresent() {
try { /**
Class.forName("mineshafter.MineServer"); * GZip compress a string of bytes
return true; *
} catch (Exception e) { * @param input
return false; * @return
} */
} public static byte[] gzip(String input) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
/** GZIPOutputStream gzos = null;
* Appends a json encoded key/value pair to the given string builder.
* try {
* @param json gzos = new GZIPOutputStream(baos);
* @param key gzos.write(input.getBytes("UTF-8"));
* @param value } catch (IOException e) {
* @throws UnsupportedEncodingException e.printStackTrace();
*/ } finally {
private static void appendJSONPair(StringBuilder json, String key, String value) throws UnsupportedEncodingException { if (gzos != null)
boolean isValueNumeric = false; try {
gzos.close();
try { } catch (IOException ignore) {
if (value.equals("0") || !value.endsWith("0")) { }
Double.parseDouble(value); }
isValueNumeric = true;
} return baos.toByteArray();
} catch (NumberFormatException e) { }
isValueNumeric = false;
} /**
* Check if mineshafter is present. If it is, we need to bypass it to send
if (json.charAt(json.length() - 1) != '{') { * POST requests
json.append(','); *
} * @return true if mineshafter is installed on the server
*/
json.append(escapeJSON(key)); private boolean isMineshafterPresent() {
json.append(':'); try {
Class.forName("mineshafter.MineServer");
if (isValueNumeric) { return true;
json.append(value); } catch (Exception e) {
} else { return false;
json.append(escapeJSON(value)); }
} }
}
/**
/** * Appends a json encoded key/value pair to the given string builder.
* Escape a string to create a valid JSON string *
* * @param json
* @param text * @param key
* @return * @param value
*/ * @throws UnsupportedEncodingException
private static String escapeJSON(String text) { */
StringBuilder builder = new StringBuilder(); private static void appendJSONPair(StringBuilder json, String key,
String value) throws UnsupportedEncodingException {
builder.append('"'); boolean isValueNumeric = false;
for (int index = 0; index < text.length(); index++) {
char chr = text.charAt(index); try {
if (value.equals("0") || !value.endsWith("0")) {
switch (chr) { Double.parseDouble(value);
case '"': isValueNumeric = true;
case '\\': }
builder.append('\\'); } catch (NumberFormatException e) {
builder.append(chr); isValueNumeric = false;
break; }
case '\b':
builder.append("\\b"); if (json.charAt(json.length() - 1) != '{') {
break; json.append(',');
case '\t': }
builder.append("\\t");
break; json.append(escapeJSON(key));
case '\n': json.append(':');
builder.append("\\n");
break; if (isValueNumeric) {
case '\r': json.append(value);
builder.append("\\r"); } else {
break; json.append(escapeJSON(value));
default: }
if (chr < ' ') { }
String t = "000" + Integer.toHexString(chr);
builder.append("\\u" + t.substring(t.length() - 4)); /**
} else { * Escape a string to create a valid JSON string
builder.append(chr); *
} * @param text
break; * @return
} */
} private static String escapeJSON(String text) {
builder.append('"'); StringBuilder builder = new StringBuilder();
return builder.toString(); builder.append('"');
} for (int index = 0; index < text.length(); index++) {
char chr = text.charAt(index);
/**
* Encode text as UTF-8 switch (chr) {
* case '"':
* @param text the text to encode case '\\':
* @return the encoded text, as UTF-8 builder.append('\\');
*/ builder.append(chr);
private static String urlEncode(final String text) throws UnsupportedEncodingException { break;
return URLEncoder.encode(text, "UTF-8"); 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");
}
} }