Skip to content

Commit

Permalink
stat track
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed May 16, 2017
1 parent edd277d commit becacd7
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/main/java/org/mcmonkey/sentinel/SentinelPlugin.java
Expand Up @@ -105,6 +105,14 @@ public void run() {
catch (Exception e) {
e.printStackTrace();
}
new BukkitRunnable() {
@Override
public void run() {
if (!getConfig().getBoolean("stats_opt_out", false)) {
new StatsRecord().start();
}
}
}.runTaskTimer(this, 100, 20 * 60 * 60);
tryGetPerms();
integrations.add(new SentinelHealth());
integrations.add(new SentinelSBTeams());
Expand Down
52 changes: 52 additions & 0 deletions src/main/java/org/mcmonkey/sentinel/StatsRecord.java
@@ -0,0 +1,52 @@
package org.mcmonkey.sentinel;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;

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 stats server
URL url = new URL("http://neo.mcmonkey.org/plugins/public_stats?plugin=Sentinel&version="
+ URLEncoder.encode(SentinelPlugin.instance.getDescription().getVersion()));
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) {
System.out.println("Sentinel stat issue: " + e.getMessage());
}
finally {
try {
if (in != null) {
in.close();
}
}
catch (Exception e) {
System.out.println("Sentinel stat issue (backup): " + e.getMessage());
}
}
}
}

0 comments on commit becacd7

Please sign in to comment.