diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..54e493c --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bin/cz/boosik/boosCooldown/Listeners/boosPlayerMoveListener.class b/bin/cz/boosik/boosCooldown/Listeners/boosPlayerMoveListener.class index caeabac..a3abdbc 100644 Binary files a/bin/cz/boosik/boosCooldown/Listeners/boosPlayerMoveListener.class and b/bin/cz/boosik/boosCooldown/Listeners/boosPlayerMoveListener.class differ diff --git a/bin/cz/boosik/boosCooldown/boosConfigManager.class b/bin/cz/boosik/boosCooldown/boosConfigManager.class index 8442647..b555116 100644 Binary files a/bin/cz/boosik/boosCooldown/boosConfigManager.class and b/bin/cz/boosik/boosCooldown/boosConfigManager.class differ diff --git a/bin/cz/boosik/boosCooldown/boosCoolDown.class b/bin/cz/boosik/boosCooldown/boosCoolDown.class index ba6546c..712e192 100644 Binary files a/bin/cz/boosik/boosCooldown/boosCoolDown.class and b/bin/cz/boosik/boosCooldown/boosCoolDown.class differ diff --git a/bin/cz/boosik/boosCooldown/boosCoolDownListener.class b/bin/cz/boosik/boosCooldown/boosCoolDownListener.class index 84204f4..9a6d679 100644 Binary files a/bin/cz/boosik/boosCooldown/boosCoolDownListener.class and b/bin/cz/boosik/boosCooldown/boosCoolDownListener.class differ diff --git a/bin/cz/boosik/boosCooldown/boosCoolDownManager.class b/bin/cz/boosik/boosCooldown/boosCoolDownManager.class index e48baf5..840a9b5 100644 Binary files a/bin/cz/boosik/boosCooldown/boosCoolDownManager.class and b/bin/cz/boosik/boosCooldown/boosCoolDownManager.class differ diff --git a/bin/cz/boosik/boosCooldown/boosWarmUpManager.class b/bin/cz/boosik/boosCooldown/boosWarmUpManager.class index d4f00c0..756dc41 100644 Binary files a/bin/cz/boosik/boosCooldown/boosWarmUpManager.class and b/bin/cz/boosik/boosCooldown/boosWarmUpManager.class differ diff --git a/bin/cz/boosik/boosCooldown/boosWarmUpTimer$boosWarmUpRunnable.class b/bin/cz/boosik/boosCooldown/boosWarmUpTimer$boosWarmUpRunnable.class index 0fe76d6..1030121 100644 Binary files a/bin/cz/boosik/boosCooldown/boosWarmUpTimer$boosWarmUpRunnable.class and b/bin/cz/boosik/boosCooldown/boosWarmUpTimer$boosWarmUpRunnable.class differ diff --git a/bin/cz/boosik/boosCooldown/boosWarmUpTimer.class b/bin/cz/boosik/boosCooldown/boosWarmUpTimer.class index 6469884..6d750fa 100644 Binary files a/bin/cz/boosik/boosCooldown/boosWarmUpTimer.class and b/bin/cz/boosik/boosCooldown/boosWarmUpTimer.class differ diff --git a/bin/org/mcstats/MetricsLite$1.class b/bin/org/mcstats/MetricsLite$1.class index 7894887..9efb79f 100644 Binary files a/bin/org/mcstats/MetricsLite$1.class and b/bin/org/mcstats/MetricsLite$1.class differ diff --git a/bin/org/mcstats/MetricsLite.class b/bin/org/mcstats/MetricsLite.class index 0215e8f..7a75a33 100644 Binary files a/bin/org/mcstats/MetricsLite.class and b/bin/org/mcstats/MetricsLite.class differ diff --git a/bin/plugin.yml b/bin/plugin.yml index adca408..77e4137 100644 --- a/bin/plugin.yml +++ b/bin/plugin.yml @@ -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 diff --git a/bin/util/boosChat.class b/bin/util/boosChat.class index 789177a..2acf5c1 100644 Binary files a/bin/util/boosChat.class and b/bin/util/boosChat.class differ diff --git a/src/cz/boosik/boosCooldown/Listeners/boosPlayerMoveListener.java b/src/cz/boosik/boosCooldown/Listeners/boosPlayerMoveListener.java index 5ecb645..ff40083 100644 --- a/src/cz/boosik/boosCooldown/Listeners/boosPlayerMoveListener.java +++ b/src/cz/boosik/boosCooldown/Listeners/boosPlayerMoveListener.java @@ -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; + } + } } \ No newline at end of file diff --git a/src/cz/boosik/boosCooldown/Listeners/boosSignChangeListener.java b/src/cz/boosik/boosCooldown/Listeners/boosSignChangeListener.java index 77ad890..d2b7529 100644 --- a/src/cz/boosik/boosCooldown/Listeners/boosSignChangeListener.java +++ b/src/cz/boosik/boosCooldown/Listeners/boosSignChangeListener.java @@ -12,9 +12,9 @@ import cz.boosik.boosCooldown.boosConfigManager; public class boosSignChangeListener implements Listener { @EventHandler(priority = EventPriority.NORMAL) public void onSignChange(SignChangeEvent event) { - if (event.isCancelled()) + if (event.isCancelled()) return; - + Player player = event.getPlayer(); String line1 = event.getLine(0); String line2 = event.getLine(1); diff --git a/src/cz/boosik/boosCooldown/Listeners/boosSignInteractListener.java b/src/cz/boosik/boosCooldown/Listeners/boosSignInteractListener.java index 1df4d1a..5e77965 100644 --- a/src/cz/boosik/boosCooldown/Listeners/boosSignInteractListener.java +++ b/src/cz/boosik/boosCooldown/Listeners/boosSignInteractListener.java @@ -23,9 +23,9 @@ public class boosSignInteractListener implements Listener { @EventHandler(priority = EventPriority.NORMAL) private void onSignInteract(PlayerInteractEvent event) { String msg; - if (event.isCancelled()) + if (event.isCancelled()) return; - + if (event.hasBlock() && event.getAction() == Action.RIGHT_CLICK_BLOCK) { if (event.getClickedBlock().getType() == Material.SIGN_POST || event.getClickedBlock().getType() == Material.WALL_SIGN) { diff --git a/src/cz/boosik/boosCooldown/boosConfigManager.java b/src/cz/boosik/boosCooldown/boosConfigManager.java index e96c3a4..83446d4 100644 --- a/src/cz/boosik/boosCooldown/boosConfigManager.java +++ b/src/cz/boosik/boosCooldown/boosConfigManager.java @@ -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 getAliases() { + Set 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 getCooldownGroups() { Set groups = conf.getConfigurationSection("commands.cooldowns") .getKeys(false); @@ -160,12 +163,6 @@ public class boosConfigManager { return lim; } - private static Set getLimitGroups() { - Set 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 getLimitGroups() { + Set 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 getPriceGroups() { + Set 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 getPriceGroups() { - Set groups = conf.getConfigurationSection("commands.prices") - .getKeys(false); - return groups; + public static Set getPrices(Player player) { + String price = getPriceGrp(player); + Set 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 getWarmupGroups() { Set 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", diff --git a/src/cz/boosik/boosCooldown/boosCoolDown.java b/src/cz/boosik/boosCooldown/boosCoolDown.java index b2c40f1..cbd9370 100644 --- a/src/cz/boosik/boosCooldown/boosCoolDown.java +++ b/src/cz/boosik/boosCooldown/boosCoolDown.java @@ -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(); } diff --git a/src/cz/boosik/boosCooldown/boosCoolDownListener.java b/src/cz/boosik/boosCooldown/boosCoolDownListener.java index 806ff11..f092673 100644 --- a/src/cz/boosik/boosCooldown/boosCoolDownListener.java +++ b/src/cz/boosik/boosCooldown/boosCoolDownListener.java @@ -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 implements Listener { @@ -28,40 +27,38 @@ public class boosCoolDownListener 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 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 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 aliases = boosConfigManager.getAliases(); + Set warmups = boosConfigManager.getWarmups(player); + Set cooldowns = boosConfigManager.getCooldowns(player); + Set limits = boosConfigManager.getLimits(player); + Set 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 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 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 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 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; } } diff --git a/src/cz/boosik/boosCooldown/boosCoolDownManager.java b/src/cz/boosik/boosCooldown/boosCoolDownManager.java index 5513496..5d65b5f 100644 --- a/src/cz/boosik/boosCooldown/boosCoolDownManager.java +++ b/src/cz/boosik/boosCooldown/boosCoolDownManager.java @@ -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); } } diff --git a/src/cz/boosik/boosCooldown/boosPriceManager.java b/src/cz/boosik/boosCooldown/boosPriceManager.java index ea68f54..d498391 100644 --- a/src/cz/boosik/boosCooldown/boosPriceManager.java +++ b/src/cz/boosik/boosCooldown/boosPriceManager.java @@ -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; } diff --git a/src/cz/boosik/boosCooldown/boosWarmUpManager.java b/src/cz/boosik/boosCooldown/boosWarmUpManager.java index 25f653b..70ef792 100644 --- a/src/cz/boosik/boosCooldown/boosWarmUpManager.java +++ b/src/cz/boosik/boosCooldown/boosWarmUpManager.java @@ -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 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); - } } diff --git a/src/cz/boosik/boosCooldown/boosWarmUpTimer.java b/src/cz/boosik/boosCooldown/boosWarmUpTimer.java index 77bc13a..af46210 100644 --- a/src/cz/boosik/boosCooldown/boosWarmUpTimer.java +++ b/src/cz/boosik/boosCooldown/boosWarmUpTimer.java @@ -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); - } - } - } } \ No newline at end of file diff --git a/src/org/mcstats/MetricsLite.java b/src/org/mcstats/MetricsLite.java index 6bc62c4..d6e5b81 100644 --- a/src/org/mcstats/MetricsLite.java +++ b/src/org/mcstats/MetricsLite.java @@ -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"); + } + + /** + *

+ * 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: + *

+ * + * StringBuffer data = new StringBuffer(); + * data.append(encode("guid")).append('=').append(encode(guid)); + * encodeDataPair(data, "version", description.getVersion()); + * + * + * @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; } } - /** - *

- * 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: - *

- * - * StringBuffer data = new StringBuffer(); - * data.append(encode("guid")).append('=').append(encode(guid)); - * encodeDataPair(data, "version", description.getVersion()); - * - * - * @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"); - } - } \ No newline at end of file diff --git a/src/plugin.yml b/src/plugin.yml index adca408..77e4137 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -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 diff --git a/src/util/boosChat.java b/src/util/boosChat.java index 8eab3c7..155d2f7 100644 --- a/src/util/boosChat.java +++ b/src/util/boosChat.java @@ -14,6 +14,57 @@ public class boosChat { static List Colors = new LinkedList(); 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); - } - } }