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;
import java.util.Set;
import org.bukkit.entity.Player;
public class BoosAliasManager {
import java.util.Set;
public static String checkCommandAlias(String originalCommand,
Set<String> aliases, Player player) {
String[] splitCommand = originalCommand.split(" ", 4);
String one = "";
String two = "";
String three = "";
if (splitCommand.length > 1) {
one = splitCommand[1];
if (splitCommand.length > 2) {
two = splitCommand[2];
if (splitCommand.length > 3) {
three = splitCommand[3];
}
}
}
for (String alias : aliases) {
String alias2 = alias.replace("*", ".+");
if (originalCommand.matches("(?i)" + alias2)) {
originalCommand = BoosConfigManager.getAlias(alias);
if (originalCommand.contains("$1")) {
originalCommand = originalCommand.replace("$1", one);
}
if (originalCommand.contains("$2")) {
originalCommand = originalCommand.replace("$2", two);
}
if (originalCommand.contains("$*")) {
originalCommand = originalCommand.replace("$*", three);
}
if (originalCommand.contains("$player")) {
originalCommand = originalCommand.replace("$player",
player.getName());
}
if (originalCommand.contains("$world")) {
originalCommand = originalCommand.replace("$world", player
.getWorld().getName());
}
}
}
originalCommand = originalCommand.trim().replaceAll(" +", " ");
return originalCommand;
}
class BoosAliasManager {
public static String checkCommandAlias(String originalCommand,
Set<String> aliases, Player player) {
String[] splitCommand = originalCommand.split(" ", 4);
String one = "";
String two = "";
String three = "";
if (splitCommand.length > 1) {
one = splitCommand[1];
if (splitCommand.length > 2) {
two = splitCommand[2];
if (splitCommand.length > 3) {
three = splitCommand[3];
}
}
}
for (String alias : aliases) {
String alias2 = alias.replace("*", ".+");
if (originalCommand.matches("(?i)" + alias2)) {
originalCommand = BoosConfigManager.getAlias(alias);
if (originalCommand.contains("$1")) {
originalCommand = originalCommand.replace("$1", one);
}
if (originalCommand.contains("$2")) {
originalCommand = originalCommand.replace("$2", two);
}
if (originalCommand.contains("$*")) {
originalCommand = originalCommand.replace("$*", three);
}
if (originalCommand.contains("$player")) {
originalCommand = originalCommand.replace("$player",
player.getName());
}
if (originalCommand.contains("$world")) {
originalCommand = originalCommand.replace("$world", player
.getWorld().getName());
}
}
}
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;
import java.io.IOException;
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 cz.boosik.boosCooldown.Listeners.*;
import net.milkbowl.vault.Vault;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
@ -26,535 +17,439 @@ import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitScheduler;
import org.mcstats.MetricsLite;
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;
/**
* Hlavn<EFBFBD> t<EFBFBD><EFBFBD>da pluginu. T<EFBFBD><EFBFBD>da je potomkem JavaPlugin a implementuje Runnable.
* 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.
* Toto zahrnuje zji<EFBFBD>t<EFBFBD>n<EFBFBD>, zda je k dispozici plugin Vault a ekonomick<EFBFBD> plugin,
* registraci poslucha<EFBFBD><EFBFBD> a tak<EFBFBD> se star<EFBFBD> o funkce v<EFBFBD>ech kontroln<EFBFBD>ch a
* konfigura<EFBFBD>n<EFBFBD>ch p<EFBFBD><EFBFBD>kaz<EFBFBD>. Periodicky tak<EFBFBD> ukl<EFBFBD>d<EFBFBD> soubor datab<EFBFBD>ze v intervalu
* nastaven<EFBFBD>m v konfiguraci.
*
* @author Jakub Kol<EFBFBD><EFBFBD>
*
*/
import java.io.IOException;
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;
public class BoosCoolDown extends JavaPlugin implements Runnable {
private static final Logger log = Logger.getLogger("Minecraft");
private static PluginDescriptionFile pdfFile;
private static Economy economy = null;
private static boolean usingVault = false;
private PluginManager pm;
private static BoosCoolDown instance = null;
private static final Logger log = Logger.getLogger("Minecraft");
private static PluginDescriptionFile pdfFile;
private static Economy economy = null;
private static boolean usingVault = false;
private PluginManager pm;
/**
* Metoda odes<EFBFBD>l<EFBFBD> zpr<EFBFBD>vy o pou<EFBFBD>it<EFBFBD> p<EFBFBD><EFBFBD>kaz<EFBFBD> do konzole serveru.
*
* @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 void commandLogger(String player, String command) {
log.info("[" + "boosLogger" + "] " + player + " used command "
+ command);
}
/**
* @return
*/
public static Economy getEconomy() {
return economy;
}
public static Economy getEconomy() {
return economy;
}
/**
* @return
*/
public static Logger getLog() {
return log;
}
public static Logger getLog() {
return log;
}
/**
* 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
* hr<EFBFBD><EFBFBD>e nebo ne.
*
* @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;
}
static boolean isPluginOnForPlayer(Player player) {
boolean on;
on = !player.hasPermission("booscooldowns.exception") && !player.isOp();
return on;
}
/**
* Metoda zji<EFBFBD><EFBFBD>uje jestli je dostupn<EFBFBD> plugin Vault a na z<EFBFBD>klad<EFBFBD> toho vol<EFBFBD>
* metodu pro nastaven<EFBFBD> ekonomick<EFBFBD>ho pluginu a informuje o tom u<EFBFBD>ivatele
* pomoc<EFBFBD> konzole serveru.
*/
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;
}
}
private static void startLimitResetTimersGlobal() {
YamlConfiguration confusers = BoosConfigManager.getConfusers();
ConfigurationSection global = confusers
.getConfigurationSection("global");
if (global != null) {
Set<String> globalKeys = global.getKeys(false);
BukkitScheduler scheduler = Bukkit.getScheduler();
for (String key : globalKeys) {
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);
}
}
}
}
/*
* (non-Javadoc)
*
* @see
* org.bukkit.plugin.java.JavaPlugin#onCommand(org.bukkit.command.CommandSender
* , org.bukkit.command.Command, java.lang.String, java.lang.String[])
*/
@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;
static void startLimitResetTimerGlobal(String key) {
YamlConfiguration confusers = BoosConfigManager.getConfusers();
BukkitScheduler scheduler = Bukkit.getScheduler();
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);
}
}
}
}
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;
}
}
private static long secondsBetween(Calendar startDate, Calendar endDate,
long limitResetDelay) {
long secondsBetween = 0;
secondsBetween = ((endDate.getTimeInMillis() - startDate
.getTimeInMillis()) / 1000) + limitResetDelay;
return secondsBetween;
}
}
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;
}
}
private 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;
try {
time = sdf.parse(currTime);
return time;
} catch (ParseException e) {
return null;
}
}
} 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,
// "&6[" + pdfFile.getName() + "]&e"
// + " Invalid command or access denied!");
return false;
}
}
return false;
return false;
}
}
return false;
}
}
/*
* (non-Javadoc)
*
* @see org.bukkit.plugin.java.JavaPlugin#onDisable()
*/
@Override
public void onDisable() {
if (BoosConfigManager.getClearOnRestart()) {
BoosConfigManager.clear();
log.info("[" + pdfFile.getName() + "]" + " cooldowns cleared!");
} else {
BoosConfigManager.saveConfusers();
log.info("[" + pdfFile.getName() + "]" + " cooldowns saved!");
}
log.info("[" + pdfFile.getName() + "]" + " version "
+ pdfFile.getVersion() + " disabled!");
}
@Override
public void onDisable() {
if (BoosConfigManager.getClearOnRestart()) {
BoosConfigManager.clear();
log.info("[" + pdfFile.getName() + "]" + " cooldowns cleared!");
} else {
BoosConfigManager.saveConfusers();
log.info("[" + pdfFile.getName() + "]" + " cooldowns saved!");
}
log.info("[" + pdfFile.getName() + "]" + " version "
+ pdfFile.getVersion() + " disabled!");
}
/*
* (non-Javadoc)
*
* @see org.bukkit.plugin.java.JavaPlugin#onEnable()
*/
@Override
public void onEnable() {
pdfFile = this.getDescription();
PluginDescriptionFile pdfFile = this.getDescription();
log.info("[" + pdfFile.getName() + "]" + " version "
+ pdfFile.getVersion() + " by " + pdfFile.getAuthors()
+ " is enabled!");
this.saveDefaultConfig();
new BoosConfigManager(this);
BoosConfigManager.load();
BoosConfigManager.loadConfusers();
pm = getServer().getPluginManager();
registerListeners();
initializeVault();
BukkitScheduler scheduler = this.getServer().getScheduler();
startLimitResetTimersGlobal();
if (BoosConfigManager.getAutoSave()) {
scheduler.scheduleSyncRepeatingTask(this, this,
BoosConfigManager.getSaveInterval() * 1200,
BoosConfigManager.getSaveInterval() * 1200);
}
@Override
public void onEnable() {
pdfFile = this.getDescription();
PluginDescriptionFile pdfFile = this.getDescription();
log.info("[" + pdfFile.getName() + "]" + " version "
+ pdfFile.getVersion() + " by " + pdfFile.getAuthors()
+ " is enabled!");
this.saveDefaultConfig();
new BoosConfigManager(this);
BoosConfigManager.load();
BoosConfigManager.loadConfusers();
pm = getServer().getPluginManager();
registerListeners();
initializeVault();
BukkitScheduler scheduler = this.getServer().getScheduler();
startLimitResetTimersGlobal();
if (BoosConfigManager.getAutoSave()) {
scheduler.scheduleSyncRepeatingTask(this, this,
BoosConfigManager.getSaveInterval() * 1200,
BoosConfigManager.getSaveInterval() * 1200);
}
if (BoosConfigManager.getClearOnRestart()) {
BoosConfigManager.clear();
}
try {
MetricsLite metrics = new MetricsLite(this);
metrics.start();
} catch (IOException e) {
// Failed to submit the stats :-(
}
if (BoosConfigManager.getClearOnRestart()) {
BoosConfigManager.clear();
}
try {
MetricsLite metrics = new MetricsLite(this);
metrics.start();
} catch (IOException e) {
// Failed to submit the stats :-(
}
}
}
static void startLimitResetTimersGlobal() {
YamlConfiguration confusers = BoosConfigManager.getConfusers();
ConfigurationSection global = confusers
.getConfigurationSection("global");
if (global != null) {
Set<String> globalKeys = global.getKeys(false);
BukkitScheduler scheduler = Bukkit.getScheduler();
for (String key : globalKeys) {
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);
}
}
}
}
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);
}
}
static void startLimitResetTimerGlobal(String key) {
YamlConfiguration confusers = BoosConfigManager.getConfusers();
BukkitScheduler scheduler = Bukkit.getScheduler();
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);
}
}
private void reload() {
BoosConfigManager.reload();
registerListeners();
}
static long secondsBetween(Calendar startDate, Calendar endDate,
long limitResetDelay) {
long secondsBetween = 0;
secondsBetween = ((endDate.getTimeInMillis() - startDate
.getTimeInMillis()) / 1000) + limitResetDelay;
return secondsBetween;
}
@Override
public void run() {
BoosConfigManager.saveConfusers();
BoosConfigManager.loadConfusers();
log.info("[boosCooldowns] Config saved!");
}
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 {
time = sdf.parse(currTime);
return time;
} catch (ParseException e) {
return null;
}
}
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;
}
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;
}
}

View File

@ -1,283 +1,223 @@
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.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import util.boosChat;
/**
* Hlavn<EFBFBD> poslucha<EFBFBD>, kter<EFBFBD> naslouch<EFBFBD> ud<EFBFBD>losti pou<EFBFBD>it<EFBFBD> p<EFBFBD><EFBFBD>kazu hr<EFBFBD><EFBFBD>em.
* Kontroluje, jestli jsou pro p<EFBFBD><EFBFBD>kaz nastaveny omezen<EFBFBD> a na z<EFBFBD>klad<EFBFBD> tohoto
* spou<EFBFBD>t<EFBFBD> <EFBFBD>asova<EFBFBD>e a vol<EFBFBD> metody spojen<EFBFBD> s poplatky a limity.
*
* @author Jakub Kol<EFBFBD><EFBFBD>
*
*/
public class BoosCoolDownListener implements Listener {
private static BoosCoolDown plugin;
import java.util.List;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @param instance
*/
public BoosCoolDownListener(BoosCoolDown instance) {
plugin = instance;
}
class BoosCoolDownListener implements Listener {
private static BoosCoolDown plugin;
/**
* Metoda zkontroluje pomoc<EFBFBD> vol<EFBFBD>n<EFBFBD> dal<EFBFBD><EFBFBD>ch metod, jestli p<EFBFBD>ikaz kter<EFBFBD> hr<EFBFBD><EFBFBD>
* 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);
}
}
}
public BoosCoolDownListener(BoosCoolDown instance) {
plugin = instance;
}
/**
* 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>
* p<EFBFBD>ed t<EFBFBD>m, ne<EFBFBD> je vykon<EFBFBD>n efekt tohto p<EFBFBD><EFBFBD>kazu. Metoda zji<EFBFBD><EFBFBD>uje, jestli
* p<EFBFBD><EFBFBD>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>
* pou<EFBFBD>il shoduje s p<EFBFBD><EFBFBD>kazem nastaven<EFBFBD>m v konfiguraci. Pokud se shoduje, pak
* jsou na<EFBFBD>teny informace o warmup dob<EFBFBD>, cooldown dob<EFBFBD>, poplatku a limitu.
* Tyto hodnoty jsou pot<EFBFBD> p<EFBFBD>ed<EFBFBD>ny metod<EFBFBD> checkRestrictions();.
*
* @param event
* ud<EFBFBD>lost PlayerCommandPreprocessEvent
*/
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
private void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
Player player = event.getPlayer();
if (event.getMessage().contains(":")) {
Pattern p = Pattern.compile("^/([a-zA-Z0-9_]+):");
Matcher m = p.matcher(event.getMessage());
if (m.find()) {
{
boosChat.sendMessageToPlayer(player, BoosConfigManager
.getInvalidCommandSyntaxMessage(player));
event.setCancelled(true);
return;
}
}
}
String originalCommand = event.getMessage().replace("\\", "\\\\");
originalCommand = originalCommand.replace("$", "S");
originalCommand = originalCommand.trim().replaceAll(" +", " ");
String regexCommad = "";
Set<String> aliases = BoosConfigManager.getAliases();
Set<String> commands = BoosConfigManager.getCommands(player);
boolean on = true;
String item = "";
int count = 0;
int warmupTime = 0;
double price = 0;
int limit = -1;
int cooldownTime = 0;
int xpPrice = 0;
on = BoosCoolDown.isPluginOnForPlayer(player);
if (aliases != null) {
originalCommand = BoosAliasManager.checkCommandAlias(
originalCommand, aliases, player);
event.setMessage(originalCommand);
}
if (on && commands != null) {
for (String group : commands) {
String group2 = group.replace("*", ".+");
if (originalCommand.matches("(?i)" + group2)) {
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 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()) {
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);
}
}
}
/**
* Metoda spou<EFBFBD>t<EFBFBD> warmup a cooldown <EFBFBD>asova<EFBFBD>e, p<EFBFBD><EFBFBD>padn<EFBFBD> je ukon<EFBFBD>uje, pokud
* ji<EFBFBD> tyto <EFBFBD>asova<EFBFBD>e skon<EFBFBD>ili.
*
* @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
*/
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);
return;
} else {
event.setCancelled(true);
return;
}
} else {
if (BoosCoolDownManager.coolDown(player, regexCommad,
originalCommand, cooldownTime)) {
event.setCancelled(true);
return;
} else {
BoosWarmUpManager.removeWarmUpOK(player, regexCommad);
return;
}
}
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
private void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
Player player = event.getPlayer();
if (event.getMessage().contains(":")) {
Pattern p = Pattern.compile("^/([a-zA-Z0-9_]+):");
Matcher m = p.matcher(event.getMessage());
if (m.find()) {
{
boosChat.sendMessageToPlayer(player, BoosConfigManager
.getInvalidCommandSyntaxMessage());
event.setCancelled(true);
return;
}
}
}
String originalCommand = event.getMessage().replace("\\", "\\\\");
originalCommand = originalCommand.replace("$", "S");
originalCommand = originalCommand.trim().replaceAll(" +", " ");
String regexCommad = "";
Set<String> aliases = BoosConfigManager.getAliases();
Set<String> commands = BoosConfigManager.getCommands(player);
boolean on;
String item = "";
int count = 0;
int warmupTime = 0;
double price = 0;
int limit = -1;
int cooldownTime = 0;
int xpPrice = 0;
on = BoosCoolDown.isPluginOnForPlayer(player);
if (aliases != null) {
originalCommand = BoosAliasManager.checkCommandAlias(
originalCommand, aliases, player);
event.setMessage(originalCommand);
}
if (on && commands != null) {
for (String group : commands) {
String group2 = group.replace("*", ".+");
if (originalCommand.matches("(?i)" + group2)) {
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;
import org.bukkit.entity.Player;
import util.boosChat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
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 {
/**
* 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);
}
/**
* Metoda vrac<EFBFBD> hodnotu boolean na z<EFBFBD>klad<EFBFBD> toho, jestli m<EFBFBD> specifikovan<EFBFBD>
* p<EFBFBD><EFBFBD>kaz aktivn<EFBFBD> cooldown <EFBFBD>asova<EFBFBD>.
*
* @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;
}
}
}
static void cancelCooldown(Player player, String regexCommand) {
int pre2 = regexCommand.toLowerCase().hashCode();
BoosConfigManager.getConfusers().set(
"users." + player.getUniqueId() + ".cooldown." + pre2, null);
}
/**
* Metoda kontroluje, jestli hr<EFBFBD><EFBFBD> nedisponuje opr<EFBFBD>vn<EFBFBD>n<EFBFBD>mi, kter<EFBFBD> obch<EFBFBD>zej<EFBFBD>
* cooldown <EFBFBD>asova<EFBFBD>e. Pokud t<EFBFBD>mito opr<EFBFBD>vn<EFBFBD>n<EFBFBD>mi hr<EFBFBD><EFBFBD> disponuje, pak metoda
* vrac<EFBFBD> false. Pokud hr<EFBFBD><EFBFBD> nedisponuje t<EFBFBD>mito opr<EFBFBD>vn<EFBFBD>n<EFBFBD>mi, vrac<EFBFBD> hodnotu
* vr<EFBFBD>cenou metodou cd();.
*
* @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 time
* cooldown doba v sekund<EFBFBD>ch, nastaven<EFBFBD> pro regexCommand v
* konfiguraci
* @return false pokud hr<EFBFBD><EFBFBD> disponuje opr<EFBFBD>vn<EFBFBD>n<EFBFBD>mi, jinak hodnotu vr<EFBFBD>cenou
* metodou cd();.
*/
static boolean coolDown(Player player, String regexCommand,
String originalCommand, int time) {
regexCommand = regexCommand.toLowerCase();
if (time > 0
&& !player.hasPermission("booscooldowns.nocooldown")
&& !player.hasPermission("booscooldowns.nocooldown."
+ originalCommand)) {
return cd(player, regexCommand, originalCommand, time);
}
return false;
}
private 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;
}
}
}
/**
* Metoda vrac<EFBFBD> sou<EFBFBD>asn<EFBFBD> p<EFBFBD>esn<EFBFBD> datum a <EFBFBD>as.
*
* @return sou<EFBFBD>asn<EFBFBD> <EFBFBD>as a datum
*/
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;
static boolean coolDown(Player player, String regexCommand,
String originalCommand, int time) {
regexCommand = regexCommand.toLowerCase();
return time > 0 && !player.hasPermission("booscooldowns.nocooldown") && !player.hasPermission("booscooldowns.nocooldown." + originalCommand) && cd(player, regexCommand, originalCommand, time);
}
try {
time = sdf.parse(currTime);
return time;
} catch (ParseException e) {
return null;
}
}
private 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;
/**
* Metoda vrac<EFBFBD> datum a <EFBFBD>as, kdy hr<EFBFBD><EFBFBD> naposledy pou<EFBFBD>il dan<EFBFBD> p<EFBFBD><EFBFBD>kaz.
*
* @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
* @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);
try {
time = sdf.parse(currTime);
return time;
} catch (ParseException e) {
return null;
}
}
if (confTime != null && !confTime.equals("")) {
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
Date lastDate = null;
private static Date getTime(Player player, String regexCommand) {
int pre2 = regexCommand.toLowerCase().hashCode();
String confTime = "";
confTime = BoosConfigManager.getConfusers().getString(
"users." + player.getUniqueId() + ".cooldown." + pre2, null);
try {
lastDate = sdf.parse(confTime);
return lastDate;
} catch (ParseException e) {
return null;
}
}
return null;
}
if (confTime != null && !confTime.equals("")) {
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
Date lastDate = null;
/**
* Metoda vrac<EFBFBD> hodnotu boolean na z<EFBFBD>klad<EFBFBD> toho, jestli m<EFBFBD> specifikovan<EFBFBD>
* p<EFBFBD><EFBFBD>kaz aktivn<EFBFBD> cooldown <EFBFBD>asova<EFBFBD>.
*
* @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 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;
}
try {
lastDate = sdf.parse(confTime);
return lastDate;
} catch (ParseException e) {
return null;
}
}
return null;
}
/**
* Metoda vrac<EFBFBD> hodnotu rozd<EFBFBD>lu v sekund<EFBFBD>ch mezi dv<EFBFBD>mi hodnotami datumu a
* <EFBFBD>asu.
*
* @param startDate
* @param endDate
* @return rozd<EFBFBD>l v sekund<EFBFBD>ch mezi startDate a endDate
*/
static long secondsBetween(Calendar startDate, Calendar endDate) {
long secondsBetween = 0;
secondsBetween = (endDate.getTimeInMillis() - startDate
.getTimeInMillis()) / 1000;
return secondsBetween;
}
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;
}
/**
* Metoda ukl<EFBFBD>d<EFBFBD> do datab<EFBFBD>ze datum a <EFBFBD>as kdy hr<EFBFBD><EFBFBD> naposledy pou<EFBFBD>il dan<EFBFBD>
* p<EFBFBD><EFBFBD>kaz.
*
* @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 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 long secondsBetween(Calendar startDate, Calendar endDate) {
long secondsBetween = 0;
secondsBetween = (endDate.getTimeInMillis() - startDate
.getTimeInMillis()) / 1000;
return secondsBetween;
}
/**
* Metoda spou<EFBFBD>t<EFBFBD> ve<EFBFBD>ker<EFBFBD> cooldown <EFBFBD>asova<EFBFBD>e pro specifick<EFBFBD>ho hr<EFBFBD><EFBFBD>e.
*
* @param player
* specifick<EFBFBD> hr<EFBFBD><EFBFBD>
* @param message
*/
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);
}
private 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);
}
}
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;
public class BoosGlobalLimitResetRunnable implements Runnable {
class BoosGlobalLimitResetRunnable implements Runnable {
private String command;
private final String command;
public BoosGlobalLimitResetRunnable(String key) {
this.command = key;
}
public BoosGlobalLimitResetRunnable(String key) {
this.command = key;
}
@Override
public void run() {
BoosCoolDown.getLog().info(
"[boosCooldowns] Reseting limits for command " + command);
BoosLimitManager.clearAllLimits(command.hashCode());
BoosLimitManager.setGlobalLimitResetDate(command);
String msg = BoosConfigManager.getLimitResetNowMessage();
msg = msg.replaceAll("&command&", command);
msg = msg.replaceAll("&", "§");
Bukkit.broadcastMessage(msg);
BoosCoolDown.startLimitResetTimerGlobal(command);
}
@Override
public void run() {
BoosCoolDown.getLog().info(
"[boosCooldowns] Reseting limits for command " + command);
BoosLimitManager.clearAllLimits(command.hashCode());
BoosLimitManager.setGlobalLimitResetDate(command);
String msg = BoosConfigManager.getLimitResetNowMessage();
msg = msg.replaceAll("&command&", command);
msg = msg.replaceAll("&", "§");
Bukkit.broadcastMessage(msg);
BoosCoolDown.startLimitResetTimerGlobal(command);
}
}

View File

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

View File

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

View File

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

View File

@ -1,287 +1,151 @@
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.Map;
import java.util.Timer;
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 {
private static ConcurrentHashMap<String, BoosWarmUpTimer> playercommands = new ConcurrentHashMap<String, BoosWarmUpTimer>();
private static ConcurrentHashMap<Player, Location> playerloc = new ConcurrentHashMap<Player, Location>();
private static ConcurrentHashMap<Player, String> playerworld = new ConcurrentHashMap<Player, String>();
private static final ConcurrentHashMap<String, BoosWarmUpTimer> playercommands = new ConcurrentHashMap<>();
private static final ConcurrentHashMap<Player, Location> playerloc = new ConcurrentHashMap<>();
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);
}
/**
* Metoda aplikuje na hr<EFBFBD><EFBFBD>e magick<EFBFBD> efekt na dobu ur<EFBFBD>enou parametrem
* warmUpSeconds.
*
* @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 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 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();
}
}
}
/**
* Metoda stornuje ve<EFBFBD>ker<EFBFBD> prob<EFBFBD>haj<EFBFBD>c<EFBFBD> warmup <EFBFBD>asova<EFBFBD>e specifick<EFBFBD>ho hr<EFBFBD><EFBFBD>e.
*
* @param player
* 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 void clearLocWorld(Player player) {
BoosWarmUpManager.playerloc.remove(player);
BoosWarmUpManager.playerworld.remove(player);
}
/**
* Metoda pro specifick<EFBFBD>ho hr<EFBFBD><EFBFBD>e vyma<EFBFBD>e ulo<EFBFBD>enou pozici a sv<EFBFBD>t.
*
* @param player
* specifick<EFBFBD> hr<EFBFBD><EFBFBD>
*/
public static void clearLocWorld(Player player) {
BoosWarmUpManager.playerloc.remove(player);
BoosWarmUpManager.playerworld.remove(player);
}
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;
}
/**
* Metoda vrac<EFBFBD> boolean hodnotu v z<EFBFBD>vislosti na tom jestli specifikovan<EFBFBD>
* hr<EFBFBD><EFBFBD> m<EFBFBD> aktivn<EFBFBD> warmup <EFBFBD>asova<EFBFBD>e nebo ne.
*
* @param player
* specifick<EFBFBD> hr<EFBFBD><EFBFBD>
* @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 checkWarmUpOK(Player player, String regexCommand) {
int pre2 = regexCommand.toLowerCase().hashCode();
int ok = 0;
ok = BoosConfigManager.getConfusers().getInt(
"users." + player.getUniqueId() + ".warmup." + pre2, ok);
return ok == 1;
}
/**
* Metoda zji<EFBFBD><EFBFBD>uje, jestli je dan<EFBFBD> warmup <EFBFBD>asova<EFBFBD> ozna<EFBFBD>en<EFBFBD> jako ji<EFBFBD> prob<EFBFBD>hl<EFBFBD>
* nebo ne.
*
* @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;
}
static boolean isWarmUpProcess(Player player, String regexCommand) {
regexCommand = regexCommand.toLowerCase();
return playercommands.containsKey(player.getUniqueId() + "@"
+ regexCommand);
}
/**
* Metoda vrac<EFBFBD> boolean hodnotu na z<EFBFBD>klad<EFBFBD> toho jestli je pro specifikovan<EFBFBD>
* p<EFBFBD><EFBFBD>kaz specifikovan<EFBFBD>ho hr<EFBFBD><EFBFBD>e aktivn<EFBFBD> warmup <EFBFBD>asova<EFBFBD>.
*
* @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> aktivn<EFBFBD>, jinak false
*/
static boolean isWarmUpProcess(Player player, String regexCommand) {
regexCommand = regexCommand.toLowerCase();
if (playercommands.containsKey(player.getUniqueId() + "@"
+ regexCommand)) {
return true;
}
return false;
}
private static void killTimer(Player player) {
Map<String, BoosWarmUpTimer> playercommands2 = playercommands;
for (String key : playercommands2.keySet()) {
if (key.startsWith(player.getUniqueId() + "@")) {
playercommands.get(key).cancel();
}
}
}
/**
* Metoda odstran<EFBFBD> v<EFBFBD>echny <EFBFBD>asova<EFBFBD>e specifikovan<EFBFBD>ho hr<EFBFBD><EFBFBD>e
*
* @param player
* 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 removeWarmUp(Player player, String regexCommand) {
int pre2 = regexCommand.toLowerCase().hashCode();
BoosConfigManager.getConfusers().set(
"users." + player.getUniqueId() + ".warmup." + pre2, null);
}
/**
* Metoda odstran<EFBFBD> <EFBFBD>asova<EFBFBD>e na specifikovan<EFBFBD>m p<EFBFBD><EFBFBD>kazu 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 removeWarmUp(Player player, String regexCommand) {
int pre2 = regexCommand.toLowerCase().hashCode();
BoosConfigManager.getConfusers().set(
"users." + player.getUniqueId() + ".warmup." + pre2, null);
}
static void removeWarmUpOK(Player player, String regexCommand) {
int pre2 = regexCommand.toLowerCase().hashCode();
BoosConfigManager.getConfusers().set(
"users." + player.getUniqueId() + ".warmup." + pre2, null);
}
/**
* Metoda odstran<EFBFBD> ukon<EFBFBD>en<EFBFBD> <EFBFBD>asova<EFBFBD>e na specifikovan<EFBFBD>m p<EFBFBD><EFBFBD>kazu
* 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 removeWarmUpProcess(String tag) {
BoosWarmUpManager.playercommands.remove(tag);
}
/**
* Metoda odstra<EFBFBD>uje dan<EFBFBD> <EFBFBD>et<EFBFBD>zec z Hashmapy
*
* @param tag
* <EFBFBD>et<EFBFBD>zec, kter<EFBFBD> se m<EFBFBD> odstranit z Hasmapy
*/
static void removeWarmUpProcess(String tag) {
BoosWarmUpManager.playercommands.remove(tag);
}
static void setWarmUpOK(Player player, String regexCommand) {
int pre2 = regexCommand.toLowerCase().hashCode();
BoosConfigManager.getConfusers().set(
"users." + player.getUniqueId() + ".warmup." + pre2, 1);
}
/**
* Metoda ozna<EFBFBD>uje warmup <EFBFBD>asova<EFBFBD> specifikovan<EFBFBD>ho p<EFBFBD><EFBFBD>kazu specifikovan<EFBFBD>ho
* hr<EFBFBD><EFBFBD>e jako ji<EFBFBD> ukon<EFBFBD>en<EFBFBD>.
*
* @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 setWarmUpOK(Player player, String regexCommand) {
int pre2 = regexCommand.toLowerCase().hashCode();
BoosConfigManager.getConfusers().set(
"users." + player.getUniqueId() + ".warmup." + pre2, 1);
}
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);
/**
* Metoda spou<EFBFBD>t<EFBFBD> warmup <EFBFBD>asova<EFBFBD> na z<EFBFBD>klad<EFBFBD> parametr<EFBFBD> pomoc<EFBFBD> Timer(). Pokud
* je ji<EFBFBD> warmup aktivn<EFBFBD>, ode<EFBFBD>le hr<EFBFBD><EFBFBD>i zpr<EFBFBD>vu kter<EFBFBD> ho o tom informuje.
*
* @param bCoolDown
* instance t<EFBFBD><EFBFBD>dy BoosCooldown
* @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 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);
Timer scheduler = new Timer();
BoosWarmUpTimer scheduleMe = new BoosWarmUpTimer(bCoolDown, 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);
}
}
scheduler = new Timer();
BoosWarmUpTimer scheduleMe = new BoosWarmUpTimer(bCoolDown,
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, String> getPlayerworld() {
return playerworld;
}
/**
* @return
*/
public static ConcurrentHashMap<Player, String> getPlayerworld() {
return playerworld;
}
/**
* @return
*/
public static ConcurrentHashMap<Player, Location> getPlayerloc() {
return playerloc;
}
public static ConcurrentHashMap<Player, Location> getPlayerloc() {
return playerloc;
}
}

View File

@ -1,82 +1,54 @@
package cz.boosik.boosCooldown;
import java.util.Timer;
import java.util.TimerTask;
import org.bukkit.entity.Player;
/**
* 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 {
import java.util.TimerTask;
private BoosCoolDown bCoolDown;
private Player player;
private String originalCommand;
private String regexCommand;
class BoosWarmUpTimer extends TimerTask {
/**
* @param bCoolDown
* instance t<EFBFBD><EFBFBD>dy BoosCoolDown
* @param timer
* @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;
}
private final BoosCoolDown bCoolDown;
private final Player player;
private final String originalCommand;
private final String regexCommand;
/*
* (non-Javadoc)
*
* @see java.util.TimerTask#run()
*/
@Override
public void run() {
bCoolDown.getServer().getScheduler()
.scheduleSyncDelayedTask(bCoolDown, new boosWarmUpRunnable());
}
public BoosWarmUpTimer(BoosCoolDown bCoolDown, Player player,
String regexCommand, String originalCommand) {
this.bCoolDown = bCoolDown;
this.player = player;
this.regexCommand = regexCommand;
this.originalCommand = originalCommand;
}
public class boosWarmUpRunnable implements Runnable {
/*
* (non-Javadoc)
*
* @see java.lang.Runnable#run()
*/
@Override
public void run() {
if (player.isOnline() && !player.isDead()
&& BoosWarmUpManager.hasWarmUps(player)) {
BoosWarmUpManager.setWarmUpOK(player, regexCommand);
BoosWarmUpManager.removeWarmUpProcess(player.getUniqueId()
+ "@" + regexCommand);
BoosWarmUpManager.clearLocWorld(player);
player.chat(originalCommand);
} else if (player.isOnline() && player.isDead()
&& BoosWarmUpManager.hasWarmUps(player)) {
BoosWarmUpManager.removeWarmUp(player, regexCommand);
BoosWarmUpManager.removeWarmUpProcess(player.getUniqueId()
+ "@" + regexCommand);
BoosWarmUpManager.clearLocWorld(player);
} else if (!player.isOnline()
&& BoosWarmUpManager.hasWarmUps(player)) {
BoosWarmUpManager.removeWarmUp(player, regexCommand);
BoosWarmUpManager.removeWarmUpProcess(player.getUniqueId()
+ "@" + regexCommand);
BoosWarmUpManager.clearLocWorld(player);
}
}
}
@Override
public void run() {
bCoolDown.getServer().getScheduler()
.scheduleSyncDelayedTask(bCoolDown, new boosWarmUpRunnable());
}
private class boosWarmUpRunnable implements Runnable {
@Override
public void run() {
if (player.isOnline() && !player.isDead()
&& BoosWarmUpManager.hasWarmUps(player)) {
BoosWarmUpManager.setWarmUpOK(player, regexCommand);
BoosWarmUpManager.removeWarmUpProcess(player.getUniqueId()
+ "@" + regexCommand);
BoosWarmUpManager.clearLocWorld(player);
player.chat(originalCommand);
} else if (player.isOnline() && player.isDead()
&& BoosWarmUpManager.hasWarmUps(player)) {
BoosWarmUpManager.removeWarmUp(player, regexCommand);
BoosWarmUpManager.removeWarmUpProcess(player.getUniqueId()
+ "@" + regexCommand);
BoosWarmUpManager.clearLocWorld(player);
} else if (!player.isOnline()
&& BoosWarmUpManager.hasWarmUps(player)) {
BoosWarmUpManager.removeWarmUp(player, regexCommand);
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.event.player.PlayerCommandPreprocessEvent;
import util.boosChat;
public class BoosXpCostManager {
private static String msg = "";
class BoosXpCostManager {
static boolean payXPForCommand(Player player, String regexCommand,
String originalCommand, int xpPrice) {
int xp = player.getLevel();
Boolean trans = false;
if (xp >= xpPrice) {
player.setLevel(xp - xpPrice);
trans = true;
}
if (trans) {
msg = String.format(BoosConfigManager.getPaidXPForCommandMessage(),
xpPrice);
msg = msg.replaceAll("&command&", originalCommand);
boosChat.sendMessageToPlayer(player, msg);
return true;
} else {
return false;
}
}
private static boolean payXPForCommand(Player player,
String originalCommand, int xpPrice) {
int xp = player.getLevel();
Boolean trans = false;
if (xp >= xpPrice) {
player.setLevel(xp - xpPrice);
trans = true;
}
if (trans) {
String msg = String.format(BoosConfigManager.getPaidXPForCommandMessage(),
xpPrice);
msg = msg.replaceAll("&command&", originalCommand);
boosChat.sendMessageToPlayer(player, msg);
return true;
} else {
return false;
}
}
static void payXPForCommand(PlayerCommandPreprocessEvent event,
Player player, String regexCommand, String originalCommand,
int xpPrice) {
if (xpPrice > 0) {
if (!player.hasPermission("booscooldowns.noxpcost")
&& !player.hasPermission("booscooldowns.noxpcost."
+ originalCommand)) {
if (payXPForCommand(player, regexCommand, originalCommand,
xpPrice)) {
return;
} else {
BoosCoolDownManager.cancelCooldown(player, regexCommand);
event.setCancelled(true);
return;
}
}
}
}
static void payXPForCommand(PlayerCommandPreprocessEvent event,
Player player, String regexCommand, String originalCommand,
int xpPrice) {
if (xpPrice > 0) {
if (!player.hasPermission("booscooldowns.noxpcost")
&& !player.hasPermission("booscooldowns.noxpcost."
+ originalCommand)) {
if (!payXPForCommand(player, originalCommand,
xpPrice)) {
BoosCoolDownManager.cancelCooldown(player, regexCommand);
event.setCancelled(true);
}
}
}
}
public static boolean has(Player player, int xpPrice) {
if (xpPrice <= 0){
return true;
}
int xp = player.getLevel();
if (xp >= xpPrice) {
return true;
}
return false;
}
public static boolean has(Player player, int xpPrice) {
if (xpPrice <= 0) {
return true;
}
int xp = player.getLevel();
return xp >= xpPrice;
}
}

View File

@ -1,53 +1,30 @@
package cz.boosik.boosCooldown.Listeners;
import cz.boosik.boosCooldown.BoosConfigManager;
import cz.boosik.boosCooldown.BoosWarmUpManager;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageEvent;
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 {
/**
* 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;
import cz.boosik.boosCooldown.BoosConfigManager;
import cz.boosik.boosCooldown.BoosCoolDownManager;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@ -7,88 +9,43 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
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 {
/**
* 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);
}
}
/**
* Na z<EFBFBD>klad<EFBFBD> konfigurace metoda spou<EFBFBD>t<EFBFBD> v<EFBFBD>echny cooldown <EFBFBD>asova<EFBFBD>e
* specifikovan<EFBFBD>ho hr<EFBFBD><EFBFBD>e t<EFBFBD>m <EFBFBD>e spust<EFBFBD> medotu startAllCooldowns();.
*
* @param player
* hr<EFBFBD><EFBFBD>, kter<EFBFBD> spustil ud<EFBFBD>lost PlayerDeathEvent
*/
private void startCooldownsOnDeath(Player player) {
if (player != null) {
if (BoosConfigManager.getStartCooldownsOnDeath()) {
BoosCoolDownManager.startAllCooldowns(player, "");
}
}
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
private void onPlayerDeath(PlayerDeathEvent event) {
Entity entity = event.getEntity();
if (entity != null) {
Player player = (Player) entity;
clearCooldownsOnDeath(player);
clearUsesOnDeath(player);
startCooldownsOnDeath(player);
}
}
/**
* Na z<EFBFBD>klad<EFBFBD> konfigurace a toho jestli hr<EFBFBD><EFBFBD> disponuje opr<EFBFBD>vn<EFBFBD>n<EFBFBD>m
* booscooldowns.clear.uses.death metoda vyma<EFBFBD>e v<EFBFBD>echny z<EFBFBD>znamy o spu<EFBFBD>t<EFBFBD>n<EFBFBD>
* v<EFBFBD>ech p<EFBFBD><EFBFBD>kaz<EFBFBD> specifikovan<EFBFBD>ho hr<EFBFBD><EFBFBD>e t<EFBFBD>m <EFBFBD>e spust<EFBFBD> metodu
* 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 startCooldownsOnDeath(Player player) {
if (player != null) {
if (BoosConfigManager.getStartCooldownsOnDeath()) {
BoosCoolDownManager.startAllCooldowns(player, "");
}
}
}
/**
* Na z<EFBFBD>klad<EFBFBD> konfigurace a toho jestli hr<EFBFBD><EFBFBD> disponuje opr<EFBFBD>vn<EFBFBD>n<EFBFBD>m
* booscooldowns.clear.cooldowns.death metoda vyma<EFBFBD>e v<EFBFBD>echny cooldown
* <EFBFBD>asova<EFBFBD>e v<EFBFBD>ech p<EFBFBD><EFBFBD>kaz<EFBFBD> specifikovan<EFBFBD>ho hr<EFBFBD><EFBFBD>e t<EFBFBD>m <EFBFBD>e spust<EFBFBD> metodu
* clearSomething();.
*
* @param player
* hr<EFBFBD><EFBFBD>, kter<EFBFBD> spustil ud<EFBFBD>lost PlayerDeathEvent
*/
private void clearCooldownsOnDeath(Player player) {
if (player != null
&& player.hasPermission("booscooldowns.clear.cooldowns.death")) {
if (BoosConfigManager.getCleanCooldownsOnDeath()) {
BoosConfigManager.clearSomething("cooldown",
player.getUniqueId());
}
}
}
private void clearUsesOnDeath(Player player) {
if (player != null
&& player.hasPermission("booscooldowns.clear.uses.death")) {
if (BoosConfigManager.getCleanUsesOnDeath()) {
BoosConfigManager.clearSomething("uses", player.getUniqueId());
}
}
}
private void clearCooldownsOnDeath(Player player) {
if (player != null
&& player.hasPermission("booscooldowns.clear.cooldowns.death")) {
if (BoosConfigManager.getCleanCooldownsOnDeath()) {
BoosConfigManager.clearSomething("cooldown",
player.getUniqueId());
}
}
}
}

View File

@ -1,54 +1,31 @@
package cz.boosik.boosCooldown.Listeners;
import cz.boosik.boosCooldown.BoosConfigManager;
import cz.boosik.boosCooldown.BoosWarmUpManager;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerGameModeChangeEvent;
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 {
/**
* 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;
import cz.boosik.boosCooldown.BoosConfigManager;
import cz.boosik.boosCooldown.BoosWarmUpManager;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEvent;
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 {
/**
* 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;
import org.bukkit.Location;
import cz.boosik.boosCooldown.BoosConfigManager;
import cz.boosik.boosCooldown.BoosWarmUpManager;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;
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 {
/**
* 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;
}
private int tempTimer = 0;
return false;
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
private void onPlayerMove(PlayerMoveEvent event) {
private int tempTimer = 0;
/**
* Pokud hráč není null a nedisponuje oprávněním booscooldowns.nocancel.move
* 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();. Metoda
* obsahuje jednoduchý časovač, který zajišťuje, že funkce nebudou prováděny
* při každém volání této metody (20x za vteřinu).
*
* @param event
* událost PlayerMoveEvent
*/
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
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;
}
}
if (tempTimer < 10) {
tempTimer = tempTimer + 1;
} else {
Player player = event.getPlayer();
if (player != null
&& !player.hasPermission("booscooldowns.nocancel.move")) {
if (BoosWarmUpManager.hasWarmUps(player) && (event.getFrom().getX() != event.getTo().getX() || event.getFrom().getZ() != event.getTo().getZ() || event.getFrom().getY() != event.getTo().getY())) {
BoosWarmUpManager.clearLocWorld(player);
boosChat.sendMessageToPlayer(player,
BoosConfigManager.getWarmUpCancelledByMoveMessage());
BoosWarmUpManager.cancelWarmUps(player);
}
}
tempTimer = 0;
}
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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