Directly using VirtualBox from Java #5

Merged
NorbiPeti merged 60 commits from directvb into master 2019-04-18 23:29:21 +00:00
2 changed files with 18 additions and 13 deletions
Showing only changes of commit 042c67a30b - Show all commits

View file

@ -4,11 +4,7 @@ import org.bukkit.Bukkit;
import org.mozilla.interfaces.IFramebuffer;
import org.mozilla.interfaces.IFramebufferOverlay;
import org.mozilla.interfaces.nsISupports;
import org.virtualbox_5_1.BitmapFormat;
import org.virtualbox_5_1.FramebufferCapabilities;
import org.virtualbox_5_1.Holder;
import org.virtualbox_5_1.IDisplay;
import org.virtualbox_5_1.IDisplaySourceBitmap;
import org.virtualbox_5_1.*;
public class MCFrameBuffer implements IFramebuffer {
private IDisplay display;
@ -35,7 +31,7 @@ public class MCFrameBuffer implements IFramebuffer {
@Override
public long[] getCapabilities(long[] arg0) {
return new long[] { FramebufferCapabilities.UpdateImage.value() };
return new long[] {};
}
@Override
@ -80,7 +76,7 @@ public class MCFrameBuffer implements IFramebuffer {
@Override
public void notifyChange(long screenId, long xOrigin, long yOrigin, long width, long height) {
Bukkit.getScheduler().runTaskLaterAsynchronously(PluginMain.Instance, () -> {
display.querySourceBitmap(0L, holder); // TODO: Crashes here
display.querySourceBitmap(0L, holder); // TODO: Test if it crashes here
holder.value.getTypedWrapped().queryBitmapInfo(PluginMain.allpixels, new long[] { width },
new long[] { height }, new long[] { getBitsPerPixel() }, new long[] { getBytesPerLine() },
new long[] { getPixelFormat() }); // These are out params but whatever

View file

@ -63,10 +63,13 @@ public class PluginMain extends JavaPlugin {
@Override
public void onDisable() {
ConsoleCommandSender ccs = getServer().getConsoleSender();
if (session.getState() == SessionState.Locked) {
if (session.getMachine().getState().equals(MachineState.Running)) {
ccs.sendMessage("§aSaving machine state...");
if (session.getState() == SessionState.Locked && session.getMachine().getState().equals(MachineState.Running))
session.getMachine().saveState();
session.getMachine().saveState().waitForCompletion(10000);
}
session.unlockMachine();
}
ccs.sendMessage("§aHuh.");
saveConfig();
}
@ -76,7 +79,10 @@ public class PluginMain extends JavaPlugin {
sender.sendMessage("§eStarting computer...");
if (machine == null)
machine = vbox.getMachines().get(0);
machine.launchVMProcess(session, "headless", "").waitForCompletion(10000);
// 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 = session.getMachine(); // This is the Machine object we can work with
session.getConsole().powerUp().waitForCompletion(10000);
session.getConsole().getDisplay().attachFramebuffer(0L,
new IFramebuffer(new MCFrameBuffer(session.getConsole().getDisplay())));
if (screenupdatetask == null)
@ -86,6 +92,8 @@ public class PluginMain extends JavaPlugin {
session.getConsole().getDisplay().invalidateAndUpdateScreen(0L);
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;
}
@ -99,6 +107,7 @@ public class PluginMain extends JavaPlugin {
public void Stop(CommandSender sender) {
sender.sendMessage("§eStopping computer...");
session.getConsole().powerDown().waitForCompletion(2000);
session.unlockMachine();
sender.sendMessage("§eComputer stopped.");
}
@ -121,7 +130,7 @@ public class PluginMain extends JavaPlugin {
public void Reset(CommandSender sender) {
sender.sendMessage("§eResetting computer...");
if (session.getState() == SessionState.Locked)
session.getConsole().powerDown().waitForCompletion(10000);
session.getConsole().reset();
sender.sendMessage("§eComputer reset.");
}