mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-29 12:27:59 +01:00
Formatting
By: Dinnerbone <dinnerbone@dinnerbone.com>
This commit is contained in:
parent
891a7dd5f8
commit
346e41a6e5
@ -6,98 +6,100 @@ import org.bukkit.*;
|
|||||||
import org.bukkit.plugin.*;
|
import org.bukkit.plugin.*;
|
||||||
|
|
||||||
public class Checker {
|
public class Checker {
|
||||||
private static String directory = Fillr.directory;
|
private static String directory = Fillr.directory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks all the plugins in plugins/ for updates
|
* Checks all the plugins in plugins/ for updates
|
||||||
*
|
*
|
||||||
* @param player
|
* @param player
|
||||||
* The player to send info to
|
* The player to send info to
|
||||||
*/
|
*/
|
||||||
void check(Player player) {
|
void check(Player player) {
|
||||||
File folder = new File(directory);
|
File folder = new File(directory);
|
||||||
File[] files = folder.listFiles(new PluginFilter());
|
File[] files = folder.listFiles(new PluginFilter());
|
||||||
if (files.length == 0) {
|
if (files.length == 0) {
|
||||||
player.sendMessage("No plugins to update.");
|
player.sendMessage("No plugins to update.");
|
||||||
} else {
|
} else {
|
||||||
player.sendMessage("Status for " + files.length
|
player.sendMessage("Status for " + files.length
|
||||||
+ " 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) {
|
||||||
checkForUpdate(file, player);
|
continue;
|
||||||
}
|
}
|
||||||
}
|
checkForUpdate(file, player);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks for an update for a given plugin
|
* Checks for an update for a given plugin
|
||||||
*
|
*
|
||||||
* @param file
|
* @param file
|
||||||
* The plugin file to check for an update
|
* The plugin file to check for an update
|
||||||
* @param player
|
* @param player
|
||||||
* The player to send info to
|
* The player to send info to
|
||||||
*/
|
*/
|
||||||
private void checkForUpdate(File file, Player player) {
|
private void checkForUpdate(File file, Player player) {
|
||||||
PluginDescriptionFile pdfFile = Checker.getPDF(file);
|
PluginDescriptionFile pdfFile = Checker.getPDF(file);
|
||||||
FillReader reader = needsUpdate(pdfFile);
|
FillReader reader = needsUpdate(pdfFile);
|
||||||
if (reader != null) {
|
if (reader != null) {
|
||||||
player.sendMessage(Color.RED + reader.getName() + " "
|
player.sendMessage(Color.RED + reader.getName() + " "
|
||||||
+ pdfFile.getVersion() + " has an update to "
|
+ pdfFile.getVersion() + " has an update to "
|
||||||
+ reader.getCurrVersion());
|
+ reader.getCurrVersion());
|
||||||
} else {
|
} else {
|
||||||
player.sendMessage(reader.getName() + " " + reader.getCurrVersion()
|
player.sendMessage(reader.getName() + " " + reader.getCurrVersion()
|
||||||
+ " is up to date!");
|
+ " is up to date!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if a given plugin needs an update
|
* Checks if a given plugin needs an update
|
||||||
*
|
*
|
||||||
* @param file
|
* @param file
|
||||||
* The .yml file to check
|
* The .yml file to check
|
||||||
* @return The FillReader for the online repo info on the plugin
|
* @return The FillReader for the online repo info on the plugin
|
||||||
*/
|
*/
|
||||||
static FillReader needsUpdate(PluginDescriptionFile file) {
|
static FillReader needsUpdate(PluginDescriptionFile file) {
|
||||||
FillReader reader = new FillReader(file.getName());
|
FillReader reader = new FillReader(file.getName());
|
||||||
String version = file.getVersion();
|
String version = file.getVersion();
|
||||||
String currVersion = reader.getCurrVersion();
|
String currVersion = reader.getCurrVersion();
|
||||||
String name = reader.getName();
|
String name = reader.getName();
|
||||||
if (currVersion.equalsIgnoreCase(version)
|
if (currVersion.equalsIgnoreCase(version)
|
||||||
&& new File(directory, name + ".jar").exists()) {
|
&& new File(directory, name + ".jar").exists()) {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
return reader;
|
return reader;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Will grab the plugin's .yml file from the give file (hopefully a plugin).
|
|
||||||
* It'll throw it into a PluginDescriptionFile
|
|
||||||
*
|
|
||||||
* @param file
|
|
||||||
* The plugin (jar) file
|
|
||||||
* @return The PluginDescriptionFile representing the .yml
|
|
||||||
*/
|
|
||||||
static PluginDescriptionFile getPDF(File file) {
|
|
||||||
// TODO supports only jar files for now. how will yml's be stored in
|
|
||||||
// different languages?
|
|
||||||
if (file.getName().endsWith(".jar")) {
|
|
||||||
JarFile jarFile;
|
|
||||||
try {
|
|
||||||
jarFile = new JarFile(file);
|
|
||||||
JarEntry entry = jarFile.getJarEntry("plugin.yml");
|
|
||||||
InputStream input = jarFile.getInputStream(entry);
|
|
||||||
return new PluginDescriptionFile(input);
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return null;
|
|
||||||
} catch (InvalidDescriptionException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Will grab the plugin's .yml file from the give file (hopefully a plugin).
|
||||||
|
* It'll throw it into a PluginDescriptionFile
|
||||||
|
*
|
||||||
|
* @param file
|
||||||
|
* The plugin (jar) file
|
||||||
|
* @return The PluginDescriptionFile representing the .yml
|
||||||
|
*/
|
||||||
|
static PluginDescriptionFile getPDF(File file) {
|
||||||
|
// TODO supports only jar files for now. how will yml's be stored in
|
||||||
|
// different languages?
|
||||||
|
if (file.getName().endsWith(".jar")) {
|
||||||
|
JarFile jarFile;
|
||||||
|
try {
|
||||||
|
jarFile = new JarFile(file);
|
||||||
|
JarEntry entry = jarFile.getJarEntry("plugin.yml");
|
||||||
|
InputStream input = jarFile.getInputStream(entry);
|
||||||
|
return new PluginDescriptionFile(input);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
} catch (InvalidDescriptionException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,159 +4,161 @@ 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
|
||||||
* tries to get the .jars out of it
|
* tries to get the .jars out of it
|
||||||
*
|
*
|
||||||
* @param url
|
* @param url
|
||||||
* The url to download from
|
* The url to download from
|
||||||
*/
|
*/
|
||||||
static void downloadJar(String url) throws Exception {
|
static void downloadJar(String url) throws Exception {
|
||||||
int index = url.lastIndexOf('/');
|
int index = url.lastIndexOf('/');
|
||||||
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);
|
||||||
/*if (name.endsWith(".zip") || name.endsWith(".tar")
|
/*if (name.endsWith(".zip") || name.endsWith(".tar")
|
||||||
|| name.endsWith(".rar") || name.endsWith(".7z")) {
|
|| name.endsWith(".rar") || name.endsWith(".7z")) {
|
||||||
unzipPlugin(file);
|
unzipPlugin(file);
|
||||||
file.delete();
|
file.delete();
|
||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Downloads the file for a given plugin
|
* Downloads the file for a given plugin
|
||||||
*
|
*
|
||||||
* @param name
|
* @param name
|
||||||
* The name of the plugin to download
|
* The name of the plugin to download
|
||||||
* @param player
|
* @param player
|
||||||
* The player to send info to
|
* The player to send info to
|
||||||
*/
|
*/
|
||||||
void downloadFile(String name, Player player) throws Exception {
|
void downloadFile(String name, Player player) throws Exception {
|
||||||
File file = new File(directory, name + ".jar");
|
File file = new File(directory, name + ".jar");
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
player.sendMessage("Downloading " + name + "'s file");
|
player.sendMessage("Downloading " + name + "'s file");
|
||||||
PluginDescriptionFile pdfFile = Checker.getPDF(file);
|
PluginDescriptionFile pdfFile = Checker.getPDF(file);
|
||||||
FillReader reader = Checker.needsUpdate(pdfFile);
|
FillReader reader = Checker.needsUpdate(pdfFile);
|
||||||
downloadFile(new URL(reader.getFile()));
|
downloadFile(new URL(reader.getFile()));
|
||||||
player.sendMessage("Finished download");
|
player.sendMessage("Finished download");
|
||||||
} else {
|
} else {
|
||||||
System.out.println("Can't find " + name);
|
System.out.println("Can't find " + name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Downloads the file to the plugin/downloads directory
|
* Downloads the file to the plugin/downloads directory
|
||||||
*
|
*
|
||||||
* @param u
|
* @param u
|
||||||
* The url of the file to download
|
* The url of the file to download
|
||||||
*/
|
*/
|
||||||
private void downloadFile(URL u) throws Exception {
|
private void downloadFile(URL u) throws Exception {
|
||||||
String name = u.getFile();
|
String name = u.getFile();
|
||||||
int index = name.lastIndexOf('/');
|
int index = name.lastIndexOf('/');
|
||||||
name = name.substring(index + 1);
|
name = name.substring(index + 1);
|
||||||
download(u, name, downloads);
|
download(u, name, downloads);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Downloads the file to a given directory with a given name
|
* Downloads the file to a given directory with a given name
|
||||||
*
|
*
|
||||||
* @param u
|
* @param u
|
||||||
* The url of the file to download
|
* The url of the file to download
|
||||||
* @param name
|
* @param name
|
||||||
* The name to give the file
|
* The name to give the file
|
||||||
* @param directory
|
* @param directory
|
||||||
* The directory to put the file
|
* The directory to put the file
|
||||||
*/
|
*/
|
||||||
private static void download(URL u, String name, String directory)
|
private static void download(URL u, String name, String directory)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
InputStream inputStream = null;
|
InputStream inputStream = null;
|
||||||
// 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) {
|
}
|
||||||
System.out.println("[UPDATR]: Error closing inputStream");
|
} catch (IOException ioe) {
|
||||||
}
|
System.out.println("[UPDATR]: Error closing inputStream");
|
||||||
// }
|
}
|
||||||
}
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decompresses a file! How nice.
|
* Decompresses a file! How nice.
|
||||||
*
|
*
|
||||||
* @param f
|
* @param f
|
||||||
* the file to decompress
|
* the file to decompress
|
||||||
*/
|
*/
|
||||||
private static void unzipPlugin(File f) {
|
private static void unzipPlugin(File f) {
|
||||||
try {
|
try {
|
||||||
System.out.println("Extracting jars out of " + f.getName());
|
System.out.println("Extracting jars out of " + f.getName());
|
||||||
//ExtractorUtil.extract(f, f.getAbsolutePath());
|
//ExtractorUtil.extract(f, f.getAbsolutePath());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.out.println("[UPDATR]: Error decompressing " + f.getName());
|
System.out.println("[UPDATR]: Error decompressing " + f.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copies an InputStream to an OutputStream!
|
* Copies an InputStream to an OutputStream!
|
||||||
*
|
*
|
||||||
* @param in
|
* @param in
|
||||||
* InputStream
|
* InputStream
|
||||||
* @param out
|
* @param out
|
||||||
* OutputStream
|
* OutputStream
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
private static final void copyInputStream(InputStream in, OutputStream out)
|
private static final void copyInputStream(InputStream in, OutputStream out)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
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.
|
*
|
||||||
*
|
* @param file
|
||||||
* @param file
|
* The file to backup
|
||||||
* The file to backup
|
*/
|
||||||
*/
|
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
|
file.renameTo(new File(backup, file.getName() + ".bak"));
|
||||||
.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;
|
||||||
@ -13,70 +12,68 @@ import org.json.simple.parser.ParseException;
|
|||||||
* Grabs the latest info for a given plugin from fill.bukkit.org
|
* Grabs the latest info for a given plugin from fill.bukkit.org
|
||||||
*/
|
*/
|
||||||
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 file;
|
||||||
|
private String name;
|
||||||
|
private String notes;
|
||||||
|
private boolean stable;
|
||||||
|
|
||||||
private String currVersion;
|
public FillReader(String name) {
|
||||||
private String file;
|
try {
|
||||||
private String name;
|
String result = "";
|
||||||
private String notes;
|
try {
|
||||||
private boolean stable;
|
URL url = new URL(baseUrl + "?name=" + name);
|
||||||
|
System.out.println(baseUrl + "?name=" + name);
|
||||||
public FillReader(String name) {
|
URLConnection conn = url.openConnection();
|
||||||
try {
|
StringBuilder buf = new StringBuilder();
|
||||||
String result = "";
|
BufferedReader rd = new BufferedReader(new InputStreamReader(
|
||||||
try {
|
conn.getInputStream()));
|
||||||
URL url = new URL(baseUrl + "?name=" + name);
|
String line;
|
||||||
System.out.println(baseUrl + "?name=" + name);
|
while ((line = rd.readLine()) != null) {
|
||||||
URLConnection conn = url.openConnection();
|
buf.append(line);
|
||||||
StringBuilder buf = new StringBuilder();
|
}
|
||||||
BufferedReader rd = new BufferedReader(new InputStreamReader(
|
result = buf.toString();
|
||||||
conn.getInputStream()));
|
rd.close();
|
||||||
String line;
|
JSONParser parser = new JSONParser();
|
||||||
while ((line = rd.readLine()) != null) {
|
Object obj;
|
||||||
buf.append(line);
|
obj = parser.parse(result);
|
||||||
}
|
JSONObject jsonObj = (JSONObject) obj;
|
||||||
result = buf.toString();
|
this.currVersion = (String) jsonObj.get("plugin_version");
|
||||||
rd.close();
|
this.name = (String) jsonObj.get("plugin_name");
|
||||||
JSONParser parser = new JSONParser();
|
this.file = (String) jsonObj.get("plugin_file");
|
||||||
Object obj;
|
this.stable = (Boolean) jsonObj.get("plugin_stable");
|
||||||
obj = parser.parse(result);
|
this.notes = (String) jsonObj.get("plugin_notes");
|
||||||
JSONObject jsonObj = (JSONObject) obj;
|
} catch (ParseException e) {
|
||||||
this.currVersion = (String)jsonObj.get("plugin_version");
|
e.printStackTrace();
|
||||||
this.name = (String)jsonObj.get("plugin_name");
|
}
|
||||||
this.file = (String)jsonObj.get("plugin_file");
|
} catch (Exception e) {
|
||||||
this.stable = (Boolean)jsonObj.get("plugin_stable");
|
e.printStackTrace();
|
||||||
this.notes = (String)jsonObj.get("plugin_notes");
|
}
|
||||||
} catch (ParseException e) {
|
}
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCurrVersion() {
|
|
||||||
return currVersion;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getFile() {
|
public String getCurrVersion() {
|
||||||
return file;
|
return currVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getFile() {
|
||||||
return name;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getNotes() {
|
|
||||||
return notes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStable(boolean stable) {
|
|
||||||
this.stable = stable;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isStable() {
|
public String getName() {
|
||||||
return stable;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getNotes() {
|
||||||
|
return notes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStable(boolean stable) {
|
||||||
|
this.stable = stable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isStable() {
|
||||||
|
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 {
|
||||||
|
@ -6,41 +6,38 @@ import org.bukkit.*;
|
|||||||
import org.bukkit.plugin.InvalidPluginException;
|
import org.bukkit.plugin.InvalidPluginException;
|
||||||
|
|
||||||
public class Getter {
|
public class Getter {
|
||||||
private Server server;
|
private Server server;
|
||||||
private static String directory = Fillr.directory;
|
private static String directory = Fillr.directory;
|
||||||
|
|
||||||
public Getter(Server server) {
|
|
||||||
this.server = server;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void get(String string, Player player) {
|
public Getter(Server server) {
|
||||||
FillReader reader = new FillReader(string);
|
this.server = server;
|
||||||
player.sendMessage("Downloading " + reader.getName() + " "
|
}
|
||||||
+ reader.getCurrVersion());
|
|
||||||
try {
|
public void get(String string, Player player) {
|
||||||
Downloader.downloadJar(reader.getFile());
|
FillReader reader = new FillReader(string);
|
||||||
if (reader.getNotes() != null && !reader.getNotes().equals("")) {
|
player.sendMessage("Downloading " + reader.getName() + " "
|
||||||
player.sendMessage("Notes: " + reader.getNotes());
|
+ reader.getCurrVersion());
|
||||||
}
|
try {
|
||||||
player.sendMessage("Finished Download!");
|
Downloader.downloadJar(reader.getFile());
|
||||||
enablePlugin(reader);
|
if (reader.getNotes() != null && !reader.getNotes().equals("")) {
|
||||||
player.sendMessage("Loading " + reader.getName());
|
player.sendMessage("Notes: " + reader.getNotes());
|
||||||
} catch (Exception e) {
|
}
|
||||||
e.printStackTrace();
|
player.sendMessage("Finished Download!");
|
||||||
}
|
enablePlugin(reader);
|
||||||
|
player.sendMessage("Loading " + reader.getName());
|
||||||
}
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
private void enablePlugin(FillReader update) {
|
}
|
||||||
final String name = update.getName();
|
}
|
||||||
//TODO again with the implicit jar support...
|
|
||||||
File plugin = new File(directory, name + ".jar");
|
private void enablePlugin(FillReader update) {
|
||||||
try {
|
final String name = update.getName();
|
||||||
server.getPluginManager().loadPlugin(plugin);
|
//TODO again with the implicit jar support...
|
||||||
} catch (InvalidPluginException e) {
|
File plugin = new File(directory, name + ".jar");
|
||||||
e.printStackTrace();
|
try {
|
||||||
}
|
server.getPluginManager().loadPlugin(plugin);
|
||||||
}
|
} catch (InvalidPluginException e) {
|
||||||
|
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,105 +4,105 @@ 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;
|
||||||
private final Server server;
|
private final Server server;
|
||||||
|
|
||||||
Updater(Server server) {
|
|
||||||
this.server = server;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
Updater(Server server) {
|
||||||
* Checks and updates the plugins
|
this.server = server;
|
||||||
*
|
}
|
||||||
* @param player
|
|
||||||
* The player to send info to
|
|
||||||
*/
|
|
||||||
void updateAll(Player player) {
|
|
||||||
File folder = new File(directory);
|
|
||||||
File[] files = folder.listFiles(new PluginFilter());
|
|
||||||
if (files.length == 0) {
|
|
||||||
player.sendMessage("No plugins to update.");
|
|
||||||
} else {
|
|
||||||
player.sendMessage("Updating "
|
|
||||||
+ files.length + " plugins:");
|
|
||||||
for (File file : files) {
|
|
||||||
PluginDescriptionFile pdfFile = Checker.getPDF(file);
|
|
||||||
if(pdfFile == null) continue;
|
|
||||||
FillReader reader = Checker.needsUpdate(pdfFile);
|
|
||||||
if (reader != null)
|
|
||||||
update(reader, player);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if a given plugin needs an update, if it does, it updates it
|
* Checks and updates the plugins
|
||||||
*
|
*
|
||||||
* @param string
|
* @param player
|
||||||
* The name of the plugin
|
* The player to send info to
|
||||||
* @param player
|
*/
|
||||||
* The player to send info to
|
void updateAll(Player player) {
|
||||||
*/
|
File folder = new File(directory);
|
||||||
void update(String string, Player player) {
|
File[] files = folder.listFiles(new PluginFilter());
|
||||||
//TODO so much .jars
|
if (files.length == 0) {
|
||||||
File file = new File(directory, string + ".jar");
|
player.sendMessage("No plugins to update.");
|
||||||
if (file.exists()) {
|
} else {
|
||||||
PluginDescriptionFile pdfFile = Checker.getPDF(file);
|
player.sendMessage("Updating "
|
||||||
FillReader reader = Checker.needsUpdate(pdfFile);
|
+ files.length + " plugins:");
|
||||||
if (reader != null) {
|
for (File file : files) {
|
||||||
update(reader, player);
|
PluginDescriptionFile pdfFile = Checker.getPDF(file);
|
||||||
} else {
|
if (pdfFile == null) {
|
||||||
player.sendMessage(string + " is up to date");
|
continue;
|
||||||
}
|
}
|
||||||
} else {
|
FillReader reader = Checker.needsUpdate(pdfFile);
|
||||||
player.sendMessage("Can't find " + string);
|
if (reader != null) {
|
||||||
}
|
update(reader, player);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Downloads the plugin specified by the URLReader
|
* Checks if a given plugin needs an update, if it does, it updates it
|
||||||
*
|
*
|
||||||
* @param update
|
* @param string
|
||||||
* The FillReader with all the plugin info
|
* The name of the plugin
|
||||||
* @param player The player to send info to
|
* @param player
|
||||||
*/
|
* The player to send info to
|
||||||
private void update(FillReader update, Player player) {
|
*/
|
||||||
disablePlugin(update);
|
void update(String string, Player player) {
|
||||||
player.sendMessage("Disabling " + update.getName() + " for update");
|
//TODO so much .jars
|
||||||
player.sendMessage("Downloading " + update.getName() + " "
|
File file = new File(directory, string + ".jar");
|
||||||
+ update.getCurrVersion());
|
if (file.exists()) {
|
||||||
try {
|
PluginDescriptionFile pdfFile = Checker.getPDF(file);
|
||||||
Downloader.downloadJar(update.getFile());
|
FillReader reader = Checker.needsUpdate(pdfFile);
|
||||||
if (update.getNotes() != null && !update.getNotes().equals("")) {
|
if (reader != null) {
|
||||||
player.sendMessage("Notes: " + update.getNotes());
|
update(reader, player);
|
||||||
}
|
} else {
|
||||||
player.sendMessage("Finished Download!");
|
player.sendMessage(string + " is up to date");
|
||||||
enablePlugin(update);
|
}
|
||||||
player.sendMessage("Loading " + update.getName());
|
} else {
|
||||||
} catch (Exception e) {
|
player.sendMessage("Can't find " + string);
|
||||||
e.printStackTrace();
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void enablePlugin(FillReader update) {
|
/**
|
||||||
final String name = update.getName();
|
* Downloads the plugin specified by the URLReader
|
||||||
//TODO again with the implicit jar support...
|
*
|
||||||
File plugin = new File(directory, name + ".jar");
|
* @param update
|
||||||
try {
|
* The FillReader with all the plugin info
|
||||||
server.getPluginManager().loadPlugin(plugin);
|
* @param player The player to send info to
|
||||||
} catch (InvalidPluginException e) {
|
*/
|
||||||
e.printStackTrace();
|
private void update(FillReader update, Player player) {
|
||||||
}
|
disablePlugin(update);
|
||||||
}
|
player.sendMessage("Disabling " + update.getName() + " for update");
|
||||||
|
player.sendMessage("Downloading " + update.getName() + " "
|
||||||
|
+ update.getCurrVersion());
|
||||||
|
try {
|
||||||
|
Downloader.downloadJar(update.getFile());
|
||||||
|
if (update.getNotes() != null && !update.getNotes().equals("")) {
|
||||||
|
player.sendMessage("Notes: " + update.getNotes());
|
||||||
|
}
|
||||||
|
player.sendMessage("Finished Download!");
|
||||||
|
enablePlugin(update);
|
||||||
|
player.sendMessage("Loading " + update.getName());
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void disablePlugin(FillReader update) {
|
void enablePlugin(FillReader update) {
|
||||||
String name = update.getName();
|
final String name = update.getName();
|
||||||
Plugin plugin = server.getPluginManager().getPlugin(name);
|
//TODO again with the implicit jar support...
|
||||||
server.getPluginManager().disablePlugin(plugin);
|
File plugin = new File(directory, name + ".jar");
|
||||||
}
|
try {
|
||||||
}
|
server.getPluginManager().loadPlugin(plugin);
|
||||||
|
} catch (InvalidPluginException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void disablePlugin(FillReader update) {
|
||||||
|
String name = update.getName();
|
||||||
|
Plugin plugin = server.getPluginManager().getPlugin(name);
|
||||||
|
server.getPluginManager().disablePlugin(plugin);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user