コード例 #1
0
  private void loadDatabase() {
    if (!this.getBooleanConfig("statistics.enabled", false)
        || !this.getStringConfig("statistics.storage", "yaml").equals("database")) {
      return;
    }

    this.getServer()
        .getConsoleSender()
        .sendMessage(ChatWriter.pluginMessage(ChatColor.GREEN + "Initialize database ..."));
    this.loadingRequiredLibs();

    String host = this.getStringConfig("database.host", null);
    int port = this.getIntConfig("database.port", 3306);
    String user = this.getStringConfig("database.user", null);
    String password = this.getStringConfig("database.password", null);
    String db = this.getStringConfig("database.db", null);

    if (host == null || user == null || password == null || db == null) {
      return;
    }

    this.dbManager = new DatabaseManager(host, port, user, password, db);
    this.dbManager.initialize();

    this.getServer()
        .getConsoleSender()
        .sendMessage(ChatWriter.pluginMessage(ChatColor.GREEN + "Update database ..."));
    (new DatabaseUpdater()).execute();

    this.getServer()
        .getConsoleSender()
        .sendMessage(ChatWriter.pluginMessage(ChatColor.GREEN + "Done."));
  }
コード例 #2
0
 public Package getMinecraftPackage() {
   try {
     if (this.minecraft == null) {
       return Package.getPackage(
           "net.minecraft.server."
               + Bukkit.getServer()
                   .getClass()
                   .getPackage()
                   .getName()
                   .replace(".", ",")
                   .split(",")[3]);
     } else {
       return this.minecraft;
     }
   } catch (Exception ex) {
     this.getServer()
         .getConsoleSender()
         .sendMessage(
             ChatWriter.pluginMessage(
                 ChatColor.RED
                     + Main._l(
                         "errors.packagenotfound",
                         ImmutableMap.of("package", "minecraft server"))));
     return null;
   }
 }
コード例 #3
0
  private void checkUpdates() {
    try {
      if (this.getBooleanConfig("check-updates", true)) {
        new PluginUpdater(
            this,
            Main.PROJECT_ID,
            this.getFile(),
            PluginUpdater.UpdateType.DEFAULT,
            this.getBooleanConfig("update-infos", true));
        this.updateChecker =
            new BukkitRunnable() {

              @Override
              public void run() {
                new PluginUpdater(
                    Main.getInstance(),
                    Main.PROJECT_ID,
                    Main.getInstance().getFile(),
                    PluginUpdater.UpdateType.DEFAULT,
                    Main.getInstance().getBooleanConfig("update-infos", true));
              }
            }.runTaskTimer(Main.getInstance(), 36000L, 36000L);
      }
    } catch (Exception ex) {
      this.getServer()
          .getConsoleSender()
          .sendMessage(
              ChatWriter.pluginMessage(ChatColor.RED + "Check for updates not successful: Error!"));
    }
  }
コード例 #4
0
  public void loadShop() {
    File file = new File(Main.getInstance().getDataFolder(), "shop.yml");
    if (!file.exists()) {
      // create default file
      this.saveResource("shop.yml", false);

      // wait until it's really saved
      try {
        Thread.sleep(100);
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
    }

    this.shopConfig = new YamlConfiguration();

    try {
      BufferedReader reader =
          new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
      this.shopConfig.load(reader);
    } catch (Exception e) {
      this.getServer()
          .getConsoleSender()
          .sendMessage(
              ChatWriter.pluginMessage(
                  ChatColor.RED + "Couldn't load shop! Error in parsing shop!"));
      e.printStackTrace();
    }
  }
コード例 #5
0
 public void startMetricsIfEnabled() {
   if (this.metricsEnabled()) {
     try {
       Metrics metrics = new Metrics(this);
       metrics.start();
     } catch (Exception ex) {
       this.getServer()
           .getConsoleSender()
           .sendMessage(
               ChatWriter.pluginMessage(
                   ChatColor.RED + "Metrics are enabled, but couldn't send data!"));
     }
   }
 }
コード例 #6
0
  @SuppressWarnings("rawtypes")
  public Class getMinecraftServerClass(String classname) {
    try {
      if (this.minecraft == null) {
        this.minecraft = this.getMinecraftPackage();
      }

      return Class.forName(this.minecraft.getName() + "." + classname);
    } catch (Exception ex) {
      this.getServer()
          .getConsoleSender()
          .sendMessage(
              ChatWriter.pluginMessage(
                  ChatColor.RED
                      + Main._l(
                          "errors.classnotfound",
                          ImmutableMap.of("package", "minecraft server", "class", classname))));
      return null;
    }
  }
コード例 #7
0
  public Class<?> getVersionRelatedClass(String className) {
    try {
      Class<?> clazz =
          Class.forName(
              "io.github.yannici.bedwars.Com." + this.getCurrentVersion() + "." + className);
      return clazz;
    } catch (Exception ex) {
      this.getServer()
          .getConsoleSender()
          .sendMessage(
              ChatWriter.pluginMessage(
                  ChatColor.RED
                      + "Couldn't find version related class io.github.yannici.bedwars.Com."
                      + this.getCurrentVersion()
                      + "."
                      + className));
    }

    return null;
  }