PermissionsEx + AsyncPlayerChatEvent

Discussion in 'Spigot Plugin Development' started by PotatoVerseMC, May 28, 2015.

  1. Hello, today I am wondering how to grab a prefix from a specific group in PermissionsEx and import a custom chat format. If anyone could contribute onto helping me, that would be great, thanks!
     
    • Agree Agree x 2
  2. Yes
     
  3. Use Vault and create a chat variable. Call the getPlayerPrefix() method to get the prefix of a player.

    I made a method that fixes NPE's if they don't have a prefix:
    Code (Text):
    private String getPrefix(Player p) {
            try {
                return MyChatVariable.getPlayerPrefix(p);
            } catch (NullPointerException e) {
                return "";
            }
        }
    NOTE: This is from an old project I did, this code could be outdated and not work, or there is better alternatives, but most likely still fully functional.
     
  4. You should not be catching runtime exceptions.
     
  5. I made this a while ago, it will still work, just bad practice.
     
  6. You probably shouldn't post it then. You also should be returning null instead of an empty String and your field does not follow naming conventions.
     
  7. Well it doesn't follow convention because I am using that as an example, I obviously wouldn't use something called "MyChatVariable" anyways.

    I return an empty String so that when using the prefix for any chat formatting or anything, it will just be a blank String.
     
  8. You are right about the String. I didn't read the first part so yeah returning null would defeat the purpose, but you still should be using naming conventions even if they are examples.
     
  9. Okay, I will use that for when giving examples, I am just assuming he wouldn't call his "MyChatVariable" :p
     
  10. You should catch them if:
    • the invalid state doesn't hinder you from recovering (think of Enum#valueOf(String) with command input) and
    • they can't be prevented any way else
    This applies to several cases, though NullPointerException surely isn't one of them, your overall statement is still incorrect :p
     
    • Like Like x 2
  11. Thank you :p
     
  12. There's another way called PEX API, wich you can easly google and find how to use it on their github. Or you can use vault as almost everyone said before.