Solved Errors with getting Vaults setupChat() instance

Discussion in 'Plugin Development' started by OTF Catastrophe, Dec 17, 2016.

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

    OTF Catastrophe

    So I'm trying to create a plugin where you get ranks depending on how many PlayerPoints you have, so using that I'd like the rank to show up in chat but the issues I'm having right now are trying to hook into Vaults setupChat() instance. I've implemented Vault permissions and it works fine but for some reason Vault chat just won't hook in.

    Main Class:

    Code:
    package me.sirapathy;
    
    import java.io.File;
    import java.io.IOException;
    
    import net.milkbowl.vault.chat.Chat;
    import net.milkbowl.vault.permission.Permission;
    
    import org.black_ixx.playerpoints.PlayerPoints;
    import org.bukkit.Bukkit;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.plugin.RegisteredServiceProvider;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin{
       
        public static Chat chat = null;
        public static Permission permission = null;
    
        public static PlayerPoints playerPoints;
       
        public void onEnable()
        {
           
            Bukkit.getServer().getPluginManager().registerEvents(new ChatEvent(), this);
           
            if (hookPlayerPoints() != true)
            {
               
                this.getServer().getPluginManager().disablePlugin(this);
                System.out.print("[SkylandSWRanks] Plugin disabled due to PlayerPoints being absent.");
               
            }
           
            else
            {
               
                System.out.print("[SkylandSWRanks] PlayerPoints has been hooked!");
               
            }
           
            if (setupChat() != true)
            {
               
                this.getServer().getPluginManager().disablePlugin(this);
                System.out.print("[SkylandSWRanks] Plugin disabled due to Vault chat being absent.");
               
            }
           
            else
            {
               
                System.out.print("[SkylandSWRanks] Vault chat has been hooked!");
               
            }
           
            if (setupPermissions() != true)
            {
               
                this.getServer().getPluginManager().disablePlugin(this);
                System.out.print("[SkylandSWRanks] Plugin disabled due to Vault perms being absent.");
               
            }
           
            else
            {
               
                System.out.print("[SkylandSWRanks] Vault perms has been hooked!");
               
            }
           
            if (!getDataFolder().exists())
            {
               
                getDataFolder().mkdir();
               
            }
           
            File c = new File(getDataFolder(), "config.yml");
           
            if (!c.exists())
            {
               
                try
                {
                   
                    c.createNewFile();
                   
                }
               
                catch (IOException e)
                {
    
                    e.printStackTrace();
                   
                }
               
            }
            this.getConfig().options().copyDefaults(true);
        }
       
        private boolean setupPermissions()
        {
            RegisteredServiceProvider<Permission> permissionProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.permission.Permission.class);
            if (permissionProvider != null) {
                permission = permissionProvider.getProvider();
            }
            return (permission != null);
        }
    
        private boolean setupChat()
        {
            RegisteredServiceProvider<Chat> chatProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.chat.Chat.class);
            if (chatProvider != null) {
                chat = chatProvider.getProvider();
            }
            return (chat != null);
        }
       
        public PlayerPoints getPlayerPoints()
        {
           
            return playerPoints;
       
        }
       
        private boolean hookPlayerPoints()
        {
           
            final Plugin plugin = this.getServer().getPluginManager().getPlugin("PlayerPoints");
            playerPoints = PlayerPoints.class.cast(plugin);
            return playerPoints != null;
           
        }
       
    }
    
    I have it set so it puts a message in console if it hooks into it just to make sure it all works fine and the only issue is Vault chat. Can anyone tell me what I'm doing wrong? I have the RSP literally copied and pasted from the Vault bukkit plugin page.
     
  2. Offline

    mythbusterma

    @OTF Catastrophe

    Do you have something that is actually a chat provider installed?
     
  3. Offline

    timtower Moderator Moderator

    @OTF Catastrophe Do you have a chat plugin installed?
    And use getLogger instead of System.out
     
  4. Offline

    OTF Catastrophe

    Like EssentialsChat? Would that work?
     
  5. Offline

    mythbusterma

  6. Offline

    OTF Catastrophe

  7. Offline

    mythbusterma

    @OTF Catastrophe

    Have you made sure your plugin soft depends on Vault and Essentials?
     
  8. Offline

    OTF Catastrophe

    Alrighty I figured you were gonna ask that, no that's not the issue aha. My personal plugin is writing chat formats by itself so I don't need Essentials. I need Vaults perms and chat to be able to get the players PermissionsEx group prefix, but for some reason Vaults setupChat method isn't working. I'll provide both classes:

    Main: http://pastebin.com/Yss9dTBk
    ChatEvent: http://pastebin.com/w3TJZs24
     
  9. Offline

    mythbusterma

    @OTF Catastrophe

    Okay. That's great. But you didn't answer my question, and that is the issue.

    If you are changing the chat format, you are the chat provider, and you won't have to request it from Vault. If you're only writing it to work with PEX, you can just access it directly, as PEX has an API.

    The method you have there works fine, but the issue is that you're requesting an instance of a plugin before it's loaded because you're not depending on it. If you don't need a chat provider, don't ask for one.
     
  10. Offline

    OTF Catastrophe

    Yes the plugin was dependent on Vault and it was put like that in the plugin.yml but that wasn't the issue. It's all good, I just decided to use EssentialsChat and getting the players displayname to complete the way my chat ranks look. Thank you for your help.
     
Thread Status:
Not open for further replies.

Share This Page