Esempio n. 1
0
  public void readLangFile(String language) {
    String filename = getLangFolder() + File.separator + language + ".yml";

    try {
      Configuration config = new Configuration(new File(filename));

      config.load();

      List<String> keys = config.getKeys();

      if (!langDb.containsKey(language)) {
        langDb.put(language, new HashMap<String, String>());
      }

      Map<String, String> langMap = langDb.get(language);

      for (Iterator<String> it = keys.iterator(); it.hasNext(); ) {
        String key = it.next();

        Log.v("Adding " + language + "." + key + ";");
        langMap.put(key, config.getString(key));
      }

      Log.d("Done parsing localization file '" + filename + "' for language '" + language + "'");
    } catch (Exception ex) {
      Log.e("Could not load localizaion file '" + filename + "'");
    }
  }
Esempio n. 2
0
 /* Load templates from template folder */
 private void loadTemplates() {
   File templatedir = new File(dataDirectory, "templates");
   templatedir.mkdirs();
   /* First, prime the templates directory with default standard templates, if needed */
   for (String stdtemplate : stdtemplates) {
     File f = new File(templatedir, stdtemplate);
     createDefaultFileFromResource("/templates/" + stdtemplate, f);
   }
   /* Now process files */
   String[] templates = templatedir.list();
   /* Go through list - process all ones not starting with 'custom' first */
   for (String tname : templates) {
     /* If matches naming convention */
     if (tname.endsWith(".txt") && (!tname.startsWith(CUSTOM_PREFIX))) {
       File tf = new File(templatedir, tname);
       org.bukkit.util.config.Configuration cfg = new org.bukkit.util.config.Configuration(tf);
       cfg.load();
       ConfigurationNode cn = new ConfigurationNode(cfg);
       /* Supplement existing values (don't replace), since configuration.txt is more custom than these */
       mergeConfigurationBranch(cn, "templates", false, false);
     }
   }
   /* Go through list again - this time do custom- ones */
   for (String tname : templates) {
     /* If matches naming convention */
     if (tname.endsWith(".txt") && tname.startsWith(CUSTOM_PREFIX)) {
       File tf = new File(templatedir, tname);
       org.bukkit.util.config.Configuration cfg = new org.bukkit.util.config.Configuration(tf);
       cfg.load();
       ConfigurationNode cn = new ConfigurationNode(cfg);
       /* This are overrides - replace even configuration.txt content */
       mergeConfigurationBranch(cn, "templates", true, false);
     }
   }
 }
Esempio n. 3
0
 public Board(
     String name,
     World world,
     Location pos1,
     Location pos2,
     boolean imported,
     Games plugin,
     Configuration conf) {
   this.data = null;
   this.field = null;
   this.conf = conf;
   this.plugin = plugin;
   pre = String.format("boards.%s.%s.", world.getName(), name);
   if (imported) {
     this.x = conf.getInt(pre + "x", 0);
     this.z = conf.getInt(pre + "z", 0);
     this.y = conf.getInt(pre + "y", -1);
     startBlock =
         world.getBlockAt(
             conf.getInt(pre + "sx", -1),
             conf.getInt(pre + "sy", -1),
             conf.getInt(pre + "sz", -1));
   } else {
     move(pos1, pos2);
   }
   this.name = name;
 }
Esempio n. 4
0
  /**
   * Sets the option located at the given path for player to val.
   *
   * @param player The player whose option is being changed.
   * @param path The path of the option to change.
   * @param val The new value of the option.
   * @return A Boolean representation of the success of the operation.
   */
  public Boolean setPlayerConfig(String player, String path, String val) {
    players.setProperty("players." + player + "." + path, val);
    players.save();
    players.load();

    return (players.getString("players." + player + "." + path) == val);
  }
Esempio n. 5
0
  /**
   * Deletes the given zone.
   *
   * @param zone The zone to delete.
   * @return A Boolean value representative of the success of the operation.
   */
  public Boolean deleteZone(String zone) {
    zones.removeProperty("zones." + zone);
    zones.save();
    zones.load();

    return (!zoneExists(zone));
  }
Esempio n. 6
0
 /** Reloads all {@link Configuration} files used by DayJobs. */
 public void reloadConfigs() {
   config.load();
   zones.load();
   players.load();
   tickets.load();
   spawns.load();
 }
Esempio n. 7
0
  /**
   * Gets the set damage for the given damage type, as defined in config.yml.
   *
   * @param player The player to check damage for.
   * @param dCause The cause of the incurred damage.
   * @param defaultDamage The default value to return if no option is set for the given damage type.
   * @return The damage to deal to the player.
   */
  public int getDamage(String player, DamageCause dCause, int defaultDamage) {
    String job = getJob(player);
    List<String> damages = config.getKeys("config.all.damages");
    int damage = defaultDamage;

    if (damages != null) {
      for (String item : damages) {
        if (item.equalsIgnoreCase(dCause.name())) {
          damage = config.getInt("config.all.damages." + item, defaultDamage);
          break;
        }
      }
    }

    damages = config.getKeys("config.jobs." + job + ".damages");

    if (damages != null) {
      for (String item : damages) {
        if (item.equalsIgnoreCase(dCause.name())) {
          damage = config.getInt("config.jobs." + job + ".damages." + item, defaultDamage);
          break;
        }
      }
    }

    return damage;
  }
Esempio n. 8
0
  /**
   * Attempts to delete the ticket opened by player.
   *
   * @param player The player whose ticket is being closed.
   * @return A Boolean representation of the operation's success.
   */
  public Boolean closeTicket(String player) {
    tickets.removeProperty("tickets." + player);
    tickets.save();
    tickets.load();

    return (!ticketExists(player));
  }
Esempio n. 9
0
  private static void setupconf() {
    File f = new File(plugin.getDataFolder(), "config.yml");
    conf = null;

    if (f.exists()) {
      conf = new Configuration(f);
      conf.load();
    } else {
      File confFile;
      confFile = new File(plugin.getDataFolder(), "config.yml");
      conf = new Configuration(confFile);
      conf.setProperty("APIkey", "Add your API-Key here");
      conf.setProperty("servername", "Add your servername here");
      conf.setProperty("owner", "Add your name here");

      // options
      conf.setProperty("options.banborder", "-40");
      conf.setProperty("options.debugmode", false);

      // features
      conf.setProperty("features.usewhitelist", false);
      conf.setProperty("features.useglobalbans", true);
      conf.setProperty("features.usebansystem", true);
      conf.setProperty("features.useprofiles", true);
      conf.setProperty("features.usecomments", true);
      conf.setProperty("features.useratings", true);
      conf.save();
    }
  }
Esempio n. 10
0
  /**
   * Checks to see if item ever equals the given jobs permits, or if the permit contains ALL or
   * NOTHING.
   *
   * @param item The item to check a match for.
   * @param job The job whose permits are being checked.
   * @param type The type of permit to check.
   * @return A Boolean value representative of the presence of a match.
   */
  public Boolean checkMatch(String item, String player, String type) {
    String job = getJob(player);
    Boolean matched = false;
    List<String> values = config.getStringList("config.all." + type, null);

    if (values != null) {
      for (String val : values) {
        if (val.equalsIgnoreCase("NOTHING")) {
          break;
        } else if (val.equalsIgnoreCase(item) || val.equalsIgnoreCase("ALL")) {
          matched = true;
          break;
        }
      }
    }

    values = config.getStringList("config.jobs." + job + "." + type, null);

    if (values != null) {
      for (String val : values) {
        if (val.equalsIgnoreCase("NOTHING")) {
          matched = false;
          break;
        } else if (val.equalsIgnoreCase(item) || val.equalsIgnoreCase("ALL")) {
          matched = true;
          break;
        }
      }
    }

    return matched;
  }
Esempio n. 11
0
  public static void updateMinecraftYMLCache() {
    if (!updated || !getConfigFile().exists()) {
      synchronized (key) {
        String current = null;
        if (getConfigFile().exists()) {
          try {
            current = getConfig().getString("current");
          } catch (Exception ex) {
            ex.printStackTrace();
          }
        }

        if (YmlUtils.downloadYmlFile(
            MINECRAFT_YML, "http://quebecgmz.ca/mods/minecraft.yml", getConfigFile())) {
          // GameUpdater.copy(getConfigFile(), output)
          config = null;
          Configuration config = getConfig();
          latest = config.getString("latest");
          recommended = config.getString("recommended");
          if (current != null) {
            config.setProperty("current", current);
            config.save();
          }
        }
        updated = true;
      }
    }
  }
Esempio n. 12
0
  /**
   * Sets the option located at the given path to val.
   *
   * @param path The path of the option to be changed.
   * @param val The new value of the option.
   * @return A Boolean representation of the success of the operation.
   */
  public Boolean setConfig(String path, String val) {
    config.setProperty("config." + path, val);
    config.save();
    config.load();

    return (config.getString("config." + path) == val);
  }
Esempio n. 13
0
  /**
   * Attempts to create a new player in players.yml.
   *
   * @param player The new player to add to players.yml.
   * @return Whether or not the player exists after the operation has run.
   */
  public Boolean createPlayer(String player) {
    players.setProperty("players." + player + ".job", config.getString("config.default-job"));
    players.setProperty("players." + player + ".exempt", false);
    players.save();
    players.load();

    return (playerExists(player));
  }
Esempio n. 14
0
  /**
   * Attempts to create a new ticket for the given player.
   *
   * @param player The player requesting the job change ticket.
   * @param job The job that player is requesting a change to.
   * @param time The timestamp of the change request.
   * @return A Boolean representation of the operation's success.
   */
  public Boolean createTicket(String player, String job, String time) {
    tickets.setProperty("tickets." + player + ".job", job);
    tickets.setProperty("tickets." + player + ".time", time);
    tickets.save();
    tickets.load();

    return ticketExists(player);
  }
Esempio n. 15
0
  /**
   * Gets the ticket currently opened by the given player.
   *
   * @param player The player whose ticket is being retrieved.
   * @return An array containing the ticket info for the given player.<br>
   *     The first element is the player's desired job, the second is the timestamp of the request.
   */
  public String[] getTicket(String player) {
    String[] ticket = {
      tickets.getString("tickets." + player + ".job"),
      tickets.getString("tickets." + player + ".time")
    };

    return ticket;
  }
Esempio n. 16
0
 public InstanceConfig(int id, String name, Configuration config) {
   config.load();
   this.instanceName = name;
   this.world = config.getString("instances." + this.instanceName + ".world", null);
   this.maxPlayers = config.getInt("instances." + this.instanceName + ".players", 0);
   this.timer = config.getInt("instances." + this.instanceName + ".timer", 0);
   this.exp = config.getInt("instances." + this.instanceName + ".exp", 0);
 }
Esempio n. 17
0
 public static void compRatio(int amount, Configuration config) {
   BigDecimal base = BigDecimal.valueOf(100000);
   BigDecimal div = BigDecimal.valueOf(amount);
   double ratio = div.divide(base, 2, RoundingMode.HALF_UP).doubleValue();
   config.load();
   config.setProperty("r", ratio);
   config.save();
 }
Esempio n. 18
0
  /**
   * Toggles exempt status on the given player.
   *
   * @param player The player to toggle exempt on.
   * @return A Boolean representation of the method's success.
   */
  public Boolean toggleExempt(String player) {
    Boolean exempt = players.getBoolean("players." + player + ".exempt", true);

    players.setProperty("players." + player + ".exempt", !exempt);
    players.save();
    players.load();

    return (!exempt == players.getBoolean("players." + player + ".exempt", false));
  }
Esempio n. 19
0
  /**
   * Gets the coordinate set of the given zone.
   *
   * @param zone The zone to retrieve coordinates for.
   * @param type The type of coordinate set to retrieve.
   * @return The coordinate set of the requested zone, of the requested type.
   */
  public int[] getZoneCoords(String zone, String type) {
    int[] coords = {
      zones.getInt("zones." + zone + ".coords." + type + ".x", 0),
      zones.getInt("zones." + zone + ".coords." + type + ".y", 0),
      zones.getInt("zones." + zone + ".coords." + type + ".z", 0)
    };

    return coords;
  }
Esempio n. 20
0
  private void load() {
    for (String key : keys) {
      if (config.getProperty(key) == null) config.setProperty(key, defaults.get(key));
      strings.put(key, config.getString(key).replace("&", "\u00a7"));
    }

    // clear defaults to free memory
    defaults.clear();
  }
Esempio n. 21
0
 public void save() {
   conf.setProperty(pre + "x", x);
   conf.setProperty(pre + "z", z);
   conf.setProperty(pre + "y", y);
   conf.setProperty(pre + "sx", startBlock.getX());
   conf.setProperty(pre + "sy", startBlock.getY());
   conf.setProperty(pre + "sz", startBlock.getZ());
   conf.save();
 }
Esempio n. 22
0
  private void updateTo4(Configuration config) {
    config.setProperty("Config.modes.cluster.enabled", Boolean.valueOf(true));
    config.setProperty("Config.modes.cluster.size", Integer.valueOf(20));

    setVersion(4);
    config.save();
    LightPoles.log("# updated config.yml to VERSION 4", new Object[0]);
    LightPoles.log("# added new mode: CLUSTER", new Object[0]);
  }
Esempio n. 23
0
  private void updateTo8(Configuration config) {
    LightPoles.log("# updated config.yml to VERSION 8", new Object[0]);

    LightPoles.log("# added removeTorchAfterConstruction: false", new Object[0]);
    config.setProperty("Config.modes.power.removeTorchAfterConstruction", Boolean.valueOf(true));

    setVersion(8);
    config.save();
  }
Esempio n. 24
0
  private Configuration load() {
    try {
      Configuration configx = new Configuration(file);
      configx.load();
      return configx;

    } catch (Exception e) {
      e.printStackTrace();
    }
    return null;
  }
Esempio n. 25
0
  public Configuration load() {
    try {
      Configuration config = new Configuration(configFile);
      config.load();
      return config;

    } catch (Exception e) {
      e.printStackTrace();
    }
    return null;
  }
Esempio n. 26
0
  public MVPortal(String name, Configuration config, MultiVerse instance) {
    this.plugin = instance;
    this.utils = new MVUtils(plugin);
    this.config = config;

    this.name = name;
    this.owner = config.getString("portals." + name + ".owner", "");
    this.price = config.getDouble("portals." + name + ".price", 0.0);
    setupLocation();
    setDestLocation(this.config.getString("portals." + name + ".destlocation", ""));
  }
Esempio n. 27
0
 public void loadPreferences(String name) {
   File pref = new File(root + File.separator + name + ".pref");
   Configuration c = new Configuration(pref);
   c.load();
   armourType.put(name.toString(), getArmour(c.getString("Preferences.ArmourType", "NONE")));
   blockHead.put(
       name.toString(),
       new ItemStack((Material.getMaterial(c.getString("Preferences.BlockOnHead", "AIR"))), 1));
   swordType.put(
       name.toString(),
       Material.getMaterial(c.getString("Preferences.Sword", Material.WOOD_SWORD.toString())));
 }
Esempio n. 28
0
 private void updateKeys() {
   String fromKey, toKey, holder;
   for (String[] update : keyUpdates) {
     fromKey = update[0];
     if (config.getProperty(fromKey) != null) {
       toKey = update[1];
       holder = config.getString(fromKey);
       config.removeProperty(fromKey);
       if (!toKey.equals("")) config.setProperty(toKey, holder);
     }
   }
 }
  private Configuration load(File readFile) {

    try {
      Configuration config = new Configuration(readFile);
      config.load();
      return config;

    } catch (Exception e) {
      e.printStackTrace();
    }
    return null;
  }
Esempio n. 30
0
  /**
   * Changes the current job of the given 'player'
   *
   * @param player The player whose job is being changed.
   * @param job The job that 'player' is being changed to.
   * @return A Boolean representation of the success of the operation.
   */
  public Boolean changeJob(String player, String job) {
    if (playerExists(player) && jobExists(job)) {
      players.setProperty("players." + player + ".job", job);

      players.save();
      players.load();

      return (getJob(player).equalsIgnoreCase(job));
    } else {
      return false;
    }
  }