2011-03-19 22:39:51 +00:00
|
|
|
package com.earth2me.essentials;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.logging.Level;
|
|
|
|
import java.util.logging.Logger;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.craftbukkit.CraftServer;
|
|
|
|
|
|
|
|
public class Backup implements Runnable {
|
|
|
|
private static final Logger logger = Logger.getLogger("Minecraft");
|
|
|
|
private CraftServer server;
|
|
|
|
private boolean running = false;
|
|
|
|
private int taskId = -1;
|
|
|
|
private boolean active = false;
|
|
|
|
|
|
|
|
public Backup() {
|
|
|
|
server = (CraftServer)Essentials.getStatic().getServer();
|
|
|
|
if (server.getOnlinePlayers().length > 0) {
|
|
|
|
startTask();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void onPlayerJoin() {
|
|
|
|
startTask();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void startTask() {
|
|
|
|
if (!running) {
|
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
|
|
|
long interval = Essentials.getStatic().getSettings().getBackupInterval()*1200; // minutes -> ticks
|
2011-03-19 22:39:51 +00:00
|
|
|
if (interval < 1200) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
taskId = server.getScheduler().scheduleSyncRepeatingTask(Essentials.getStatic(), this, interval, interval);
|
|
|
|
running = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void run() {
|
|
|
|
if (active) return;
|
|
|
|
active = true;
|
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
|
|
|
final String command = Essentials.getStatic().getSettings().getBackupCommand();
|
2011-03-19 22:39:51 +00:00
|
|
|
if (command == null || "".equals(command)) {
|
|
|
|
return;
|
|
|
|
}
|
2011-05-09 20:46:25 +00:00
|
|
|
logger.log(Level.INFO, Util.i18n("backupStarted"));
|
2011-03-19 22:39:51 +00:00
|
|
|
final CommandSender cs = server.getServer().console;
|
|
|
|
server.dispatchCommand(cs, "save-all");
|
|
|
|
server.dispatchCommand(cs, "save-off");
|
|
|
|
|
|
|
|
server.getScheduler().scheduleAsyncDelayedTask(Essentials.getStatic(),
|
|
|
|
new Runnable() {
|
|
|
|
|
|
|
|
public void run() {
|
|
|
|
try {
|
|
|
|
Process child = Runtime.getRuntime().exec(command);
|
|
|
|
child.waitFor();
|
|
|
|
} catch (InterruptedException ex) {
|
|
|
|
logger.log(Level.SEVERE, null, ex);
|
|
|
|
} catch (IOException ex) {
|
|
|
|
logger.log(Level.SEVERE, null, ex);
|
|
|
|
} finally {
|
|
|
|
server.getScheduler().scheduleSyncDelayedTask(Essentials.getStatic(),
|
|
|
|
new Runnable() {
|
|
|
|
|
|
|
|
public void run() {
|
|
|
|
server.dispatchCommand(cs, "save-on");
|
|
|
|
if (server.getOnlinePlayers().length == 0) {
|
|
|
|
running = false;
|
|
|
|
if (taskId != -1) {
|
|
|
|
server.getScheduler().cancelTask(taskId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
active = false;
|
2011-05-09 20:46:25 +00:00
|
|
|
logger.log(Level.INFO, Util.i18n("backupFinished"));
|
2011-03-19 22:39:51 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|