Attachment not working

Discussion in 'Plugin Development' started by LittleMonster7_, Jul 31, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    LittleMonster7_

    Hello, im creating a simple permissions plugin for my server and when im trying to attach a player to a permission attachment it doesnt work. No errors, no anything. Can something help me?

    Code:
    public class groupsMain extends JavaPlugin
        {
     
                    public HashMap<String, PermissionAttachment> permissions = new HashMap<String, PermissionAttachment>();
                               
                    public void onEnable()
                        {
                           
                            getConfig().options().copyDefaults(true);
                           
                            saveConfig();
                           
                            for (Player p : Bukkit.getOnlinePlayers())
                                {
                                   
                                    addPermissions(p);
                                                           
                                }
                           
                        }
                   
                    public void addPermissions(Player p)
                        {
                                           
                            PermissionAttachment pa = p.addAttachment(this);
                                           
                            permissions.put(p.getName(), pa);
                                           
                            String pGroup = getConfig().getString(p.getName() + ".group");
                           
                            Bukkit.broadcastMessage("Player group: " + pGroup);
                           
                            for (String perms : getConfig().getStringList("groups." + pGroup + ".permissions"))
                                {
                                   
                                    pa.setPermission(perms, true);
                                   
                                    Bukkit.broadcastMessage("Set permission '" + perms + "' to player '" + p.getName() + "'.");
                                   
                                }
                           
                        }
     
        }
    This is the config.yml if your wondering.

    Code:
    groups:
      player:
        permissions:
        - kit.pvp
        - kit.archer
        prefix: '[p] %USERNAME% > &7%MESSAGE%'
    players:
      littlemonster7:
        group: player
     
  2. Offline

    xTigerRebornx

    LittleMonster7_ You only call addPermissions() when your plugin enables, and unless the server is reloaded, there are no Players online. Try calling it in a join event.
     
  3. Offline

    LittleMonster7_

  4. Offline

    xTigerRebornx

    LittleMonster7_ I see you have debug code, is that ever shown? If not, debug your onEnable and see if its actually getting called. Startup log would probably be helpful here as well, so can you post that?
     
  5. Offline

    LittleMonster7_

    No those are never called.

    Why not:

    Code:
    [17:54:20 INFO]: [lPerms] Enabling lPerms v1.0
    [17:54:20 INFO]: [lPerms] Plugin ENABLED
    [17:54:20 INFO]: [lPerms] Copied default configuration
    [17:54:20 INFO]: [lPerms] Save configuration
    [17:54:20 INFO]: [lPerms] Added attachment
    [17:54:20 INFO]: [lPerms] Set attachment to permissions
    [17:54:20 INFO]: [lPerms] Called method
    [17:54:20 INFO]: [lCore] Enabling lCore v1.0
    [17:54:20 INFO]: [WorldEdit] Enabling WorldEdit v5.6.3
    [17:54:20 INFO]: WEPIF: Using the Bukkit Permissions API.
    [17:54:21 INFO]: [lEXP] Enabling lEXP v1.0
    [17:54:21 INFO]: [lEXP] Successfully enabled plugin.
    [17:54:21 INFO]: [lCommon] Enabling lCommon v1.0
    [17:54:21 INFO]: [lCommon] Successfully enabled plugin.
    [17:54:21 INFO]: [lKits] Enabling lKits v1.0
    [17:54:21 INFO]: [lKits] Successfully enabled plugin.
    [17:54:21 INFO]: [lEvents] Enabling lEvents v1.0
    [17:54:21 INFO]: Server permissions file permissions.yml is empty, ignoring it
     
    [17:54:21 INFO]: CONSOLE: Reload complete.
    
     
  6. Offline

    caderape

    try
    PermissionAttachement pa = permissions.get(player)
    if (pa != null) pa.remove();
    pa = player.addattchment(this)
     
  7. Offline

    Necrodoom

    LittleMonster7_ why not use player join event? What happens if a player logs off and on after /reload then? He would lose his perms.
     
Thread Status:
Not open for further replies.

Share This Page