|
|
@ -33,6 +33,7 @@ import org.bukkit.configuration.InvalidConfigurationException; |
|
|
|
import org.bukkit.configuration.file.YamlConfiguration; |
|
|
|
import org.bukkit.configuration.file.YamlConfiguration; |
|
|
|
import org.bukkit.plugin.Plugin; |
|
|
|
import org.bukkit.plugin.Plugin; |
|
|
|
import org.bukkit.plugin.PluginDescriptionFile; |
|
|
|
import org.bukkit.plugin.PluginDescriptionFile; |
|
|
|
|
|
|
|
import org.bukkit.scheduler.BukkitTask; |
|
|
|
|
|
|
|
|
|
|
|
import java.io.BufferedReader; |
|
|
|
import java.io.BufferedReader; |
|
|
|
import java.io.File; |
|
|
|
import java.io.File; |
|
|
@ -97,7 +98,7 @@ public class MetricsLite { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Id of the scheduled task |
|
|
|
* Id of the scheduled task |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private volatile int taskId = -1; |
|
|
|
private volatile BukkitTask taskId = null; |
|
|
|
|
|
|
|
|
|
|
|
public MetricsLite(Plugin plugin) throws IOException { |
|
|
|
public MetricsLite(Plugin plugin) throws IOException { |
|
|
|
if (plugin == null) { |
|
|
|
if (plugin == null) { |
|
|
@ -139,12 +140,12 @@ public class MetricsLite { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Is metrics already running?
|
|
|
|
// Is metrics already running?
|
|
|
|
if (taskId >= 0) { |
|
|
|
if (taskId != null) { |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Begin hitting the server with glorious data
|
|
|
|
// Begin hitting the server with glorious data
|
|
|
|
taskId = plugin.getServer().getScheduler().scheduleAsyncRepeatingTask(plugin, new Runnable() { |
|
|
|
taskId = plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, new Runnable() { |
|
|
|
|
|
|
|
|
|
|
|
private boolean firstPost = true; |
|
|
|
private boolean firstPost = true; |
|
|
|
|
|
|
|
|
|
|
@ -153,9 +154,9 @@ public class MetricsLite { |
|
|
|
// This has to be synchronized or it can collide with the disable method.
|
|
|
|
// This has to be synchronized or it can collide with the disable method.
|
|
|
|
synchronized (optOutLock) { |
|
|
|
synchronized (optOutLock) { |
|
|
|
// Disable Task, if it is running and the server owner decided to opt-out
|
|
|
|
// Disable Task, if it is running and the server owner decided to opt-out
|
|
|
|
if (isOptOut() && taskId > 0) { |
|
|
|
if (isOptOut() && (taskId != null)) { |
|
|
|
plugin.getServer().getScheduler().cancelTask(taskId); |
|
|
|
taskId.cancel(); |
|
|
|
taskId = -1; |
|
|
|
taskId = null; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -213,7 +214,7 @@ public class MetricsLite { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Enable Task, if it is not running
|
|
|
|
// Enable Task, if it is not running
|
|
|
|
if (taskId < 0) { |
|
|
|
if (taskId == null) { |
|
|
|
start(); |
|
|
|
start(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -234,9 +235,9 @@ public class MetricsLite { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Disable Task, if it is running
|
|
|
|
// Disable Task, if it is running
|
|
|
|
if (taskId > 0) { |
|
|
|
if (taskId != null) { |
|
|
|
this.plugin.getServer().getScheduler().cancelTask(taskId); |
|
|
|
taskId.cancel(); |
|
|
|
taskId = -1; |
|
|
|
taskId = null; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -270,7 +271,7 @@ public class MetricsLite { |
|
|
|
data.append(encode("guid")).append('=').append(encode(guid)); |
|
|
|
data.append(encode("guid")).append('=').append(encode(guid)); |
|
|
|
encodeDataPair(data, "version", description.getVersion()); |
|
|
|
encodeDataPair(data, "version", description.getVersion()); |
|
|
|
encodeDataPair(data, "server", Bukkit.getVersion()); |
|
|
|
encodeDataPair(data, "server", Bukkit.getVersion()); |
|
|
|
encodeDataPair(data, "players", Integer.toString(Bukkit.getServer().getOnlinePlayers().length)); |
|
|
|
encodeDataPair(data, "players", Integer.toString(Bukkit.getServer().getOnlinePlayers().size())); |
|
|
|
encodeDataPair(data, "revision", String.valueOf(REVISION)); |
|
|
|
encodeDataPair(data, "revision", String.valueOf(REVISION)); |
|
|
|
|
|
|
|
|
|
|
|
// If we're pinging, append it
|
|
|
|
// If we're pinging, append it
|
|
|
|