From 5f09d6d910337e59c3bd26c4b8ce9b9bc995df95 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Fri, 28 Aug 2020 06:15:56 +1200 Subject: [PATCH] Organize imports --- .../libraryaddict/disguise/LibsDisguises.java | 2 - .../utilities/listeners/DisguiseListener.java | 1 - .../disguise/utilities/updates/LDJenkins.java | 60 +++++++++++++++---- 3 files changed, 50 insertions(+), 13 deletions(-) diff --git a/src/main/java/me/libraryaddict/disguise/LibsDisguises.java b/src/main/java/me/libraryaddict/disguise/LibsDisguises.java index ced75399..116c2eee 100644 --- a/src/main/java/me/libraryaddict/disguise/LibsDisguises.java +++ b/src/main/java/me/libraryaddict/disguise/LibsDisguises.java @@ -30,7 +30,6 @@ import me.libraryaddict.disguise.utilities.sounds.SoundManager; import me.libraryaddict.disguise.utilities.updates.UpdateChecker; import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; -import org.bukkit.ChatColor; import org.bukkit.command.*; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; @@ -41,7 +40,6 @@ import java.io.File; import java.util.Arrays; import java.util.Iterator; import java.util.Map; -import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; public class LibsDisguises extends JavaPlugin { diff --git a/src/main/java/me/libraryaddict/disguise/utilities/listeners/DisguiseListener.java b/src/main/java/me/libraryaddict/disguise/utilities/listeners/DisguiseListener.java index 1a8a9b7c..0c3b01c5 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/listeners/DisguiseListener.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/listeners/DisguiseListener.java @@ -48,7 +48,6 @@ import java.util.HashMap; import java.util.Optional; import java.util.Random; import java.util.Set; -import java.util.concurrent.TimeUnit; public class DisguiseListener implements Listener { private HashMap interactions = new HashMap<>(); diff --git a/src/main/java/me/libraryaddict/disguise/utilities/updates/LDJenkins.java b/src/main/java/me/libraryaddict/disguise/utilities/updates/LDJenkins.java index a8e46142..5e179906 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/updates/LDJenkins.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/updates/LDJenkins.java @@ -3,7 +3,9 @@ package me.libraryaddict.disguise.utilities.updates; import com.google.gson.Gson; import lombok.AllArgsConstructor; import lombok.Getter; +import me.libraryaddict.disguise.LibsDisguises; import me.libraryaddict.disguise.utilities.DisguiseUtilities; +import me.libraryaddict.disguise.utilities.LibsPremium; import org.bukkit.ChatColor; import java.io.BufferedReader; @@ -12,10 +14,7 @@ import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; /** @@ -42,15 +41,58 @@ public class LDJenkins { } } + private String[] getBadUsers() { + // List of bad users that need to redownload Libs Disguises + + try { + // We're connecting to md_5's jenkins REST api + URL url = new URL("https://api.github.com/repos/libraryaddict/libsdisguises/issues/469"); + // Creating a connection + HttpURLConnection con = (HttpURLConnection) url.openConnection(); + con.setRequestProperty("User-Agent", "libraryaddict/LibsDisguises"); + con.setRequestProperty("Accept", "application/vnd.github.v3+json"); + + HashMap map; + + // Get the input stream, what we receive + try (InputStream input = con.getInputStream()) { + // Read it to string + String json = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8)).lines() + .collect(Collectors.joining("\n")); + + map = new Gson().fromJson(json, HashMap.class); + } + + if (!map.containsKey("body")) { + return new String[0]; + } + + return ((String) map.get("body")).split("(\\r|\\n)+"); + } catch (Exception ignored) { + } + + return new String[0]; + } + /** * Fetches from jenkins, using the REST api the last snapshot build information */ private Map fetchLastSnapshotBuild() { try { + String[] users = getBadUsers(); + + for (String s : users) { + if (LibsPremium.getPaidInformation() != null && + (s.equals(LibsPremium.getPaidInformation().getDownloadID()) || + s.equals(LibsPremium.getPaidInformation().getUserID()))) { + LibsDisguises.getInstance().unregisterCommands(true); + } + } + DisguiseUtilities.getLogger().info("Now looking for update on Jenkins.."); // We're connecting to md_5's jenkins REST api - URL url = new URL( - "https://ci.md-5.net/job/LibsDisguises/api/json?tree=builds[changeSet[items[msg]],id,result]"); + URL url = new URL("https://ci.md-5.net/job/LibsDisguises/api/json?tree=builds[changeSet[items[msg]],id," + + "result]"); // Creating a connection HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setDefaultUseCaches(false); @@ -66,8 +108,7 @@ public class LDJenkins { } return jsonObject; - } - catch (Exception ex) { + } catch (Exception ex) { DisguiseUtilities.getLogger().warning("Failed to check for a snapshot update on jenkins."); ex.printStackTrace(); } @@ -95,8 +136,7 @@ public class LDJenkins { try { Thread.sleep(10000); - } - catch (InterruptedException e) { + } catch (InterruptedException e) { e.printStackTrace(); }