updated metrics, added option to disable limits (and logging

to users.yml)
This commit is contained in:
Boosik 2013-01-01 15:57:15 +01:00
parent 2dabe6e7ac
commit 304cbed516
21 changed files with 697 additions and 571 deletions

View File

@ -2,7 +2,7 @@
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="C:/Users/Boos/Desktop/Mineplanet/plugins/Vault.jar"/>
<classpathentry kind="lib" path="C:/Users/Boos/Desktop/Mineplanet/bukkit-1.3.1-R2.0.jar"/>
<classpathentry kind="lib" path="C:/Users/Jakub/workspace/bukkit-1.4.6-R0.1.jar"/>
<classpathentry kind="lib" path="D:/Downloads/df/Vault.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

Binary file not shown.

Binary file not shown.

View File

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

Binary file not shown.

View File

@ -17,7 +17,8 @@ public class boosConfigManager {
private static YamlConfiguration conf;
private static File confFile;
static List<String> players = new LinkedList<String>();
//test
// test
@SuppressWarnings("static-access")
public boosConfigManager(boosCoolDown boosCoolDown) {
confFile = new File(boosCoolDown.getDataFolder(), "config.yml");
@ -49,6 +50,7 @@ public class boosConfigManager {
conf.addDefault("options.options.clear_cooldowns_on_death", false);
conf.addDefault("options.options.command_logging", false);
conf.addDefault("options.options.command_signs", false);
conf.addDefault("options.options.enable_limits", true);
conf.addDefault("options.units.seconds", "seconds");
conf.addDefault("options.units.minutes", "minutes");
conf.addDefault("options.units.hours", "hours");
@ -75,7 +77,8 @@ public class boosConfigManager {
"&6Price of&e &command& &6was&e %s &6and you now have&e %s");
conf.addDefault("options.messages.limit_achieved",
"&6You cannot use this command anymore!&f");
conf.addDefault("options.messages.limit_list",
conf.addDefault(
"options.messages.limit_list",
"&6Limit for command &e&command&&6 is &e&limit&&6. You can still use it &e&times&&6 times.&f");
conf.addDefault("options.messages.interact_blocked_during_warmup",
"&6You can't do this when command is warming-up!&f");
@ -133,7 +136,8 @@ public class boosConfigManager {
conf.addDefault("commands.links.linkGroups.yourNameHere",
Arrays.asList(def2));
conf.addDefault("commands.aliases./newcommand", "/originalcommand");
conf.addDefault("commands.aliases./new spawn command", "/original spawn command");
conf.addDefault("commands.aliases./new spawn command",
"/original spawn command");
conf.save(confFile);
} catch (IOException e) {
e.printStackTrace();
@ -191,24 +195,24 @@ public class boosConfigManager {
coolDown = conf.getInt("commands.cooldowns.cooldown5." + pre, coolDown);
return coolDown;
}
static void setAddToConfigFile(String coSetnout, String co, int hodnota) {
co = co.toLowerCase();
coSetnout = coSetnout.toLowerCase();
String sekce = null;
if (coSetnout.contains("cooldown")){
if (coSetnout.contains("cooldown")) {
sekce = "cooldowns";
} else if (coSetnout.contains("warmup")){
} else if (coSetnout.contains("warmup")) {
sekce = "warmups";
} else if (coSetnout.contains("limit")){
} else if (coSetnout.contains("limit")) {
sekce = "limits";
} else if (coSetnout.contains("price")){
} else if (coSetnout.contains("price")) {
sekce = "prices";
} else {
return;
}
reload();
conf.set("commands."+sekce+"."+coSetnout+"." + co, hodnota);
conf.set("commands." + sekce + "." + coSetnout + "." + co, hodnota);
try {
conf.save(confFile);
} catch (IOException e) {
@ -457,52 +461,49 @@ public class boosConfigManager {
return conf.getBoolean("options.options.clear_cooldowns_on_death",
false);
}
public static String getLimitListMessage(){
return conf.getString("options.messages.limit_list",
"&6Limit for command &e&command&&6 is &e&limit&&6. You can still use it &e&times&&6 times.&f");
public static String getLimitListMessage() {
return conf
.getString(
"options.messages.limit_list",
"&6Limit for command &e&command&&6 is &e&limit&&6. You can still use it &e&times&&6 times.&f");
}
public static String getLimGrp(Player player){
String lim;
if (player.hasPermission(
"booscooldowns.limit2")) {
public static String getLimGrp(Player player) {
String lim;
if (player.hasPermission("booscooldowns.limit2")) {
lim = "limit2";
} else if (player.hasPermission(
"booscooldowns.limit3")) {
} else if (player.hasPermission("booscooldowns.limit3")) {
lim = "limit3";
} else if (player.hasPermission(
"booscooldowns.limit4")) {
} else if (player.hasPermission("booscooldowns.limit4")) {
lim = "limit4";
} else if (player.hasPermission(
"booscooldowns.limit5")) {
} else if (player.hasPermission("booscooldowns.limit5")) {
lim = "limit5";
} else {
lim = "limit";
}
return lim;
return lim;
}
public static ConfigurationSection getLimits(Player player){
public static ConfigurationSection getLimits(Player player) {
String lim = getLimGrp(player);
ConfigurationSection uses = conf
.getConfigurationSection("commands.limits." + lim);
return uses;
ConfigurationSection uses = conf
.getConfigurationSection("commands.limits." + lim);
return uses;
}
public static ConfigurationSection getAliases(){
public static ConfigurationSection getAliases() {
ConfigurationSection aliases = conf
.getConfigurationSection("commands.aliases");
return aliases;
}
public static String getAlias(String message){
public static String getAlias(String message) {
return conf.getString("commands.aliases." + message);
}
public static boolean getSignCommands() {
return conf.getBoolean("options.options.command_signs",
false);
return conf.getBoolean("options.options.command_signs", false);
}
public static String getCannotUseSignMessage() {
@ -514,4 +515,8 @@ public class boosConfigManager {
return conf.getString("options.messages.cannot_create_sign",
"&6You are not allowed to create this kind of signs!&f");
}
public static boolean getLimitsEnabled() {
return conf.getBoolean("options.options.enable_limits", true);
}
}

View File

@ -42,10 +42,10 @@ public class boosCoolDown extends JavaPlugin {
boosCoolDownManager.clear();
}
try {
MetricsLite metrics = new MetricsLite(this);
metrics.start();
MetricsLite metrics = new MetricsLite(this);
metrics.start();
} catch (IOException e) {
// Failed to submit the stats :-(
// Failed to submit the stats :-(
}
}
@ -66,152 +66,150 @@ public class boosCoolDown extends JavaPlugin {
public boolean onCommand(CommandSender sender, Command c,
String commandLabel, String[] args) {
String command = c.getName().toLowerCase();
if (command.equalsIgnoreCase("booscooldowns")) {
if (args.length == 1) {
if (sender.hasPermission("booscooldowns.reload")
&& args[0].equalsIgnoreCase("reload")) {
boosConfigManager.reload();
boosChat.sendMessageToCommandSender(sender, "&6["
+ pdfFile.getName() + "]&e"
+ " config reloaded");
return true;
}
if (sender.hasPermission("booscooldowns.list.limits")
&& args[0].equalsIgnoreCase("limits")) {
try {
Player send = (Player) sender;
boosCoolDownManager.getLimits(send);
} catch (ClassCastException e) {
log.warning("You cannot use this command from console!");
}
return true;
}
if (command.equalsIgnoreCase("booscooldowns")) {
if (args.length == 1) {
if (sender.hasPermission("booscooldowns.reload")
&& args[0].equalsIgnoreCase("reload")) {
boosConfigManager.reload();
boosChat.sendMessageToCommandSender(sender,
"&6[" + pdfFile.getName() + "]&e"
+ " config reloaded");
return true;
}
if (args.length == 2) {
String jmeno = args[1];
if (sender.hasPermission("booscooldowns.clearcooldowns")
&& args[0].equalsIgnoreCase("clearcooldowns")) {
String co = "cooldown";
boosCoolDownManager.clearSomething(co, jmeno);
boosChat.sendMessageToCommandSender(sender, "&6["
+ pdfFile.getName() + "]&e"
+ " cooldowns of player " + jmeno + " cleared");
return true;
} else if (sender.hasPermission("booscooldowns.clearuses")
&& command.equalsIgnoreCase("booscooldowns")
&& args[0].equalsIgnoreCase("clearuses")) {
String co = "uses";
boosCoolDownManager.clearSomething(co, jmeno);
boosChat.sendMessageToCommandSender(sender, "&6["
+ pdfFile.getName() + "]&e"
+ " uses of player " + jmeno + " cleared");
return true;
} else if (sender.hasPermission("booscooldowns.clearwarmups")
&& command.equalsIgnoreCase("booscooldowns")
&& args[0].equalsIgnoreCase("clearwarmups")) {
String co = "warmup";
boosCoolDownManager.clearSomething(co, jmeno);
boosChat.sendMessageToCommandSender(sender, "&6["
+ pdfFile.getName() + "]&e"
+ " warmups of player " + jmeno + " cleared");
if (sender.hasPermission("booscooldowns.list.limits")
&& args[0].equalsIgnoreCase("limits")) {
try {
Player send = (Player) sender;
boosCoolDownManager.getLimits(send);
} catch (ClassCastException e) {
log.warning("You cannot use this command from console!");
}
return true;
}
}
if (args.length == 2) {
String jmeno = args[1];
if (sender.hasPermission("booscooldowns.clearcooldowns")
&& args[0].equalsIgnoreCase("clearcooldowns")) {
String co = "cooldown";
boosCoolDownManager.clearSomething(co, jmeno);
boosChat.sendMessageToCommandSender(sender,
"&6[" + pdfFile.getName() + "]&e"
+ " cooldowns of player " + jmeno
+ " cleared");
return true;
} else if (sender.hasPermission("booscooldowns.clearuses")
&& command.equalsIgnoreCase("booscooldowns")
&& args[0].equalsIgnoreCase("clearuses")) {
String co = "uses";
boosCoolDownManager.clearSomething(co, jmeno);
boosChat.sendMessageToCommandSender(sender,
"&6[" + pdfFile.getName() + "]&e"
+ " uses of player " + jmeno + " cleared");
return true;
} else if (sender.hasPermission("booscooldowns.clearwarmups")
&& command.equalsIgnoreCase("booscooldowns")
&& args[0].equalsIgnoreCase("clearwarmups")) {
String co = "warmup";
boosCoolDownManager.clearSomething(co, jmeno);
boosChat.sendMessageToCommandSender(sender,
"&6[" + pdfFile.getName() + "]&e"
+ " warmups of player " + jmeno
+ " cleared");
return true;
}
}
if (args.length == 3) {
String jmeno = args[1];
String command2 = args[2].trim();
if (sender.hasPermission("booscooldowns.clearcooldowns")
&& args[0].equalsIgnoreCase("clearcooldowns")) {
String co = "cooldown";
boosCoolDownManager.clearSomething(co, jmeno, command2);
boosChat.sendMessageToCommandSender(sender,
"&6[" + pdfFile.getName() + "]&e"
+ " cooldown for command " + command2
+ " of player " + jmeno + " cleared");
return true;
} else if (sender.hasPermission("booscooldowns.clearuses")
&& args[0].equalsIgnoreCase("clearuses")) {
String co = "uses";
boosCoolDownManager.clearSomething(co, jmeno, command2);
boosChat.sendMessageToCommandSender(sender,
"&6[" + pdfFile.getName() + "]&e"
+ " uses for command " + command2
+ " of player " + jmeno + " cleared");
return true;
} else if (sender.hasPermission("booscooldowns.clearwarmups")
&& args[0].equalsIgnoreCase("clearwarmups")) {
String co = "warmup";
boosCoolDownManager.clearSomething(co, jmeno, command2);
boosChat.sendMessageToCommandSender(sender,
"&6[" + pdfFile.getName() + "]&e"
+ " warmups for command " + command2
+ " of player " + jmeno + " cleared");
return true;
}
}
if (args.length == 4) {
if (sender.hasPermission("booscooldowns.set")
&& args[0].equalsIgnoreCase("set")) {
String coSetnout = args[1];
String co = args[2];
int hodnota = 0;
try {
hodnota = Integer.valueOf(args[3]);
} catch (Exception e) {
boosChat.sendMessageToCommandSender(sender,
"Added value must be number!");
return true;
}
}
if (args.length == 3) {
String jmeno = args[1];
String command2 = args[2].trim();
if (sender.hasPermission("booscooldowns.clearcooldowns")
&& args[0].equalsIgnoreCase("clearcooldowns")) {
String co = "cooldown";
boosCoolDownManager.clearSomething(co, jmeno, command2);
boosChat.sendMessageToCommandSender(sender, "&6["
+ pdfFile.getName() + "]&e"
+ " cooldown for command " + command2
+ " of player " + jmeno + " cleared");
return true;
} else if (sender.hasPermission("booscooldowns.clearuses")
&& args[0].equalsIgnoreCase("clearuses")) {
String co = "uses";
boosCoolDownManager.clearSomething(co, jmeno, command2);
boosChat.sendMessageToCommandSender(sender, "&6["
+ pdfFile.getName() + "]&e"
+ " uses for command " + command2
+ " of player " + jmeno + " cleared");
return true;
} else if (sender.hasPermission("booscooldowns.clearwarmups")
&& args[0].equalsIgnoreCase("clearwarmups")) {
String co = "warmup";
boosCoolDownManager.clearSomething(co, jmeno, command2);
boosChat.sendMessageToCommandSender(sender, "&6["
+ pdfFile.getName() + "]&e"
+ " warmups for command " + command2
+ " of player " + jmeno + " cleared");
return true;
}
}
if (args.length == 4) {
if (sender.hasPermission("booscooldowns.set")
&& args[0].equalsIgnoreCase("set")) {
String coSetnout = args[1];
String co = args[2];
int hodnota = 0;
try {
hodnota = Integer.valueOf(args[3]);
} catch (Exception e) {
boosChat.sendMessageToCommandSender(sender,
"Added value must be number!");
if (co.startsWith("/")) {
if (coSetnout.equals("cooldown")
|| coSetnout.equals("cooldown2")
|| coSetnout.equals("cooldown3")
|| coSetnout.equals("cooldown4")
|| coSetnout.equals("cooldown5")
|| coSetnout.equals("warmup")
|| coSetnout.equals("warmup2")
|| coSetnout.equals("warmup3")
|| coSetnout.equals("warmup4")
|| coSetnout.equals("warmup5")
|| coSetnout.equals("limit")
|| coSetnout.equals("limit2")
|| coSetnout.equals("limit3")
|| coSetnout.equals("limit4")
|| coSetnout.equals("limit5")
|| coSetnout.equals("price")
|| coSetnout.equals("price2")
|| coSetnout.equals("price3")
|| coSetnout.equals("price4")
|| coSetnout.equals("price5")) {
boosConfigManager.setAddToConfigFile(coSetnout, co,
hodnota);
boosChat.sendMessageToCommandSender(sender, "&6["
+ pdfFile.getName() + "]&e" + " "
+ coSetnout + " for command " + co
+ " is now set to " + hodnota);
return true;
}
if (co.startsWith("/")) {
if (coSetnout.equals("cooldown")
|| coSetnout.equals("cooldown2")
|| coSetnout.equals("cooldown3")
|| coSetnout.equals("cooldown4")
|| coSetnout.equals("cooldown5")
|| coSetnout.equals("warmup")
|| coSetnout.equals("warmup2")
|| coSetnout.equals("warmup3")
|| coSetnout.equals("warmup4")
|| coSetnout.equals("warmup5")
|| coSetnout.equals("limit")
|| coSetnout.equals("limit2")
|| coSetnout.equals("limit3")
|| coSetnout.equals("limit4")
|| coSetnout.equals("limit5")
|| coSetnout.equals("price")
|| coSetnout.equals("price2")
|| coSetnout.equals("price3")
|| coSetnout.equals("price4")
|| coSetnout.equals("price5")) {
boosConfigManager.setAddToConfigFile(coSetnout,
co, hodnota);
boosChat.sendMessageToCommandSender(sender,
"&6[" + pdfFile.getName() + "]&e" + " "
+ coSetnout + " for command "
+ co + " is now set to "
+ hodnota);
return true;
} else {
boosChat.sendMessageToCommandSender(
sender,
"&6["
+ pdfFile.getName()
+ "]&e"
+ " You can only set cooldown, cooldown2, cooldown3, cooldown4, cooldown5, warmup, warmup2, warmup3, warmup4, warmup5, limit, limit2, limit3, limit4, limit5, price, price2, price3, price4, price5.");
return true;
}
} else {
boosChat.sendMessageToCommandSender(
sender,
"&6["
+ pdfFile.getName()
+ "]&e"
+ " Added command have to start with \"/\".");
+ " You can only set cooldown, cooldown2, cooldown3, cooldown4, cooldown5, warmup, warmup2, warmup3, warmup4, warmup5, limit, limit2, limit3, limit4, limit5, price, price2, price3, price4, price5.");
return true;
}
} else {
boosChat.sendMessageToCommandSender(sender, "&6["
+ pdfFile.getName() + "]&e"
+ " Added command have to start with \"/\".");
return true;
}
}
}
} else {
boosChat.sendMessageToCommandSender(
sender,
@ -266,13 +264,12 @@ public class boosCoolDown extends JavaPlugin {
+ " economy plugin not found, disabling prices support.");
}
} else {
log.info("["
+ pdfFile.getName()
+ "]"
log.info("[" + pdfFile.getName() + "]"
+ " [Vault] not found disabling economy support.");
usingVault = false;
}
}
public static Logger getLog() {
return log;
}

View File

@ -107,7 +107,9 @@ public class boosCoolDownManager {
ConfigurationSection uses = boosConfigManager.getLimits(player);
if (uses != null) {
for (String key : uses.getKeys(false)) {
usesNum = confusers.getInt("users." + player.getName().toLowerCase() + ".uses." + key, usesNum);
usesNum = confusers.getInt("users."
+ player.getName().toLowerCase() + ".uses." + key,
usesNum);
if (lim.equals("limit")) {
limitNum = boosConfigManager.getLimit(key);
} else if (lim.equals("limit2")) {
@ -120,14 +122,15 @@ public class boosCoolDownManager {
limitNum = boosConfigManager.getLimit5(key);
}
num = limitNum - usesNum;
if (num < 0){
if (num < 0) {
num = 0;
}
message = boosConfigManager.getLimitListMessage();
message = message.replaceAll("&command&", key);
message = message.replaceAll("&limit&", String.valueOf(limitNum));
message = message.replaceAll("&times&", String.valueOf(num));
boosChat.sendMessageToPlayer(player, message);
message = boosConfigManager.getLimitListMessage();
message = message.replaceAll("&command&", key);
message = message.replaceAll("&limit&",
String.valueOf(limitNum));
message = message.replaceAll("&times&", String.valueOf(num));
boosChat.sendMessageToPlayer(player, message);
}
}
}
@ -156,11 +159,11 @@ public class boosCoolDownManager {
pre = pre.toLowerCase();
int coolDownSeconds = 0;
coolDownSeconds = getCooldownGroup(player, pre, coolDownSeconds);
if (coolDownSeconds > 0
&& !player.hasPermission("booscooldowns.nocooldown")
&& !player.hasPermission("booscooldowns.nocooldown." + pre)) {
return cd(player, pre, coolDownSeconds);
}
if (coolDownSeconds > 0
&& !player.hasPermission("booscooldowns.nocooldown")
&& !player.hasPermission("booscooldowns.nocooldown." + pre)) {
return cd(player, pre, coolDownSeconds);
}
return false;
}
@ -211,11 +214,10 @@ public class boosCoolDownManager {
boosConfigManager.getUnitHoursMessage());
} else {
String secs = Long.toString(waitSeconds);
if (secs.equals("0")){
if (secs.equals("0")) {
secs = "1";
}
msg = msg.replaceAll("&seconds&",
secs);
msg = msg.replaceAll("&seconds&", secs);
msg = msg.replaceAll("&unit&",
boosConfigManager.getUnitSecondsMessage());
}
@ -226,7 +228,8 @@ public class boosCoolDownManager {
}
static void cancelCooldown(Player player, String pre) {
confusers.set("users." + player.getName().toLowerCase() + ".cooldown." + pre, null);
confusers.set("users." + player.getName().toLowerCase() + ".cooldown."
+ pre, null);
}
static boolean checkCoolDownOK(Player player, String pre, String message) {
@ -277,17 +280,17 @@ public class boosCoolDownManager {
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);
}
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);
}
return coolDownSeconds;
}
@ -297,8 +300,8 @@ public class boosCoolDownManager {
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
currTime = sdf.format(cal.getTime());
confusers.set("users." + player.getName().toLowerCase() + ".cooldown." + pre,
currTime);
confusers.set("users." + player.getName().toLowerCase() + ".cooldown."
+ pre, currTime);
}
static Date getCurrTime() {
@ -319,8 +322,8 @@ public class boosCoolDownManager {
static Date getTime(Player player, String pre) {
pre = pre.toLowerCase();
String confTime = "";
confTime = confusers.getString("users." + player.getName().toLowerCase()
+ ".cooldown." + pre, null);
confTime = confusers.getString("users."
+ player.getName().toLowerCase() + ".cooldown." + pre, null);
if (confTime != null && !confTime.equals("")) {
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
@ -348,14 +351,15 @@ public class boosCoolDownManager {
static void setWarmUpOK(Player player, String pre, String message) {
pre = pre.toLowerCase();
confusers.set("users." + player.getName().toLowerCase() + ".warmup." + pre, 1);
confusers.set("users." + player.getName().toLowerCase() + ".warmup."
+ pre, 1);
}
static boolean checkWarmUpOK(Player player, String pre, String message) {
pre = pre.toLowerCase();
int ok = 0;
ok = confusers.getInt("users." + player.getName().toLowerCase() + ".warmup." + pre,
ok);
ok = confusers.getInt("users." + player.getName().toLowerCase()
+ ".warmup." + pre, ok);
if (ok == 1) {
return true;
}
@ -364,32 +368,38 @@ public class boosCoolDownManager {
static void removeWarmUpOK(Player player, String pre, String message) {
pre = pre.toLowerCase();
confusers.set("users." + player.getName().toLowerCase() + ".warmup." + pre, null);
confusers.set("users." + player.getName().toLowerCase() + ".warmup."
+ pre, null);
}
static void removeWarmUp(Player player, String pre, String message) {
pre = pre.toLowerCase();
confusers.set("users." + player.getName().toLowerCase() + ".warmup." + pre, null);
confusers.set("users." + player.getName().toLowerCase() + ".warmup."
+ pre, null);
}
static void setUses(Player player, String pre, String message) {
pre = pre.toLowerCase();
int uses = getUses(player, pre, message);
uses = uses + 1;
try {
confusers.set("users." + player.getName().toLowerCase() + ".uses." + pre
+ message, uses);
} catch (IllegalArgumentException e) {
boosCoolDown.log.warning("Player " + player.getName()
+ " used empty command and caused this error!");
if (boosConfigManager.getLimitsEnabled()) {
pre = pre.toLowerCase();
int uses = getUses(player, pre, message);
uses = uses + 1;
try {
confusers.set("users." + player.getName().toLowerCase()
+ ".uses." + pre + message, uses);
} catch (IllegalArgumentException e) {
boosCoolDown.log.warning("Player " + player.getName()
+ " used empty command and caused this error!");
}
} else {
return;
}
}
static int getUses(Player player, String pre, String message) {
pre = pre.toLowerCase();
int uses = 0;
uses = confusers.getInt("users." + player.getName().toLowerCase() + ".uses." + pre
+ message, uses);
uses = confusers.getInt("users." + player.getName().toLowerCase()
+ ".uses." + pre + message, uses);
return uses;
}

View File

@ -9,9 +9,12 @@ import net.milkbowl.vault.economy.EconomyResponse;
public class boosPriceManager {
private static Economy economy = boosCoolDown.getEconomy();
public static boolean payForCommand(Player player, String pre, int price, String name) {
if (economy == null){
return true;}
public static boolean payForCommand(Player player, String pre, int price,
String name) {
if (economy == null) {
return true;
}
EconomyResponse r = economy.withdrawPlayer(name, price);
if (r.transactionSuccess()) {
String msg = String.format(

View File

@ -63,13 +63,13 @@ public class boosWarmUpManager {
boosWarmUpManager.playercommands.remove(tag);
}
// public static void cancelWarmUps(Player player) {
// for (String key : playercommands.keySet()) {
// if (key.startsWith(player.getName() + "@")) {
// removeWarmUpProcess(key);
// }
// }
// }
// public static void cancelWarmUps(Player player) {
// for (String key : playercommands.keySet()) {
// if (key.startsWith(player.getName() + "@")) {
// removeWarmUpProcess(key);
// }
// }
// }
public static void cancelWarmUps(Player player) {
Iterator<String> iter = playercommands.keySet().iterator();
@ -80,14 +80,15 @@ public class boosWarmUpManager {
}
}
}
public static void killTimer(Player player) {
for (String key : playercommands.keySet()) {
if (key.startsWith(player.getName() + "@")) {
playercommands.get(key).cancel();
for (String key : playercommands.keySet()) {
if (key.startsWith(player.getName() + "@")) {
playercommands.get(key).cancel();
}
}
}
}
public static boolean hasWarmUps(Player player) {
for (String key : playercommands.keySet()) {
if (key.startsWith(player.getName() + "@")) {

View File

@ -5,7 +5,7 @@ import java.util.TimerTask;
import org.bukkit.entity.Player;
public class boosWarmUpTimer extends TimerTask {
private boosCoolDown bCoolDown;
private Player player;
private String pre;
@ -24,23 +24,27 @@ public class boosWarmUpTimer extends TimerTask {
@Override
public void run() {
bCoolDown.getServer().getScheduler().scheduleSyncDelayedTask(bCoolDown, new boosWarmUpRunnable());
bCoolDown.getServer().getScheduler()
.scheduleSyncDelayedTask(bCoolDown, new boosWarmUpRunnable());
}
public class boosWarmUpRunnable implements Runnable {
public void run() {
if (player.isOnline() && !player.isDead() && boosWarmUpManager.hasWarmUps(player)) {
if (player.isOnline() && !player.isDead()
&& boosWarmUpManager.hasWarmUps(player)) {
boosCoolDownManager.setWarmUpOK(player, pre, message);
boosWarmUpManager.removeWarmUpProcess(player.getName() + "@"
+ pre);
boosCoolDownListener.clearLocWorld(player);
player.chat(pre + message);
} else if (player.isOnline() && player.isDead() && boosWarmUpManager.hasWarmUps(player)){
} else if (player.isOnline() && player.isDead()
&& boosWarmUpManager.hasWarmUps(player)) {
boosCoolDownManager.removeWarmUp(player, pre, message);
boosWarmUpManager.removeWarmUpProcess(player.getName() + "@"
+ pre);
boosCoolDownListener.clearLocWorld(player);
} else if (!player.isOnline() && boosWarmUpManager.hasWarmUps(player)){
} else if (!player.isOnline()
&& boosWarmUpManager.hasWarmUps(player)) {
boosCoolDownManager.removeWarmUp(player, pre, message);
boosWarmUpManager.removeWarmUpProcess(player.getName() + "@"
+ pre);

View File

@ -33,6 +33,7 @@ import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.scheduler.BukkitTask;
import java.io.BufferedReader;
import java.io.File;
@ -49,309 +50,388 @@ import java.util.logging.Level;
public class MetricsLite {
/**
* The current revision number
*/
private final static int REVISION = 5;
/**
* The current revision number
*/
private final static int REVISION = 6;
/**
* The base url of the metrics domain
*/
private static final String BASE_URL = "http://mcstats.org";
/**
* The base url of the metrics domain
*/
private static final String BASE_URL = "http://mcstats.org";
/**
* The url used to report a server's status
*/
private static final String REPORT_URL = "/report/%s";
/**
* The url used to report a server's status
*/
private static final String REPORT_URL = "/report/%s";
/**
* Interval of time to ping (in minutes)
*/
private final static int PING_INTERVAL = 10;
/**
* Interval of time to ping (in minutes)
*/
private final static int PING_INTERVAL = 10;
/**
* The plugin this metrics submits for
*/
private final Plugin plugin;
/**
* The plugin this metrics submits for
*/
private final Plugin plugin;
/**
* The plugin configuration file
*/
private final YamlConfiguration configuration;
/**
* The plugin configuration file
*/
private final YamlConfiguration configuration;
/**
* The plugin configuration file
*/
private final File configurationFile;
/**
* The plugin configuration file
*/
private final File configurationFile;
/**
* Unique server id
*/
private final String guid;
/**
* Unique server id
*/
private final String guid;
/**
* Lock for synchronization
*/
private final Object optOutLock = new Object();
/**
* Debug mode
*/
private final boolean debug;
/**
* Id of the scheduled task
*/
private volatile int taskId = -1;
/**
* Lock for synchronization
*/
private final Object optOutLock = new Object();
public MetricsLite(Plugin plugin) throws IOException {
if (plugin == null) {
throw new IllegalArgumentException("Plugin cannot be null");
}
/**
* Id of the scheduled task
*/
private volatile BukkitTask task = null;
this.plugin = plugin;
public MetricsLite(Plugin plugin) throws IOException {
if (plugin == null) {
throw new IllegalArgumentException("Plugin cannot be null");
}
// load the config
configurationFile = getConfigFile();
configuration = YamlConfiguration.loadConfiguration(configurationFile);
this.plugin = plugin;
// add some defaults
configuration.addDefault("opt-out", false);
configuration.addDefault("guid", UUID.randomUUID().toString());
// load the config
configurationFile = getConfigFile();
configuration = YamlConfiguration.loadConfiguration(configurationFile);
// Do we need to create the file?
if (configuration.get("guid", null) == null) {
configuration.options().header("http://mcstats.org").copyDefaults(true);
configuration.save(configurationFile);
}
// add some defaults
configuration.addDefault("opt-out", false);
configuration.addDefault("guid", UUID.randomUUID().toString());
configuration.addDefault("debug", false);
// Load the guid then
guid = configuration.getString("guid");
}
// Do we need to create the file?
if (configuration.get("guid", null) == null) {
configuration.options().header("http://mcstats.org")
.copyDefaults(true);
configuration.save(configurationFile);
}
/**
* Start measuring statistics. This will immediately create an async repeating task as the plugin and send
* the initial data to the metrics backend, and then after that it will post in increments of
* PING_INTERVAL * 1200 ticks.
*
* @return True if statistics measuring is running, otherwise false.
*/
public boolean start() {
synchronized (optOutLock) {
// Did we opt out?
if (isOptOut()) {
return false;
}
// Load the guid then
guid = configuration.getString("guid");
debug = configuration.getBoolean("debug", false);
}
// Is metrics already running?
if (taskId >= 0) {
return true;
}
/**
* Start measuring statistics. This will immediately create an async
* repeating task as the plugin and send the initial data to the metrics
* backend, and then after that it will post in increments of PING_INTERVAL
* * 1200 ticks.
*
* @return True if statistics measuring is running, otherwise false.
*/
public boolean start() {
synchronized (optOutLock) {
// Did we opt out?
if (isOptOut()) {
return false;
}
// Begin hitting the server with glorious data
taskId = plugin.getServer().getScheduler().scheduleAsyncRepeatingTask(plugin, new Runnable() {
// Is metrics already running?
if (task != null) {
return true;
}
private boolean firstPost = true;
// Begin hitting the server with glorious data
task = plugin.getServer().getScheduler()
.runTaskTimerAsynchronously(plugin, new Runnable() {
public void run() {
try {
// This has to be synchronized or it can collide with the disable method.
synchronized (optOutLock) {
// Disable Task, if it is running and the server owner decided to opt-out
if (isOptOut() && taskId > 0) {
plugin.getServer().getScheduler().cancelTask(taskId);
taskId = -1;
}
}
private boolean firstPost = true;
// We use the inverse of firstPost because if it is the first time we are posting,
// it is not a interval ping, so it evaluates to FALSE
// Each time thereafter it will evaluate to TRUE, i.e PING!
postPlugin(!firstPost);
public void run() {
try {
// This has to be synchronized or it can collide
// with the disable method.
synchronized (optOutLock) {
// Disable Task, if it is running and the
// server owner decided to opt-out
if (isOptOut() && task != null) {
task.cancel();
task = null;
}
}
// After the first post we set firstPost to false
// Each post thereafter will be a ping
firstPost = false;
} catch (IOException e) {
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + e.getMessage());
}
}
}, 0, PING_INTERVAL * 1200);
// We use the inverse of firstPost because if it
// is the first time we are posting,
// it is not a interval ping, so it evaluates to
// FALSE
// Each time thereafter it will evaluate to
// TRUE, i.e PING!
postPlugin(!firstPost);
return true;
}
}
// After the first post we set firstPost to
// false
// Each post thereafter will be a ping
firstPost = false;
} catch (IOException e) {
if (debug) {
Bukkit.getLogger().log(Level.INFO,
"[Metrics] " + e.getMessage());
}
}
}
}, 0, PING_INTERVAL * 1200);
/**
* Has the server owner denied plugin metrics?
*
* @return true if metrics should be opted out of it
*/
public boolean isOptOut() {
synchronized(optOutLock) {
try {
// Reload the metrics file
configuration.load(getConfigFile());
} catch (IOException ex) {
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
return true;
} catch (InvalidConfigurationException ex) {
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
return true;
}
return configuration.getBoolean("opt-out", false);
}
}
return true;
}
}
/**
* Enables metrics for the server by setting "opt-out" to false in the config file and starting the metrics task.
*
* @throws IOException
*/
public void enable() throws IOException {
// This has to be synchronized or it can collide with the check in the task.
synchronized (optOutLock) {
// Check if the server owner has already set opt-out, if not, set it.
if (isOptOut()) {
configuration.set("opt-out", false);
configuration.save(configurationFile);
}
/**
* Has the server owner denied plugin metrics?
*
* @return true if metrics should be opted out of it
*/
public boolean isOptOut() {
synchronized (optOutLock) {
try {
// Reload the metrics file
configuration.load(getConfigFile());
} catch (IOException ex) {
if (debug) {
Bukkit.getLogger().log(Level.INFO,
"[Metrics] " + ex.getMessage());
}
return true;
} catch (InvalidConfigurationException ex) {
if (debug) {
Bukkit.getLogger().log(Level.INFO,
"[Metrics] " + ex.getMessage());
}
return true;
}
return configuration.getBoolean("opt-out", false);
}
}
// Enable Task, if it is not running
if (taskId < 0) {
start();
}
}
}
/**
* Enables metrics for the server by setting "opt-out" to false in the
* config file and starting the metrics task.
*
* @throws java.io.IOException
*/
public void enable() throws IOException {
// This has to be synchronized or it can collide with the check in the
// task.
synchronized (optOutLock) {
// Check if the server owner has already set opt-out, if not, set
// it.
if (isOptOut()) {
configuration.set("opt-out", false);
configuration.save(configurationFile);
}
/**
* Disables metrics for the server by setting "opt-out" to true in the config file and canceling the metrics task.
*
* @throws IOException
*/
public void disable() throws IOException {
// This has to be synchronized or it can collide with the check in the task.
synchronized (optOutLock) {
// Check if the server owner has already set opt-out, if not, set it.
if (!isOptOut()) {
configuration.set("opt-out", true);
configuration.save(configurationFile);
}
// Enable Task, if it is not running
if (task == null) {
start();
}
}
}
// Disable Task, if it is running
if (taskId > 0) {
this.plugin.getServer().getScheduler().cancelTask(taskId);
taskId = -1;
}
}
}
/**
* Disables metrics for the server by setting "opt-out" to true in the
* config file and canceling the metrics task.
*
* @throws java.io.IOException
*/
public void disable() throws IOException {
// This has to be synchronized or it can collide with the check in the
// task.
synchronized (optOutLock) {
// Check if the server owner has already set opt-out, if not, set
// it.
if (!isOptOut()) {
configuration.set("opt-out", true);
configuration.save(configurationFile);
}
/**
* Gets the File object of the config file that should be used to store data such as the GUID and opt-out status
*
* @return the File object for the config file
*/
public File getConfigFile() {
// I believe the easiest way to get the base folder (e.g craftbukkit set via -P) for plugins to use
// is to abuse the plugin object we already have
// plugin.getDataFolder() => base/plugins/PluginA/
// pluginsFolder => base/plugins/
// The base is not necessarily relative to the startup directory.
File pluginsFolder = plugin.getDataFolder().getParentFile();
// Disable Task, if it is running
if (task != null) {
task.cancel();
task = null;
}
}
}
// return => base/plugins/PluginMetrics/config.yml
return new File(new File(pluginsFolder, "PluginMetrics"), "config.yml");
}
/**
* Gets the File object of the config file that should be used to store data
* such as the GUID and opt-out status
*
* @return the File object for the config file
*/
public File getConfigFile() {
// I believe the easiest way to get the base folder (e.g craftbukkit set
// via -P) for plugins to use
// is to abuse the plugin object we already have
// plugin.getDataFolder() => base/plugins/PluginA/
// pluginsFolder => base/plugins/
// The base is not necessarily relative to the startup directory.
File pluginsFolder = plugin.getDataFolder().getParentFile();
/**
* Generic method that posts a plugin to the metrics website
*/
private void postPlugin(boolean isPing) throws IOException {
// The plugin's description file containg all of the plugin data such as name, version, author, etc
final PluginDescriptionFile description = plugin.getDescription();
// return => base/plugins/PluginMetrics/config.yml
return new File(new File(pluginsFolder, "PluginMetrics"), "config.yml");
}
// Construct the post data
final StringBuilder data = new StringBuilder();
data.append(encode("guid")).append('=').append(encode(guid));
encodeDataPair(data, "version", description.getVersion());
encodeDataPair(data, "server", Bukkit.getVersion());
encodeDataPair(data, "players", Integer.toString(Bukkit.getServer().getOnlinePlayers().length));
encodeDataPair(data, "revision", String.valueOf(REVISION));
/**
* Generic method that posts a plugin to the metrics website
*/
private void postPlugin(boolean isPing) throws IOException {
// Server software specific section
PluginDescriptionFile description = plugin.getDescription();
String pluginName = description.getName();
boolean onlineMode = Bukkit.getServer().getOnlineMode(); // TRUE if
// online
// mode is
// enabled
String pluginVersion = description.getVersion();
String serverVersion = Bukkit.getVersion();
int playersOnline = Bukkit.getServer().getOnlinePlayers().length;
// If we're pinging, append it
if (isPing) {
encodeDataPair(data, "ping", "true");
}
// END server software specific section -- all code below does not use
// any code outside of this class / Java
// Create the url
URL url = new URL(BASE_URL + String.format(REPORT_URL, encode(plugin.getDescription().getName())));
// Construct the post data
final StringBuilder data = new StringBuilder();
// Connect to the website
URLConnection connection;
// The plugin's description file containg all of the plugin data such as
// name, version, author, etc
data.append(encode("guid")).append('=').append(encode(guid));
encodeDataPair(data, "version", pluginVersion);
encodeDataPair(data, "server", serverVersion);
encodeDataPair(data, "players", Integer.toString(playersOnline));
encodeDataPair(data, "revision", String.valueOf(REVISION));
// Mineshafter creates a socks proxy, so we can safely bypass it
// It does not reroute POST requests so we need to go around it
if (isMineshafterPresent()) {
connection = url.openConnection(Proxy.NO_PROXY);
} else {
connection = url.openConnection();
}
// New data as of R6
String osname = System.getProperty("os.name");
String osarch = System.getProperty("os.arch");
String osversion = System.getProperty("os.version");
String java_version = System.getProperty("java.version");
int coreCount = Runtime.getRuntime().availableProcessors();
connection.setDoOutput(true);
// normalize os arch .. amd64 -> x86_64
if (osarch.equals("amd64")) {
osarch = "x86_64";
}
// Write the data
final OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());
writer.write(data.toString());
writer.flush();
encodeDataPair(data, "osname", osname);
encodeDataPair(data, "osarch", osarch);
encodeDataPair(data, "osversion", osversion);
encodeDataPair(data, "cores", Integer.toString(coreCount));
encodeDataPair(data, "online-mode", Boolean.toString(onlineMode));
encodeDataPair(data, "java_version", java_version);
// Now read the response
final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
final String response = reader.readLine();
// If we're pinging, append it
if (isPing) {
encodeDataPair(data, "ping", "true");
}
// close resources
writer.close();
reader.close();
// Create the url
URL url = new URL(BASE_URL
+ String.format(REPORT_URL, encode(pluginName)));
if (response == null || response.startsWith("ERR")) {
throw new IOException(response); //Throw the exception
}
//if (response.startsWith("OK")) - We should get "OK" followed by an optional description if everything goes right
}
// Connect to the website
URLConnection connection;
/**
* Check if mineshafter is present. If it is, we need to bypass it to send POST requests
*
* @return true if mineshafter is installed on the server
*/
private boolean isMineshafterPresent() {
try {
Class.forName("mineshafter.MineServer");
return true;
} catch (Exception e) {
return false;
}
}
// Mineshafter creates a socks proxy, so we can safely bypass it
// It does not reroute POST requests so we need to go around it
if (isMineshafterPresent()) {
connection = url.openConnection(Proxy.NO_PROXY);
} else {
connection = url.openConnection();
}
/**
* <p>Encode a key/value data pair to be used in a HTTP post request. This INCLUDES a & so the first
* key/value pair MUST be included manually, e.g:</p>
* <code>
* StringBuffer data = new StringBuffer();
* data.append(encode("guid")).append('=').append(encode(guid));
* encodeDataPair(data, "version", description.getVersion());
* </code>
*
* @param buffer the stringbuilder to append the data pair onto
* @param key the key value
* @param value the value
*/
private static void encodeDataPair(final StringBuilder buffer, final String key, final String value) throws UnsupportedEncodingException {
buffer.append('&').append(encode(key)).append('=').append(encode(value));
}
connection.setDoOutput(true);
/**
* Encode text as UTF-8
*
* @param text the text to encode
* @return the encoded text, as UTF-8
*/
private static String encode(final String text) throws UnsupportedEncodingException {
return URLEncoder.encode(text, "UTF-8");
}
// Write the data
final OutputStreamWriter writer = new OutputStreamWriter(
connection.getOutputStream());
writer.write(data.toString());
writer.flush();
// Now read the response
final BufferedReader reader = new BufferedReader(new InputStreamReader(
connection.getInputStream()));
final String response = reader.readLine();
// close resources
writer.close();
reader.close();
if (response == null || response.startsWith("ERR")) {
throw new IOException(response); // Throw the exception
}
}
/**
* Check if mineshafter is present. If it is, we need to bypass it to send
* POST requests
*
* @return true if mineshafter is installed on the server
*/
private boolean isMineshafterPresent() {
try {
Class.forName("mineshafter.MineServer");
return true;
} catch (Exception e) {
return false;
}
}
/**
* <p>
* Encode a key/value data pair to be used in a HTTP post request. This
* INCLUDES a & so the first key/value pair MUST be included manually, e.g:
* </p>
* <code>
* StringBuffer data = new StringBuffer();
* data.append(encode("guid")).append('=').append(encode(guid));
* encodeDataPair(data, "version", description.getVersion());
* </code>
*
* @param buffer
* the stringbuilder to append the data pair onto
* @param key
* the key value
* @param value
* the value
*/
private static void encodeDataPair(final StringBuilder buffer,
final String key, final String value)
throws UnsupportedEncodingException {
buffer.append('&').append(encode(key)).append('=')
.append(encode(value));
}
/**
* Encode text as UTF-8
*
* @param text
* the text to encode
* @return the encoded text, as UTF-8
*/
private static String encode(final String text)
throws UnsupportedEncodingException {
return URLEncoder.encode(text, "UTF-8");
}
}

View File

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

View File

@ -9,69 +9,95 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class boosChat {
static Logger log = Logger.getLogger("Minecraft");
static List<String> Colors = new LinkedList<String>();
static Server server;
public boosChat(Server server) {
Colors.add("&black&"); Colors.add("&darkblue&"); Colors.add("&darkgreen&");
Colors.add("&darkaqua&"); Colors.add("&darkred&"); Colors.add("&purple&");
Colors.add("&gold&"); Colors.add("&gray&"); Colors.add("&darkgray&");
Colors.add("&blue&"); Colors.add("&green&"); Colors.add("&aqua&");
Colors.add("&red&"); Colors.add("&pink&"); Colors.add("&yellow&");
Colors.add("&white&");
Colors.add("&0"); Colors.add("&1"); Colors.add("&2"); Colors.add("&3"); Colors.add("&4");
Colors.add("&5"); Colors.add("&6"); Colors.add("&7"); Colors.add("&8"); Colors.add("&9");
Colors.add("&a"); Colors.add("&b"); Colors.add("&c"); Colors.add("&d"); Colors.add("&e");
Colors.add("&f");
boosChat.server = server;
}
static String replaceColorCodes(String line) {
line = replaceTags(line);
line = line.replaceAll("(&([a-f0-9]))", "\u00A7$2");
return line;
}
static String replaceTags(String line) {
line = line.replaceAll("&black&", "&0");
line = line.replaceAll("&darkblue&", "&1");
line = line.replaceAll("&darkgreen&", "&2");
line = line.replaceAll("&darkaqua&", "&3");
line = line.replaceAll("&darkred&", "&4");
line = line.replaceAll("&purple&", "&5");
line = line.replaceAll("&gold&", "&6");
line = line.replaceAll("&gray&", "&7");
line = line.replaceAll("&darkgray&", "&8");
line = line.replaceAll("&blue&", "&9");
line = line.replaceAll("&green&", "&a");
line = line.replaceAll("&aqua&", "&b");
line = line.replaceAll("&red&", "&c");
line = line.replaceAll("&pink&", "&d");
line = line.replaceAll("&yellow&", "&e");
line = line.replaceAll("&white&", "&f");
return line;
}
public static void broadcastMessage(String message) {
message = boosChat.replaceColorCodes(message);
log.info( "[bColoredChat] " + message);
server.broadcastMessage(message);
}
public static void sendMessageToPlayer(Player player, String message) {
message = boosChat.replaceColorCodes(message);
player.sendMessage(message);
}
public static void sendMessageToServer(String message) {
message = boosChat.replaceColorCodes(message);
log.info(message);
}
public static void sendMessageToCommandSender(CommandSender sender, String message) {
if(sender instanceof Player) {
boosChat.sendMessageToPlayer((Player) sender, message);
}
else {
boosChat.sendMessageToServer(message);
}
}
static Logger log = Logger.getLogger("Minecraft");
static List<String> Colors = new LinkedList<String>();
static Server server;
public boosChat(Server server) {
Colors.add("&black&");
Colors.add("&darkblue&");
Colors.add("&darkgreen&");
Colors.add("&darkaqua&");
Colors.add("&darkred&");
Colors.add("&purple&");
Colors.add("&gold&");
Colors.add("&gray&");
Colors.add("&darkgray&");
Colors.add("&blue&");
Colors.add("&green&");
Colors.add("&aqua&");
Colors.add("&red&");
Colors.add("&pink&");
Colors.add("&yellow&");
Colors.add("&white&");
Colors.add("&0");
Colors.add("&1");
Colors.add("&2");
Colors.add("&3");
Colors.add("&4");
Colors.add("&5");
Colors.add("&6");
Colors.add("&7");
Colors.add("&8");
Colors.add("&9");
Colors.add("&a");
Colors.add("&b");
Colors.add("&c");
Colors.add("&d");
Colors.add("&e");
Colors.add("&f");
boosChat.server = server;
}
static String replaceColorCodes(String line) {
line = replaceTags(line);
line = line.replaceAll("(&([a-f0-9]))", "\u00A7$2");
return line;
}
static String replaceTags(String line) {
line = line.replaceAll("&black&", "&0");
line = line.replaceAll("&darkblue&", "&1");
line = line.replaceAll("&darkgreen&", "&2");
line = line.replaceAll("&darkaqua&", "&3");
line = line.replaceAll("&darkred&", "&4");
line = line.replaceAll("&purple&", "&5");
line = line.replaceAll("&gold&", "&6");
line = line.replaceAll("&gray&", "&7");
line = line.replaceAll("&darkgray&", "&8");
line = line.replaceAll("&blue&", "&9");
line = line.replaceAll("&green&", "&a");
line = line.replaceAll("&aqua&", "&b");
line = line.replaceAll("&red&", "&c");
line = line.replaceAll("&pink&", "&d");
line = line.replaceAll("&yellow&", "&e");
line = line.replaceAll("&white&", "&f");
return line;
}
public static void broadcastMessage(String message) {
message = boosChat.replaceColorCodes(message);
log.info("[bColoredChat] " + message);
server.broadcastMessage(message);
}
public static void sendMessageToPlayer(Player player, String message) {
message = boosChat.replaceColorCodes(message);
player.sendMessage(message);
}
public static void sendMessageToServer(String message) {
message = boosChat.replaceColorCodes(message);
log.info(message);
}
public static void sendMessageToCommandSender(CommandSender sender,
String message) {
if (sender instanceof Player) {
boosChat.sendMessageToPlayer((Player) sender, message);
} else {
boosChat.sendMessageToServer(message);
}
}
}