Examples of YamlConfiguration


Examples of org.bukkit.configuration.file.YamlConfiguration

        ItemStack[] items = this.items.remove(p);
        ItemStack[] armor = this.armor.remove(p);
       
        // If we can't restore from memory, restore from file
        if (items == null || armor == null) {
            YamlConfiguration config = new YamlConfiguration();
            config.load(file);
           
            // Get the items and armor lists
            List<?> itemsList = config.getList("items");
            List<?> armorList = config.getList("armor");
           
            // Turn the lists into arrays
            items = itemsList.toArray(new ItemStack[itemsList.size()]);
            armor = armorList.toArray(new ItemStack[armorList.size()]);
        }
View Full Code Here

Examples of org.bukkit.configuration.file.YamlConfiguration

    public static boolean restoreFromFile(MobArena plugin, Player p) {
        try {
            // Grab the file and load the config
            File dir = new File(plugin.getDataFolder(), "inventories");
            File file = new File(dir, p.getName());
            YamlConfiguration config = new YamlConfiguration();
            config.load(file);
           
            // Get the items and armor lists
            List<?> itemsList = config.getList("items");
            List<?> armorList = config.getList("armor");
           
            // Turn the lists into arrays
            ItemStack[] items = itemsList.toArray(new ItemStack[itemsList.size()]);
            ItemStack[] armor = armorList.toArray(new ItemStack[armorList.size()]);
           
View Full Code Here

Examples of org.bukkit.configuration.file.YamlConfiguration

    public static Random random = new Random();

    public void onEnable() {
        // Initialize config-file
        configFile = new File(getDataFolder(), "config.yml");
        config = new YamlConfiguration();
        reloadConfig();

        // Set the header and save
        getConfig().options().header(getHeader());
        saveConfig();
View Full Code Here

Examples of org.bukkit.configuration.file.YamlConfiguration

        // Create if missing
        File file = new File(getDataFolder(), "announcements.yml");
        try {
            if (file.createNewFile()) {
                Messenger.info("announcements.yml created.");
                YamlConfiguration yaml = Msg.toYaml();
                yaml.save(file);
                return;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        // Otherwise, load the announcements from the file
        try {
            YamlConfiguration yaml = new YamlConfiguration();
            yaml.load(file);
            ConfigUtils.addMissingRemoveObsolete(file, Msg.toYaml(), yaml);
            Msg.load(yaml);
        } catch (Exception e) {
            e.printStackTrace();
        }
View Full Code Here

Examples of org.bukkit.configuration.file.YamlConfiguration

  /**
   * Clears and then populates the plugin's tier list
   */
  public void build() {
    plugin.tiers.clear();
    FileConfiguration cs = new YamlConfiguration();
    File f = new File(plugin.getDataFolder(), "tier.yml");
    if (f.exists())
      try {
        cs.load(f);
      } catch (Exception e) {
        if (plugin.getDebug())
          plugin.log.warning(e.getMessage());
      }
    for (String name : cs.getKeys(false)) {
      int amt = cs.getInt(name + ".Enchantments.Amt");
      int lvl = cs.getInt(name + ".Enchantments.Levels");
      double chance = cs.getDouble(name + ".Chance");
      String color = cs.getString(name + ".Color");
      List<Material> l = new ArrayList<Material>();
      for (String s : cs.getStringList(name + ".Materials")) {
        Material mat = Material.getMaterial(s.toUpperCase());
        if (mat != null)
          l.add(mat);
      }
      for (String s : cs.getStringList(name + ".Material")) {
        Material mat = Material.getMaterial(s.toUpperCase());
        if (mat != null)
          l.add(mat);
      }
      List<String> lore = new ArrayList<String>();
      for (String s : cs.getStringList(name + ".Lore"))
        if (s != null)
          lore.add(ChatColor.translateAlternateColorCodes('&', s));
      plugin.tiers.add(new Tier(name, ChatColor.valueOf(color
          .toUpperCase()), Math.abs(amt), Math.abs(lvl), Math
          .abs((int) (chance * 100)), l, lore, cs.getString(name
          + ".DisplayName", name), ((float) cs.getDouble(name
          + ".DropChance", 100)) / 100));
    }
  }
View Full Code Here

Examples of org.bukkit.configuration.file.YamlConfiguration

  /**
   * Clears and then populates the plugin's custom items list
   */
  public void build() {
    FileConfiguration fc = new YamlConfiguration();
    File f = new File(plugin.getDataFolder(), "custom.yml");
    if (f.exists()) {
      try {
        fc.load(f);
      } catch (Exception e) {
        if (plugin.getDebug())
          plugin.log.warning(e.getMessage());
      }
    }
    for (String name : fc.getKeys(false)) {
      ConfigurationSection cs = fc.getConfigurationSection(name);
      Material mat = Material.matchMaterial(cs.getString("Material"));
      ChatColor color = ChatColor.valueOf(cs.getString("Color")
          .toUpperCase());
      List<String> lore = cs.getStringList("Lore");
      ItemStack tool = new ItemStack(mat);
View Full Code Here

Examples of org.bukkit.configuration.file.YamlConfiguration

  /**
   * Clears and then populates the plugin's ArmorSet list
   */
  public void build() {
    plugin.armorSets.clear();
    FileConfiguration cs = new YamlConfiguration();
    File f = new File(plugin.getDataFolder(), "set.yml");
    if (f.exists()) {
      try {
        cs.load(f);
      } catch (Exception e) {
        if (plugin.getDebug())
          plugin.log.warning(e.getMessage());
      }
    }
    for (String name : cs.getKeys(false)) {
      List<String> bonuses = cs.getStringList(name + ".Bonuses");
      if (bonuses == null)
        bonuses = new ArrayList<String>();
      plugin.armorSets.add(new ArmorSet(name, bonuses));
    }
  }
View Full Code Here

Examples of org.bukkit.configuration.file.YamlConfiguration

        }
    }

    private static void process(Plugin plugin, String resource, ConfigurationSection section, boolean addOnlyIfEmpty, boolean removeObsolete) {
        try {
            YamlConfiguration defaults = new YamlConfiguration();
            defaults.load(plugin.getResource("res/" + resource));

            process(defaults, section, addOnlyIfEmpty, removeObsolete);
            plugin.saveConfig();
        } catch (Exception e) {
            e.printStackTrace();
View Full Code Here

Examples of org.bukkit.configuration.file.YamlConfiguration

          .addCode(exStackTrace, null);
    }


    // PEX Configuration
    YamlConfiguration pexConfig = new YamlConfiguration();
    boolean successfulLoad = false;
    final File mainConfigFile = pexPlugin != null ? new File(pexPlugin.getDataFolder(), "config.yml") : null;
    String configuration;
    String permissionsDb = "Permissions configuration could not be read. Does it exist?";
    String activeBackend = "unknown";

    if (mainConfigFile == null) {
      configuration = "PEX plugin was inaccessible!";
    } else if (mainConfigFile.exists()) {
      try {
        pexConfig.load(mainConfigFile);
        successfulLoad = true;
      } catch (IOException | InvalidConfigurationException ignore) {
      }

      try {
        configuration = StringUtils.readStream(new FileInputStream(mainConfigFile));
      } catch (IOException e1) {
        configuration = "Unable to read configuration file at: " + mainConfigFile.getAbsolutePath();
      }
    } else {
      configuration = "PEX configuration does not exist!";
    }
    configuration = configuration.replaceAll("password: (.*)", "password: XXXXXXXXXX"); // Attempt to remove any passwords from the file (SQL)
    builder.addHeading("PEX configuration")
        .addCode(configuration, "yaml");

    // Permissions database
    if (pexPlugin != null) {
      PermissionManager manager = pexPlugin.getPermissionsManager();
      if (manager != null) {
        PermissionBackend backend = manager.getBackend();
        try {
          if (backend != null) {
            final StringWriter writer = new StringWriter();
            backend.writeContents(writer);
            permissionsDb = writer.toString();
            activeBackend = backend.toString();
          }
        } catch (Throwable t) {
          // Continue
        }
      }
      if (permissionsDb == null && pexConfig.getString("permissions.backends." + pexConfig.getString("permissions.backend", "file") + ".type", "file").equalsIgnoreCase("file")) {
        File file = new File(pexPlugin.getDataFolder(), pexConfig.getString("permissions.backends.file.file", "permissions.yml"));
        if (file.exists()) {
          try {
            permissionsDb = StringUtils.readStream(new FileInputStream(file));
            activeBackend = "file";
          } catch (IOException ignore) {
View Full Code Here

Examples of org.bukkit.configuration.file.YamlConfiguration

    compound.put("values", new int[] { 1, 2, 3});
    compound.put(NbtFactory.ofList("telephone", "12345678", "81549300"));
   
    compound.put(NbtFactory.ofList("lists", NbtFactory.ofList("", "a", "a", "b", "c")));
   
    YamlConfiguration yaml = new YamlConfiguration();
    NbtConfigurationSerializer.DEFAULT.serialize(compound, yaml);
   
    NbtCompound result = NbtConfigurationSerializer.DEFAULT.deserializeCompound(yaml, "hello");
   
    assertEquals(compound, result);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.