Formatting

By: Dinnerbone <dinnerbone@dinnerbone.com>
This commit is contained in:
Bukkit/Spigot
2011-01-03 15:31:54 +00:00
parent 891a7dd5f8
commit 346e41a6e5
7 changed files with 427 additions and 430 deletions

View File

@@ -4,105 +4,105 @@ import org.bukkit.*;
import org.bukkit.plugin.*;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.jar.*;
public class Updater {
public static String directory = Fillr.directory;
private final Server server;
Updater(Server server) {
this.server = server;
}
public static String directory = Fillr.directory;
private final Server server;
/**
* Checks and updates the plugins
*
* @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);
}
}
}
Updater(Server server) {
this.server = server;
}
/**
* Checks if a given plugin needs an update, if it does, it updates it
*
* @param string
* The name of the plugin
* @param player
* The player to send info to
*/
void update(String string, Player player) {
//TODO so much .jars
File file = new File(directory, string + ".jar");
if (file.exists()) {
PluginDescriptionFile pdfFile = Checker.getPDF(file);
FillReader reader = Checker.needsUpdate(pdfFile);
if (reader != null) {
update(reader, player);
} else {
player.sendMessage(string + " is up to date");
}
} else {
player.sendMessage("Can't find " + string);
}
}
/**
* Checks and updates the plugins
*
* @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);
}
}
}
}
/**
* Downloads the plugin specified by the URLReader
*
* @param update
* The FillReader with all the plugin info
* @param player The player to send info to
*/
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();
}
}
/**
* Checks if a given plugin needs an update, if it does, it updates it
*
* @param string
* The name of the plugin
* @param player
* The player to send info to
*/
void update(String string, Player player) {
//TODO so much .jars
File file = new File(directory, string + ".jar");
if (file.exists()) {
PluginDescriptionFile pdfFile = Checker.getPDF(file);
FillReader reader = Checker.needsUpdate(pdfFile);
if (reader != null) {
update(reader, player);
} else {
player.sendMessage(string + " is up to date");
}
} else {
player.sendMessage("Can't find " + string);
}
}
void enablePlugin(FillReader update) {
final String name = update.getName();
//TODO again with the implicit jar support...
File plugin = new File(directory, name + ".jar");
try {
server.getPluginManager().loadPlugin(plugin);
} catch (InvalidPluginException e) {
e.printStackTrace();
}
}
/**
* Downloads the plugin specified by the URLReader
*
* @param update
* The FillReader with all the plugin info
* @param player The player to send info to
*/
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) {
String name = update.getName();
Plugin plugin = server.getPluginManager().getPlugin(name);
server.getPluginManager().disablePlugin(plugin);
}
}
void enablePlugin(FillReader update) {
final String name = update.getName();
//TODO again with the implicit jar support...
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);
}
}