ChatPrefix Help?

Discussion in 'Spigot Plugin Development' started by Nosmakos, May 17, 2016.

  1. Hey guys i was wondering how i xan add multiple prefix? i was trying bit the only thing i did was make my own chat prefix but i want something like that : because if i have groupmanager and make my chat prefix its just removing the groupmanager prefix and adding only mine and i want to have the both
    "[MyOwnRank] | [Rank-GroupManager][Name] » [Message]"
     
  2. Could I see the code you're using? Changing the even priority may allow you to add your extra prefix before Group Manager does.
     
  3. I will show u when i open my pc it was simple i just added a chat format for the the player name and the message and if i had already admin prefix it changed to my prefix i made but i want to have 2 prefix mine and gm
     
  4. Yeah, once you get on your computer show me what you have. I believe we can do what you're asking if we implement event priorities. That way your prefix would be added to Group Manager's.
     
  5. Cool i hope because i want to make something like kits or teams and i want first to be my own prefix and then the other
     
  6. this is an example what i had
    Code (Text):
        @EventHandler
          public void onChatPlayer(AsyncPlayerChatEvent e) {
            Player p = e.getPlayer();
              if ((p.hasPermission("example.twd"))){
                 
                e.setFormat("[TWD]" + p.getName() + " §6» §7" + e.getMessage());
              }
        }
     
  7. Okay, looking at Group Manager it seems you can add to a group's prefix.
    Which seems it would be the easiest way to go.

    First, you would want to add the Group Manager API to your project (From here: Github Page).

    After you've added it you need to get the group you want to modify:

    Code (Text):

    //imports
    import org.anjocaido.groupmanager.data.Group;
    import org.anjocaido.groupmanager.GroupManager;

    public class ExamplePlugin extends JavaPlugin
    {
         @Override
         public void onEnable()
         {
              GlobalGroups groups = GroupManager.getGlobalGroups();
              Group group = groups.getGroup("exampleGroup"); // this is the group you want (it has the same name as the one you defined in the groups YAML file)
         }
    }
     
    Now you need to actually add to the prefix with the one you want:

    Code (Text):

    //imports
    import org.anjocaido.groupmanager.data.Group;
    import org.anjocaido.groupmanager.GroupManager;

    public class ExamplePlugin extends JavaPlugin
    {
         @Override
         public void onEnable()
         {
              GlobalGroups groups = GroupManager.getGlobalGroups();
              Group group = groups.getGroup("exampleGroup"); // this is the group you want

              // now we need to add your prefix
              String myPrefix = "[Example Prefix]";
              group.getVariables().addVar("prefix", group.getVariables.getVarString("prefix") + myPrefix); // add Group Manager's prefix AND your prefix
         }
    }
     
    A few things to note:

    If you check the Github page you can see how the functions I used work, as they're well documented.
    Also, ensure your plugin depends on the "GroupManager" plugin before it loads, as the groups must be loaded before you start modifying them! Hopefully this helps. ;)

    Edit:
    I corrected an error in my addVar function syntax.
     
    #7 CovertLizard, May 17, 2016
    Last edited: May 17, 2016
    • Useful Useful x 1
  8. cool thanks for the help!!!!
     
    • Like Like x 1