mirror of
https://github.com/LordBoos/boosCooldowns.git
synced 2025-02-16 12:31:27 +01:00
many things I've forget to commit
This commit is contained in:
parent
3d594f2c03
commit
ff5075b0e4
149
pom.xml
149
pom.xml
@ -1,67 +1,82 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>cz.boosik</groupId>
|
||||
<artifactId>boosCooldowns</artifactId>
|
||||
<version>3.8.5</version>
|
||||
<name>boosCooldowns</name>
|
||||
<packaging>jar</packaging>
|
||||
<url>http://maven.apache.org</url>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
</properties>
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<id>maven2-repository.dev.java.net</id>
|
||||
<name>Java.net Repository for Maven</name>
|
||||
<url>http://download.java.net/maven/2/</url>
|
||||
<layout>default</layout>
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>bukkit-repo</id>
|
||||
<url>http://repo.bukkit.org/content/groups/public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>vault-repo</id>
|
||||
<url>http://nexus.theyeticave.net/content/repositories/pub_releases</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
<version>LATEST</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.milkbowl.vault</groupId>
|
||||
<artifactId>Vault</artifactId>
|
||||
<version>LATEST</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<finalName>boosCooldowns</finalName>
|
||||
<sourceDirectory>${basedir}/src/main/java/</sourceDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<targetPath>.</targetPath>
|
||||
<filtering>true</filtering>
|
||||
<directory>${basedir}/src/main/resources/</directory>
|
||||
<includes>
|
||||
<include>plugin.yml</include>
|
||||
</includes>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.1</version>
|
||||
<configuration>
|
||||
<source>1.7</source>
|
||||
<target>1.7</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>cz.boosik</groupId>
|
||||
<artifactId>boosCooldowns</artifactId>
|
||||
<version>3.9.5</version>
|
||||
<name>boosCooldowns</name>
|
||||
<packaging>jar</packaging>
|
||||
<url>http://maven.apache.org</url>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<minecraft.version>1.8</minecraft.version>
|
||||
<bukkit.version>R0.1</bukkit.version>
|
||||
<bukkit.packet>v1_8_R1</bukkit.packet>
|
||||
</properties>
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<id>maven2-repository.dev.java.net</id>
|
||||
<name>Java.net Repository for Maven</name>
|
||||
<url>http://download.java.net/maven/2/</url>
|
||||
<layout>default</layout>
|
||||
</pluginRepository>
|
||||
<pluginRepository>
|
||||
<id>bukkit-plugins</id>
|
||||
<url>http://repo.bukkit.org/content/groups/public/</url>
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>bukkit-repo</id>
|
||||
<url>http://repo.bukkit.org/content/groups/public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>vault-repo</id>
|
||||
<url>http://nexus.theyeticave.net/content/repositories/pub_releases</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>http://repo.md-5.net/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
<version>${minecraft.version}-${bukkit.version}-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.milkbowl.vault</groupId>
|
||||
<artifactId>Vault</artifactId>
|
||||
<version>LATEST</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<finalName>boosCooldowns</finalName>
|
||||
<sourceDirectory>${basedir}/src/main/java/</sourceDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<targetPath>.</targetPath>
|
||||
<filtering>true</filtering>
|
||||
<directory>${basedir}/src/main/resources/</directory>
|
||||
<includes>
|
||||
<include>plugin.yml</include>
|
||||
<include>config.yml</include>
|
||||
</includes>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.1</version>
|
||||
<configuration>
|
||||
<source>1.7</source>
|
||||
<target>1.7</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,430 +1,560 @@
|
||||
package cz.boosik.boosCooldown;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
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;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
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>
|
||||
*
|
||||
*/
|
||||
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;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
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;
|
||||
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.bukkit.plugin.java.JavaPlugin#onDisable()
|
||||
*/
|
||||
@Override
|
||||
public void onDisable() {
|
||||
if (BoosConfigManager.getClearOnRestart() == true) {
|
||||
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!");
|
||||
new BoosConfigManager(this);
|
||||
BoosConfigManager.load();
|
||||
BoosConfigManager.loadConfusers();
|
||||
pm = getServer().getPluginManager();
|
||||
registerListeners();
|
||||
initializeVault();
|
||||
BukkitScheduler scheduler = this.getServer().getScheduler();
|
||||
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 :-(
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
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 net.milkbowl.vault.Vault;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
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>
|
||||
*
|
||||
*/
|
||||
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;
|
||||
}
|
||||
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() {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
static long secondsBetween(Calendar startDate, Calendar endDate,
|
||||
long limitResetDelay) {
|
||||
long secondsBetween = 0;
|
||||
secondsBetween = ((endDate.getTimeInMillis() - startDate
|
||||
.getTimeInMillis()) / 1000) + limitResetDelay;
|
||||
return secondsBetween;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -1,295 +1,295 @@
|
||||
package cz.boosik.boosCooldown;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* @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,
|
||||
int count, int limit, int xpPrice) {
|
||||
boolean 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);
|
||||
String msg = String.format(BoosConfigManager
|
||||
.getCommandBlockedMessage());
|
||||
boosChat.sendMessageToPlayer(player, msg);
|
||||
}
|
||||
if (!event.isCancelled()) {
|
||||
BoosLimitManager.setUses(player, regexCommad, originalCommand);
|
||||
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();
|
||||
String originalCommand = event.getMessage().replace("\\", "\\\\");
|
||||
originalCommand = originalCommand.replace("$", "S");
|
||||
originalCommand = originalCommand.trim().replaceAll(" +", " ");
|
||||
String regexCommad = "";
|
||||
Set<String> aliases = null;
|
||||
try {
|
||||
aliases = BoosConfigManager.getAliases();
|
||||
} catch (Exception e1) {
|
||||
BoosCoolDown
|
||||
.getLog()
|
||||
.warning(
|
||||
"Aliases section in config.yml is missing! Please delete your config.yml, restart server and set it again!");
|
||||
}
|
||||
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);
|
||||
try {
|
||||
if (aliases.contains(originalCommand)) {
|
||||
originalCommand = BoosConfigManager.getAlias(originalCommand);
|
||||
if (originalCommand.contains("$player")) {
|
||||
originalCommand.replaceAll("$player", player.getName());
|
||||
}
|
||||
if (originalCommand.contains("$world")) {
|
||||
originalCommand.replaceAll("$world", player.getWorld()
|
||||
.getName());
|
||||
}
|
||||
event.setMessage(originalCommand);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
BoosCoolDown
|
||||
.getLog()
|
||||
.warning(
|
||||
"Aliases section in config.yml is missing! Please delete your config.yml, restart server and set it again!");
|
||||
}
|
||||
if (on) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
try {
|
||||
this.checkRestrictions(event, player, regexCommad, originalCommand,
|
||||
warmupTime, cooldownTime, price, item, count, limit,
|
||||
xpPrice);
|
||||
} catch (Exception e) {
|
||||
BoosCoolDown.getLog().warning("[boosCooldowns] Looks like you have deleted some important part of config file (like default group or aliases section. To get rid of this message, you have to restore it.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
package cz.boosik.boosCooldown;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
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;
|
||||
|
||||
/**
|
||||
* @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,
|
||||
int count, int limit, int xpPrice) {
|
||||
boolean 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 = null;
|
||||
try {
|
||||
aliases = BoosConfigManager.getAliases();
|
||||
} catch (Exception e1) {
|
||||
BoosCoolDown
|
||||
.getLog()
|
||||
.warning(
|
||||
"Aliases section in config.yml is missing! Please delete your config.yml, restart server and set it again!");
|
||||
}
|
||||
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);
|
||||
originalCommand = BoosAliasManager.checkCommandAlias(originalCommand,
|
||||
aliases, player);
|
||||
event.setMessage(originalCommand);
|
||||
if (on) {
|
||||
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);
|
||||
try {
|
||||
} catch (Exception e) {
|
||||
BoosCoolDown
|
||||
.getLog()
|
||||
.warning(
|
||||
"[boosCooldowns] Looks like you have deleted some important part of config file (like default group or aliases section. To get rid of this message, you have to restore it.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,304 +1,300 @@
|
||||
package cz.boosik.boosCooldown;
|
||||
|
||||
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);
|
||||
String link = BoosConfigManager.getLink(regexCommand);
|
||||
if (lastTime == null) {
|
||||
if (link == null) {
|
||||
setTime(player, regexCommand);
|
||||
} else {
|
||||
List<String> linkGroup = BoosConfigManager.getLinkList(link);
|
||||
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 = Math.round(waitSeconds / 60) + 1;
|
||||
long waitHours = Math.round(waitMinutes / 60) + 1;
|
||||
if (secondsBetween > coolDownSeconds) {
|
||||
if (link == null) {
|
||||
setTime(player, regexCommand);
|
||||
} else {
|
||||
List<String> linkGroup = BoosConfigManager
|
||||
.getLinkList(link);
|
||||
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 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
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.getName().toLowerCase().hashCode()
|
||||
+ ".cooldown." + pre2, 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 = Math.round(waitSeconds / 60) + 1;
|
||||
long waitHours = Math.round(waitMinutes / 60) + 1;
|
||||
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 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;
|
||||
|
||||
while (startDate.before(endDate)) {
|
||||
startDate.add(Calendar.SECOND, 1);
|
||||
secondsBetween++;
|
||||
}
|
||||
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) {
|
||||
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.getName().toLowerCase().hashCode()
|
||||
+ ".cooldown." + pre2, 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);
|
||||
coolDown(player, a, message, cooldownTime);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
package cz.boosik.boosCooldown;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
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() + ".cooldown." + pre2, 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,132 +1,362 @@
|
||||
package cz.boosik.boosCooldown;
|
||||
|
||||
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> 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) {
|
||||
int uses = getUses(player, regexCommand);
|
||||
if (player.hasPermission("booscooldowns.nolimit")
|
||||
|| player.hasPermission("booscooldowns.nolimit."
|
||||
+ originalCommand)) {
|
||||
} else {
|
||||
if (limit == -1) {
|
||||
return false;
|
||||
} else if (limit <= uses) {
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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,
|
||||
String originalCommand) {
|
||||
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.getName().toLowerCase().hashCode()
|
||||
+ ".uses." + regexCommand2, uses);
|
||||
} catch (IllegalArgumentException e) {
|
||||
BoosCoolDown
|
||||
.getLog()
|
||||
.warning(
|
||||
"Player "
|
||||
+ 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);
|
||||
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("×&", String.valueOf(num));
|
||||
boosChat.sendMessageToPlayer(send, message);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
package cz.boosik.boosCooldown;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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("×&", 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;
|
||||
|
||||
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);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
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(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);
|
||||
}
|
||||
}
|
||||
|
@ -1,283 +1,283 @@
|
||||
package cz.boosik.boosCooldown;
|
||||
|
||||
import java.util.Iterator;
|
||||
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 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,
|
||||
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 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) {
|
||||
Iterator<String> iter = playercommands.keySet().iterator();
|
||||
while (iter.hasNext()) {
|
||||
if (iter.next().startsWith(player.getUniqueId() + "@")) {
|
||||
killTimer(player);
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
for (String key : playercommands.keySet()) {
|
||||
if (key.startsWith(player.getUniqueId() + "@")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
for (String key : playercommands.keySet()) {
|
||||
if (key.startsWith(player.getUniqueId() + "@")) {
|
||||
playercommands.get(key).cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
long warmUpMinutes = Math.round(warmUpSeconds / 60);
|
||||
long warmUpHours = Math.round(warmUpMinutes / 60);
|
||||
if (!isWarmUpProcess(player, regexCommand)) {
|
||||
BoosWarmUpManager.removeWarmUpOK(player, regexCommand);
|
||||
String msg = BoosConfigManager.getWarmUpMessage();
|
||||
msg = msg.replaceAll("&command&", originalCommand);
|
||||
if (warmUpSeconds >= 60 && 3600 >= warmUpSeconds) {
|
||||
msg = msg.replaceAll("&seconds&", Long.toString(warmUpMinutes));
|
||||
msg = msg.replaceAll("&unit&",
|
||||
BoosConfigManager.getUnitMinutesMessage());
|
||||
} else if (warmUpMinutes >= 60) {
|
||||
msg = msg.replaceAll("&seconds&", Long.toString(warmUpHours));
|
||||
msg = msg.replaceAll("&unit&",
|
||||
BoosConfigManager.getUnitHoursMessage());
|
||||
} else {
|
||||
msg = msg.replaceAll("&seconds&", Long.toString(warmUpSeconds));
|
||||
msg = msg.replaceAll("&unit&",
|
||||
BoosConfigManager.getUnitSecondsMessage());
|
||||
}
|
||||
boosChat.sendMessageToPlayer(player, msg);
|
||||
|
||||
scheduler = new Timer();
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public static ConcurrentHashMap<Player, String> getPlayerworld() {
|
||||
return playerworld;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public static ConcurrentHashMap<Player, Location> getPlayerloc() {
|
||||
return playerloc;
|
||||
}
|
||||
}
|
||||
package cz.boosik.boosCooldown;
|
||||
|
||||
import java.util.Iterator;
|
||||
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 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,
|
||||
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 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) {
|
||||
Iterator<String> iter = playercommands.keySet().iterator();
|
||||
while (iter.hasNext()) {
|
||||
if (iter.next().startsWith(player.getUniqueId() + "@")) {
|
||||
killTimer(player);
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
for (String key : playercommands.keySet()) {
|
||||
if (key.startsWith(player.getUniqueId() + "@")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
for (String key : playercommands.keySet()) {
|
||||
if (key.startsWith(player.getUniqueId() + "@")) {
|
||||
playercommands.get(key).cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
long warmUpMinutes = (long) Math.ceil(warmUpSeconds / 60.0);
|
||||
long warmUpHours = (long) Math.ceil(warmUpMinutes / 60.0);
|
||||
if (!isWarmUpProcess(player, regexCommand)) {
|
||||
BoosWarmUpManager.removeWarmUpOK(player, regexCommand);
|
||||
String msg = BoosConfigManager.getWarmUpMessage();
|
||||
msg = msg.replaceAll("&command&", originalCommand);
|
||||
if (warmUpSeconds >= 60 && 3600 >= warmUpSeconds) {
|
||||
msg = msg.replaceAll("&seconds&", Long.toString(warmUpMinutes));
|
||||
msg = msg.replaceAll("&unit&",
|
||||
BoosConfigManager.getUnitMinutesMessage());
|
||||
} else if (warmUpMinutes >= 60) {
|
||||
msg = msg.replaceAll("&seconds&", Long.toString(warmUpHours));
|
||||
msg = msg.replaceAll("&unit&",
|
||||
BoosConfigManager.getUnitHoursMessage());
|
||||
} else {
|
||||
msg = msg.replaceAll("&seconds&", Long.toString(warmUpSeconds));
|
||||
msg = msg.replaceAll("&unit&",
|
||||
BoosConfigManager.getUnitSecondsMessage());
|
||||
}
|
||||
boosChat.sendMessageToPlayer(player, msg);
|
||||
|
||||
scheduler = new Timer();
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public static ConcurrentHashMap<Player, String> getPlayerworld() {
|
||||
return playerworld;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public static ConcurrentHashMap<Player, Location> getPlayerloc() {
|
||||
return playerloc;
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,110 +1,110 @@
|
||||
name: boosCooldowns
|
||||
main: cz.boosik.boosCooldown.BoosCoolDown
|
||||
version: 3.8.5
|
||||
authors: [LordBoos (ingame name boosik)]
|
||||
softdepend: [Vault]
|
||||
description: >
|
||||
Shortcuts
|
||||
commands:
|
||||
booscooldowns:
|
||||
description: Reload command.
|
||||
usage: Use /booscooldowns reload, clearcooldowns <player>, clearwarmups <player> or clearuses <player>
|
||||
aliases: bcd
|
||||
permissions:
|
||||
booscooldowns.exception:
|
||||
description: Player wont be affected by plugin at all (no warmups, no cooldowns, no prices, no limits, no aliases).
|
||||
default: false
|
||||
booscooldowns.norestriction:
|
||||
description: Player wont be affected by restrictions but will be affected by aliases(no warmups, no cooldowns, no prices, no limits).
|
||||
default: false
|
||||
children:
|
||||
booscooldowns.noprice: true
|
||||
booscooldowns.nocooldown: true
|
||||
booscooldowns.nowarmup: true
|
||||
booscooldowns.nolimit: true
|
||||
booscooldowns.noitemcost: true
|
||||
booscooldowns.noxpcost: true
|
||||
booscooldowns.nocancel.move:
|
||||
description: Players warmups will not be canceled by moving, even if it's turned on.
|
||||
default: false
|
||||
booscooldowns.nocancel.damage:
|
||||
description: Players warmups will not be canceled by damage, even if it's turned on.
|
||||
default: false
|
||||
booscooldowns.nocancel.sneak:
|
||||
description: Players warmups will not be canceled by sneaking, even if it's turned on.
|
||||
default: false
|
||||
booscooldowns.nocancel.sprint:
|
||||
description: Players warmups will not be canceled by sprinting, even if it's turned on.
|
||||
default: false
|
||||
booscooldowns.nocancel.gamemodechange:
|
||||
description: Players warmups will not be canceled by changing gamemode, even if it's turned on.
|
||||
default: false
|
||||
booscooldowns.dontblock.interact:
|
||||
description: Players interaction will not be blocked during warmup, even if it's turned on.
|
||||
default: false
|
||||
booscooldowns.noprice:
|
||||
description: Players commands will always be free of charge.
|
||||
default: false
|
||||
booscooldowns.noprice./command:
|
||||
description: Command "/command" will not be affected by price for users with this permission.
|
||||
default: false
|
||||
booscooldowns.noitemcost:
|
||||
description: Players commands will always be free of charge (items).
|
||||
default: false
|
||||
booscooldowns.noitemcost./command:
|
||||
description: Command "/command" will not be affected by item cost for users with this permission.
|
||||
default: false
|
||||
booscooldowns.noxpcost:
|
||||
description: Players commands will always be free of charge (XP).
|
||||
default: false
|
||||
booscooldowns.noxpcost./command:
|
||||
description: Command "/command" will not be affected by xp cost for users with this permission.
|
||||
default: false
|
||||
booscooldowns.nocooldown:
|
||||
description: Player wont be affected by cooldowns.
|
||||
default: false
|
||||
booscooldowns.nocooldown./command:
|
||||
description: Command "/command" will not be affected by cooldown for users with this permission.
|
||||
default: false
|
||||
booscooldowns.nowarmup:
|
||||
description: Player wont be affected by warmups.
|
||||
default: false
|
||||
booscooldowns.nowarmup./command:
|
||||
description: Command "/command" will not be affected by warmup for users with this permission.
|
||||
default: false
|
||||
booscooldowns.nolimit:
|
||||
description: Player wont be affected by limiting.
|
||||
default: false
|
||||
booscooldowns.start.cooldowns.death.exception:
|
||||
description: Player's cooldowns wont be started on death.
|
||||
default: false
|
||||
booscooldowns.nolimit./command:
|
||||
description: Command "/command" will not be affected by limits for users with this permission.
|
||||
default: false
|
||||
booscooldowns.reload:
|
||||
description: Player can use "/booscooldowns reload" to reload config file.
|
||||
default: op
|
||||
booscooldowns.clear.uses.death:
|
||||
description: Players uses (limit-uses=how many times playr can still use command) are cleared on death (must be enabled in config file too!).
|
||||
default: false
|
||||
booscooldowns.clear.cooldowns.death:
|
||||
description: Players cooldowns are cleared on death (must be enabled in config file too!).
|
||||
default: false
|
||||
booscooldowns.list.limits:
|
||||
description: Player can use "/booscooldowns limits" to see limits and how many times he can still use commands.
|
||||
default: true
|
||||
booscooldowns.set:
|
||||
description: Users with this can use "/booscooldowns set" command.
|
||||
default: op
|
||||
booscooldowns.signs.player.use:
|
||||
description: Player can use boosCooldowns signs (marked as player on second line).
|
||||
default: false
|
||||
booscooldowns.signs.server.use:
|
||||
description: Player can use boosCooldowns signs (marked as server on second line).
|
||||
default: false
|
||||
booscooldowns.signs.player.place:
|
||||
description: Player can place/create boosCooldowns signs (marked as player on second line).
|
||||
default: false
|
||||
booscooldowns.signs.server.place:
|
||||
description: Player can place/create boosCooldowns signs (marked as server on second line). !!WARNING!! With this permission, player can create sign with commands that are run as if used from console!
|
||||
name: boosCooldowns
|
||||
main: cz.boosik.boosCooldown.BoosCoolDown
|
||||
version: 3.9.5
|
||||
authors: [LordBoos (ingame name boosik)]
|
||||
softdepend: [Vault]
|
||||
description: >
|
||||
Shortcuts
|
||||
commands:
|
||||
booscooldowns:
|
||||
description: Reload command.
|
||||
usage: §6[boosCooldowns] §eInvalid command or access denied!
|
||||
aliases: bcd
|
||||
permissions:
|
||||
booscooldowns.exception:
|
||||
description: Player wont be affected by plugin at all (no warmups, no cooldowns, no prices, no limits, no aliases).
|
||||
default: false
|
||||
booscooldowns.norestriction:
|
||||
description: Player wont be affected by restrictions but will be affected by aliases(no warmups, no cooldowns, no prices, no limits).
|
||||
default: false
|
||||
children:
|
||||
booscooldowns.noprice: true
|
||||
booscooldowns.nocooldown: true
|
||||
booscooldowns.nowarmup: true
|
||||
booscooldowns.nolimit: true
|
||||
booscooldowns.noitemcost: true
|
||||
booscooldowns.noxpcost: true
|
||||
booscooldowns.nocancel.move:
|
||||
description: Players warmups will not be canceled by moving, even if it's turned on.
|
||||
default: false
|
||||
booscooldowns.nocancel.damage:
|
||||
description: Players warmups will not be canceled by damage, even if it's turned on.
|
||||
default: false
|
||||
booscooldowns.nocancel.sneak:
|
||||
description: Players warmups will not be canceled by sneaking, even if it's turned on.
|
||||
default: false
|
||||
booscooldowns.nocancel.sprint:
|
||||
description: Players warmups will not be canceled by sprinting, even if it's turned on.
|
||||
default: false
|
||||
booscooldowns.nocancel.gamemodechange:
|
||||
description: Players warmups will not be canceled by changing gamemode, even if it's turned on.
|
||||
default: false
|
||||
booscooldowns.dontblock.interact:
|
||||
description: Players interaction will not be blocked during warmup, even if it's turned on.
|
||||
default: false
|
||||
booscooldowns.noprice:
|
||||
description: Players commands will always be free of charge.
|
||||
default: false
|
||||
booscooldowns.noprice./command:
|
||||
description: Command "/command" will not be affected by price for users with this permission.
|
||||
default: false
|
||||
booscooldowns.noitemcost:
|
||||
description: Players commands will always be free of charge (items).
|
||||
default: false
|
||||
booscooldowns.noitemcost./command:
|
||||
description: Command "/command" will not be affected by item cost for users with this permission.
|
||||
default: false
|
||||
booscooldowns.noxpcost:
|
||||
description: Players commands will always be free of charge (XP).
|
||||
default: false
|
||||
booscooldowns.noxpcost./command:
|
||||
description: Command "/command" will not be affected by xp cost for users with this permission.
|
||||
default: false
|
||||
booscooldowns.nocooldown:
|
||||
description: Player wont be affected by cooldowns.
|
||||
default: false
|
||||
booscooldowns.nocooldown./command:
|
||||
description: Command "/command" will not be affected by cooldown for users with this permission.
|
||||
default: false
|
||||
booscooldowns.nowarmup:
|
||||
description: Player wont be affected by warmups.
|
||||
default: false
|
||||
booscooldowns.nowarmup./command:
|
||||
description: Command "/command" will not be affected by warmup for users with this permission.
|
||||
default: false
|
||||
booscooldowns.nolimit:
|
||||
description: Player wont be affected by limiting.
|
||||
default: false
|
||||
booscooldowns.start.cooldowns.death.exception:
|
||||
description: Player's cooldowns wont be started on death.
|
||||
default: false
|
||||
booscooldowns.nolimit./command:
|
||||
description: Command "/command" will not be affected by limits for users with this permission.
|
||||
default: false
|
||||
booscooldowns.reload:
|
||||
description: Player can use "/booscooldowns reload" to reload config file.
|
||||
default: op
|
||||
booscooldowns.clear.uses.death:
|
||||
description: Players uses (limit-uses=how many times playr can still use command) are cleared on death (must be enabled in config file too!).
|
||||
default: false
|
||||
booscooldowns.clear.cooldowns.death:
|
||||
description: Players cooldowns are cleared on death (must be enabled in config file too!).
|
||||
default: false
|
||||
booscooldowns.list.limits:
|
||||
description: Player can use "/booscooldowns limits" to see limits and how many times he can still use commands.
|
||||
default: true
|
||||
booscooldowns.set:
|
||||
description: Users with this can use "/booscooldowns set" command.
|
||||
default: op
|
||||
booscooldowns.signs.player.use:
|
||||
description: Player can use boosCooldowns signs (marked as player on second line).
|
||||
default: false
|
||||
booscooldowns.signs.server.use:
|
||||
description: Player can use boosCooldowns signs (marked as server on second line).
|
||||
default: false
|
||||
booscooldowns.signs.player.place:
|
||||
description: Player can place/create boosCooldowns signs (marked as player on second line).
|
||||
default: false
|
||||
booscooldowns.signs.server.place:
|
||||
description: Player can place/create boosCooldowns signs (marked as server on second line). !!WARNING!! With this permission, player can create sign with commands that are run as if used from console!
|
||||
default: false
|
Loading…
Reference in New Issue
Block a user