Directly using VirtualBox from Java #5
6 changed files with 73 additions and 28 deletions
|
@ -90,4 +90,26 @@
|
|||
<version>3.0.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<!-- <profiles>
|
||||
<profile>
|
||||
<id>XPCOM</id>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.virtualbox</groupId>
|
||||
<artifactId>VirtualBox</artifactId>
|
||||
<version>6.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>MSCOM</id>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.virtualbox</groupId>
|
||||
<artifactId>VirtualBox-MSCOM</artifactId>
|
||||
<version>6.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</profile>
|
||||
</profiles> -->
|
||||
</project>
|
Binary file not shown.
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.virtualbox</groupId>
|
||||
<artifactId>VirtualBox-MSCOM</artifactId>
|
||||
<version>6.0</version>
|
||||
<description>POM was created from install:install-file</description>
|
||||
</project>
|
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<metadata>
|
||||
<groupId>org.virtualbox</groupId>
|
||||
<artifactId>VirtualBox-MSCOM</artifactId>
|
||||
<versioning>
|
||||
<release>6.0</release>
|
||||
<versions>
|
||||
<version>6.0</version>
|
||||
</versions>
|
||||
<lastUpdated>20190405225845</lastUpdated>
|
||||
</versioning>
|
||||
</metadata>
|
|
@ -25,11 +25,13 @@ public final class Computer {
|
|||
private IMachine machine;
|
||||
private MachineEventHandler handler;
|
||||
private IEventListener listener;
|
||||
private VirtualBoxManager manager;
|
||||
|
||||
@java.beans.ConstructorProperties({"plugin"})
|
||||
public Computer(PluginMain plugin, ISession session, IVirtualBox vbox) {
|
||||
public Computer(PluginMain plugin, VirtualBoxManager manager, IVirtualBox vbox) {
|
||||
this.plugin = plugin;
|
||||
this.session = session;
|
||||
this.manager = manager;
|
||||
session = manager.getSessionObject();
|
||||
this.vbox = vbox;
|
||||
if (instance != null) throw new IllegalStateException("A computer already exists!");
|
||||
instance = this;
|
||||
|
@ -94,14 +96,13 @@ public final class Computer {
|
|||
public void Stop(CommandSender sender) {
|
||||
if (checkMachineNotRunning(sender)) {
|
||||
if (session.getState().equals(SessionState.Locked)) {
|
||||
session.unlockMachine();
|
||||
sendMessage(sender, "§eComputer powered off, released it.");
|
||||
onMachineStop(sender); //Needed for session reset
|
||||
sendMessage(sender, "§eComputer was already off, released it.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
sendMessage(sender, "§eStopping computer...");
|
||||
session.getConsole().powerDown().waitForCompletion(2000);
|
||||
sendMessage(sender, "§eComputer stopped.");
|
||||
session.getConsole().powerDown();
|
||||
}
|
||||
|
||||
public void PowerButton(CommandSender sender, int index) {
|
||||
|
@ -202,12 +203,13 @@ public final class Computer {
|
|||
session.unlockMachine(); //Needs to be outside of the event handler
|
||||
handler = null;
|
||||
machine = null;
|
||||
session = manager.getSessionObject();
|
||||
sendMessage(sender, "§eComputer powered off."); //This block runs later
|
||||
}
|
||||
});
|
||||
GPURendererInternal.setPixels(new byte[1], 0, 0); //Black screen
|
||||
stopEvents();
|
||||
MouseLockerPlayerListener.computerStop();
|
||||
sendMessage(sender, "§eComputer powered off.");
|
||||
}
|
||||
|
||||
public void stopEvents() {
|
||||
|
@ -217,4 +219,14 @@ public final class Computer {
|
|||
handler.disable();
|
||||
listener = null;
|
||||
}
|
||||
|
||||
public void pluginDisable(CommandSender ccs) {
|
||||
if (session.getState() == SessionState.Locked) {
|
||||
if (session.getMachine().getState().equals(MachineState.Running)) {
|
||||
ccs.sendMessage("§aSaving machine state...");
|
||||
session.getMachine().saveState().waitForCompletion(10000);
|
||||
}
|
||||
session.unlockMachine();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,9 @@ import org.bukkit.Bukkit;
|
|||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.virtualbox_6_0.*;
|
||||
import org.virtualbox_6_0.IEventListener;
|
||||
import org.virtualbox_6_0.IVirtualBox;
|
||||
import org.virtualbox_6_0.VirtualBoxManager;
|
||||
import sznp.virtualcomputer.events.VBoxEventHandler;
|
||||
import sznp.virtualcomputer.renderer.BukkitRenderer;
|
||||
import sznp.virtualcomputer.renderer.GPURenderer;
|
||||
|
@ -21,15 +23,10 @@ import java.util.Arrays;
|
|||
import java.util.function.Predicate;
|
||||
|
||||
public class PluginMain extends JavaPlugin {
|
||||
public static final int MCX = 5;
|
||||
public static final int MCY = 4;
|
||||
private IVirtualBox vbox;
|
||||
private ISession session;
|
||||
private IMachine machine;
|
||||
private BukkitTask screenupdatetask;
|
||||
private static final int MCX = 5;
|
||||
private static final int MCY = 4;
|
||||
private BukkitTask mousetask;
|
||||
private IEventListener listener;
|
||||
private IEventSource source;
|
||||
|
||||
public static PluginMain Instance;
|
||||
//public static ByteBuffer allpixels = ByteBuffer.allocate(640 * 480 * 4); // It's set on each change
|
||||
|
@ -37,7 +34,7 @@ public class PluginMain extends JavaPlugin {
|
|||
* Only used if {@link #direct} is false.
|
||||
*/
|
||||
public static ByteBuffer allpixels; // It's set on each change
|
||||
public static ArrayList<IRenderer> renderers = new ArrayList<>();
|
||||
private static ArrayList<IRenderer> renderers = new ArrayList<>();
|
||||
/*
|
||||
* Only used if {@link #direct} is true.
|
||||
*/
|
||||
|
@ -72,10 +69,9 @@ public class PluginMain extends JavaPlugin {
|
|||
final VirtualBoxManager manager = VirtualBoxManager.createInstance(getDataFolder().getAbsolutePath());
|
||||
VBoxLib vbl = LibraryLoader.create(VBoxLib.class).load("vboxjxpcom");
|
||||
vbl.RTR3InitExe(0, "", 0);
|
||||
vbox = manager.getVBox();
|
||||
listener = new VBoxEventHandler().registerTo(source = vbox.getEventSource());
|
||||
session = manager.getSessionObject();
|
||||
new Computer(this, session, vbox); //Saves itself
|
||||
IVirtualBox vbox = manager.getVBox();
|
||||
listener = new VBoxEventHandler().registerTo(vbox.getEventSource());
|
||||
new Computer(this, manager, vbox); //Saves itself
|
||||
ccs.sendMessage("§bLoading Screen...");
|
||||
try {
|
||||
//throw new NoClassDefFoundError("Test error pls ignore");
|
||||
|
@ -121,14 +117,7 @@ public class PluginMain extends JavaPlugin {
|
|||
}*/
|
||||
((VBoxEventHandler) listener.getTypedWrapped()).disable(); //The save progress wait locks with the event
|
||||
if (Computer.getInstance() != null)
|
||||
Computer.getInstance().stopEvents();
|
||||
if (session.getState() == SessionState.Locked) {
|
||||
if (session.getMachine().getState().equals(MachineState.Running)) {
|
||||
ccs.sendMessage("§aSaving machine state...");
|
||||
session.getMachine().saveState().waitForCompletion(10000);
|
||||
}
|
||||
session.unlockMachine();
|
||||
}
|
||||
Computer.getInstance().pluginDisable(ccs);
|
||||
ccs.sendMessage("§aHuh.");
|
||||
saveConfig();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue