From 1697351805dcfb38eae7d28d1ab8d8411c852205 Mon Sep 17 00:00:00 2001 From: Steffion Date: Sat, 28 Sep 2013 20:41:33 +0200 Subject: [PATCH] + Added Custom Graph for MCStats. --- src/nl/Steffion/BlockHunt/BlockHunt.java | 79 ++++++++++++++++++------ 1 file changed, 60 insertions(+), 19 deletions(-) diff --git a/src/nl/Steffion/BlockHunt/BlockHunt.java b/src/nl/Steffion/BlockHunt/BlockHunt.java index 8213466..75e8b06 100644 --- a/src/nl/Steffion/BlockHunt/BlockHunt.java +++ b/src/nl/Steffion/BlockHunt/BlockHunt.java @@ -41,6 +41,7 @@ import nl.Steffion.BlockHunt.Managers.MessageM; import nl.Steffion.BlockHunt.Managers.PermissionsM; import nl.Steffion.BlockHunt.Serializables.LocationSerializable; import nl.Steffion.BlockHunt.mcstats.Metrics; +import nl.Steffion.BlockHunt.mcstats.Metrics.Graph; import org.bukkit.Bukkit; import org.bukkit.GameMode; @@ -79,6 +80,7 @@ public class BlockHunt extends JavaPlugin implements Listener { */ public static PluginDescriptionFile pdfFile; + public static BlockHunt plugin; @SuppressWarnings("serial") public static List BlockHuntCMD = new ArrayList() { @@ -117,7 +119,6 @@ public class BlockHunt extends JavaPlugin implements Listener { public static CommandM CMDtokens; public void onEnable() { - getServer().getPluginManager().registerEvents(this, this); getServer().getPluginManager().registerEvents(new OnBlockBreakEvent(), @@ -234,25 +235,65 @@ public class BlockHunt extends JavaPlugin implements Listener { ArenaHandler.loadArenas(); - try { - Metrics metrics = new Metrics(this); - metrics.start(); - FileConfiguration metrics_fc = new YamlConfiguration(); - metrics_fc.load(metrics.getConfigFile()); - if (!metrics_fc.getBoolean("opt-out", false)) { - MessageM.sendMessage(null, - "%TAG%NSending %AMCStats %Nto their server."); - } else { - MessageM.sendMessage(null, - "%TAG%EUnable to send %AMCStats %Eto their server. %AMCStats%E is disabled?"); + Bukkit.getScheduler().runTaskTimer(this, new Runnable() { + + @Override + public void run() { + try { + Metrics metrics = new Metrics(plugin); + Graph playersPlayingBlockHunt = metrics + .createGraph("Players playing BlockHunt"); + + playersPlayingBlockHunt.addPlotter(new Metrics.Plotter( + "Playing") { + + @Override + public int getValue() { + int playersPlaying = 0; + for (Arena arena : W.arenaList) { + playersPlaying = playersPlaying + + arena.playersInArena.size(); + } + return playersPlaying; + } + + }); + + playersPlayingBlockHunt.addPlotter(new Metrics.Plotter( + "Not playing") { + + @Override + public int getValue() { + int playersPlaying = 0; + for (Arena arena : W.arenaList) { + playersPlaying = playersPlaying + + arena.playersInArena.size(); + } + return Bukkit.getOnlinePlayers().length + - playersPlaying; + } + + }); + + metrics.start(); + FileConfiguration metrics_fc = new YamlConfiguration(); + metrics_fc.load(metrics.getConfigFile()); + if (!metrics_fc.getBoolean("opt-out", false)) { + MessageM.sendMessage(null, + "%TAG%NSending %AMCStats%N to the server..."); + } else { + MessageM.sendMessage(null, + "%TAG%EUnable to send %AMCStats %Eto the server. %AMCStats%E is disabled?"); + } + } catch (IOException e) { + MessageM.sendMessage(null, + "%TAG%EUnable to send %AMCStats %Eto the server. Something went wrong ;(!"); + } catch (InvalidConfigurationException e) { + MessageM.sendMessage(null, + "%TAG%EUnable to send %AMCStats %Eto the server. Something went wrong ;(!"); + } } - } catch (IOException e) { - MessageM.sendMessage(null, - "%TAG%EUnable to send %AMCStats %Eto their server. Something went wrong ;(!"); - } catch (InvalidConfigurationException e) { - MessageM.sendMessage(null, - "%TAG%EUnable to send %AMCStats %Eto their server. Something went wrong ;(!"); - } + }, 0, 100); if ((Boolean) W.config.get(ConfigC.autoUpdateCheck)) { if ((Boolean) W.config.get(ConfigC.autoDownloadUpdate)) {