* @param isPing are we pinging?
* @throws IOException A problem reading data from server.
*/
private void postPlugin(final boolean isPing) throws IOException {
// The plugin's description file containg all of the plugin data such as name, version, author, etc
PluginDescriptionFile description = plugin.getDescription();
// Construct the post data
StringBuilder data = new StringBuilder();
data.append(encode("guid")).append('=').append(encode(guid));
data.append(encodeDataPair("version", description.getVersion()));
data.append(encodeDataPair("server", Bukkit.getVersion()));
data.append(encodeDataPair("players", Integer.toString(Bukkit.getServer().getOnlinePlayers().length)));
data.append(encodeDataPair("revision", String.valueOf(REVISION)));
// If we're pinging, append it
if (isPing) {
data.append(encodeDataPair("ping", "true"));
}
// Acquire a lock on the graphs, which lets us make the assumption we also lock everything
// inside of the graph (e.g plotters)
synchronized (graphs) {
Iterator<Graph> iter = graphs.iterator();
while (iter.hasNext()) {
Graph graph = iter.next();
// Because we have a lock on the graphs set already, it is reasonable to assume
// that our lock transcends down to the individual plotters in the graphs also.
// Because our methods are private, no one but us can reasonably access this list
// without reflection so this is a safe assumption without adding more code.
for (Plotter plotter : graph.getPlotters()) {
// The key name to send to the metrics server
// The format is C-GRAPHNAME-PLOTTERNAME where separator - is defined at the top
// Legacy (R4) submitters use the format Custom%s, or CustomPLOTTERNAME
String key = String.format("C%s%s%s%s", CUSTOM_DATA_SEPARATOR, graph.getName(), CUSTOM_DATA_SEPARATOR, plotter.getColumnName());
// The value to send, which for the foreseeable future is just the string
// value of plotter.getValue()
String value = Integer.toString(plotter.getValue());
// Add it to the http post data :)
data.append(encodeDataPair(key, value));
}
}
}
// Create the url
URL url = new URL(BASE_URL + String.format(REPORT_URL, description.getName()));
// Connect to the website
URLConnection connection;
// Mineshafter creates a socks proxy, so we can safely bypass it