Example #1
0
  /**
   * Turns on the plugin. Signs all users into IRC sets shutdown flag to false. parses config file.
   * registers events with bukkit.
   */
  @Override
  public void onEnable() {
    this.playerListener = new IRCTransportPlayerListener(this);
    this.entityListener = new IRCTransportEntityListener(this);
    getConfig().options().copyDefaults(true);
    PluginManager pm = getServer().getPluginManager();
    PluginDescriptionFile pdfFile = this.getDescription();
    if (getConfig().getString("server.address") == null) {
      LOG.severe(
          pdfFile.getName()
              + ": set \"server.address\" in "
              + this.getDataFolder()
              + "/config.yml");
      return;
    }

    getConfig()
        .options()
        .header("Config File for IRCTransport\nSee the website for more information");
    saveConfig();
    initDatabase();

    // establish list of players
    Player[] players = getServer().getOnlinePlayers();
    for (Player player : players) {
      this.bots.put(player.getEntityId(), new IrcAgent(this, player));
    }

    // register for events we care about
    pm.registerEvent(Event.Type.PLAYER_CHAT, playerListener, Priority.Normal, this);
    pm.registerEvent(Event.Type.PLAYER_JOIN, playerListener, Priority.Normal, this);
    pm.registerEvent(Event.Type.PLAYER_QUIT, playerListener, Priority.Normal, this);

    // Using Highest to allow other plugins to manipulate this before we propagate it
    pm.registerEvent(Event.Type.ENTITY_DEATH, entityListener, Priority.Highest, this);

    // set command executors
    IRCTransportCommandExecutor commandExecutor = new IRCTransportCommandExecutor(this);
    getCommand("join").setExecutor(commandExecutor);
    getCommand("leave").setExecutor(commandExecutor);
    getCommand("channel").setExecutor(commandExecutor);
    getCommand("msg").setExecutor(commandExecutor);
    getCommand("nick").setExecutor(commandExecutor);
    getCommand("names").setExecutor(commandExecutor);
    getCommand("me").setExecutor(commandExecutor);
    getCommand("topic").setExecutor(commandExecutor);
    getCommand("whois").setExecutor(commandExecutor);
    LOG.log(Level.INFO, pdfFile.getFullName() + " is enabled!");
  }
Example #2
0
  @Override
  public void onEnable() {
    pdfFile = this.getDescription();
    CraftMailUtil.init(this);
    saveDefaultConfig();
    Configuration config = getConfig();
    boolean keepSettingUp = true;
    useSMTP = config.getBoolean("mail.enabled");
    if (useSMTP) {
      String from = config.getString("mail.smtp.from");
      String fromName = config.getString("mail.smtp.name");
      InternetAddress fromAddress = null;
      try {
        fromAddress = new InternetAddress(from);
      } catch (AddressException ex) {
        log.severe(CraftMailUtil.prependName("Invalid from address specified in config.yml!"));
        if (errorMessage == null)
          errorMessage = "Failed to set up SMTP! Please check console for details.";
        keepSettingUp = false;
      }
      keepSettingUp = keepSettingUp && fromAddress != null;
      if (keepSettingUp) {
        try {
          fromAddress.setPersonal(fromName);
        } catch (UnsupportedEncodingException e) {
          log.severe(CraftMailUtil.prependName("Invalid from name specified in config.yml!"));
          if (errorMessage == null) errorMessage = "Invalid from name specified in config.yml!";
        }
        final InternetAddress fromAddressFinal = fromAddress;
        final String host = config.getString("mail.smtp.host");
        final String port = config.getString("mail.smtp.port");
        final String username = config.getString("mail.smtp.auth.username");
        final String password = config.getString("mail.smtp.auth.password");
        final String authType = config.getString("mail.smtp.auth.type");
        final CraftMail plugin = this;
        getServer()
            .getScheduler()
            .scheduleAsyncDelayedTask(
                this,
                new Runnable() {
                  @Override
                  public void run() {
                    EmailSender.initialise(
                        fromAddressFinal, host, port, username, password, authType);
                    plugin.startSendAsyncTask();
                  }
                });
      }
    }
    if (keepSettingUp) {
      String hostname = config.getString("sql.hostname");
      int port = config.getInt("sql.port");
      String database = config.getString("sql.database");
      if (database == null) database = String.valueOf(config.getInt("sql.database"));
      String url = "jdbc:mysql://" + hostname + ":" + port + "/" + database;

      String username = config.getString("sql.username");
      if (username == null) username = String.valueOf(config.getInt("sql.username"));
      String password = config.getString("sql.password");
      if (password == null) password = String.valueOf(config.getInt("sql.password"));

      if (!DatabaseManager.init(this, url, username, password)) {
        keepSettingUp = false;
        log.severe(CraftMailUtil.prependName("Failed to set up database!"));
        if (errorMessage == null)
          errorMessage = "Failed to set up database! Please check console for details.";
      }
    }
    getCommand("mail").setExecutor(new CraftMailCommandExecutor(this));
    playerListener = new CraftMailPlayerListener(this);
    getServer().getPluginManager().registerEvents(playerListener, this);
    log.info(pdfFile.getFullName() + " is enabled!");
  }
Example #3
0
 private void getInfo() {
   info = getDescription();
   logPrefix = "[" + info.getFullName() + "] ";
 }
Example #4
0
 @Override
 public void onDisable() {
   this.stopSendAsyncTask();
   log.info(pdfFile.getFullName() + " is disabled!");
 }