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:
parent
c56225d051
commit
abf00e038b
@ -19,12 +19,12 @@ import com.google.gson.JsonObject;
|
|||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
|
|
||||||
public class CSCoreLibLoader {
|
public class CSCoreLibLoader {
|
||||||
|
|
||||||
private Plugin plugin;
|
private Plugin plugin;
|
||||||
private URL url;
|
private URL url;
|
||||||
private URL download;
|
private URL download;
|
||||||
private File file;
|
private File file;
|
||||||
|
|
||||||
public CSCoreLibLoader(Plugin plugin) {
|
public CSCoreLibLoader(Plugin plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
try {
|
try {
|
||||||
@ -33,7 +33,7 @@ public class CSCoreLibLoader {
|
|||||||
plugin.getLogger().log(Level.SEVERE, "The Auto-Updater URL is malformed!", e);
|
plugin.getLogger().log(Level.SEVERE, "The Auto-Updater URL is malformed!", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean load() {
|
public boolean load() {
|
||||||
if (plugin.getServer().getPluginManager().isPluginEnabled("CS-CoreLib")) {
|
if (plugin.getServer().getPluginManager().isPluginEnabled("CS-CoreLib")) {
|
||||||
return true;
|
return true;
|
||||||
@ -52,35 +52,35 @@ public class CSCoreLibLoader {
|
|||||||
plugin.getLogger().log(Level.INFO, " ");
|
plugin.getLogger().log(Level.INFO, " ");
|
||||||
plugin.getLogger().log(Level.INFO, "#################### - INFO - ####################");
|
plugin.getLogger().log(Level.INFO, "#################### - INFO - ####################");
|
||||||
plugin.getLogger().log(Level.INFO, " ");
|
plugin.getLogger().log(Level.INFO, " ");
|
||||||
|
|
||||||
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> {
|
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> {
|
||||||
if (connect()) {
|
if (connect()) {
|
||||||
install();
|
install();
|
||||||
}
|
}
|
||||||
}, 10L);
|
}, 10L);
|
||||||
|
|
||||||
return false;
|
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()));
|
private boolean connect() {
|
||||||
final JsonArray array = new JsonParser().parse(reader).getAsJsonArray();
|
try {
|
||||||
final JsonObject json = array.get(array.size() - 1).getAsJsonObject();
|
final URLConnection connection = this.url.openConnection();
|
||||||
|
connection.setConnectTimeout(5000);
|
||||||
download = traceURL(json.get("downloadUrl").getAsString().replace("https:", "http:"));
|
connection.addRequestProperty("User-Agent", "CS-CoreLib Loader (by mrCookieSlime)");
|
||||||
file = new File("plugins/" + json.get("name").getAsString() + ".jar");
|
connection.setDoOutput(true);
|
||||||
|
|
||||||
return true;
|
final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||||
} catch (IOException e) {
|
final JsonArray array = new JsonParser().parse(reader).getAsJsonArray();
|
||||||
plugin.getLogger().log(Level.WARNING, " ");
|
final JsonObject json = array.get(array.size() - 1).getAsJsonObject();
|
||||||
plugin.getLogger().log(Level.WARNING, "#################### - WARNING - ####################");
|
|
||||||
|
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, " ");
|
||||||
plugin.getLogger().log(Level.WARNING, "Could not connect to BukkitDev.");
|
plugin.getLogger().log(Level.WARNING, "Could not connect to BukkitDev.");
|
||||||
plugin.getLogger().log(Level.WARNING, "Please download & install CS-CoreLib manually:");
|
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, " ");
|
||||||
plugin.getLogger().log(Level.WARNING, "#################### - WARNING - ####################");
|
plugin.getLogger().log(Level.WARNING, "#################### - WARNING - ####################");
|
||||||
plugin.getLogger().log(Level.WARNING, " ");
|
plugin.getLogger().log(Level.WARNING, " ");
|
||||||
return false;
|
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 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() {
|
private void install() {
|
||||||
BufferedInputStream input = null;
|
BufferedInputStream input = null;
|
||||||
FileOutputStream output = null;
|
FileOutputStream output = null;
|
||||||
try {
|
try {
|
||||||
input = new BufferedInputStream(download.openStream());
|
input = new BufferedInputStream(download.openStream());
|
||||||
output = new FileOutputStream(file);
|
output = new FileOutputStream(file);
|
||||||
|
|
||||||
final byte[] data = new byte[1024];
|
final byte[] data = new byte[1024];
|
||||||
int read;
|
int read;
|
||||||
while ((read = input.read(data, 0, 1024)) != -1) {
|
while ((read = input.read(data, 0, 1024)) != -1) {
|
||||||
output.write(data, 0, read);
|
output.write(data, 0, read);
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
plugin.getLogger().log(Level.WARNING, " ");
|
plugin.getLogger().log(Level.WARNING, " ");
|
||||||
plugin.getLogger().log(Level.WARNING, "#################### - WARNING - ####################");
|
plugin.getLogger().log(Level.WARNING, "#################### - WARNING - ####################");
|
||||||
plugin.getLogger().log(Level.WARNING, " ");
|
plugin.getLogger().log(Level.WARNING, " ");
|
||||||
plugin.getLogger().log(Level.WARNING, "Failed to download CS-CoreLib");
|
plugin.getLogger().log(Level.WARNING, "Failed to download CS-CoreLib");
|
||||||
plugin.getLogger().log(Level.WARNING, "Please download & install CS-CoreLib manually:");
|
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, " ");
|
||||||
plugin.getLogger().log(Level.WARNING, "#################### - WARNING - ####################");
|
plugin.getLogger().log(Level.WARNING, "#################### - WARNING - ####################");
|
||||||
plugin.getLogger().log(Level.WARNING, " ");
|
plugin.getLogger().log(Level.WARNING, " ");
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
if (input != null) input.close();
|
if (input != null) input.close();
|
||||||
if (output != null) output.close();
|
if (output != null) output.close();
|
||||||
plugin.getLogger().log(Level.INFO, " ");
|
plugin.getLogger().log(Level.INFO, " ");
|
||||||
plugin.getLogger().log(Level.INFO, "#################### - INFO - ####################");
|
plugin.getLogger().log(Level.INFO, "#################### - INFO - ####################");
|
||||||
plugin.getLogger().log(Level.INFO, " ");
|
plugin.getLogger().log(Level.INFO, " ");
|
||||||
plugin.getLogger().log(Level.INFO, "Please restart your Server to finish the Installation");
|
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, "of " + plugin.getName() + " and CS-CoreLib");
|
||||||
plugin.getLogger().log(Level.INFO, " ");
|
plugin.getLogger().log(Level.INFO, " ");
|
||||||
plugin.getLogger().log(Level.INFO, "#################### - INFO - ####################");
|
plugin.getLogger().log(Level.INFO, "#################### - INFO - ####################");
|
||||||
plugin.getLogger().log(Level.INFO, " ");
|
plugin.getLogger().log(Level.INFO, " ");
|
||||||
} catch (IOException x) {
|
} catch (IOException x) {
|
||||||
plugin.getLogger().log(Level.SEVERE, "An Error occured while closing the Download Stream for CS-CoreLib", x);
|
plugin.getLogger().log(Level.SEVERE, "An Error occured while closing the Download Stream for CS-CoreLib", x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user