예제 #1
0
 @SuppressWarnings({"rawtypes", "unchecked"})
 protected List getList(Field field, ConfigurationSection cs, String path, int depth)
     throws Exception {
   depth++;
   int listSize = cs.getKeys(false).size();
   String key = path;
   if (key.lastIndexOf(".") >= 0) {
     key = key.substring(key.lastIndexOf("."));
   }
   List list = new ArrayList();
   if (listSize > 0) {
     int loaded = 0;
     int i = 0;
     while (loaded < listSize) {
       if (cs.isSet(key + i)) {
         Object in = cs.get(key + i);
         in = loadObject(field, cs, key + i, depth);
         list.add(in);
         loaded++;
       }
       i++;
       // ugly overflow guard... should only be needed if config was manually edited very badly
       if (i > (listSize * 3)) loaded = listSize;
     }
   }
   return list;
 }
예제 #2
0
 /**
  * Loads a list of ItemStack objects from a ConfigurationSection.
  *
  * @param section Where to read the saved list.
  * @return A correctly build List of Itemstack Objects.
  */
 public static List<ItemStack> loadItemStack(ConfigurationSection section) {
   List<ItemStack> stacks = new LinkedList<>();
   for (String key : section.getKeys(false)) {
     stacks.add((ItemStack) section.get(key));
   }
   return stacks;
 }
예제 #3
0
 public KitInfo(ConfigurationSection config) {
   this(config.getName());
   icon = config.getItemStack("icon");
   helmet = config.getItemStack("helmet");
   chest = config.getItemStack("chest");
   legs = config.getItemStack("legs");
   boots = config.getItemStack("boots");
   try {
     items = (List<ItemStack>) config.get("items", new ArrayList<ItemStack>());
   } catch (ClassCastException e) {
     Bukkit.getLogger().log(Level.WARNING, "[SimpleTeamPvP] Could not load items for kit " + name);
   }
 }
  public WirelessChannel getWirelessChannel(String channelName) {
    ConfigurationSection section = getConfig().getConfigurationSection(CHANNEL_SECTION);
    if (section == null) return null; // section not found.

    Object channel = section.get(channelName);
    if (channel == null) return null; // channel not found
    else if (!(channel instanceof WirelessChannel)) {
      plugin
          .getLogger()
          .warning("Channel " + channelName + " does not seem to be of type WirelessChannel.");
      return null;
    } else return (WirelessChannel) channel;
  }
  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;
  }
예제 #6
0
 @SuppressWarnings({"rawtypes", "unchecked"})
 protected Map getMap(Field field, ConfigurationSection cs, String path, int depth)
     throws Exception {
   depth++;
   Set<String> keys = cs.getKeys(false);
   Map map = new HashMap();
   if (keys != null && keys.size() > 0) {
     for (String key : keys) {
       Object in = cs.get(key);
       in = loadObject(field, cs, key, depth);
       map.put(key, in);
     }
   }
   return map;
 }
예제 #7
0
  public static void save(ConfigurationSection section, ConfigurationSection oldData) {
    p.createWorldSections(section);

    // loc is saved as a String in world sections with format x/y/z/pitch/yaw
    if (!wakeups.isEmpty()) {

      Iterator<Wakeup> iter = wakeups.iterator();
      for (int id = 0; iter.hasNext(); id++) {
        Wakeup wakeup = iter.next();

        if (!wakeup.active) {
          continue;
        }

        String worldName = wakeup.loc.getWorld().getName();
        String prefix;

        if (worldName.startsWith("DXL_")) {
          prefix = p.getDxlName(worldName) + "." + id;
        } else {
          prefix = wakeup.loc.getWorld().getUID().toString() + "." + id;
        }

        section.set(
            prefix,
            wakeup.loc.getX()
                + "/"
                + wakeup.loc.getY()
                + "/"
                + wakeup.loc.getZ()
                + "/"
                + wakeup.loc.getPitch()
                + "/"
                + wakeup.loc.getYaw());
      }
    }

    // copy Wakeups that are not loaded
    if (oldData != null) {
      for (String uuid : oldData.getKeys(false)) {
        if (!section.contains(uuid)) {
          section.set(uuid, oldData.get(uuid));
        }
      }
    }
  }
예제 #8
0
 public void load(ConfigurationSection config) {
   // Set some defaults.
   config.addDefault("Permission", "");
   config.addDefault("Interval", 60);
   config.addDefault("Prefix", "[&eServer&r] ");
   config.addDefault("LogToConsole", true);
   config.addDefault("Randomize", true);
   config.addDefault("Announcements", new ArrayList<String>(0));
   // Load
   permission = config.getString("Permission");
   if (permission.length() == 0) permission = null;
   interval = config.getInt("Interval");
   Object prefix = config.get("Prefix");
   logToConsole = config.getBoolean("LogToConsole");
   randomize = config.getBoolean("Randomize");
   announcements.clear();
   randomQueue = null;
   for (Object entry : config.getList("Announcements")) {
     announcements.add(Announcement.withPrefixAndEntry(prefix, entry));
   }
 }
예제 #9
0
  private void loadUnsafe() throws Exception {
    boolean autoSave = wm.getAutoSave();
    wm.setAutoSave(false);
    if (!ufile.exists()) {
      if (ufile.getParentFile() != null) ufile.getParentFile().mkdirs();
      ufile.createNewFile();
      gfile.createNewFile();
    } else {
      uconfig = new YamlConfiguration();
      gconfig = new YamlConfiguration();
      uconfig.load(ufile);
      gconfig.load(gfile);
    }
    /*
     * Load the users
     */
    ConfigurationSection usersConfig = uconfig.getConfigurationSection(USERS);
    if (usersConfig != null) {

      Set<String> names = usersConfig.getKeys(false);

      for (String name : names) {
        List<String> nPerm = usersConfig.getStringList(name + "." + PERMISSIONS);
        List<String> nGroup = usersConfig.getStringList(name + "." + GROUPS);
        Set<Permission> perms = Permission.loadFromString(nPerm);
        // Create the new user
        User user = new User(name, nGroup, perms, getName(), this);
        // MetaData
        ConfigurationSection meta = usersConfig.getConfigurationSection(name + "." + META);
        if (meta != null) {
          Set<String> keys = meta.getKeys(false);
          if (keys != null && keys.size() > 0)
            for (String key : keys) user.setValue(key, meta.get(key).toString());
        }
        // Upload to API
        add(user);
      }
    }
    /*
     * Load the groups
     */
    ConfigurationSection groupsConfig = gconfig.getConfigurationSection(GROUPS);
    if (groupsConfig != null) {

      Set<String> names = groupsConfig.getKeys(false);

      for (String name : names) {
        List<String> nPerm = groupsConfig.getStringList(name + "." + PERMISSIONS);
        List<String> nGroup = groupsConfig.getStringList(name + "." + GROUPS);

        Set<Permission> perms = Permission.loadFromString(nPerm);
        // Create the new group
        Group group = new Group(name, nGroup, perms, getName(), this);
        // MetaData
        ConfigurationSection meta = groupsConfig.getConfigurationSection(name + "." + META);
        if (meta != null) {
          Set<String> keys = meta.getKeys(false);
          if (keys != null && keys.size() > 0)
            for (String key : keys) group.setValue(key, meta.get(key).toString());
        }
        // Upload to API
        add(group);
      }
    }

    // for (Calculable user : getAll(CalculableType.USER)) {
    // try {
    //	user.calculateEffectivePermissions();
    // user.calculateEffectiveMeta();
    // } catch (RecursiveGroupException e) {
    //	System.err.println(e.getMessage());
    // }
    // }
    for (Player player : this.permissions.getServer().getOnlinePlayers()) {
      String name = player.getName();
      String world = player.getWorld().getName();
      if (wm.getWorld(world) == this) {
        getUser(name).calculateEffectivePermissions();
      }
    }
    wm.setAutoSave(autoSave);
  }
예제 #10
0
 @SuppressWarnings("rawtypes")
 protected Object loadObject(Field field, ConfigurationSection cs, String path, int depth)
     throws Exception {
   Class clazz = getClassAtDepth(field.getGenericType(), depth);
   if (ConfigObject.class.isAssignableFrom(clazz) && isConfigurationSection(cs.get(path))) {
     return getConfigObject(clazz, cs.getConfigurationSection(path));
   } else if (Location.class.isAssignableFrom(clazz) && isJSON(cs.get(path))) {
     return getLocation((String) cs.get(path));
   } else if (Vector.class.isAssignableFrom(clazz) && isJSON(cs.get(path))) {
     return getVector((String) cs.get(path));
   } else if (Map.class.isAssignableFrom(clazz) && isConfigurationSection(cs.get(path))) {
     return getMap(field, cs.getConfigurationSection(path), path, depth);
   } else if (clazz.isEnum() && isString(cs.get(path))) {
     return getEnum(clazz, (String) cs.get(path));
   } else if (List.class.isAssignableFrom(clazz) && isConfigurationSection(cs.get(path))) {
     Class subClazz = getClassAtDepth(field.getGenericType(), depth + 1);
     if (ConfigObject.class.isAssignableFrom(subClazz)
         || Location.class.isAssignableFrom(subClazz)
         || Vector.class.isAssignableFrom(subClazz)
         || Map.class.isAssignableFrom(subClazz)
         || List.class.isAssignableFrom(subClazz)
         || subClazz.isEnum()) {
       return getList(field, cs.getConfigurationSection(path), path, depth);
     } else {
       return cs.get(path);
     }
   } else {
     return cs.get(path);
   }
 }
예제 #11
0
 @Override
 public Object getRaw(String key) {
   return root.get(getKeyFor(key));
 }