use of org.bukkit.plugin.PluginDescriptionFile in project Towny by ElgarL.
the class Metrics method postPlugin.
/**
* Generic method that posts a plugin to the metrics website
*/
private void postPlugin(final boolean isPing) throws IOException {
// Server software specific section
PluginDescriptionFile description = plugin.getDescription();
// Due to an idiot taking the Towny name on Metrics.
String pluginName = "TownyAdvanced";
// TRUE if online mode is enabled
boolean onlineMode = Bukkit.getServer().getOnlineMode();
String pluginVersion = description.getVersion();
String serverVersion = Bukkit.getVersion();
int playersOnline = Bukkit.getServer().getOnlinePlayers().size();
// END server software specific section -- all code below does not use any code outside of this class / Java
// Construct the post data
StringBuilder json = new StringBuilder(1024);
json.append('{');
// The plugin's description file containg all of the plugin data such as name, version, author, etc
appendJSONPair(json, "guid", guid);
appendJSONPair(json, "plugin_version", pluginVersion);
appendJSONPair(json, "server_version", serverVersion);
appendJSONPair(json, "players_online", Integer.toString(playersOnline));
// New data as of R6
String osname = System.getProperty("os.name");
String osarch = System.getProperty("os.arch");
String osversion = System.getProperty("os.version");
String java_version = System.getProperty("java.version");
int coreCount = Runtime.getRuntime().availableProcessors();
// normalize os arch .. amd64 -> x86_64
if (osarch.equals("amd64")) {
osarch = "x86_64";
}
appendJSONPair(json, "osname", osname);
appendJSONPair(json, "osarch", osarch);
appendJSONPair(json, "osversion", osversion);
appendJSONPair(json, "cores", Integer.toString(coreCount));
appendJSONPair(json, "auth_mode", onlineMode ? "1" : "0");
appendJSONPair(json, "java_version", java_version);
// If we're pinging, append it
if (isPing) {
appendJSONPair(json, "ping", "1");
}
if (graphs.size() > 0) {
synchronized (graphs) {
json.append(',');
json.append('"');
json.append("graphs");
json.append('"');
json.append(':');
json.append('{');
boolean firstGraph = true;
final Iterator<Graph> iter = graphs.iterator();
while (iter.hasNext()) {
Graph graph = iter.next();
StringBuilder graphJson = new StringBuilder();
graphJson.append('{');
for (Plotter plotter : graph.getPlotters()) {
appendJSONPair(graphJson, plotter.getColumnName(), Integer.toString(plotter.getValue()));
}
graphJson.append('}');
if (!firstGraph) {
json.append(',');
}
json.append(escapeJSON(graph.getName()));
json.append(':');
json.append(graphJson);
firstGraph = false;
}
json.append('}');
}
}
// close json
json.append('}');
// Create the url
URL url = new URL(BASE_URL + String.format(REPORT_URL, urlEncode(pluginName)));
// Connect to the website
URLConnection connection;
// It does not reroute POST requests so we need to go around it
if (isMineshafterPresent()) {
connection = url.openConnection(Proxy.NO_PROXY);
} else {
connection = url.openConnection();
}
byte[] uncompressed = json.toString().getBytes();
byte[] compressed = gzip(json.toString());
// Headers
connection.addRequestProperty("User-Agent", "MCStats/" + REVISION);
connection.addRequestProperty("Content-Type", "application/json");
connection.addRequestProperty("Content-Encoding", "gzip");
connection.addRequestProperty("Content-Length", Integer.toString(compressed.length));
connection.addRequestProperty("Accept", "application/json");
connection.addRequestProperty("Connection", "close");
connection.setDoOutput(true);
if (debug) {
System.out.println("[Metrics] Prepared request for " + pluginName + " uncompressed=" + uncompressed.length + " compressed=" + compressed.length);
}
// Write the data
OutputStream os = connection.getOutputStream();
os.write(compressed);
os.flush();
// Now read the response
final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String response = reader.readLine();
// close resources
os.close();
reader.close();
if (response == null || response.startsWith("ERR") || response.startsWith("7")) {
if (response == null) {
response = "null";
} else if (response.startsWith("7")) {
response = response.substring(response.startsWith("7,") ? 2 : 1);
}
throw new IOException(response);
} else {
// Is this the first update this hour?
if (response.equals("1") || response.contains("This is your first update this hour")) {
synchronized (graphs) {
final Iterator<Graph> iter = graphs.iterator();
while (iter.hasNext()) {
final Graph graph = iter.next();
for (Plotter plotter : graph.getPlotters()) {
plotter.reset();
}
}
}
}
}
}
use of org.bukkit.plugin.PluginDescriptionFile in project Minigames by AddstarMC.
the class Metrics method postPlugin.
/**
* Generic method that posts a plugin to the metrics website
*/
private void postPlugin(final boolean isPing) throws IOException {
// Server software specific section
PluginDescriptionFile description = plugin.getDescription();
String pluginName = description.getName();
// TRUE if online mode is enabled
boolean onlineMode = Bukkit.getServer().getOnlineMode();
String pluginVersion = description.getVersion();
String serverVersion = Bukkit.getVersion();
int playersOnline = Bukkit.getServer().getOnlinePlayers().size();
// END server software specific section -- all code below does not use any code outside of this class / Java
// Construct the post data
StringBuilder json = new StringBuilder(1024);
json.append('{');
// The plugin's description file containg all of the plugin data such as name, version, author, etc
appendJSONPair(json, "guid", guid);
appendJSONPair(json, "plugin_version", pluginVersion);
appendJSONPair(json, "server_version", serverVersion);
appendJSONPair(json, "players_online", Integer.toString(playersOnline));
// New data as of R6
String osname = System.getProperty("os.name");
String osarch = System.getProperty("os.arch");
String osversion = System.getProperty("os.version");
String java_version = System.getProperty("java.version");
int coreCount = Runtime.getRuntime().availableProcessors();
// normalize os arch .. amd64 -> x86_64
if (osarch.equals("amd64")) {
osarch = "x86_64";
}
appendJSONPair(json, "osname", osname);
appendJSONPair(json, "osarch", osarch);
appendJSONPair(json, "osversion", osversion);
appendJSONPair(json, "cores", Integer.toString(coreCount));
appendJSONPair(json, "auth_mode", onlineMode ? "1" : "0");
appendJSONPair(json, "java_version", java_version);
// If we're pinging, append it
if (isPing) {
appendJSONPair(json, "ping", "1");
}
if (graphs.size() > 0) {
synchronized (graphs) {
json.append(',');
json.append('"');
json.append("graphs");
json.append('"');
json.append(':');
json.append('{');
boolean firstGraph = true;
final Iterator<Graph> iter = graphs.iterator();
while (iter.hasNext()) {
Graph graph = iter.next();
StringBuilder graphJson = new StringBuilder();
graphJson.append('{');
for (Plotter plotter : graph.getPlotters()) {
appendJSONPair(graphJson, plotter.getColumnName(), Integer.toString(plotter.getValue()));
}
graphJson.append('}');
if (!firstGraph) {
json.append(',');
}
json.append(escapeJSON(graph.getName()));
json.append(':');
json.append(graphJson);
firstGraph = false;
}
json.append('}');
}
}
// close json
json.append('}');
// Create the url
URL url = new URL(BASE_URL + String.format(REPORT_URL, urlEncode(pluginName)));
// Connect to the website
URLConnection connection;
// It does not reroute POST requests so we need to go around it
if (isMineshafterPresent()) {
connection = url.openConnection(Proxy.NO_PROXY);
} else {
connection = url.openConnection();
}
byte[] uncompressed = json.toString().getBytes();
byte[] compressed = gzip(json.toString());
// Headers
connection.addRequestProperty("User-Agent", "MCStats/" + REVISION);
connection.addRequestProperty("Content-Type", "application/json");
connection.addRequestProperty("Content-Encoding", "gzip");
connection.addRequestProperty("Content-Length", Integer.toString(compressed.length));
connection.addRequestProperty("Accept", "application/json");
connection.addRequestProperty("Connection", "close");
connection.setDoOutput(true);
if (debug) {
System.out.println("[Metrics] Prepared request for " + pluginName + " uncompressed=" + uncompressed.length + " compressed=" + compressed.length);
}
// Write the data
OutputStream os = connection.getOutputStream();
os.write(compressed);
os.flush();
// Now read the response
final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String response = reader.readLine();
// close resources
os.close();
reader.close();
if (response == null || response.startsWith("ERR") || response.startsWith("7")) {
if (response == null) {
response = "null";
} else if (response.startsWith("7")) {
response = response.substring(response.startsWith("7,") ? 2 : 1);
}
throw new IOException(response);
} else {
// Is this the first update this hour?
if (response.equals("1") || response.contains("This is your first update this hour")) {
synchronized (graphs) {
final Iterator<Graph> iter = graphs.iterator();
while (iter.hasNext()) {
final Graph graph = iter.next();
for (Plotter plotter : graph.getPlotters()) {
plotter.reset();
}
}
}
}
}
}
use of org.bukkit.plugin.PluginDescriptionFile in project Minigames by AddstarMC.
the class Minigames method onDisable.
public void onDisable() {
if (plugin == null) {
return;
}
PluginDescriptionFile desc = this.getDescription();
log.info(desc.getName() + " successfully disabled.");
for (Player p : getServer().getOnlinePlayers()) {
if (pdata.getMinigamePlayer(p).isInMinigame()) {
pdata.quitMinigame(pdata.getMinigamePlayer(p), true);
}
}
for (Minigame minigame : mdata.getAllMinigames().values()) {
if (minigame.getType() == MinigameType.GLOBAL && minigame.getMechanicName().equals("treasure_hunt") && minigame.isEnabled()) {
if (minigame.getMinigameTimer() != null)
minigame.getMinigameTimer().stopTimer();
TreasureHuntMechanic.removeTreasure(minigame);
}
}
for (Minigame mg : mdata.getAllMinigames().values()) {
mg.saveMinigame();
}
backend.shutdown();
// pdata.saveDCPlayers();
pdata.saveDeniedCommands();
MinigameSave globalLoadouts = new MinigameSave("globalLoadouts");
if (mdata.hasLoadouts()) {
for (String loadout : mdata.getLoadouts()) {
// }
for (Integer slot : mdata.getLoadout(loadout).getItems()) {
globalLoadouts.getConfig().set(loadout + "." + slot, mdata.getLoadout(loadout).getItem(slot));
}
if (!mdata.getLoadout(loadout).getAllPotionEffects().isEmpty()) {
for (PotionEffect eff : mdata.getLoadout(loadout).getAllPotionEffects()) {
globalLoadouts.getConfig().set(loadout + ".potions." + eff.getType().getName() + ".amp", eff.getAmplifier());
globalLoadouts.getConfig().set(loadout + ".potions." + eff.getType().getName() + ".dur", eff.getDuration());
}
} else {
globalLoadouts.getConfig().set(loadout + ".potions", null);
}
if (mdata.getLoadout(loadout).getUsePermissions()) {
globalLoadouts.getConfig().set(loadout + ".usepermissions", true);
} else {
globalLoadouts.getConfig().set(loadout + ".usepermissions", null);
}
}
} else {
globalLoadouts.getConfig().set("globalloadouts", null);
}
globalLoadouts.saveConfig();
mdata.saveRewardSigns();
}
use of org.bukkit.plugin.PluginDescriptionFile in project Minigames by AddstarMC.
the class Minigames method onEnable.
public void onEnable() {
try {
plugin = this;
PluginDescriptionFile desc = this.getDescription();
MinigameSave sv = new MinigameSave("lang/" + getConfig().getString("lang"));
lang = sv.getConfig();
loadLang();
lang.setDefaults(defLang);
getLogger().info("Using lang " + getConfig().getString("lang"));
String prespath = getDataFolder() + "/presets/";
String[] presets = { "spleef", "lms", "ctf", "infection" };
File pres;
for (String preset : presets) {
pres = new File(prespath + preset + ".yml");
if (!pres.exists()) {
saveResource("presets/" + preset + ".yml", false);
}
}
mdata = new MinigameData();
pdata = new PlayerData();
display = new DisplayManager();
mdata.addMinigameType(new SingleplayerType());
// mdata.addMinigameType(new FreeForAllType());
// mdata.addMinigameType(new TeamsType());
mdata.addMinigameType(new MultiplayerType());
MinigameSave completion = new MinigameSave("completion");
mdata.addConfigurationFile("completion", completion.getConfig());
getServer().getPluginManager().registerEvents(new Events(), this);
getServer().getPluginManager().registerEvents(new BasicRecorder(), this);
try {
this.getConfig().load(this.getDataFolder() + "/config.yml");
List<String> mgs = new ArrayList<String>();
if (getConfig().contains("minigames")) {
mgs = getConfig().getStringList("minigames");
}
final List<String> allMGS = new ArrayList<String>();
allMGS.addAll(mgs);
if (!mgs.isEmpty()) {
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
@Override
public void run() {
for (String minigame : allMGS) {
final Minigame game = new Minigame(minigame);
try {
game.loadMinigame();
mdata.addMinigame(game);
} catch (Exception e) {
getLogger().severe(ChatColor.RED.toString() + "Failed to load \"" + minigame + "\"! The configuration file may be corrupt or missing!");
e.printStackTrace();
}
}
}
}, 1L);
}
} catch (FileNotFoundException ex) {
log.info("Failed to load config, creating one.");
try {
this.getConfig().save(this.getDataFolder() + "/config.yml");
} catch (IOException e) {
log.log(Level.SEVERE, "Could not save config.yml!");
e.printStackTrace();
}
} catch (Exception e) {
log.log(Level.SEVERE, "Failed to load config!");
e.printStackTrace();
}
if (!setupEconomy()) {
getLogger().info("No Vault plugin found! You may only reward items.");
}
backend = new BackendManager(getLogger());
if (!backend.initialize(getConfig())) {
getServer().getPluginManager().disablePlugin(this);
return;
}
getConfig().options().copyDefaults(true);
saveConfig();
Calendar cal = Calendar.getInstance();
if (cal.get(Calendar.DAY_OF_MONTH) == 21 && cal.get(Calendar.MONTH) == 8 || cal.get(Calendar.DAY_OF_MONTH) == 25 && cal.get(Calendar.MONTH) == 11 || cal.get(Calendar.DAY_OF_MONTH) == 1 && cal.get(Calendar.MONTH) == 0) {
getLogger().info(ChatColor.GREEN.name() + "Party Mode enabled!");
pdata.setPartyMode(true);
}
// pdata.loadDCPlayers();
pdata.loadDeniedCommands();
MinigameSave globalLoadouts = new MinigameSave("globalLoadouts");
Set<String> keys = globalLoadouts.getConfig().getKeys(false);
for (String loadout : keys) {
mdata.addLoadout(loadout);
Set<String> items = globalLoadouts.getConfig().getConfigurationSection(loadout).getKeys(false);
// }
for (String slot : items) {
if (slot.matches("[0-9]+"))
mdata.getLoadout(loadout).addItem(globalLoadouts.getConfig().getItemStack(loadout + "." + slot), Integer.parseInt(slot));
}
if (globalLoadouts.getConfig().contains(loadout + ".potions")) {
Set<String> pots = globalLoadouts.getConfig().getConfigurationSection(loadout + ".potions").getKeys(false);
for (String eff : pots) {
if (PotionEffectType.getByName(eff) != null) {
PotionEffect effect = new PotionEffect(PotionEffectType.getByName(eff), globalLoadouts.getConfig().getInt(loadout + ".potions." + eff + ".dur"), globalLoadouts.getConfig().getInt(loadout + ".potions." + eff + ".amp"));
mdata.getLoadout(loadout).addPotionEffect(effect);
}
}
}
if (globalLoadouts.getConfig().contains(loadout + ".usepermissions")) {
mdata.getLoadout(loadout).setUsePermissions(globalLoadouts.getConfig().getBoolean(loadout + ".usepermissions"));
}
}
minigameSigns = new SignBase();
mdata.loadRewardSigns();
CommandDispatcher disp = new CommandDispatcher();
getCommand("minigame").setExecutor(disp);
getCommand("minigame").setTabCompleter(disp);
for (Player player : getServer().getOnlinePlayers()) {
pdata.addMinigamePlayer(player);
}
initMetrics();
log.info(desc.getName() + " successfully enabled.");
} catch (Throwable e) {
plugin = null;
getLogger().log(Level.SEVERE, "Failed to enable Minigames " + getDescription().getVersion() + ": ", e);
getPluginLoader().disablePlugin(this);
}
}
use of org.bukkit.plugin.PluginDescriptionFile in project BKCommonLib by bergerhealer.
the class Metrics method postPlugin.
/**
* Generic method that posts a plugin to the metrics website
*/
private void postPlugin(final boolean isPing) throws IOException {
// Server software specific section
PluginDescriptionFile description = plugin.getDescription();
String pluginName = description.getName();
// TRUE if online mode is enabled
boolean onlineMode = Bukkit.getServer().getOnlineMode();
String pluginVersion = description.getVersion();
String serverVersion = Bukkit.getVersion();
int playersOnline = Bukkit.getServer().getOnlinePlayers().size();
// END server software specific section -- all code below does not use any code outside of this class / Java
// Construct the post data
final StringBuilder data = new StringBuilder();
// The plugin's description file containg all of the plugin data such as name, version, author, etc
data.append(encode("guid")).append('=').append(encode(guid));
encodeDataPair(data, "version", pluginVersion);
encodeDataPair(data, "server", serverVersion);
encodeDataPair(data, "players", Integer.toString(playersOnline));
encodeDataPair(data, "revision", String.valueOf(REVISION));
// New data as of R6
String osname = System.getProperty("os.name");
String osarch = System.getProperty("os.arch");
String osversion = System.getProperty("os.version");
String java_version = System.getProperty("java.version");
int coreCount = Runtime.getRuntime().availableProcessors();
// normalize os arch .. amd64 -> x86_64
if (osarch.equals("amd64")) {
osarch = "x86_64";
}
encodeDataPair(data, "osname", osname);
encodeDataPair(data, "osarch", osarch);
encodeDataPair(data, "osversion", osversion);
encodeDataPair(data, "cores", Integer.toString(coreCount));
encodeDataPair(data, "online-mode", Boolean.toString(onlineMode));
encodeDataPair(data, "java_version", java_version);
// If we're pinging, append it
if (isPing) {
encodeDataPair(data, "ping", "true");
}
// inside of the graph (e.g plotters)
synchronized (graphs) {
final Iterator<Graph> iter = graphs.iterator();
while (iter.hasNext()) {
final Graph graph = iter.next();
for (Entry<String, Object> entry : graph.getPlotters().entrySet()) {
// Ignore null values
if (entry.getValue() == null) {
continue;
}
// 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
final String key = String.format("C%s%s%s%s", CUSTOM_DATA_SEPARATOR, graph.getName(), CUSTOM_DATA_SEPARATOR, entry.getKey());
// Add it to the http post data :)
encodeDataPair(data, key, entry.getValue().toString());
}
}
}
// Create the url
URL url = new URL(BASE_URL + String.format(REPORT_URL, encode(pluginName)));
// Connect to the website
URLConnection connection;
// It does not reroute POST requests so we need to go around it
if (isMineshafterPresent()) {
connection = url.openConnection(Proxy.NO_PROXY);
} else {
connection = url.openConnection();
}
connection.setDoOutput(true);
// Write the data
final OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());
writer.write(data.toString());
writer.flush();
// Now read the response
final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
final String response = reader.readLine();
// close resources
writer.close();
reader.close();
if (response == null || response.startsWith("ERR")) {
//Throw the exception
throw new IOException(response);
} else {
// Is this the first update this hour?
if (response.contains("OK This is your first update this hour")) {
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
public void run() {
synchronized (graphs) {
for (Graph graph : graphs) {
graph.onReset(plugin);
}
}
}
});
}
}
}
Aggregations