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 name: boosCooldowns
main: cz.boosik.boosCooldown.boosCoolDown main: cz.boosik.boosCooldown.boosCoolDown
version: 3.5.0 version: 3.6.0 BETA
authors: [LordBoos (ingame name boosik)] authors: [LordBoos (ingame name boosik)]
softdepend: [Vault] softdepend: [Vault]
description: > description: >
@ -67,54 +67,6 @@ permissions:
booscooldowns.nolimit./command: booscooldowns.nolimit./command:
description: Command "/command" will not be affected by limits for users with this permission. description: Command "/command" will not be affected by limits for users with this permission.
default: false 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: booscooldowns.reload:
description: Player can use "/booscooldowns reload" to reload config file. description: Player can use "/booscooldowns reload" to reload config file.
default: op default: op

Binary file not shown.

View File

@ -12,30 +12,6 @@ import cz.boosik.boosCooldown.boosCoolDownListener;
import cz.boosik.boosCooldown.boosWarmUpManager; import cz.boosik.boosCooldown.boosWarmUpManager;
public class boosPlayerMoveListener implements Listener { 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) { private static boolean hasMoved(Player player) {
String curworld = player.getWorld().getName(); String curworld = player.getWorld().getName();
String cmdworld = boosCoolDownListener.playerworld.get(player); String cmdworld = boosCoolDownListener.playerworld.get(player);
@ -49,4 +25,29 @@ public class boosPlayerMoveListener implements Listener {
return false; 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

@ -12,9 +12,9 @@ import cz.boosik.boosCooldown.boosConfigManager;
public class boosSignChangeListener implements Listener { public class boosSignChangeListener implements Listener {
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL)
public void onSignChange(SignChangeEvent event) { public void onSignChange(SignChangeEvent event) {
if (event.isCancelled()) if (event.isCancelled())
return; return;
Player player = event.getPlayer(); Player player = event.getPlayer();
String line1 = event.getLine(0); String line1 = event.getLine(0);
String line2 = event.getLine(1); String line2 = event.getLine(1);

View File

@ -23,9 +23,9 @@ public class boosSignInteractListener implements Listener {
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL)
private void onSignInteract(PlayerInteractEvent event) { private void onSignInteract(PlayerInteractEvent event) {
String msg; String msg;
if (event.isCancelled()) if (event.isCancelled())
return; return;
if (event.hasBlock() && event.getAction() == Action.RIGHT_CLICK_BLOCK) { if (event.hasBlock() && event.getAction() == Action.RIGHT_CLICK_BLOCK) {
if (event.getClickedBlock().getType() == Material.SIGN_POST if (event.getClickedBlock().getType() == Material.SIGN_POST
|| event.getClickedBlock().getType() == Material.WALL_SIGN) { || event.getClickedBlock().getType() == Material.WALL_SIGN) {

View File

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

View File

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

View File

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

View File

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

View File

@ -15,6 +15,18 @@ public class boosWarmUpManager {
static Timer scheduler; 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) { public static void cancelWarmUps(Player player) {
Iterator<String> iter = playercommands.keySet().iterator(); Iterator<String> iter = playercommands.keySet().iterator();
while (iter.hasNext()) { while (iter.hasNext()) {
@ -34,15 +46,6 @@ public class boosWarmUpManager {
return false; 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) { // public static void cancelWarmUps(Player player) {
// for (String key : playercommands.keySet()) { // for (String key : playercommands.keySet()) {
// if (key.startsWith(player.getName() + "@")) { // 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) { public static void killTimer(Player player) {
for (String key : playercommands.keySet()) { for (String key : playercommands.keySet()) {
if (key.startsWith(player.getName() + "@")) { if (key.startsWith(player.getName() + "@")) {
@ -64,12 +75,12 @@ public class boosWarmUpManager {
} }
public static void startWarmUp(boosCoolDown bCoolDown, Player player, public static void startWarmUp(boosCoolDown bCoolDown, Player player,
String pre, String message, int warmUpSeconds) { String pre, int warmUpSeconds) {
pre = pre.toLowerCase(); pre = pre.toLowerCase();
long warmUpMinutes = Math.round(warmUpSeconds / 60); long warmUpMinutes = Math.round(warmUpSeconds / 60);
long warmUpHours = Math.round(warmUpMinutes / 60); long warmUpHours = Math.round(warmUpMinutes / 60);
if (!isWarmUpProcess(player, pre, message)) { if (!isWarmUpProcess(player, pre)) {
boosCoolDownManager.removeWarmUpOK(player, pre, message); boosCoolDownManager.removeWarmUpOK(player, pre);
String msg = boosConfigManager.getWarmUpMessage(); String msg = boosConfigManager.getWarmUpMessage();
msg = msg.replaceAll("&command&", pre); msg = msg.replaceAll("&command&", pre);
if (warmUpSeconds >= 60 && 3600 >= warmUpSeconds) { if (warmUpSeconds >= 60 && 3600 >= warmUpSeconds) {
@ -89,24 +100,14 @@ public class boosWarmUpManager {
scheduler = new Timer(); scheduler = new Timer();
boosWarmUpTimer scheduleMe = new boosWarmUpTimer(bCoolDown, boosWarmUpTimer scheduleMe = new boosWarmUpTimer(bCoolDown,
scheduler, player, pre, message); scheduler, player, pre);
playercommands.put(player.getName() + "@" + pre, scheduleMe); playercommands.put(player.getName() + "@" + pre, scheduleMe);
scheduler.schedule(scheduleMe, warmUpSeconds * 1000); scheduler.schedule(scheduleMe, warmUpSeconds * 1000);
applyPotionEffect(player, pre, message, warmUpSeconds); applyPotionEffect(player, pre, warmUpSeconds);
} else { } else {
String msg = boosConfigManager.getWarmUpAlreadyStartedMessage(); String msg = boosConfigManager.getWarmUpAlreadyStartedMessage();
msg = msg.replaceAll("&command&", pre); msg = msg.replaceAll("&command&", pre);
boosChat.sendMessageToPlayer(player, msg); 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 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 boosCoolDown bCoolDown;
private Player player; private Player player;
private String pre; private String pre;
private String message;
public boosWarmUpTimer() {
}
public boosWarmUpTimer(boosCoolDown bCoolDown, Timer timer, Player player, public boosWarmUpTimer(boosCoolDown bCoolDown, Timer timer, Player player,
String pre, String message) { String pre) {
this.bCoolDown = bCoolDown; this.bCoolDown = bCoolDown;
this.player = player; this.player = player;
this.pre = pre; this.pre = pre;
this.message = message;
}
public boosWarmUpTimer() {
} }
@Override @Override
@ -28,29 +52,4 @@ public class boosWarmUpTimer extends TimerTask {
bCoolDown.getServer().getScheduler() bCoolDown.getServer().getScheduler()
.scheduleSyncDelayedTask(bCoolDown, new boosWarmUpRunnable()); .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; 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 * The plugin this metrics submits for
*/ */
@ -134,93 +171,27 @@ public class MetricsLite {
} }
/** /**
* Start measuring statistics. This will immediately create an async * Disables metrics for the server by setting "opt-out" to true in the
* repeating task as the plugin and send the initial data to the metrics * config file and canceling the metrics task.
* backend, and then after that it will post in increments of PING_INTERVAL
* * 1200 ticks.
* *
* @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) { synchronized (optOutLock) {
// Did we opt out? // Check if the server owner has already set opt-out, if not, set
if (isOptOut()) { // it.
return false; if (!isOptOut()) {
configuration.set("opt-out", true);
configuration.save(configurationFile);
} }
// Is metrics already running? // Disable Task, if it is running
if (task != null) { 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 * Gets the File object of the config file that should be used to store data
* such as the GUID and opt-out status * such as the GUID and opt-out status
@ -292,6 +238,48 @@ public class MetricsLite {
return new File(new File(pluginsFolder, "PluginMetrics"), "config.yml"); 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 * 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 * Start measuring statistics. This will immediately create an async
* POST requests * 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() { public boolean start() {
try { synchronized (optOutLock) {
Class.forName("mineshafter.MineServer"); // 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; 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 name: boosCooldowns
main: cz.boosik.boosCooldown.boosCoolDown main: cz.boosik.boosCooldown.boosCoolDown
version: 3.5.0 version: 3.6.0 BETA
authors: [LordBoos (ingame name boosik)] authors: [LordBoos (ingame name boosik)]
softdepend: [Vault] softdepend: [Vault]
description: > description: >
@ -67,54 +67,6 @@ permissions:
booscooldowns.nolimit./command: booscooldowns.nolimit./command:
description: Command "/command" will not be affected by limits for users with this permission. description: Command "/command" will not be affected by limits for users with this permission.
default: false 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: booscooldowns.reload:
description: Player can use "/booscooldowns reload" to reload config file. description: Player can use "/booscooldowns reload" to reload config file.
default: op default: op

View File

@ -14,6 +14,57 @@ public class boosChat {
static List<String> Colors = new LinkedList<String>(); static List<String> Colors = new LinkedList<String>();
static Server server; 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) { public boosChat(Server server) {
Colors.add("&black&"); Colors.add("&black&");
Colors.add("&darkblue&"); Colors.add("&darkblue&");
@ -49,55 +100,4 @@ public class boosChat {
Colors.add("&f"); Colors.add("&f");
boosChat.server = server; 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);
}
}
} }