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,6 +284,7 @@ public class PluginMain extends JavaPlugin
*/ */
} }
}, 1, 10); }, 1, 10);
if (getServer().getPluginManager().isPluginEnabled("Movecraft")) {
this.getServer().getScheduler() this.getServer().getScheduler()
.scheduleSyncRepeatingTask(this, new Runnable() .scheduleSyncRepeatingTask(this, new Runnable()
{ {
@ -324,6 +325,7 @@ public class PluginMain extends JavaPlugin
} }
} }
}, 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,