From 446cd422e04c6f9b62de8adf25aa29b0a0b4fb4c Mon Sep 17 00:00:00 2001 From: Sauilitired Date: Sat, 11 Oct 2014 18:16:08 +0200 Subject: [PATCH] Well, some stuff... --- .../intellectualcrafters/plot/PlotMain.java | 3 ++ .../plot/UUIDHandler.java | 20 ++++--- .../plot/commands/Schematic.java | 5 +- .../plot/commands/plugin.java | 53 ++++++++++++++----- 4 files changed, 54 insertions(+), 27 deletions(-) diff --git a/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java b/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java index bb093cb13..390f0be9e 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java @@ -681,6 +681,9 @@ public class PlotMain extends JavaPlugin { PlotHelper.canSetFast = false; } + //Setup version + downloads, will not be updated... maybe setup runnable? TODO Let jesse decide... + com.intellectualcrafters.plot.commands.plugin.setup(this); + // TODO Test... UUIDHandler.startFetch(this); } diff --git a/PlotSquared/src/com/intellectualcrafters/plot/UUIDHandler.java b/PlotSquared/src/com/intellectualcrafters/plot/UUIDHandler.java index b80ec5bbf..3a213c79b 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/UUIDHandler.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/UUIDHandler.java @@ -1,20 +1,17 @@ package com.intellectualcrafters.plot; -import java.util.Arrays; -import java.util.Map; -import java.util.UUID; -import java.util.concurrent.ConcurrentHashMap; - -import org.bukkit.Bukkit; -import org.bukkit.OfflinePlayer; -import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; - import com.google.common.base.Charsets; import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; import com.intellectualcrafters.plot.uuid.NameFetcher; import com.intellectualcrafters.plot.uuid.UUIDFetcher; +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; + +import java.util.Arrays; +import java.util.UUID; public class UUIDHandler { @@ -56,7 +53,8 @@ public class UUIDHandler { } long time = System.currentTimeMillis() - start; - PlotMain.sendConsoleSenderMessage("&cFinished caching of offlineplayers! Took &6" + time + "&cms, &6" + long timePerUUID = time / uuidMap.size(); + PlotMain.sendConsoleSenderMessage("&cFinished caching of offlineplayers! Took &6" + time + "&cms (&6" + timePerUUID + "&c per second), &6" + length + " &cUUID's were cached" + " and there is now a grand total of &6" + uuidMap.size() + " &ccached."); } diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Schematic.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Schematic.java index 48d995a21..2f152d1e7 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Schematic.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Schematic.java @@ -54,10 +54,7 @@ public class Schematic extends SubCommand { sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent"); break; } - if (!PlayerFunctions.isInPlot(plr)) { - sendMessage(plr, C.NOT_IN_PLOT); - break; - } + int l1 = schematic.getSchematicDimension().getX(); int l2 = schematic.getSchematicDimension().getZ(); diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/plugin.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/plugin.java index f020b6464..68a651264 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/plugin.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/plugin.java @@ -8,35 +8,53 @@ package com.intellectualcrafters.plot.commands; +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; + import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.URL; import java.net.URLConnection; import java.util.ArrayList; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; - -import com.intellectualcrafters.plot.PlayerFunctions; -import com.intellectualcrafters.plot.PlotMain; - public class plugin extends SubCommand { public plugin() { super("plugin", "plots.use", "Show plugin information", "plugin", "pl", CommandCategory.INFO); } - @Override + public static String + downloads, + version; + + + public static void setup(JavaPlugin plugin) { + plugin.getServer().getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() { + @Override + public void run() { + downloads = + convertToNumericString(getInfo("https://intellectualsites.com/spigot_api.php?method=downloads&url=http://www.spigotmc.org/resources/plotsquared.1177/"), false); + } + }, 1l); + plugin.getServer().getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() { + @Override + public void run() { + version = + convertToNumericString(getInfo("https://intellectualsites.com/spigot_api.php?method=version&resource=1177"), true); + } + }, 200l); + } + + @Override public boolean execute(final Player plr, String... args) { Bukkit.getScheduler().runTaskAsynchronously(JavaPlugin.getPlugin(PlotMain.class), new Runnable() { @Override public void run() { ArrayList strings = new ArrayList() { { - String downloads = - getInfo("https://intellectualsites.com/spigot_api.php?method=downloads&url=http://www.spigotmc.org/resources/plotsquared.1177/"), version = - getInfo("https://intellectualsites.com/spigot_api.php?method=version&resource=1177"); 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")); @@ -52,11 +70,22 @@ public class plugin extends SubCommand { return true; } + 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(); + } + /** * @param link * @return */ - private String getInfo(String link) { + private static String getInfo(String link) { try { URLConnection connection = new URL(link).openConnection(); connection.addRequestProperty("User-Agent", "Mozilla/4.0");