Changing Movecraft to soft-depend

Needs testing
This commit is contained in:
Norbi Peti 2016-04-07 09:00:25 +02:00
parent 429a6fc175
commit 433fc0c5a8

View file

@ -40,7 +40,7 @@ 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("§bExtracting necessary libraries..."); ccs.sendMessage("§bExtracting necessary libraries...");
final File[] libs = new File[] { // added to class path final File[] libs = new File[] { // added to class path
new File(getDataFolder(), "jni4net.j-0.8.8.0.jar"), new File(getDataFolder(), "jni4net.j-0.8.8.0.jar"),
new File(getDataFolder(), "VirtualComputerSender.j4n.jar") }; new File(getDataFolder(), "VirtualComputerSender.j4n.jar") };
@ -75,17 +75,17 @@ public class PluginMain extends JavaPlugin
} }
addClassPath(JarUtils.getJarUrl(lib)); addClassPath(JarUtils.getJarUrl(lib));
} }
ccs.sendMessage("§bInitializing bridge..."); ccs.sendMessage("§bInitializing bridge...");
// Bridge.setVerbose(true); // Bridge.setVerbose(true);
// Bridge.setDebug(true); // Bridge.setDebug(true);
Bridge.init(new File(getDataFolder(), Bridge.init(new File(getDataFolder(),
"jni4net.n.w64.v40-0.8.8.0.dll").getAbsoluteFile()); "jni4net.n.w64.v40-0.8.8.0.dll").getAbsoluteFile());
Bridge.LoadAndRegisterAssemblyFrom(new File(getDataFolder(), Bridge.LoadAndRegisterAssemblyFrom(new File(getDataFolder(),
"VirtualComputerSender.j4n.dll")); "VirtualComputerSender.j4n.dll"));
ccs.sendMessage("§bInititalizing VirtualBox interface..."); ccs.sendMessage("§bInititalizing VirtualBox interface...");
computer = new Computer(); computer = new Computer();
//ccs.sendMessage("§bLoading ArmorStands..."); //ccs.sendMessage("§bLoading ArmorStands...");
ccs.sendMessage("§bLoading SketchMap..."); ccs.sendMessage("§bLoading SketchMap...");
/* /*
* for (ArmorStand as : Bukkit.getWorlds().get(0) * for (ArmorStand as : Bukkit.getWorlds().get(0)
* .getEntitiesByClass(ArmorStand.class)) * .getEntitiesByClass(ArmorStand.class))
@ -127,7 +127,7 @@ public class PluginMain extends JavaPlugin
for (int j = 0; j < 4; j++) for (int j = 0; j < 4; j++)
map.put((short) (i * 4 + j), new RelativeLocation(i, j)); map.put((short) (i * 4 + j), new RelativeLocation(i, j));
smap = new SketchMap(img, "Screen", 5, 4, false, map); smap = new SketchMap(img, "Screen", 5, 4, false, map);
ccs.sendMessage("§bLoaded!"); ccs.sendMessage("§bLoaded!");
DoStart(); DoStart();
} catch (final Exception e) } catch (final Exception e)
{ {
@ -140,8 +140,8 @@ public class PluginMain extends JavaPlugin
public void onDisable() public void onDisable()
{ {
ConsoleCommandSender ccs = getServer().getConsoleSender(); ConsoleCommandSender ccs = getServer().getConsoleSender();
//ccs.sendMessage("§aSaving ArmorStands..."); //ccs.sendMessage("§aSaving ArmorStands...");
//ccs.sendMessage("§aSaving Maps..."); //ccs.sendMessage("§aSaving Maps...");
/* /*
* for (int i = 0; i < iframes.length; i++) * for (int i = 0; i < iframes.length; i++)
* { * {
@ -154,7 +154,7 @@ public class PluginMain extends JavaPlugin
* } * }
* } * }
*/ */
ccs.sendMessage("§aHuh."); ccs.sendMessage("§aHuh.");
saveConfig(); saveConfig();
} }
@ -169,9 +169,9 @@ 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();
/* /*
* this.getServer().getScheduler() * this.getServer().getScheduler()
@ -284,46 +284,48 @@ public class PluginMain extends JavaPlugin
*/ */
} }
}, 1, 10); }, 1, 10);
this.getServer().getScheduler() if (getServer().getPluginManager().isPluginEnabled("Movecraft")) {
.scheduleSyncRepeatingTask(this, new Runnable() this.getServer().getScheduler()
{ .scheduleSyncRepeatingTask(this, new Runnable()
public void run()
{ {
Craft[] crafts = CraftManager.getInstance() public void run()
.getCraftsInWorld(Bukkit.getWorlds().get(0));
if (crafts == null)
return;
for (Craft c : crafts)
{ {
if (c.getType().getCraftName() Craft[] crafts = CraftManager.getInstance()
.equalsIgnoreCase("mouse")) .getCraftsInWorld(Bukkit.getWorlds().get(0));
if (crafts == null)
return;
for (Craft c : crafts)
{ {
int dx = c.getLastDX(); if (c.getType().getCraftName()
/* .equalsIgnoreCase("mouse"))
* if (dx != 0) {
* System.out.println(dx); int dx = c.getLastDX();
*/ /*
//int dy = c.getLastDY(); * if (dx != 0)
int dz = c.getLastDZ(); * System.out.println(dx);
if (Bukkit */
.getWorlds() //int dy = c.getLastDY();
.get(0) int dz = c.getLastDZ();
.getBlockAt(c.getMinX(), if (Bukkit
c.getMinY() - 1, c.getMinZ()) .getWorlds()
.getType() != Material.AIR .get(0)
&& (dx != 0 || dz != 0)) .getBlockAt(c.getMinX(),
UpdateMouse(null, dx * MouseSpeed, dz c.getMinY() - 1, c.getMinZ())
* MouseSpeed, 0, 0, ""); .getType() != Material.AIR
c.setLastDX(0); && (dx != 0 || dz != 0))
/* UpdateMouse(null, dx * MouseSpeed, dz
* if (dz != 0) * MouseSpeed, 0, 0, "");
* System.out.println(dz); c.setLastDX(0);
*/ /*
c.setLastDZ(0); * if (dz != 0)
* System.out.println(dz);
*/
c.setLastDZ(0);
}
} }
} }
} }, 1, 1);
}, 1, 1); }
getServer().getPluginManager().registerEvents( getServer().getPluginManager().registerEvents(
new MouseLockerPlayerListener(), this); new MouseLockerPlayerListener(), this);
@ -331,7 +333,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();
/* /*
* if (taskid != -1) * if (taskid != -1)
@ -341,13 +343,13 @@ public class PluginMain extends JavaPlugin
* taskid = -1; * taskid = -1;
* } * }
*/ */
sender.sendMessage("§eComputer stopped."); sender.sendMessage("§eComputer stopped.");
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public void PowerButton(CommandSender sender) public void PowerButton(CommandSender sender)
{ {
sender.sendMessage("§eStarting/stoppping computer..."); sender.sendMessage("§eStarting/stoppping computer...");
final CommandSender s = sender; final CommandSender s = sender;
getServer().getScheduler().scheduleAsyncDelayedTask(this, getServer().getScheduler().scheduleAsyncDelayedTask(this,
new Runnable() new Runnable()
@ -358,25 +360,25 @@ public class PluginMain extends JavaPlugin
if (computer.PowerButton()) if (computer.PowerButton())
{ {
DoStart(); DoStart();
s.sendMessage("§eComputer started."); s.sendMessage("§eComputer started.");
} else } else
s.sendMessage("§ePowerbutton pressed."); 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, public void PressKey(CommandSender sender, String key,