Event Chat Formatting issues.

Discussion in 'Plugin Development' started by AeroLiquid, Oct 3, 2015.

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

    AeroLiquid

    So I decided to make a chat format event, but it seems to not work. No errors are in the console/in-game.
    -snip-
    I believe it has something to do with the else if statements,but I've got no idea.
     
    Last edited: Oct 3, 2015
  2. Offline

    dlange

    @AeroLiquid Debug, see if the event is being fired or not
     
  3. Offline

    567legodude

    @AeroLiquid Because you are not formatting the message correctly.
    setFormat() sets the base string that a Formatter will use to parse the message, and it has specific variables.

    Use: %1$s
    where you want the player's name to appear.
    Use: %2$s
    where you want the message to appear.
     
  4. Offline

    AeroLiquid

    Thank you. I'll try this out now.

    EDIT: It still seems to default me to the standard scenario of pbasic.chat.normal, even though I am op.
    -snip-
     
    Last edited: Oct 3, 2015
  5. Offline

    teej107

    Because the OP has every permission.
     
    AeroLiquid likes this.
  6. Offline

    AeroLiquid

    Ohhhhhh, thank you.
     
  7. Offline

    567legodude

    @AeroLiquid Remember you can also register your permissions with PermissionDefault.FALSE so then even ops won't automatically get it.
     
  8. Offline

    AeroLiquid

    Okay, so next day. The plugin still doesn't work even with myself being op. No errors ingame/in console, and I'm still not being marked as an Owner, even though I'm configured as one in the PEX user groups - with the permission node to mark me as one. Anyone help?
    PHP:
        @EventHandler
        
    public void onPlayerChat(AsyncPlayerChatEvent e) {
            
    Player player e.getPlayer();
            if (
    player.hasPermission("pbasic.chat.normal")
                    || 
    player.hasPermission("")) {
                
    e.setFormat("§7%1$s » %2$s");
                
    player.setDisplayName("§7" player.getDisplayName());
                
    player.setPlayerListName("§7" player.getDisplayName());
            } else if (
    player.hasPermission("pbasic.chat.investor")) {
                
    e.setFormat("§a%1$s §f» %2$s");
                
    player.setDisplayName("§a" player.getDisplayName());
                
    player.setPlayerListName("§a" player.getDisplayName());
            } else if (
    player.hasPermission("pbasic.chat.expert")) {
                
    e.setFormat("§6%1$s §f» %2$s");
                
    player.setDisplayName("§6" player.getDisplayName());
                
    player.setPlayerListName("§6" player.getDisplayName());
            } else if (
    player.hasPermission("pbasic.chat.titan")) {
                
    e.setFormat("§9§o%1$s §f» §3%2$s");
                
    player.setDisplayName("§9§o" player.getDisplayName());
                
    player.setPlayerListName("§9§o" player.getDisplayName());
            } else if (
    player.hasPermission("pbasic.chat.supervisor")) {
                
    e.setFormat("§d%1$s §f» §e%2$s");
                
    player.setDisplayName("§d" player.getDisplayName());
                
    player.setPlayerListName("§d" player.getDisplayName());
            } else if (
    player.hasPermission("pbasic.chat.mod")) {
                
    e.setFormat("§5%1$s §f» §e%2$s");
                
    player.setDisplayName("§5" player.getDisplayName());
                
    player.setPlayerListName("§5" player.getDisplayName());
            } else if (
    player.hasPermission("pbasic.chat.mod+")) {
                
    e.setFormat("§5§o%1$s §f» §e%2$s");
                
    player.setDisplayName("§5§o" player.getDisplayName());
                
    player.setPlayerListName("§5§o" player.getDisplayName());
            } else if (
    player.hasPermission("pbasic.chat.dev")) {
                
    e.setFormat("§b§o%1$s §f» §e%2$s");
                
    player.setDisplayName("§b§o" player.getDisplayName());
                
    player.setPlayerListName("§b§o" player.getDisplayName());
            } else if (
    player.hasPermission("pbasic.chat.admin")) {
                
    e.setFormat("§c%1$s §f» §e%2$s");
                
    player.setDisplayName("§c" player.getDisplayName());
                
    player.setPlayerListName("§c" player.getDisplayName());
            } else if (
    player.hasPermission("pbasic.chat.owner") || player.isOp()
                    || 
    player.hasPermission("*")) {
                
    e.setFormat("§4%1$s §f» §e%2$s");
                
    player.setDisplayName("§4" player.getDisplayName());
                
    player.setPlayerListName("§4" player.getDisplayName());
            }
        }

        @
    EventHandler
        
    public void onJoin(PlayerJoinEvent ee) {
            
    Player player ee.getPlayer();
            if (
    player.hasPermission("pbasic.chat.normal")
                    || 
    player.hasPermission("")) {
                
    player.setDisplayName("§7" player.getDisplayName());
                
    player.setPlayerListName("§7" player.getDisplayName());
            } else if (
    player.hasPermission("pbasic.chat.investor")) {
                
    player.setDisplayName("§a" player.getDisplayName());
                
    player.setPlayerListName("§a" player.getDisplayName());
            } else if (
    player.hasPermission("pbasic.chat.expert")) {
                
    player.setDisplayName("§6" player.getDisplayName());
                
    player.setPlayerListName("§6" player.getDisplayName());
            } else if (
    player.hasPermission("pbasic.chat.titan")) {
                
    player.setDisplayName("§9§o" player.getDisplayName());
                
    player.setPlayerListName("§9§o" player.getDisplayName());
            } else if (
    player.hasPermission("pbasic.chat.supervisor")) {
                
    player.setDisplayName("§d" player.getDisplayName());
                
    player.setPlayerListName("§d" player.getDisplayName());
            } else if (
    player.hasPermission("pbasic.chat.mod")) {
                
    player.setDisplayName("§5" player.getDisplayName());
                
    player.setPlayerListName("§5" player.getDisplayName());
            } else if (
    player.hasPermission("pbasic.chat.mod+")) {
                
    player.setDisplayName("§5§o" player.getDisplayName());
                
    player.setPlayerListName("§5§o" player.getDisplayName());
            } else if (
    player.hasPermission("pbasic.chat.dev")) {
                
    player.setDisplayName("§b§o" player.getDisplayName());
            } else if (
    player.hasPermission("pbasic.chat.admin")) {
                
    player.setPlayerListName("§c" player.getDisplayName());
                
    player.setDisplayName("§c" player.getDisplayName());
            } else if (
    player.hasPermission("pbasic.chat.owner") || player.isOp()
                    || 
    player.hasPermission("*")) {
                
    player.setDisplayName("§4" player.getDisplayName());
                
    player.setPlayerListName("§4" player.getDisplayName());
            }
        }
    }


    psI've got to go for a bit so I may not respond with answers quickly.
     
  9. Offline

    boomboompower

    What?
    Code:
    player.hasPermission("")
    Just deop yourself and use a plugin like PermissionsEx and separately give yourself permissions
     
  10. Offline

    AeroLiquid

Thread Status:
Not open for further replies.

Share This Page