New handling of configuration. Now uses Regex.

This commit is contained in:
Boosik 2013-03-31 20:22:14 +02:00
parent 12ff7d5458
commit 40972d9dfd
26 changed files with 472 additions and 621 deletions

View File

@ -0,0 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6

Binary file not shown.

Binary file not shown.

View File

@ -1,6 +1,6 @@
name: boosCooldowns
main: cz.boosik.boosCooldown.boosCoolDown
version: 3.5.0
version: 3.6.0 BETA
authors: [LordBoos (ingame name boosik)]
softdepend: [Vault]
description: >
@ -67,54 +67,6 @@ permissions:
booscooldowns.nolimit./command:
description: Command "/command" will not be affected by limits for users with this permission.
default: false
booscooldowns.warmup2:
description: Player will be affected by warmup2 group. Players without this permission, will be affected by default warmups.
default: false
booscooldowns.warmup3:
description: Player will be affected by warmup3 group. Players without this permission, will be affected by default warmups.
default: false
booscooldowns.warmup4:
description: Player will be affected by warmup4 group. Players without this permission, will be affected by default warmups.
default: false
booscooldowns.warmup5:
description: Player will be affected by warmup5 group. Players without this permission, will be affected by default warmups.
default: false
booscooldowns.price2:
description: Player will be affected by price2 group. Players without this permission, will be affected by default prices.
default: false
booscooldowns.price3:
description: Player will be affected by price3 group. Players without this permission, will be affected by default prices.
default: false
booscooldowns.price4:
description: Player will be affected by price4 group. Players without this permission, will be affected by default prices.
default: false
booscooldowns.price5:
description: Player will be affected by price5 group. Players without this permission, will be affected by default prices.
default: false
booscooldowns.cooldown2:
description: Player will be affected by cooldown2 group. Players without this permission, will be affected by default cooldowns.
default: false
booscooldowns.cooldown3:
description: Player will be affected by cooldown3 group. Players without this permission, will be affected by default cooldowns.
default: false
booscooldowns.cooldown4:
description: Player will be affected by cooldown4 group. Players without this permission, will be affected by default cooldowns.
default: false
booscooldowns.cooldown5:
description: Player will be affected by cooldown5 group. Players without this permission, will be affected by default cooldowns.
default: false
booscooldowns.limit2:
description: Player will be affected by limit2 group. Players without this permission, will be affected by default limits.
default: false
booscooldowns.limit3:
description: Player will be affected by limit3 group. Players without this permission, will be affected by default limits.
default: false
booscooldowns.limit4:
description: Player will be affected by limit4 group. Players without this permission, will be affected by default limits.
default: false
booscooldowns.limit5:
description: Player will be affected by limit5 group. Players without this permission, will be affected by default limits.
default: false
booscooldowns.reload:
description: Player can use "/booscooldowns reload" to reload config file.
default: op

Binary file not shown.

View File

@ -12,30 +12,6 @@ import cz.boosik.boosCooldown.boosCoolDownListener;
import cz.boosik.boosCooldown.boosWarmUpManager;
public class boosPlayerMoveListener implements Listener {
int tempTimer = 0;
@EventHandler(priority = EventPriority.NORMAL)
private void onPlayerMove(PlayerMoveEvent event) {
if (event.isCancelled()) {
return;
}
if (tempTimer < 20){
tempTimer = tempTimer + 1;
return;
} else {
Player player = event.getPlayer();
if (player != null
&& !player.hasPermission("booscooldowns.nocancel.move")) {
if (boosWarmUpManager.hasWarmUps(player) && hasMoved(player)) {
boosCoolDownListener.clearLocWorld(player);
boosChat.sendMessageToPlayer(player,
boosConfigManager.getWarmUpCancelledByMoveMessage());
boosWarmUpManager.cancelWarmUps(player);
}
}
tempTimer = 0;
}
}
private static boolean hasMoved(Player player) {
String curworld = player.getWorld().getName();
String cmdworld = boosCoolDownListener.playerworld.get(player);
@ -49,4 +25,29 @@ public class boosPlayerMoveListener implements Listener {
return false;
}
int tempTimer = 0;
@EventHandler(priority = EventPriority.NORMAL)
private void onPlayerMove(PlayerMoveEvent event) {
if (event.isCancelled()) {
return;
}
if (tempTimer < 20) {
tempTimer = tempTimer + 1;
return;
} else {
Player player = event.getPlayer();
if (player != null
&& !player.hasPermission("booscooldowns.nocancel.move")) {
if (boosWarmUpManager.hasWarmUps(player) && hasMoved(player)) {
boosCoolDownListener.clearLocWorld(player);
boosChat.sendMessageToPlayer(player,
boosConfigManager.getWarmUpCancelledByMoveMessage());
boosWarmUpManager.cancelWarmUps(player);
}
}
tempTimer = 0;
}
}
}

View File

@ -8,7 +8,6 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
@ -23,9 +22,9 @@ public class boosConfigManager {
return conf.getString("commands.aliases." + message);
}
public static ConfigurationSection getAliases() {
ConfigurationSection aliases = conf
.getConfigurationSection("commands.aliases");
public static Set<String> getAliases() {
Set<String> aliases = conf.getConfigurationSection("commands.aliases")
.getKeys(false);
return aliases;
}
@ -114,6 +113,10 @@ public class boosConfigManager {
return coolDown;
}
public static boolean getCooldownEnabled() {
return conf.getBoolean("options.options.cooldowns_enabled", true);
}
private static Set<String> getCooldownGroups() {
Set<String> groups = conf.getConfigurationSection("commands.cooldowns")
.getKeys(false);
@ -160,12 +163,6 @@ public class boosConfigManager {
return lim;
}
private static Set<String> getLimitGroups() {
Set<String> groups = conf.getConfigurationSection("commands.limits")
.getKeys(false);
return groups;
}
public static int getLimit(String pre, Player player) {
int limit = -1;
String group = getLimGrp(player);
@ -174,6 +171,16 @@ public class boosConfigManager {
return limit;
}
public static boolean getLimitEnabled() {
return conf.getBoolean("options.options.limits_enabled", true);
}
private static Set<String> getLimitGroups() {
Set<String> groups = conf.getConfigurationSection("commands.limits")
.getKeys(false);
return groups;
}
public static String getLimitListMessage() {
return conf
.getString(
@ -232,6 +239,16 @@ public class boosConfigManager {
return price;
}
public static boolean getPriceEnabled() {
return conf.getBoolean("options.options.prices_enabled", true);
}
private static Set<String> getPriceGroups() {
Set<String> groups = conf.getConfigurationSection("commands.prices")
.getKeys(false);
return groups;
}
private static String getPriceGrp(Player player) {
String price = "price";
for (String group : getPriceGroups()) {
@ -242,10 +259,11 @@ public class boosConfigManager {
return price;
}
private static Set<String> getPriceGroups() {
Set<String> groups = conf.getConfigurationSection("commands.prices")
.getKeys(false);
return groups;
public static Set<String> getPrices(Player player) {
String price = getPriceGrp(player);
Set<String> prices = conf.getConfigurationSection(
"commands.prices." + price).getKeys(false);
return prices;
}
public static int getSaveInterval() {
@ -306,6 +324,10 @@ public class boosConfigManager {
"&6Warm-ups have been cancelled due to moving.&f");
}
public static boolean getWarmupEnabled() {
return conf.getBoolean("options.options.warmups_enabled", true);
}
public static Set<String> getWarmupGroups() {
Set<String> groups = conf.getConfigurationSection("commands.warmups")
.getKeys(false);
@ -386,6 +408,10 @@ public class boosConfigManager {
this.confFile = new File(boosCoolDown.getDataFolder(), "config.yml");
this.conf = new YamlConfiguration();
conf.options().copyDefaults(true);
conf.addDefault("options.options.warmups_enabled", true);
conf.addDefault("options.options.cooldowns_enabled", true);
conf.addDefault("options.options.prices_enabled", true);
conf.addDefault("options.options.limits_enabled", true);
conf.addDefault("options.options.save_interval_in_minutes", 15);
conf.addDefault("options.options.cancel_warmup_on_damage", false);
conf.addDefault("options.options.cancel_warmup_on_move", false);
@ -401,7 +427,6 @@ public class boosConfigManager {
conf.addDefault("options.options.start_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");
@ -450,19 +475,16 @@ public class boosConfigManager {
}
}
try {
conf.addDefault("commands.cooldowns.cooldown./spawn", 60);
conf.addDefault("commands.cooldowns.cooldown./home", 30);
conf.addDefault("commands.cooldowns.cooldown2./home", 40);
conf.addDefault("commands.cooldowns.cooldown3./home", 90);
conf.addDefault("commands.cooldowns.cooldown4./home", 99);
conf.addDefault("commands.cooldowns.cooldown5./home", 542);
conf.addDefault("commands.warmups.warmup./warp", 10);
conf.addDefault("commands.warmups.warmup./warp list", 0);
conf.addDefault("commands.warmups.warmup./warp arena", 60);
conf.addDefault("commands.warmups.warmup2./home", 40);
conf.addDefault("commands.warmups.warmup3./home", 90);
conf.addDefault("commands.warmups.warmup4./home", 99);
conf.addDefault("commands.warmups.warmup5./home", 542);
conf.addDefault("commands.cooldowns.cooldown./command", 60);
conf.addDefault("commands.cooldowns.cooldown./anotherCommand *", 30);
conf.addDefault("commands.cooldowns.VIP./home", 40);
conf.addDefault("commands.cooldowns.Premium./home", 90);
conf.addDefault("commands.cooldowns.Donator./home", 99);
conf.addDefault("commands.cooldowns.something./home", 542);
conf.addDefault("commands.warmups.warmup.'*'", 1);
conf.addDefault("commands.warmups.warmup./anotherCommand *", 0);
conf.addDefault("commands.warmups.Donor./home", 40);
conf.addDefault("commands.warmups.example./home", 90);
conf.addDefault("commands.warmupPotionEffects.effect./home",
"WEAKNESS@3");
conf.addDefault(
@ -471,23 +493,17 @@ public class boosConfigManager {
conf.addDefault(
"commands.warmupPotionEffects.howto2",
"#After effect add @number, for example WEAKNESS@3 will apply weakness III to player for the duration of warmup.");
conf.addDefault("commands.prices.price./spawn", 10.0);
conf.addDefault("commands.prices.price./home", 20.0);
conf.addDefault("commands.prices.price2./home", 40.0);
conf.addDefault("commands.prices.price3./home", 90.0);
conf.addDefault("commands.prices.price4./home", 99.0);
conf.addDefault("commands.prices.price5./home", 542.0);
conf.addDefault("commands.limits.limit./example", 0);
conf.addDefault("commands.limits.limit2./example", 100);
conf.addDefault("commands.limits.limit3./command", 50);
conf.addDefault("commands.limits.limit4./command", 11);
conf.addDefault("commands.limits.limit5./lol", 2);
conf.addDefault("commands.prices.price./command *", 10.0);
conf.addDefault("commands.prices.price./anotherCommand", 20.0);
conf.addDefault("commands.prices.yourGroup./home", 40.0);
conf.addDefault("commands.limits.limit./command *", 0);
conf.addDefault("commands.limits.limit2./lol", 100);
conf.addDefault("commands.links.link./lol", "default");
conf.addDefault("commands.links.link./home", "default");
conf.addDefault("commands.links.link./warp", "default");
conf.addDefault("commands.links.link./example", "default");
conf.addDefault("commands.links.link./command", "default");
conf.addDefault("commands.links.link./yourCommandHere",
"yourNameHere");
String[] def = { "/home", "/lol", "/warp" };
String[] def = { "/lol", "/example" };
conf.addDefault("commands.links.linkGroups.default",
Arrays.asList(def));
String[] def2 = { "/yourCommandHere", "/someCommand",

View File

@ -34,8 +34,6 @@ public class boosCoolDown extends JavaPlugin implements Runnable {
public static PluginDescriptionFile pdfFile;
private static Economy economy = null;
private static boolean usingVault = false;
private PluginManager pm;
public static void commandLogger(String player, String command) {
log.info("[" + "boosLogger" + "] " + player + " used command "
+ command);
@ -53,6 +51,8 @@ public class boosCoolDown extends JavaPlugin implements Runnable {
return usingVault;
}
private PluginManager pm;
private void initializeVault() {
Plugin x = this.getServer().getPluginManager().getPlugin("Vault");
if (x != null & x instanceof Vault) {
@ -235,6 +235,7 @@ public class boosCoolDown extends JavaPlugin implements Runnable {
return false;
}
@Override
public void onDisable() {
if (boosConfigManager.getClearOnRestart() == true) {
boosCoolDownManager.clear();
@ -247,6 +248,7 @@ public class boosCoolDown extends JavaPlugin implements Runnable {
+ pdfFile.getVersion() + " disabled!");
}
@Override
public void onEnable() {
pdfFile = this.getDescription();
PluginDescriptionFile pdfFile = this.getDescription();
@ -262,7 +264,9 @@ public class boosCoolDown extends JavaPlugin implements Runnable {
registerListeners();
initializeVault();
BukkitScheduler scheduler = this.getServer().getScheduler();
scheduler.scheduleSyncRepeatingTask(this, this, boosConfigManager.getSaveInterval()*1200, boosConfigManager.getSaveInterval()*1200);
scheduler.scheduleSyncRepeatingTask(this, this,
boosConfigManager.getSaveInterval() * 1200,
boosConfigManager.getSaveInterval() * 1200);
if (boosConfigManager.getClearOnRestart()) {
boosCoolDownManager.clear();
}

View File

@ -1,16 +1,15 @@
package cz.boosik.boosCooldown;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import org.bukkit.Location;
import org.bukkit.configuration.ConfigurationSection;
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;
public class boosCoolDownListener<a> implements Listener {
@ -28,40 +27,38 @@ public class boosCoolDownListener<a> implements Listener {
plugin = instance;
}
private boolean blocked(Player player, String pre, String msg) {
int limit = -1;
int uses = boosCoolDownManager.getUses(player, pre, msg);
private boolean blocked(Player player, String pre, int limit) {
int uses = boosCoolDownManager.getUses(player, pre);
if (player.hasPermission("booscooldowns.nolimit")
|| player.hasPermission("booscooldowns.nolimit." + pre)) {
} else {
limit = boosConfigManager.getLimit(pre, player);
if (limit == -1) {
return false;
} else if (limit <= uses) {
return true;
}
if (limit == -1) {
return false;
} else if (limit <= uses) {
return true;
}
}
return false;
}
// Returns true if the command is on cooldown, false otherwise
private void checkCooldown(PlayerCommandPreprocessEvent event,
Player player, String pre, String message, int warmUpSeconds,
double price) {
int cooldownTime, double price) {
if (!blocked) {
if (warmUpSeconds > 0) {
if (!player.hasPermission("booscooldowns.nowarmup")
&& !player.hasPermission("booscooldowns.nowarmup."
+ pre)) {
start(event, player, pre, message, warmUpSeconds);
+ message)) {
start(event, player, message, warmUpSeconds, cooldownTime);
}
} else {
if (boosCoolDownManager.coolDown(player, pre)) {
if (boosCoolDownManager.coolDown(player, message, cooldownTime)) {
event.setCancelled(true);
}
}
if (!event.isCancelled()) {
payForCommand(event, player, pre, price);
payForCommand(event, player, message, price);
}
} else {
event.setCancelled(true);
@ -72,7 +69,7 @@ public class boosCoolDownListener<a> implements Listener {
if (!event.isCancelled()) {
boosCoolDownManager.setUses(player, pre, message);
if (boosConfigManager.getCommandLogging()) {
boosCoolDown.commandLogger(player.getName(), pre + message);
boosCoolDown.commandLogger(player.getName(), message);
}
}
}
@ -97,8 +94,21 @@ public class boosCoolDownListener<a> implements Listener {
if (event.isCancelled()) {
return;
}
ConfigurationSection aliases = boosConfigManager.getAliases();
String message = event.getMessage();
Player player = event.getPlayer();
String message = event.getMessage().trim().replaceAll(" +", " ");
String confCmd = "";
Set<String> aliases = boosConfigManager.getAliases();
Set<String> warmups = boosConfigManager.getWarmups(player);
Set<String> cooldowns = boosConfigManager.getCooldowns(player);
Set<String> limits = boosConfigManager.getLimits(player);
Set<String> prices = boosConfigManager.getPrices(player);
boolean on = true;
boolean used = false;
int warmupTime = 0;
double price = 0;
int limit = -1;
int cooldownTime = 0;
on = isPluginOnForPlayer(player);
try {
if (aliases.contains(message)) {
message = boosConfigManager.getAlias(message);
@ -110,140 +120,69 @@ public class boosCoolDownListener<a> implements Listener {
.warning(
"Aliases section in config.yml is missing! Please delete your config.yml, restart server and set it again!");
}
message = message.trim().replaceAll(" +", " ");
Player player = event.getPlayer();
boolean on = true;
on = isPluginOnForPlayer(player);
if (on) {
boolean used = false;
String messageCommand = "";
String preSub = "";
String preSub2 = "";
String preSub3 = "";
String messageSub = "";
String messageSub2 = "";
String messageSub3 = "";
int preSubCheck = -1;
int preSubCheck2 = -1;
int preSubCheck3 = -1;
double price = 0;
int limit = 0;
int cd = 0;
playerloc.put(player, player.getLocation());
playerworld.put(player, player.getWorld().getName());
String[] splitCommand;
splitCommand = message.split(" ");
String preCommand = splitCommand[0];
if (splitCommand.length > 1) {
for (int i = 1; i < splitCommand.length; i++) {
messageCommand = messageCommand + " " + splitCommand[i];
}
}
if (splitCommand.length > 1) {
preSub = splitCommand[0] + " " + splitCommand[1];
for (int i = 2; i < splitCommand.length; i++) {
messageSub = messageSub + " " + splitCommand[i];
}
}
if (splitCommand.length > 2) {
preSub2 = splitCommand[0] + " " + splitCommand[1] + " "
+ splitCommand[2];
for (int i = 3; i < splitCommand.length; i++) {
messageSub2 = messageSub2 + " " + splitCommand[i];
}
}
if (splitCommand.length > 3) {
preSub3 = splitCommand[0] + " " + splitCommand[1] + " "
+ splitCommand[2] + " " + splitCommand[3];
for (int i = 4; i < splitCommand.length; i++) {
messageSub3 = messageSub3 + " " + splitCommand[i];
}
}
if (preSub3.length() > 0) {
if (preSub3 != null) {
preSubCheck3 = preSubCheck(player, preSub3);
if (preSubCheck3 < 0) {
price = prePriceCheck(player, preSub3);
cd = preCDCheck(player, preSub3);
limit = preLimitCheck(player, preSub3);
if (cd > 0) {
preSubCheck3 = 0;
} else if (price > 0) {
preSubCheck3 = 0;
} else if (limit > 0) {
preSubCheck3 = 0;
if (boosConfigManager.getWarmupEnabled()) {
for (String warmup : warmups) {
String warmup2 = warmup.replace("*", ".+");
if (message.matches(warmup2)) {
warmupTime = boosConfigManager
.getWarmUp(warmup, player);
boosCoolDown.log.info("Regex: " + warmup + "Command: "
+ message);
if (warmupTime > 0) {
confCmd = warmup;
playerloc.put(player, player.getLocation());
playerworld
.put(player, player.getWorld().getName());
}
}
}
}
if (preSub2.length() > 0) {
if (preSub2 != null && preSubCheck3 < 0) {
preSubCheck2 = preSubCheck(player, preSub2);
if (preSubCheck2 < 0) {
price = prePriceCheck(player, preSub2);
cd = preCDCheck(player, preSub2);
limit = preLimitCheck(player, preSub2);
if (cd > 0) {
preSubCheck2 = 0;
} else if (price > 0) {
preSubCheck2 = 0;
} else if (limit > 0) {
preSubCheck2 = 0;
if (boosConfigManager.getCooldownEnabled()) {
for (String cooldown : cooldowns) {
String cooldown2 = cooldown.replace("*", ".+");
if (message.matches(cooldown2)) {
cooldownTime = boosConfigManager.getCoolDown(cooldown,
player);
if (cooldownTime > 0 && confCmd.equals("")) {
confCmd = cooldown;
}
}
}
}
if (preSub.length() > 0) {
if (preSub.length() < 1 || preSub != null && preSubCheck2 < 0) {
preSubCheck = preSubCheck(player, preSub);
if (preSubCheck < 0) {
price = prePriceCheck(player, preSub);
cd = preCDCheck(player, preSub);
limit = preLimitCheck(player, preSub);
if (cd > 0) {
preSubCheck = 0;
} else if (price > 0) {
preSubCheck = 0;
} else if (limit > 0) {
preSubCheck = 0;
if (boosConfigManager.getPriceEnabled()) {
for (String pric : prices) {
String pric2 = pric.replace("*", ".+");
if (message.matches(pric2)) {
price = boosConfigManager.getPrice(pric, player);
if (price > 0 && confCmd.equals("")) {
confCmd = pric;
}
}
}
}
if (preSubCheck3 >= 0) {
blocked = blocked(player, preSub3, messageSub3);
this.checkCooldown(event, player, preSub3, messageSub3,
preSubCheck3, price);
used = true;
} else if (preSubCheck2 >= 0) {
blocked = blocked(player, preSub2, messageSub2);
this.checkCooldown(event, player, preSub2, messageSub2,
preSubCheck2, price);
used = true;
} else if (preSubCheck >= 0) {
blocked = blocked(player, preSub, messageSub);
this.checkCooldown(event, player, preSub, messageSub,
preSubCheck, price);
used = true;
} else {
blocked = blocked(player, preCommand, messageCommand);
int preCmdCheck = preSubCheck(player, preCommand);
price = prePriceCheck(player, preCommand);
this.checkCooldown(event, player, preCommand, messageCommand,
preCmdCheck, price);
used = true;
if (boosConfigManager.getLimitEnabled()) {
for (String lim : limits) {
String lim2 = lim.replace("*", ".+");
if (message.matches(lim2)) {
limit = boosConfigManager.getLimit(lim, player);
if (limit > -1 && confCmd.equals("")) {
confCmd = lim;
}
}
}
}
blocked = blocked(player, message, limit);
this.checkCooldown(event, player, confCmd, message, warmupTime,
cooldownTime, price);
used = true;
}
if (!used) {
blocked = blocked(player, preCommand, messageCommand);
int preCmdCheck = preSubCheck(player, preCommand);
price = prePriceCheck(player, preCommand);
this.checkCooldown(event, player, preCommand, messageCommand,
preCmdCheck, price);
used = false;
}
if (!used) {
blocked = blocked(player, message, limit);
this.checkCooldown(event, player, confCmd, message, warmupTime,
cooldownTime, price);
used = false;
}
}
@ -253,17 +192,19 @@ public class boosCoolDownListener<a> implements Listener {
String temp = "globalchat";
double price = 0;
Player player = event.getPlayer();
int cooldownTime = boosConfigManager.getCoolDown(temp, player);
if (chatMessage.startsWith("!")) {
if (!boosCoolDownManager.checkCoolDownOK(player, temp, chatMessage)) {
if (!boosCoolDownManager
.checkCoolDownOK(player, temp, cooldownTime)) {
event.setCancelled(true);
return;
} else {
if (boosCoolDownManager.coolDown(player, temp)) {
if (boosCoolDownManager.coolDown(player, temp, cooldownTime)) {
event.setCancelled(true);
return;
}
}
price = prePriceCheck(player, temp);
price = boosConfigManager.getPrice(temp, player);
payForCommand2(event, player, temp, price);
}
}
@ -302,28 +243,12 @@ public class boosCoolDownListener<a> implements Listener {
}
}
private int preCDCheck(Player player, String preSub) {
return boosConfigManager.getCoolDown(preSub, player);
}
private int preLimitCheck(Player player, String preSub) {
return boosConfigManager.getLimit(preSub, player);
}
private double prePriceCheck(Player player, String preSub) {
return boosConfigManager.getPrice(preSub, player);
}
private int preSubCheck(Player player, String preSub) {
return boosConfigManager.getWarmUp(preSub, player);
}
private void start(PlayerCommandPreprocessEvent event, Player player,
String pre, String message, int warmUpSeconds) {
if (!boosCoolDownManager.checkWarmUpOK(player, pre, message)) {
if (boosCoolDownManager.checkCoolDownOK(player, pre, message)) {
String pre, int warmUpSeconds, int cooldownTime) {
if (!boosCoolDownManager.checkWarmUpOK(player, pre)) {
if (boosCoolDownManager.checkCoolDownOK(player, pre, cooldownTime)) {
boosWarmUpManager.startWarmUp(this.plugin, player, pre,
message, warmUpSeconds);
warmUpSeconds);
event.setCancelled(true);
return;
} else {
@ -331,11 +256,11 @@ public class boosCoolDownListener<a> implements Listener {
return;
}
} else {
if (boosCoolDownManager.coolDown(player, pre)) {
if (boosCoolDownManager.coolDown(player, pre, cooldownTime)) {
event.setCancelled(true);
return;
} else {
boosCoolDownManager.removeWarmUpOK(player, pre, message);
boosCoolDownManager.removeWarmUpOK(player, pre);
return;
}
}

View File

@ -140,23 +140,15 @@ public class boosCoolDownManager {
load();
}
static boolean coolDown(Player player, String pre) {
static boolean coolDown(Player player, String pre, int time) {
pre = pre.toLowerCase();
int coolDownSeconds = 0;
coolDownSeconds = getCooldownTime(player, pre);
if (coolDownSeconds > 0
&& !player.hasPermission("booscooldowns.nocooldown")
if (time > 0 && !player.hasPermission("booscooldowns.nocooldown")
&& !player.hasPermission("booscooldowns.nocooldown." + pre)) {
return cd(player, pre, coolDownSeconds);
return cd(player, pre, time);
}
return false;
}
private static int getCooldownTime(Player player, String pre) {
int coolDownSeconds = boosConfigManager.getCoolDown(pre, player);
return coolDownSeconds;
}
static Date getCurrTime() {
String currTime = "";
Calendar cal = Calendar.getInstance();
@ -183,7 +175,7 @@ public class boosCoolDownManager {
usesNum = confusers.getInt("users."
+ player.getName().toLowerCase().hashCode() + ".uses."
+ key, usesNum);
limitNum = boosConfigManager.getLimit(key, player);
limitNum = boosConfigManager.getLimit(key, player);
num = limitNum - usesNum;
if (num < 0) {
num = 0;
@ -219,21 +211,18 @@ public class boosCoolDownManager {
return null;
}
static int getUses(Player player, String pre, String message) {
int pre2 = pre.toLowerCase().hashCode();
static int getUses(Player player, String message) {
int message2 = message.toLowerCase().hashCode();
int uses = 0;
uses = confusers.getInt("users."
+ player.getName().toLowerCase().hashCode() + ".uses." + pre2
+ player.getName().toLowerCase().hashCode() + ".uses."
+ message2, uses);
return uses;
}
static boolean checkCoolDownOK(Player player, String pre, String message) {
static boolean checkCoolDownOK(Player player, String pre, int time) {
pre = pre.toLowerCase();
int coolDownSeconds = 0;
coolDownSeconds = getCooldownTime(player, pre);
if (coolDownSeconds > 0) {
if (time > 0) {
Date lastTime = getTime(player, pre);
if (lastTime == null) {
return true;
@ -243,10 +232,10 @@ public class boosCoolDownManager {
Calendar callastTime = Calendar.getInstance();
callastTime.setTime(lastTime);
long secondsBetween = secondsBetween(callastTime, calcurrTime);
long waitSeconds = coolDownSeconds - secondsBetween;
long waitSeconds = time - secondsBetween;
long waitMinutes = Math.round(waitSeconds / 60) + 1;
long waitHours = Math.round(waitMinutes / 60) + 1;
if (secondsBetween > coolDownSeconds) {
if (secondsBetween > time) {
return true;
} else {
String msg = boosConfigManager.getCoolDownMessage();
@ -275,7 +264,7 @@ public class boosCoolDownManager {
return true;
}
static boolean checkWarmUpOK(Player player, String pre, String message) {
static boolean checkWarmUpOK(Player player, String pre) {
int pre2 = pre.toLowerCase().hashCode();
int ok = 0;
ok = confusers.getInt(
@ -299,13 +288,13 @@ public class boosCoolDownManager {
}
}
static void removeWarmUp(Player player, String pre, String message) {
static void removeWarmUp(Player player, String pre) {
int pre2 = pre.toLowerCase().hashCode();
confusers.set("users." + player.getName().toLowerCase().hashCode()
+ ".warmup." + pre2, null);
}
static void removeWarmUpOK(Player player, String pre, String message) {
static void removeWarmUpOK(Player player, String pre) {
int pre2 = pre.toLowerCase().hashCode();
confusers.set("users." + player.getName().toLowerCase().hashCode()
+ ".warmup." + pre2, null);
@ -343,14 +332,13 @@ public class boosCoolDownManager {
static void setUses(Player player, String pre, String message) {
if (boosConfigManager.getLimitsEnabled()) {
if (boosConfigManager.getLimits(player).contains(pre)) {
int pre2 = pre.toLowerCase().hashCode();
int message2 = message.toLowerCase().hashCode();
int uses = getUses(player, pre, message);
int uses = getUses(player, message);
uses = uses + 1;
try {
confusers.set("users."
+ player.getName().toLowerCase().hashCode()
+ ".uses." + pre2 + message2, uses);
+ ".uses." + message2, uses);
} catch (IllegalArgumentException e) {
boosCoolDown.log.warning("Player " + player.getName()
+ " used empty command and caused this error!");
@ -361,7 +349,7 @@ public class boosCoolDownManager {
}
}
static void setWarmUpOK(Player player, String pre, String message) {
static void setWarmUpOK(Player player, String pre) {
int pre2 = pre.toLowerCase().hashCode();
confusers.set("users." + player.getName().toLowerCase().hashCode()
+ ".warmup." + pre2, 1);
@ -369,7 +357,8 @@ public class boosCoolDownManager {
public static void startAllCooldowns(Player player) {
for (String a : boosConfigManager.getCooldowns(player)) {
coolDown(player, a);
int cooldownTime = boosConfigManager.getCoolDown(a, player);
coolDown(player, a, cooldownTime);
}
}

View File

@ -10,8 +10,8 @@ import util.boosChat;
public class boosPriceManager {
private static Economy economy = boosCoolDown.getEconomy();
public static boolean payForCommand(Player player, String pre, double price,
String name) {
public static boolean payForCommand(Player player, String pre,
double price, String name) {
if (economy == null) {
return true;
}

View File

@ -15,6 +15,18 @@ public class boosWarmUpManager {
static Timer scheduler;
public static void applyPotionEffect(Player player, String pre,
int warmUpSeconds) {
String potionTemp = boosConfigManager.getPotionEffect(pre);
if (potionTemp == null)
return;
String[] potion = potionTemp.split("@");
PotionEffectType effect = PotionEffectType.getByName(potion[0]);
player.addPotionEffect(
effect.createEffect(warmUpSeconds * 40,
Integer.parseInt(potion[1]) - 1), true);
}
public static void cancelWarmUps(Player player) {
Iterator<String> iter = playercommands.keySet().iterator();
while (iter.hasNext()) {
@ -34,15 +46,6 @@ public class boosWarmUpManager {
return false;
}
public static boolean isWarmUpProcess(Player player, String pre,
String message) {
pre = pre.toLowerCase();
if (playercommands.containsKey(player.getName() + "@" + pre)) {
return true;
}
return false;
}
// public static void cancelWarmUps(Player player) {
// for (String key : playercommands.keySet()) {
// if (key.startsWith(player.getName() + "@")) {
@ -51,6 +54,14 @@ public class boosWarmUpManager {
// }
// }
public static boolean isWarmUpProcess(Player player, String pre) {
pre = pre.toLowerCase();
if (playercommands.containsKey(player.getName() + "@" + pre)) {
return true;
}
return false;
}
public static void killTimer(Player player) {
for (String key : playercommands.keySet()) {
if (key.startsWith(player.getName() + "@")) {
@ -64,12 +75,12 @@ public class boosWarmUpManager {
}
public static void startWarmUp(boosCoolDown bCoolDown, Player player,
String pre, String message, int warmUpSeconds) {
String pre, int warmUpSeconds) {
pre = pre.toLowerCase();
long warmUpMinutes = Math.round(warmUpSeconds / 60);
long warmUpHours = Math.round(warmUpMinutes / 60);
if (!isWarmUpProcess(player, pre, message)) {
boosCoolDownManager.removeWarmUpOK(player, pre, message);
if (!isWarmUpProcess(player, pre)) {
boosCoolDownManager.removeWarmUpOK(player, pre);
String msg = boosConfigManager.getWarmUpMessage();
msg = msg.replaceAll("&command&", pre);
if (warmUpSeconds >= 60 && 3600 >= warmUpSeconds) {
@ -89,24 +100,14 @@ public class boosWarmUpManager {
scheduler = new Timer();
boosWarmUpTimer scheduleMe = new boosWarmUpTimer(bCoolDown,
scheduler, player, pre, message);
scheduler, player, pre);
playercommands.put(player.getName() + "@" + pre, scheduleMe);
scheduler.schedule(scheduleMe, warmUpSeconds * 1000);
applyPotionEffect(player, pre, message, warmUpSeconds);
applyPotionEffect(player, pre, warmUpSeconds);
} else {
String msg = boosConfigManager.getWarmUpAlreadyStartedMessage();
msg = msg.replaceAll("&command&", pre);
boosChat.sendMessageToPlayer(player, msg);
}
}
public static void applyPotionEffect(Player player, String pre,
String message, int warmUpSeconds) {
String potionTemp = boosConfigManager.getPotionEffect(pre);
if (potionTemp == null)
return;
String[] potion = potionTemp.split("@");
PotionEffectType effect = PotionEffectType.getByName(potion[0]);
player.addPotionEffect(effect.createEffect(warmUpSeconds*40, Integer.parseInt(potion[1])-1), true);
}
}

View File

@ -7,20 +7,44 @@ import org.bukkit.entity.Player;
public class boosWarmUpTimer extends TimerTask {
public class boosWarmUpRunnable implements Runnable {
@Override
public void run() {
if (player.isOnline() && !player.isDead()
&& boosWarmUpManager.hasWarmUps(player)) {
boosCoolDownManager.setWarmUpOK(player, pre);
boosWarmUpManager.removeWarmUpProcess(player.getName() + "@"
+ pre);
boosCoolDownListener.clearLocWorld(player);
player.chat(pre);
} else if (player.isOnline() && player.isDead()
&& boosWarmUpManager.hasWarmUps(player)) {
boosCoolDownManager.removeWarmUp(player, pre);
boosWarmUpManager.removeWarmUpProcess(player.getName() + "@"
+ pre);
boosCoolDownListener.clearLocWorld(player);
} else if (!player.isOnline()
&& boosWarmUpManager.hasWarmUps(player)) {
boosCoolDownManager.removeWarmUp(player, pre);
boosWarmUpManager.removeWarmUpProcess(player.getName() + "@"
+ pre);
boosCoolDownListener.clearLocWorld(player);
}
}
}
private boosCoolDown bCoolDown;
private Player player;
private String pre;
private String message;
public boosWarmUpTimer() {
}
public boosWarmUpTimer(boosCoolDown bCoolDown, Timer timer, Player player,
String pre, String message) {
String pre) {
this.bCoolDown = bCoolDown;
this.player = player;
this.pre = pre;
this.message = message;
}
public boosWarmUpTimer() {
}
@Override
@ -28,29 +52,4 @@ public class boosWarmUpTimer extends TimerTask {
bCoolDown.getServer().getScheduler()
.scheduleSyncDelayedTask(bCoolDown, new boosWarmUpRunnable());
}
public class boosWarmUpRunnable implements Runnable {
public void run() {
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)) {
boosCoolDownManager.removeWarmUp(player, pre, message);
boosWarmUpManager.removeWarmUpProcess(player.getName() + "@"
+ pre);
boosCoolDownListener.clearLocWorld(player);
} else if (!player.isOnline()
&& boosWarmUpManager.hasWarmUps(player)) {
boosCoolDownManager.removeWarmUp(player, pre, message);
boosWarmUpManager.removeWarmUpProcess(player.getName() + "@"
+ pre);
boosCoolDownListener.clearLocWorld(player);
}
}
}
}

View File

@ -70,6 +70,43 @@ public class MetricsLite {
*/
private final static int PING_INTERVAL = 10;
/**
* 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");
}
/**
* <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));
}
/**
* The plugin this metrics submits for
*/
@ -134,93 +171,27 @@ public class MetricsLite {
}
/**
* 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.
* Disables metrics for the server by setting "opt-out" to true in the
* config file and canceling the metrics task.
*
* @return True if statistics measuring is running, otherwise false.
* @throws java.io.IOException
*/
public boolean start() {
public void disable() throws IOException {
// This has to be synchronized or it can collide with the check in the
// task.
synchronized (optOutLock) {
// Did we opt out?
if (isOptOut()) {
return false;
// Check if the server owner has already set opt-out, if not, set
// it.
if (!isOptOut()) {
configuration.set("opt-out", true);
configuration.save(configurationFile);
}
// Is metrics already running?
// Disable Task, if it is running
if (task != null) {
return true;
task.cancel();
task = null;
}
// Begin hitting the server with glorious data
task = plugin.getServer().getScheduler()
.runTaskTimerAsynchronously(plugin, new Runnable() {
private boolean firstPost = true;
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;
}
}
// 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);
// 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);
return true;
}
}
/**
* 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);
}
}
@ -248,31 +219,6 @@ public class MetricsLite {
}
}
/**
* 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);
}
// Disable Task, if it is running
if (task != null) {
task.cancel();
task = null;
}
}
}
/**
* Gets the File object of the config file that should be used to store data
* such as the GUID and opt-out status
@ -292,6 +238,48 @@ public class MetricsLite {
return new File(new File(pluginsFolder, "PluginMetrics"), "config.yml");
}
/**
* 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;
}
}
/**
* 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);
}
}
/**
* Generic method that posts a plugin to the metrics website
*/
@ -383,55 +371,68 @@ public class MetricsLite {
}
/**
* Check if mineshafter is present. If it is, we need to bypass it to send
* POST requests
* 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 mineshafter is installed on the server
* @return True if statistics measuring is running, otherwise false.
*/
private boolean isMineshafterPresent() {
try {
Class.forName("mineshafter.MineServer");
public boolean start() {
synchronized (optOutLock) {
// Did we opt out?
if (isOptOut()) {
return false;
}
// Is metrics already running?
if (task != null) {
return true;
}
// Begin hitting the server with glorious data
task = plugin.getServer().getScheduler()
.runTaskTimerAsynchronously(plugin, new Runnable() {
private boolean firstPost = true;
@Override
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;
}
}
// 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);
// 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);
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.5.0
version: 3.6.0 BETA
authors: [LordBoos (ingame name boosik)]
softdepend: [Vault]
description: >
@ -67,54 +67,6 @@ permissions:
booscooldowns.nolimit./command:
description: Command "/command" will not be affected by limits for users with this permission.
default: false
booscooldowns.warmup2:
description: Player will be affected by warmup2 group. Players without this permission, will be affected by default warmups.
default: false
booscooldowns.warmup3:
description: Player will be affected by warmup3 group. Players without this permission, will be affected by default warmups.
default: false
booscooldowns.warmup4:
description: Player will be affected by warmup4 group. Players without this permission, will be affected by default warmups.
default: false
booscooldowns.warmup5:
description: Player will be affected by warmup5 group. Players without this permission, will be affected by default warmups.
default: false
booscooldowns.price2:
description: Player will be affected by price2 group. Players without this permission, will be affected by default prices.
default: false
booscooldowns.price3:
description: Player will be affected by price3 group. Players without this permission, will be affected by default prices.
default: false
booscooldowns.price4:
description: Player will be affected by price4 group. Players without this permission, will be affected by default prices.
default: false
booscooldowns.price5:
description: Player will be affected by price5 group. Players without this permission, will be affected by default prices.
default: false
booscooldowns.cooldown2:
description: Player will be affected by cooldown2 group. Players without this permission, will be affected by default cooldowns.
default: false
booscooldowns.cooldown3:
description: Player will be affected by cooldown3 group. Players without this permission, will be affected by default cooldowns.
default: false
booscooldowns.cooldown4:
description: Player will be affected by cooldown4 group. Players without this permission, will be affected by default cooldowns.
default: false
booscooldowns.cooldown5:
description: Player will be affected by cooldown5 group. Players without this permission, will be affected by default cooldowns.
default: false
booscooldowns.limit2:
description: Player will be affected by limit2 group. Players without this permission, will be affected by default limits.
default: false
booscooldowns.limit3:
description: Player will be affected by limit3 group. Players without this permission, will be affected by default limits.
default: false
booscooldowns.limit4:
description: Player will be affected by limit4 group. Players without this permission, will be affected by default limits.
default: false
booscooldowns.limit5:
description: Player will be affected by limit5 group. Players without this permission, will be affected by default limits.
default: false
booscooldowns.reload:
description: Player can use "/booscooldowns reload" to reload config file.
default: op

View File

@ -14,6 +14,57 @@ public class boosChat {
static List<String> Colors = new LinkedList<String>();
static Server server;
public static void broadcastMessage(String message) {
message = boosChat.replaceColorCodes(message);
log.info("[bColoredChat] " + message);
server.broadcastMessage(message);
}
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 sendMessageToCommandSender(CommandSender sender,
String message) {
if (sender instanceof Player) {
boosChat.sendMessageToPlayer((Player) sender, message);
} else {
boosChat.sendMessageToServer(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 boosChat(Server server) {
Colors.add("&black&");
Colors.add("&darkblue&");
@ -49,55 +100,4 @@ public class boosChat {
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);
}
}
}