Directly using VirtualBox from Java #5
2 changed files with 26 additions and 18 deletions
|
@ -3,7 +3,7 @@
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>io.github.NorbiPeti</groupId>
|
<groupId>io.github.NorbiPeti</groupId>
|
||||||
<artifactId>VirtualComputer</artifactId>
|
<artifactId>VirtualComputer</artifactId>
|
||||||
<version>1.2-SNAPSHOT</version>
|
<version>2.0-SNAPSHOT</version>
|
||||||
<build>
|
<build>
|
||||||
<sourceDirectory>src</sourceDirectory>
|
<sourceDirectory>src</sourceDirectory>
|
||||||
<resources>
|
<resources>
|
||||||
|
|
|
@ -81,23 +81,31 @@ public class PluginMain extends JavaPlugin {
|
||||||
machine = vbox.getMachines().get(0);
|
machine = vbox.getMachines().get(0);
|
||||||
// machine.launchVMProcess(session, "headless", "").waitForCompletion(10000); - This creates a *process*, we don't want that anymore
|
// machine.launchVMProcess(session, "headless", "").waitForCompletion(10000); - This creates a *process*, we don't want that anymore
|
||||||
machine.lockMachine(session, LockType.Write); // We want the machine inside *our* process
|
machine.lockMachine(session, LockType.Write); // We want the machine inside *our* process
|
||||||
machine = session.getMachine(); // This is the Machine object we can work with
|
screenupdatetask = Bukkit.getScheduler().runTaskTimerAsynchronously(this, () -> {
|
||||||
session.getConsole().powerUp().waitForCompletion(10000);
|
if (session.getState() == SessionState.Spawning) // https://www.virtualbox.org/sdkref/_virtual_box_8idl.html#ac82c179a797c0d7c249d1b98a8e3aa8f
|
||||||
session.getConsole().getDisplay().attachFramebuffer(0L,
|
return; // "This state also occurs as a short transient state during an IMachine::lockMachine call."
|
||||||
new IFramebuffer(new MCFrameBuffer(session.getConsole().getDisplay())));
|
else {
|
||||||
if (screenupdatetask == null)
|
screenupdatetask.cancel();
|
||||||
screenupdatetask = Bukkit.getScheduler().runTaskTimerAsynchronously(this, () -> {
|
screenupdatetask = null;
|
||||||
if (session.getState().equals(SessionState.Locked) // Don't run until the machine is running
|
}
|
||||||
&& session.getConsole().getState().equals(MachineState.Running))
|
machine = session.getMachine(); // This is the Machine object we can work with
|
||||||
session.getConsole().getDisplay().invalidateAndUpdateScreen(0L);
|
session.getConsole().powerUp().waitForCompletion(10000);
|
||||||
if (session.getState().equals(SessionState.Unlocked) // Stop if the machine stopped fully
|
session.getConsole().getDisplay().attachFramebuffer(0L,
|
||||||
|| session.getConsole().getState().equals(MachineState.PoweredOff)) {
|
new IFramebuffer(new MCFrameBuffer(session.getConsole().getDisplay())));
|
||||||
if (session.getState().equals(SessionState.Locked))
|
if (screenupdatetask == null)
|
||||||
session.unlockMachine();
|
screenupdatetask = Bukkit.getScheduler().runTaskTimerAsynchronously(this, () -> {
|
||||||
screenupdatetask.cancel();
|
if (session.getState().equals(SessionState.Locked) // Don't run until the machine is running
|
||||||
screenupdatetask = null;
|
&& session.getConsole().getState().equals(MachineState.Running))
|
||||||
}
|
session.getConsole().getDisplay().invalidateAndUpdateScreen(0L);
|
||||||
}, 100, 100); // Do a full update every 5 seconds
|
if (session.getState().equals(SessionState.Unlocked) // Stop if the machine stopped fully
|
||||||
|
|| session.getConsole().getState().equals(MachineState.PoweredOff)) {
|
||||||
|
if (session.getState().equals(SessionState.Locked))
|
||||||
|
session.unlockMachine();
|
||||||
|
screenupdatetask.cancel();
|
||||||
|
screenupdatetask = null;
|
||||||
|
}
|
||||||
|
}, 100, 100); // Do a full update every 5 seconds
|
||||||
|
}, 5, 5);
|
||||||
sender.sendMessage("§eComputer started.");
|
sender.sendMessage("§eComputer started.");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue