mirror of
https://github.com/essentials/Essentials.git
synced 2025-08-23 06:45:04 +02:00
Cleanup of Backup class
This commit is contained in:
@@ -35,7 +35,8 @@ public class Backup implements Runnable, IBackup
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startTask()
|
@Override
|
||||||
|
public final void startTask()
|
||||||
{
|
{
|
||||||
if (running.compareAndSet(false, true))
|
if (running.compareAndSet(false, true))
|
||||||
{
|
{
|
||||||
@@ -63,18 +64,28 @@ public class Backup implements Runnable, IBackup
|
|||||||
final ISettings settings = ess.getSettings();
|
final ISettings settings = ess.getSettings();
|
||||||
settings.acquireReadLock();
|
settings.acquireReadLock();
|
||||||
final String command = settings.getData().getGeneral().getBackup().getCommand();
|
final String command = settings.getData().getGeneral().getBackup().getCommand();
|
||||||
if (command == null || "".equals(command))
|
if (command == null || command.isEmpty())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
LOGGER.log(Level.INFO, _("backupStarted"));
|
LOGGER.log(Level.INFO, _("backupStarted"));
|
||||||
final CommandSender cs = server.getConsoleSender();
|
final CommandSender consoleSender = server.getConsoleSender();
|
||||||
server.dispatchCommand(cs, "save-all");
|
server.dispatchCommand(consoleSender, "save-all");
|
||||||
server.dispatchCommand(cs, "save-off");
|
server.dispatchCommand(consoleSender, "save-off");
|
||||||
|
|
||||||
ess.scheduleAsyncDelayedTask(
|
ess.scheduleAsyncDelayedTask(new BackupRunner(command));
|
||||||
new Runnable()
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private class BackupRunner implements Runnable
|
||||||
{
|
{
|
||||||
|
private final transient String command;
|
||||||
|
|
||||||
|
public BackupRunner(final String command)
|
||||||
|
{
|
||||||
|
this.command = command;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
@@ -114,13 +125,18 @@ public class Backup implements Runnable, IBackup
|
|||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
ess.scheduleSyncDelayedTask(
|
ess.scheduleSyncDelayedTask(new EnableSavingRunner());
|
||||||
new Runnable()
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private class EnableSavingRunner implements Runnable
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
server.dispatchCommand(cs, "save-on");
|
server.dispatchCommand(server.getConsoleSender(), "save-on");
|
||||||
if (server.getOnlinePlayers().length == 0)
|
if (server.getOnlinePlayers().length == 0)
|
||||||
{
|
{
|
||||||
running.set(false);
|
running.set(false);
|
||||||
@@ -129,12 +145,9 @@ public class Backup implements Runnable, IBackup
|
|||||||
server.getScheduler().cancelTask(taskId);
|
server.getScheduler().cancelTask(taskId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
active.set(false);
|
active.set(false);
|
||||||
LOGGER.log(Level.INFO, _("backupFinished"));
|
LOGGER.log(Level.INFO, _("backupFinished"));
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user