optimisation

This commit is contained in:
Boosik 2015-01-24 15:22:02 +01:00
parent bd6d6859a6
commit 046df72e38
7 changed files with 342 additions and 327 deletions

View File

@ -111,8 +111,13 @@ public class BoosConfigManager {
* @return
*/
static Set<String> getAliases() {
Set<String> aliases = conf.getConfigurationSection("commands.aliases")
.getKeys(false);
Set<String> aliases = null;
ConfigurationSection aliasesSection = conf
.getConfigurationSection("commands.aliases");
if (aliasesSection != null) {
aliases = conf.getConfigurationSection("commands.aliases").getKeys(
false);
}
return aliases;
}
@ -248,11 +253,14 @@ public class BoosConfigManager {
*/
static String getCommandGroup(Player player) {
String cmdGroup = "default";
for (String group : getCommandGroups()) {
Set<String> groups = getCommandGroups();
if (groups != null) {
for (String group : groups) {
if (player.hasPermission("booscooldowns." + group)) {
cmdGroup = group;
}
}
}
return cmdGroup;
}
@ -260,8 +268,12 @@ public class BoosConfigManager {
* @return
*/
static Set<String> getCommandGroups() {
Set<String> groups = conf.getConfigurationSection("commands.groups")
.getKeys(false);
ConfigurationSection groupsSection = conf
.getConfigurationSection("commands.groups");
Set<String> groups = null;
if (groupsSection != null) {
groups = groupsSection.getKeys(false);
}
return groups;
}
@ -278,8 +290,12 @@ public class BoosConfigManager {
*/
static Set<String> getCommands(Player player) {
String group = getCommandGroup(player);
Set<String> commands = conf.getConfigurationSection(
"commands.groups." + group).getKeys(false);
Set<String> commands = null;
ConfigurationSection commandsSection = conf
.getConfigurationSection("commands.groups." + group);
if (commandsSection != null) {
commands = commandsSection.getKeys(false);
}
return commands;
}
@ -861,7 +877,7 @@ public class BoosConfigManager {
static int parseTime(String time) {
String[] timeString = time.split(" ", 2);
if (timeString[0].equals("cancel")){
if (timeString[0].equals("cancel")) {
return -65535;
}
int timeNumber = Integer.valueOf(timeString[0]);
@ -886,9 +902,7 @@ public class BoosConfigManager {
}
public static String getLimitResetNowMessage() {
return conf
.getString(
"options.messages.limit_reset_now",
return conf.getString("options.messages.limit_reset_now",
"&6Reseting limits for command&e &command& &6now.&f");
}
}

View File

@ -57,8 +57,11 @@ public class BoosCoolDownListener implements Listener {
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,
boolean blocked = false;
if (limit != -1) {
blocked = BoosLimitManager.blocked(player, regexCommad,
originalCommand, limit);
}
if (!blocked) {
if (warmupTime > 0) {
if (!player.hasPermission("booscooldowns.nowarmup")
@ -180,15 +183,7 @@ public class BoosCoolDownListener implements Listener {
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> aliases = BoosConfigManager.getAliases();
Set<String> commands = BoosConfigManager.getCommands(player);
boolean on = true;
String item = "";
@ -199,10 +194,12 @@ public class BoosCoolDownListener implements Listener {
int cooldownTime = 0;
int xpPrice = 0;
on = BoosCoolDown.isPluginOnForPlayer(player);
originalCommand = BoosAliasManager.checkCommandAlias(originalCommand,
aliases, player);
if (aliases != null) {
originalCommand = BoosAliasManager.checkCommandAlias(
originalCommand, aliases, player);
event.setMessage(originalCommand);
if (on) {
}
if (on && commands != null) {
for (String group : commands) {
String group2 = group.replace("*", ".+");
if (originalCommand.matches("(?i)" + group2)) {
@ -237,14 +234,6 @@ public class BoosCoolDownListener implements Listener {
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;
}
}
}

View File

@ -104,6 +104,9 @@ public class BoosItemCostManager {
if (item.equals("")) {
return true;
}
if (count <= 0) {
return true;
}
Material material = Material.getMaterial(item);
Inventory inventory = player.getInventory();
if (inventory.contains(material, count)) {

View File

@ -109,6 +109,8 @@ public class BoosPriceManager {
public static boolean has(Player player, double price) {
if (economy == null) {
return true;
} else if (price <= 0){
return true;
} else {
return economy.has(player, price);
}

View File

@ -1,6 +1,7 @@
package cz.boosik.boosCooldown;
import java.util.Iterator;
import java.util.Map;
import java.util.Timer;
import java.util.concurrent.ConcurrentHashMap;
@ -62,7 +63,8 @@ public class BoosWarmUpManager {
* specifick<EFBFBD> hr<EFBFBD><EFBFBD>
*/
public static void cancelWarmUps(Player player) {
Iterator<String> iter = playercommands.keySet().iterator();
Map<String, BoosWarmUpTimer> playercommands2 = playercommands;
Iterator<String> iter = playercommands2.keySet().iterator();
while (iter.hasNext()) {
if (iter.next().startsWith(player.getUniqueId() + "@")) {
killTimer(player);
@ -91,7 +93,8 @@ public class BoosWarmUpManager {
* @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()) {
Map<String, BoosWarmUpTimer> playercommands2 = playercommands;
for (String key : playercommands2.keySet()) {
if (key.startsWith(player.getUniqueId() + "@")) {
return true;
}
@ -149,7 +152,8 @@ public class BoosWarmUpManager {
* specifick<EFBFBD> hr<EFBFBD><EFBFBD>
*/
static void killTimer(Player player) {
for (String key : playercommands.keySet()) {
Map<String, BoosWarmUpTimer> playercommands2 = playercommands;
for (String key : playercommands2.keySet()) {
if (key.startsWith(player.getUniqueId() + "@")) {
playercommands.get(key).cancel();
}

View File

@ -47,6 +47,9 @@ public class BoosXpCostManager {
}
public static boolean has(Player player, int xpPrice) {
if (xpPrice <= 0){
return true;
}
int xp = player.getLevel();
if (xp >= xpPrice) {
return true;

View File

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