/MCStreamClient/src/org/wyrez/StreamClient/StreamClient.java

https://bitbucket.org/DarthAffe/mcreplay · Java · 65 lines · 54 code · 7 blank · 4 comment · 10 complexity · e14e902eb907f6eac577b4e8aa73f6f5 MD5 · raw file

  1. package org.wyrez.StreamClient;
  2. import java.util.logging.Logger;
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.command.Command;
  5. import org.bukkit.command.CommandSender;
  6. import org.bukkit.plugin.java.JavaPlugin;
  7. import org.wyrez.Replay.Replay;
  8. import org.wyrez.Replay.ReplayManager;
  9. import org.wyrez.StreamClient.network.NetworkManager;
  10. import org.wyrez.StreamClient.npc.PlayerManager;
  11. import org.wyrez.StreamClient.replay.ReplayPlayer;
  12. /**
  13. *
  14. * @author Darth Affe
  15. */
  16. public class StreamClient extends JavaPlugin {
  17. public static final String WORLD = "world";
  18. public static final Logger LOG = Logger.getLogger("Minecraft");
  19. private NetworkManager network;
  20. private PlayerManager playerManager;
  21. private ReplayManager replayManager;
  22. private ReplayPlayer rp;
  23. public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
  24. if (command.getName().equalsIgnoreCase("replay")) {
  25. if (args.length == 1) {
  26. loadReplay(args[0]);
  27. return true;
  28. }
  29. } else if (command.getName().equalsIgnoreCase("rabbrechen")) {
  30. if (rp != null) {
  31. rp.exit();
  32. }
  33. }
  34. return false;
  35. }
  36. private void loadReplay(String name) {
  37. replayManager = new ReplayManager();
  38. Bukkit.broadcastMessage("loading " + name + "...");
  39. Replay r = replayManager.load(name);
  40. if (r == null) {
  41. Bukkit.broadcastMessage("failed!");
  42. } else {
  43. rp = new ReplayPlayer(r, playerManager, Bukkit.getWorld(WORLD), name);
  44. Bukkit.broadcastMessage("running!");
  45. rp.start();
  46. }
  47. }
  48. @Override
  49. public void onDisable() {
  50. LOG.info("StreamClient has been disabled.");
  51. }
  52. @Override
  53. public void onEnable() {
  54. playerManager = new PlayerManager(Bukkit.getWorld(WORLD));
  55. network = new NetworkManager(Bukkit.getWorld(WORLD), playerManager);
  56. LOG.info("StreamClient has been enabled.");
  57. }
  58. }