コード例 #1
0
 private boolean importIsland(uSkyBlock plugin, File file) {
   log.info("Importing " + file);
   FileConfiguration config = new YamlConfiguration();
   readConfig(config, file);
   if (config.contains("party.leader") && !config.contains("party.leader.name")) {
     String leaderName = config.getString("party.leader");
     ConfigurationSection leaderSection = config.createSection("party.leader");
     leaderSection.set("name", leaderName);
     leaderSection.set("uuid", UUIDUtil.asString(getUUID(leaderName)));
   }
   ConfigurationSection members = config.getConfigurationSection("party.members");
   if (members != null) {
     for (String member : members.getKeys(false)) {
       ConfigurationSection section = members.getConfigurationSection(member);
       if (!section.contains("name")) {
         members.set(member, null);
         String uuid = UUIDUtil.asString(getUUID(member));
         members.createSection(uuid, section.getValues(true));
         members.set(uuid + ".name", member);
       } else {
         log.info("Skipping " + member + ", already has a name");
       }
     }
   }
   try {
     config.save(file);
     return true;
   } catch (IOException e) {
     log.log(Level.SEVERE, "Failed to import " + file, e);
     return false;
   }
 }
コード例 #2
0
  @Override
  public void setDefaultGroup(PermissionGroup group, String worldName) {
    ConfigurationSection groups = this.permissions.getConfigurationSection("groups");

    String defaultGroupProperty = "default";
    if (worldName != null) {
      defaultGroupProperty = buildPath("worlds", worldName, defaultGroupProperty);
    }

    for (Map.Entry<String, Object> entry : groups.getValues(false).entrySet()) {
      if (entry.getValue() instanceof ConfigurationSection) {
        ConfigurationSection groupSection = (ConfigurationSection) entry.getValue();

        groupSection.set(defaultGroupProperty, false);

        if (!entry.getValue().equals(group.getName())) {
          groupSection.set(defaultGroupProperty, null);
        } else {
          groupSection.set(defaultGroupProperty, true);
        }
      }
    }

    this.save();
  }
コード例 #3
0
ファイル: KitManager.java プロジェクト: jcdesimp/CanvasKits
  /**
   * Recursive method to parse and create a new kit
   *
   * @param cfg configurationSection mapping representing a kit
   * @return the newly created kit
   */
  private Kit parseKit(ConfigurationSection cfg, String uName) {
    // System.out.println( cfg.toString() );
    Map<String, Object> vals = cfg.getValues(true);
    String displayName;
    ItemStack displayItem;
    List<String> desc = new ArrayList<String>();

    // check name
    if (vals.containsKey("name")) {
      displayName = (String) vals.get("name");
    } else {
      displayName = "Unnamed";
    }
    // System.out.println("KitName: " + displayName);

    // check display item
    if (vals.containsKey("item")) {
      displayItem = parseItem(cfg.getConfigurationSection("item"));
    } else {
      displayItem = new ItemStack(Material.STONE);
    }
    // System.out.println("KitItem: " + displayItem.toString());

    // check description
    if (vals.containsKey("description")) {
      desc = cfg.getStringList("description");
    }
    // System.out.println("Description: " + desc.toString());

    // is categrory
    if (vals.containsKey("kits")) {
      KitCategory k = new KitCategory(displayName, desc, displayItem, uName);
      for (String s : cfg.getConfigurationSection("kits").getKeys(false)) {
        k.addKit(parseKit(cfg.getConfigurationSection("kits." + s), uName + "." + s));
      }

      return k;
    } else { // is concrete kit

      ConcreteKit k = new ConcreteKit(displayName, desc, displayItem, uName);
      if (vals.containsKey("actions")) {
        for (String s : cfg.getConfigurationSection("actions").getKeys(false)) {
          k.addKitAction(parseAction(cfg.getConfigurationSection("actions." + s)));
        }
      }

      // set cooldown
      if (vals.containsKey("cooldown")) {
        // System.out.println(vals.get("cooldown"));
        k.setCooldown(((Integer) vals.get("cooldown")));
      }

      if (vals.containsKey("price")) {
        // System.out.println(vals.get("cooldown"));
        k.setPrice(cfg.getInt("price"));
      }

      return k;
    }
  }
コード例 #4
0
  @Override
  public PermissionGroup getDefaultGroup(String worldName) {
    ConfigurationSection groups = this.permissions.getConfigurationSection("groups");

    if (groups == null) {
      throw new RuntimeException("No groups defined. Check your permissions file.");
    }

    String defaultGroupProperty = "default";
    if (worldName != null) {
      defaultGroupProperty = buildPath("worlds", worldName, defaultGroupProperty);
    }

    for (Map.Entry<String, Object> entry : groups.getValues(false).entrySet()) {
      if (entry.getValue() instanceof ConfigurationSection) {
        ConfigurationSection groupSection = (ConfigurationSection) entry.getValue();

        if (groupSection.getBoolean(defaultGroupProperty, false)) {
          return this.manager.getGroup(entry.getKey());
        }
      }
    }

    if (worldName == null) {
      throw new RuntimeException(
          "Default user group is not defined. Please select one using the \"default: true\" property");
    }

    return null;
  }
コード例 #5
0
ファイル: KitManager.java プロジェクト: jcdesimp/CanvasKits
  /**
   * parse through dat to create a new item with enchantments, quantity, and damage value
   *
   * @param cfg to parse through
   * @return the new ItemStack
   */
  private ItemStack parseItem(ConfigurationSection cfg) {
    Map<String, Object> vals = cfg.getValues(true);
    ItemStack newItem;
    // check material
    newItem =
        new ItemStack(Material.getMaterial((cfg.getString("material", "stone")).toUpperCase()));

    // check damage value

    newItem.setDurability((short) (cfg.getInt("damage", 0)));

    // check quantity

    newItem.setAmount(cfg.getInt("amount", 1));

    // enchantment parsing
    for (String s : cfg.getStringList("enchantments")) {
      String[] parts = s.split(":");
      String enchant = parts[0];
      int level = 1;

      if (parts.length > 1) {
        level = Integer.parseInt(parts[1]);
      }
      newItem.addUnsafeEnchantment(Enchantment.getByName(enchant.toUpperCase()), level);
    }

    // System.out.println("Item: "+ newItem.toString());
    return newItem;

    // ItemStack is = new ItemStack(Material.);
  }
コード例 #6
0
ファイル: KitManager.java プロジェクト: jcdesimp/CanvasKits
  /**
   * Parses data for a kit action
   *
   * @param cfg section to parse
   * @return KitAction
   */
  private KitAction parseAction(ConfigurationSection cfg) {
    Map<String, Object> vals = cfg.getValues(true);
    KitAction action;

    if (vals.containsKey("type")) {
      String actionType = (String) vals.get("type");
      // System.out.println("Type: " + actionType);

      // Determine what type of action it is
      if (actionType.equalsIgnoreCase("ITEMS") || actionType.equalsIgnoreCase("ITEM")) {
        if (vals.containsKey("item")) {
          action = new ItemsAction(parseItem(cfg.getConfigurationSection("item")));
          return action;
        }
        return null;

      } else if (actionType.equalsIgnoreCase("EFFECT") || actionType.equalsIgnoreCase("POTION")) {
        if (vals.containsKey("effect")) {

          action = new EffectAction(parsePotion(cfg.getConfigurationSection("effect")));
          return action;
        }
        return null;

      } else if (actionType.equalsIgnoreCase("COMMAND")
          || actionType.equalsIgnoreCase("COMMANDS")) {
        String cType = cfg.getString("command.type", "console");
        String cmd = cfg.getString("command.command", "list");

        action = new CommandAction(cType, cmd);
        return action;
      }
    }
    return null;
  }
コード例 #7
0
  @Override
  public Set<String> getDefaultGroupNames(String worldName) {
    ConfigurationSection groups = this.permissions.getConfigurationSection("groups");

    if (groups == null) {
      return Collections.emptySet();
    }

    Set<String> names = new HashSet<String>();

    String defaultGroupProperty = "default";
    if (worldName != null) {
      defaultGroupProperty = buildPath("worlds", worldName, defaultGroupProperty);
    }

    for (Map.Entry<String, Object> entry : groups.getValues(false).entrySet()) {
      if (entry.getValue() instanceof ConfigurationSection) {
        ConfigurationSection groupSection = (ConfigurationSection) entry.getValue();

        if (groupSection.getBoolean(defaultGroupProperty, false)) {
          names.add(entry.getKey());
        }
      }
    }

    return Collections.unmodifiableSet(names);
  }
コード例 #8
0
 private static void addFormats(ConfigurationSection configList) {
   if (configList == null) return;
   Map<String, Object> objs = configList.getValues(false);
   if (objs == null) return;
   Iterator<Entry<String, Object>> it = objs.entrySet().iterator();
   while (it.hasNext()) {
     Entry<String, Object> obj = it.next();
     if (obj.getValue() instanceof String) {
       formats.put(obj.getKey(), ((String) obj.getValue()).replace('&', ChatColor.COLOR_CHAR));
     }
   }
 }
コード例 #9
0
 @Override
 public void setValues(ConfigurationSection sect) {
   if (sect == null || sect.getValues(false).size() == 0) {
     ConfigurationSection parent_sect = mod.getConfig().getValues();
     if (parent_sect.contains("armore") && parent_sect.isConfigurationSection("armor")) {
       sect =
           parent_sect.createSection(
               this.getName(), parent_sect.getConfigurationSection("armor").getValues(true));
     }
   }
   super.setValues(sect);
 }
コード例 #10
0
  public Collection<WirelessChannel> getAllChannels() {
    ConfigurationSection section = getConfig().getConfigurationSection(CHANNEL_SECTION);
    if (section == null) return new ArrayList<WirelessChannel>(0);

    Map<String, Object> values = section.getValues(true);
    List<WirelessChannel> channels = new ArrayList<WirelessChannel>();
    for (String cname : values.keySet()) {
      Object channel = section.get(cname);
      if (channel instanceof WirelessChannel) {
        channels.add((WirelessChannel) channel);
      } else plugin.getLogger().warning("Channel " + channel + " is not of type WirelessChannel.");
    }
    return channels;
  }
コード例 #11
0
  private void save() {

    for (Lot lot : lots) {
      this.saveToBackend(lot);
    }

    // Vaults section cleanup
    ConfigurationSection vaultsSection = data.getYamlConfig().getConfigurationSection("vaults");
    if (vaultsSection != null) {
      for (Entry<String, Object> e : vaultsSection.getValues(false).entrySet()) {

        Object v = e.getValue();
        if (!(v instanceof ConfigurationSection)) continue;

        ConfigurationSection singleVaultSection = (ConfigurationSection) v;
        int size = singleVaultSection.getKeys(false).size();

        if (size == 0 || (size == 1 && singleVaultSection.getInt("itemCount", -1) == 0)) {
          vaultsSection.set(e.getKey(), null);
        }
      }
    }
  }
コード例 #12
0
  /**
   * Enable all plugins of the given load order type.
   *
   * @param type The type of plugin to enable.
   */
  private void enablePlugins(PluginLoadOrder type) {
    if (type == PluginLoadOrder.STARTUP) {
      helpMap.clear();
      helpMap.initializeGeneralTopics();
    }

    // load all the plugins
    Plugin[] plugins = pluginManager.getPlugins();
    for (Plugin plugin : plugins) {
      if (!plugin.isEnabled() && plugin.getDescription().getLoad() == type) {
        List<Permission> perms = plugin.getDescription().getPermissions();
        for (Permission perm : perms) {
          try {
            pluginManager.addPermission(perm);
          } catch (IllegalArgumentException ex) {
            getLogger()
                .log(
                    Level.WARNING,
                    "Plugin "
                        + plugin.getDescription().getFullName()
                        + " tried to register permission '"
                        + perm.getName()
                        + "' but it's already registered",
                    ex);
          }
        }

        try {
          pluginManager.enablePlugin(plugin);
        } catch (Throwable ex) {
          logger.log(Level.SEVERE, "Error loading " + plugin.getDescription().getFullName(), ex);
        }
      }
    }

    if (type == PluginLoadOrder.POSTWORLD) {
      commandMap.setFallbackCommands();
      commandMap.registerServerAliases();
      DefaultPermissions.registerCorePermissions();
      helpMap.initializeCommands();

      // load permissions.yml
      ConfigurationSection permConfig = config.getConfigFile(ServerConfig.Key.PERMISSIONS_FILE);
      List<Permission> perms =
          Permission.loadPermissions(
              permConfig.getValues(false),
              "Permission node '%s' in permissions config is invalid",
              PermissionDefault.OP);
      for (Permission perm : perms) {
        try {
          pluginManager.addPermission(perm);
        } catch (IllegalArgumentException ex) {
          getLogger()
              .log(
                  Level.WARNING,
                  "Permission config tried to register '"
                      + perm.getName()
                      + "' but it's already registered",
                  ex);
        }
      }
    }
  }
コード例 #13
0
ファイル: P.java プロジェクト: ProgrammerDan/Brewery
  // load Block locations of given world
  public void loadWorldData(String uuid, World world) {

    File file = new File(p.getDataFolder(), "data.yml");
    if (file.exists()) {

      FileConfiguration data = YamlConfiguration.loadConfiguration(file);

      // loading BCauldron
      if (data.contains("BCauldron." + uuid)) {
        ConfigurationSection section = data.getConfigurationSection("BCauldron." + uuid);
        for (String cauldron : section.getKeys(false)) {
          // block is splitted into x/y/z
          String block = section.getString(cauldron + ".block");
          if (block != null) {
            String[] splitted = block.split("/");
            if (splitted.length == 3) {

              Block worldBlock =
                  world.getBlockAt(
                      parseInt(splitted[0]), parseInt(splitted[1]), parseInt(splitted[2]));
              BIngredients ingredients =
                  loadIngredients(section.getConfigurationSection(cauldron + ".ingredients"));
              int state = section.getInt(cauldron + ".state", 1);

              new BCauldron(worldBlock, ingredients, state);
            } else {
              errorLog(
                  "Incomplete Block-Data in data.yml: "
                      + section.getCurrentPath()
                      + "."
                      + cauldron);
            }
          } else {
            errorLog(
                "Missing Block-Data in data.yml: " + section.getCurrentPath() + "." + cauldron);
          }
        }
      }

      // loading Barrel
      if (data.contains("Barrel." + uuid)) {
        ConfigurationSection section = data.getConfigurationSection("Barrel." + uuid);
        for (String barrel : section.getKeys(false)) {
          // block spigot is splitted into x/y/z
          String spigot = section.getString(barrel + ".spigot");
          if (spigot != null) {
            String[] splitted = spigot.split("/");
            if (splitted.length == 3) {

              // load itemStacks from invSection
              ConfigurationSection invSection = section.getConfigurationSection(barrel + ".inv");
              Block block =
                  world.getBlockAt(
                      parseInt(splitted[0]), parseInt(splitted[1]), parseInt(splitted[2]));
              float time = (float) section.getDouble(barrel + ".time", 0.0);
              byte sign = (byte) section.getInt(barrel + ".sign", 0);
              String[] st = section.getString(barrel + ".st", "").split(",");
              String[] wo = section.getString(barrel + ".wo", "").split(",");

              if (invSection != null) {
                new Barrel(block, sign, st, wo, invSection.getValues(true), time);
              } else {
                // Barrel has no inventory
                new Barrel(block, sign, st, wo, null, time);
              }

            } else {
              errorLog(
                  "Incomplete Block-Data in data.yml: " + section.getCurrentPath() + "." + barrel);
            }
          } else {
            errorLog("Missing Block-Data in data.yml: " + section.getCurrentPath() + "." + barrel);
          }
        }
      }

      // loading Wakeup
      if (data.contains("Wakeup." + uuid)) {
        ConfigurationSection section = data.getConfigurationSection("Wakeup." + uuid);
        for (String wakeup : section.getKeys(false)) {
          // loc of wakeup is splitted into x/y/z/pitch/yaw
          String loc = section.getString(wakeup);
          if (loc != null) {
            String[] splitted = loc.split("/");
            if (splitted.length == 5) {

              double x = NumberUtils.toDouble(splitted[0]);
              double y = NumberUtils.toDouble(splitted[1]);
              double z = NumberUtils.toDouble(splitted[2]);
              float pitch = NumberUtils.toFloat(splitted[3]);
              float yaw = NumberUtils.toFloat(splitted[4]);
              Location location = new Location(world, x, y, z, yaw, pitch);

              Wakeup.wakeups.add(new Wakeup(location));

            } else {
              errorLog(
                  "Incomplete Location-Data in data.yml: "
                      + section.getCurrentPath()
                      + "."
                      + wakeup);
            }
          }
        }
      }
    }
  }