Cleaned up old comments messed up by wrong encoding

Implemented shared limits functionality
Fixed a bug where player was unable to look around without canceling his warmups, while cancel warmups on move was enabled
This commit is contained in:
Boosik 2015-02-02 14:35:25 +01:00
parent 046df72e38
commit 8d0cad1e7c
25 changed files with 2309 additions and 3427 deletions

View File

@ -1,51 +1,51 @@
package cz.boosik.boosCooldown; package cz.boosik.boosCooldown;
import java.util.Set;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class BoosAliasManager { import java.util.Set;
public static String checkCommandAlias(String originalCommand, class BoosAliasManager {
Set<String> aliases, Player player) {
String[] splitCommand = originalCommand.split(" ", 4); public static String checkCommandAlias(String originalCommand,
String one = ""; Set<String> aliases, Player player) {
String two = ""; String[] splitCommand = originalCommand.split(" ", 4);
String three = ""; String one = "";
if (splitCommand.length > 1) { String two = "";
one = splitCommand[1]; String three = "";
if (splitCommand.length > 2) { if (splitCommand.length > 1) {
two = splitCommand[2]; one = splitCommand[1];
if (splitCommand.length > 3) { if (splitCommand.length > 2) {
three = splitCommand[3]; two = splitCommand[2];
} if (splitCommand.length > 3) {
} three = splitCommand[3];
} }
for (String alias : aliases) { }
String alias2 = alias.replace("*", ".+"); }
if (originalCommand.matches("(?i)" + alias2)) { for (String alias : aliases) {
originalCommand = BoosConfigManager.getAlias(alias); String alias2 = alias.replace("*", ".+");
if (originalCommand.contains("$1")) { if (originalCommand.matches("(?i)" + alias2)) {
originalCommand = originalCommand.replace("$1", one); originalCommand = BoosConfigManager.getAlias(alias);
} if (originalCommand.contains("$1")) {
if (originalCommand.contains("$2")) { originalCommand = originalCommand.replace("$1", one);
originalCommand = originalCommand.replace("$2", two); }
} if (originalCommand.contains("$2")) {
if (originalCommand.contains("$*")) { originalCommand = originalCommand.replace("$2", two);
originalCommand = originalCommand.replace("$*", three); }
} if (originalCommand.contains("$*")) {
if (originalCommand.contains("$player")) { originalCommand = originalCommand.replace("$*", three);
originalCommand = originalCommand.replace("$player", }
player.getName()); if (originalCommand.contains("$player")) {
} originalCommand = originalCommand.replace("$player",
if (originalCommand.contains("$world")) { player.getName());
originalCommand = originalCommand.replace("$world", player }
.getWorld().getName()); if (originalCommand.contains("$world")) {
} originalCommand = originalCommand.replace("$world", player
} .getWorld().getName());
} }
originalCommand = originalCommand.trim().replaceAll(" +", " "); }
return originalCommand; }
} originalCommand = originalCommand.trim().replaceAll(" +", " ");
return originalCommand;
}
} }

File diff suppressed because it is too large Load Diff

View File

@ -1,17 +1,8 @@
package cz.boosik.boosCooldown; package cz.boosik.boosCooldown;
import java.io.IOException; import cz.boosik.boosCooldown.Listeners.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Set;
import java.util.UUID;
import java.util.logging.Logger;
import net.milkbowl.vault.Vault; import net.milkbowl.vault.Vault;
import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -26,535 +17,439 @@ import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitScheduler; import org.bukkit.scheduler.BukkitScheduler;
import org.mcstats.MetricsLite; import org.mcstats.MetricsLite;
import util.boosChat; import util.boosChat;
import cz.boosik.boosCooldown.Listeners.BoosEntityDamageListener;
import cz.boosik.boosCooldown.Listeners.BoosPlayerDeathListener;
import cz.boosik.boosCooldown.Listeners.BoosPlayerGameModeChangeListener;
import cz.boosik.boosCooldown.Listeners.BoosPlayerInteractListener;
import cz.boosik.boosCooldown.Listeners.BoosPlayerMoveListener;
import cz.boosik.boosCooldown.Listeners.BoosPlayerToggleSneakListener;
import cz.boosik.boosCooldown.Listeners.BoosPlayerToggleSprintListener;
import cz.boosik.boosCooldown.Listeners.BoosSignChangeListener;
import cz.boosik.boosCooldown.Listeners.BoosSignInteractListener;
/** import java.io.IOException;
* Hlavn<EFBFBD> t<EFBFBD><EFBFBD>da pluginu. T<EFBFBD><EFBFBD>da je potomkem JavaPlugin a implementuje Runnable. import java.text.ParseException;
* Tato t<EFBFBD><EFBFBD>da se star<EFBFBD> o ve<EFBFBD>ker<EFBFBD> inicializace p<EFBFBD>i spu<EFBFBD>t<EFBFBD>n<EFBFBD> a ukon<EFBFBD>en<EFBFBD> pluginu. import java.text.SimpleDateFormat;
* Toto zahrnuje zji<EFBFBD>t<EFBFBD>n<EFBFBD>, zda je k dispozici plugin Vault a ekonomick<EFBFBD> plugin, import java.util.Calendar;
* registraci poslucha<EFBFBD><EFBFBD> a tak<EFBFBD> se star<EFBFBD> o funkce v<EFBFBD>ech kontroln<EFBFBD>ch a import java.util.Date;
* konfigura<EFBFBD>n<EFBFBD>ch p<EFBFBD><EFBFBD>kaz<EFBFBD>. Periodicky tak<EFBFBD> ukl<EFBFBD>d<EFBFBD> soubor datab<EFBFBD>ze v intervalu import java.util.Set;
* nastaven<EFBFBD>m v konfiguraci. import java.util.UUID;
* import java.util.logging.Logger;
* @author Jakub Kol<EFBFBD><EFBFBD>
*
*/
public class BoosCoolDown extends JavaPlugin implements Runnable { public class BoosCoolDown extends JavaPlugin implements Runnable {
private static final Logger log = Logger.getLogger("Minecraft"); private static final Logger log = Logger.getLogger("Minecraft");
private static PluginDescriptionFile pdfFile; private static PluginDescriptionFile pdfFile;
private static Economy economy = null; private static Economy economy = null;
private static boolean usingVault = false; private static boolean usingVault = false;
private PluginManager pm; private PluginManager pm;
private static BoosCoolDown instance = null;
/** public static void commandLogger(String player, String command) {
* Metoda odes<EFBFBD>l<EFBFBD> zpr<EFBFBD>vy o pou<EFBFBD>it<EFBFBD> p<EFBFBD><EFBFBD>kaz<EFBFBD> do konzole serveru. log.info("[" + "boosLogger" + "] " + player + " used command "
* + command);
* @param player }
* jm<EFBFBD>no hr<EFBFBD><EFBFBD>e kter<EFBFBD> vykonal p<EFBFBD><EFBFBD>kaz
* @param command
* vykonan<EFBFBD> p<EFBFBD><EFBFBD>kaz
*/
public static void commandLogger(String player, String command) {
log.info("[" + "boosLogger" + "] " + player + " used command "
+ command);
}
/** public static Economy getEconomy() {
* @return return economy;
*/ }
public static Economy getEconomy() {
return economy;
}
/** public static Logger getLog() {
* @return return log;
*/ }
public static Logger getLog() {
return log;
}
/** static boolean isPluginOnForPlayer(Player player) {
* Metoda zji<EFBFBD><EFBFBD>uje na z<EFBFBD>klad<EFBFBD> opr<EFBFBD>vn<EFBFBD>n<EFBFBD> jestli je plugin aktivn<EFBFBD> pro dan<EFBFBD>ho boolean on;
* hr<EFBFBD><EFBFBD>e nebo ne. on = !player.hasPermission("booscooldowns.exception") && !player.isOp();
* return on;
* @param player }
* specifikovan<EFBFBD> hr<EFBFBD><EFBFBD>
* @return
*/
static boolean isPluginOnForPlayer(Player player) {
boolean on;
if (player.hasPermission("booscooldowns.exception")) {
on = false;
} else if (player.isOp()) {
on = false;
} else {
on = true;
}
return on;
}
/** private static void startLimitResetTimersGlobal() {
* Metoda zji<EFBFBD><EFBFBD>uje jestli je dostupn<EFBFBD> plugin Vault a na z<EFBFBD>klad<EFBFBD> toho vol<EFBFBD> YamlConfiguration confusers = BoosConfigManager.getConfusers();
* metodu pro nastaven<EFBFBD> ekonomick<EFBFBD>ho pluginu a informuje o tom u<EFBFBD>ivatele ConfigurationSection global = confusers
* pomoc<EFBFBD> konzole serveru. .getConfigurationSection("global");
*/ if (global != null) {
private void initializeVault() { Set<String> globalKeys = global.getKeys(false);
Plugin x = pm.getPlugin("Vault"); BukkitScheduler scheduler = Bukkit.getScheduler();
if (x != null & x instanceof Vault) { for (String key : globalKeys) {
log.info("[" + pdfFile.getName() + "]" String confTime = confusers.getString("global." + key
+ " found [Vault] searching for economy plugin."); + ".reset");
usingVault = true; long limitResetDelay = BoosConfigManager
if (setupEconomy()) { .getLimitResetDelayGlobal(key);
log.info("[" + pdfFile.getName() + "]" + " found [" Date endDate = getTime(confTime);
+ economy.getName() Date startDate = getCurrTime();
+ "] plugin, enabling prices support."); Calendar calcurrTime = Calendar.getInstance();
} else { calcurrTime.setTime(startDate);
log.info("[" Calendar callastTime = Calendar.getInstance();
+ pdfFile.getName() callastTime.setTime(endDate);
+ "]" long time = secondsBetween(calcurrTime, callastTime,
+ " economy plugin not found, disabling prices support."); limitResetDelay);
} if (limitResetDelay != -65535) {
} else { if (time <= 0) {
log.info("[" + pdfFile.getName() + "]" time = 1;
+ " [Vault] not found disabling economy support."); }
usingVault = false; BoosCoolDown.getLog().info(
} "[boosCooldowns] Starting timer for " + time
} + " seconds to reset limits for command "
+ key);
scheduler.scheduleSyncDelayedTask(Bukkit.getPluginManager()
.getPlugin("boosCooldowns"),
new BoosGlobalLimitResetRunnable(key), time * 20);
} else {
BoosCoolDown.getLog().info(
"[boosCooldowns] Stoping timer to reset limits for command "
+ key);
}
}
}
}
/* static void startLimitResetTimerGlobal(String key) {
* (non-Javadoc) YamlConfiguration confusers = BoosConfigManager.getConfusers();
* BukkitScheduler scheduler = Bukkit.getScheduler();
* @see String confTime = confusers.getString("global." + key + ".reset");
* org.bukkit.plugin.java.JavaPlugin#onCommand(org.bukkit.command.CommandSender long limitResetDelay = BoosConfigManager.getLimitResetDelayGlobal(key);
* , org.bukkit.command.Command, java.lang.String, java.lang.String[]) Date endDate = getTime(confTime);
*/ Date startDate = getCurrTime();
@SuppressWarnings("deprecation") Calendar calcurrTime = Calendar.getInstance();
@Override calcurrTime.setTime(startDate);
public boolean onCommand(CommandSender sender, Command c, Calendar callastTime = Calendar.getInstance();
String commandLabel, String[] args) { callastTime.setTime(endDate);
String command = c.getName().toLowerCase(); long time = secondsBetween(calcurrTime, callastTime, limitResetDelay);
if (command.equalsIgnoreCase("booscooldowns")) { if (limitResetDelay != -65535) {
if (args.length == 1) { if (time <= 0) {
if (sender.hasPermission("booscooldowns.reload") time = 1;
&& args[0].equalsIgnoreCase("reload")) { }
reload(); BoosCoolDown.getLog().info(
boosChat.sendMessageToCommandSender(sender, "[boosCooldowns] Starting timer for " + time
"&6[" + pdfFile.getName() + "]&e" + " seconds to reset limits for command " + key);
+ " config reloaded"); scheduler.scheduleSyncDelayedTask(Bukkit.getPluginManager()
return true; .getPlugin("boosCooldowns"),
} new BoosGlobalLimitResetRunnable(key), time * 20);
if (sender.hasPermission("booscooldowns.list.limits") } else {
&& args[0].equalsIgnoreCase("limits")) { BoosCoolDown.getLog().info(
try { "[boosCooldowns] Stoping timer to reset limits for command "
Player send = (Player) sender; + key);
Set<String> commands = BoosConfigManager }
.getCommands(send); }
for (String comm : commands) {
int lim = BoosConfigManager.getLimit(comm, send);
BoosLimitManager.getLimitListMessages(send, comm,
lim);
}
} catch (ClassCastException e) {
log.warning("You cannot use this command from console!");
}
return true;
}
else if (sender.hasPermission("booscooldowns.globalreset")
&& args[0].equalsIgnoreCase("startglobalreset")) {
BoosLimitManager.setGlobalLimitResetDate();
startLimitResetTimersGlobal();
return true;
}
}
else if (args.length == 2) {
String jmeno = args[1];
Player player = Bukkit.getPlayerExact(jmeno);
UUID uuid = player.getUniqueId();
if (sender.hasPermission("booscooldowns.clearcooldowns")
&& args[0].equalsIgnoreCase("clearcooldowns")) {
String co = "cooldown";
BoosConfigManager.clearSomething(co, uuid);
boosChat.sendMessageToCommandSender(sender,
"&6[" + pdfFile.getName() + "]&e"
+ " cooldowns of player " + jmeno
+ " cleared");
return true;
} else if (sender.hasPermission("booscooldowns.clearuses")
&& command.equalsIgnoreCase("booscooldowns")
&& args[0].equalsIgnoreCase("clearuses")) {
String co = "uses";
BoosConfigManager.clearSomething(co, uuid);
boosChat.sendMessageToCommandSender(sender,
"&6[" + pdfFile.getName() + "]&e"
+ " uses of player " + jmeno + " cleared");
return true;
} else if (sender.hasPermission("booscooldowns.clearwarmups")
&& command.equalsIgnoreCase("booscooldowns")
&& args[0].equalsIgnoreCase("clearwarmups")) {
String co = "warmup";
BoosConfigManager.clearSomething(co, uuid);
boosChat.sendMessageToCommandSender(sender,
"&6[" + pdfFile.getName() + "]&e"
+ " warmups of player " + jmeno
+ " cleared");
return true;
}
}
else if (args.length == 3) {
String jmeno = args[1];
Player player = Bukkit.getPlayerExact(jmeno);
UUID uuid = player.getUniqueId();
String command2 = args[2].trim();
if (sender.hasPermission("booscooldowns.clearcooldowns")
&& args[0].equalsIgnoreCase("clearcooldowns")) {
String co = "cooldown";
BoosConfigManager.clearSomething(co, uuid, command2);
boosChat.sendMessageToCommandSender(sender,
"&6[" + pdfFile.getName() + "]&e"
+ " cooldown for command " + command2
+ " of player " + uuid + " cleared");
return true;
} else if (sender.hasPermission("booscooldowns.clearuses")
&& args[0].equalsIgnoreCase("clearuses")) {
String co = "uses";
BoosConfigManager.clearSomething(co, uuid, command2);
boosChat.sendMessageToCommandSender(sender,
"&6[" + pdfFile.getName() + "]&e"
+ " uses for command " + command2
+ " of player " + jmeno + " cleared");
return true;
} else if (sender.hasPermission("booscooldowns.clearwarmups")
&& args[0].equalsIgnoreCase("clearwarmups")) {
String co = "warmup";
BoosConfigManager.clearSomething(co, uuid, command2);
boosChat.sendMessageToCommandSender(sender,
"&6[" + pdfFile.getName() + "]&e"
+ " warmups for command " + command2
+ " of player " + jmeno + " cleared");
return true;
} private static long secondsBetween(Calendar startDate, Calendar endDate,
} long limitResetDelay) {
else if (args.length == 4) { long secondsBetween = 0;
if (sender.hasPermission("booscooldowns.set") secondsBetween = ((endDate.getTimeInMillis() - startDate
&& args[0].equalsIgnoreCase("set")) { .getTimeInMillis()) / 1000) + limitResetDelay;
String what = args[1]; return secondsBetween;
String comm = args[2]; }
String value = args[3];
String group = "default";
if (comm.startsWith("/") || comm.equals("*")) {
if (comm.contains("_")) {
comm = comm.replace("_", " ");
}
BoosConfigManager.setAddToConfigFile(group, comm, what,
value);
boosChat.sendMessageToCommandSender(sender, "&6["
+ pdfFile.getName() + "]&e " + what
+ " for command" + comm + " in group " + group
+ " is now set to " + value);
return true;
} else {
boosChat.sendMessageToCommandSender(sender, "&6["
+ pdfFile.getName() + "]&e"
+ " Command has to start with \"/\".");
return true;
}
}
} private static Date getCurrTime() {
else if (args.length == 5) { String currTime = "";
if (sender.hasPermission("booscooldowns.set") Calendar cal = Calendar.getInstance();
&& args[0].equalsIgnoreCase("set")) { SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
String what = args[1]; currTime = sdf.format(cal.getTime());
String comm = args[2]; Date time;
String value = args[3]; try {
String group = args[4]; time = sdf.parse(currTime);
if (comm.startsWith("/") || comm.equals("*")) { return time;
if (comm.contains("_")) { } catch (ParseException e) {
comm = comm.replace("_", " "); return null;
} }
BoosConfigManager.setAddToConfigFile(group, comm, what, }
value);
boosChat.sendMessageToCommandSender(sender, "&6["
+ pdfFile.getName() + "]&e " + what
+ " for command" + comm + " in group " + group
+ " is now set to " + value);
return true;
} else {
boosChat.sendMessageToCommandSender(sender, "&6["
+ pdfFile.getName() + "]&e"
+ " Command has to start with \"/\".");
return true;
}
}
} else { private static Date getTime(String confTime) {
if (confTime != null && !confTime.equals("")) {
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
Date lastDate;
try {
lastDate = sdf.parse(confTime);
return lastDate;
} catch (ParseException e) {
return null;
}
}
return null;
}
private void initializeVault() {
Plugin x = pm.getPlugin("Vault");
if (x != null & x instanceof Vault) {
log.info("[" + pdfFile.getName() + "]"
+ " found [Vault] searching for economy plugin.");
usingVault = true;
if (setupEconomy()) {
log.info("[" + pdfFile.getName() + "]" + " found ["
+ economy.getName()
+ "] plugin, enabling prices support.");
} else {
log.info("["
+ pdfFile.getName()
+ "]"
+ " economy plugin not found, disabling prices support.");
}
} else {
log.info("[" + pdfFile.getName() + "]"
+ " [Vault] not found disabling economy support.");
usingVault = false;
}
}
@SuppressWarnings("deprecation")
@Override
public boolean onCommand(CommandSender sender, Command c,
String commandLabel, String[] args) {
String command = c.getName().toLowerCase();
if (command.equalsIgnoreCase("booscooldowns")) {
if (args.length == 1) {
if (sender.hasPermission("booscooldowns.reload")
&& args[0].equalsIgnoreCase("reload")) {
reload();
boosChat.sendMessageToCommandSender(sender,
"&6[" + pdfFile.getName() + "]&e"
+ " config reloaded");
return true;
}
if (sender.hasPermission("booscooldowns.list.limits")
&& args[0].equalsIgnoreCase("limits")) {
try {
Player send = (Player) sender;
Set<String> commands = BoosConfigManager
.getCommands(send);
for (String comm : commands) {
int lim = BoosConfigManager.getLimit(comm, send);
BoosLimitManager.getLimitListMessages(send, comm,
lim);
}
} catch (ClassCastException e) {
log.warning("You cannot use this command from console!");
}
return true;
} else if (sender.hasPermission("booscooldowns.globalreset")
&& args[0].equalsIgnoreCase("startglobalreset")) {
BoosLimitManager.setGlobalLimitResetDate();
startLimitResetTimersGlobal();
return true;
}
} else if (args.length == 2) {
String jmeno = args[1];
Player player = Bukkit.getPlayerExact(jmeno);
UUID uuid = player.getUniqueId();
if (sender.hasPermission("booscooldowns.clearcooldowns")
&& args[0].equalsIgnoreCase("clearcooldowns")) {
String co = "cooldown";
BoosConfigManager.clearSomething(co, uuid);
boosChat.sendMessageToCommandSender(sender,
"&6[" + pdfFile.getName() + "]&e"
+ " cooldowns of player " + jmeno
+ " cleared");
return true;
} else if (sender.hasPermission("booscooldowns.clearuses")
&& command.equalsIgnoreCase("booscooldowns")
&& args[0].equalsIgnoreCase("clearuses")) {
String co = "uses";
BoosConfigManager.clearSomething(co, uuid);
boosChat.sendMessageToCommandSender(sender,
"&6[" + pdfFile.getName() + "]&e"
+ " uses of player " + jmeno + " cleared");
return true;
} else if (sender.hasPermission("booscooldowns.clearwarmups")
&& command.equalsIgnoreCase("booscooldowns")
&& args[0].equalsIgnoreCase("clearwarmups")) {
String co = "warmup";
BoosConfigManager.clearSomething(co, uuid);
boosChat.sendMessageToCommandSender(sender,
"&6[" + pdfFile.getName() + "]&e"
+ " warmups of player " + jmeno
+ " cleared");
return true;
}
} else if (args.length == 3) {
String jmeno = args[1];
Player player = Bukkit.getPlayerExact(jmeno);
UUID uuid = player.getUniqueId();
String command2 = args[2].trim();
if (sender.hasPermission("booscooldowns.clearcooldowns")
&& args[0].equalsIgnoreCase("clearcooldowns")) {
String co = "cooldown";
BoosConfigManager.clearSomething(co, uuid, command2);
boosChat.sendMessageToCommandSender(sender,
"&6[" + pdfFile.getName() + "]&e"
+ " cooldown for command " + command2
+ " of player " + uuid + " cleared");
return true;
} else if (sender.hasPermission("booscooldowns.clearuses")
&& args[0].equalsIgnoreCase("clearuses")) {
String co = "uses";
BoosConfigManager.clearSomething(co, uuid, command2);
boosChat.sendMessageToCommandSender(sender,
"&6[" + pdfFile.getName() + "]&e"
+ " uses for command " + command2
+ " of player " + jmeno + " cleared");
return true;
} else if (sender.hasPermission("booscooldowns.clearwarmups")
&& args[0].equalsIgnoreCase("clearwarmups")) {
String co = "warmup";
BoosConfigManager.clearSomething(co, uuid, command2);
boosChat.sendMessageToCommandSender(sender,
"&6[" + pdfFile.getName() + "]&e"
+ " warmups for command " + command2
+ " of player " + jmeno + " cleared");
return true;
}
} else if (args.length == 4) {
if (sender.hasPermission("booscooldowns.set")
&& args[0].equalsIgnoreCase("set")) {
String what = args[1];
String comm = args[2];
String value = args[3];
String group = "default";
if (comm.startsWith("/") || comm.equals("*")) {
if (comm.contains("_")) {
comm = comm.replace("_", " ");
}
BoosConfigManager.setAddToConfigFile(group, comm, what,
value);
boosChat.sendMessageToCommandSender(sender, "&6["
+ pdfFile.getName() + "]&e " + what
+ " for command" + comm + " in group " + group
+ " is now set to " + value);
return true;
} else {
boosChat.sendMessageToCommandSender(sender, "&6["
+ pdfFile.getName() + "]&e"
+ " Command has to start with \"/\".");
return true;
}
}
} else if (args.length == 5) {
if (sender.hasPermission("booscooldowns.set")
&& args[0].equalsIgnoreCase("set")) {
String what = args[1];
String comm = args[2];
String value = args[3];
String group = args[4];
if (comm.startsWith("/") || comm.equals("*")) {
if (comm.contains("_")) {
comm = comm.replace("_", " ");
}
BoosConfigManager.setAddToConfigFile(group, comm, what,
value);
boosChat.sendMessageToCommandSender(sender, "&6["
+ pdfFile.getName() + "]&e " + what
+ " for command" + comm + " in group " + group
+ " is now set to " + value);
return true;
} else {
boosChat.sendMessageToCommandSender(sender, "&6["
+ pdfFile.getName() + "]&e"
+ " Command has to start with \"/\".");
return true;
}
}
} else {
// boosChat.sendMessageToCommandSender(sender, // boosChat.sendMessageToCommandSender(sender,
// "&6[" + pdfFile.getName() + "]&e" // "&6[" + pdfFile.getName() + "]&e"
// + " Invalid command or access denied!"); // + " Invalid command or access denied!");
return false; return false;
} }
} }
return false; return false;
} }
/* @Override
* (non-Javadoc) public void onDisable() {
* if (BoosConfigManager.getClearOnRestart()) {
* @see org.bukkit.plugin.java.JavaPlugin#onDisable() BoosConfigManager.clear();
*/ log.info("[" + pdfFile.getName() + "]" + " cooldowns cleared!");
@Override } else {
public void onDisable() { BoosConfigManager.saveConfusers();
if (BoosConfigManager.getClearOnRestart()) { log.info("[" + pdfFile.getName() + "]" + " cooldowns saved!");
BoosConfigManager.clear(); }
log.info("[" + pdfFile.getName() + "]" + " cooldowns cleared!"); log.info("[" + pdfFile.getName() + "]" + " version "
} else { + pdfFile.getVersion() + " disabled!");
BoosConfigManager.saveConfusers(); }
log.info("[" + pdfFile.getName() + "]" + " cooldowns saved!");
}
log.info("[" + pdfFile.getName() + "]" + " version "
+ pdfFile.getVersion() + " disabled!");
}
/* @Override
* (non-Javadoc) public void onEnable() {
* pdfFile = this.getDescription();
* @see org.bukkit.plugin.java.JavaPlugin#onEnable() PluginDescriptionFile pdfFile = this.getDescription();
*/ log.info("[" + pdfFile.getName() + "]" + " version "
@Override + pdfFile.getVersion() + " by " + pdfFile.getAuthors()
public void onEnable() { + " is enabled!");
pdfFile = this.getDescription(); this.saveDefaultConfig();
PluginDescriptionFile pdfFile = this.getDescription(); new BoosConfigManager(this);
log.info("[" + pdfFile.getName() + "]" + " version " BoosConfigManager.load();
+ pdfFile.getVersion() + " by " + pdfFile.getAuthors() BoosConfigManager.loadConfusers();
+ " is enabled!"); pm = getServer().getPluginManager();
this.saveDefaultConfig(); registerListeners();
new BoosConfigManager(this); initializeVault();
BoosConfigManager.load(); BukkitScheduler scheduler = this.getServer().getScheduler();
BoosConfigManager.loadConfusers(); startLimitResetTimersGlobal();
pm = getServer().getPluginManager(); if (BoosConfigManager.getAutoSave()) {
registerListeners(); scheduler.scheduleSyncRepeatingTask(this, this,
initializeVault(); BoosConfigManager.getSaveInterval() * 1200,
BukkitScheduler scheduler = this.getServer().getScheduler(); BoosConfigManager.getSaveInterval() * 1200);
startLimitResetTimersGlobal(); }
if (BoosConfigManager.getAutoSave()) {
scheduler.scheduleSyncRepeatingTask(this, this,
BoosConfigManager.getSaveInterval() * 1200,
BoosConfigManager.getSaveInterval() * 1200);
}
if (BoosConfigManager.getClearOnRestart()) { if (BoosConfigManager.getClearOnRestart()) {
BoosConfigManager.clear(); BoosConfigManager.clear();
} }
try { try {
MetricsLite metrics = new MetricsLite(this); MetricsLite metrics = new MetricsLite(this);
metrics.start(); metrics.start();
} catch (IOException e) { } catch (IOException e) {
// Failed to submit the stats :-( // Failed to submit the stats :-(
} }
} }
static void startLimitResetTimersGlobal() { private void registerListeners() {
YamlConfiguration confusers = BoosConfigManager.getConfusers(); HandlerList.unregisterAll(this);
ConfigurationSection global = confusers pm.registerEvents(new BoosCoolDownListener(this), this);
.getConfigurationSection("global"); if (BoosConfigManager.getCancelWarmUpOnDamage()) {
if (global != null) { pm.registerEvents(new BoosEntityDamageListener(), this);
Set<String> globalKeys = global.getKeys(false); }
BukkitScheduler scheduler = Bukkit.getScheduler(); if (BoosConfigManager.getCleanCooldownsOnDeath()
for (String key : globalKeys) { || BoosConfigManager.getCleanUsesOnDeath()
String confTime = confusers.getString("global." + key || BoosConfigManager.getStartCooldownsOnDeath()) {
+ ".reset"); pm.registerEvents(new BoosPlayerDeathListener(), this);
long limitResetDelay = BoosConfigManager }
.getLimitResetDelayGlobal(key); if (BoosConfigManager.getCancelWarmUpOnGameModeChange()) {
Date endDate = getTime(confTime); pm.registerEvents(new BoosPlayerGameModeChangeListener(), this);
Date startDate = getCurrTime(); }
Calendar calcurrTime = Calendar.getInstance(); if (BoosConfigManager.getBlockInteractDuringWarmup()) {
calcurrTime.setTime(startDate); pm.registerEvents(new BoosPlayerInteractListener(), this);
Calendar callastTime = Calendar.getInstance(); }
callastTime.setTime(endDate); if (BoosConfigManager.getCancelWarmupOnMove()) {
long time = secondsBetween(calcurrTime, callastTime, pm.registerEvents(new BoosPlayerMoveListener(), this);
limitResetDelay); }
if (limitResetDelay != -65535) { if (BoosConfigManager.getCancelWarmupOnSneak()) {
if (time <= 0) { pm.registerEvents(new BoosPlayerToggleSneakListener(), this);
time = 1; }
} if (BoosConfigManager.getCancelWarmupOnSprint()) {
BoosCoolDown.getLog().info( pm.registerEvents(new BoosPlayerToggleSprintListener(), this);
"[boosCooldowns] Starting timer for " + time }
+ " seconds to reset limits for command " if (BoosConfigManager.getSignCommands()) {
+ key); pm.registerEvents(new BoosSignChangeListener(), this);
scheduler.scheduleSyncDelayedTask(Bukkit.getPluginManager() pm.registerEvents(new BoosSignInteractListener(this), this);
.getPlugin("boosCooldowns"), }
new BoosGlobalLimitResetRunnable(key), time * 20); }
} else {
BoosCoolDown.getLog().info(
"[boosCooldowns] Stoping timer to reset limits for command "
+ key);
}
}
}
}
static void startLimitResetTimerGlobal(String key) { private void reload() {
YamlConfiguration confusers = BoosConfigManager.getConfusers(); BoosConfigManager.reload();
BukkitScheduler scheduler = Bukkit.getScheduler(); registerListeners();
String confTime = confusers.getString("global." + key + ".reset"); }
long limitResetDelay = BoosConfigManager.getLimitResetDelayGlobal(key);
Date endDate = getTime(confTime);
Date startDate = getCurrTime();
Calendar calcurrTime = Calendar.getInstance();
calcurrTime.setTime(startDate);
Calendar callastTime = Calendar.getInstance();
callastTime.setTime(endDate);
long time = secondsBetween(calcurrTime, callastTime, limitResetDelay);
if (limitResetDelay != -65535) {
if (time <= 0) {
time = 1;
}
BoosCoolDown.getLog().info(
"[boosCooldowns] Starting timer for " + time
+ " seconds to reset limits for command " + key);
scheduler.scheduleSyncDelayedTask(Bukkit.getPluginManager()
.getPlugin("boosCooldowns"),
new BoosGlobalLimitResetRunnable(key), time * 20);
} else {
BoosCoolDown.getLog().info(
"[boosCooldowns] Stoping timer to reset limits for command "
+ key);
}
}
static long secondsBetween(Calendar startDate, Calendar endDate, @Override
long limitResetDelay) { public void run() {
long secondsBetween = 0; BoosConfigManager.saveConfusers();
secondsBetween = ((endDate.getTimeInMillis() - startDate BoosConfigManager.loadConfusers();
.getTimeInMillis()) / 1000) + limitResetDelay; log.info("[boosCooldowns] Config saved!");
return secondsBetween; }
}
static Date getCurrTime() { private boolean setupEconomy() {
String currTime = ""; if (usingVault) {
Calendar cal = Calendar.getInstance(); RegisteredServiceProvider<Economy> economyProvider = getServer()
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss"); .getServicesManager().getRegistration(
currTime = sdf.format(cal.getTime()); net.milkbowl.vault.economy.Economy.class);
Date time = null; if (economyProvider != null) {
try { economy = economyProvider.getProvider();
time = sdf.parse(currTime); }
return time; return (economy != null);
} catch (ParseException e) { }
return null; return false;
} }
}
static Date getTime(String confTime) {
if (confTime != null && !confTime.equals("")) {
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
Date lastDate = null;
try {
lastDate = sdf.parse(confTime);
return lastDate;
} catch (ParseException e) {
return null;
}
}
return null;
}
/**
* Metoda registruje poslucha<EFBFBD>e v PluginManageru na z<EFBFBD>klad<EFBFBD> konfigurace
* pluginu. Registroj<EFBFBD> se v<EFBFBD>dy jen nezbytn<EFBFBD> poslucha<EFBFBD>i. Poslucha<EFBFBD>i pro
* vypnut<EFBFBD> funkce nejsou registrov<EFBFBD>ni.
*/
private void registerListeners() {
HandlerList.unregisterAll(this);
pm.registerEvents(new BoosCoolDownListener(this), this);
if (BoosConfigManager.getCancelWarmUpOnDamage()) {
pm.registerEvents(new BoosEntityDamageListener(), this);
}
if (BoosConfigManager.getCleanCooldownsOnDeath()
|| BoosConfigManager.getCleanUsesOnDeath()
|| BoosConfigManager.getStartCooldownsOnDeath()) {
pm.registerEvents(new BoosPlayerDeathListener(), this);
}
if (BoosConfigManager.getCancelWarmUpOnGameModeChange()) {
pm.registerEvents(new BoosPlayerGameModeChangeListener(), this);
}
if (BoosConfigManager.getBlockInteractDuringWarmup()) {
pm.registerEvents(new BoosPlayerInteractListener(), this);
}
if (BoosConfigManager.getCancelWarmupOnMove()) {
pm.registerEvents(new BoosPlayerMoveListener(), this);
}
if (BoosConfigManager.getCancelWarmupOnSneak()) {
pm.registerEvents(new BoosPlayerToggleSneakListener(), this);
}
if (BoosConfigManager.getCancelWarmupOnSprint()) {
pm.registerEvents(new BoosPlayerToggleSprintListener(), this);
}
if (BoosConfigManager.getSignCommands()) {
pm.registerEvents(new BoosSignChangeListener(), this);
pm.registerEvents(new BoosSignInteractListener(this), this);
}
}
/**
* Metoda vol<EFBFBD> metodu pro znovuna<EFBFBD>ten<EFBFBD> konfigura<EFBFBD>n<EFBFBD>ho souboru a metodu pro
* registraci poslucha<EFBFBD><EFBFBD>.
*/
private void reload() {
BoosConfigManager.reload();
registerListeners();
}
/*
* (non-Javadoc)
*
* @see java.lang.Runnable#run()
*/
@Override
public void run() {
BoosConfigManager.saveConfusers();
BoosConfigManager.loadConfusers();
log.info("[boosCooldowns] Config saved!");
}
/**
* Metoda vrac<EFBFBD> hodnotu true, pokud je na serveru dostupn<EFBFBD> Ekonomick<EFBFBD> plugin
* kompatibiln<EFBFBD> s pluginem Vault.
*
* @return true pokud je dostupn<EFBFBD> ekonomick<EFBFBD> plugin kompatibiln<EFBFBD> s pluginem
* Vault, jinak vrac<EFBFBD> hodnotu false
*/
private boolean setupEconomy() {
if (usingVault) {
RegisteredServiceProvider<Economy> economyProvider = getServer()
.getServicesManager().getRegistration(
net.milkbowl.vault.economy.Economy.class);
if (economyProvider != null) {
economy = economyProvider.getProvider();
}
return (economy != null);
}
return false;
}
public static BoosCoolDown getInstance() {
if (instance == null) {
instance = new BoosCoolDown();
}
return instance;
}
} }

View File

@ -1,283 +1,223 @@
package cz.boosik.boosCooldown; package cz.boosik.boosCooldown;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import util.boosChat; import util.boosChat;
/** import java.util.List;
* Hlavn<EFBFBD> poslucha<EFBFBD>, kter<EFBFBD> naslouch<EFBFBD> ud<EFBFBD>losti pou<EFBFBD>it<EFBFBD> p<EFBFBD><EFBFBD>kazu hr<EFBFBD><EFBFBD>em. import java.util.Set;
* Kontroluje, jestli jsou pro p<EFBFBD><EFBFBD>kaz nastaveny omezen<EFBFBD> a na z<EFBFBD>klad<EFBFBD> tohoto import java.util.regex.Matcher;
* spou<EFBFBD>t<EFBFBD> <EFBFBD>asova<EFBFBD>e a vol<EFBFBD> metody spojen<EFBFBD> s poplatky a limity. import java.util.regex.Pattern;
*
* @author Jakub Kol<EFBFBD><EFBFBD>
*
*/
public class BoosCoolDownListener implements Listener {
private static BoosCoolDown plugin;
/** class BoosCoolDownListener implements Listener {
* @param instance private static BoosCoolDown plugin;
*/
public BoosCoolDownListener(BoosCoolDown instance) {
plugin = instance;
}
/** public BoosCoolDownListener(BoosCoolDown instance) {
* Metoda zkontroluje pomoc<EFBFBD> vol<EFBFBD>n<EFBFBD> dal<EFBFBD><EFBFBD>ch metod, jestli p<EFBFBD>ikaz kter<EFBFBD> hr<EFBFBD><EFBFBD> plugin = instance;
* 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 }
* pou<EFBFBD>it<EFBFBD> p<EFBFBD><EFBFBD>kazu stornov<EFBFBD>na, nebo ne.
*
* @param event
* ud<EFBFBD>lost PlayerCommandPreprocessEvent
* @param player
* hr<EFBFBD><EFBFBD> kter<EFBFBD> spustil tuto ud<EFBFBD>lost
* @param regexCommad
* p<EFBFBD><EFBFBD>kaz z konfigura<EFBFBD>n<EFBFBD>ho souboru, kter<EFBFBD> vyhovuje origin<EFBFBD>ln<EFBFBD>mu
* p<EFBFBD><EFBFBD>kazu
* @param originalCommand
* origin<EFBFBD>ln<EFBFBD> p<EFBFBD><EFBFBD>kaz kter<EFBFBD> hr<EFBFBD><EFBFBD> pou<EFBFBD>il
* @param warmupTime
* warmup doba nastaven<EFBFBD> pro regexCommand
* @param cooldownTime
* cooldown doba nastaven<EFBFBD> pro regexCommand
* @param price
* cena nastaven<EFBFBD> pro regexCommand
* @param limit
* limit nastaven<EFBFBD> pro regexCommand
*/
private void checkRestrictions(PlayerCommandPreprocessEvent event,
Player player, String regexCommad, String originalCommand,
int warmupTime, int cooldownTime, double price, String item,
int count, int limit, int xpPrice) {
boolean blocked = false;
if (limit != -1) {
blocked = BoosLimitManager.blocked(player, regexCommad,
originalCommand, limit);
}
if (!blocked) {
if (warmupTime > 0) {
if (!player.hasPermission("booscooldowns.nowarmup")
&& !player.hasPermission("booscooldowns.nowarmup."
+ originalCommand)) {
start(event, player, regexCommad, originalCommand,
warmupTime, cooldownTime);
}
} else if (BoosPriceManager.has(player, price)
& BoosItemCostManager.has(player, item, count)
& BoosXpCostManager.has(player, xpPrice)) {
if (BoosCoolDownManager.coolDown(player, regexCommad,
originalCommand, cooldownTime)) {
event.setCancelled(true);
}
}
if (BoosPriceManager.has(player, price)
& BoosItemCostManager.has(player, item, count)
& BoosXpCostManager.has(player, xpPrice)) {
if (!event.isCancelled()) {
BoosPriceManager.payForCommand(event, player, regexCommad,
originalCommand, price);
}
if (!event.isCancelled()) {
BoosItemCostManager.payItemForCommand(event, player,
regexCommad, originalCommand, item, count);
}
if (!event.isCancelled()) {
BoosXpCostManager.payXPForCommand(event, player,
regexCommad, originalCommand, xpPrice);
}
} else {
if (!BoosPriceManager.has(player, price)
& !BoosWarmUpManager.isWarmUpProcess(player,
regexCommad)) {
String unit;
String msg = "";
if (price == 1) {
unit = BoosCoolDown.getEconomy().currencyNameSingular();
} else {
unit = BoosCoolDown.getEconomy().currencyNamePlural();
}
msg = String.format(
BoosConfigManager.getInsufficientFundsMessage(),
(price + " " + unit),
BoosCoolDown.getEconomy().format(
BoosCoolDown.getEconomy()
.getBalance(player)));
msg = msg.replaceAll("&command&", originalCommand);
boosChat.sendMessageToPlayer(player, msg);
}
if (!BoosItemCostManager.has(player, item, count)
& !BoosWarmUpManager.isWarmUpProcess(player,
regexCommad)) {
String msg = "";
msg = String.format(
BoosConfigManager.getInsufficientItemsMessage(),
(count + " " + item));
msg = msg.replaceAll("&command&", originalCommand);
boosChat.sendMessageToPlayer(player, msg);
}
if (!BoosXpCostManager.has(player, xpPrice)
& !BoosWarmUpManager.isWarmUpProcess(player,
regexCommad)) {
String msg = "";
msg = String.format(
BoosConfigManager.getInsufficientXpMessage(),
(xpPrice));
msg = msg.replaceAll("&command&", originalCommand);
boosChat.sendMessageToPlayer(player, msg);
}
event.setCancelled(true);
}
if (!event.isCancelled()) {
String msg = String.format(BoosConfigManager.getMessage(
regexCommad, player));
if (!msg.equals("")) {
boosChat.sendMessageToPlayer(player, msg);
}
}
} else {
event.setCancelled(true);
}
if (!event.isCancelled()) {
BoosLimitManager.setUses(player, regexCommad);
if (BoosConfigManager.getCommandLogging()) {
BoosCoolDown.commandLogger(player.getName(), originalCommand);
}
}
}
/** private void checkRestrictions(PlayerCommandPreprocessEvent event,
* 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> Player player, String regexCommad, String originalCommand,
* p<EFBFBD>ed t<EFBFBD>m, ne<EFBFBD> je vykon<EFBFBD>n efekt tohto p<EFBFBD><EFBFBD>kazu. Metoda zji<EFBFBD><EFBFBD>uje, jestli int warmupTime, int cooldownTime, double price, String item,
* 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> int count, int limit, int xpPrice) {
* pou<EFBFBD>il shoduje s p<EFBFBD><EFBFBD>kazem nastaven<EFBFBD>m v konfiguraci. Pokud se shoduje, pak boolean blocked = false;
* jsou na<EFBFBD>teny informace o warmup dob<EFBFBD>, cooldown dob<EFBFBD>, poplatku a limitu. if (limit != -1) {
* Tyto hodnoty jsou pot<EFBFBD> p<EFBFBD>ed<EFBFBD>ny metod<EFBFBD> checkRestrictions();. blocked = BoosLimitManager.blocked(player, regexCommad,
* originalCommand, limit);
* @param event }
* ud<EFBFBD>lost PlayerCommandPreprocessEvent if (!blocked) {
*/ if (warmupTime > 0) {
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) if (!player.hasPermission("booscooldowns.nowarmup")
private void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) { && !player.hasPermission("booscooldowns.nowarmup."
Player player = event.getPlayer(); + originalCommand)) {
if (event.getMessage().contains(":")) { start(event, player, regexCommad, originalCommand,
Pattern p = Pattern.compile("^/([a-zA-Z0-9_]+):"); warmupTime, cooldownTime);
Matcher m = p.matcher(event.getMessage()); }
if (m.find()) { } else if (BoosPriceManager.has(player, price)
{ & BoosItemCostManager.has(player, item, count)
boosChat.sendMessageToPlayer(player, BoosConfigManager & BoosXpCostManager.has(player, xpPrice)) {
.getInvalidCommandSyntaxMessage(player)); if (BoosCoolDownManager.coolDown(player, regexCommad,
event.setCancelled(true); originalCommand, cooldownTime)) {
return; event.setCancelled(true);
} }
} }
} if (BoosPriceManager.has(player, price)
String originalCommand = event.getMessage().replace("\\", "\\\\"); & BoosItemCostManager.has(player, item, count)
originalCommand = originalCommand.replace("$", "S"); & BoosXpCostManager.has(player, xpPrice)) {
originalCommand = originalCommand.trim().replaceAll(" +", " "); if (!event.isCancelled()) {
String regexCommad = ""; BoosPriceManager.payForCommand(event, player, regexCommad,
Set<String> aliases = BoosConfigManager.getAliases(); originalCommand, price);
Set<String> commands = BoosConfigManager.getCommands(player); }
boolean on = true; if (!event.isCancelled()) {
String item = ""; BoosItemCostManager.payItemForCommand(event, player,
int count = 0; regexCommad, originalCommand, item, count);
int warmupTime = 0; }
double price = 0; if (!event.isCancelled()) {
int limit = -1; BoosXpCostManager.payXPForCommand(event, player,
int cooldownTime = 0; regexCommad, originalCommand, xpPrice);
int xpPrice = 0; }
on = BoosCoolDown.isPluginOnForPlayer(player); } else {
if (aliases != null) { if (!BoosPriceManager.has(player, price)
originalCommand = BoosAliasManager.checkCommandAlias( & !BoosWarmUpManager.isWarmUpProcess(player,
originalCommand, aliases, player); regexCommad)) {
event.setMessage(originalCommand); String unit;
} String msg = "";
if (on && commands != null) { if (price == 1) {
for (String group : commands) { unit = BoosCoolDown.getEconomy().currencyNameSingular();
String group2 = group.replace("*", ".+"); } else {
if (originalCommand.matches("(?i)" + group2)) { unit = BoosCoolDown.getEconomy().currencyNamePlural();
regexCommad = group; }
if (BoosConfigManager.getWarmupEnabled()) { msg = String.format(
warmupTime = BoosConfigManager.getWarmUp(regexCommad, BoosConfigManager.getInsufficientFundsMessage(),
player); (price + " " + unit),
} BoosCoolDown.getEconomy().format(
if (BoosConfigManager.getCooldownEnabled()) { BoosCoolDown.getEconomy()
cooldownTime = BoosConfigManager.getCoolDown( .getBalance(player)));
regexCommad, player); msg = msg.replaceAll("&command&", originalCommand);
} boosChat.sendMessageToPlayer(player, msg);
if (BoosConfigManager.getPriceEnabled()) { }
price = BoosConfigManager.getPrice(regexCommad, player); if (!BoosItemCostManager.has(player, item, count)
} & !BoosWarmUpManager.isWarmUpProcess(player,
if (BoosConfigManager.getXpPriceEnabled()) { regexCommad)) {
xpPrice = BoosConfigManager.getXpPrice(regexCommad, String msg = "";
player); msg = String.format(
} BoosConfigManager.getInsufficientItemsMessage(),
if (BoosConfigManager.getItemCostEnabled()) { (count + " " + item));
item = BoosConfigManager.getItemCostItem(regexCommad, msg = msg.replaceAll("&command&", originalCommand);
player); boosChat.sendMessageToPlayer(player, msg);
count = BoosConfigManager.getItemCostCount(regexCommad, }
player); if (!BoosXpCostManager.has(player, xpPrice)
} & !BoosWarmUpManager.isWarmUpProcess(player,
if (BoosConfigManager.getLimitEnabled()) { regexCommad)) {
limit = BoosConfigManager.getLimit(regexCommad, player); String msg = "";
} msg = String.format(
break; BoosConfigManager.getInsufficientXpMessage(),
} (xpPrice));
} msg = msg.replaceAll("&command&", originalCommand);
this.checkRestrictions(event, player, regexCommad, originalCommand, boosChat.sendMessageToPlayer(player, msg);
warmupTime, cooldownTime, price, item, count, limit, }
xpPrice); event.setCancelled(true);
} }
} if (!event.isCancelled()) {
String msg = String.format(BoosConfigManager.getMessage(
regexCommad, player));
if (!msg.equals("")) {
boosChat.sendMessageToPlayer(player, msg);
}
}
} else {
event.setCancelled(true);
}
if (!event.isCancelled()) {
List<String> linkGroup = BoosConfigManager.getSharedLimits(
regexCommad, player);
if (linkGroup.isEmpty()) {
BoosLimitManager.setUses(player, regexCommad);
} else {
BoosLimitManager.setUses(player, regexCommad);
for (String a : linkGroup) {
BoosLimitManager.setUses(player, a);
}
}
if (BoosConfigManager.getCommandLogging()) {
BoosCoolDown.commandLogger(player.getName(), originalCommand);
}
}
}
/** @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
* Metoda spou<EFBFBD>t<EFBFBD> warmup a cooldown <EFBFBD>asova<EFBFBD>e, p<EFBFBD><EFBFBD>padn<EFBFBD> je ukon<EFBFBD>uje, pokud private void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
* ji<EFBFBD> tyto <EFBFBD>asova<EFBFBD>e skon<EFBFBD>ili. Player player = event.getPlayer();
* if (event.getMessage().contains(":")) {
* @param event Pattern p = Pattern.compile("^/([a-zA-Z0-9_]+):");
* ud<EFBFBD>lost PlayerCommandPreprocessEvent Matcher m = p.matcher(event.getMessage());
* @param player if (m.find()) {
* hr<EFBFBD><EFBFBD> kter<EFBFBD> spustil tuto ud<EFBFBD>lost {
* @param regexCommad boosChat.sendMessageToPlayer(player, BoosConfigManager
* p<EFBFBD><EFBFBD>kaz z konfigura<EFBFBD>n<EFBFBD>ho souboru, kter<EFBFBD> vyhovuje origin<EFBFBD>ln<EFBFBD>mu .getInvalidCommandSyntaxMessage());
* p<EFBFBD><EFBFBD>kazu event.setCancelled(true);
* @param originalCommand return;
* origin<EFBFBD>ln<EFBFBD> p<EFBFBD><EFBFBD>kaz kter<EFBFBD> hr<EFBFBD><EFBFBD> pou<EFBFBD>il }
* @param warmupTime }
* warmup doba nastaven<EFBFBD> pro regexCommand }
* @param cooldownTime String originalCommand = event.getMessage().replace("\\", "\\\\");
* cooldown doba nastaven<EFBFBD> pro regexCommand originalCommand = originalCommand.replace("$", "S");
*/ originalCommand = originalCommand.trim().replaceAll(" +", " ");
private void start(PlayerCommandPreprocessEvent event, Player player, String regexCommad = "";
String regexCommad, String originalCommand, int warmupTime, Set<String> aliases = BoosConfigManager.getAliases();
int cooldownTime) { Set<String> commands = BoosConfigManager.getCommands(player);
if (!BoosWarmUpManager.checkWarmUpOK(player, regexCommad)) { boolean on;
if (BoosCoolDownManager.checkCoolDownOK(player, regexCommad, String item = "";
originalCommand, cooldownTime)) { int count = 0;
BoosWarmUpManager.startWarmUp(plugin, player, regexCommad, int warmupTime = 0;
originalCommand, warmupTime); double price = 0;
event.setCancelled(true); int limit = -1;
return; int cooldownTime = 0;
} else { int xpPrice = 0;
event.setCancelled(true); on = BoosCoolDown.isPluginOnForPlayer(player);
return; if (aliases != null) {
} originalCommand = BoosAliasManager.checkCommandAlias(
} else { originalCommand, aliases, player);
if (BoosCoolDownManager.coolDown(player, regexCommad, event.setMessage(originalCommand);
originalCommand, cooldownTime)) { }
event.setCancelled(true); if (on && commands != null) {
return; for (String group : commands) {
} else { String group2 = group.replace("*", ".+");
BoosWarmUpManager.removeWarmUpOK(player, regexCommad); if (originalCommand.matches("(?i)" + group2)) {
return; regexCommad = group;
} if (BoosConfigManager.getWarmupEnabled()) {
} warmupTime = BoosConfigManager.getWarmUp(regexCommad,
} player);
}
if (BoosConfigManager.getCooldownEnabled()) {
cooldownTime = BoosConfigManager.getCoolDown(
regexCommad, player);
}
if (BoosConfigManager.getPriceEnabled()) {
price = BoosConfigManager.getPrice(regexCommad, player);
}
if (BoosConfigManager.getXpPriceEnabled()) {
xpPrice = BoosConfigManager.getXpPrice(regexCommad,
player);
}
if (BoosConfigManager.getItemCostEnabled()) {
item = BoosConfigManager.getItemCostItem(regexCommad,
player);
count = BoosConfigManager.getItemCostCount(regexCommad,
player);
}
if (BoosConfigManager.getLimitEnabled()) {
limit = BoosConfigManager.getLimit(regexCommad, player);
}
break;
}
}
this.checkRestrictions(event, player, regexCommad, originalCommand,
warmupTime, cooldownTime, price, item, count, limit,
xpPrice);
}
}
private void start(PlayerCommandPreprocessEvent event, Player player,
String regexCommad, String originalCommand, int warmupTime,
int cooldownTime) {
if (!BoosWarmUpManager.checkWarmUpOK(player, regexCommad)) {
if (BoosCoolDownManager.checkCoolDownOK(player, regexCommad,
originalCommand, cooldownTime)) {
BoosWarmUpManager.startWarmUp(plugin, player, regexCommad,
originalCommand, warmupTime);
event.setCancelled(true);
} else {
event.setCancelled(true);
}
} else if (BoosCoolDownManager.coolDown(player, regexCommad,
originalCommand, cooldownTime)) {
event.setCancelled(true);
} else {
BoosWarmUpManager.removeWarmUpOK(player, regexCommad);
}
}
} }

View File

@ -1,300 +1,193 @@
package cz.boosik.boosCooldown; package cz.boosik.boosCooldown;
import org.bukkit.entity.Player;
import util.boosChat;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import org.bukkit.entity.Player;
import util.boosChat;
/**
* 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<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<EFBFBD><EFBFBD>
*
*/
public class BoosCoolDownManager { public class BoosCoolDownManager {
/**
* Metoda ukon<EFBFBD>uje specifikovan<EFBFBD> cooldown <EFBFBD>asova<EFBFBD> pro specifikovan<EFBFBD>ho hr<EFBFBD><EFBFBD>e.
*
* @param player
* specifick<EFBFBD> hr<EFBFBD><EFBFBD>
* @param regexCommand
* 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) {
int pre2 = regexCommand.toLowerCase().hashCode();
BoosConfigManager.getConfusers().set(
"users." + player.getUniqueId() + ".cooldown." + pre2, null);
}
/** static void cancelCooldown(Player player, String regexCommand) {
* Metoda vrac<EFBFBD> hodnotu boolean na z<EFBFBD>klad<EFBFBD> toho, jestli m<EFBFBD> specifikovan<EFBFBD> int pre2 = regexCommand.toLowerCase().hashCode();
* p<EFBFBD><EFBFBD>kaz aktivn<EFBFBD> cooldown <EFBFBD>asova<EFBFBD>. BoosConfigManager.getConfusers().set(
* "users." + player.getUniqueId() + ".cooldown." + pre2, null);
* @param player }
* specifikovan<EFBFBD> hr<EFBFBD><EFBFBD>
* @param regexCommand
* p<EFBFBD><EFBFBD>kaz z konfigurace vyhovuj<EFBFBD>c<EFBFBD> origin<EFBFBD>ln<EFBFBD>mu p<EFBFBD><EFBFBD>kazu
* @param originalCommand
* origin<EFBFBD>ln<EFBFBD> p<EFBFBD><EFBFBD>kaz pou<EFBFBD>it<EFBFBD> hr<EFBFBD><EFBFBD>em
* @param coolDownSeconds
* cooldown doba v sekund<EFBFBD>ch, nastaven<EFBFBD> pro regexCommand v
* konfiguraci
* @return true pokud je p<EFBFBD><EFBFBD>kaz na cooldown <EFBFBD>asova<EFBFBD>i, jinak false
*/
static boolean cd(Player player, String regexCommand,
String originalCommand, int coolDownSeconds) {
Date lastTime = getTime(player, regexCommand);
List<String> linkGroup = BoosConfigManager.getSharedCooldowns(
regexCommand, player);
if (lastTime == null) {
if (linkGroup.isEmpty()) {
setTime(player, regexCommand);
} else {
setTime(player, regexCommand);
for (String a : linkGroup) {
setTime(player, a);
}
}
return false;
} else {
Calendar calcurrTime = Calendar.getInstance();
calcurrTime.setTime(getCurrTime());
Calendar callastTime = Calendar.getInstance();
callastTime.setTime(lastTime);
long secondsBetween = secondsBetween(callastTime, calcurrTime);
long waitSeconds = coolDownSeconds - secondsBetween;
long waitMinutes = (long) Math.ceil(waitSeconds / 60.0);
long waitHours = (long) Math.ceil(waitMinutes / 60.0);
if (secondsBetween > coolDownSeconds) {
if (linkGroup.isEmpty()) {
setTime(player, regexCommand);
} else {
setTime(player, regexCommand);
for (String a : linkGroup) {
setTime(player, a);
}
}
return false;
} else {
String msg = BoosConfigManager.getCoolDownMessage();
msg = msg.replaceAll("&command&", originalCommand);
if (waitSeconds >= 60 && 3600 >= waitSeconds) {
msg = msg.replaceAll("&seconds&",
Long.toString(waitMinutes));
msg = msg.replaceAll("&unit&",
BoosConfigManager.getUnitMinutesMessage());
} else if (waitMinutes >= 60) {
msg = msg.replaceAll("&seconds&", Long.toString(waitHours));
msg = msg.replaceAll("&unit&",
BoosConfigManager.getUnitHoursMessage());
} else {
String secs = Long.toString(waitSeconds);
if (secs.equals("0")) {
secs = "1";
}
msg = msg.replaceAll("&seconds&", secs);
msg = msg.replaceAll("&unit&",
BoosConfigManager.getUnitSecondsMessage());
}
boosChat.sendMessageToPlayer(player, msg);
return true;
}
}
}
/** private static boolean cd(Player player, String regexCommand,
* Metoda kontroluje, jestli hr<EFBFBD><EFBFBD> nedisponuje opr<EFBFBD>vn<EFBFBD>n<EFBFBD>mi, kter<EFBFBD> obch<EFBFBD>zej<EFBFBD> String originalCommand, int coolDownSeconds) {
* cooldown <EFBFBD>asova<EFBFBD>e. Pokud t<EFBFBD>mito opr<EFBFBD>vn<EFBFBD>n<EFBFBD>mi hr<EFBFBD><EFBFBD> disponuje, pak metoda Date lastTime = getTime(player, regexCommand);
* vrac<EFBFBD> false. Pokud hr<EFBFBD><EFBFBD> nedisponuje t<EFBFBD>mito opr<EFBFBD>vn<EFBFBD>n<EFBFBD>mi, vrac<EFBFBD> hodnotu List<String> linkGroup = BoosConfigManager.getSharedCooldowns(
* vr<EFBFBD>cenou metodou cd();. regexCommand, player);
* if (lastTime == null) {
* @param player if (linkGroup.isEmpty()) {
* specifikovan<EFBFBD> hr<EFBFBD><EFBFBD> setTime(player, regexCommand);
* @param regexCommand } else {
* p<EFBFBD><EFBFBD>kaz z konfigurace vyhovuj<EFBFBD>c<EFBFBD> origin<EFBFBD>ln<EFBFBD>mu p<EFBFBD><EFBFBD>kazu setTime(player, regexCommand);
* @param originalCommand for (String a : linkGroup) {
* origin<EFBFBD>ln<EFBFBD> p<EFBFBD><EFBFBD>kaz pou<EFBFBD>it<EFBFBD> hr<EFBFBD><EFBFBD>em setTime(player, a);
* @param time }
* cooldown doba v sekund<EFBFBD>ch, nastaven<EFBFBD> pro regexCommand v }
* konfiguraci return false;
* @return false pokud hr<EFBFBD><EFBFBD> disponuje opr<EFBFBD>vn<EFBFBD>n<EFBFBD>mi, jinak hodnotu vr<EFBFBD>cenou } else {
* metodou cd();. Calendar calcurrTime = Calendar.getInstance();
*/ calcurrTime.setTime(getCurrTime());
static boolean coolDown(Player player, String regexCommand, Calendar callastTime = Calendar.getInstance();
String originalCommand, int time) { callastTime.setTime(lastTime);
regexCommand = regexCommand.toLowerCase(); long secondsBetween = secondsBetween(callastTime, calcurrTime);
if (time > 0 long waitSeconds = coolDownSeconds - secondsBetween;
&& !player.hasPermission("booscooldowns.nocooldown") long waitMinutes = (long) Math.ceil(waitSeconds / 60.0);
&& !player.hasPermission("booscooldowns.nocooldown." long waitHours = (long) Math.ceil(waitMinutes / 60.0);
+ originalCommand)) { if (secondsBetween > coolDownSeconds) {
return cd(player, regexCommand, originalCommand, time); if (linkGroup.isEmpty()) {
} setTime(player, regexCommand);
return false; } else {
} setTime(player, regexCommand);
for (String a : linkGroup) {
setTime(player, a);
}
}
return false;
} else {
String msg = BoosConfigManager.getCoolDownMessage();
msg = msg.replaceAll("&command&", originalCommand);
if (waitSeconds >= 60 && 3600 >= waitSeconds) {
msg = msg.replaceAll("&seconds&",
Long.toString(waitMinutes));
msg = msg.replaceAll("&unit&",
BoosConfigManager.getUnitMinutesMessage());
} else if (waitMinutes >= 60) {
msg = msg.replaceAll("&seconds&", Long.toString(waitHours));
msg = msg.replaceAll("&unit&",
BoosConfigManager.getUnitHoursMessage());
} else {
String secs = Long.toString(waitSeconds);
if (secs.equals("0")) {
secs = "1";
}
msg = msg.replaceAll("&seconds&", secs);
msg = msg.replaceAll("&unit&",
BoosConfigManager.getUnitSecondsMessage());
}
boosChat.sendMessageToPlayer(player, msg);
return true;
}
}
}
/** static boolean coolDown(Player player, String regexCommand,
* Metoda vrac<EFBFBD> sou<EFBFBD>asn<EFBFBD> p<EFBFBD>esn<EFBFBD> datum a <EFBFBD>as. String originalCommand, int time) {
* regexCommand = regexCommand.toLowerCase();
* @return sou<EFBFBD>asn<EFBFBD> <EFBFBD>as a datum return time > 0 && !player.hasPermission("booscooldowns.nocooldown") && !player.hasPermission("booscooldowns.nocooldown." + originalCommand) && cd(player, regexCommand, originalCommand, time);
*/ }
static Date getCurrTime() {
String currTime = "";
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
currTime = sdf.format(cal.getTime());
Date time = null;
try { private static Date getCurrTime() {
time = sdf.parse(currTime); String currTime = "";
return time; Calendar cal = Calendar.getInstance();
} catch (ParseException e) { SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
return null; currTime = sdf.format(cal.getTime());
} Date time = null;
}
/** try {
* Metoda vrac<EFBFBD> datum a <EFBFBD>as, kdy hr<EFBFBD><EFBFBD> naposledy pou<EFBFBD>il dan<EFBFBD> p<EFBFBD><EFBFBD>kaz. time = sdf.parse(currTime);
* return time;
* @param player } catch (ParseException e) {
* specifikovan<EFBFBD> hr<EFBFBD><EFBFBD> return null;
* @param regexCommand }
* p<EFBFBD><EFBFBD>kaz z konfigurace vyhovuj<EFBFBD>c<EFBFBD> origin<EFBFBD>ln<EFBFBD>mu p<EFBFBD><EFBFBD>kazu }
* @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) {
int pre2 = regexCommand.toLowerCase().hashCode();
String confTime = "";
confTime = BoosConfigManager.getConfusers().getString(
"users." + player.getUniqueId() + ".cooldown." + pre2, null);
if (confTime != null && !confTime.equals("")) { private static Date getTime(Player player, String regexCommand) {
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss"); int pre2 = regexCommand.toLowerCase().hashCode();
Date lastDate = null; String confTime = "";
confTime = BoosConfigManager.getConfusers().getString(
"users." + player.getUniqueId() + ".cooldown." + pre2, null);
try { if (confTime != null && !confTime.equals("")) {
lastDate = sdf.parse(confTime); SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
return lastDate; Date lastDate = null;
} catch (ParseException e) {
return null;
}
}
return null;
}
/** try {
* Metoda vrac<EFBFBD> hodnotu boolean na z<EFBFBD>klad<EFBFBD> toho, jestli m<EFBFBD> specifikovan<EFBFBD> lastDate = sdf.parse(confTime);
* p<EFBFBD><EFBFBD>kaz aktivn<EFBFBD> cooldown <EFBFBD>asova<EFBFBD>. return lastDate;
* } catch (ParseException e) {
* @param player return null;
* specifikovan<EFBFBD> hr<EFBFBD><EFBFBD> }
* @param regexCommand }
* p<EFBFBD><EFBFBD>kaz z konfigurace vyhovuj<EFBFBD>c<EFBFBD> origin<EFBFBD>ln<EFBFBD>mu p<EFBFBD><EFBFBD>kazu return null;
* @param originalCommand }
* origin<EFBFBD>ln<EFBFBD> p<EFBFBD><EFBFBD>kaz pou<EFBFBD>it<EFBFBD> hr<EFBFBD><EFBFBD>em
* @param time
* cooldown doba v sekund<EFBFBD>ch, nastaven<EFBFBD> pro regexCommand v
* konfiguraci
* @return false pokud m<EFBFBD> p<EFBFBD><EFBFBD>kaz aktivn<EFBFBD> cooldown <EFBFBD>asova<EFBFBD>, jinak false
*/
static boolean checkCoolDownOK(Player player, String regexCommand,
String originalCommand, int time) {
regexCommand = regexCommand.toLowerCase();
if (time > 0) {
Date lastTime = getTime(player, regexCommand);
if (lastTime == null) {
return true;
} else {
Calendar calcurrTime = Calendar.getInstance();
calcurrTime.setTime(getCurrTime());
Calendar callastTime = Calendar.getInstance();
callastTime.setTime(lastTime);
long secondsBetween = secondsBetween(callastTime, calcurrTime);
long waitSeconds = time - secondsBetween;
long waitMinutes = (long) Math.ceil(waitSeconds / 60.0);
long waitHours = (long) Math.ceil(waitMinutes / 60.0);
if (secondsBetween > time) {
return true;
} else {
String msg = BoosConfigManager.getCoolDownMessage();
msg = msg.replaceAll("&command&", originalCommand);
if (waitSeconds >= 60 && 3600 >= waitSeconds) {
msg = msg.replaceAll("&seconds&",
Long.toString(waitMinutes));
msg = msg.replaceAll("&unit&",
BoosConfigManager.getUnitMinutesMessage());
} else if (waitMinutes >= 60) {
msg = msg.replaceAll("&seconds&",
Long.toString(waitHours));
msg = msg.replaceAll("&unit&",
BoosConfigManager.getUnitHoursMessage());
} else {
msg = msg.replaceAll("&seconds&",
Long.toString(waitSeconds));
msg = msg.replaceAll("&unit&",
BoosConfigManager.getUnitSecondsMessage());
}
boosChat.sendMessageToPlayer(player, msg);
return false;
}
}
}
return true;
}
/** static boolean checkCoolDownOK(Player player, String regexCommand,
* Metoda vrac<EFBFBD> hodnotu rozd<EFBFBD>lu v sekund<EFBFBD>ch mezi dv<EFBFBD>mi hodnotami datumu a String originalCommand, int time) {
* <EFBFBD>asu. regexCommand = regexCommand.toLowerCase();
* if (time > 0) {
* @param startDate Date lastTime = getTime(player, regexCommand);
* @param endDate if (lastTime == null) {
* @return rozd<EFBFBD>l v sekund<EFBFBD>ch mezi startDate a endDate return true;
*/ } else {
static long secondsBetween(Calendar startDate, Calendar endDate) { Calendar calcurrTime = Calendar.getInstance();
long secondsBetween = 0; calcurrTime.setTime(getCurrTime());
secondsBetween = (endDate.getTimeInMillis() - startDate Calendar callastTime = Calendar.getInstance();
.getTimeInMillis()) / 1000; callastTime.setTime(lastTime);
return secondsBetween; long secondsBetween = secondsBetween(callastTime, calcurrTime);
} long waitSeconds = time - secondsBetween;
long waitMinutes = (long) Math.ceil(waitSeconds / 60.0);
long waitHours = (long) Math.ceil(waitMinutes / 60.0);
if (secondsBetween > time) {
return true;
} else {
String msg = BoosConfigManager.getCoolDownMessage();
msg = msg.replaceAll("&command&", originalCommand);
if (waitSeconds >= 60 && 3600 >= waitSeconds) {
msg = msg.replaceAll("&seconds&",
Long.toString(waitMinutes));
msg = msg.replaceAll("&unit&",
BoosConfigManager.getUnitMinutesMessage());
} else if (waitMinutes >= 60) {
msg = msg.replaceAll("&seconds&",
Long.toString(waitHours));
msg = msg.replaceAll("&unit&",
BoosConfigManager.getUnitHoursMessage());
} else {
msg = msg.replaceAll("&seconds&",
Long.toString(waitSeconds));
msg = msg.replaceAll("&unit&",
BoosConfigManager.getUnitSecondsMessage());
}
boosChat.sendMessageToPlayer(player, msg);
return false;
}
}
}
return true;
}
/** private static long secondsBetween(Calendar startDate, Calendar endDate) {
* Metoda ukl<EFBFBD>d<EFBFBD> do datab<EFBFBD>ze datum a <EFBFBD>as kdy hr<EFBFBD><EFBFBD> naposledy pou<EFBFBD>il dan<EFBFBD> long secondsBetween = 0;
* p<EFBFBD><EFBFBD>kaz. secondsBetween = (endDate.getTimeInMillis() - startDate
* .getTimeInMillis()) / 1000;
* @param player return secondsBetween;
* specifick<EFBFBD> hr<EFBFBD><EFBFBD> }
* @param regexCommand
* 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) {
int pre2 = regexCommand.toLowerCase().hashCode();
String currTime = "";
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
currTime = sdf.format(cal.getTime());
BoosConfigManager.getConfusers()
.set("users." + player.getUniqueId() + ".cooldown." + pre2,
currTime);
}
/** private static void setTime(Player player, String regexCommand) {
* Metoda spou<EFBFBD>t<EFBFBD> ve<EFBFBD>ker<EFBFBD> cooldown <EFBFBD>asova<EFBFBD>e pro specifick<EFBFBD>ho hr<EFBFBD><EFBFBD>e. int pre2 = regexCommand.toLowerCase().hashCode();
* String currTime = "";
* @param player Calendar cal = Calendar.getInstance();
* specifick<EFBFBD> hr<EFBFBD><EFBFBD> SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
* @param message currTime = sdf.format(cal.getTime());
*/ BoosConfigManager.getConfusers()
public static void startAllCooldowns(Player player, String message) { .set("users." + player.getUniqueId() + ".cooldown." + pre2,
for (String a : BoosConfigManager.getCooldowns(player)) { currTime);
int cooldownTime = BoosConfigManager.getCoolDown(a, player); }
coolDown(player, a, message, cooldownTime);
}
} public static void startAllCooldowns(Player player, String message) {
for (String a : BoosConfigManager.getCooldowns(player)) {
int cooldownTime = BoosConfigManager.getCoolDown(a, player);
coolDown(player, a, message, cooldownTime);
}
}
} }

View File

@ -2,25 +2,25 @@ package cz.boosik.boosCooldown;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
public class BoosGlobalLimitResetRunnable implements Runnable { class BoosGlobalLimitResetRunnable implements Runnable {
private String command; private final String command;
public BoosGlobalLimitResetRunnable(String key) { public BoosGlobalLimitResetRunnable(String key) {
this.command = key; this.command = key;
} }
@Override @Override
public void run() { public void run() {
BoosCoolDown.getLog().info( BoosCoolDown.getLog().info(
"[boosCooldowns] Reseting limits for command " + command); "[boosCooldowns] Reseting limits for command " + command);
BoosLimitManager.clearAllLimits(command.hashCode()); BoosLimitManager.clearAllLimits(command.hashCode());
BoosLimitManager.setGlobalLimitResetDate(command); BoosLimitManager.setGlobalLimitResetDate(command);
String msg = BoosConfigManager.getLimitResetNowMessage(); String msg = BoosConfigManager.getLimitResetNowMessage();
msg = msg.replaceAll("&command&", command); msg = msg.replaceAll("&command&", command);
msg = msg.replaceAll("&", "§"); msg = msg.replaceAll("&", "§");
Bukkit.broadcastMessage(msg); Bukkit.broadcastMessage(msg);
BoosCoolDown.startLimitResetTimerGlobal(command); BoosCoolDown.startLimitResetTimerGlobal(command);
} }
} }

View File

@ -5,113 +5,62 @@ import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import util.boosChat; import util.boosChat;
/** class BoosItemCostManager {
* 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<EFBFBD><EFBFBD>
*
*/
public class BoosItemCostManager {
private static String msg = "";
/** private static boolean payItemForCommand(Player player,
* Metoda zaji<EFBFBD><EFBFBD>uje funkci platby za p<EFBFBD><EFBFBD>kaz. Vrac<EFBFBD> hodnotu v z<EFBFBD>vislosti na String originalCommand, String item, int count) {
* <EFBFBD>sp<EFBFBD>nosti platby. Material material = Material.getMaterial(item);
* Inventory inventory = player.getInventory();
* @param player Boolean trans = false;
* specifikovan<EFBFBD> hr<EFBFBD><EFBFBD> if (inventory.contains(material, count)) {
* @param regexCommand ItemStack itemstack = new ItemStack(material, count);
* p<EFBFBD><EFBFBD>kaz z konfigurace vyhovuj<EFBFBD>c<EFBFBD> origin<EFBFBD>ln<EFBFBD>mu p<EFBFBD><EFBFBD>kazu inventory.removeItem(itemstack);
* @param originalCommand trans = true;
* origin<EFBFBD>ln<EFBFBD> p<EFBFBD><EFBFBD>kaz pou<EFBFBD>it<EFBFBD> hr<EFBFBD><EFBFBD>em }
* @param item if (trans) {
* @param price String msg = String.format(
* cena pou<EFBFBD>it<EFBFBD> p<EFBFBD><EFBFBD>kazu BoosConfigManager.getPaidItemsForCommandMessage(), count
* @param name + " " + item);
* jm<EFBFBD>no specifick<EFBFBD>ho hr<EFBFBD><EFBFBD>e msg = msg.replaceAll("&command&", originalCommand);
* @return true pokud byl <EFBFBD>sp<EFBFBD>n<EFBFBD> zaplacen poplatek, nebo pokud nebyl nalezen boosChat.sendMessageToPlayer(player, msg);
* ekonomick<EFBFBD> plugin; false pokud do<EFBFBD>lo k chyb<EFBFBD> nebo hr<EFBFBD><EFBFBD> nem<EFBFBD>l return true;
* dostatek financ<EFBFBD> } else {
*/ // msg = String.format(
static boolean payItemForCommand(Player player, String regexCommand, // BoosConfigManager.getInsufficientItemsMessage(), (count
String originalCommand, String item, int count, String name) { // + " " + item));
Material material = Material.getMaterial(item); // msg = msg.replaceAll("&command&", originalCommand);
Inventory inventory = player.getInventory(); // boosChat.sendMessageToPlayer(player, msg);
Boolean trans = false; return false;
if (inventory.contains(material, count)) { }
ItemStack itemstack = new ItemStack(material, count); }
inventory.removeItem(itemstack);
trans = true;
}
if (trans) {
msg = String.format(
BoosConfigManager.getPaidItemsForCommandMessage(), count
+ " " + item);
msg = msg.replaceAll("&command&", originalCommand);
boosChat.sendMessageToPlayer(player, msg);
return true;
} else {
// msg = String.format(
// BoosConfigManager.getInsufficientItemsMessage(), (count
// + " " + item));
// msg = msg.replaceAll("&command&", originalCommand);
// boosChat.sendMessageToPlayer(player, msg);
return false;
}
}
/** static void payItemForCommand(PlayerCommandPreprocessEvent event,
* Metoda ukon<EFBFBD>uje/neukon<EFBFBD>uje ud<EFBFBD>lost pou<EFBFBD>it<EFBFBD> p<EFBFBD><EFBFBD>kazu v z<EFBFBD>vislosti na tom, Player player, String regexCommand, String originalCommand,
* jakou hodnotu vr<EFBFBD>tila metoda payForCommand(Player player, String String item, int count) {
* regexCommand, String originalCommand, double price, String name);. if (count > 0) {
* if (!player.hasPermission("booscooldowns.noitemcost")
* @param event && !player.hasPermission("booscooldowns.noitemcost."
* ud<EFBFBD>lost PlayerCommandPreprocessEvent + originalCommand)) {
* @param player if (!payItemForCommand(player, originalCommand,
* specifick<EFBFBD> hr<EFBFBD><EFBFBD> item, count)) {
* @param regexCommand BoosCoolDownManager.cancelCooldown(player, regexCommand);
* p<EFBFBD><EFBFBD>kaz z konfigurace vyhovuj<EFBFBD>c<EFBFBD> origin<EFBFBD>ln<EFBFBD>mu p<EFBFBD><EFBFBD>kazu event.setCancelled(true);
* @param originalCommand }
* origin<EFBFBD>ln<EFBFBD> p<EFBFBD><EFBFBD>kaz pou<EFBFBD>it<EFBFBD> hr<EFBFBD><EFBFBD>em }
* @param item }
* @param price }
* cena pou<EFBFBD>it<EFBFBD> p<EFBFBD><EFBFBD>kazu
*/
static void payItemForCommand(PlayerCommandPreprocessEvent event,
Player player, String regexCommand, String originalCommand,
String item, int count) {
String name = player.getName();
if (count > 0) {
if (!player.hasPermission("booscooldowns.noitemcost")
&& !player.hasPermission("booscooldowns.noitemcost."
+ originalCommand)) {
if (payItemForCommand(player, regexCommand, originalCommand,
item, count, name)) {
return;
} else {
BoosCoolDownManager.cancelCooldown(player, regexCommand);
event.setCancelled(true);
return;
}
}
}
}
public static boolean has(Player player, String item, int count) { public static boolean has(Player player, String item, int count) {
if (item.equals("")) { if (item.equals("")) {
return true; return true;
} }
if (count <= 0) { if (count <= 0) {
return true; return true;
} }
Material material = Material.getMaterial(item); Material material = Material.getMaterial(item);
Inventory inventory = player.getInventory(); Inventory inventory = player.getInventory();
if (inventory.contains(material, count)) { return inventory.contains(material, count);
return true; }
}
return false;
}
} }

View File

@ -1,362 +1,270 @@
package cz.boosik.boosCooldown; package cz.boosik.boosCooldown;
import org.bukkit.entity.Player;
import util.boosChat;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.Set; import java.util.Set;
import org.bukkit.entity.Player;
import util.boosChat; class BoosLimitManager {
/** static boolean blocked(Player player, String regexCommand,
* T<EFBFBD><EFBFBD>da obsahuje ve<EFBFBD>ker<EFBFBD> metody pot<EFBFBD>ebn<EFBFBD> k <EFBFBD><EFBFBD>zen<EFBFBD> limit<EFBFBD>. String originalCommand, int limit) {
* Date time = getTime(player, regexCommand);
* @author Jakub Kol<EFBFBD><EFBFBD> Date confTime = getTime(regexCommand);
* Calendar calcurrTime = Calendar.getInstance();
*/ calcurrTime.setTime(getCurrTime());
public class BoosLimitManager { Calendar callastTime = Calendar.getInstance();
/** Calendar callastTimeGlobal = Calendar.getInstance();
* 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> int uses = getUses(player, regexCommand);
* zablokovan<EFBFBD>. long limitResetDelay = BoosConfigManager.getLimitResetDelay(
* regexCommand, player);
* @param player long limitResetDelayGlobal = BoosConfigManager
* specifick<EFBFBD> hr<EFBFBD><EFBFBD> .getLimitResetDelayGlobal(regexCommand);
* @param regexCommand if (time != null) {
* p<EFBFBD><EFBFBD>kaz z konfigura<EFBFBD>n<EFBFBD>ho souboru, kter<EFBFBD> vyhovuje origin<EFBFBD>ln<EFBFBD>mu callastTime.setTime(time);
* p<EFBFBD><EFBFBD>kazu } else {
* @param originalCommand setTime(player, regexCommand);
* origin<EFBFBD>ln<EFBFBD> p<EFBFBD><EFBFBD>kaz pou<EFBFBD>it<EFBFBD> hr<EFBFBD><EFBFBD>em }
* @param limit if (limit - uses == 1) {
* limit nastaven<EFBFBD> pro regexCommand setTime(player, regexCommand);
* @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> time = getTime(player, regexCommand);
* pou<EFBFBD><EFBFBD>t callastTime.setTime(time);
*/ }
static boolean blocked(Player player, String regexCommand, if (limitResetDelay > 0) {
String originalCommand, int limit) { if (secondsBetween(callastTime, calcurrTime, limitResetDelay) <= 0) {
Date time = getTime(player, regexCommand); if (uses != 0) {
Date confTime = getTime(regexCommand); BoosConfigManager.clearSomething("uses",
Calendar calcurrTime = Calendar.getInstance(); player.getUniqueId(), regexCommand);
calcurrTime.setTime(getCurrTime()); uses = getUses(player, regexCommand);
Calendar callastTime = Calendar.getInstance(); }
Calendar callastTimeGlobal = Calendar.getInstance(); }
int uses = getUses(player, regexCommand); }
long limitResetDelay = BoosConfigManager.getLimitResetDelay(
regexCommand, player);
long limitResetDelayGlobal = BoosConfigManager
.getLimitResetDelayGlobal(regexCommand);
if (time != null) {
callastTime.setTime(time);
} else {
setTime(player, regexCommand);
}
if (limit - uses == 1) {
setTime(player, regexCommand);
time = getTime(player, regexCommand);
callastTime.setTime(time);
}
if (limitResetDelay > 0) {
if (secondsBetween(callastTime, calcurrTime, limitResetDelay) <= 0) {
if (uses != 0) {
BoosConfigManager.clearSomething("uses",
player.getUniqueId(), regexCommand);
uses = getUses(player, regexCommand);
}
}
}
if (player.hasPermission("booscooldowns.nolimit") if (!player.hasPermission("booscooldowns.nolimit")
|| player.hasPermission("booscooldowns.nolimit." || player.hasPermission("booscooldowns.nolimit."
+ originalCommand)) { + originalCommand)) {
} else { if (limit == -1) {
if (limit == -1) { return false;
return false; } else if (limit <= uses) {
} else if (limit <= uses) { if (limitResetDelay > 0) {
if (limitResetDelay > 0) { long waitSeconds = secondsBetween(callastTime,
long secondsBetween = secondsBetween(callastTime, calcurrTime, limitResetDelay);
calcurrTime, limitResetDelay); long waitMinutes = Math.round(waitSeconds / 60) + 1;
long waitSeconds = secondsBetween; long waitHours = Math.round(waitMinutes / 60) + 1;
long waitMinutes = Math.round(waitSeconds / 60) + 1; String msg = BoosConfigManager.getLimitResetMessage();
long waitHours = Math.round(waitMinutes / 60) + 1; msg = msg.replaceAll("&command&", originalCommand);
String msg = BoosConfigManager.getLimitResetMessage(); if (waitSeconds >= 60 && 3600 >= waitSeconds) {
msg = msg.replaceAll("&command&", originalCommand); msg = msg.replaceAll("&seconds&",
if (waitSeconds >= 60 && 3600 >= waitSeconds) { Long.toString(waitMinutes));
msg = msg.replaceAll("&seconds&", msg = msg.replaceAll("&unit&",
Long.toString(waitMinutes)); BoosConfigManager.getUnitMinutesMessage());
msg = msg.replaceAll("&unit&", } else if (waitMinutes >= 60) {
BoosConfigManager.getUnitMinutesMessage()); msg = msg.replaceAll("&seconds&",
} else if (waitMinutes >= 60) { Long.toString(waitHours));
msg = msg.replaceAll("&seconds&", msg = msg.replaceAll("&unit&",
Long.toString(waitHours)); BoosConfigManager.getUnitHoursMessage());
msg = msg.replaceAll("&unit&", } else {
BoosConfigManager.getUnitHoursMessage()); msg = msg.replaceAll("&seconds&",
} else { Long.toString(waitSeconds));
msg = msg.replaceAll("&seconds&", msg = msg.replaceAll("&unit&",
Long.toString(waitSeconds)); BoosConfigManager.getUnitSecondsMessage());
msg = msg.replaceAll("&unit&", }
BoosConfigManager.getUnitSecondsMessage()); boosChat.sendMessageToPlayer(player, msg);
} } else if (limitResetDelayGlobal > 0) {
boosChat.sendMessageToPlayer(player, msg); if (confTime != null) {
} else if (limitResetDelayGlobal > 0) { callastTimeGlobal.setTime(confTime);
if (confTime != null) { long waitSeconds = secondsBetween(callastTimeGlobal,
callastTimeGlobal.setTime(confTime); calcurrTime, limitResetDelayGlobal);
long secondsBetween = secondsBetween(callastTimeGlobal, long waitMinutes = (long) Math.ceil(waitSeconds / 60.0);
calcurrTime, limitResetDelayGlobal); long waitHours = (long) Math.ceil(waitMinutes / 60.0);
long waitSeconds = secondsBetween; String msg = BoosConfigManager.getLimitResetMessage();
long waitMinutes = (long) Math.ceil(waitSeconds / 60.0); msg = msg.replaceAll("&command&", originalCommand);
long waitHours = (long) Math.ceil(waitMinutes / 60.0); if (waitSeconds >= 60 && 3600 >= waitSeconds) {
String msg = BoosConfigManager.getLimitResetMessage(); msg = msg.replaceAll("&seconds&",
msg = msg.replaceAll("&command&", originalCommand); Long.toString(waitMinutes));
if (waitSeconds >= 60 && 3600 >= waitSeconds) { msg = msg.replaceAll("&unit&",
msg = msg.replaceAll("&seconds&", BoosConfigManager.getUnitMinutesMessage());
Long.toString(waitMinutes)); } else if (waitMinutes >= 60) {
msg = msg.replaceAll("&unit&", msg = msg.replaceAll("&seconds&",
BoosConfigManager.getUnitMinutesMessage()); Long.toString(waitHours));
} else if (waitMinutes >= 60) { msg = msg.replaceAll("&unit&",
msg = msg.replaceAll("&seconds&", BoosConfigManager.getUnitHoursMessage());
Long.toString(waitHours)); } else {
msg = msg.replaceAll("&unit&", msg = msg.replaceAll("&seconds&",
BoosConfigManager.getUnitHoursMessage()); Long.toString(waitSeconds));
} else { msg = msg.replaceAll("&unit&",
msg = msg.replaceAll("&seconds&", BoosConfigManager.getUnitSecondsMessage());
Long.toString(waitSeconds)); }
msg = msg.replaceAll("&unit&", boosChat.sendMessageToPlayer(player, msg);
BoosConfigManager.getUnitSecondsMessage()); }
} } else {
boosChat.sendMessageToPlayer(player, msg); String msg = String.format(BoosConfigManager
} .getCommandBlockedMessage());
} else { boosChat.sendMessageToPlayer(player, msg);
String msg = String.format(BoosConfigManager }
.getCommandBlockedMessage()); return true;
boosChat.sendMessageToPlayer(player, msg); }
} }
return true; return false;
} }
}
return false;
}
/** private static int getUses(Player player, String regexCommand) {
* Metoda vrac<EFBFBD> hodnotu, kter<EFBFBD> je ur<EFBFBD>ena t<EFBFBD>m, kolikr<EFBFBD>t ji<EFBFBD> hr<EFBFBD><EFBFBD> pou<EFBFBD>il int regexCommand2 = regexCommand.toLowerCase().hashCode();
* specifikovan<EFBFBD> p<EFBFBD><EFBFBD>kaz. int uses = 0;
* uses = BoosConfigManager.getConfusers().getInt(
* @param player "users." + player.getUniqueId() + ".uses." + regexCommand2,
* specifick<EFBFBD> hr<EFBFBD><EFBFBD> uses);
* @param regexCommand return uses;
* p<EFBFBD><EFBFBD>kaz z konfigura<EFBFBD>n<EFBFBD>ho souboru, kter<EFBFBD> vyhovuje origin<EFBFBD>ln<EFBFBD>mu }
* p<EFBFBD><EFBFBD>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) {
int regexCommand2 = regexCommand.toLowerCase().hashCode();
int uses = 0;
uses = BoosConfigManager.getConfusers().getInt(
"users." + player.getUniqueId() + ".uses." + regexCommand2,
uses);
return uses;
}
/** static void setUses(Player player, String regexCommand) {
* 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> if (BoosConfigManager.getLimitsEnabled()) {
* p<EFBFBD><EFBFBD>kazu hr<EFBFBD><EFBFBD>em. Nasteven<EFBFBD> hodnoty prob<EFBFBD>h<EFBFBD> jen pro p<EFBFBD><EFBFBD>kazy, kter<EFBFBD> jsou if (BoosConfigManager.getCommands(player).contains(regexCommand)) {
* definov<EFBFBD>ny v konfiguraci. int regexCommand2 = regexCommand.toLowerCase().hashCode();
* int uses = getUses(player, regexCommand);
* @param player uses = uses + 1;
* specifick<EFBFBD> hr<EFBFBD><EFBFBD> try {
* @param regexCommand BoosConfigManager.getConfusers().set(
* p<EFBFBD><EFBFBD>kaz z konfigura<EFBFBD>n<EFBFBD>ho souboru, kter<EFBFBD> vyhovuje origin<EFBFBD>ln<EFBFBD>mu "users." + player.getUniqueId() + ".uses."
* p<EFBFBD><EFBFBD>kazu + regexCommand2, uses);
* @param originalCommand } catch (IllegalArgumentException e) {
* origin<EFBFBD>ln<EFBFBD> p<EFBFBD><EFBFBD>kaz pou<EFBFBD>it<EFBFBD> hr<EFBFBD><EFBFBD>em BoosCoolDown
*/ .getLog()
static void setUses(Player player, String regexCommand) { .warning(
if (BoosConfigManager.getLimitsEnabled()) { "Player "
if (BoosConfigManager.getCommands(player).contains(regexCommand)) { + player.getName()
int regexCommand2 = regexCommand.toLowerCase().hashCode(); + " used empty command and caused this error!");
int uses = getUses(player, regexCommand); }
uses = uses + 1; }
try { }
BoosConfigManager.getConfusers().set( }
"users." + player.getUniqueId() + ".uses."
+ regexCommand2, uses);
} catch (IllegalArgumentException e) {
BoosCoolDown
.getLog()
.warning(
"Player "
+ player.getName()
+ " used empty command and caused this error!");
}
} else {
return;
}
}
}
/** static void getLimitListMessages(Player send, String comm, int lim) {
* Metoda odes<EFBFBD>l<EFBFBD> hr<EFBFBD><EFBFBD>i zpr<EFBFBD>vu o limitovan<EFBFBD>m p<EFBFBD><EFBFBD>kazu, hodnotu tohoto limitu if (lim != -1) {
* a kolikr<EFBFBD>t je je<EFBFBD>t<EFBFBD> mo<EFBFBD>n<EFBFBD> limitovan<EFBFBD> p<EFBFBD><EFBFBD>kaz pou<EFBFBD><EFBFBD>t. int uses = getUses(send, comm);
* String message = BoosConfigManager.getLimitListMessage();
* @param send int num = lim - uses;
* hr<EFBFBD><EFBFBD> kter<EFBFBD>mu bude odesl<EFBFBD>n seznam if (num < 0) {
* @param comm num = 0;
* p<EFBFBD><EFBFBD>kaz o kter<EFBFBD>m si hr<EFBFBD><EFBFBD> vy<EFBFBD><EFBFBD>dal informace }
* @param lim message = BoosConfigManager.getLimitListMessage();
* hodnota limitu na p<EFBFBD><EFBFBD>kazu message = message.replaceAll("&command&", comm);
*/ message = message.replaceAll("&limit&", String.valueOf(lim));
static void getLimitListMessages(Player send, String comm, int lim) { message = message.replaceAll("&times&", String.valueOf(num));
if (lim != -1) { boosChat.sendMessageToPlayer(send, message);
int uses = getUses(send, comm); }
String message = BoosConfigManager.getLimitListMessage(); }
int num = lim - uses;
if (num < 0) {
num = 0;
}
message = BoosConfigManager.getLimitListMessage();
message = message.replaceAll("&command&", comm);
message = message.replaceAll("&limit&", String.valueOf(lim));
message = message.replaceAll("&times&", String.valueOf(num));
boosChat.sendMessageToPlayer(send, message);
}
}
/** private static Date getCurrTime() {
* Metoda vrac<EFBFBD> sou<EFBFBD>asn<EFBFBD> p<EFBFBD>esn<EFBFBD> datum a <EFBFBD>as. String currTime = "";
* Calendar cal = Calendar.getInstance();
* @return sou<EFBFBD>asn<EFBFBD> <EFBFBD>as a datum SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
*/ currTime = sdf.format(cal.getTime());
static Date getCurrTime() { Date time = null;
String currTime = "";
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
currTime = sdf.format(cal.getTime());
Date time = null;
try { try {
time = sdf.parse(currTime); time = sdf.parse(currTime);
return time; return time;
} catch (ParseException e) { } catch (ParseException e) {
return null; return null;
} }
} }
/** private static Date getTime(Player player, String regexCommand) {
* Metoda vrac<EFBFBD> datum a <EFBFBD>as, kdy hr<EFBFBD><EFBFBD> naposledy pou<EFBFBD>il dan<EFBFBD> p<EFBFBD><EFBFBD>kaz. int pre2 = regexCommand.toLowerCase().hashCode();
* String confTime = "";
* @param player confTime = BoosConfigManager.getConfusers().getString(
* specifikovan<EFBFBD> hr<EFBFBD><EFBFBD> "users." + player.getUniqueId() + ".lastused." + pre2, null);
* @param regexCommand
* p<EFBFBD><EFBFBD>kaz z konfigurace vyhovuj<EFBFBD>c<EFBFBD> origin<EFBFBD>ln<EFBFBD>mu p<EFBFBD><EFBFBD>kazu
* @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) {
int pre2 = regexCommand.toLowerCase().hashCode();
String confTime = "";
confTime = BoosConfigManager.getConfusers().getString(
"users." + player.getUniqueId() + ".lastused." + pre2, null);
if (confTime != null && !confTime.equals("")) { if (confTime != null && !confTime.equals("")) {
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss"); SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
Date lastDate = null; Date lastDate = null;
try { try {
lastDate = sdf.parse(confTime); lastDate = sdf.parse(confTime);
return lastDate; return lastDate;
} catch (ParseException e) { } catch (ParseException e) {
return null; return null;
} }
} }
return null; return null;
} }
static Date getTime(String regexCommand) { private static Date getTime(String regexCommand) {
String confTime = ""; String confTime = "";
confTime = BoosConfigManager.getConfusers().getString( confTime = BoosConfigManager.getConfusers().getString(
"global." + regexCommand + ".reset", null); "global." + regexCommand + ".reset", null);
if (confTime != null && !confTime.equals("")) { if (confTime != null && !confTime.equals("")) {
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss"); SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
Date lastDate = null; Date lastDate = null;
try { try {
lastDate = sdf.parse(confTime); lastDate = sdf.parse(confTime);
return lastDate; return lastDate;
} catch (ParseException e) { } catch (ParseException e) {
return null; return null;
} }
} }
return null; return null;
} }
/** private static void setTime(Player player, String regexCommand) {
* Metoda ukl<EFBFBD>d<EFBFBD> do datab<EFBFBD>ze datum a <EFBFBD>as kdy hr<EFBFBD><EFBFBD> naposledy pou<EFBFBD>il dan<EFBFBD> int pre2 = regexCommand.toLowerCase().hashCode();
* p<EFBFBD><EFBFBD>kaz. String currTime = "";
* Calendar cal = Calendar.getInstance();
* @param player SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
* specifick<EFBFBD> hr<EFBFBD><EFBFBD> currTime = sdf.format(cal.getTime());
* @param regexCommand BoosConfigManager.getConfusers()
* p<EFBFBD><EFBFBD>kaz z konfigurace vyhovuj<EFBFBD>c<EFBFBD> origin<EFBFBD>ln<EFBFBD>mu p<EFBFBD><EFBFBD>kazu .set("users." + player.getUniqueId() + ".lastused." + pre2,
*/ currTime);
static void setTime(Player player, String regexCommand) { }
int pre2 = regexCommand.toLowerCase().hashCode();
String currTime = "";
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
currTime = sdf.format(cal.getTime());
BoosConfigManager.getConfusers()
.set("users." + player.getUniqueId() + ".lastused." + pre2,
currTime);
}
/** private static long secondsBetween(Calendar startDate, Calendar endDate,
* Metoda vrac<EFBFBD> hodnotu rozd<EFBFBD>lu v sekund<EFBFBD>ch mezi dv<EFBFBD>mi hodnotami datumu a long limitResetDelay) {
* <EFBFBD>asu. long secondsBetween = 0;
* secondsBetween = ((startDate.getTimeInMillis() - endDate
* @param startDate .getTimeInMillis()) / 1000) + limitResetDelay;
* @param endDate return secondsBetween;
* @return rozd<EFBFBD>l v sekund<EFBFBD>ch mezi startDate a endDate }
*/
static long secondsBetween(Calendar startDate, Calendar endDate,
long limitResetDelay) {
long secondsBetween = 0;
secondsBetween = ((startDate.getTimeInMillis() - endDate
.getTimeInMillis()) / 1000) + limitResetDelay;
return secondsBetween;
}
static void clearAllLimits(int hashedCommand) { static void clearAllLimits(int hashedCommand) {
Set<String> players = BoosConfigManager.getAllPlayers(); Set<String> players = BoosConfigManager.getAllPlayers();
for (String player : players) { for (String player : players) {
BoosConfigManager.clearSomething2("uses", player, hashedCommand); BoosConfigManager.clearSomething2("uses", player, hashedCommand);
} }
BoosConfigManager.saveConfusers(); BoosConfigManager.saveConfusers();
BoosConfigManager.loadConfusers(); BoosConfigManager.loadConfusers();
} }
static void setGlobalLimitResetDate() { static void setGlobalLimitResetDate() {
for (String command : BoosConfigManager.getLimitResetCommandsGlobal()) { for (String command : BoosConfigManager.getLimitResetCommandsGlobal()) {
if (BoosConfigManager.getLimitResetDelayGlobal(command) == -65535) { if (BoosConfigManager.getLimitResetDelayGlobal(command) == -65535) {
BoosConfigManager.getConfusers().set("global." + command, null); BoosConfigManager.getConfusers().set("global." + command, null);
} else { } else {
setTime(command); setTime(command);
} }
} }
BoosConfigManager.saveConfusers(); BoosConfigManager.saveConfusers();
BoosConfigManager.loadConfusers(); BoosConfigManager.loadConfusers();
} }
static void setGlobalLimitResetDate(String command) { static void setGlobalLimitResetDate(String command) {
setTime(command); setTime(command);
BoosConfigManager.saveConfusers(); BoosConfigManager.saveConfusers();
BoosConfigManager.loadConfusers(); BoosConfigManager.loadConfusers();
} }
static void setTime(String command) { private static void setTime(String command) {
String currTime = ""; String currTime = "";
Calendar cal = Calendar.getInstance(); Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss"); SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
currTime = sdf.format(cal.getTime()); currTime = sdf.format(cal.getTime());
BoosConfigManager.getConfusers().set("global." + command + ".reset", BoosConfigManager.getConfusers().set("global." + command + ".reset",
currTime); currTime);
} }
} }

View File

@ -2,117 +2,50 @@ package cz.boosik.boosCooldown;
import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.economy.EconomyResponse; import net.milkbowl.vault.economy.EconomyResponse;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import util.boosChat; import util.boosChat;
/** class BoosPriceManager {
* 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 private static final Economy economy = BoosCoolDown.getEconomy();
* p<EFBFBD><EFBFBD>kazy.
*
* @author Jakub Kol<EFBFBD><EFBFBD>
*
*/
public class BoosPriceManager {
private static Economy economy = BoosCoolDown.getEconomy();
private static String msg = "";
/** private static boolean payForCommand(Player player,
* Metoda zaji<EFBFBD><EFBFBD>uje funkci platby za p<EFBFBD><EFBFBD>kaz. Vrac<EFBFBD> hodnotu v z<EFBFBD>vislosti na String originalCommand, double price) {
* <EFBFBD>sp<EFBFBD>nosti platby. if (economy == null) {
* return true;
* @param player }
* specifikovan<EFBFBD> hr<EFBFBD><EFBFBD> EconomyResponse r = economy.withdrawPlayer(player, price);
* @param regexCommand String msg = "";
* p<EFBFBD><EFBFBD>kaz z konfigurace vyhovuj<EFBFBD>c<EFBFBD> origin<EFBFBD>ln<EFBFBD>mu p<EFBFBD><EFBFBD>kazu if (r.transactionSuccess()) {
* @param originalCommand msg = String.format(BoosConfigManager.getPaidForCommandMessage(),
* origin<EFBFBD>ln<EFBFBD> p<EFBFBD><EFBFBD>kaz pou<EFBFBD>it<EFBFBD> hr<EFBFBD><EFBFBD>em economy.format(r.amount), economy.format(r.balance));
* @param price msg = msg.replaceAll("&command&", originalCommand);
* cena pou<EFBFBD>it<EFBFBD> p<EFBFBD><EFBFBD>kazu boosChat.sendMessageToPlayer(player, msg);
* @param name return true;
* jm<EFBFBD>no specifick<EFBFBD>ho hr<EFBFBD><EFBFBD>e } else {
* @return true pokud byl <EFBFBD>sp<EFBFBD>n<EFBFBD> zaplacen poplatek, nebo pokud nebyl nalezen msg = String.format(BoosConfigManager.getPaidErrorMessage(),
* ekonomick<EFBFBD> plugin; false pokud do<EFBFBD>lo k chyb<EFBFBD> nebo hr<EFBFBD><EFBFBD> nem<EFBFBD>l r.errorMessage);
* dostatek financ<EFBFBD> boosChat.sendMessageToPlayer(player, msg);
*/ return false;
static boolean payForCommand(Player player, String regexCommand, }
String originalCommand, double price, String name) { }
if (economy == null) {
return true;
}
EconomyResponse r = economy.withdrawPlayer(player, price);
if (r.transactionSuccess()) {
msg = String.format(BoosConfigManager.getPaidForCommandMessage(),
economy.format(r.amount), economy.format(r.balance));
msg = msg.replaceAll("&command&", originalCommand);
boosChat.sendMessageToPlayer(player, msg);
return true;
} else {
if (r.errorMessage.equals("Insufficient funds")) {
// String unit;
// if (price == 1) {
// unit = economy.currencyNameSingular();
// } else {
// unit = economy.currencyNamePlural();
// }
// msg = String.format(
// BoosConfigManager.getInsufficientFundsMessage(), (price
// + " " + unit), economy.format(r.balance));
// msg = msg.replaceAll("&command&", originalCommand);
} else {
msg = String.format(BoosConfigManager.getPaidErrorMessage(),
r.errorMessage);
}
boosChat.sendMessageToPlayer(player, msg);
return false;
}
}
/** static void payForCommand(PlayerCommandPreprocessEvent event,
* Metoda ukon<EFBFBD>uje/neukon<EFBFBD>uje ud<EFBFBD>lost pou<EFBFBD>it<EFBFBD> p<EFBFBD><EFBFBD>kazu v z<EFBFBD>vislosti na tom, Player player, String regexCommand, String originalCommand,
* jakou hodnotu vr<EFBFBD>tila metoda payForCommand(Player player, String double price) {
* regexCommand, String originalCommand, double price, String name);. if (price > 0) {
* if (!player.hasPermission("booscooldowns.noprice")
* @param event && !player.hasPermission("booscooldowns.noprice."
* ud<EFBFBD>lost PlayerCommandPreprocessEvent + originalCommand)) {
* @param player if (!payForCommand(player, originalCommand, price)) {
* specifick<EFBFBD> hr<EFBFBD><EFBFBD> BoosCoolDownManager.cancelCooldown(player, regexCommand);
* @param regexCommand event.setCancelled(true);
* p<EFBFBD><EFBFBD>kaz z konfigurace vyhovuj<EFBFBD>c<EFBFBD> origin<EFBFBD>ln<EFBFBD>mu p<EFBFBD><EFBFBD>kazu }
* @param originalCommand }
* origin<EFBFBD>ln<EFBFBD> p<EFBFBD><EFBFBD>kaz pou<EFBFBD>it<EFBFBD> hr<EFBFBD><EFBFBD>em }
* @param price }
* cena pou<EFBFBD>it<EFBFBD> p<EFBFBD><EFBFBD>kazu
*/
static void payForCommand(PlayerCommandPreprocessEvent event,
Player player, String regexCommand, String originalCommand,
double price) {
String name = player.getName();
if (price > 0) {
if (!player.hasPermission("booscooldowns.noprice")
&& !player.hasPermission("booscooldowns.noprice."
+ originalCommand)) {
if (payForCommand(player, regexCommand, originalCommand, price,
name)) {
return;
} else {
BoosCoolDownManager.cancelCooldown(player, regexCommand);
event.setCancelled(true);
return;
}
}
}
}
public static boolean has(Player player, double price) { public static boolean has(Player player, double price) {
if (economy == null) { return economy == null || price <= 0 || economy.has(player, price);
return true; }
} else if (price <= 0){
return true;
} else {
return economy.has(player, price);
}
}
} }

View File

@ -1,287 +1,151 @@
package cz.boosik.boosCooldown; package cz.boosik.boosCooldown;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffectType;
import util.boosChat;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.Timer; import java.util.Timer;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffectType;
import util.boosChat;
/**
* 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<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<EFBFBD><EFBFBD>
*
*/
public class BoosWarmUpManager { public class BoosWarmUpManager {
private static ConcurrentHashMap<String, BoosWarmUpTimer> playercommands = new ConcurrentHashMap<String, BoosWarmUpTimer>(); private static final ConcurrentHashMap<String, BoosWarmUpTimer> playercommands = new ConcurrentHashMap<>();
private static ConcurrentHashMap<Player, Location> playerloc = new ConcurrentHashMap<Player, Location>(); private static final ConcurrentHashMap<Player, Location> playerloc = new ConcurrentHashMap<>();
private static ConcurrentHashMap<Player, String> playerworld = new ConcurrentHashMap<Player, String>(); private static final ConcurrentHashMap<Player, String> playerworld = new ConcurrentHashMap<>();
private static Timer scheduler; private static void applyPotionEffect(Player player, String regexCommand,
int warmUpSeconds) {
String potion = BoosConfigManager.getPotionEffect(regexCommand, player);
if (potion.equals("")) {
return;
}
int potionStrength = BoosConfigManager.getPotionEffectStrength(
regexCommand, player);
if (potionStrength == 0) {
return;
}
PotionEffectType effect = PotionEffectType.getByName(potion);
player.addPotionEffect(
effect.createEffect(warmUpSeconds * 40, potionStrength - 1),
true);
}
/** public static void cancelWarmUps(Player player) {
* Metoda aplikuje na hr<EFBFBD><EFBFBD>e magick<EFBFBD> efekt na dobu ur<EFBFBD>enou parametrem Map<String, BoosWarmUpTimer> playercommands2 = playercommands;
* warmUpSeconds. Iterator<String> iter = playercommands2.keySet().iterator();
* while (iter.hasNext()) {
* @param player if (iter.next().startsWith(player.getUniqueId() + "@")) {
* specifick<EFBFBD> hr<EFBFBD><EFBFBD> killTimer(player);
* @param regexCommand iter.remove();
* p<EFBFBD><EFBFBD>kaz z konfigura<EFBFBD>n<EFBFBD>ho souboru, kter<EFBFBD> vyhovuje origin<EFBFBD>ln<EFBFBD>mu }
* p<EFBFBD><EFBFBD>kazu }
* @param warmUpSeconds }
* doba warmup v sekund<EFBFBD>ch, nastaven<EFBFBD> pro regexCommand v
* konfiguraci
*/
static void applyPotionEffect(Player player, String regexCommand,
int warmUpSeconds) {
String potion = BoosConfigManager.getPotionEffect(regexCommand, player);
if (potion.equals("")) {
return;
}
int potionStrength = BoosConfigManager.getPotionEffectStrength(
regexCommand, player);
if (potionStrength == 0) {
return;
}
PotionEffectType effect = PotionEffectType.getByName(potion);
player.addPotionEffect(
effect.createEffect(warmUpSeconds * 40, potionStrength - 1),
true);
}
/** public static void clearLocWorld(Player player) {
* Metoda stornuje ve<EFBFBD>ker<EFBFBD> prob<EFBFBD>haj<EFBFBD>c<EFBFBD> warmup <EFBFBD>asova<EFBFBD>e specifick<EFBFBD>ho hr<EFBFBD><EFBFBD>e. BoosWarmUpManager.playerloc.remove(player);
* BoosWarmUpManager.playerworld.remove(player);
* @param player }
* specifick<EFBFBD> hr<EFBFBD><EFBFBD>
*/
public static void cancelWarmUps(Player player) {
Map<String, BoosWarmUpTimer> playercommands2 = playercommands;
Iterator<String> iter = playercommands2.keySet().iterator();
while (iter.hasNext()) {
if (iter.next().startsWith(player.getUniqueId() + "@")) {
killTimer(player);
iter.remove();
}
}
}
/** public static boolean hasWarmUps(Player player) {
* Metoda pro specifick<EFBFBD>ho hr<EFBFBD><EFBFBD>e vyma<EFBFBD>e ulo<EFBFBD>enou pozici a sv<EFBFBD>t. Map<String, BoosWarmUpTimer> playercommands2 = playercommands;
* for (String key : playercommands2.keySet()) {
* @param player if (key.startsWith(player.getUniqueId() + "@")) {
* specifick<EFBFBD> hr<EFBFBD><EFBFBD> return true;
*/ }
public static void clearLocWorld(Player player) { }
BoosWarmUpManager.playerloc.remove(player); return false;
BoosWarmUpManager.playerworld.remove(player); }
}
/** static boolean checkWarmUpOK(Player player, String regexCommand) {
* Metoda vrac<EFBFBD> boolean hodnotu v z<EFBFBD>vislosti na tom jestli specifikovan<EFBFBD> int pre2 = regexCommand.toLowerCase().hashCode();
* hr<EFBFBD><EFBFBD> m<EFBFBD> aktivn<EFBFBD> warmup <EFBFBD>asova<EFBFBD>e nebo ne. int ok = 0;
* ok = BoosConfigManager.getConfusers().getInt(
* @param player "users." + player.getUniqueId() + ".warmup." + pre2, ok);
* specifick<EFBFBD> hr<EFBFBD><EFBFBD> return ok == 1;
* @return true pokud hr<EFBFBD><EFBFBD> m<EFBFBD> aktivn<EFBFBD> warmup <EFBFBD>asova<EFBFBD>e, jinak false }
*/
public static boolean hasWarmUps(Player player) {
Map<String, BoosWarmUpTimer> playercommands2 = playercommands;
for (String key : playercommands2.keySet()) {
if (key.startsWith(player.getUniqueId() + "@")) {
return true;
}
}
return false;
}
/** static boolean isWarmUpProcess(Player player, String regexCommand) {
* Metoda zji<EFBFBD><EFBFBD>uje, jestli je dan<EFBFBD> warmup <EFBFBD>asova<EFBFBD> ozna<EFBFBD>en<EFBFBD> jako ji<EFBFBD> prob<EFBFBD>hl<EFBFBD> regexCommand = regexCommand.toLowerCase();
* nebo ne. return playercommands.containsKey(player.getUniqueId() + "@"
* + regexCommand);
* @param player }
* specifick<EFBFBD> hr<EFBFBD><EFBFBD>
* @param regexCommand
* p<EFBFBD><EFBFBD>kaz z konfigura<EFBFBD>n<EFBFBD>ho souboru, kter<EFBFBD> vyhovuje origin<EFBFBD>ln<EFBFBD>mu
* p<EFBFBD><EFBFBD>kazu
* @return true pokud je warmup <EFBFBD>asova<EFBFBD> ozna<EFBFBD>en jako ji<EFBFBD> prob<EFBFBD>hl<EFBFBD>, 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);
if (ok == 1) {
return true;
}
return false;
}
/** private static void killTimer(Player player) {
* Metoda vrac<EFBFBD> boolean hodnotu na z<EFBFBD>klad<EFBFBD> toho jestli je pro specifikovan<EFBFBD> Map<String, BoosWarmUpTimer> playercommands2 = playercommands;
* p<EFBFBD><EFBFBD>kaz specifikovan<EFBFBD>ho hr<EFBFBD><EFBFBD>e aktivn<EFBFBD> warmup <EFBFBD>asova<EFBFBD>. for (String key : playercommands2.keySet()) {
* if (key.startsWith(player.getUniqueId() + "@")) {
* @param player playercommands.get(key).cancel();
* specifick<EFBFBD> hr<EFBFBD><EFBFBD> }
* @param regexCommand }
* p<EFBFBD><EFBFBD>kaz z konfigura<EFBFBD>n<EFBFBD>ho souboru, kter<EFBFBD> vyhovuje origin<EFBFBD>ln<EFBFBD>mu }
* p<EFBFBD><EFBFBD>kazu
* @return true pokud je warmup <EFBFBD>asova<EFBFBD> aktivn<EFBFBD>, jinak false
*/
static boolean isWarmUpProcess(Player player, String regexCommand) {
regexCommand = regexCommand.toLowerCase();
if (playercommands.containsKey(player.getUniqueId() + "@"
+ regexCommand)) {
return true;
}
return false;
}
/** static void removeWarmUp(Player player, String regexCommand) {
* Metoda odstran<EFBFBD> v<EFBFBD>echny <EFBFBD>asova<EFBFBD>e specifikovan<EFBFBD>ho hr<EFBFBD><EFBFBD>e int pre2 = regexCommand.toLowerCase().hashCode();
* BoosConfigManager.getConfusers().set(
* @param player "users." + player.getUniqueId() + ".warmup." + pre2, null);
* specifick<EFBFBD> hr<EFBFBD><EFBFBD> }
*/
static void killTimer(Player player) {
Map<String, BoosWarmUpTimer> playercommands2 = playercommands;
for (String key : playercommands2.keySet()) {
if (key.startsWith(player.getUniqueId() + "@")) {
playercommands.get(key).cancel();
}
}
}
/** static void removeWarmUpOK(Player player, String regexCommand) {
* Metoda odstran<EFBFBD> <EFBFBD>asova<EFBFBD>e na specifikovan<EFBFBD>m p<EFBFBD><EFBFBD>kazu specifikovan<EFBFBD>ho hr<EFBFBD><EFBFBD>e int pre2 = regexCommand.toLowerCase().hashCode();
* BoosConfigManager.getConfusers().set(
* @param player "users." + player.getUniqueId() + ".warmup." + pre2, null);
* specifick<EFBFBD> hr<EFBFBD><EFBFBD> }
* @param regexCommand
* p<EFBFBD><EFBFBD>kaz z konfigura<EFBFBD>n<EFBFBD>ho souboru, kter<EFBFBD> vyhovuje origin<EFBFBD>ln<EFBFBD>mu
* p<EFBFBD><EFBFBD>kazu
*/
static void removeWarmUp(Player player, String regexCommand) {
int pre2 = regexCommand.toLowerCase().hashCode();
BoosConfigManager.getConfusers().set(
"users." + player.getUniqueId() + ".warmup." + pre2, null);
}
/** static void removeWarmUpProcess(String tag) {
* Metoda odstran<EFBFBD> ukon<EFBFBD>en<EFBFBD> <EFBFBD>asova<EFBFBD>e na specifikovan<EFBFBD>m p<EFBFBD><EFBFBD>kazu BoosWarmUpManager.playercommands.remove(tag);
* specifikovan<EFBFBD>ho hr<EFBFBD><EFBFBD>e }
*
* @param player
* specifick<EFBFBD> hr<EFBFBD><EFBFBD>
* @param regexCommand
* p<EFBFBD><EFBFBD>kaz z konfigura<EFBFBD>n<EFBFBD>ho souboru, kter<EFBFBD> vyhovuje origin<EFBFBD>ln<EFBFBD>mu
* p<EFBFBD><EFBFBD>kazu
*/
static void removeWarmUpOK(Player player, String regexCommand) {
int pre2 = regexCommand.toLowerCase().hashCode();
BoosConfigManager.getConfusers().set(
"users." + player.getUniqueId() + ".warmup." + pre2, null);
}
/** static void setWarmUpOK(Player player, String regexCommand) {
* Metoda odstra<EFBFBD>uje dan<EFBFBD> <EFBFBD>et<EFBFBD>zec z Hashmapy int pre2 = regexCommand.toLowerCase().hashCode();
* BoosConfigManager.getConfusers().set(
* @param tag "users." + player.getUniqueId() + ".warmup." + pre2, 1);
* <EFBFBD>et<EFBFBD>zec, kter<EFBFBD> se m<EFBFBD> odstranit z Hasmapy }
*/
static void removeWarmUpProcess(String tag) {
BoosWarmUpManager.playercommands.remove(tag);
}
/** static void startWarmUp(BoosCoolDown bCoolDown, Player player,
* Metoda ozna<EFBFBD>uje warmup <EFBFBD>asova<EFBFBD> specifikovan<EFBFBD>ho p<EFBFBD><EFBFBD>kazu specifikovan<EFBFBD>ho String regexCommand, String originalCommand, int warmUpSeconds) {
* hr<EFBFBD><EFBFBD>e jako ji<EFBFBD> ukon<EFBFBD>en<EFBFBD>. regexCommand = regexCommand.toLowerCase();
* long warmUpMinutes = (long) Math.ceil(warmUpSeconds / 60.0);
* @param player long warmUpHours = (long) Math.ceil(warmUpMinutes / 60.0);
* specifick<EFBFBD> hr<EFBFBD><EFBFBD> if (!isWarmUpProcess(player, regexCommand)) {
* @param regexCommand BoosWarmUpManager.removeWarmUpOK(player, regexCommand);
* p<EFBFBD><EFBFBD>kaz z konfigura<EFBFBD>n<EFBFBD>ho souboru, kter<EFBFBD> vyhovuje origin<EFBFBD>ln<EFBFBD>mu String msg = BoosConfigManager.getWarmUpMessage();
* p<EFBFBD><EFBFBD>kazu msg = msg.replaceAll("&command&", originalCommand);
*/ if (warmUpSeconds >= 60 && 3600 >= warmUpSeconds) {
static void setWarmUpOK(Player player, String regexCommand) { msg = msg.replaceAll("&seconds&", Long.toString(warmUpMinutes));
int pre2 = regexCommand.toLowerCase().hashCode(); msg = msg.replaceAll("&unit&",
BoosConfigManager.getConfusers().set( BoosConfigManager.getUnitMinutesMessage());
"users." + player.getUniqueId() + ".warmup." + pre2, 1); } else if (warmUpMinutes >= 60) {
} msg = msg.replaceAll("&seconds&", Long.toString(warmUpHours));
msg = msg.replaceAll("&unit&",
BoosConfigManager.getUnitHoursMessage());
} else {
msg = msg.replaceAll("&seconds&", Long.toString(warmUpSeconds));
msg = msg.replaceAll("&unit&",
BoosConfigManager.getUnitSecondsMessage());
}
boosChat.sendMessageToPlayer(player, msg);
/** Timer scheduler = new Timer();
* Metoda spou<EFBFBD>t<EFBFBD> warmup <EFBFBD>asova<EFBFBD> na z<EFBFBD>klad<EFBFBD> parametr<EFBFBD> pomoc<EFBFBD> Timer(). Pokud BoosWarmUpTimer scheduleMe = new BoosWarmUpTimer(bCoolDown, player, regexCommand, originalCommand);
* je ji<EFBFBD> warmup aktivn<EFBFBD>, ode<EFBFBD>le hr<EFBFBD><EFBFBD>i zpr<EFBFBD>vu kter<EFBFBD> ho o tom informuje. playercommands.put(player.getUniqueId() + "@" + regexCommand,
* scheduleMe);
* @param bCoolDown scheduler.schedule(scheduleMe, warmUpSeconds * 1000);
* instance t<EFBFBD><EFBFBD>dy BoosCooldown applyPotionEffect(player, regexCommand, warmUpSeconds);
* @param player } else {
* specifick<EFBFBD> hr<EFBFBD><EFBFBD> String msg = BoosConfigManager.getWarmUpAlreadyStartedMessage();
* @param regexCommand msg = msg.replaceAll("&command&", originalCommand);
* p<EFBFBD><EFBFBD>kaz z konfigura<EFBFBD>n<EFBFBD>ho souboru, kter<EFBFBD> vyhovuje origin<EFBFBD>ln<EFBFBD>mu boosChat.sendMessageToPlayer(player, msg);
* p<EFBFBD><EFBFBD>kazu }
* @param originalCommand }
* origin<EFBFBD>ln<EFBFBD> p<EFBFBD><EFBFBD>kaz pou<EFBFBD>it<EFBFBD> hr<EFBFBD><EFBFBD>em
* @param warmUpSeconds
* warmup doba nastaven<EFBFBD> pro p<EFBFBD><EFBFBD>kaz v sekund<EFBFBD>ch
*/
static void startWarmUp(BoosCoolDown bCoolDown, Player player,
String regexCommand, String originalCommand, int warmUpSeconds) {
regexCommand = regexCommand.toLowerCase();
long warmUpMinutes = (long) Math.ceil(warmUpSeconds / 60.0);
long warmUpHours = (long) Math.ceil(warmUpMinutes / 60.0);
if (!isWarmUpProcess(player, regexCommand)) {
BoosWarmUpManager.removeWarmUpOK(player, regexCommand);
String msg = BoosConfigManager.getWarmUpMessage();
msg = msg.replaceAll("&command&", originalCommand);
if (warmUpSeconds >= 60 && 3600 >= warmUpSeconds) {
msg = msg.replaceAll("&seconds&", Long.toString(warmUpMinutes));
msg = msg.replaceAll("&unit&",
BoosConfigManager.getUnitMinutesMessage());
} else if (warmUpMinutes >= 60) {
msg = msg.replaceAll("&seconds&", Long.toString(warmUpHours));
msg = msg.replaceAll("&unit&",
BoosConfigManager.getUnitHoursMessage());
} else {
msg = msg.replaceAll("&seconds&", Long.toString(warmUpSeconds));
msg = msg.replaceAll("&unit&",
BoosConfigManager.getUnitSecondsMessage());
}
boosChat.sendMessageToPlayer(player, msg);
scheduler = new Timer(); public static ConcurrentHashMap<Player, String> getPlayerworld() {
BoosWarmUpTimer scheduleMe = new BoosWarmUpTimer(bCoolDown, return playerworld;
scheduler, player, regexCommand, originalCommand); }
playercommands.put(player.getUniqueId() + "@" + regexCommand,
scheduleMe);
scheduler.schedule(scheduleMe, warmUpSeconds * 1000);
applyPotionEffect(player, regexCommand, warmUpSeconds);
} else {
String msg = BoosConfigManager.getWarmUpAlreadyStartedMessage();
msg = msg.replaceAll("&command&", originalCommand);
boosChat.sendMessageToPlayer(player, msg);
}
}
/** public static ConcurrentHashMap<Player, Location> getPlayerloc() {
* @return return playerloc;
*/ }
public static ConcurrentHashMap<Player, String> getPlayerworld() {
return playerworld;
}
/**
* @return
*/
public static ConcurrentHashMap<Player, Location> getPlayerloc() {
return playerloc;
}
} }

View File

@ -1,82 +1,54 @@
package cz.boosik.boosCooldown; package cz.boosik.boosCooldown;
import java.util.Timer;
import java.util.TimerTask;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
/** import java.util.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<EFBFBD><EFBFBD>
*
*/
public class BoosWarmUpTimer extends TimerTask {
private BoosCoolDown bCoolDown; class BoosWarmUpTimer extends TimerTask {
private Player player;
private String originalCommand;
private String regexCommand;
/** private final BoosCoolDown bCoolDown;
* @param bCoolDown private final Player player;
* instance t<EFBFBD><EFBFBD>dy BoosCoolDown private final String originalCommand;
* @param timer private final String regexCommand;
* @param player
* specifick<EFBFBD> hr<EFBFBD><EFBFBD>
* @param regexCommand
* p<EFBFBD><EFBFBD>kaz z konfigura<EFBFBD>n<EFBFBD>ho souboru, kter<EFBFBD> vyhovuje origin<EFBFBD>ln<EFBFBD>mu
* p<EFBFBD><EFBFBD>kazu
* @param originalCommand
* origin<EFBFBD>ln<EFBFBD> p<EFBFBD><EFBFBD>kaz kter<EFBFBD> hr<EFBFBD><EFBFBD> pou<EFBFBD>il
*/
public BoosWarmUpTimer(BoosCoolDown bCoolDown, Timer timer, Player player,
String regexCommand, String originalCommand) {
this.bCoolDown = bCoolDown;
this.player = player;
this.regexCommand = regexCommand;
this.originalCommand = originalCommand;
}
/* public BoosWarmUpTimer(BoosCoolDown bCoolDown, Player player,
* (non-Javadoc) String regexCommand, String originalCommand) {
* this.bCoolDown = bCoolDown;
* @see java.util.TimerTask#run() this.player = player;
*/ this.regexCommand = regexCommand;
@Override this.originalCommand = originalCommand;
public void run() { }
bCoolDown.getServer().getScheduler()
.scheduleSyncDelayedTask(bCoolDown, new boosWarmUpRunnable());
}
public class boosWarmUpRunnable implements Runnable { @Override
/* public void run() {
* (non-Javadoc) bCoolDown.getServer().getScheduler()
* .scheduleSyncDelayedTask(bCoolDown, new boosWarmUpRunnable());
* @see java.lang.Runnable#run() }
*/
@Override private class boosWarmUpRunnable implements Runnable {
public void run() {
if (player.isOnline() && !player.isDead() @Override
&& BoosWarmUpManager.hasWarmUps(player)) { public void run() {
BoosWarmUpManager.setWarmUpOK(player, regexCommand); if (player.isOnline() && !player.isDead()
BoosWarmUpManager.removeWarmUpProcess(player.getUniqueId() && BoosWarmUpManager.hasWarmUps(player)) {
+ "@" + regexCommand); BoosWarmUpManager.setWarmUpOK(player, regexCommand);
BoosWarmUpManager.clearLocWorld(player); BoosWarmUpManager.removeWarmUpProcess(player.getUniqueId()
player.chat(originalCommand); + "@" + regexCommand);
} else if (player.isOnline() && player.isDead() BoosWarmUpManager.clearLocWorld(player);
&& BoosWarmUpManager.hasWarmUps(player)) { player.chat(originalCommand);
BoosWarmUpManager.removeWarmUp(player, regexCommand); } else if (player.isOnline() && player.isDead()
BoosWarmUpManager.removeWarmUpProcess(player.getUniqueId() && BoosWarmUpManager.hasWarmUps(player)) {
+ "@" + regexCommand); BoosWarmUpManager.removeWarmUp(player, regexCommand);
BoosWarmUpManager.clearLocWorld(player); BoosWarmUpManager.removeWarmUpProcess(player.getUniqueId()
} else if (!player.isOnline() + "@" + regexCommand);
&& BoosWarmUpManager.hasWarmUps(player)) { BoosWarmUpManager.clearLocWorld(player);
BoosWarmUpManager.removeWarmUp(player, regexCommand); } else if (!player.isOnline()
BoosWarmUpManager.removeWarmUpProcess(player.getUniqueId() && BoosWarmUpManager.hasWarmUps(player)) {
+ "@" + regexCommand); BoosWarmUpManager.removeWarmUp(player, regexCommand);
BoosWarmUpManager.clearLocWorld(player); BoosWarmUpManager.removeWarmUpProcess(player.getUniqueId()
} + "@" + regexCommand);
} BoosWarmUpManager.clearLocWorld(player);
} }
}
}
} }

View File

@ -2,58 +2,50 @@ package cz.boosik.boosCooldown;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import util.boosChat; import util.boosChat;
public class BoosXpCostManager { class BoosXpCostManager {
private static String msg = "";
static boolean payXPForCommand(Player player, String regexCommand, private static boolean payXPForCommand(Player player,
String originalCommand, int xpPrice) { String originalCommand, int xpPrice) {
int xp = player.getLevel(); int xp = player.getLevel();
Boolean trans = false; Boolean trans = false;
if (xp >= xpPrice) { if (xp >= xpPrice) {
player.setLevel(xp - xpPrice); player.setLevel(xp - xpPrice);
trans = true; trans = true;
} }
if (trans) { if (trans) {
msg = String.format(BoosConfigManager.getPaidXPForCommandMessage(), String msg = String.format(BoosConfigManager.getPaidXPForCommandMessage(),
xpPrice); xpPrice);
msg = msg.replaceAll("&command&", originalCommand); msg = msg.replaceAll("&command&", originalCommand);
boosChat.sendMessageToPlayer(player, msg); boosChat.sendMessageToPlayer(player, msg);
return true; return true;
} else { } else {
return false; return false;
} }
} }
static void payXPForCommand(PlayerCommandPreprocessEvent event, static void payXPForCommand(PlayerCommandPreprocessEvent event,
Player player, String regexCommand, String originalCommand, Player player, String regexCommand, String originalCommand,
int xpPrice) { int xpPrice) {
if (xpPrice > 0) { if (xpPrice > 0) {
if (!player.hasPermission("booscooldowns.noxpcost") if (!player.hasPermission("booscooldowns.noxpcost")
&& !player.hasPermission("booscooldowns.noxpcost." && !player.hasPermission("booscooldowns.noxpcost."
+ originalCommand)) { + originalCommand)) {
if (payXPForCommand(player, regexCommand, originalCommand, if (!payXPForCommand(player, originalCommand,
xpPrice)) { xpPrice)) {
return; BoosCoolDownManager.cancelCooldown(player, regexCommand);
} else { event.setCancelled(true);
BoosCoolDownManager.cancelCooldown(player, regexCommand); }
event.setCancelled(true); }
return; }
} }
}
}
}
public static boolean has(Player player, int xpPrice) { public static boolean has(Player player, int xpPrice) {
if (xpPrice <= 0){ if (xpPrice <= 0) {
return true; return true;
} }
int xp = player.getLevel(); int xp = player.getLevel();
if (xp >= xpPrice) { return xp >= xpPrice;
return true; }
}
return false;
}
} }

View File

@ -1,53 +1,30 @@
package cz.boosik.boosCooldown.Listeners; package cz.boosik.boosCooldown.Listeners;
import cz.boosik.boosCooldown.BoosConfigManager;
import cz.boosik.boosCooldown.BoosWarmUpManager;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent;
import util.boosChat; import util.boosChat;
import cz.boosik.boosCooldown.BoosConfigManager;
import cz.boosik.boosCooldown.BoosWarmUpManager;
/**
* Posluchač naslouchající události, která se spouští v okamžiku kdy dojde ke
* zranění jakékoli entity ve světě. Pokud je touto entitou hráč a na jeho
* příkazech je aktivní časovač warmup, ve chvíli spuštění této události jsou
* všechny jeho warmup časovače stornovány a hráči je odeslána zpráva, která ho
* o této skutečnosti informuje. Pokud hráč disponuje oprávněním
* booscooldowns.nocancel.damage, jeho warmup časovače stornovány nejsou.
*
* @author Jakub Kolář
*
*/
public class BoosEntityDamageListener implements Listener { public class BoosEntityDamageListener implements Listener {
/**
* Metoda zjišťuje jestli je entita která spustila tuto událost hráč. Pokud
* je entita hráč, hráč není null a nedisponuje oprávněním
* booscooldowns.nocancel.damage a pokud tento hráč disponuje aktivními
* warmup časovači, pak je hráči odeslána zpráva, která ho informuje o
* ukončení všech warmup časovačů a následně tyto časovače ukončuje pomocí
* metody cancelWarmUps();.
*
* @param event
* událost EntityDamageEvent
*/
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
private void onEntityDamage(EntityDamageEvent event) {
Entity entity = event.getEntity();
if (entity != null && entity instanceof Player) {
Player player = (Player) entity;
if (player != null
&& !player.hasPermission("booscooldowns.nocancel.damage")) {
if (BoosWarmUpManager.hasWarmUps(player)) {
boosChat.sendMessageToPlayer(player, BoosConfigManager
.getWarmUpCancelledByDamageMessage());
BoosWarmUpManager.cancelWarmUps(player);
}
} @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
} private void onEntityDamage(EntityDamageEvent event) {
} Entity entity = event.getEntity();
if (entity != null && entity instanceof Player) {
Player player = (Player) entity;
if (!player.hasPermission("booscooldowns.nocancel.damage")) {
if (BoosWarmUpManager.hasWarmUps(player)) {
boosChat.sendMessageToPlayer(player, BoosConfigManager
.getWarmUpCancelledByDamageMessage());
BoosWarmUpManager.cancelWarmUps(player);
}
}
}
}
} }

View File

@ -1,5 +1,7 @@
package cz.boosik.boosCooldown.Listeners; package cz.boosik.boosCooldown.Listeners;
import cz.boosik.boosCooldown.BoosConfigManager;
import cz.boosik.boosCooldown.BoosCoolDownManager;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -7,88 +9,43 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.entity.PlayerDeathEvent;
import cz.boosik.boosCooldown.BoosConfigManager;
import cz.boosik.boosCooldown.BoosCoolDownManager;
/**
* 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<EFBFBD>vislosti na konfiguraci pluginu a opr<EFBFBD>vn<EFBFBD>n<EFBFBD>ch hr<EFBFBD><EFBFBD>e mohou nastat t<EFBFBD>i
* r<EFBFBD>zn<EFBFBD> aktivity. Cooldown <EFBFBD>asova<EFBFBD>e mohou b<EFBFBD>t po smrti vymaz<EFBFBD>ny, nebo naopak
* 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<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<EFBFBD><EFBFBD>vat limitovan<EFBFBD> p<EFBFBD><EFBFBD>kazy a<EFBFBD> po hodnotu limitu.
*
* @author Jakub Kol<EFBFBD><EFBFBD>
*
*/
public class BoosPlayerDeathListener implements Listener { public class BoosPlayerDeathListener implements Listener {
/**
* Metoda zji<EFBFBD><EFBFBD>uje jestli je entita kter<EFBFBD> spustila tuto ud<EFBFBD>lost hr<EFBFBD><EFBFBD> a
* jestli nen<EFBFBD> null. Na z<EFBFBD>klad<EFBFBD> toho spou<EFBFBD>t<EFBFBD> dal<EFBFBD><EFBFBD> metody.
*
* @param event
* ud<EFBFBD>lost PlayerDeathEvent
*/
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
private void onPlayerDeath(PlayerDeathEvent event) {
Entity entity = event.getEntity();
if (entity != null && entity instanceof Player) {
Player player = (Player) entity;
clearCooldownsOnDeath(player);
clearUsesOnDeath(player);
startCooldownsOnDeath(player);
}
}
/** @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
* Na z<EFBFBD>klad<EFBFBD> konfigurace metoda spou<EFBFBD>t<EFBFBD> v<EFBFBD>echny cooldown <EFBFBD>asova<EFBFBD>e private void onPlayerDeath(PlayerDeathEvent event) {
* specifikovan<EFBFBD>ho hr<EFBFBD><EFBFBD>e t<EFBFBD>m <EFBFBD>e spust<EFBFBD> medotu startAllCooldowns();. Entity entity = event.getEntity();
* if (entity != null) {
* @param player Player player = (Player) entity;
* hr<EFBFBD><EFBFBD>, kter<EFBFBD> spustil ud<EFBFBD>lost PlayerDeathEvent clearCooldownsOnDeath(player);
*/ clearUsesOnDeath(player);
private void startCooldownsOnDeath(Player player) { startCooldownsOnDeath(player);
if (player != null) { }
if (BoosConfigManager.getStartCooldownsOnDeath()) { }
BoosCoolDownManager.startAllCooldowns(player, "");
}
}
}
/** private void startCooldownsOnDeath(Player player) {
* Na z<EFBFBD>klad<EFBFBD> konfigurace a toho jestli hr<EFBFBD><EFBFBD> disponuje opr<EFBFBD>vn<EFBFBD>n<EFBFBD>m if (player != null) {
* booscooldowns.clear.uses.death metoda vyma<EFBFBD>e v<EFBFBD>echny z<EFBFBD>znamy o spu<EFBFBD>t<EFBFBD>n<EFBFBD> if (BoosConfigManager.getStartCooldownsOnDeath()) {
* v<EFBFBD>ech p<EFBFBD><EFBFBD>kaz<EFBFBD> specifikovan<EFBFBD>ho hr<EFBFBD><EFBFBD>e t<EFBFBD>m <EFBFBD>e spust<EFBFBD> metodu BoosCoolDownManager.startAllCooldowns(player, "");
* clearSomething();. }
* }
* @param player }
* hr<EFBFBD><EFBFBD>, kter<EFBFBD> spustil ud<EFBFBD>lost PlayerDeathEvent
*/
private void clearUsesOnDeath(Player player) {
if (player != null
&& player.hasPermission("booscooldowns.clear.uses.death")) {
if (BoosConfigManager.getCleanUsesOnDeath()) {
BoosConfigManager.clearSomething("uses", player.getUniqueId());
}
}
}
/** private void clearUsesOnDeath(Player player) {
* Na z<EFBFBD>klad<EFBFBD> konfigurace a toho jestli hr<EFBFBD><EFBFBD> disponuje opr<EFBFBD>vn<EFBFBD>n<EFBFBD>m if (player != null
* booscooldowns.clear.cooldowns.death metoda vyma<EFBFBD>e v<EFBFBD>echny cooldown && player.hasPermission("booscooldowns.clear.uses.death")) {
* <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 if (BoosConfigManager.getCleanUsesOnDeath()) {
* clearSomething();. BoosConfigManager.clearSomething("uses", player.getUniqueId());
* }
* @param player }
* 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", BoosConfigManager.clearSomething("cooldown",
player.getUniqueId()); player.getUniqueId());
} }
} }
} }
} }

View File

@ -1,54 +1,31 @@
package cz.boosik.boosCooldown.Listeners; package cz.boosik.boosCooldown.Listeners;
import cz.boosik.boosCooldown.BoosConfigManager;
import cz.boosik.boosCooldown.BoosWarmUpManager;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerGameModeChangeEvent; import org.bukkit.event.player.PlayerGameModeChangeEvent;
import util.boosChat; import util.boosChat;
import cz.boosik.boosCooldown.BoosConfigManager;
import cz.boosik.boosCooldown.BoosWarmUpManager;
/**
* Posluchač naslouchající události, která se spouští v okamžiku kdy hráč změní
* herní mód. Pokud na příkazech hráče je aktivní časovač warmup, ve chvíli
* spuštění této události jsou všechny jeho warmup časovače stornovány a hráči
* je odeslána zpráva, která ho o této skutečnosti informuje. Pokud hráč
* disponuje oprávněním booscooldowns.nocancel.gamemodechange, jeho warmup
* časovače stornovány nejsou.
*
* @author Jakub Kolář
*
*/
public class BoosPlayerGameModeChangeListener implements Listener { public class BoosPlayerGameModeChangeListener implements Listener {
/**
* Metoda zjišťuje jestli je entita která spustila tuto událost hráč. Pokud
* je entita hráč, hráč není null a nedisponuje oprávněním
* booscooldowns.nocancel.gamemodechange a pokud tento hráč disponuje
* aktivními warmup časovači, pak je hráči odeslána zpráva, která ho
* informuje o ukončení všech warmup časovačů a následně tyto časovače
* ukončuje pomocí metody cancelWarmUps();.
*
* @param event
* událost PlayerGameModeChangeEvent
*/
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
private void onPlayerGameModeChange(PlayerGameModeChangeEvent event) {
Entity entity = event.getPlayer();
if (entity != null && entity instanceof Player) {
Player player = (Player) entity;
if (player != null
&& !player
.hasPermission("booscooldowns.nocancel.gamemodechange")) {
if (BoosWarmUpManager.hasWarmUps(player)) {
boosChat.sendMessageToPlayer(player, BoosConfigManager
.getCancelWarmupByGameModeChangeMessage());
BoosWarmUpManager.cancelWarmUps(player);
}
} @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
} private void onPlayerGameModeChange(PlayerGameModeChangeEvent event) {
} Entity entity = event.getPlayer();
if (entity != null) {
Player player = (Player) entity;
if (!player
.hasPermission("booscooldowns.nocancel.gamemodechange")) {
if (BoosWarmUpManager.hasWarmUps(player)) {
boosChat.sendMessageToPlayer(player, BoosConfigManager
.getCancelWarmupByGameModeChangeMessage());
BoosWarmUpManager.cancelWarmUps(player);
}
}
}
}
} }

View File

@ -1,84 +1,60 @@
package cz.boosik.boosCooldown.Listeners; package cz.boosik.boosCooldown.Listeners;
import cz.boosik.boosCooldown.BoosConfigManager;
import cz.boosik.boosCooldown.BoosWarmUpManager;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import util.boosChat; import util.boosChat;
import cz.boosik.boosCooldown.BoosConfigManager;
import cz.boosik.boosCooldown.BoosWarmUpManager;
/**
* Posluchaè naslouchající události, která se spouští v okamžiku kdy hráè
* provádí interakce s herními bloky. Pokud na pøíkazech hráèe je aktivní
* èasovaè warmup a blok se kterým hráè interaguje je kontejner, pak tato tøída
* poté ukonèuje tuto událost a blokuje hráèi pøístup do kontejnerù. Pokud hráè
* disponuje oprávnìním booscooldowns.dontblock.interact, jeho pøístup do
* kontejnerù není blokován.
*
* @author Jakub Koláø
*
*/
public class BoosPlayerInteractListener implements Listener { public class BoosPlayerInteractListener implements Listener {
/**
* Metoda zjiš<EFBFBD>uje jestli je entita která spustila tuto událost hráè. Pokud
* je entita hráè, hráè není null a nedisponuje oprávnìním
* booscooldowns.dontblock.interact a pokud tento hráè disponuje aktivními
* warmup èasovaèi a blok se kterým interaguje je kontejner, pak je hráèi
* odeslána zpráva, která ho informuje o tom, že do kontejneru není možné
* pøistupovat a tato událost je následnì ukonèena. To zablokuje hráèi
* pøístup do kontejneru.
*
* @param event
* událost PlayerInteractEvent
*/
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
private void onPlayerInteract(PlayerInteractEvent event) {
Entity entity = event.getPlayer();
if (entity != null && entity instanceof Player) {
Player player = (Player) entity;
if (player != null
&& !player
.hasPermission("booscooldowns.dontblock.interact")) {
if (BoosWarmUpManager.hasWarmUps(player)) {
if (event.getClickedBlock().getType().name()
.equals("CHEST")
|| event.getClickedBlock().getType().name()
.equals("FURNACE")
|| event.getClickedBlock().getType().name()
.equals("BURNING_FURNACE")
|| event.getClickedBlock().getType().name()
.equals("WORKBENCH")
|| event.getClickedBlock().getType().name()
.equals("DISPENSER")
|| event.getClickedBlock().getType().name()
.equals("JUKEBOX")
|| event.getClickedBlock().getType().name()
.equals("LOCKED_CHEST")
|| event.getClickedBlock().getType().name()
.equals("ENCHANTMENT_TABLE")
|| event.getClickedBlock().getType().name()
.equals("BREWING_STAND")
|| event.getClickedBlock().getType().name()
.equals("CAULDRON")
|| event.getClickedBlock().getType().name()
.equals("STORAGE_MINECART")
|| event.getClickedBlock().getType().name()
.equals("TRAPPED_CHEST")
|| event.getClickedBlock().getType().name()
.equals("DROPPER")
|| event.getClickedBlock().getType().name()
.equals("HOPPER")) {
event.setCancelled(true);
boosChat.sendMessageToPlayer(player,
BoosConfigManager.getInteractBlockedMessage());
}
}
} @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
} private void onPlayerInteract(PlayerInteractEvent event) {
} Entity entity = event.getPlayer();
if (entity != null) {
Player player = (Player) entity;
if (!player
.hasPermission("booscooldowns.dontblock.interact")) {
if (BoosWarmUpManager.hasWarmUps(player)) {
if (event.getClickedBlock().getType().name()
.equals("CHEST")
|| event.getClickedBlock().getType().name()
.equals("FURNACE")
|| event.getClickedBlock().getType().name()
.equals("BURNING_FURNACE")
|| event.getClickedBlock().getType().name()
.equals("WORKBENCH")
|| event.getClickedBlock().getType().name()
.equals("DISPENSER")
|| event.getClickedBlock().getType().name()
.equals("JUKEBOX")
|| event.getClickedBlock().getType().name()
.equals("LOCKED_CHEST")
|| event.getClickedBlock().getType().name()
.equals("ENCHANTMENT_TABLE")
|| event.getClickedBlock().getType().name()
.equals("BREWING_STAND")
|| event.getClickedBlock().getType().name()
.equals("CAULDRON")
|| event.getClickedBlock().getType().name()
.equals("STORAGE_MINECART")
|| event.getClickedBlock().getType().name()
.equals("TRAPPED_CHEST")
|| event.getClickedBlock().getType().name()
.equals("DROPPER")
|| event.getClickedBlock().getType().name()
.equals("HOPPER")) {
event.setCancelled(true);
boosChat.sendMessageToPlayer(player,
BoosConfigManager.getInteractBlockedMessage());
}
}
}
}
}
} }

View File

@ -1,83 +1,34 @@
package cz.boosik.boosCooldown.Listeners; package cz.boosik.boosCooldown.Listeners;
import org.bukkit.Location; import cz.boosik.boosCooldown.BoosConfigManager;
import cz.boosik.boosCooldown.BoosWarmUpManager;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerMoveEvent;
import util.boosChat; import util.boosChat;
import cz.boosik.boosCooldown.BoosConfigManager;
import cz.boosik.boosCooldown.BoosWarmUpManager;
/**
* Posluchač naslouchající události, která se spouští v okamžiku kdy se hráč
* pohybuje. Pokud na příkazech hráče je aktivní časovač warmup, ve chvíli
* spuštění této události jsou všechny jeho warmup časovače stornovány a hráči
* je odeslána zpráva, která ho o této skutečnosti informuje. Při pohybech hráče
* hra tuto událost spouští 20 krát každou vteřinu. To může být na velkých
* serverech velmi neoptimální a proto se funkce spouští jen jednou za vteřinu,
* pomocí jednoduchého cyklu. Pokud hráč disponuje oprávněním
* booscooldowns.nocancel.move, jeho warmup časovače stornovány nejsou.
*
* @author Jakub Kolář
*
*/
public class BoosPlayerMoveListener implements Listener { public class BoosPlayerMoveListener implements Listener {
/** private int tempTimer = 0;
* Metoda zjišťující, jestli hráč změnil pozico ve světě, nebo případně svět
* od doby kdy použil příkaz do doby volání této metody.
*
* @param player
* hráč který se pohybuje
* @return true pokud hráč změnil svou pozici, nebo pokud přešel do jiného
* světa; jinak vrací false
*/
private static boolean hasMoved(Player player) {
String curworld = player.getWorld().getName();
String cmdworld = BoosWarmUpManager.getPlayerworld().get(player);
Location curloc = player.getLocation();
Location cmdloc = BoosWarmUpManager.getPlayerloc().get(player);
if (!curworld.equals(cmdworld)) {
return true;
} else if (cmdloc.distance(curloc) > 1) {
return true;
}
return false; @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
} private void onPlayerMove(PlayerMoveEvent event) {
private int tempTimer = 0; if (tempTimer < 10) {
tempTimer = tempTimer + 1;
/** } else {
* Pokud hráč není null a nedisponuje oprávněním booscooldowns.nocancel.move Player player = event.getPlayer();
* a pokud tento hráč disponuje aktivními warmup časovači, pak je hráči if (player != null
* odeslána zpráva, která ho informuje o ukončení všech warmup časovačů a && !player.hasPermission("booscooldowns.nocancel.move")) {
* následně tyto časovače ukončuje pomocí metody cancelWarmUps();. Metoda if (BoosWarmUpManager.hasWarmUps(player) && (event.getFrom().getX() != event.getTo().getX() || event.getFrom().getZ() != event.getTo().getZ() || event.getFrom().getY() != event.getTo().getY())) {
* obsahuje jednoduchý časovač, který zajišťuje, že funkce nebudou prováděny BoosWarmUpManager.clearLocWorld(player);
* při každém volání této metody (20x za vteřinu). boosChat.sendMessageToPlayer(player,
* BoosConfigManager.getWarmUpCancelledByMoveMessage());
* @param event BoosWarmUpManager.cancelWarmUps(player);
* událost PlayerMoveEvent }
*/ }
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) tempTimer = 0;
private void onPlayerMove(PlayerMoveEvent event) { }
if (tempTimer < 20) { }
tempTimer = tempTimer + 1;
return;
} else {
Player player = event.getPlayer();
if (player != null
&& !player.hasPermission("booscooldowns.nocancel.move")) {
if (BoosWarmUpManager.hasWarmUps(player) && hasMoved(player)) {
BoosWarmUpManager.clearLocWorld(player);
boosChat.sendMessageToPlayer(player,
BoosConfigManager.getWarmUpCancelledByMoveMessage());
BoosWarmUpManager.cancelWarmUps(player);
}
}
tempTimer = 0;
}
}
} }

View File

@ -1,48 +1,27 @@
package cz.boosik.boosCooldown.Listeners; package cz.boosik.boosCooldown.Listeners;
import cz.boosik.boosCooldown.BoosConfigManager;
import cz.boosik.boosCooldown.BoosWarmUpManager;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerToggleSneakEvent; import org.bukkit.event.player.PlayerToggleSneakEvent;
import util.boosChat; import util.boosChat;
import cz.boosik.boosCooldown.BoosConfigManager;
import cz.boosik.boosCooldown.BoosWarmUpManager;
/**
* Posluchač naslouchající události, která se spouští v okamžiku kdy hráč zapne
* plížení (defaultně pomocí klávesy control). Pokud na příkazech hráče je
* aktivní časovač warmup, ve chvíli spuštění této události jsou všechny jeho
* warmup časovače stornovány a hráči je odeslána zpráva, která ho o této
* skutečnosti informuje. Pokud hráč disponuje oprávněním
* booscooldowns.nocancel.sneak, jeho warmup časovače stornovány nejsou.
*
* @author Jakub Kolář
*
*/
public class BoosPlayerToggleSneakListener implements Listener { public class BoosPlayerToggleSneakListener implements Listener {
/**
* Pokud hráč není null a nedisponuje oprávněním
* booscooldowns.nocancel.sneak a pokud tento hráč disponuje aktivními
* warmup časovači, pak je hráči odeslána zpráva, která ho informuje o
* ukončení všech warmup časovačů a následně tyto časovače ukončuje pomocí
* metody cancelWarmUps();.
*
* @param event
* událost PlayerToggleSneakEvent
*/
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
private void onPlayerToggleSneak(PlayerToggleSneakEvent event) {
Player player = event.getPlayer();
if (player != null
&& !player.hasPermission("booscooldowns.nocancel.sneak")) {
if (BoosWarmUpManager.hasWarmUps(player)) {
boosChat.sendMessageToPlayer(player,
BoosConfigManager.getCancelWarmupOnSneakMessage());
BoosWarmUpManager.cancelWarmUps(player);
}
} @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
} private void onPlayerToggleSneak(PlayerToggleSneakEvent event) {
Player player = event.getPlayer();
if (player != null
&& !player.hasPermission("booscooldowns.nocancel.sneak")) {
if (BoosWarmUpManager.hasWarmUps(player)) {
boosChat.sendMessageToPlayer(player,
BoosConfigManager.getCancelWarmupOnSneakMessage());
BoosWarmUpManager.cancelWarmUps(player);
}
}
}
} }

View File

@ -1,48 +1,27 @@
package cz.boosik.boosCooldown.Listeners; package cz.boosik.boosCooldown.Listeners;
import cz.boosik.boosCooldown.BoosConfigManager;
import cz.boosik.boosCooldown.BoosWarmUpManager;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerToggleSprintEvent; import org.bukkit.event.player.PlayerToggleSprintEvent;
import util.boosChat; import util.boosChat;
import cz.boosik.boosCooldown.BoosConfigManager;
import cz.boosik.boosCooldown.BoosWarmUpManager;
/**
* Posluchač naslouchající události, která se spouští v okamžiku kdy hráč zapne
* sprintování (pomocí dvojitého stisknutí klávesy pro pohyb vpřed). Pokud na
* příkazech hráče je aktivní časovač warmup, ve chvíli spuštění této události
* jsou všechny jeho warmup časovače stornovány a hráči je odeslána zpráva,
* která ho o této skutečnosti informuje. Pokud hráč disponuje oprávněním
* booscooldowns.nocancel.sprint, jeho warmup časovače stornovány nejsou.
*
* @author Jakub Kolář
*
*/
public class BoosPlayerToggleSprintListener implements Listener { public class BoosPlayerToggleSprintListener implements Listener {
/**
* Pokud hráč není null a nedisponuje oprávněním
* booscooldowns.nocancel.sprint a pokud tento hráč disponuje aktivními
* warmup časovači, pak je hráči odeslána zpráva, která ho informuje o
* ukončení všech warmup časovačů a následně tyto časovače ukončuje pomocí
* metody cancelWarmUps();.
*
* @param event
* událost PlayerToggleSprintEvent
*/
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
private void onPlayerToggleSprint(PlayerToggleSprintEvent event) {
Player player = event.getPlayer();
if (player != null
&& !player.hasPermission("booscooldowns.nocancel.sprint")) {
if (BoosWarmUpManager.hasWarmUps(player)) {
boosChat.sendMessageToPlayer(player,
BoosConfigManager.getCancelWarmupOnSprintMessage());
BoosWarmUpManager.cancelWarmUps(player);
}
} @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
} private void onPlayerToggleSprint(PlayerToggleSprintEvent event) {
Player player = event.getPlayer();
if (player != null
&& !player.hasPermission("booscooldowns.nocancel.sprint")) {
if (BoosWarmUpManager.hasWarmUps(player)) {
boosChat.sendMessageToPlayer(player,
BoosConfigManager.getCancelWarmupOnSprintMessage());
BoosWarmUpManager.cancelWarmUps(player);
}
}
}
} }

View File

@ -1,46 +1,37 @@
package cz.boosik.boosCooldown.Listeners; package cz.boosik.boosCooldown.Listeners;
import cz.boosik.boosCooldown.BoosConfigManager;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.SignChangeEvent; import org.bukkit.event.block.SignChangeEvent;
import util.boosChat; import util.boosChat;
import cz.boosik.boosCooldown.BoosConfigManager;
/**
* @author Jakub Koláø
*
*/
public class BoosSignChangeListener implements Listener { public class BoosSignChangeListener implements Listener {
/**
* @param event @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
*/ private void onSignChange(SignChangeEvent event) {
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) Player player = event.getPlayer();
private void onSignChange(SignChangeEvent event) { String line1 = event.getLine(0);
Player player = event.getPlayer(); String line2 = event.getLine(1);
String line1 = event.getLine(0); if (line1.equals("[boosCooldowns]")) {
String line2 = event.getLine(1); if (line2.equals("player")
if (line1.equals("[boosCooldowns]")) { && !player
if (line2.equals("player") .hasPermission("booscooldowns.signs.player.place")) {
&& !player boosChat.sendMessageToPlayer(player,
.hasPermission("booscooldowns.signs.player.place")) { BoosConfigManager.getCannotCreateSignMessage());
boosChat.sendMessageToPlayer(player, event.getBlock().breakNaturally();
BoosConfigManager.getCannotCreateSignMessage()); event.setCancelled(true);
event.getBlock().breakNaturally(); }
event.setCancelled(true); if (line2.equals("server")
return; && !player
} .hasPermission("booscooldowns.signs.server.place")) {
if (line2.equals("server") boosChat.sendMessageToPlayer(player,
&& !player BoosConfigManager.getCannotCreateSignMessage());
.hasPermission("booscooldowns.signs.server.place")) { event.getBlock().breakNaturally();
boosChat.sendMessageToPlayer(player, event.setCancelled(true);
BoosConfigManager.getCannotCreateSignMessage()); }
event.getBlock().breakNaturally(); }
event.setCancelled(true); }
return;
}
}
}
} }

View File

@ -1,5 +1,7 @@
package cz.boosik.boosCooldown.Listeners; package cz.boosik.boosCooldown.Listeners;
import cz.boosik.boosCooldown.BoosConfigManager;
import cz.boosik.boosCooldown.BoosCoolDown;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Sign; import org.bukkit.block.Sign;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -8,69 +10,56 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import util.boosChat; import util.boosChat;
import cz.boosik.boosCooldown.BoosConfigManager;
import cz.boosik.boosCooldown.BoosCoolDown;
/**
* @author Jakub
*
*/
public class BoosSignInteractListener implements Listener { public class BoosSignInteractListener implements Listener {
private final BoosCoolDown plugin; private final BoosCoolDown plugin;
/** public BoosSignInteractListener(BoosCoolDown instance) {
* @param instance plugin = instance;
*/ }
public BoosSignInteractListener(BoosCoolDown instance) {
plugin = instance;
}
/** @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
* @param event private void onSignInteract(PlayerInteractEvent event) {
*/ String msg;
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) if (event.isCancelled())
private void onSignInteract(PlayerInteractEvent event) { return;
String msg;
if (event.isCancelled())
return;
if (event.hasBlock() && event.getAction() == Action.RIGHT_CLICK_BLOCK) { if (event.hasBlock() && event.getAction() == Action.RIGHT_CLICK_BLOCK) {
if (event.getClickedBlock().getType() == Material.SIGN_POST if (event.getClickedBlock().getType() == Material.SIGN_POST
|| event.getClickedBlock().getType() == Material.WALL_SIGN) { || event.getClickedBlock().getType() == Material.WALL_SIGN) {
Sign s = (Sign) event.getClickedBlock().getState(); Sign s = (Sign) event.getClickedBlock().getState();
String line1 = s.getLine(0); String line1 = s.getLine(0);
String line2 = s.getLine(1); String line2 = s.getLine(1);
String line3 = s.getLine(2); String line3 = s.getLine(2);
String line4 = s.getLine(3); String line4 = s.getLine(3);
Player player = event.getPlayer(); Player player = event.getPlayer();
if (line1.equals("[boosCooldowns]")) { if (line1.equals("[boosCooldowns]")) {
if (line2.equals("player") if (line2.equals("player")
&& player && player
.hasPermission("booscooldowns.signs.player.use")) { .hasPermission("booscooldowns.signs.player.use")) {
msg = line3; msg = line3;
if (line3.endsWith("+") || !line4.isEmpty()) { if (line3.endsWith("+") || !line4.isEmpty()) {
msg = line3.substring(0, line3.length() - 1) + " " msg = line3.substring(0, line3.length() - 1) + " "
+ line4; + line4;
} }
event.getPlayer().chat(msg); event.getPlayer().chat(msg);
} else if (line2.equals("server") } else if (line2.equals("server")
&& player && player
.hasPermission("booscooldowns.signs.server.use")) { .hasPermission("booscooldowns.signs.server.use")) {
msg = line3; msg = line3;
if (line3.endsWith("+") || !line4.isEmpty()) { if (line3.endsWith("+") || !line4.isEmpty()) {
msg = line3.substring(0, line3.length() - 1) + " " msg = line3.substring(0, line3.length() - 1) + " "
+ line4; + line4;
} }
plugin.getServer().dispatchCommand( plugin.getServer().dispatchCommand(
plugin.getServer().getConsoleSender(), msg); plugin.getServer().getConsoleSender(), msg);
} else { } else {
boosChat.sendMessageToPlayer(player, boosChat.sendMessageToPlayer(player,
BoosConfigManager.getCannotUseSignMessage()); BoosConfigManager.getCannotUseSignMessage());
} }
} }
} }
} }
} }
} }

View File

@ -52,6 +52,7 @@ import java.util.UUID;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.zip.GZIPOutputStream; import java.util.zip.GZIPOutputStream;
@SuppressWarnings("ALL")
public class MetricsLite { public class MetricsLite {
/** /**
@ -206,7 +207,7 @@ public class MetricsLite {
* *
* @return true if metrics should be opted out of it * @return true if metrics should be opted out of it
*/ */
public boolean isOptOut() { boolean isOptOut() {
synchronized (optOutLock) { synchronized (optOutLock) {
try { try {
// Reload the metrics file // Reload the metrics file
@ -283,7 +284,7 @@ public class MetricsLite {
* *
* @return the File object for the config file * @return the File object for the config file
*/ */
public File getConfigFile() { File getConfigFile() {
// I believe the easiest way to get the base folder (e.g craftbukkit set // I believe the easiest way to get the base folder (e.g craftbukkit set
// via -P) for plugins to use // via -P) for plugins to use
// is to abuse the plugin object we already have // is to abuse the plugin object we already have
@ -428,7 +429,7 @@ public class MetricsLite {
* @param input * @param input
* @return * @return
*/ */
public static byte[] gzip(String input) { private static byte[] gzip(String input) {
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream gzos = null; GZIPOutputStream gzos = null;

View File

@ -8,25 +8,28 @@ import org.bukkit.Server;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@SuppressWarnings("ALL")
public class boosChat { public class boosChat {
static Logger log = Logger.getLogger("Minecraft"); private static final Logger log = Logger.getLogger("Minecraft");
static List<String> Colors = new LinkedList<String>(); @SuppressWarnings("MismatchedQueryAndUpdateOfCollection")
static Server server; private static final List<String> Colors = new LinkedList<>();
private static Server server;
@SuppressWarnings("UnusedDeclaration")
public static void broadcastMessage(String message) { public static void broadcastMessage(String message) {
message = boosChat.replaceColorCodes(message); message = boosChat.replaceColorCodes(message);
log.info("[bColoredChat] " + message); log.info("[bColoredChat] " + message);
server.broadcastMessage(message); server.broadcastMessage(message);
} }
static String replaceColorCodes(String line) { private static String replaceColorCodes(String line) {
line = replaceTags(line); line = replaceTags(line);
line = line.replaceAll("(&([a-f0-9]))", "\u00A7$2"); line = line.replaceAll("(&([a-f0-9]))", "\u00A7$2");
return line; return line;
} }
static String replaceTags(String line) { private static String replaceTags(String line) {
line = line.replaceAll("&black&", "&0"); line = line.replaceAll("&black&", "&0");
line = line.replaceAll("&darkblue&", "&1"); line = line.replaceAll("&darkblue&", "&1");
line = line.replaceAll("&darkgreen&", "&2"); line = line.replaceAll("&darkgreen&", "&2");
@ -60,7 +63,7 @@ public class boosChat {
player.sendMessage(message); player.sendMessage(message);
} }
public static void sendMessageToServer(String message) { private static void sendMessageToServer(String message) {
message = boosChat.replaceColorCodes(message); message = boosChat.replaceColorCodes(message);
log.info(message); log.info(message);
} }

View File

@ -57,6 +57,14 @@ options:
commands: commands:
groups: groups:
default: default:
/day_command:
limit: 5
shared_limit:
- /night_command
/night_command:
limit: 5
shared_limit:
- /day_command
/command parameter: /command parameter:
cooldown: 2 hours cooldown: 2 hours
/commandwithparameters *: /commandwithparameters *:

View File

@ -1,7 +1,7 @@
name: boosCooldowns name: boosCooldowns
main: cz.boosik.boosCooldown.BoosCoolDown main: cz.boosik.boosCooldown.BoosCoolDown
version: 3.9.5c version: 3.9.6a
authors: [LordBoos (ingame name boosik)] authors: [LordBoos (boosik)]
softdepend: [Vault] softdepend: [Vault]
description: > description: >
Shortcuts Shortcuts