diff --git a/src/main/java/net/aufdemrand/denizen/Denizen.java b/src/main/java/net/aufdemrand/denizen/Denizen.java index b7c24c6ef2..a983246a68 100644 --- a/src/main/java/net/aufdemrand/denizen/Denizen.java +++ b/src/main/java/net/aufdemrand/denizen/Denizen.java @@ -36,6 +36,7 @@ import net.aufdemrand.denizen.utilities.command.Injector; import net.aufdemrand.denizen.utilities.command.messaging.Messaging; import net.aufdemrand.denizen.utilities.debugging.LogInterceptor; +import net.aufdemrand.denizen.utilities.debugging.StatsRecord; import net.aufdemrand.denizen.utilities.debugging.dB; import net.aufdemrand.denizen.utilities.depends.Depends; import net.aufdemrand.denizen.utilities.entity.*; @@ -69,6 +70,7 @@ import org.bukkit.entity.Player; import org.bukkit.event.HandlerList; import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.scheduler.BukkitRunnable; import java.io.File; import java.io.IOException; @@ -344,8 +346,7 @@ public RequirementChecker getRequirementChecker() { public void onEnable() { try { net.minecraft.server.v1_8_R3.Block.getById(0); - } - catch (NoClassDefFoundError e) { + } catch (NoClassDefFoundError e) { getLogger().warning("-------------------------------------"); getLogger().warning("This Denizen version is not compatible with this CraftBukkit version! Deactivating Denizen!"); getLogger().warning("-------------------------------------"); @@ -356,8 +357,7 @@ public void onEnable() { try { org.spigotmc.AsyncCatcher.enabled = false; - } - catch (Throwable e) { + } catch (Throwable e) { dB.echoError("Running not-Spigot?!"); } @@ -387,16 +387,14 @@ public void onEnable() { dB.log(ChatColor.GRAY + "by: " + ChatColor.WHITE + "aufdemrand"); dB.log(ChatColor.GRAY + "version: " + ChatColor.WHITE + versionTag); dB.log(ChatColor.LIGHT_PURPLE + "+-------------------------+"); - } - catch (Exception e) { + } catch (Exception e) { dB.echoError(e); } try { MetricsLite metrics = new MetricsLite(this); metrics.start(); - } - catch (Exception e) { + } catch (Exception e) { dB.echoError(e); } @@ -423,16 +421,14 @@ public void onEnable() { for (OfflinePlayer player : Bukkit.getOfflinePlayers()) { dPlayer.notePlayer(player); } - } - catch (Exception e) { + } catch (Exception e) { dB.echoError(e); } try { DenizenCore.setCommandRegistry(getCommandRegistry()); getCommandRegistry().registerCoreMembers(); - } - catch (Exception e) { + } catch (Exception e) { dB.echoError(e); } @@ -443,8 +439,7 @@ public void onEnable() { // Populate config.yml if it doesn't yet exist. saveDefaultConfig(); reloadConfig(); - } - catch (Exception e) { + } catch (Exception e) { dB.echoError(e); } @@ -459,8 +454,7 @@ public void onEnable() { ScriptRegistry._registerType("command", CommandScriptContainer.class); ScriptRegistry._registerType("map", MapScriptContainer.class); ScriptRegistry._registerType("version", VersionScriptContainer.class); - } - catch (Exception e) { + } catch (Exception e) { dB.echoError(e); } @@ -476,8 +470,7 @@ public void onEnable() { dB.log("Denizen.mid not found, extracting from " + sourceFile); Utilities.extractFile(new File(sourceFile), "Denizen.mid", getDataFolder() + "/midi/"); } - } - catch (Exception e) { + } catch (Exception e) { dB.echoError(e); } @@ -498,8 +491,7 @@ public void onEnable() { InventoryScriptHelper in_helper = new InventoryScriptHelper(); EntityScriptHelper es_helper = new EntityScriptHelper(); CommandScriptHelper cs_helper = new CommandScriptHelper(); - } - catch (Exception e) { + } catch (Exception e) { dB.echoError(e); } @@ -535,8 +527,7 @@ public void onEnable() { // Compile and load Denizen externals runtimeCompiler = new RuntimeCompiler(this); runtimeCompiler.loader(); - } - catch (Exception e) { + } catch (Exception e) { dB.echoError(e); } @@ -546,8 +537,7 @@ public void onEnable() { getTriggerRegistry().registerCoreMembers(); getRequirementRegistry().registerCoreMembers(); getListenerRegistry().registerCoreMembers(); - } - catch (Exception e) { + } catch (Exception e) { dB.echoError(e); } @@ -727,8 +717,7 @@ public void onEnable() { // Register Core dObjects with the ObjectFetcher ObjectFetcher._registerCoreObjects(); - } - catch (Exception e) { + } catch (Exception e) { dB.echoError(e); } @@ -799,8 +788,7 @@ public void onEnable() { propertyParser.registerProperty(ItemQuantity.class, dItem.class); propertyParser.registerProperty(ItemSkullskin.class, dItem.class); propertyParser.registerProperty(ItemSpawnEgg.class, dItem.class); - } - catch (Exception e) { + } catch (Exception e) { dB.echoError(e); } @@ -808,8 +796,7 @@ public void onEnable() { for (World world : getServer().getWorlds()) { EntityScriptHelper.linkWorld(world); } - } - catch (Exception e) { + } catch (Exception e) { dB.echoError(e); } @@ -833,8 +820,7 @@ public void run() { // Fire the 'on Server Start' world event ws_helper.serverStartEvent(); - } - catch (Exception e) { + } catch (Exception e) { dB.echoError(e); } } @@ -846,6 +832,15 @@ public void run() { DenizenCore.tick(50); // Sadly, minecraft has no delta timing, so a tick is always 50ms. } }, 1, 1); + + new BukkitRunnable() { + @Override + public void run() { + if (Settings.canRecordStats()) { + new StatsRecord().start(); + } + } + }.runTaskTimer(this, 100, 20 * 60 * 60); } diff --git a/src/main/java/net/aufdemrand/denizen/Settings.java b/src/main/java/net/aufdemrand/denizen/Settings.java index ef82efbfb0..25c33259b3 100644 --- a/src/main/java/net/aufdemrand/denizen/Settings.java +++ b/src/main/java/net/aufdemrand/denizen/Settings.java @@ -53,6 +53,10 @@ public static boolean allowConsoleRedirection() { .getBoolean("Debug.Allow console redirection", false); } + public static boolean canRecordStats() { + return DenizenAPI.getCurrentInstance().getConfig().getBoolean("Debug.Stats", true); + } + /* # Sets the default speed between execution of commands in queues diff --git a/src/main/java/net/aufdemrand/denizen/utilities/debugging/StatsRecord.java b/src/main/java/net/aufdemrand/denizen/utilities/debugging/StatsRecord.java new file mode 100644 index 0000000000..cf800231ee --- /dev/null +++ b/src/main/java/net/aufdemrand/denizen/utilities/debugging/StatsRecord.java @@ -0,0 +1,58 @@ +package net.aufdemrand.denizen.utilities.debugging; + +import net.aufdemrand.denizen.Denizen; +import net.aufdemrand.denizen.objects.dPlayer; +import net.aufdemrand.denizen.utilities.DenizenAPI; +import net.aufdemrand.denizencore.DenizenCore; +import net.aufdemrand.denizencore.objects.Duration; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; +import java.net.URLEncoder; + +public class StatsRecord extends Thread { + @Override + public void run() { + BufferedReader in = null; + try { + // Open a connection to the paste server + URL url = new URL("http://neo.mcmonkey.org/plugins/public_stats?plugin=Denizen&version=" + URLEncoder.encode(DenizenAPI.getCurrentInstance().getImplementationVersion())); + HttpURLConnection uc = (HttpURLConnection) url.openConnection(); + uc.setDoInput(true); + uc.setDoOutput(true); + uc.setConnectTimeout(10000); + uc.connect(); + // Safely connected at this point + // Create the final message pack and upload it + uc.getOutputStream().write(("postid=pluginstats&plugin_st_players=" + Bukkit.getOnlinePlayers().size() + + "&plugin_st_motd=" + URLEncoder.encode(Bukkit.getServer().getMotd().replace(ChatColor.COLOR_CHAR, (char) 0x01))) + .getBytes("UTF-8")); + // Wait for a response from the server + in = new BufferedReader(new InputStreamReader(uc.getInputStream())); + // Record the response + String Result = in.readLine(); + // TODO: Use return? + // Close the connection + in.close(); + } + catch (Exception e) { + dB.echoError(e); + } + finally { + try { + if (in != null) + in.close(); + } + catch (Exception e) { + dB.echoError(e); + } + } + } +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index b689b39503..c12bf0d91e 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -8,6 +8,10 @@ Debug: Trim length: 512 # Whether to permit the "server.redirect_logging" mechanism Allow console redirection: false + # Whether to send basic statistic information to the Denizen central server. + # This is purely to maintain basic information on things like how many servers run any given version of Denizen. + # Please do not disable this unless it is throwing errors (Please report any errors you receive as well). + Stats: true Scripts: World: