Improved group handling

This commit is contained in:
Boosik 2013-03-31 08:27:53 +02:00
parent fbb90cec8f
commit 12ff7d5458
8 changed files with 102 additions and 266 deletions

View File

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

View File

@ -105,39 +105,19 @@ public class boosConfigManager {
return conf.getBoolean("options.options.command_logging", false);
}
static int getCoolDown(String pre) {
static int getCoolDown(String pre, Player player) {
int coolDown = 0;
String group = getCoolGrp(player);
pre = pre.toLowerCase();
coolDown = conf.getInt("commands.cooldowns.cooldown." + pre, coolDown);
coolDown = conf.getInt("commands.cooldowns." + group + "." + pre,
coolDown);
return coolDown;
}
public static int getCoolDown2(String pre) {
int coolDown = 0;
pre = pre.toLowerCase();
coolDown = conf.getInt("commands.cooldowns.cooldown2." + pre, coolDown);
return coolDown;
}
public static int getCoolDown3(String pre) {
int coolDown = 0;
pre = pre.toLowerCase();
coolDown = conf.getInt("commands.cooldowns.cooldown3." + pre, coolDown);
return coolDown;
}
public static int getCoolDown4(String pre) {
int coolDown = 0;
pre = pre.toLowerCase();
coolDown = conf.getInt("commands.cooldowns.cooldown4." + pre, coolDown);
return coolDown;
}
public static int getCoolDown5(String pre) {
int coolDown = 0;
pre = pre.toLowerCase();
coolDown = conf.getInt("commands.cooldowns.cooldown5." + pre, coolDown);
return coolDown;
private static Set<String> getCooldownGroups() {
Set<String> groups = conf.getConfigurationSection("commands.cooldowns")
.getKeys(false);
return groups;
}
static String getCoolDownMessage() {
@ -147,30 +127,21 @@ public class boosConfigManager {
"&6Wait&e &seconds& seconds&6 before you can use command&e &command& &6again.&f");
}
public static String getCooldownsGrp(Player player) {
String cooldown;
if (player.hasPermission("booscooldowns.cooldown2")) {
cooldown = "cooldown2";
} else if (player.hasPermission("booscooldowns.cooldown3")) {
cooldown = "cooldown3";
} else if (player.hasPermission("booscooldowns.cooldown4")) {
cooldown = "cooldown4";
} else if (player.hasPermission("booscooldowns.cooldown5")) {
cooldown = "cooldown5";
} else {
cooldown = "cooldown";
}
return cooldown;
public static Set<String> getCooldowns(Player player) {
String cool = getCoolGrp(player);
Set<String> cooldowns = conf.getConfigurationSection(
"commands.cooldowns." + cool).getKeys(false);
return cooldowns;
}
public static Set<String> getCooldownsList(Player player) {
String cool = getCooldownsGrp(player);
boosCoolDown.log.info("Cooldown group: " + cool);
ConfigurationSection cooldownsList;
cooldownsList = conf.getConfigurationSection("commands.cooldowns."
+ cool);
Set<String> cooldowns = cooldownsList.getKeys(false);
return cooldowns;
private static String getCoolGrp(Player player) {
String cool = "cooldown";
for (String group : getCooldownGroups()) {
if (player.hasPermission("booscooldowns." + group)) {
cool = group;
}
}
return cool;
}
public static String getInteractBlockedMessage() {
@ -180,53 +151,26 @@ public class boosConfigManager {
}
public static String getLimGrp(Player player) {
String lim;
if (player.hasPermission("booscooldowns.limit2")) {
lim = "limit2";
} else if (player.hasPermission("booscooldowns.limit3")) {
lim = "limit3";
} else if (player.hasPermission("booscooldowns.limit4")) {
lim = "limit4";
} else if (player.hasPermission("booscooldowns.limit5")) {
lim = "limit5";
} else {
lim = "limit";
String lim = "limit";
for (String group : getLimitGroups()) {
if (player.hasPermission("booscooldowns." + group)) {
lim = group;
}
}
return lim;
}
public static int getLimit(String pre) {
int limit = -1;
pre = pre.toLowerCase();
limit = conf.getInt("commands.limits.limit." + pre, limit);
return limit;
private static Set<String> getLimitGroups() {
Set<String> groups = conf.getConfigurationSection("commands.limits")
.getKeys(false);
return groups;
}
public static int getLimit2(String pre) {
public static int getLimit(String pre, Player player) {
int limit = -1;
String group = getLimGrp(player);
pre = pre.toLowerCase();
limit = conf.getInt("commands.limits.limit2." + pre, limit);
return limit;
}
public static int getLimit3(String pre) {
int limit = -1;
pre = pre.toLowerCase();
limit = conf.getInt("commands.limits.limit3." + pre, limit);
return limit;
}
public static int getLimit4(String pre) {
int limit = -1;
pre = pre.toLowerCase();
limit = conf.getInt("commands.limits.limit4." + pre, limit);
return limit;
}
public static int getLimit5(String pre) {
int limit = -1;
pre = pre.toLowerCase();
limit = conf.getInt("commands.limits.limit5." + pre, limit);
limit = conf.getInt("commands.limits." + group + "." + pre, limit);
return limit;
}
@ -237,11 +181,11 @@ public class boosConfigManager {
"&6Limit for command &e&command&&6 is &e&limit&&6. You can still use it &e&times&&6 times.&f");
}
public static ConfigurationSection getLimits(Player player) {
public static Set<String> getLimits(Player player) {
String lim = getLimGrp(player);
ConfigurationSection uses = conf
.getConfigurationSection("commands.limits." + lim);
return uses;
Set<String> limits = conf.getConfigurationSection(
"commands.limits." + lim).getKeys(false);
return limits;
}
public static boolean getLimitsEnabled() {
@ -272,39 +216,40 @@ public class boosConfigManager {
"Price of &command& was %s and you now have %s");
}
public static double getPrice(String pre) {
double price = 0.0;
public static String getPotionEffect(String pre) {
String effect = null;
pre = pre.toLowerCase();
price = conf.getDouble("commands.prices.price." + pre, price);
effect = conf.getString("commands.warmupPotionEffects.effect." + pre,
effect);
return effect;
}
public static double getPrice(String pre, Player player) {
double price = 0.0;
String group = getPriceGrp(player);
pre = pre.toLowerCase();
price = conf.getDouble("commands.prices." + group + "." + pre, price);
return price;
}
public static double getPrice2(String pre) {
double price = 0.0;
pre = pre.toLowerCase();
price = conf.getDouble("commands.prices.price2." + pre, price);
private static String getPriceGrp(Player player) {
String price = "price";
for (String group : getPriceGroups()) {
if (player.hasPermission("booscooldowns." + group)) {
price = group;
}
}
return price;
}
public static double getPrice3(String pre) {
double price = 0.0;
pre = pre.toLowerCase();
price = conf.getDouble("commands.prices.price3." + pre, price);
return price;
private static Set<String> getPriceGroups() {
Set<String> groups = conf.getConfigurationSection("commands.prices")
.getKeys(false);
return groups;
}
public static double getPrice4(String pre) {
double price = 0.0;
pre = pre.toLowerCase();
price = conf.getDouble("commands.prices.price4." + pre, price);
return price;
}
public static double getPrice5(String pre) {
Double price = 0.0;
pre = pre.toLowerCase();
price = conf.getDouble("commands.prices.price5." + pre, price);
return price;
public static int getSaveInterval() {
return conf.getInt("options.options.save_interval_in_minutes", 15);
}
public static boolean getSignCommands() {
@ -328,38 +273,21 @@ public class boosConfigManager {
return conf.getString("options.units.seconds", "seconds");
}
public static int getWarmUp(String pre) {
int warmUp = -1;
pre = pre.toLowerCase();
warmUp = conf.getInt("commands.warmups.warmup." + pre, warmUp);
return warmUp;
public static String getWarmGrp(Player player) {
String warm = "warmup";
for (String group : getWarmupGroups()) {
if (player.hasPermission("booscooldowns." + group)) {
warm = group;
}
}
return warm;
}
public static int getWarmUp2(String pre) {
public static int getWarmUp(String pre, Player player) {
int warmUp = -1;
String group = getWarmGrp(player);
pre = pre.toLowerCase();
warmUp = conf.getInt("commands.warmups.warmup2." + pre, warmUp);
return warmUp;
}
public static int getWarmUp3(String pre) {
int warmUp = -1;
pre = pre.toLowerCase();
warmUp = conf.getInt("commands.warmups.warmup3." + pre, warmUp);
return warmUp;
}
public static int getWarmUp4(String pre) {
int warmUp = -1;
pre = pre.toLowerCase();
warmUp = conf.getInt("commands.warmups.warmup4." + pre, warmUp);
return warmUp;
}
public static int getWarmUp5(String pre) {
int warmUp = -1;
pre = pre.toLowerCase();
warmUp = conf.getInt("commands.warmups.warmup5." + pre, warmUp);
warmUp = conf.getInt("commands.warmups." + group + "." + pre, warmUp);
return warmUp;
}
@ -378,12 +306,25 @@ public class boosConfigManager {
"&6Warm-ups have been cancelled due to moving.&f");
}
public static Set<String> getWarmupGroups() {
Set<String> groups = conf.getConfigurationSection("commands.warmups")
.getKeys(false);
return groups;
}
static String getWarmUpMessage() {
return conf
.getString("options.messages.warming_up",
"&6Wait&e &seconds& seconds&6 before command&e &command& &6has warmed up.&f");
}
public static Set<String> getWarmups(Player player) {
String warm = getWarmGrp(player);
Set<String> warmups = conf.getConfigurationSection(
"commands.warmups." + warm).getKeys(false);
return warmups;
}
static void load() {
try {
conf.load(confFile);
@ -561,16 +502,4 @@ public class boosConfigManager {
e.printStackTrace();
}
}
public static int getSaveInterval() {
return conf.getInt("options.options.save_interval_in_minutes", 15);
}
public static String getPotionEffect(String pre) {
String effect = null;
pre = pre.toLowerCase();
effect = conf.getString("commands.warmupPotionEffects.effect." + pre,
effect);
return effect;
}
}

View File

@ -34,43 +34,13 @@ public class boosCoolDownListener<a> implements Listener {
if (player.hasPermission("booscooldowns.nolimit")
|| player.hasPermission("booscooldowns.nolimit." + pre)) {
} else {
if (player.hasPermission("booscooldowns.limit2")) {
limit = boosConfigManager.getLimit2(pre);
if (limit == -1) {
return false;
} else if (limit <= uses) {
return true;
}
} else if (player.hasPermission("booscooldowns.limit3")) {
limit = boosConfigManager.getLimit3(pre);
if (limit == -1) {
return false;
} else if (limit <= uses) {
return true;
}
} else if (player.hasPermission("booscooldowns.limit4")) {
limit = boosConfigManager.getLimit4(pre);
if (limit == -1) {
return false;
} else if (limit <= uses) {
return true;
}
} else if (player.hasPermission("booscooldowns.limit5")) {
limit = boosConfigManager.getLimit5(pre);
if (limit == -1) {
return false;
} else if (limit <= uses) {
return true;
}
} else {
limit = boosConfigManager.getLimit(pre);
limit = boosConfigManager.getLimit(pre, player);
if (limit == -1) {
return false;
} else if (limit <= uses) {
return true;
}
}
}
return false;
}
@ -333,61 +303,19 @@ public class boosCoolDownListener<a> implements Listener {
}
private int preCDCheck(Player player, String preSub) {
if (player.hasPermission("booscooldowns.cooldown2")) {
return boosConfigManager.getCoolDown2(preSub);
} else if (player.hasPermission("booscooldowns.cooldown3")) {
return boosConfigManager.getCoolDown3(preSub);
} else if (player.hasPermission("booscooldowns.cooldown4")) {
return boosConfigManager.getCoolDown4(preSub);
} else if (player.hasPermission("booscooldowns.cooldown5")) {
return boosConfigManager.getCoolDown5(preSub);
} else {
return boosConfigManager.getCoolDown(preSub);
}
return boosConfigManager.getCoolDown(preSub, player);
}
private int preLimitCheck(Player player, String preSub) {
if (player.hasPermission("booscooldowns.limit2")) {
return boosConfigManager.getLimit2(preSub);
} else if (player.hasPermission("booscooldowns.limit3")) {
return boosConfigManager.getLimit3(preSub);
} else if (player.hasPermission("booscooldowns.limit4")) {
return boosConfigManager.getLimit4(preSub);
} else if (player.hasPermission("booscooldowns.limit5")) {
return boosConfigManager.getLimit5(preSub);
} else {
return boosConfigManager.getLimit(preSub);
}
return boosConfigManager.getLimit(preSub, player);
}
private double prePriceCheck(Player player, String preSub) {
if (player.hasPermission("booscooldowns.price2")) {
return boosConfigManager.getPrice2(preSub);
} else if (player.hasPermission("booscooldowns.price3")) {
return boosConfigManager.getPrice3(preSub);
} else if (player.hasPermission("booscooldowns.price4")) {
return boosConfigManager.getPrice4(preSub);
} else if (player.hasPermission("booscooldowns.price5")) {
return boosConfigManager.getPrice5(preSub);
} else {
return boosConfigManager.getPrice(preSub);
}
return boosConfigManager.getPrice(preSub, player);
}
private int preSubCheck(Player player, String preSub) {
if (player.hasPermission("booscooldowns.warmup2")) {
return boosConfigManager.getWarmUp2(preSub);
} else if (player.hasPermission("booscooldowns.warmup3")) {
return boosConfigManager.getWarmUp3(preSub);
} else if (player.hasPermission("booscooldowns.warmup4")) {
return boosConfigManager.getWarmUp4(preSub);
} else if (player.hasPermission("booscooldowns.warmup5")) {
return boosConfigManager.getWarmUp5(preSub);
} else {
return boosConfigManager.getWarmUp(preSub);
}
return boosConfigManager.getWarmUp(preSub, player);
}
private void start(PlayerCommandPreprocessEvent event, Player player,

View File

@ -8,6 +8,7 @@ import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Set;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.InvalidConfigurationException;
@ -142,7 +143,7 @@ public class boosCoolDownManager {
static boolean coolDown(Player player, String pre) {
pre = pre.toLowerCase();
int coolDownSeconds = 0;
coolDownSeconds = getCooldownGroup(player, pre, coolDownSeconds);
coolDownSeconds = getCooldownTime(player, pre);
if (coolDownSeconds > 0
&& !player.hasPermission("booscooldowns.nocooldown")
&& !player.hasPermission("booscooldowns.nocooldown." + pre)) {
@ -151,19 +152,8 @@ public class boosCoolDownManager {
return false;
}
private static int getCooldownGroup(Player player, String pre,
int coolDownSeconds) {
if (player.hasPermission("booscooldowns.cooldown2")) {
coolDownSeconds = boosConfigManager.getCoolDown2(pre);
} else if (player.hasPermission("booscooldowns.cooldown3")) {
coolDownSeconds = boosConfigManager.getCoolDown3(pre);
} else if (player.hasPermission("booscooldowns.cooldown4")) {
coolDownSeconds = boosConfigManager.getCoolDown4(pre);
} else if (player.hasPermission("booscooldowns.cooldown5")) {
coolDownSeconds = boosConfigManager.getCoolDown5(pre);
} else {
coolDownSeconds = boosConfigManager.getCoolDown(pre);
}
private static int getCooldownTime(Player player, String pre) {
int coolDownSeconds = boosConfigManager.getCoolDown(pre, player);
return coolDownSeconds;
}
@ -187,24 +177,13 @@ public class boosCoolDownManager {
int limitNum = 0;
int num;
String message;
String lim = boosConfigManager.getLimGrp(player);
ConfigurationSection uses = boosConfigManager.getLimits(player);
Set<String> uses = boosConfigManager.getLimits(player);
if (uses != null) {
for (String key : uses.getKeys(false)) {
for (String key : uses) {
usesNum = confusers.getInt("users."
+ player.getName().toLowerCase().hashCode() + ".uses."
+ key, usesNum);
if (lim.equals("limit")) {
limitNum = boosConfigManager.getLimit(key);
} else if (lim.equals("limit2")) {
limitNum = boosConfigManager.getLimit2(key);
} else if (lim.equals("limit3")) {
limitNum = boosConfigManager.getLimit3(key);
} else if (lim.equals("limit4")) {
limitNum = boosConfigManager.getLimit4(key);
} else if (lim.equals("limit5")) {
limitNum = boosConfigManager.getLimit5(key);
}
limitNum = boosConfigManager.getLimit(key, player);
num = limitNum - usesNum;
if (num < 0) {
num = 0;
@ -253,7 +232,7 @@ public class boosCoolDownManager {
static boolean checkCoolDownOK(Player player, String pre, String message) {
pre = pre.toLowerCase();
int coolDownSeconds = 0;
coolDownSeconds = getCooldownGroup(player, pre, coolDownSeconds);
coolDownSeconds = getCooldownTime(player, pre);
if (coolDownSeconds > 0) {
Date lastTime = getTime(player, pre);
if (lastTime == null) {
@ -389,7 +368,7 @@ public class boosCoolDownManager {
}
public static void startAllCooldowns(Player player) {
for (String a : boosConfigManager.getCooldownsList(player)) {
for (String a : boosConfigManager.getCooldowns(player)) {
coolDown(player, a);
}

View File

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