Example #1
0
 @Override
 public void onDisable() {
   performanceMonitor.infanticide();
   timer.cancel();
   try {
     if (panelListener != null) panelListener.stopServer();
   } catch (final Exception e) {
     getLogger().severe(e.getMessage());
   }
   edt.setRunning(false);
   synchronized (edt) {
     edt.notifyAll();
   }
   toolkitEventWorker.setEnabled(false);
 }
Example #2
0
  @Override
  public void onEnable() {
    spacebukkit = this;

    config = YamlConfiguration.loadConfiguration(new File("SpaceModule", "configuration.yml"));
    config.addDefault("General.salt", "<default>");
    config.addDefault("General.worldContainer", Bukkit.getWorldContainer().getPath());
    config.addDefault("General.bindIp", Bukkit.getServer().getIp());
    config.addDefault("SpaceBukkit.port", 2011);
    config.addDefault("SpaceRTK.port", 2012);
    config.addDefault("SpaceBukkit.maxJoins", 199);
    config.addDefault("SpaceBukkit.maxMessages", 199);
    config.addDefault("SpaceBukkit.maxQuits", 199);
    config.options().copyDefaults(true);
    salt = config.getString("General.salt", "<default>");
    if (salt.equals("<default>")) {
      salt = UUID.randomUUID().toString().replaceAll("-", "").toUpperCase();
      config.set("General.salt", salt);
    }
    config.set("General.worldContainer", Bukkit.getWorldContainer().getPath());
    port = config.getInt("SpaceBukkit.port", 2011);
    rPort = config.getInt("SpaceRTK.port", 2012);

    String bindAddressString = config.getString("General.bindIp", "0.0.0.0");
    if (bindAddressString.trim().isEmpty()) bindAddressString = "0.0.0.0";
    try {
      bindAddress = InetAddress.getByName(bindAddressString);
    } catch (UnknownHostException e) {
      try {
        bindAddress = InetAddress.getLocalHost();
      } catch (UnknownHostException e2) {
      }
      System.err.println("Warning: Could not assign bind address " + bindAddressString + ":");
      System.err.println(e.getMessage());
      System.err.println("Will bind to loopback address: " + bindAddress.getHostAddress() + "...");
    }

    pingPort = config.getInt("SpaceBukkit.pingPort", 2014);
    maxJoins = config.getInt("SpaceBukkit.maxJoins", 199);
    maxMessages = config.getInt("SpaceBukkit.maxMessages", 199);
    maxQuits = config.getInt("SpaceBukkit.maxQuits", 199);
    try {
      config.save(SpaceModule.CONFIGURATION);
    } catch (IOException e) {
      e.printStackTrace();
    }

    if (edt == null) edt = new EventDispatcher();

    if (toolkitEventWorker == null) {
      toolkitEventWorker = new EventDispatchWorker();
      toolkitEventWorker.setEnabled(true);
      edt.registerEventHandler(eventHandler, toolkitEventWorker);
    }

    if (!edt.isRunning()) {
      synchronized (edt) {
        edt.notifyAll();
      }
      edt.setRunning(true);
      Thread edtThread = new Thread(edt, "SpaceModule EventDispatcher");
      edtThread.setDaemon(true);
      edtThread.start();
    }

    if (!toolkitEventWorker.isRunning()) {
      toolkitEventWorker.setEnabled(true);
    }

    setupMetrics();

    new SBListener(this);
    pluginsManager = new PluginsManager();
    actionsManager = new ActionsManager();
    actionsManager.register(PlayerActions.class);
    actionsManager.register(ServerActions.class);
    actionsManager.register(SystemActions.class);
    panelListener = new PanelListener();
    performanceMonitor = new PerformanceMonitor();
    timer.scheduleAtFixedRate(performanceMonitor, 0L, 1000L);
  }