Confirmations for limited commands, fixed replacing of $ with S

This commit is contained in:
Boosik 2015-02-28 22:44:09 +01:00
parent 614e1434f9
commit 4ae0f8711e
9 changed files with 176 additions and 15 deletions

View File

@ -0,0 +1,13 @@
<component name="libraryTable">
<library name="Maven: net.milkbowl.vault:Vault:1.5.2">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/net/milkbowl/vault/Vault/1.5.2/Vault-1.5.2.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/net/milkbowl/vault/Vault/1.5.2/Vault-1.5.2-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/net/milkbowl/vault/Vault/1.5.2/Vault-1.5.2-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

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

View File

@ -1,25 +1,32 @@
package cz.boosik.boosCooldown;
import cz.boosik.boosCooldown.Managers.*;
import net.milkbowl.vault.economy.Economy;
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.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import util.boosChat;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
class BoosCoolDownListener implements Listener {
public class BoosCoolDownListener implements Listener {
private static BoosCoolDown plugin;
public BoosCoolDownListener(BoosCoolDown instance) {
plugin = instance;
}
public static ConcurrentHashMap<String,Boolean> commandQueue = new ConcurrentHashMap();
private void checkRestrictions(PlayerCommandPreprocessEvent event,
Player player, String regexCommad, String originalCommand,
int warmupTime, int cooldownTime, double price, String item,
@ -137,11 +144,17 @@ class BoosCoolDownListener implements Listener {
BoosCoolDown.commandLogger(player.getName(), originalCommand);
}
}
for (String key : commandQueue.keySet()){
if (key.startsWith(String.valueOf(player.getUniqueId()))){
commandQueue.remove(key);
}
}
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
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());
@ -154,8 +167,22 @@ class BoosCoolDownListener implements Listener {
}
}
}
for (String key : commandQueue.keySet()) {
String[] keyList = key.split("@");
if (keyList[0].equals(String.valueOf(uuid))) {
if (!keyList[1].equals(event.getMessage())){
commandQueue.remove(key);
String commandCancelMessage = BoosConfigManager.getCommandCanceledMessage();
commandCancelMessage = commandCancelMessage.replace("&command&", keyList[1]);
boosChat.sendMessageToPlayer(player, commandCancelMessage);
event.setCancelled(true);
return;
}
}
}
String originalCommand = event.getMessage().replace("\\", "\\\\");
originalCommand = originalCommand.replace("$", "S");
originalCommand = originalCommand.replace("$", "SdollarS");
originalCommand = originalCommand.trim().replaceAll(" +", " ");
String regexCommad = "";
Set<String> aliases = BoosConfigManager.getAliases();
@ -206,12 +233,84 @@ class BoosCoolDownListener implements Listener {
break;
}
}
this.checkRestrictions(event, player, regexCommad, originalCommand,
warmupTime, cooldownTime, price, item, count, limit,
xpPrice);
if (commandQueue.keySet().contains(uuid + "@" + originalCommand) && commandQueue.get(uuid + "@" + originalCommand)) {
this.checkRestrictions(event, player, regexCommad, originalCommand,
warmupTime, cooldownTime, price, item, count, limit,
xpPrice);
} else {
if (price > 0 || xpPrice > 0 || count > 0 || limit > 0) {
commandQueue.put(uuid + "@" + originalCommand, false);
String questionMessage = BoosConfigManager.getQuestionMessage();
questionMessage = questionMessage.replace("&command&", originalCommand);
boosChat.sendMessageToPlayer(player, questionMessage);
if (BoosCoolDown.getEconomy() != null) {
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)));
}
boosChat.sendMessageToPlayer(player, " " + priceMessage);
}
}
}
if (xpPrice > 0) {
String xpMessage = BoosConfigManager.getItsXpPriceMessage();
xpMessage = xpMessage.replace("&xpprice&", String.valueOf(xpPrice));
boosChat.sendMessageToPlayer(player, " " + xpMessage);
}
if (count > 0) {
String itemMessage = BoosConfigManager.getItsItemCostMessage();
itemMessage = itemMessage.replace("&itemprice&", String.valueOf(count)).replace("&itemname&", item);
boosChat.sendMessageToPlayer(player, " " + itemMessage);
}
if (limit > 0) {
int uses = BoosLimitManager.getUses(player, regexCommad);
String limitMessage = BoosConfigManager.getItsLimitMessage();
limitMessage = limitMessage.replace("&limit&", String.valueOf(limit))
.replace("&uses&", String.valueOf(limit - uses));
boosChat.sendMessageToPlayer(player, " " + limitMessage);
}
boosChat.sendMessageToPlayer(player, " &2" + BoosConfigManager.getConfirmCommandMessage());
boosChat.sendMessageToPlayer(player, " &c" + BoosConfigManager.getCancelCommandMessage());
event.setCancelled(true);
return;
} else {
commandQueue.put(player.getUniqueId() + "@" + originalCommand, true);
}
}
}
originalCommand = originalCommand.replace("SdollarS", "$");
event.setMessage(originalCommand);
}
@EventHandler(priority = EventPriority.NORMAL)
private void onPlayerChatEvent(AsyncPlayerChatEvent event){
Player player = event.getPlayer();
UUID uuid = player.getUniqueId();
for(String key : commandQueue.keySet()) {
String[] keyList = key.split("@");
if (keyList[0].equals(String.valueOf(uuid))) {
if (event.getMessage().equalsIgnoreCase(BoosConfigManager.getConfirmCommandMessage())) {
commandQueue.put(key, true);
player.chat(keyList[1]);
event.setCancelled(true);
} else {
commandQueue.remove(key);
String commandCancelMessage = BoosConfigManager.getCommandCanceledMessage();
commandCancelMessage = commandCancelMessage.replace("&command&", keyList[1]);
boosChat.sendMessageToPlayer(player, commandCancelMessage);
event.setCancelled(true);
}
}
}
}
private void start(PlayerCommandPreprocessEvent event, Player player,
String regexCommad, String originalCommand, int warmupTime,
int cooldownTime) {

View File

@ -666,4 +666,44 @@ public class BoosConfigManager {
return conf.getString("commands.groups." + group + "."
+ regexCommad + ".denied_message");
}
public static String getCancelCommandMessage() {
return conf.getString("options.messages.confirmation_cancel_command_execution",
"No");
}
public static String getConfirmCommandMessage() {
return conf.getString("options.messages.confirmation_confirm_command_execution",
"Yes");
}
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&");
}
public static String getQuestionMessage() {
return conf.getString("options.messages.confirmation_message",
"&6Would you like to use command&e &command& &6?");
}
public static String getItsItemCostMessage() {
return conf.getString("options.messages.confirmation_item_price_of_command",
"&6its price is&e &itemprice& &itemname&");
}
public static String getItsLimitMessage() {
return conf.getString("options.messages.confirmation_limit_of_command",
"&6it is limited to&e &limit& &6uses and you can still use it&e &uses& &6times");
}
public static String getItsXpPriceMessage() {
return conf.getString("options.messages.confirmation_xp_price_of_command",
"&6its price is&e &xpprice& experience levels");
}
public static String getCommandCanceledMessage() {
return conf.getString("options.messages.confirmation_command_cancelled",
"&6Execution of command&e &command& &6was cancelled");
}
}

View File

@ -27,11 +27,6 @@ public class BoosItemCostManager {
boosChat.sendMessageToPlayer(player, msg);
return true;
} else {
// msg = String.format(
// BoosConfigManager.getInsufficientItemsMessage(), (count
// + " " + item));
// msg = msg.replaceAll("&command&", originalCommand);
// boosChat.sendMessageToPlayer(player, msg);
return false;
}
}

View File

@ -113,7 +113,7 @@ public class BoosLimitManager {
return false;
}
private static int getUses(Player player, String regexCommand) {
public static int getUses(Player player, String regexCommand) {
int regexCommand2 = regexCommand.toLowerCase().hashCode();
int uses = 0;
uses = BoosConfigManager.getConfusers().getInt(

View File

@ -1,6 +1,7 @@
package cz.boosik.boosCooldown.Runnables;
import cz.boosik.boosCooldown.BoosCoolDown;
import cz.boosik.boosCooldown.BoosCoolDownListener;
import cz.boosik.boosCooldown.Managers.BoosWarmUpManager;
import org.bukkit.entity.Player;
@ -36,6 +37,7 @@ public class BoosWarmUpTimer extends TimerTask {
BoosWarmUpManager.setWarmUpOK(player, regexCommand);
BoosWarmUpManager.removeWarmUpProcess(player.getUniqueId()
+ "@" + regexCommand);
BoosCoolDownListener.commandQueue.put(player.getUniqueId() + "@" + originalCommand, true);
player.chat(originalCommand);
} else if (player.isOnline() && player.isDead()
&& BoosWarmUpManager.hasWarmUps(player)) {

View File

@ -54,12 +54,20 @@ 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_item_price_of_command: '&6its price is&e &itemprice& &itemname&'
confirmation_limit_of_command: '&6it is limited to&e &limit& &6uses'
confirmation_xp_price_of_command: '&6its price is&e &xpprice& experience levels'
confirmation_command_cancelled: '&6Execution of command&e &command& &6was cancelled'
commands:
groups:
default:
/permissionstest:
permission: "nice.permission"
denied_message: You lack required permissions to use this command!
denied_message: '&cYou lack required permissions to use this command!'
/day_command:
limit: 5
shared_limit:
@ -98,6 +106,10 @@ commands:
cooldown: 5
warmup: 1
limit: 10
/testitemcommand:
itemcost: STONE,5
/testxpcommand:
xpcost: 5
vip:
/command *:
warmup: 5

View File

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