This commit is contained in:
Boosik 2015-03-13 10:00:37 +01:00
parent 4ae0f8711e
commit 020b3ca234
7 changed files with 143 additions and 93 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>cz.boosik</groupId>
<artifactId>boosCooldowns</artifactId>
<version>3.9.8-GIT</version>
<version>3.9.8c-GIT</version>
<name>boosCooldowns</name>
<packaging>jar</packaging>
<url>http://maven.apache.org</url>

View File

@ -78,19 +78,14 @@ public class BoosCoolDownListener implements Listener {
regexCommad, originalCommand, xpPrice);
}
} else {
boolean warmupInProgress = BoosWarmUpManager.isWarmUpProcess(player, regexCommad);
boolean cooldownInProgress = BoosCoolDownManager.isCoolingdown(player,regexCommad,cooldownTime);
if (!BoosPriceManager.has(player, price)
& !BoosWarmUpManager.isWarmUpProcess(player,
regexCommad)) {
String unit;
&& !warmupInProgress && !cooldownInProgress) {
String msg = "";
if (price == 1) {
unit = BoosCoolDown.getEconomy().currencyNameSingular();
} else {
unit = BoosCoolDown.getEconomy().currencyNamePlural();
}
msg = String.format(
BoosConfigManager.getInsufficientFundsMessage(),
(price + " " + unit),
BoosCoolDown.getEconomy().format(price),
BoosCoolDown.getEconomy().format(
BoosCoolDown.getEconomy()
.getBalance(player)));
@ -98,8 +93,7 @@ public class BoosCoolDownListener implements Listener {
boosChat.sendMessageToPlayer(player, msg);
}
if (!BoosItemCostManager.has(player, item, count)
& !BoosWarmUpManager.isWarmUpProcess(player,
regexCommad)) {
&& !warmupInProgress && !cooldownInProgress) {
String msg = "";
msg = String.format(
BoosConfigManager.getInsufficientItemsMessage(),
@ -108,8 +102,7 @@ public class BoosCoolDownListener implements Listener {
boosChat.sendMessageToPlayer(player, msg);
}
if (!BoosXpCostManager.has(player, xpPrice)
& !BoosWarmUpManager.isWarmUpProcess(player,
regexCommad)) {
&& !warmupInProgress && !cooldownInProgress) {
String msg = "";
msg = String.format(
BoosConfigManager.getInsufficientXpMessage(),
@ -155,15 +148,17 @@ public class BoosCoolDownListener implements Listener {
private void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
Player player = event.getPlayer();
UUID uuid = player.getUniqueId();
if (event.getMessage().contains(":")) {
Pattern p = Pattern.compile("^/([a-zA-Z0-9_]+):");
Matcher m = p.matcher(event.getMessage());
if (m.find()) {
{
boosChat.sendMessageToPlayer(player, BoosConfigManager
.getInvalidCommandSyntaxMessage());
event.setCancelled(true);
return;
if (BoosConfigManager.getSyntaxBlocker() && !player.isOp() && !player.hasPermission("booscooldowns.syntaxblockerexception")) {
if (event.getMessage().contains(":")) {
Pattern p = Pattern.compile("^/([a-zA-Z0-9_]+):");
Matcher m = p.matcher(event.getMessage());
if (m.find()) {
{
boosChat.sendMessageToPlayer(player, BoosConfigManager
.getInvalidCommandSyntaxMessage());
event.setCancelled(true);
return;
}
}
}
}
@ -238,7 +233,7 @@ public class BoosCoolDownListener implements Listener {
warmupTime, cooldownTime, price, item, count, limit,
xpPrice);
} else {
if (price > 0 || xpPrice > 0 || count > 0 || limit > 0) {
if ((price > 0 || xpPrice > 0 || count > 0 || limit > 0) && !BoosWarmUpManager.isWarmUpProcess(player, regexCommad) && !BoosCoolDownManager.isCoolingdown(player,regexCommad,cooldownTime)) {
commandQueue.put(uuid + "@" + originalCommand, false);
String questionMessage = BoosConfigManager.getQuestionMessage();
questionMessage = questionMessage.replace("&command&", originalCommand);
@ -247,15 +242,8 @@ public class BoosCoolDownListener implements Listener {
if (BoosConfigManager.getPriceEnabled()) {
if (price > 0) {
String priceMessage = BoosConfigManager.getItsPriceMessage();
if (price > 1) {
priceMessage = priceMessage.replace("&price&", String.valueOf(price))
.replace("&currency&", BoosCoolDown.getEconomy().currencyNamePlural())
.replace("&balance&", String.valueOf(BoosCoolDown.getEconomy().getBalance(player)));
} else {
priceMessage = priceMessage.replace("&price&", String.valueOf(price))
.replace("&currency&", BoosCoolDown.getEconomy().currencyNameSingular())
.replace("&balance&", String.valueOf(BoosCoolDown.getEconomy().getBalance(player)));
}
priceMessage = priceMessage.replace("&price&", BoosCoolDown.getEconomy().format(price))
.replace("&balance&", BoosCoolDown.getEconomy().format(BoosCoolDown.getEconomy().getBalance(player)));
boosChat.sendMessageToPlayer(player, " " + priceMessage);
}
}
@ -282,14 +270,16 @@ public class BoosCoolDownListener implements Listener {
event.setCancelled(true);
return;
} else {
commandQueue.put(player.getUniqueId() + "@" + originalCommand, true);
this.checkRestrictions(event, player, regexCommad, originalCommand,
warmupTime, cooldownTime, price, item, count, limit,
xpPrice);
}
}
}
originalCommand = originalCommand.replace("SdollarS", "$");
event.setMessage(originalCommand);
}
@EventHandler(priority = EventPriority.NORMAL)
private void onPlayerChatEvent(AsyncPlayerChatEvent event){
Player player = event.getPlayer();

View File

@ -679,7 +679,7 @@ public class BoosConfigManager {
public static String getItsPriceMessage() {
return conf.getString("options.messages.confirmation_price_of_command",
"&6its price is&e &price& &currency& &6and you now have &e&balance& &currency&");
"&6its price is&e &price& &6and you now have &e&balance&");
}
public static String getQuestionMessage() {
@ -706,4 +706,9 @@ public class BoosConfigManager {
return conf.getString("options.messages.confirmation_command_cancelled",
"&6Execution of command&e &command& &6was cancelled");
}
public static boolean getSyntaxBlocker() {
return conf.getBoolean("options.options.syntax_blocker_enabled",
true);
}
}

View File

@ -17,6 +17,22 @@ public class BoosCoolDownManager {
"users." + player.getUniqueId() + ".cooldown." + pre2, null);
}
public static boolean isCoolingdown(Player player, String regexCommand, int time){
Date lastTime = getTime(player, regexCommand);
if (lastTime == null){
return false;
}
Calendar calcurrTime = Calendar.getInstance();
calcurrTime.setTime(getCurrTime());
Calendar callastTime = Calendar.getInstance();
callastTime.setTime(lastTime);
long secondsBetween = secondsBetween(callastTime, calcurrTime);
if ((secondsBetween > time) || secondsBetween == 0){
return false;
}
return true;
}
private static boolean cd(Player player, String regexCommand,
String originalCommand, int coolDownSeconds) {
Date lastTime = getTime(player, regexCommand);
@ -39,8 +55,8 @@ public class BoosCoolDownManager {
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);
long waitMinutes = (long) Math.floor(waitSeconds / 60.0);
long waitHours = (long) Math.floor(waitMinutes / 60.0);
if (secondsBetween > coolDownSeconds) {
if (linkGroup.isEmpty()) {
setTime(player, regexCommand);
@ -53,25 +69,35 @@ public class BoosCoolDownManager {
return false;
} else {
String msg = BoosConfigManager.getCoolDownMessage();
StringBuilder stringBuilder = new StringBuilder();
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());
if (waitSeconds >= 3600) {
stringBuilder.append(Long.toString(waitHours));
stringBuilder.append(" ");
stringBuilder.append(BoosConfigManager.getUnitHoursMessage());
stringBuilder.append(", ");
waitSeconds = waitSeconds - (waitHours * 3600);
}
if (waitSeconds >= 60) {
waitMinutes = waitMinutes - (waitHours * 60);
stringBuilder.append(Long.toString(waitMinutes));
stringBuilder.append(" ");
stringBuilder.append(BoosConfigManager.getUnitMinutesMessage());
stringBuilder.append(", ");
waitSeconds = waitSeconds - (waitMinutes * 60);
}
String secs = Long.toString(waitSeconds);
if (secs.equals("0")) {
secs = "1";
}
stringBuilder.append(secs);
stringBuilder.append(" ");
stringBuilder.append(BoosConfigManager.getUnitSecondsMessage());
msg = msg.replaceAll("&seconds&", stringBuilder.toString());
msg = msg.replaceAll("&unit&", "");
msg = msg.replaceAll(" +", " ");
boosChat.sendMessageToPlayer(player, msg);
return true;
}
@ -133,29 +159,41 @@ public class BoosCoolDownManager {
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);
long waitMinutes = (long) Math.floor(waitSeconds / 60.0);
long waitHours = (long) Math.floor(waitMinutes / 60.0);
if (secondsBetween > time) {
return true;
} else {
String msg = BoosConfigManager.getCoolDownMessage();
StringBuilder stringBuilder = new StringBuilder();
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());
if (waitSeconds >= 3600) {
stringBuilder.append(Long.toString(waitHours));
stringBuilder.append(" ");
stringBuilder.append(BoosConfigManager.getUnitHoursMessage());
stringBuilder.append(", ");
waitSeconds = waitSeconds - (waitHours * 3600);
}
if (waitSeconds >= 60) {
waitMinutes = waitMinutes - (waitHours * 60);
stringBuilder.append(Long.toString(waitMinutes));
stringBuilder.append(" ");
stringBuilder.append(BoosConfigManager.getUnitMinutesMessage());
stringBuilder.append(", ");
waitSeconds = waitSeconds - (waitMinutes * 60);
}
String secs = Long.toString(waitSeconds);
if (secs.equals("0")) {
secs = "1";
}
stringBuilder.append(secs);
stringBuilder.append(" ");
stringBuilder.append(BoosConfigManager.getUnitSecondsMessage());
msg = msg.replaceAll("&seconds&", stringBuilder.toString());
msg = msg.replaceAll("&unit&", "");
msg = msg.replaceAll(" +", " ");
boosChat.sendMessageToPlayer(player, msg);
return false;
}

View File

@ -101,33 +101,49 @@ public class BoosWarmUpManager {
public 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);
int warmUpSecondsTem = warmUpSeconds;
long warmUpMinutes = (long) Math.floor(warmUpSeconds / 60.0);
long warmUpHours = (long) Math.floor(warmUpMinutes / 60.0);
if (!isWarmUpProcess(player, regexCommand)) {
BoosWarmUpManager.removeWarmUpOK(player, regexCommand);
String msg = BoosConfigManager.getWarmUpMessage();
StringBuilder stringBuilder = new StringBuilder();
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());
if (warmUpSeconds >= 3600) {
stringBuilder.append(Long.toString(warmUpHours));
stringBuilder.append(" ");
stringBuilder.append(BoosConfigManager.getUnitHoursMessage());
stringBuilder.append(", ");
warmUpSeconds = (int) (warmUpSeconds - (warmUpHours * 3600));
}
if (warmUpSeconds >= 60) {
warmUpMinutes = warmUpMinutes - (warmUpHours * 60);
stringBuilder.append(Long.toString(warmUpMinutes));
stringBuilder.append(" ");
stringBuilder.append(BoosConfigManager.getUnitMinutesMessage());
stringBuilder.append(", ");
warmUpSeconds = (int) (warmUpSeconds - (warmUpMinutes * 60));
}
String secs = Long.toString(warmUpSeconds);
if (secs.equals("0")) {
secs = "1";
}
stringBuilder.append(secs);
stringBuilder.append(" ");
stringBuilder.append(BoosConfigManager.getUnitSecondsMessage());
msg = msg.replaceAll("&seconds&", stringBuilder.toString());
msg = msg.replaceAll("&unit&", "");
msg = msg.replaceAll(" +", " ");
boosChat.sendMessageToPlayer(player, msg);
Timer scheduler = new Timer();
BoosWarmUpTimer scheduleMe = new BoosWarmUpTimer(bCoolDown, player, regexCommand, originalCommand);
playercommands.put(player.getUniqueId() + "@" + regexCommand,
scheduleMe);
scheduler.schedule(scheduleMe, warmUpSeconds * 1000);
applyPotionEffect(player, regexCommand, warmUpSeconds);
scheduler.schedule(scheduleMe, warmUpSecondsTem * 1000);
applyPotionEffect(player, regexCommand, warmUpSecondsTem);
} else {
String msg = BoosConfigManager.getWarmUpAlreadyStartedMessage();
msg = msg.replaceAll("&command&", originalCommand);

View File

@ -20,6 +20,7 @@ options:
start_cooldowns_on_death: false
command_logging: false
command_signs: false
syntax_blocker_enabled: true
units:
seconds: seconds
minutes: minutes
@ -54,13 +55,13 @@ options:
cannot_create_sign: '&6You are not allowed to create this kind of signs!&f'
cannot_use_sign: '&6You are not allowed to use this sign!&f'
invalid_command_syntax: '&6You are not allowed to use command syntax /<pluginname>:<command>!'
confirmation_cancel_command_execution: 'No'
confirmation_confirm_command_execution: 'Yes'
confirmation_price_of_command: '&6its price is&e &price& &currency& &6and you now have &e&balance& &currency&'
confirmation_message: '&6Would you like to use command&e &command& &6?'
confirmation_price_of_command: '&6its price is&e &price& &6and you now have &e&balance&'
confirmation_item_price_of_command: '&6its price is&e &itemprice& &itemname&'
confirmation_limit_of_command: '&6it is limited to&e &limit& &6uses'
confirmation_limit_of_command: '&6it is limited to&e &limit& &6uses and you can still use it&e &uses& &6times'
confirmation_xp_price_of_command: '&6its price is&e &xpprice& experience levels'
confirmation_confirm_command_execution: 'Yes'
confirmation_cancel_command_execution: 'No'
confirmation_command_cancelled: '&6Execution of command&e &command& &6was cancelled'
commands:
groups:

View File

@ -1,6 +1,6 @@
name: boosCooldowns
main: cz.boosik.boosCooldown.BoosCoolDown
version: 3.9.8-GIT
version: 3.9.8c-GIT
authors: [LordBoos (boosik)]
softdepend: [Vault]
description: >