mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-30 16:19:03 +01:00
Formatting
By: Dinnerbone <dinnerbone@dinnerbone.com>
This commit is contained in:
parent
891a7dd5f8
commit
346e41a6e5
7 changed files with 427 additions and 430 deletions
|
@ -24,7 +24,9 @@ public class Checker {
|
||||||
+ " plugins:");
|
+ " plugins:");
|
||||||
for (File file : files) {
|
for (File file : files) {
|
||||||
PluginDescriptionFile pdfFile = Checker.getPDF(file);
|
PluginDescriptionFile pdfFile = Checker.getPDF(file);
|
||||||
if(pdfFile == null) continue;
|
if (pdfFile == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
checkForUpdate(file, player);
|
checkForUpdate(file, player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,8 +98,8 @@ public class Checker {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
} else
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,13 +4,12 @@ import org.bukkit.*;
|
||||||
import org.bukkit.plugin.PluginDescriptionFile;
|
import org.bukkit.plugin.PluginDescriptionFile;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
public class Downloader {
|
public class Downloader {
|
||||||
private static String directory = Fillr.directory;
|
private final static String directory = Fillr.directory;
|
||||||
private static String downloads = directory + File.separator + "downloads";
|
private final static String downloads = directory + File.separator + "downloads";
|
||||||
private static String backup = "backup";
|
private final static String backup = "backup";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Downloads the jar from a given url. If it is a compressed archive, it
|
* Downloads the jar from a given url. If it is a compressed archive, it
|
||||||
|
@ -24,8 +23,9 @@ public class Downloader {
|
||||||
String name = url.substring(index + 1);
|
String name = url.substring(index + 1);
|
||||||
|
|
||||||
File file = new File(directory, name);
|
File file = new File(directory, name);
|
||||||
if (url.endsWith(".jar") && file.exists())
|
if (url.endsWith(".jar") && file.exists()) {
|
||||||
backupFile(file);
|
backupFile(file);
|
||||||
|
}
|
||||||
|
|
||||||
download(new URL(url), name, directory);
|
download(new URL(url), name, directory);
|
||||||
file = new File("plugins", name);
|
file = new File("plugins", name);
|
||||||
|
@ -86,20 +86,23 @@ public class Downloader {
|
||||||
// try {
|
// try {
|
||||||
inputStream = u.openStream();
|
inputStream = u.openStream();
|
||||||
|
|
||||||
if (!new File(directory).exists())
|
if (!new File(directory).exists()) {
|
||||||
new File(directory).mkdir();
|
new File(directory).mkdir();
|
||||||
|
}
|
||||||
|
|
||||||
File f = new File(directory, name);
|
File f = new File(directory, name);
|
||||||
if (f.exists())
|
if (f.exists()) {
|
||||||
f.delete();
|
f.delete();
|
||||||
|
}
|
||||||
f.createNewFile();
|
f.createNewFile();
|
||||||
|
|
||||||
copyInputStream(inputStream, new BufferedOutputStream(
|
copyInputStream(inputStream, new BufferedOutputStream(
|
||||||
new FileOutputStream(f)));
|
new FileOutputStream(f)));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (inputStream != null)
|
if (inputStream != null) {
|
||||||
inputStream.close();
|
inputStream.close();
|
||||||
|
}
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
System.out.println("[UPDATR]: Error closing inputStream");
|
System.out.println("[UPDATR]: Error closing inputStream");
|
||||||
}
|
}
|
||||||
|
@ -135,14 +138,14 @@ public class Downloader {
|
||||||
byte[] buffer = new byte[1024];
|
byte[] buffer = new byte[1024];
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
while ((len = in.read(buffer)) >= 0)
|
while ((len = in.read(buffer)) >= 0) {
|
||||||
out.write(buffer, 0, len);
|
out.write(buffer, 0, len);
|
||||||
|
}
|
||||||
|
|
||||||
in.close();
|
in.close();
|
||||||
out.close();
|
out.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Moves the file to the backup folder.
|
* Moves the file to the backup folder.
|
||||||
*
|
*
|
||||||
|
@ -152,11 +155,10 @@ public class Downloader {
|
||||||
private static void backupFile(File file) {
|
private static void backupFile(File file) {
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
System.out.println("Backing up old file: " + file.getName());
|
System.out.println("Backing up old file: " + file.getName());
|
||||||
if (!new File(backup).exists())
|
if (!new File(backup).exists()) {
|
||||||
new File(backup).mkdir();
|
new File(backup).mkdir();
|
||||||
file.renameTo(new File(backup, file
|
}
|
||||||
.getName() + ".bak"));
|
file.renameTo(new File(backup, file.getName() + ".bak"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,6 +1,5 @@
|
||||||
package org.bukkit.fillr;
|
package org.bukkit.fillr;
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
|
@ -15,7 +14,6 @@ import org.json.simple.parser.ParseException;
|
||||||
public class FillReader {
|
public class FillReader {
|
||||||
//TODO change this to what it will actually be...
|
//TODO change this to what it will actually be...
|
||||||
private static String baseUrl = "http://taylorkelly.me/pnfo.php";
|
private static String baseUrl = "http://taylorkelly.me/pnfo.php";
|
||||||
|
|
||||||
private String currVersion;
|
private String currVersion;
|
||||||
private String file;
|
private String file;
|
||||||
private String name;
|
private String name;
|
||||||
|
@ -42,11 +40,11 @@ public class FillReader {
|
||||||
Object obj;
|
Object obj;
|
||||||
obj = parser.parse(result);
|
obj = parser.parse(result);
|
||||||
JSONObject jsonObj = (JSONObject) obj;
|
JSONObject jsonObj = (JSONObject) obj;
|
||||||
this.currVersion = (String)jsonObj.get("plugin_version");
|
this.currVersion = (String) jsonObj.get("plugin_version");
|
||||||
this.name = (String)jsonObj.get("plugin_name");
|
this.name = (String) jsonObj.get("plugin_name");
|
||||||
this.file = (String)jsonObj.get("plugin_file");
|
this.file = (String) jsonObj.get("plugin_file");
|
||||||
this.stable = (Boolean)jsonObj.get("plugin_stable");
|
this.stable = (Boolean) jsonObj.get("plugin_stable");
|
||||||
this.notes = (String)jsonObj.get("plugin_notes");
|
this.notes = (String) jsonObj.get("plugin_notes");
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -78,5 +76,4 @@ public class FillReader {
|
||||||
public boolean isStable() {
|
public boolean isStable() {
|
||||||
return stable;
|
return stable;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@ import org.bukkit.plugin.java.*;
|
||||||
import org.bukkit.event.*;
|
import org.bukkit.event.*;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.logging.Logger;
|
|
||||||
import org.bukkit.event.player.PlayerListener;
|
import org.bukkit.event.player.PlayerListener;
|
||||||
|
|
||||||
public class Fillr extends JavaPlugin {
|
public class Fillr extends JavaPlugin {
|
||||||
|
|
|
@ -28,7 +28,6 @@ public class Getter {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void enablePlugin(FillReader update) {
|
private void enablePlugin(FillReader update) {
|
||||||
|
@ -41,6 +40,4 @@ public class Getter {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
package org.bukkit.fillr;
|
package org.bukkit.fillr;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FilenameFilter;
|
import java.io.FilenameFilter;
|
||||||
|
|
||||||
|
@ -6,12 +7,11 @@ import java.io.FilenameFilter;
|
||||||
* Used to filter out non-updatr files
|
* Used to filter out non-updatr files
|
||||||
*/
|
*/
|
||||||
public class PluginFilter implements FilenameFilter {
|
public class PluginFilter implements FilenameFilter {
|
||||||
|
|
||||||
public boolean accept(File file, String name) {
|
public boolean accept(File file, String name) {
|
||||||
if(name.endsWith(".jar"))
|
if (name.endsWith(".jar")) {
|
||||||
return true;
|
return true;
|
||||||
else
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,9 +4,6 @@ import org.bukkit.*;
|
||||||
import org.bukkit.plugin.*;
|
import org.bukkit.plugin.*;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.jar.*;
|
|
||||||
|
|
||||||
public class Updater {
|
public class Updater {
|
||||||
public static String directory = Fillr.directory;
|
public static String directory = Fillr.directory;
|
||||||
|
@ -32,13 +29,16 @@ public class Updater {
|
||||||
+ files.length + " plugins:");
|
+ files.length + " plugins:");
|
||||||
for (File file : files) {
|
for (File file : files) {
|
||||||
PluginDescriptionFile pdfFile = Checker.getPDF(file);
|
PluginDescriptionFile pdfFile = Checker.getPDF(file);
|
||||||
if(pdfFile == null) continue;
|
if (pdfFile == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
FillReader reader = Checker.needsUpdate(pdfFile);
|
FillReader reader = Checker.needsUpdate(pdfFile);
|
||||||
if (reader != null)
|
if (reader != null) {
|
||||||
update(reader, player);
|
update(reader, player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if a given plugin needs an update, if it does, it updates it
|
* Checks if a given plugin needs an update, if it does, it updates it
|
||||||
|
|
Loading…
Reference in a new issue