Directly using VirtualBox from Java #5

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

View file

@ -16,5 +16,6 @@
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="lib" path="vboxjws.jar"/>
<classpathentry kind="output" path="target/classes"/> <classpathentry kind="output" path="target/classes"/>
</classpath> </classpath>

View file

@ -0,0 +1,108 @@
package sznp.virtualcomputer;
import org.virtualbox_5_1.IFramebuffer;
import org.virtualbox_5_1.ObjectRefManager;
import org.virtualbox_5_1.jaxws.VboxPortType;
public class MCFrameBuffer extends IFramebuffer {
public MCFrameBuffer(String wrapped, ObjectRefManager objMgr, VboxPortType port) {
super(wrapped, objMgr, port);
// TODO Auto-generated constructor stub
}
/*@Override
public nsISupports queryInterface(String arg0) {
return null;
}
@Override
public long getBitsPerPixel() {
return 32;
}
@Override
public long getBytesPerLine() {
return 640 * 4;
}
@Override
public long[] getCapabilities(long[] arg0) {
return new long[] { FramebufferCapabilities.UpdateImage };
}
@Override
public long getHeight() {
return 480;
}
@Override
public long getHeightReduction() {
return 0;
}
@Override
public IFramebufferOverlay getOverlay() {
return null;
}
@Override
public long getPixelFormat() {
return BitmapFormat.RGBA;
}
private byte visibleRegionB;
private long visibleRegionL;
@Override
public long getVisibleRegion(byte arg0, long arg1) {
System.out.println("Visible region get.");
return visibleRegionL;
}
@Override
public long getWidth() {
return 640;
}
@Override
public long getWinId() {
return 0;
}
@Override
public void notify3DEvent(long arg0, byte[] arg1) {
}
@Override
public void notifyChange(long arg0, long arg1, long arg2, long arg3, long arg4) {
}
@Override
public void notifyUpdate(long arg0, long arg1, long arg2, long arg3) {
// TODO Auto-generated method stub
System.out.println("UPDATE");
}
@Override
public void notifyUpdateImage(long arg0, long arg1, long arg2, long arg3, byte[] arg4) {
// TODO Auto-generated method stub
System.out.println("UPDATE IMAGE");
}
@Override
public void processVHWACommand(byte arg0) {
}
@Override
public void setVisibleRegion(byte arg0, long arg1) {
visibleRegionB = arg0;
visibleRegionL = arg1;
System.out.println("Visible region set.");
}
@Override
public boolean videoModeSupported(long arg0, long arg1, long arg2) {
return true; // We support EVERYTHING
}*/
}

View file

@ -14,6 +14,9 @@ import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender; import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitTask;
import org.mozilla.interfaces.IFramebufferOverlay;
import org.mozilla.interfaces.nsISupports;
import org.virtualbox_5_1.IFramebuffer;
import org.virtualbox_5_1.ISession; import org.virtualbox_5_1.ISession;
import org.virtualbox_5_1.IVirtualBox; import org.virtualbox_5_1.IVirtualBox;
import org.virtualbox_5_1.VirtualBoxManager; import org.virtualbox_5_1.VirtualBoxManager;
@ -36,9 +39,13 @@ public class PluginMain extends JavaPlugin {
ConsoleCommandSender ccs = getServer().getConsoleSender(); ConsoleCommandSender ccs = getServer().getConsoleSender();
this.getCommand("computer").setExecutor(new Commands()); this.getCommand("computer").setExecutor(new Commands());
ccs.sendMessage("§bInitializing VirtualBox..."); ccs.sendMessage("§bInitializing VirtualBox...");
final VirtualBoxManager manager = VirtualBoxManager.createInstance(null); // Connect con = new Connect("vbox:///");
final VirtualBoxManager manager = VirtualBoxManager.createInstance(getDataFolder().getAbsolutePath());
vbox = manager.getVBox(); vbox = manager.getVBox();
session = manager.getSessionObject(); session = manager.getSessionObject();
vbox.getMachines().get(0).launchVMProcess(session, "headless", "");
session.getConsole().getDisplay().attachFramebuffer(0L, new MCFrameBuffer());
ccs.sendMessage("§bLoading SketchMap..."); ccs.sendMessage("§bLoading SketchMap...");
img = new BufferedImage(640, 480, BufferedImage.TYPE_INT_ARGB); img = new BufferedImage(640, 480, BufferedImage.TYPE_INT_ARGB);
HashMap<Short, RelativeLocation> map = new HashMap<>(); HashMap<Short, RelativeLocation> map = new HashMap<>();

Binary file not shown.

Binary file not shown.

BIN
VirtualComputer/vboxjws.jar Normal file

Binary file not shown.