Stop throwing the exceptions and instead catch them earlier.
This commit is contained in:
parent
0b8a86e6de
commit
cae9917a8e
Binary file not shown.
@ -2,6 +2,7 @@ package sig.plugin.TwosideKeeper;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.file.CopyOption;
|
import java.nio.file.CopyOption;
|
||||||
@ -30,22 +31,39 @@ public class AutoUpdatePlugin implements Runnable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
|
||||||
FetchPlugins();
|
FetchPlugins();
|
||||||
|
}
|
||||||
|
|
||||||
|
void FetchPlugins(){
|
||||||
|
for (int i=0;i<plugins.size();i++) {
|
||||||
|
try {
|
||||||
|
FileUtils.copyURLToFile(new URL(plugins.get(i).url), new File(TwosideKeeper.filesave,"updates/"+plugins.get(i).name));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void FetchPlugins() throws IOException {
|
|
||||||
for (int i=0;i<plugins.size();i++) {
|
|
||||||
FileUtils.copyURLToFile(new URL(plugins.get(i).url), new File(TwosideKeeper.filesave,"updates/"+plugins.get(i).name));
|
|
||||||
|
|
||||||
//After that's done, check the hash.
|
//After that's done, check the hash.
|
||||||
FileInputStream file = new FileInputStream(new File(TwosideKeeper.filesave,"updates/"+plugins.get(i).name));
|
FileInputStream file = null;
|
||||||
String md5 = org.apache.commons.codec.digest.DigestUtils.md5Hex(file);
|
try {
|
||||||
|
file = new FileInputStream(new File(TwosideKeeper.filesave,"updates/"+plugins.get(i).name));
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
String md5 = null;
|
||||||
|
try {
|
||||||
|
md5 = org.apache.commons.codec.digest.DigestUtils.md5Hex(file);
|
||||||
|
} catch (IOException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
try {
|
||||||
file.close();
|
file.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
if (plugins.get(i).hash==null || !md5.equalsIgnoreCase(plugins.get(i).hash)) {
|
if (plugins.get(i).hash==null || !md5.equalsIgnoreCase(plugins.get(i).hash)) {
|
||||||
//This plugin is different! Update the hash for it. Prepare for a restart of the server!
|
//This plugin is different! Update the hash for it. Prepare for a restart of the server!
|
||||||
@ -55,8 +73,13 @@ public class AutoUpdatePlugin implements Runnable {
|
|||||||
SaveHash(plugins.get(i));
|
SaveHash(plugins.get(i));
|
||||||
Bukkit.broadcastMessage("The server has detected a new version of "+ChatColor.YELLOW+plugins.get(i).name+". The server will restart in 3 minutes!");
|
Bukkit.broadcastMessage("The server has detected a new version of "+ChatColor.YELLOW+plugins.get(i).name+". The server will restart in 3 minutes!");
|
||||||
//Move the file to the new location.
|
//Move the file to the new location.
|
||||||
|
try {
|
||||||
FileUtils.copyFile(new File(TwosideKeeper.filesave,"updates/"+plugins.get(i).name),
|
FileUtils.copyFile(new File(TwosideKeeper.filesave,"updates/"+plugins.get(i).name),
|
||||||
new File(TwosideKeeper.filesave,"../"+plugins.get(i).name+".jar"));
|
new File(TwosideKeeper.filesave,"../"+plugins.get(i).name+".jar"));
|
||||||
|
} catch (IOException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (restarting) {
|
if (restarting) {
|
||||||
|
@ -370,13 +370,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
|
|||||||
//Every 5 minutes, check for a plugin update.
|
//Every 5 minutes, check for a plugin update.
|
||||||
getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){
|
getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){
|
||||||
public void run(){
|
public void run(){
|
||||||
try {
|
|
||||||
pluginupdater.FetchPlugins();
|
pluginupdater.FetchPlugins();
|
||||||
} catch (IOException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
|
|
||||||
}
|
|
||||||
}}, 20*300, 20*300);
|
}}, 20*300, 20*300);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user