Organize imports

This commit is contained in:
libraryaddict 2020-08-28 06:15:56 +12:00
parent 33b7a5e8c8
commit 5f09d6d910
3 changed files with 50 additions and 13 deletions

View File

@ -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 {

View File

@ -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<String, LibsEntityInteract> interactions = new HashMap<>();

View File

@ -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<String, Object> 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<String, Object> 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();
}