Directly using VirtualBox from Java #5
14 changed files with 163 additions and 105 deletions
|
@ -1,6 +1,6 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<classpath>
|
<classpath>
|
||||||
<classpathentry kind="src" output="target/classes" path="src">
|
<classpathentry including="**/*.java" kind="src" output="target/classes" path="src">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="optional" value="true"/>
|
<attribute name="optional" value="true"/>
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
@ -16,6 +16,5 @@
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry kind="lib" path="VirtualComputerSender.j4n.jar"/>
|
|
||||||
<classpathentry kind="output" path="target/classes"/>
|
<classpathentry kind="output" path="target/classes"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
89
VirtualComputer/pom.xml
Normal file
89
VirtualComputer/pom.xml
Normal file
|
@ -0,0 +1,89 @@
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>io.github.NorbiPeti</groupId>
|
||||||
|
<artifactId>VirtualComputer</artifactId>
|
||||||
|
<version>1.2-SNAPSHOT</version>
|
||||||
|
<build>
|
||||||
|
<sourceDirectory>src</sourceDirectory>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>src</directory>
|
||||||
|
<excludes>
|
||||||
|
<exclude>**/*.java</exclude>
|
||||||
|
</excludes>
|
||||||
|
</resource>
|
||||||
|
<resource>
|
||||||
|
<directory>.</directory>
|
||||||
|
<includes>
|
||||||
|
<include>*.dll</include>
|
||||||
|
<include>*.yml</include>
|
||||||
|
</includes>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.5.1</version>
|
||||||
|
<configuration>
|
||||||
|
<source>1.8</source>
|
||||||
|
<target>1.8</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>2.4.2</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<artifactSet>
|
||||||
|
<includes>
|
||||||
|
<include>org.virtualbox:VirtualBox</include>
|
||||||
|
</includes>
|
||||||
|
</artifactSet>
|
||||||
|
<pluginExecution>
|
||||||
|
<action>
|
||||||
|
<execute />
|
||||||
|
</action>
|
||||||
|
</pluginExecution>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>spigot-repo</id>
|
||||||
|
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>repo</id>
|
||||||
|
<url>file://${basedir}/repo</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.spigotmc</groupId>
|
||||||
|
<artifactId>spigot-api</artifactId>
|
||||||
|
<version>1.9.2-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.countercraft</groupId>
|
||||||
|
<artifactId>Movecraft</artifactId>
|
||||||
|
<version>3.0.0</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.virtualbox</groupId>
|
||||||
|
<artifactId>VirtualBox</artifactId>
|
||||||
|
<version>5.1</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
Binary file not shown.
Binary file not shown.
|
@ -2,8 +2,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"
|
<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">
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>io.github.NorbiPeti</groupId>
|
<groupId>org.virtualbox</groupId>
|
||||||
<artifactId>SenderBridge</artifactId>
|
<artifactId>VirtualBox</artifactId>
|
||||||
<version>1.0</version>
|
<version>5.1</version>
|
||||||
<description>POM was created from install:install-file</description>
|
<description>POM was created from install:install-file</description>
|
||||||
</project>
|
</project>
|
|
@ -8,13 +8,12 @@ import org.bukkit.map.MapCanvas;
|
||||||
import org.bukkit.map.MapRenderer;
|
import org.bukkit.map.MapRenderer;
|
||||||
import org.bukkit.map.MapView;
|
import org.bukkit.map.MapView;
|
||||||
|
|
||||||
public class ImageRenderer extends MapRenderer
|
public class ImageRenderer extends MapRenderer // Modified
|
||||||
{
|
{
|
||||||
|
|
||||||
private BufferedImage image;
|
private BufferedImage image;
|
||||||
|
|
||||||
public ImageRenderer(BufferedImage image)
|
public ImageRenderer(BufferedImage image) {
|
||||||
{
|
|
||||||
this.image = image;
|
this.image = image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,29 +21,22 @@ public class ImageRenderer extends MapRenderer
|
||||||
public static int updatepixels = 15;
|
public static int updatepixels = 15;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(MapView view, MapCanvas canvas, Player player)
|
public void render(MapView view, MapCanvas canvas, Player player) {
|
||||||
{
|
|
||||||
long time = System.nanoTime();
|
long time = System.nanoTime();
|
||||||
|
|
||||||
try
|
try {
|
||||||
{
|
canvas.drawImage(0, progress * updatepixels, image.getSubimage(0, progress * updatepixels, 128,
|
||||||
canvas.drawImage(0, progress * updatepixels, image.getSubimage(0,
|
(progress * updatepixels + updatepixels >= 128 ? 128 - progress * updatepixels : updatepixels)));
|
||||||
progress * updatepixels, 128, (progress * updatepixels
|
|
||||||
+ updatepixels >= 128 ? 128 - progress
|
|
||||||
* updatepixels : updatepixels)));
|
|
||||||
if (progress < 128 / updatepixels)
|
if (progress < 128 / updatepixels)
|
||||||
progress++;
|
progress++;
|
||||||
else
|
else
|
||||||
progress = 0;
|
progress = 0;
|
||||||
|
|
||||||
long diff = System.nanoTime() - time;
|
long diff = System.nanoTime() - time;
|
||||||
if (TimeUnit.NANOSECONDS.toMillis(diff) > 40)
|
if (TimeUnit.NANOSECONDS.toMillis(diff) > 40) {
|
||||||
{
|
System.out.println("Map rendering took " + TimeUnit.NANOSECONDS.toMillis(diff) + " ms");
|
||||||
System.out.println("Map rendering took "
|
|
||||||
+ TimeUnit.NANOSECONDS.toMillis(diff) + " ms");
|
|
||||||
}
|
}
|
||||||
} catch (Exception e)
|
} catch (Exception e) {
|
||||||
{
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
System.out.println("Progess: " + progress);
|
System.out.println("Progess: " + progress);
|
||||||
System.out.println("UpdatePixels: " + updatepixels);
|
System.out.println("UpdatePixels: " + updatepixels);
|
||||||
|
|
|
@ -7,7 +7,6 @@ import java.util.HashMap;
|
||||||
|
|
||||||
import net.countercraft.movecraft.craft.Craft;
|
import net.countercraft.movecraft.craft.Craft;
|
||||||
import net.countercraft.movecraft.craft.CraftManager;
|
import net.countercraft.movecraft.craft.CraftManager;
|
||||||
import net.sf.jni4net.Bridge;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
@ -15,14 +14,16 @@ 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.virtualbox_5_1.ISession;
|
||||||
import virtualcomputersender.Computer;
|
import org.virtualbox_5_1.IVirtualBox;
|
||||||
|
import org.virtualbox_5_1.VirtualBoxManager;
|
||||||
|
|
||||||
import com.mcplugindev.slipswhitley.sketchmap.map.RelativeLocation;
|
import com.mcplugindev.slipswhitley.sketchmap.map.RelativeLocation;
|
||||||
import com.mcplugindev.slipswhitley.sketchmap.map.SketchMap;
|
import com.mcplugindev.slipswhitley.sketchmap.map.SketchMap;
|
||||||
|
|
||||||
public class PluginMain extends JavaPlugin {
|
public class PluginMain extends JavaPlugin {
|
||||||
private Computer computer;
|
private IVirtualBox vbox;
|
||||||
|
private ISession session;
|
||||||
private SketchMap smap;
|
private SketchMap smap;
|
||||||
|
|
||||||
public static PluginMain Instance;
|
public static PluginMain Instance;
|
||||||
|
@ -34,26 +35,10 @@ public class PluginMain extends JavaPlugin {
|
||||||
try {
|
try {
|
||||||
ConsoleCommandSender ccs = getServer().getConsoleSender();
|
ConsoleCommandSender ccs = getServer().getConsoleSender();
|
||||||
this.getCommand("computer").setExecutor(new Commands());
|
this.getCommand("computer").setExecutor(new Commands());
|
||||||
ccs.sendMessage("§bExtracting necessary libraries...");
|
ccs.sendMessage("§bInitializing VirtualBox...");
|
||||||
final File[] libs = new File[] {
|
final VirtualBoxManager manager = VirtualBoxManager.createInstance(null);
|
||||||
// new File(getDataFolder(), "jni4net.j-0.8.8.0.jar"),
|
vbox = manager.getVBox();
|
||||||
new File(getDataFolder(), "jni4net.n-0.8.8.0.dll"),
|
session = manager.getSessionObject();
|
||||||
new File(getDataFolder(), "jni4net.n.w64.v40-0.8.8.0.dll"),
|
|
||||||
// new File(getDataFolder(), "VirtualComputerSender.j4n.jar"),
|
|
||||||
new File(getDataFolder(), "VirtualComputerSender.j4n.dll"),
|
|
||||||
new File(getDataFolder(), "VirtualComputerSender.dll"),
|
|
||||||
new File(getDataFolder(), "Interop.VirtualBox.dll") };
|
|
||||||
|
|
||||||
for (final File lib : libs) {
|
|
||||||
if (!lib.exists()) {
|
|
||||||
JarUtils.extractFromJar(lib.getName(), lib.getAbsolutePath());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ccs.sendMessage("§bInitializing bridge...");
|
|
||||||
Bridge.init(new File(getDataFolder(), "jni4net.n.w64.v40-0.8.8.0.dll").getAbsoluteFile());
|
|
||||||
Bridge.LoadAndRegisterAssemblyFrom(new File(getDataFolder(), "VirtualComputerSender.j4n.dll"));
|
|
||||||
ccs.sendMessage("§bInititalizing VirtualBox interface...");
|
|
||||||
computer = new Computer();
|
|
||||||
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<>();
|
||||||
|
@ -82,7 +67,7 @@ public class PluginMain extends JavaPlugin {
|
||||||
|
|
||||||
public void Start(CommandSender sender) {
|
public void Start(CommandSender sender) {
|
||||||
sender.sendMessage("§eStarting computer...");
|
sender.sendMessage("§eStarting computer...");
|
||||||
computer.Start();
|
// computer.Start();
|
||||||
sender.sendMessage("§eComputer started.");
|
sender.sendMessage("§eComputer started.");
|
||||||
DoStart();
|
DoStart();
|
||||||
}
|
}
|
||||||
|
@ -94,8 +79,8 @@ public class PluginMain extends JavaPlugin {
|
||||||
task = this.getServer().getScheduler().runTaskTimerAsynchronously(this, new Runnable() {
|
task = this.getServer().getScheduler().runTaskTimerAsynchronously(this, new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
final int[] a = ((DataBufferInt) smap.image.getRaster().getDataBuffer()).getData();
|
final int[] a = ((DataBufferInt) smap.image.getRaster().getDataBuffer()).getData();
|
||||||
final int[] data = computer.GetScreenPixelColors();
|
// final int[] data = computer.GetScreenPixelColors();
|
||||||
System.arraycopy(data, 0, a, 0, data.length);
|
// System.arraycopy(data, 0, a, 0, data.length);
|
||||||
}
|
}
|
||||||
}, 1, 10);
|
}, 1, 10);
|
||||||
if (getServer().getPluginManager().isPluginEnabled("Movecraft")) {
|
if (getServer().getPluginManager().isPluginEnabled("Movecraft")) {
|
||||||
|
@ -123,7 +108,7 @@ public class PluginMain extends JavaPlugin {
|
||||||
|
|
||||||
public void Stop(CommandSender sender) {
|
public void Stop(CommandSender sender) {
|
||||||
sender.sendMessage("§eStopping computer...");
|
sender.sendMessage("§eStopping computer...");
|
||||||
computer.PowerOff();
|
// computer.PowerOff();
|
||||||
sender.sendMessage("§eComputer stopped.");
|
sender.sendMessage("§eComputer stopped.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,43 +118,36 @@ public class PluginMain extends JavaPlugin {
|
||||||
getServer().getScheduler().runTaskAsynchronously(this, new Runnable() {
|
getServer().getScheduler().runTaskAsynchronously(this, new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (computer.PowerButton()) {
|
/*
|
||||||
DoStart();
|
* if (computer.PowerButton()) { DoStart(); s.sendMessage("§eComputer started."); } else s.sendMessage("§ePowerbutton pressed.");
|
||||||
s.sendMessage("§eComputer started.");
|
*/
|
||||||
} else
|
|
||||||
s.sendMessage("§ePowerbutton pressed.");
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Reset(CommandSender sender) {
|
public void Reset(CommandSender sender) {
|
||||||
sender.sendMessage("§eResetting computer...");
|
sender.sendMessage("§eResetting computer...");
|
||||||
computer.Reset();
|
// computer.Reset();
|
||||||
sender.sendMessage("§eComputer reset.");
|
sender.sendMessage("§eComputer reset.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void FixScreen(CommandSender sender) {
|
public void FixScreen(CommandSender sender) {
|
||||||
sender.sendMessage("§eFixing screen...");
|
sender.sendMessage("§eFixing screen...");
|
||||||
computer.FixScreen();
|
// computer.FixScreen();
|
||||||
sender.sendMessage("§eScreen fixed.");
|
sender.sendMessage("§eScreen fixed.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PressKey(CommandSender sender, String key, String stateorduration) {
|
public void PressKey(CommandSender sender, String key, String stateorduration) {
|
||||||
if (stateorduration.length() == 0)
|
/*
|
||||||
computer.PressKey(key, (short) 0);
|
* if (stateorduration.length() == 0) computer.PressKey(key, (short) 0); else if (stateorduration.equalsIgnoreCase("down")) computer.PressKey(key, (short) -1); else if
|
||||||
else if (stateorduration.equalsIgnoreCase("down"))
|
* (stateorduration.equalsIgnoreCase("up")) computer.PressKey(key, (short) -2); else computer.PressKey(key, Short.parseShort(stateorduration));
|
||||||
computer.PressKey(key, (short) -1);
|
*/
|
||||||
else if (stateorduration.equalsIgnoreCase("up"))
|
|
||||||
computer.PressKey(key, (short) -2);
|
|
||||||
else
|
|
||||||
computer.PressKey(key, Short.parseShort(stateorduration));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateMouse(CommandSender sender, int x, int y, int z, int w, String mbs, boolean down) {
|
public void UpdateMouse(CommandSender sender, int x, int y, int z, int w, String mbs, boolean down) {
|
||||||
if (down)
|
/*
|
||||||
computer.UpdateMouse(x, y, z, w, mbs);
|
* if (down) computer.UpdateMouse(x, y, z, w, mbs); else computer.UpdateMouse(x, y, z, w, "");
|
||||||
else
|
*/
|
||||||
computer.UpdateMouse(x, y, z, w, "");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateMouse(CommandSender sender, int x, int y, int z, int w, String mbs) {
|
public void UpdateMouse(CommandSender sender, int x, int y, int z, int w, String mbs) {
|
||||||
|
|
Loading…
Reference in a new issue