Add option to disable command confirmations

This commit is contained in:
Jakub Kolář 2016-03-12 14:39:54 +01:00
parent 020b3ca234
commit 6779923320
5 changed files with 51 additions and 40 deletions

View File

@ -3,16 +3,16 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>cz.boosik</groupId> <groupId>cz.boosik</groupId>
<artifactId>boosCooldowns</artifactId> <artifactId>boosCooldowns</artifactId>
<version>3.9.8c-GIT</version> <version>3.10.0-GIT</version>
<name>boosCooldowns</name> <name>boosCooldowns</name>
<packaging>jar</packaging> <packaging>jar</packaging>
<url>http://maven.apache.org</url> <url>http://maven.apache.org</url>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<minecraft.version>1.8</minecraft.version> <minecraft.version>1.9</minecraft.version>
<bukkit.version>R0.1</bukkit.version> <bukkit.version>R0.1</bukkit.version>
<bukkit.packet>v1_8_R1</bukkit.packet> <bukkit.packet>v1_9_R1</bukkit.packet>
</properties> </properties>
<pluginRepositories> <pluginRepositories>
<pluginRepository> <pluginRepository>

View File

@ -1,7 +1,6 @@
package cz.boosik.boosCooldown; package cz.boosik.boosCooldown;
import cz.boosik.boosCooldown.Managers.*; import cz.boosik.boosCooldown.Managers.*;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
@ -10,8 +9,8 @@ import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import util.boosChat; import util.boosChat;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@ -25,7 +24,7 @@ public class BoosCoolDownListener implements Listener {
plugin = instance; plugin = instance;
} }
public static ConcurrentHashMap<String,Boolean> commandQueue = new ConcurrentHashMap(); public static Map<String,Boolean> commandQueue = new ConcurrentHashMap();
private void checkRestrictions(PlayerCommandPreprocessEvent event, private void checkRestrictions(PlayerCommandPreprocessEvent event,
Player player, String regexCommad, String originalCommand, Player player, String regexCommad, String originalCommand,
@ -162,16 +161,18 @@ public class BoosCoolDownListener implements Listener {
} }
} }
} }
for (String key : commandQueue.keySet()) { if (BoosConfigManager.getConfirmCommandEnabled()) {
String[] keyList = key.split("@"); for (String key : commandQueue.keySet()) {
if (keyList[0].equals(String.valueOf(uuid))) { String[] keyList = key.split("@");
if (!keyList[1].equals(event.getMessage())){ if (keyList[0].equals(String.valueOf(uuid))) {
commandQueue.remove(key); if (!keyList[1].equals(event.getMessage())) {
String commandCancelMessage = BoosConfigManager.getCommandCanceledMessage(); commandQueue.remove(key);
commandCancelMessage = commandCancelMessage.replace("&command&", keyList[1]); String commandCancelMessage = BoosConfigManager.getCommandCanceledMessage();
boosChat.sendMessageToPlayer(player, commandCancelMessage); commandCancelMessage = commandCancelMessage.replace("&command&", keyList[1]);
event.setCancelled(true); boosChat.sendMessageToPlayer(player, commandCancelMessage);
return; event.setCancelled(true);
return;
}
} }
} }
} }
@ -198,7 +199,7 @@ public class BoosCoolDownListener implements Listener {
} }
if (on && commands != null) { if (on && commands != null) {
for (String group : commands) { for (String group : commands) {
String group2 = group.replace("*", ".+"); String group2 = group.replace("*", ".*");
if (originalCommand.matches("(?i)" + group2)) { if (originalCommand.matches("(?i)" + group2)) {
regexCommad = group; regexCommad = group;
if (BoosConfigManager.getWarmupEnabled()) { if (BoosConfigManager.getWarmupEnabled()) {
@ -228,16 +229,18 @@ public class BoosCoolDownListener implements Listener {
break; break;
} }
} }
if (commandQueue.keySet().contains(uuid + "@" + originalCommand) && commandQueue.get(uuid + "@" + originalCommand)) { if (!BoosConfigManager.getConfirmCommandEnabled() || (commandQueue.keySet().contains(uuid + "@" + originalCommand) && commandQueue.get(uuid + "@" + originalCommand))) {
this.checkRestrictions(event, player, regexCommad, originalCommand, this.checkRestrictions(event, player, regexCommad, originalCommand,
warmupTime, cooldownTime, price, item, count, limit, warmupTime, cooldownTime, price, item, count, limit,
xpPrice); xpPrice);
} else { } else {
if ((price > 0 || xpPrice > 0 || count > 0 || limit > 0) && !BoosWarmUpManager.isWarmUpProcess(player, regexCommad) && !BoosCoolDownManager.isCoolingdown(player,regexCommad,cooldownTime)) { if ((price > 0 || xpPrice > 0 || count > 0 || limit > 0) && !BoosWarmUpManager.isWarmUpProcess(player, regexCommad) && !BoosCoolDownManager.isCoolingdown(player,regexCommad,cooldownTime)) {
commandQueue.put(uuid + "@" + originalCommand, false); if (BoosConfigManager.getConfirmCommandEnabled()) {
String questionMessage = BoosConfigManager.getQuestionMessage(); commandQueue.put(uuid + "@" + originalCommand, false);
questionMessage = questionMessage.replace("&command&", originalCommand); String questionMessage = BoosConfigManager.getQuestionMessage();
boosChat.sendMessageToPlayer(player, questionMessage); questionMessage = questionMessage.replace("&command&", originalCommand);
boosChat.sendMessageToPlayer(player, questionMessage);
}
if (BoosCoolDown.getEconomy() != null) { if (BoosCoolDown.getEconomy() != null) {
if (BoosConfigManager.getPriceEnabled()) { if (BoosConfigManager.getPriceEnabled()) {
if (price > 0) { if (price > 0) {
@ -284,19 +287,21 @@ public class BoosCoolDownListener implements Listener {
private void onPlayerChatEvent(AsyncPlayerChatEvent event){ private void onPlayerChatEvent(AsyncPlayerChatEvent event){
Player player = event.getPlayer(); Player player = event.getPlayer();
UUID uuid = player.getUniqueId(); UUID uuid = player.getUniqueId();
for(String key : commandQueue.keySet()) { if (BoosConfigManager.getConfirmCommandEnabled()) {
String[] keyList = key.split("@"); for (String key : commandQueue.keySet()) {
if (keyList[0].equals(String.valueOf(uuid))) { String[] keyList = key.split("@");
if (event.getMessage().equalsIgnoreCase(BoosConfigManager.getConfirmCommandMessage())) { if (keyList[0].equals(String.valueOf(uuid))) {
commandQueue.put(key, true); if (event.getMessage().equalsIgnoreCase(BoosConfigManager.getConfirmCommandMessage())) {
player.chat(keyList[1]); commandQueue.put(key, true);
event.setCancelled(true); player.chat(keyList[1]);
} else { event.setCancelled(true);
commandQueue.remove(key); } else {
String commandCancelMessage = BoosConfigManager.getCommandCanceledMessage(); commandQueue.remove(key);
commandCancelMessage = commandCancelMessage.replace("&command&", keyList[1]); String commandCancelMessage = BoosConfigManager.getCommandCanceledMessage();
boosChat.sendMessageToPlayer(player, commandCancelMessage); commandCancelMessage = commandCancelMessage.replace("&command&", keyList[1]);
event.setCancelled(true); boosChat.sendMessageToPlayer(player, commandCancelMessage);
event.setCancelled(true);
}
} }
} }
} }

View File

@ -711,4 +711,9 @@ public class BoosConfigManager {
return conf.getBoolean("options.options.syntax_blocker_enabled", return conf.getBoolean("options.options.syntax_blocker_enabled",
true); true);
} }
public static boolean getConfirmCommandEnabled() {
return conf.getBoolean("options.options.command_confirmation",
true);
}
} }

View File

@ -12,6 +12,7 @@ public class BoosItemCostManager {
private static boolean payItemForCommand(Player player, private static boolean payItemForCommand(Player player,
String originalCommand, String item, int count) { String originalCommand, String item, int count) {
Material material = Material.getMaterial(item); Material material = Material.getMaterial(item);
Inventory inventory = player.getInventory(); Inventory inventory = player.getInventory();
Boolean trans = false; Boolean trans = false;
if (inventory.contains(material, count)) { if (inventory.contains(material, count)) {

View File

@ -1,13 +1,13 @@
package util; package util;
import java.util.LinkedList;
import java.util.List;
import java.util.logging.Logger;
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.LinkedList;
import java.util.List;
import java.util.logging.Logger;
@SuppressWarnings("ALL") @SuppressWarnings("ALL")
public class boosChat { public class boosChat {
@ -25,7 +25,7 @@ public class boosChat {
private static String replaceColorCodes(String line) { private static String replaceColorCodes(String line) {
line = replaceTags(line); line = replaceTags(line);
line = line.replaceAll("(&([a-f0-9]))", "\u00A7$2"); line = line.replaceAll("&", "§");
return line; return line;
} }