1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-20 03:35:51 +00:00

Use tabs everywhere

This commit is contained in:
SoSeDiK 2019-09-30 19:33:35 +03:00
parent c56225d051
commit abf00e038b

View File

@ -19,12 +19,12 @@ import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
public class CSCoreLibLoader {
private Plugin plugin;
private URL url;
private URL download;
private File file;
public CSCoreLibLoader(Plugin plugin) {
this.plugin = plugin;
try {
@ -33,7 +33,7 @@ public class CSCoreLibLoader {
plugin.getLogger().log(Level.SEVERE, "The Auto-Updater URL is malformed!", e);
}
}
public boolean load() {
if (plugin.getServer().getPluginManager().isPluginEnabled("CS-CoreLib")) {
return true;
@ -52,35 +52,35 @@ public class CSCoreLibLoader {
plugin.getLogger().log(Level.INFO, " ");
plugin.getLogger().log(Level.INFO, "#################### - INFO - ####################");
plugin.getLogger().log(Level.INFO, " ");
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> {
if (connect()) {
install();
}
}, 10L);
return false;
}
}
private boolean connect() {
try {
final URLConnection connection = this.url.openConnection();
connection.setConnectTimeout(5000);
connection.addRequestProperty("User-Agent", "CS-CoreLib Loader (by mrCookieSlime)");
connection.setDoOutput(true);
final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
final JsonArray array = new JsonParser().parse(reader).getAsJsonArray();
final JsonObject json = array.get(array.size() - 1).getAsJsonObject();
download = traceURL(json.get("downloadUrl").getAsString().replace("https:", "http:"));
file = new File("plugins/" + json.get("name").getAsString() + ".jar");
return true;
} catch (IOException e) {
plugin.getLogger().log(Level.WARNING, " ");
plugin.getLogger().log(Level.WARNING, "#################### - WARNING - ####################");
private boolean connect() {
try {
final URLConnection connection = this.url.openConnection();
connection.setConnectTimeout(5000);
connection.addRequestProperty("User-Agent", "CS-CoreLib Loader (by mrCookieSlime)");
connection.setDoOutput(true);
final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
final JsonArray array = new JsonParser().parse(reader).getAsJsonArray();
final JsonObject json = array.get(array.size() - 1).getAsJsonObject();
download = traceURL(json.get("downloadUrl").getAsString().replace("https:", "http:"));
file = new File("plugins/" + json.get("name").getAsString() + ".jar");
return true;
} catch (IOException e) {
plugin.getLogger().log(Level.WARNING, " ");
plugin.getLogger().log(Level.WARNING, "#################### - WARNING - ####################");
plugin.getLogger().log(Level.WARNING, " ");
plugin.getLogger().log(Level.WARNING, "Could not connect to BukkitDev.");
plugin.getLogger().log(Level.WARNING, "Please download & install CS-CoreLib manually:");
@ -88,50 +88,50 @@ public class CSCoreLibLoader {
plugin.getLogger().log(Level.WARNING, " ");
plugin.getLogger().log(Level.WARNING, "#################### - WARNING - ####################");
plugin.getLogger().log(Level.WARNING, " ");
return false;
}
}
private URL traceURL(String location) throws IOException {
HttpURLConnection connection = null;
while (true) {
URL url = new URL(location);
connection = (HttpURLConnection) url.openConnection();
connection.setInstanceFollowRedirects(false);
connection.setConnectTimeout(5000);
connection.addRequestProperty("User-Agent", "Auto Updater (by mrCookieSlime)");
int response = connection.getResponseCode();
if (response == HttpURLConnection.HTTP_MOVED_PERM || response == HttpURLConnection.HTTP_MOVED_TEMP) {
String loc = connection.getHeaderField("Location");
location = new URL(new URL(location), loc).toExternalForm();
}
else {
break;
}
}
return new URL(connection.getURL().toString().replace(" ", "%20"));
return false;
}
}
private URL traceURL(String location) throws IOException {
HttpURLConnection connection = null;
while (true) {
URL url = new URL(location);
connection = (HttpURLConnection) url.openConnection();
connection.setInstanceFollowRedirects(false);
connection.setConnectTimeout(5000);
connection.addRequestProperty("User-Agent", "Auto Updater (by mrCookieSlime)");
int response = connection.getResponseCode();
if (response == HttpURLConnection.HTTP_MOVED_PERM || response == HttpURLConnection.HTTP_MOVED_TEMP) {
String loc = connection.getHeaderField("Location");
location = new URL(new URL(location), loc).toExternalForm();
}
else {
break;
}
}
return new URL(connection.getURL().toString().replace(" ", "%20"));
}
private void install() {
BufferedInputStream input = null;
FileOutputStream output = null;
try {
input = new BufferedInputStream(download.openStream());
output = new FileOutputStream(file);
try {
input = new BufferedInputStream(download.openStream());
output = new FileOutputStream(file);
final byte[] data = new byte[1024];
int read;
while ((read = input.read(data, 0, 1024)) != -1) {
output.write(data, 0, read);
}
} catch (Exception ex) {
plugin.getLogger().log(Level.WARNING, " ");
plugin.getLogger().log(Level.WARNING, "#################### - WARNING - ####################");
final byte[] data = new byte[1024];
int read;
while ((read = input.read(data, 0, 1024)) != -1) {
output.write(data, 0, read);
}
} catch (Exception ex) {
plugin.getLogger().log(Level.WARNING, " ");
plugin.getLogger().log(Level.WARNING, "#################### - WARNING - ####################");
plugin.getLogger().log(Level.WARNING, " ");
plugin.getLogger().log(Level.WARNING, "Failed to download CS-CoreLib");
plugin.getLogger().log(Level.WARNING, "Please download & install CS-CoreLib manually:");
@ -139,22 +139,22 @@ public class CSCoreLibLoader {
plugin.getLogger().log(Level.WARNING, " ");
plugin.getLogger().log(Level.WARNING, "#################### - WARNING - ####################");
plugin.getLogger().log(Level.WARNING, " ");
} finally {
try {
if (input != null) input.close();
if (output != null) output.close();
plugin.getLogger().log(Level.INFO, " ");
plugin.getLogger().log(Level.INFO, "#################### - INFO - ####################");
plugin.getLogger().log(Level.INFO, " ");
plugin.getLogger().log(Level.INFO, "Please restart your Server to finish the Installation");
plugin.getLogger().log(Level.INFO, "of " + plugin.getName() + " and CS-CoreLib");
plugin.getLogger().log(Level.INFO, " ");
plugin.getLogger().log(Level.INFO, "#################### - INFO - ####################");
plugin.getLogger().log(Level.INFO, " ");
} catch (IOException x) {
plugin.getLogger().log(Level.SEVERE, "An Error occured while closing the Download Stream for CS-CoreLib", x);
}
}
} finally {
try {
if (input != null) input.close();
if (output != null) output.close();
plugin.getLogger().log(Level.INFO, " ");
plugin.getLogger().log(Level.INFO, "#################### - INFO - ####################");
plugin.getLogger().log(Level.INFO, " ");
plugin.getLogger().log(Level.INFO, "Please restart your Server to finish the Installation");
plugin.getLogger().log(Level.INFO, "of " + plugin.getName() + " and CS-CoreLib");
plugin.getLogger().log(Level.INFO, " ");
plugin.getLogger().log(Level.INFO, "#################### - INFO - ####################");
plugin.getLogger().log(Level.INFO, " ");
} catch (IOException x) {
plugin.getLogger().log(Level.SEVERE, "An Error occured while closing the Download Stream for CS-CoreLib", x);
}
}
}
}