many things I've forget to commit

This commit is contained in:
Boosik 2015-01-06 11:33:42 +01:00
parent 3d594f2c03
commit ff5075b0e4
9 changed files with 3444 additions and 3117 deletions

147
pom.xml
View File

@ -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 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>

View File

@ -7,6 +7,7 @@ import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.InvalidConfigurationException;
@ -313,9 +314,11 @@ public class BoosConfigManager {
*/
static int getCoolDown(String regexCommand, Player player) {
int coolDown;
String coolDownString = "";
String group = getCommandGroup(player);
coolDown = conf.getInt("commands.groups." + group + "." + regexCommand
+ ".cooldown", 0);
coolDownString = conf.getString("commands.groups." + group + "."
+ regexCommand + ".cooldown", "0");
coolDown = parseTime(coolDownString);
return coolDown;
}
@ -441,26 +444,18 @@ public class BoosConfigManager {
return conf.getBoolean("options.options.limits_enabled", true);
}
/**
* @param pre
* @return
*/
static String getLink(String pre) {
String link = null;
pre = pre.toLowerCase();
link = conf.getString("commands.links.link." + pre, link);
return link;
static Set<String> getAllPlayers() {
ConfigurationSection users = confusers.getConfigurationSection("users");
Set<String> list = users.getKeys(false);
return list;
}
/**
* @param link
* @return
*/
static List<String> getLinkList(String link) {
List<String> linkGroup;
link = link.toLowerCase();
linkGroup = conf.getStringList("commands.links.linkGroups." + link);
return linkGroup;
static List<String> getSharedCooldowns(String pre, Player player) {
List<String> sharedCooldowns;
String group = getCommandGroup(player);
sharedCooldowns = conf.getStringList("commands.groups." + group + "."
+ pre + ".shared_cooldown");
return sharedCooldowns;
}
/**
@ -600,9 +595,11 @@ public class BoosConfigManager {
*/
static int getWarmUp(String regexCommand, Player player) {
int warmUp;
String warmUpString = "";
String group = getCommandGroup(player);
warmUp = conf.getInt("commands.groups." + group + "." + regexCommand
+ ".warmup", 0);
warmUpString = conf.getString("commands.groups." + group + "."
+ regexCommand + ".warmup", "0");
warmUp = parseTime(warmUpString);
return warmUp;
}
@ -764,127 +761,10 @@ public class BoosConfigManager {
} else {
this.confFile = new File(boosCoolDown.getDataFolder(), "config.yml");
this.conf = new YamlConfiguration();
conf.options().copyDefaults(true);
conf.addDefault("options.options.warmups_enabled", true);
conf.addDefault("options.options.cooldowns_enabled", true);
conf.addDefault("options.options.prices_enabled", true);
conf.addDefault("options.options.item_cost_enabled", true);
conf.addDefault("options.options.xp_cost_enabled", true);
conf.addDefault("options.options.limits_enabled", true);
conf.addDefault(
"options.options.auto_save_enabled_CAN_CAUSE_BIG_LAGS",
false);
conf.addDefault("options.options.save_interval_in_minutes", 15);
conf.addDefault("options.options.cancel_warmup_on_damage", false);
conf.addDefault("options.options.cancel_warmup_on_move", false);
conf.addDefault("options.options.cancel_warmup_on_sneak", false);
conf.addDefault("options.options.cancel_warmup_on_sprint", false);
conf.addDefault("options.options.cancel_warmup_on_gamemode_change",
false);
conf.addDefault("options.options.block_interact_during_warmup",
false);
conf.addDefault("options.options.clear_on_restart", false);
conf.addDefault("options.options.clear_uses_on_death", false);
conf.addDefault("options.options.clear_cooldowns_on_death", false);
conf.addDefault("options.options.start_cooldowns_on_death", false);
conf.addDefault("options.options.command_logging", false);
conf.addDefault("options.options.command_signs", false);
conf.addDefault("options.units.seconds", "seconds");
conf.addDefault("options.units.minutes", "minutes");
conf.addDefault("options.units.hours", "hours");
conf.addDefault("options.messages.warmup_cancelled_by_damage",
"&6Warm-ups have been cancelled due to receiving damage.&f");
conf.addDefault("options.messages.warmup_cancelled_by_move",
"&6Warm-ups have been cancelled due to moving.&f");
conf.addDefault("options.messages.warmup_cancelled_by_sprint",
"&6Warm-ups have been cancelled due to sprinting.&f");
conf.addDefault("options.messages.warmup_cancelled_by_sneak",
"&6Warm-ups have been cancelled due to sneaking.&f");
conf.addDefault(
"options.messages.warmup_cancelled_by_gamemode_change",
"&6Warm-ups have been cancelled due to changing gamemode.&f");
conf.addDefault("options.messages.cooling_down",
"&6Wait&e &seconds& &unit&&6 before you can use command&e &command& &6again.&f");
conf.addDefault("options.messages.warming_up",
"&6Wait&e &seconds& &unit&&6 before command&e &command& &6has warmed up.&f");
conf.addDefault("options.messages.warmup_already_started",
"&6Warm-Up process for&e &command& &6has already started.&f");
conf.addDefault("options.messages.paid_error",
"&6An error has occured:&e %s");
conf.addDefault(
"options.messages.insufficient_funds",
"&6You have insufficient funds!&e &command& &6costs &e%s &6but you only have &e%s");
conf.addDefault("options.messages.paid_for_command",
"&6Price of&e &command& &6was&e %s &6and you now have&e %s");
conf.addDefault("options.messages.paid_items_for_command",
"&6Price of&e &command& &6was &e%s");
conf.addDefault("options.messages.paid_xp_for_command",
"&6Price of&e &command& &6was &e%s levels");
conf.addDefault("options.messages.insufficient_items",
"&6You have not enough items!&e &command& &6needs &e%s");
conf.addDefault("options.messages.insufficient_xp",
"&6You have not enough XP!&e &command& &6needs &e%s");
conf.addDefault("options.messages.limit_achieved",
"&6You cannot use this command anymore!&f");
conf.addDefault(
"options.messages.limit_list",
"&6Limit for command &e&command&&6 is &e&limit&&6. You can still use it &e&times&&6 times.&f");
conf.addDefault("options.messages.interact_blocked_during_warmup",
"&6You can't do this when command is warming-up!&f");
conf.addDefault("options.messages.cannot_create_sign",
"&6You are not allowed to create this kind of signs!&f");
conf.addDefault("options.messages.cannot_use_sign",
"&6You are not allowed to use this sign!&f");
}
if (confFile.exists()) {
load();
}
try {
conf.addDefault(
"commands.groups.default./command parameter.cooldown", 2);
conf.addDefault(
"commands.groups.default./commandwithparameters *.cooldown",
5);
conf.addDefault("commands.groups.default./anothercommand.cooldown",
2);
conf.addDefault(
"commands.groups.default./yetanothercommand.warmup", 5);
conf.addDefault("commands.groups.default./yetanothercommand.price",
10.0);
conf.addDefault("commands.groups.default./yetanothercommand.limit",
5);
conf.addDefault(
"commands.groups.default./yetanothercommand.potion",
"WEAKNESS,3");
conf.addDefault("commands.groups.default./test.message",
"You just used /test!");
conf.addDefault("commands.groups.default./test.itemcost",
"STONE,10");
conf.addDefault("commands.groups.default./test.xpcost", 6);
conf.addDefault("commands.groups.default.*.warmup", 1);
conf.addDefault("commands.groups.default.*.cooldown", 1);
conf.addDefault("commands.groups.default.*.price", 0.0);
conf.addDefault("commands.groups.default.*.limit", -1);
conf.addDefault("commands.groups.vip./command *.warmup", 5);
conf.addDefault("commands.links.link./lol", "default");
conf.addDefault("commands.links.link./example", "default");
conf.addDefault("commands.links.link./command", "default");
conf.addDefault("commands.links.link./yourCommandHere",
"yourNameHere");
String[] def = { "/lol", "/example" };
conf.addDefault("commands.links.linkGroups.default",
Arrays.asList(def));
String[] def2 = { "/yourCommandHere", "/someCommand",
"/otherCommand" };
conf.addDefault("commands.links.linkGroups.yourNameHere",
Arrays.asList(def2));
conf.addDefault("commands.aliases./newcommand", "/originalcommand");
conf.addDefault("commands.aliases./new spawn command",
"/original spawn command");
conf.save(confFile);
} catch (IOException e) {
e.printStackTrace();
}
confusersFile = new File(boosCoolDown.getDataFolder(), "users.yml");
confusers = new YamlConfiguration();
if (confusersFile.exists()) {
@ -905,26 +785,26 @@ public class BoosConfigManager {
"options.options.auto_save_enabled_CAN_CAUSE_BIG_LAGS", false);
}
public static String getPaidItemsForCommandMessage() {
static String getPaidItemsForCommandMessage() {
return conf.getString("options.messages.paid_items_for_command",
"&6Price of&e &command& &6was &e%s");
}
public static String getInsufficientItemsMessage() {
static String getInsufficientItemsMessage() {
return conf.getString("options.messages.insufficient_items",
"&6You have not enough items!&e &command& &6needs &e%s");
}
public static boolean getItemCostEnabled() {
static boolean getItemCostEnabled() {
return conf.getBoolean("options.options.item_cost_enabled", true);
}
public static String getPaidXPForCommandMessage() {
static String getPaidXPForCommandMessage() {
return conf.getString("options.messages.paid_xp_for_command",
"&6Price of&e &command& &6was &e%s");
}
public static int getXpPrice(String regexCommand, Player player) {
static int getXpPrice(String regexCommand, Player player) {
int price;
String group = getCommandGroup(player);
price = conf.getInt("commands.groups." + group + "." + regexCommand
@ -932,12 +812,85 @@ public class BoosConfigManager {
return price;
}
public static boolean getXpPriceEnabled() {
static boolean getXpPriceEnabled() {
return conf.getBoolean("options.options.xp_cost_enabled", true);
}
public static String getInsufficientXpMessage() {
static String getInsufficientXpMessage() {
return conf.getString("options.messages.insufficient_xp",
"&6You have not enough XP!&e &command& &6needs &e%s");
}
static String getInvalidCommandSyntaxMessage(Player player) {
return conf
.getString("options.messages.invalid_command_syntax",
"&6You are not allowed to use command syntax /<pluginname>:<command>!");
}
static long getLimitResetDelay(String regexCommand, Player player) {
long limitreset;
String limitResetString = "";
String group = getCommandGroup(player);
limitResetString = conf.getString("commands.groups." + group + "."
+ regexCommand + ".limit_reset_delay", "0");
limitreset = parseTime(limitResetString);
return limitreset;
}
static String getLimitResetMessage() {
return conf
.getString(
"options.messages.limit_reset",
"&6Wait&e &seconds& &unit&&6 before your limit for command&e &command& &6is reset.&f");
}
static void clearSomething2(String co, String uuid, int hashedCommand) {
confusers.set("users." + uuid + "." + co + "." + hashedCommand, 0);
}
static long getLimitResetDelayGlobal(String command) {
long delay = 0;
String delayString = "";
delayString = conf.getString(
"global." + command + ".limit_reset_delay", "0");
delay = parseTime(delayString);
return delay;
}
static Set<String> getLimitResetCommandsGlobal() {
return conf.getConfigurationSection("global").getKeys(false);
}
static int parseTime(String time) {
String[] timeString = time.split(" ", 2);
if (timeString[0].equals("cancel")){
return -65535;
}
int timeNumber = Integer.valueOf(timeString[0]);
int timeMultiplier = 1;
if (timeString.length > 1) {
String timeUnit = timeString[1];
if (timeUnit.equals("minute") || timeUnit.equals("minutes")) {
timeMultiplier = 60;
} else if (timeUnit.equals("hour") || timeUnit.equals("hours")) {
timeMultiplier = 60 * 60;
} else if (timeUnit.equals("day") || timeUnit.equals("days")) {
timeMultiplier = 60 * 60 * 24;
} else if (timeUnit.equals("week") || timeUnit.equals("weeks")) {
timeMultiplier = 60 * 60 * 24 * 7;
} else if (timeUnit.equals("month") || timeUnit.equals("months")) {
timeMultiplier = 60 * 60 * 24 * 30;
} else {
timeMultiplier = 1;
}
}
return timeNumber * timeMultiplier;
}
public static String getLimitResetNowMessage() {
return conf
.getString(
"options.messages.limit_reset_now",
"&6Reseting limits for command&e &command& &6now.&f");
}
}

View File

@ -1,6 +1,10 @@
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;
@ -11,6 +15,8 @@ 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;
@ -49,6 +55,7 @@ public class BoosCoolDown extends JavaPlugin implements Runnable {
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.
@ -163,8 +170,14 @@ public class BoosCoolDown extends JavaPlugin implements Runnable {
}
return true;
}
else if (sender.hasPermission("booscooldowns.globalreset")
&& args[0].equalsIgnoreCase("startglobalreset")) {
BoosLimitManager.setGlobalLimitResetDate();
startLimitResetTimersGlobal();
return true;
}
}
if (args.length == 2) {
else if (args.length == 2) {
String jmeno = args[1];
Player player = Bukkit.getPlayerExact(jmeno);
UUID uuid = player.getUniqueId();
@ -198,7 +211,7 @@ public class BoosCoolDown extends JavaPlugin implements Runnable {
return true;
}
}
if (args.length == 3) {
else if (args.length == 3) {
String jmeno = args[1];
Player player = Bukkit.getPlayerExact(jmeno);
UUID uuid = player.getUniqueId();
@ -233,7 +246,7 @@ public class BoosCoolDown extends JavaPlugin implements Runnable {
}
}
if (args.length == 4) {
else if (args.length == 4) {
if (sender.hasPermission("booscooldowns.set")
&& args[0].equalsIgnoreCase("set")) {
String what = args[1];
@ -260,7 +273,7 @@ public class BoosCoolDown extends JavaPlugin implements Runnable {
}
}
if (args.length == 5) {
else if (args.length == 5) {
if (sender.hasPermission("booscooldowns.set")
&& args[0].equalsIgnoreCase("set")) {
String what = args[1];
@ -287,9 +300,10 @@ public class BoosCoolDown extends JavaPlugin implements Runnable {
}
} else {
boosChat.sendMessageToCommandSender(sender,
"&6[" + pdfFile.getName() + "]&e"
+ " Invalid command or access denied!");
// boosChat.sendMessageToCommandSender(sender,
// "&6[" + pdfFile.getName() + "]&e"
// + " Invalid command or access denied!");
return false;
}
}
return false;
@ -303,7 +317,7 @@ public class BoosCoolDown extends JavaPlugin implements Runnable {
*/
@Override
public void onDisable() {
if (BoosConfigManager.getClearOnRestart() == true) {
if (BoosConfigManager.getClearOnRestart()) {
BoosConfigManager.clear();
log.info("[" + pdfFile.getName() + "]" + " cooldowns cleared!");
} else {
@ -326,6 +340,7 @@ public class BoosCoolDown extends JavaPlugin implements Runnable {
log.info("[" + pdfFile.getName() + "]" + " version "
+ pdfFile.getVersion() + " by " + pdfFile.getAuthors()
+ " is enabled!");
this.saveDefaultConfig();
new BoosConfigManager(this);
BoosConfigManager.load();
BoosConfigManager.loadConfusers();
@ -333,11 +348,13 @@ public class BoosCoolDown extends JavaPlugin implements Runnable {
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();
}
@ -350,6 +367,112 @@ public class BoosCoolDown extends JavaPlugin implements Runnable {
}
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
@ -427,4 +550,11 @@ public class BoosCoolDown extends JavaPlugin implements Runnable {
}
return false;
}
public static BoosCoolDown getInstance() {
if (instance == null) {
instance = new BoosCoolDown();
}
return instance;
}
}

View File

@ -1,7 +1,10 @@
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;
@ -139,12 +142,9 @@ public class BoosCoolDownListener implements Listener {
}
} else {
event.setCancelled(true);
String msg = String.format(BoosConfigManager
.getCommandBlockedMessage());
boosChat.sendMessageToPlayer(player, msg);
}
if (!event.isCancelled()) {
BoosLimitManager.setUses(player, regexCommad, originalCommand);
BoosLimitManager.setUses(player, regexCommad);
if (BoosConfigManager.getCommandLogging()) {
BoosCoolDown.commandLogger(player.getName(), originalCommand);
}
@ -165,6 +165,18 @@ public class BoosCoolDownListener implements Listener {
@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(" +", " ");
@ -188,28 +200,13 @@ public class BoosCoolDownListener implements Listener {
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!");
}
originalCommand = BoosAliasManager.checkCommandAlias(originalCommand,
aliases, player);
event.setMessage(originalCommand);
if (on) {
for (String group : commands) {
String group2 = group.replace("*", ".+");
if (originalCommand.matches("(?i)"+group2)) {
if (originalCommand.matches("(?i)" + group2)) {
regexCommad = group;
if (BoosConfigManager.getWarmupEnabled()) {
warmupTime = BoosConfigManager.getWarmUp(regexCommad,
@ -238,12 +235,15 @@ public class BoosCoolDownListener implements Listener {
break;
}
}
this.checkRestrictions(event, player, regexCommad, originalCommand,
warmupTime, cooldownTime, price, item, count, limit,
xpPrice);
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.");
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;
}
}

View File

@ -50,12 +50,13 @@ public class BoosCoolDownManager {
static boolean cd(Player player, String regexCommand,
String originalCommand, int coolDownSeconds) {
Date lastTime = getTime(player, regexCommand);
String link = BoosConfigManager.getLink(regexCommand);
List<String> linkGroup = BoosConfigManager.getSharedCooldowns(
regexCommand, player);
if (lastTime == null) {
if (link == null) {
if (linkGroup.isEmpty()) {
setTime(player, regexCommand);
} else {
List<String> linkGroup = BoosConfigManager.getLinkList(link);
setTime(player, regexCommand);
for (String a : linkGroup) {
setTime(player, a);
}
@ -68,14 +69,13 @@ public class BoosCoolDownManager {
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;
long waitMinutes = (long) Math.ceil(waitSeconds / 60.0);
long waitHours = (long) Math.ceil(waitMinutes / 60.0);
if (secondsBetween > coolDownSeconds) {
if (link == null) {
if (linkGroup.isEmpty()) {
setTime(player, regexCommand);
} else {
List<String> linkGroup = BoosConfigManager
.getLinkList(link);
setTime(player, regexCommand);
for (String a : linkGroup) {
setTime(player, a);
}
@ -171,8 +171,7 @@ public class BoosCoolDownManager {
int pre2 = regexCommand.toLowerCase().hashCode();
String confTime = "";
confTime = BoosConfigManager.getConfusers().getString(
"users." + player.getName().toLowerCase().hashCode()
+ ".cooldown." + pre2, null);
"users." + player.getUniqueId() + ".cooldown." + pre2, null);
if (confTime != null && !confTime.equals("")) {
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
@ -217,8 +216,8 @@ public class BoosCoolDownManager {
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;
long waitMinutes = (long) Math.ceil(waitSeconds / 60.0);
long waitHours = (long) Math.ceil(waitMinutes / 60.0);
if (secondsBetween > time) {
return true;
} else {
@ -258,11 +257,8 @@ public class BoosCoolDownManager {
*/
static long secondsBetween(Calendar startDate, Calendar endDate) {
long secondsBetween = 0;
while (startDate.before(endDate)) {
startDate.add(Calendar.SECOND, 1);
secondsBetween++;
}
secondsBetween = (endDate.getTimeInMillis() - startDate
.getTimeInMillis()) / 1000;
return secondsBetween;
}
@ -281,9 +277,9 @@ public class BoosCoolDownManager {
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);
BoosConfigManager.getConfusers()
.set("users." + player.getUniqueId() + ".cooldown." + pre2,
currTime);
}
/**

View File

@ -1,5 +1,10 @@
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;
@ -29,7 +34,37 @@ public class BoosLimitManager {
*/
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)) {
@ -37,6 +72,64 @@ public class BoosLimitManager {
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;
}
}
@ -76,8 +169,7 @@ public class BoosLimitManager {
* @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) {
static void setUses(Player player, String regexCommand) {
if (BoosConfigManager.getLimitsEnabled()) {
if (BoosConfigManager.getCommands(player).contains(regexCommand)) {
int regexCommand2 = regexCommand.toLowerCase().hashCode();
@ -85,9 +177,8 @@ public class BoosLimitManager {
uses = uses + 1;
try {
BoosConfigManager.getConfusers().set(
"users."
+ player.getName().toLowerCase().hashCode()
+ ".uses." + regexCommand2, uses);
"users." + player.getUniqueId() + ".uses."
+ regexCommand2, uses);
} catch (IllegalArgumentException e) {
BoosCoolDown
.getLog()
@ -129,4 +220,143 @@ public class BoosLimitManager {
}
}
/**
* Metoda vrac<EFBFBD> sou<EFBFBD>asn<EFBFBD> p<EFBFBD>esn<EFBFBD> datum a <EFBFBD>as.
*
* @return sou<EFBFBD>asn<EFBFBD> <EFBFBD>as a datum
*/
static Date getCurrTime() {
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);
}
}

View File

@ -232,8 +232,8 @@ public class BoosWarmUpManager {
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);
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();

View File

@ -313,7 +313,10 @@ public class MetricsLite {
try {
playersOnline = Bukkit.getServer().getOnlinePlayers().size();
} catch (Exception e) {
BoosCoolDown.getLog().warning("[boosCooldowns] This error was caused because you are using old CraftBukkit version. Please update to 1.7.10 (1.7.9-R0.3).");
BoosCoolDown
.getLog()
.warning(
"[boosCooldowns] This error was caused because you are using old CraftBukkit version. Please update to 1.7.10 (1.7.9-R0.3).");
}
// END server software specific section -- all code below does not use

View File

@ -1,6 +1,6 @@
name: boosCooldowns
main: cz.boosik.boosCooldown.BoosCoolDown
version: 3.8.5
version: 3.9.5
authors: [LordBoos (ingame name boosik)]
softdepend: [Vault]
description: >
@ -8,7 +8,7 @@ description: >
commands:
booscooldowns:
description: Reload command.
usage: Use /booscooldowns reload, clearcooldowns <player>, clearwarmups <player> or clearuses <player>
usage: §6[boosCooldowns] §eInvalid command or access denied!
aliases: bcd
permissions:
booscooldowns.exception: