2014-09-22 13:02:14 +02:00
|
|
|
/*
|
2014-10-12 00:37:36 -07:00
|
|
|
* Copyright (c) IntellectualCrafters - 2014. You are not allowed to distribute
|
|
|
|
* and/or monetize any of our intellectual property. IntellectualCrafters is not
|
|
|
|
* affiliated with Mojang AB. Minecraft is a trademark of Mojang AB.
|
|
|
|
*
|
|
|
|
* >> File = plugin.java >> Generated by: Citymonstret at 2014-08-09 01:42
|
2014-09-22 13:02:14 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
package com.intellectualcrafters.plot.commands;
|
|
|
|
|
2014-10-11 18:16:08 +02:00
|
|
|
import com.intellectualcrafters.plot.PlayerFunctions;
|
|
|
|
import com.intellectualcrafters.plot.PlotMain;
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
|
|
|
2014-10-08 16:06:06 +02:00
|
|
|
import java.io.BufferedReader;
|
|
|
|
import java.io.InputStreamReader;
|
|
|
|
import java.net.URL;
|
|
|
|
import java.net.URLConnection;
|
|
|
|
import java.util.ArrayList;
|
2014-09-22 13:02:14 +02:00
|
|
|
|
|
|
|
public class plugin extends SubCommand {
|
|
|
|
|
2014-10-11 00:33:10 -07:00
|
|
|
public plugin() {
|
2014-10-12 00:37:36 -07:00
|
|
|
super("plugin", "plots.use", "Show plugin information", "plugin", "pl", CommandCategory.INFO);
|
2014-10-11 00:33:10 -07:00
|
|
|
}
|
2014-09-22 13:02:14 +02:00
|
|
|
|
2014-10-11 18:16:08 +02:00
|
|
|
public static String
|
|
|
|
downloads,
|
|
|
|
version;
|
|
|
|
|
|
|
|
|
|
|
|
public static void setup(JavaPlugin plugin) {
|
|
|
|
plugin.getServer().getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2014-10-11 18:24:50 +02:00
|
|
|
try {
|
|
|
|
downloads =
|
|
|
|
convertToNumericString(getInfo("https://intellectualsites.com/spigot_api.php?method=downloads&url=http://www.spigotmc.org/resources/plotsquared.1177/"), false);
|
|
|
|
} catch (Exception e) {
|
|
|
|
downloads = "unknown";
|
|
|
|
}
|
2014-10-11 18:16:08 +02:00
|
|
|
}
|
|
|
|
}, 1l);
|
|
|
|
plugin.getServer().getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2014-10-11 18:24:50 +02:00
|
|
|
try {
|
|
|
|
version =
|
|
|
|
convertToNumericString(getInfo("https://intellectualsites.com/spigot_api.php?method=version&resource=1177"), true);
|
|
|
|
} catch(Exception e) {
|
|
|
|
//Let's just ignore this, most likely error 500...
|
|
|
|
version = "unknown";
|
|
|
|
}
|
2014-10-11 18:16:08 +02:00
|
|
|
}
|
|
|
|
}, 200l);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-10-11 00:33:10 -07:00
|
|
|
public boolean execute(final Player plr, String... args) {
|
2014-10-12 00:37:36 -07:00
|
|
|
Bukkit.getScheduler().runTaskAsynchronously(JavaPlugin.getPlugin(PlotMain.class), new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
ArrayList<String> strings = new ArrayList<String>() {
|
|
|
|
{
|
|
|
|
add(String.format("&c>> &6PlotSquared (Version: %s)", PlotMain.getMain().getDescription().getVersion()));
|
|
|
|
add(String.format("&c>> &6Made by Citymonstret and Empire92"));
|
|
|
|
add(String.format("&c>> &6Download at &lhttp://i-s.link/ps"));
|
|
|
|
add(String.format("&c>> &cNewest Version (Spigot): %s", version));
|
|
|
|
add(String.format("&c>> &cTotal Downloads (Spigot): %s", downloads));
|
2014-10-11 00:33:10 -07:00
|
|
|
}
|
2014-10-12 00:37:36 -07:00
|
|
|
};
|
|
|
|
for (String s : strings) {
|
|
|
|
PlayerFunctions.sendMessage(plr, s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2014-10-11 00:33:10 -07:00
|
|
|
return true;
|
|
|
|
}
|
2014-09-22 13:02:14 +02:00
|
|
|
|
2014-10-11 18:16:08 +02:00
|
|
|
private static String convertToNumericString(String str, boolean dividers) {
|
|
|
|
StringBuilder builder = new StringBuilder();
|
|
|
|
for(char c : str.toCharArray()) {
|
|
|
|
if(Character.isDigit(c))
|
|
|
|
builder.append(c);
|
|
|
|
else if(dividers && (c == ',' || c == '.' || c == '-' || c == '_'))
|
|
|
|
builder.append(c);
|
|
|
|
}
|
|
|
|
return builder.toString();
|
|
|
|
}
|
|
|
|
|
2014-10-11 00:33:10 -07:00
|
|
|
/**
|
|
|
|
* @param link
|
|
|
|
* @return
|
|
|
|
*/
|
2014-10-11 18:16:08 +02:00
|
|
|
private static String getInfo(String link) {
|
2014-10-11 00:33:10 -07:00
|
|
|
try {
|
|
|
|
URLConnection connection = new URL(link).openConnection();
|
|
|
|
connection.addRequestProperty("User-Agent", "Mozilla/4.0");
|
2014-10-12 00:37:36 -07:00
|
|
|
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
2014-10-11 00:33:10 -07:00
|
|
|
String document = "", line;
|
|
|
|
while ((line = reader.readLine()) != null) {
|
|
|
|
document += (line + "\n");
|
|
|
|
}
|
|
|
|
reader.close();
|
|
|
|
return document;
|
2014-10-12 00:37:36 -07:00
|
|
|
}
|
|
|
|
catch (Exception e) {
|
2014-10-11 00:33:10 -07:00
|
|
|
e.printStackTrace();
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
2014-10-08 16:06:06 +02:00
|
|
|
|
2014-09-22 13:02:14 +02:00
|
|
|
}
|