Solved How do i make a api in multiple classes

Discussion in 'Plugin Development' started by phil14052, Jun 27, 2015.

Thread Status:
Not open for further replies.
  1. So i want to make a API for my plugin and i have made the methods but i am using a class for only the API but i dont know how so people easy can get that class and only that class.
    Code:
    package me.Phil14052.ClearChat2_0;
    
    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    
    public class API {
    
        private ClearChat2_0 plugin = ClearChat2_0.getInstance();
      
        public void ClearGlobalChat(int lines,Boolean InGamePlayersOnly,Boolean MessageEnabled, String Message){
    
            if(InGamePlayersOnly == true){
                for (Player player1 : Bukkit.getOnlinePlayers()){
                    player1.sendMessage("                ");  
                }
                if(MessageEnabled == true){
                    Bukkit.broadcastMessage(Message
                            .replaceAll("%PlayerName%", "Console")
                            .replaceAll("%PlayerDisplayName%", "§cConsole")
                            .replaceAll("%World%", "The world of consols")
                            .replaceAll("%Prefix%", plugin.getPrefix())
                            .replaceAll("&","§"));
                }
            }else{
            for(int i=0; i<lines; i++){
                Bukkit.broadcastMessage("                ");
            }
          
            if(MessageEnabled == true){
                Bukkit.broadcastMessage(Message
                        .replaceAll("%PlayerName%", "Console")
                        .replaceAll("%PlayerDisplayName%", "§cConsole")
                        .replaceAll("%World%", "The world of consols")
                        .replaceAll("%Prefix%", plugin.getPrefix())
                        .replaceAll("&","§"));
            }
            }
    
        }
      
        public void ClearPersonalChat(Player p,int Lines , Boolean MessageEnabled, String Message){
            for(int i=0; i<Lines; i++){
                p.sendMessage("                ");
            }
            if(MessageEnabled == true){
                Bukkit.broadcastMessage(Message
                        .replaceAll("%PlayerName%", "Console")
                        .replaceAll("%PlayerDisplayName%", "§cConsole")
                        .replaceAll("%World%", "The world of consols")
                        .replaceAll("%Prefix%", plugin.getPrefix())
                        .replaceAll("&","§"));
            }
        }
    
    }
    
     
  2. Offline

    Xerox262

    If you go to your ClearChat2_0 class and do something like this

    public API api;

    then add this in your onEnable
    api = new API();

    then you should be able to call ClearChat2_0.getInstance().api from any class to access your api
     
  3. Thanks it helped!
     
  4. Xerox262 likes this.
Thread Status:
Not open for further replies.

Share This Page