title: Create Permissions plugin (aplugin.*) - Spigot/Bukkit - Java
body: <p>I tried to create something like a little Permissions plugin, but my problem is that I don't know how to give a Player for example the Permissions <code>aplugin.chat</code> and <code>aplugin.color</code> when I only give him the Permission <code>aplugin.*</code>. Of course it is no problem if the Permission is registered and I can check every Permission from <code>Bukkit.getPluginManager().getPermissions()</code>. How can I solve it if it isn't registered? In BungeeCord there is a Event where I can see the required Permission, but in Spigot/Bukkit?</p>
  
  <p>Here is my newest version of code for setting the permissions:</p>
  
  <pre><code>// setPerms
  public static void setPerms(Player p) {
      try {
          PreparedStatement ps = MySQL.getConnection()
                  .prepareStatement("SELECT Permission FROM Permissions WHERE Gruppe = ?");
          ps.setString(1, User.getPermGroup(p.getName()));
          ResultSet rs = ps.executeQuery();
          PermissionAttachment pa;
          if (main.perms.containsKey(p.getName())) {
              pa = main.perms.get(p.getName());
          } else {
              pa = p.addAttachment(plugin);
          }
          while (rs.next() == true) {
              String perm = rs.getString("Permission");
              boolean value = true;
              if (perm.startsWith("-")) {
                  perm = perm.substring(1);
                  value = false;
              }
              if (perm.endsWith("*")) {
                  if (perm.equals("*")) {
                      for (Permission pe : Bukkit.getPluginManager().getPermissions()) {
                          pa.setPermission(pe, value);
                      }
                      pa.setPermission(perm, value);
                  } else {
                      String search = perm.substring(0, perm.length() - 1);
                      for (Permission pe : Bukkit.getPluginManager().getPermissions()) {
                          if (pe.getName().startsWith(search)) {
                              pa.setPermission(pe, value);
                          }
                      }
                      pa.setPermission(perm, value);
                  }
              }
              pa.setPermission(perm, value);
          }
          main.perms.replace(p.getName(), pa);
      } catch (SQLException e) {
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>Thank you for your help and sorry for my bad English ;)</p>