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,10 +1,10 @@
package cz.boosik.boosCooldown;
import java.util.Set;
import org.bukkit.entity.Player;
public class BoosAliasManager {
import java.util.Set;
class BoosAliasManager {
public static String checkCommandAlias(String originalCommand,
Set<String> aliases, Player player) {

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,348 +17,44 @@ 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;
/**
* 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);
}
/**
* @return
*/
public static Economy getEconomy() {
return economy;
}
/**
* @return
*/
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;
}
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;
}
}
/*
* (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;
}
}
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;
}
/*
* (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!");
}
/*
* (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);
}
if (BoosConfigManager.getClearOnRestart()) {
BoosConfigManager.clear();
}
try {
MetricsLite metrics = new MetricsLite(this);
metrics.start();
} catch (IOException e) {
// Failed to submit the stats :-(
}
}
static void startLimitResetTimersGlobal() {
private static void startLimitResetTimersGlobal() {
YamlConfiguration confusers = BoosConfigManager.getConfusers();
ConfigurationSection global = confusers
.getConfigurationSection("global");
@ -436,7 +123,7 @@ public class BoosCoolDown extends JavaPlugin implements Runnable {
}
}
static long secondsBetween(Calendar startDate, Calendar endDate,
private static long secondsBetween(Calendar startDate, Calendar endDate,
long limitResetDelay) {
long secondsBetween = 0;
secondsBetween = ((endDate.getTimeInMillis() - startDate
@ -444,12 +131,12 @@ public class BoosCoolDown extends JavaPlugin implements Runnable {
return secondsBetween;
}
static Date getCurrTime() {
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;
Date time;
try {
time = sdf.parse(currTime);
return time;
@ -458,10 +145,10 @@ public class BoosCoolDown extends JavaPlugin implements Runnable {
}
}
static Date getTime(String confTime) {
private static Date getTime(String confTime) {
if (confTime != null && !confTime.equals("")) {
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
Date lastDate = null;
Date lastDate;
try {
lastDate = sdf.parse(confTime);
@ -473,11 +160,242 @@ public class BoosCoolDown extends JavaPlugin implements Runnable {
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 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;
}
@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 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 :-(
}
}
private void registerListeners() {
HandlerList.unregisterAll(this);
pm.registerEvents(new BoosCoolDownListener(this), this);
@ -510,20 +428,11 @@ public class BoosCoolDown extends JavaPlugin implements Runnable {
}
}
/**
* 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();
@ -531,13 +440,6 @@ public class BoosCoolDown extends JavaPlugin implements Runnable {
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()
@ -550,11 +452,4 @@ public class BoosCoolDown extends JavaPlugin implements Runnable {
}
return false;
}
public static BoosCoolDown getInstance() {
if (instance == null) {
instance = new BoosCoolDown();
}
return instance;
}
}

View File

@ -1,58 +1,24 @@
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 {
import java.util.List;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
class BoosCoolDownListener implements Listener {
private static BoosCoolDown plugin;
/**
* @param instance
*/
public BoosCoolDownListener(BoosCoolDown instance) {
plugin = instance;
}
/**
* 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,
@ -146,24 +112,22 @@ public class BoosCoolDownListener implements Listener {
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);
}
}
}
/**
* 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();
@ -173,7 +137,7 @@ public class BoosCoolDownListener implements Listener {
if (m.find()) {
{
boosChat.sendMessageToPlayer(player, BoosConfigManager
.getInvalidCommandSyntaxMessage(player));
.getInvalidCommandSyntaxMessage());
event.setCancelled(true);
return;
}
@ -185,7 +149,7 @@ public class BoosCoolDownListener implements Listener {
String regexCommad = "";
Set<String> aliases = BoosConfigManager.getAliases();
Set<String> commands = BoosConfigManager.getCommands(player);
boolean on = true;
boolean on;
String item = "";
int count = 0;
int warmupTime = 0;
@ -237,24 +201,6 @@ public class BoosCoolDownListener implements Listener {
}
}
/**
* 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) {
@ -264,20 +210,14 @@ public class BoosCoolDownListener implements Listener {
BoosWarmUpManager.startWarmUp(plugin, player, regexCommad,
originalCommand, warmupTime);
event.setCancelled(true);
return;
} else {
event.setCancelled(true);
return;
}
} else {
if (BoosCoolDownManager.coolDown(player, regexCommad,
} else if (BoosCoolDownManager.coolDown(player, regexCommad,
originalCommand, cooldownTime)) {
event.setCancelled(true);
return;
} else {
BoosWarmUpManager.removeWarmUpOK(player, regexCommad);
return;
}
}
}
}

View File

@ -1,53 +1,23 @@
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,
private static boolean cd(Player player, String regexCommand,
String originalCommand, int coolDownSeconds) {
Date lastTime = getTime(player, regexCommand);
List<String> linkGroup = BoosConfigManager.getSharedCooldowns(
@ -108,42 +78,13 @@ public class BoosCoolDownManager {
}
}
/**
* 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;
return time > 0 && !player.hasPermission("booscooldowns.nocooldown") && !player.hasPermission("booscooldowns.nocooldown." + originalCommand) && cd(player, regexCommand, originalCommand, time);
}
/**
* 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() {
private static Date getCurrTime() {
String currTime = "";
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
@ -158,16 +99,7 @@ public class BoosCoolDownManager {
}
}
/**
* 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) {
private static Date getTime(Player player, String regexCommand) {
int pre2 = regexCommand.toLowerCase().hashCode();
String confTime = "";
confTime = BoosConfigManager.getConfusers().getString(
@ -187,21 +119,6 @@ public class BoosCoolDownManager {
return 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();
@ -247,31 +164,14 @@ public class BoosCoolDownManager {
return true;
}
/**
* 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) {
private static long secondsBetween(Calendar startDate, Calendar endDate) {
long secondsBetween = 0;
secondsBetween = (endDate.getTimeInMillis() - startDate
.getTimeInMillis()) / 1000;
return secondsBetween;
}
/**
* 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) {
private static void setTime(Player player, String regexCommand) {
int pre2 = regexCommand.toLowerCase().hashCode();
String currTime = "";
Calendar cal = Calendar.getInstance();
@ -282,13 +182,6 @@ public class BoosCoolDownManager {
currTime);
}
/**
* 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);

View File

@ -2,9 +2,9 @@ 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;

View File

@ -5,39 +5,12 @@ 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) {
private static boolean payItemForCommand(Player player,
String originalCommand, String item, int count) {
Material material = Material.getMaterial(item);
Inventory inventory = player.getInventory();
Boolean trans = false;
@ -47,7 +20,7 @@ public class BoosItemCostManager {
trans = true;
}
if (trans) {
msg = String.format(
String msg = String.format(
BoosConfigManager.getPaidItemsForCommandMessage(), count
+ " " + item);
msg = msg.replaceAll("&command&", originalCommand);
@ -63,38 +36,17 @@ public class BoosItemCostManager {
}
}
/**
* 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 {
if (!payItemForCommand(player, originalCommand,
item, count)) {
BoosCoolDownManager.cancelCooldown(player, regexCommand);
event.setCancelled(true);
return;
}
}
}
@ -109,9 +61,6 @@ public class BoosItemCostManager {
}
Material material = Material.getMaterial(item);
Inventory inventory = player.getInventory();
if (inventory.contains(material, count)) {
return true;
}
return false;
return inventory.contains(material, count);
}
}

View File

@ -1,37 +1,16 @@
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);
@ -65,17 +44,15 @@ public class BoosLimitManager {
}
}
if (player.hasPermission("booscooldowns.nolimit")
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,
long waitSeconds = 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();
@ -100,9 +77,8 @@ public class BoosLimitManager {
} else if (limitResetDelayGlobal > 0) {
if (confTime != null) {
callastTimeGlobal.setTime(confTime);
long secondsBetween = secondsBetween(callastTimeGlobal,
long waitSeconds = 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();
@ -136,18 +112,7 @@ public class BoosLimitManager {
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) {
private static int getUses(Player player, String regexCommand) {
int regexCommand2 = regexCommand.toLowerCase().hashCode();
int uses = 0;
uses = BoosConfigManager.getConfusers().getInt(
@ -156,19 +121,6 @@ public class BoosLimitManager {
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)) {
@ -187,23 +139,10 @@ public class BoosLimitManager {
+ player.getName()
+ " used empty command and caused this error!");
}
} else {
return;
}
}
}
/**
* 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);
@ -220,12 +159,7 @@ public class BoosLimitManager {
}
}
/**
* 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() {
private static Date getCurrTime() {
String currTime = "";
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
@ -240,16 +174,7 @@ public class BoosLimitManager {
}
}
/**
* 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) {
private static Date getTime(Player player, String regexCommand) {
int pre2 = regexCommand.toLowerCase().hashCode();
String confTime = "";
confTime = BoosConfigManager.getConfusers().getString(
@ -269,7 +194,7 @@ public class BoosLimitManager {
return null;
}
static Date getTime(String regexCommand) {
private static Date getTime(String regexCommand) {
String confTime = "";
confTime = BoosConfigManager.getConfusers().getString(
"global." + regexCommand + ".reset", null);
@ -288,16 +213,7 @@ public class BoosLimitManager {
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) {
private static void setTime(Player player, String regexCommand) {
int pre2 = regexCommand.toLowerCase().hashCode();
String currTime = "";
Calendar cal = Calendar.getInstance();
@ -308,15 +224,7 @@ public class BoosLimitManager {
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,
private static long secondsBetween(Calendar startDate, Calendar endDate,
long limitResetDelay) {
long secondsBetween = 0;
secondsBetween = ((startDate.getTimeInMillis() - endDate
@ -351,7 +259,7 @@ public class BoosLimitManager {
BoosConfigManager.loadConfusers();
}
static void setTime(String command) {
private static void setTime(String command) {
String currTime = "";
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");

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) {
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 {
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;
}
}
/**
* 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 {
if (!payForCommand(player, originalCommand, price)) {
BoosCoolDownManager.cancelCooldown(player, regexCommand);
event.setCancelled(true);
return;
}
}
}
}
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);
}
return economy == null || price <= 0 || economy.has(player, price);
}
}

View File

@ -1,45 +1,22 @@
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;
/**
* 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,
private static void applyPotionEffect(Player player, String regexCommand,
int warmUpSeconds) {
String potion = BoosConfigManager.getPotionEffect(regexCommand, player);
if (potion.equals("")) {
@ -56,12 +33,6 @@ public class BoosWarmUpManager {
true);
}
/**
* 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();
@ -73,25 +44,11 @@ public class BoosWarmUpManager {
}
}
/**
* 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);
}
/**
* 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()) {
@ -102,56 +59,21 @@ public class BoosWarmUpManager {
return false;
}
/**
* 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;
return ok == 1;
}
/**
* 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;
return playercommands.containsKey(player.getUniqueId() + "@"
+ regexCommand);
}
/**
* 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) {
private static void killTimer(Player player) {
Map<String, BoosWarmUpTimer> playercommands2 = playercommands;
for (String key : playercommands2.keySet()) {
if (key.startsWith(player.getUniqueId() + "@")) {
@ -160,79 +82,28 @@ public class BoosWarmUpManager {
}
}
/**
* 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);
}
/**
* 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);
}
/**
* 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);
}
/**
* 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);
}
/**
* 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();
@ -257,9 +128,8 @@ public class BoosWarmUpManager {
}
boosChat.sendMessageToPlayer(player, msg);
scheduler = new Timer();
BoosWarmUpTimer scheduleMe = new BoosWarmUpTimer(bCoolDown,
scheduler, player, regexCommand, originalCommand);
Timer scheduler = new Timer();
BoosWarmUpTimer scheduleMe = new BoosWarmUpTimer(bCoolDown, player, regexCommand, originalCommand);
playercommands.put(player.getUniqueId() + "@" + regexCommand,
scheduleMe);
scheduler.schedule(scheduleMe, warmUpSeconds * 1000);
@ -271,16 +141,10 @@ public class BoosWarmUpManager {
}
}
/**
* @return
*/
public static ConcurrentHashMap<Player, String> getPlayerworld() {
return playerworld;
}
/**
* @return
*/
public static ConcurrentHashMap<Player, Location> getPlayerloc() {
return playerloc;
}

View File

@ -1,36 +1,17 @@
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,
private final BoosCoolDown bCoolDown;
private final Player player;
private final String originalCommand;
private final String regexCommand;
public BoosWarmUpTimer(BoosCoolDown bCoolDown, Player player,
String regexCommand, String originalCommand) {
this.bCoolDown = bCoolDown;
this.player = player;
@ -38,23 +19,14 @@ public class BoosWarmUpTimer extends TimerTask {
this.originalCommand = originalCommand;
}
/*
* (non-Javadoc)
*
* @see java.util.TimerTask#run()
*/
@Override
public void run() {
bCoolDown.getServer().getScheduler()
.scheduleSyncDelayedTask(bCoolDown, new boosWarmUpRunnable());
}
public class boosWarmUpRunnable implements Runnable {
/*
* (non-Javadoc)
*
* @see java.lang.Runnable#run()
*/
private class boosWarmUpRunnable implements Runnable {
@Override
public void run() {
if (player.isOnline() && !player.isDead()

View File

@ -2,13 +2,11 @@ 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,
private static boolean payXPForCommand(Player player,
String originalCommand, int xpPrice) {
int xp = player.getLevel();
Boolean trans = false;
@ -17,7 +15,7 @@ public class BoosXpCostManager {
trans = true;
}
if (trans) {
msg = String.format(BoosConfigManager.getPaidXPForCommandMessage(),
String msg = String.format(BoosConfigManager.getPaidXPForCommandMessage(),
xpPrice);
msg = msg.replaceAll("&command&", originalCommand);
boosChat.sendMessageToPlayer(player, msg);
@ -34,26 +32,20 @@ public class BoosXpCostManager {
if (!player.hasPermission("booscooldowns.noxpcost")
&& !player.hasPermission("booscooldowns.noxpcost."
+ originalCommand)) {
if (payXPForCommand(player, regexCommand, originalCommand,
if (!payXPForCommand(player, originalCommand,
xpPrice)) {
return;
} else {
BoosCoolDownManager.cancelCooldown(player, regexCommand);
event.setCancelled(true);
return;
}
}
}
}
public static boolean has(Player player, int xpPrice) {
if (xpPrice <= 0){
if (xpPrice <= 0) {
return true;
}
int xp = player.getLevel();
if (xp >= xpPrice) {
return true;
}
return false;
return xp >= xpPrice;
}
}

View File

@ -1,46 +1,23 @@
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 (!player.hasPermission("booscooldowns.nocancel.damage")) {
if (BoosWarmUpManager.hasWarmUps(player)) {
boosChat.sendMessageToPlayer(player, BoosConfigManager
.getWarmUpCancelledByDamageMessage());

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,32 +9,12 @@ 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) {
if (entity != null) {
Player player = (Player) entity;
clearCooldownsOnDeath(player);
clearUsesOnDeath(player);
@ -40,13 +22,6 @@ public class BoosPlayerDeathListener implements Listener {
}
}
/**
* 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()) {
@ -55,15 +30,6 @@ public class BoosPlayerDeathListener implements Listener {
}
}
/**
* 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")) {
@ -73,15 +39,6 @@ public class BoosPlayerDeathListener implements Listener {
}
}
/**
* 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")) {

View File

@ -1,46 +1,23 @@
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) {
if (entity != null) {
Player player = (Player) entity;
if (player != null
&& !player
if (!player
.hasPermission("booscooldowns.nocancel.gamemodechange")) {
if (BoosWarmUpManager.hasWarmUps(player)) {
boosChat.sendMessageToPlayer(player, BoosConfigManager

View File

@ -1,47 +1,23 @@
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šť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) {
if (entity != null) {
Player player = (Player) entity;
if (player != null
&& !player
if (!player
.hasPermission("booscooldowns.dontblock.interact")) {
if (BoosWarmUpManager.hasWarmUps(player)) {
if (event.getClickedBlock().getType().name()

View File

@ -1,76 +1,27 @@
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;
}
return false;
}
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) {
if (tempTimer < 10) {
tempTimer = tempTimer + 1;
return;
} else {
Player player = event.getPlayer();
if (player != null
&& !player.hasPermission("booscooldowns.nocancel.move")) {
if (BoosWarmUpManager.hasWarmUps(player) && hasMoved(player)) {
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());

View File

@ -1,37 +1,16 @@
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();

View File

@ -1,37 +1,16 @@
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();

View File

@ -1,22 +1,15 @@
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();
@ -30,7 +23,6 @@ public class BoosSignChangeListener implements Listener {
BoosConfigManager.getCannotCreateSignMessage());
event.getBlock().breakNaturally();
event.setCancelled(true);
return;
}
if (line2.equals("server")
&& !player
@ -39,7 +31,6 @@ public class BoosSignChangeListener implements Listener {
BoosConfigManager.getCannotCreateSignMessage());
event.getBlock().breakNaturally();
event.setCancelled(true);
return;
}
}
}

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,28 +10,15 @@ 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;
/**
* @param instance
*/
public BoosSignInteractListener(BoosCoolDown instance) {
plugin = instance;
}
/**
* @param event
*/
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
private void onSignInteract(PlayerInteractEvent event) {
String msg;

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