Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
93 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/main/java/net/aufdemrand/denizen/utilities/debugging/StatsRecord.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters