PlaceHolderAPI not working

Discussion in 'Plugin Development' started by AL_1, Aug 16, 2016.

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

    AL_1

    As part of my plugin i have a clear chat command and at the end of the blank messages there is an option to display text. My problem is that the PlaceHolderAPI isn't working as it should.

    Command Code:
    Code:
            
    if (label.equalsIgnoreCase("clearchat") || label.equalsIgnoreCase("mcc")) {
                if (p.hasPermission("mystic.chat.admin.clearchat")) {
                    for (int i = 0; i < getConfig().getInt("clearChat.blankLines"); i++) {
                        Bukkit.broadcastMessage(" ");
                    }
                    for (String s : getConfig().getStringList("clearChat.endMessage")) {
                        s = PlaceholderAPI.setPlaceholders(p, s);
                        // This is here to check if the PlaceHolderAPI even knows there is place holders in it
                        p.sendMessage(String.valueOf(PlaceholderAPI.containsPlaceholders(s)));
                        Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', s));
    
                    }
                    return true;
                } else {
                    p.sendMessage(ChatColor.RED + "You are lacking the required permission node!");
                    return true;
                }
            }
    
    
    On a side note, is it better to use label.equalsIgnoreCase("command") or command.getName().equalsIgnoreCase("command")?

    Config File section:
    Code:
    clearChat:
      blankLines: 256
      endMessage:
      - '&bChat was cleared by %player_name%'
    When i run the command "/mcc" or "/clearchat" it always says false (for not recognizing any placeholders) and none of the place holders are replaced.

    I feel as if im making a stupid mistake, or that im doing this the complete wrong way...
     
  2. Offline

    timtower Administrator Administrator Moderator

    command.getName as that is always the same, label can change due to aliases.
     
    AL_1 likes this.
  3. Offline

    AL_1

    So they are both the same, and it doesn't matter which one I use?
     
    Last edited: Aug 16, 2016
  4. Offline

    timtower Administrator Administrator Moderator

    @DiamondDeveloper Example:
    Code:
    commands:
      help:
        aliases: [helpme]
    command.getName returns the same for /help and /helpme
    label returns /help OR /helpme depending on the command being called.

    So use command.getName
     
  5. Offline

    AL_1

    Okay, got it. Thanks


    Now back to my original question lol
     
  6. Offline

    Lordloss

    as replacing placeholders in text is actually a one-liner in code, for what exactly do you need an API?
     
  7. Offline

    timtower Administrator Administrator Moderator

    PlaceholderAPI gets its data from ..... plugins etc.
    So 1 line of code can make 100 changes.
     
  8. Offline

    AL_1

    The person I am making this plugin for requested place holders, and i was thinking this was the best option, so now I need a way to make it work. If no one can help me then I'll just recreate the whole command from scratch, that ushaly fixes the problem (s).

    -bump-
     
    Last edited: Sep 9, 2016
Thread Status:
Not open for further replies.

Share This Page