mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-04-29 17:58:25 +00:00
Read backup output async
This commit is contained in:
parent
32b118d3c0
commit
52c3169a3c
1 changed files with 62 additions and 50 deletions
|
@ -91,65 +91,77 @@ public class Backup implements Runnable
|
||||||
server.dispatchCommand(cs, "save-all");
|
server.dispatchCommand(cs, "save-all");
|
||||||
server.dispatchCommand(cs, "save-off");
|
server.dispatchCommand(cs, "save-off");
|
||||||
|
|
||||||
ess.runTaskAsynchronously(
|
ess.runTaskAsynchronously(new Runnable()
|
||||||
new Runnable()
|
{
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
@Override
|
final ProcessBuilder childBuilder = new ProcessBuilder(command);
|
||||||
public void run()
|
childBuilder.redirectErrorStream(true);
|
||||||
|
childBuilder.directory(ess.getDataFolder().getParentFile().getParentFile());
|
||||||
|
final Process child = childBuilder.start();
|
||||||
|
ess.runTaskAsynchronously(new Runnable()
|
||||||
{
|
{
|
||||||
try
|
@Override
|
||||||
|
public void run()
|
||||||
{
|
{
|
||||||
final ProcessBuilder childBuilder = new ProcessBuilder(command);
|
|
||||||
childBuilder.redirectErrorStream(true);
|
|
||||||
childBuilder.directory(ess.getDataFolder().getParentFile().getParentFile());
|
|
||||||
final Process child = childBuilder.start();
|
|
||||||
final BufferedReader reader = new BufferedReader(new InputStreamReader(child.getInputStream()));
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
child.waitFor();
|
final BufferedReader reader = new BufferedReader(new InputStreamReader(child.getInputStream()));
|
||||||
String line;
|
try
|
||||||
do
|
|
||||||
{
|
{
|
||||||
line = reader.readLine();
|
String line;
|
||||||
if (line != null)
|
do
|
||||||
{
|
{
|
||||||
LOGGER.log(Level.INFO, line);
|
line = reader.readLine();
|
||||||
}
|
if (line != null)
|
||||||
}
|
|
||||||
while (line != null);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
reader.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (InterruptedException ex)
|
|
||||||
{
|
|
||||||
LOGGER.log(Level.SEVERE, null, ex);
|
|
||||||
}
|
|
||||||
catch (IOException ex)
|
|
||||||
{
|
|
||||||
LOGGER.log(Level.SEVERE, null, ex);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
ess.scheduleSyncDelayedTask(
|
|
||||||
new Runnable()
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
{
|
||||||
server.dispatchCommand(cs, "save-on");
|
LOGGER.log(Level.INFO, line);
|
||||||
if (server.getOnlinePlayers().length == 0)
|
|
||||||
{
|
|
||||||
stopTask();
|
|
||||||
}
|
|
||||||
active = false;
|
|
||||||
LOGGER.log(Level.INFO, _("backupFinished"));
|
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
while (line != null);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
reader.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (IOException ex)
|
||||||
|
{
|
||||||
|
LOGGER.log(Level.SEVERE, null, ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
child.waitFor();
|
||||||
|
}
|
||||||
|
catch (InterruptedException ex)
|
||||||
|
{
|
||||||
|
LOGGER.log(Level.SEVERE, null, ex);
|
||||||
|
}
|
||||||
|
catch (IOException ex)
|
||||||
|
{
|
||||||
|
LOGGER.log(Level.SEVERE, null, ex);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
ess.scheduleSyncDelayedTask(new Runnable()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
server.dispatchCommand(cs, "save-on");
|
||||||
|
if (server.getOnlinePlayers().length == 0)
|
||||||
|
{
|
||||||
|
stopTask();
|
||||||
|
}
|
||||||
|
active = false;
|
||||||
|
LOGGER.log(Level.INFO, _("backupFinished"));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue