Skip to content

Commit

Permalink
First pass at neo stats engine
Browse files Browse the repository at this point in the history
mcstats so unreliable. This is more fun.
  • Loading branch information
mcmonkey4eva committed Nov 2, 2015
1 parent f0d2aab commit 1a584f2
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 32 deletions.
59 changes: 27 additions & 32 deletions src/main/java/net/aufdemrand/denizen/Denizen.java
Expand Up @@ -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.*;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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("-------------------------------------");
Expand All @@ -356,8 +357,7 @@ public void onEnable() {

try {
org.spigotmc.AsyncCatcher.enabled = false;
}
catch (Throwable e) {
} catch (Throwable e) {
dB.echoError("Running not-Spigot?!");
}

Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand All @@ -546,8 +537,7 @@ public void onEnable() {
getTriggerRegistry().registerCoreMembers();
getRequirementRegistry().registerCoreMembers();
getListenerRegistry().registerCoreMembers();
}
catch (Exception e) {
} catch (Exception e) {
dB.echoError(e);
}

Expand Down Expand Up @@ -727,8 +717,7 @@ public void onEnable() {

// Register Core dObjects with the ObjectFetcher
ObjectFetcher._registerCoreObjects();
}
catch (Exception e) {
} catch (Exception e) {
dB.echoError(e);
}

Expand Down Expand Up @@ -799,17 +788,15 @@ 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);
}

try {
for (World world : getServer().getWorlds()) {
EntityScriptHelper.linkWorld(world);
}
}
catch (Exception e) {
} catch (Exception e) {
dB.echoError(e);
}

Expand All @@ -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);
}
}
Expand All @@ -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);
}


Expand Down
4 changes: 4 additions & 0 deletions src/main/java/net/aufdemrand/denizen/Settings.java
Expand Up @@ -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
Expand Down
@@ -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);
}
}
}
}
4 changes: 4 additions & 0 deletions src/main/resources/config.yml
Expand Up @@ -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:
Expand Down

0 comments on commit 1a584f2

Please sign in to comment.