Example #1
0
 public void SaveConfig() {
   if (conf == null || file == null) {
     return;
   }
   try {
     conf.save(file); // Save the memory configurations to the config file
   } catch (IOException ex) {
     plugin
         .getLogger()
         .log(Level.SEVERE, "IOException: Error saving configuration file '" + fname + "'!");
     plugin.getLogger().log(Level.SEVERE, ex.toString());
   }
 }
 @Override
 public S loadEntry(final String key) {
   final String rawData = entries.get(key);
   if (rawData == null) return null;
   try {
     return loadEntryWithData(key, rawData.trim());
   } catch (final InvocationTargetException e) {
     plugin.getLogger().log(Level.SEVERE, "Error occured while trying to load entry: " + key);
     try {
       plugin.getLogger().log(Level.SEVERE, "Trying to fix entry...");
       final String backupData = backupEntries.remove(key);
       if (backupData == null)
         try {
           if (e.getCause() instanceof ArrayIndexOutOfBoundsException)
             return loadEntryWithRepairedData(key, rawData.trim());
         } catch (final Exception e1) {
         }
       else
         try {
           return loadEntryWithData(key, backupData);
         } catch (final InvocationTargetException e1) {
           try {
             if (e.getCause() instanceof ArrayIndexOutOfBoundsException)
               return loadEntryWithRepairedData(key, rawData.trim());
           } catch (final InvocationTargetException e2) {
             try {
               if (e.getCause() instanceof ArrayIndexOutOfBoundsException)
                 return loadEntryWithRepairedData(key, backupData);
             } catch (final Exception e3) {
             }
           } catch (final Exception e2) {
           }
         } catch (final Exception e1) {
         }
     } finally {
       if (datas.containsKey(key.toLowerCase())) {
         plugin.getLogger().log(Level.SEVERE, "Repair success.");
         save(key);
       } else plugin.getLogger().log(Level.SEVERE, "Repair failed.");
     }
     shortPrintStackTrace(e, e.getCause());
     return null;
   } catch (final Exception e) {
     System.err.println("Error occured while trying to load entry: " + key);
     e.printStackTrace();
     return null;
   }
 }
Example #3
0
  /**
   * Constructor for the ConsoleLogger.
   *
   * @param instance - The JavaPlugin instance that initiated this logmanager.
   * @param debug - If set to true, it will output debug info to the console.
   */
  public ConsoleLogger(JavaPlugin instance, String loggerName) {
    plugin = instance;
    this.logger = instance.getLogger();
    this.name = loggerName;

    ConsoleLogger.debug = plugin.getConfig().getBoolean("debug");

    ConsoleLogger.template = "v" + plugin.getDescription().getVersion() + ": ";
  }
Example #4
0
 public void saveConfig() {
   if (fileConfiguration != null || configFile != null) {
     try {
       getConfig().save(configFile);
     } catch (IOException ex) {
       plugin.getLogger().log(Level.SEVERE, "Could not save config to " + configFile, ex);
     }
   }
 }
  public SimpleYamlConfiguration(
      final JavaPlugin plugin,
      final String fileName,
      final LinkedHashMap<String, Object> configDefaults,
      final String name) {
    /*
     * accepts null as configDefaults -> check for resource and copies it if
     * found, makes an empty config if nothing is found
     */
    final String folderPath = plugin.getDataFolder().getAbsolutePath() + File.separator;
    file = new File(folderPath + fileName);

    if (file.exists() == false) {
      if (configDefaults == null) {
        if (plugin.getResource(fileName) != null) {
          plugin.saveResource(fileName, false);
          plugin.getLogger().info("New " + name + " file copied from jar");
          try {
            this.load(file);
          } catch (final Exception e) {
            e.printStackTrace();
          }
        }
      } else {
        for (final String key : configDefaults.keySet()) {
          this.set(key, configDefaults.get(key));
        }

        try {
          this.save(file);
          plugin.getLogger().info("New " + name + " file created");
        } catch (final IOException e) {
          e.printStackTrace();
        }
      }
    } else {
      try {
        this.load(file);
        plugin.getLogger().info(name + " file loaded");
      } catch (final Exception e) {
        e.printStackTrace();
      }
    }
  }
Example #6
0
  /** Run the updater. */
  @Override
  public void run() {

    Updater.UpdateType type;

    switch (updaterType.toLowerCase()) {
      case "download":
        type = Updater.UpdateType.DEFAULT;
        break;
      case "check":
        type = Updater.UpdateType.NO_DOWNLOAD;
        break;
      case "force":
        type = Updater.UpdateType.NO_VERSION_CHECK;
        break;
      default:
        type = Updater.UpdateType.DEFAULT;
    }

    Updater updater = new Updater(plugin, ID, file, type, true);

    Updater.UpdateResult result = updater.getResult();

    switch (result) {
      case SUCCESS:
        plugin
            .getLogger()
            .log(
                Level.INFO,
                "A new update has been downloaded. Please restart the server for the changes to take effect.");
        break;
      case NO_UPDATE:
        plugin.getLogger().log(Level.INFO, "No update was found.");
        break;
      case DISABLED:
        plugin.getLogger().log(Level.INFO, "Updater did not run, it is globally disabled.");
        break;
      case FAIL_DOWNLOAD:
        plugin.getLogger().log(Level.WARNING, "An update was found, but failed to download.");
        break;
      case FAIL_DBO:
        plugin
            .getLogger()
            .log(
                Level.WARNING,
                "Updater was unable to connect with dev.bukkit.org to look for updates.");
        break;
      case FAIL_NOVERSION:
        plugin
            .getLogger()
            .log(
                Level.WARNING,
                "Invalid version name on dev.bukkit.org - please contact the author.");
        break;
      case FAIL_BADID:
        plugin.getLogger().log(Level.WARNING, "The project ID was invalid or could not be found.");
        break;
      case FAIL_APIKEY:
        plugin.getLogger().log(Level.WARNING, "Invalid API key.");
        break;
      case UPDATE_AVAILABLE:
        plugin
            .getLogger()
            .log(
                Level.INFO,
                "A new update has been found. Please visit \""
                    + updater.getLatestFileLink()
                    + "\" to download it.");
        updateAvailable = true;
        break;
      default:
        plugin.getLogger().log(Level.WARNING, "An unexpected result was received from Updater.");
    }
  }