2014-11-08 20:27:09 +01:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
|
|
|
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
|
|
|
// /
|
|
|
|
// This program is free software; you can redistribute it and/or modify /
|
|
|
|
// it under the terms of the GNU General Public License as published by /
|
|
|
|
// the Free Software Foundation; either version 3 of the License, or /
|
|
|
|
// (at your option) any later version. /
|
|
|
|
// /
|
|
|
|
// This program is distributed in the hope that it will be useful, /
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
|
|
|
// GNU General Public License for more details. /
|
|
|
|
// /
|
|
|
|
// You should have received a copy of the GNU General Public License /
|
|
|
|
// along with this program; if not, write to the Free Software Foundation, /
|
|
|
|
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
|
|
|
// /
|
|
|
|
// You can contact us via: support@intellectualsites.com /
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
2014-09-22 13:02:14 +02:00
|
|
|
|
|
|
|
package com.intellectualcrafters.plot.commands;
|
|
|
|
|
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
|
|
|
|
2015-01-14 03:38:15 +11:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
|
|
|
|
|
|
import com.intellectualcrafters.plot.PlotMain;
|
|
|
|
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
|
|
|
|
2014-11-05 14:42:08 +11:00
|
|
|
public class plugin extends SubCommand {
|
2014-10-11 18:16:08 +02:00
|
|
|
|
2014-11-09 12:51:17 +01:00
|
|
|
public static String downloads, version;
|
|
|
|
|
2014-11-05 14:42:08 +11:00
|
|
|
public plugin() {
|
|
|
|
super("plugin", "plots.use", "Show plugin information", "plugin", "pl", CommandCategory.INFO, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setup(final JavaPlugin plugin) {
|
2014-10-11 18:16:08 +02:00
|
|
|
plugin.getServer().getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2014-10-11 18:24:50 +02:00
|
|
|
try {
|
2014-11-05 14:42:08 +11:00
|
|
|
downloads = convertToNumericString(getInfo("https://intellectualsites.com/spigot_api.php?method=downloads&url=http://www.spigotmc.org/resources/plotsquared.1177/"), false);
|
2014-12-17 20:15:11 -06:00
|
|
|
} catch (final Exception e) {
|
2014-10-11 18:24:50 +02:00
|
|
|
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 {
|
2014-11-05 14:42:08 +11:00
|
|
|
version = convertToNumericString(getInfo("https://intellectualsites.com/spigot_api.php?method=version&resource=1177"), true);
|
2014-12-17 20:15:11 -06:00
|
|
|
} catch (final Exception e) {
|
2014-11-05 14:42:08 +11:00
|
|
|
// Let's just ignore this, most likely error 500...
|
2014-10-11 18:24:50 +02:00
|
|
|
version = "unknown";
|
|
|
|
}
|
2014-10-11 18:16:08 +02:00
|
|
|
}
|
|
|
|
}, 200l);
|
|
|
|
}
|
|
|
|
|
2014-11-05 14:42:08 +11:00
|
|
|
private static String convertToNumericString(final String str, final boolean dividers) {
|
|
|
|
final StringBuilder builder = new StringBuilder();
|
|
|
|
for (final char c : str.toCharArray()) {
|
|
|
|
if (Character.isDigit(c)) {
|
2014-10-11 18:16:08 +02:00
|
|
|
builder.append(c);
|
2014-12-17 20:15:11 -06:00
|
|
|
} else if (dividers && ((c == ',') || (c == '.') || (c == '-') || (c == '_'))) {
|
2014-10-11 18:16:08 +02:00
|
|
|
builder.append(c);
|
2014-11-05 14:42:08 +11:00
|
|
|
}
|
2014-10-11 18:16:08 +02:00
|
|
|
}
|
|
|
|
return builder.toString();
|
|
|
|
}
|
|
|
|
|
2014-11-05 14:42:08 +11:00
|
|
|
private static String getInfo(final String link) throws Exception {
|
|
|
|
final URLConnection connection = new URL(link).openConnection();
|
2014-10-11 18:30:24 +02:00
|
|
|
connection.addRequestProperty("User-Agent", "Mozilla/4.0");
|
2014-11-05 14:42:08 +11:00
|
|
|
final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
2014-10-11 18:30:24 +02:00
|
|
|
String document = "", line;
|
|
|
|
while ((line = reader.readLine()) != null) {
|
|
|
|
document += (line + "\n");
|
|
|
|
}
|
|
|
|
reader.close();
|
|
|
|
return document;
|
2014-11-05 14:42:08 +11:00
|
|
|
}
|
2014-10-08 16:06:06 +02:00
|
|
|
|
2014-11-09 12:51:17 +01:00
|
|
|
@Override
|
|
|
|
public boolean execute(final Player plr, final String... args) {
|
2014-12-14 00:30:29 +11:00
|
|
|
Bukkit.getScheduler().runTaskAsynchronously(PlotMain.getMain(), new Runnable() {
|
2014-11-09 12:51:17 +01:00
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
final 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));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
for (final String s : strings) {
|
|
|
|
PlayerFunctions.sendMessage(plr, s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-09-22 13:02:14 +02:00
|
|
|
}
|