Example #1
0
  @Override
  public void onEnable() {
    this.getLogger().info(TextFormat.DARK_GREEN + "I've been enabled!");

    this.getLogger().info(String.valueOf(this.getDataFolder().mkdirs()));

    // Register the EventListener
    this.getServer().getPluginManager().registerEvents(new EventListener(this), this);

    // PluginTask
    this.getServer().getScheduler().scheduleRepeatingTask(new BroadcastPluginTask(this), 200);

    // Save resources
    this.saveResource("string.txt");

    // Config reading and writing
    Config config =
        new Config(
            new File(this.getDataFolder(), "config.yml"),
            Config.YAML,
            // Default values (not necessary)
            new LinkedHashMap<String, Object>() {
              {
                put("this-is-a-key", "Hello! Config!");
                put("another-key", true); // you can also put other standard objects!
              }
            });
    // Now try to get the value, the default value will be given if the key isn't exist!
    this.getLogger().info(String.valueOf(config.get("this-is-a-key", "this-is-default-value")));
    // Don't forget to save it!
    config.save();
  }
Example #2
0
 private static void saveMessages() {
   File f = new File(plugin.getDataFolder() + File.separator + language + ".lng");
   Config lng = new Config(f, Config.YAML);
   for (Message key : Message.values()) lng.set(key.name().toLowerCase(), key.message);
   try {
     lng.save();
   } catch (Exception e) {
     LNG_SAVE_FAIL.log();
     if (debugMode) e.printStackTrace();
     return;
   }
 }
Example #3
0
 private static void initMessages() {
   copyLanguage();
   Config lng = null;
   try {
     File f = new File(plugin.getDataFolder() + File.separator + language + ".lng");
     lng = new Config(f, Config.YAML);
   } catch (Exception e) {
     LNG_LOAD_FAIL.log();
     if (debugMode) e.printStackTrace();
     return;
   }
   for (Message key : Message.values())
     key.initMessage((String) lng.get(key.name().toLowerCase(), key.message));
 }