コード例 #1
0
  @Override
  public void onEnable() {
    instance =
        this; // setting the instance so we can use it in any other class without needing to pass
              // the variable through countless methods
    getCommand("animalessentials")
        .setExecutor(
            new AECommands()); // registers the command executor to the command "animalessentials"
    getCommand("aetp")
        .setExecutor(new AECommands()); // registers the command executor to the command "aetp"
    Utilities.registerEvents(
        instance,
        new Teleport(),
        new Name(),
        new Kill(),
        new Heal(),
        new Owner(),
        new Tame(),
        new Spawn(),
        new Clone(),
        new EntityDamageByEntityListener(instance));
    Config.createConfig(instance); // setting up the config
    aetpString = Utilities.getRandomString(10);

    if (getConfig().getBoolean("update.check")) checkForUpdate();
    else
      Utilities.sendConsoleMessage(
          "AnimalEssentials successfully enabled."); // sending this message to the console
  }
コード例 #2
0
  /** Checks for a plugin update, if enabled in config */
  public void checkForUpdate() {
    try {
      BufferedReader reader =
          new BufferedReader(
              new InputStreamReader(
                  new URL(
                          "https://raw.githubusercontent.com/JustRamon/AnimalEssentials/master/version.txt")
                      .openStream()));
      String version = reader.readLine();
      int major = Integer.parseInt(version.split("\\.")[0]);
      int minor = Integer.parseInt(version.split("\\.")[1]);
      int bugfix = Integer.parseInt(version.split("\\.")[2]);
      int curMajor = Integer.parseInt(getDescription().getVersion().split("\\.")[0]);
      int curMinor = Integer.parseInt(getDescription().getVersion().split("\\.")[1]);
      int curBugfix = Integer.parseInt(getDescription().getVersion().split("\\.")[2]);

      if (bugfix > curBugfix || minor > curMinor || major > curMajor) {
        if (getConfig().getBoolean("update.force")) {
          Utilities.sendConsoleMessage(
              ChatColor.RED
                  + "There is a new version ("
                  + major
                  + "."
                  + minor
                  + "."
                  + bugfix
                  + ") available here: http://dev.bukkit.org/bukkit-plugins/animalessentials/");
          Utilities.sendConsoleMessage(
              ChatColor.RED + "It is highly suggested to update to this version!");
          Utilities.sendConsoleMessage(
              ChatColor.RED + "You can't use the plugin until you update it.");
          getServer().getPluginManager().disablePlugin(this);
          return;
        } else {
          Utilities.sendConsoleMessage(
              ChatColor.RED
                  + "There is a new version ("
                  + major
                  + "."
                  + minor
                  + "."
                  + bugfix
                  + ") available here: http://dev.bukkit.org/bukkit-plugins/animalessentials/");
          Utilities.sendConsoleMessage(
              ChatColor.RED + "It is highly suggested to update to this version!");
        }
      } else Utilities.sendConsoleMessage(ChatColor.RED + "No update has been found.");

      reader.close();
    } catch (Exception e) {
      Utilities.sendConsoleMessage(
          ChatColor.RED + "Could not find update file. Are you connected to the internet?");
    }

    Utilities.sendConsoleMessage(
        "AnimalEssentials successfully enabled."); // sending this message to the console
  }
コード例 #3
0
 @Override
 public void onDisable() {
   Utilities.sendConsoleMessage(
       "AnimalEssentials successfully disabled."); // sending this message to the console
 }