Solved Calling method from another class

Discussion in 'Plugin Development' started by Just_Jitse, May 29, 2015.

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

    Just_Jitse

    How can I fix this?

    Main:
    Code:
    package me.Just_Jitse.Server;
    
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin implements Listener{
       
        static Plugin plugin;
    
        public void onEnable(){
           
            Main.plugin = this;
           
            PluginManager pm = getServer().getPluginManager();
            pm.registerEvents(new Broadcast(), this);
           
            //HERE IS THE ERROR
            broadcast;
        }
    
    
        public static Plugin getMain(){
            return plugin;
        }
    }
    
    Broadcast:
    Code:
    package me.Just_Jitse.Server;
    
    import java.util.Arrays;
    import java.util.Random;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.event.Listener;
    
    public class Broadcast implements Listener{
       
        public void broadcast() {
           
            String str = Main.plugin.getConfig().getString("zin1");
            str = ChatColor.translateAlternateColorCodes('&', str);
           
            String str2 = Main.plugin.getConfig().getString("zin2");
            str2 = ChatColor.translateAlternateColorCodes('&', str2);
           
            String str3 = Main.plugin.getConfig().getString("zin3");
            str3 = ChatColor.translateAlternateColorCodes('&', str3);
           
            final String[] messages = {
                    str, str2, str3
            };
           
            Bukkit.getScheduler().scheduleSyncRepeatingTask(Main.plugin, new Runnable() {
               
                @Override
                public void run() {
                    Bukkit.broadcastMessage(Arrays.asList(messages).get(new Random().nextInt(messages.length)));
                }
            }, 0, 20 * 30);
        }
    
    }
    
     
  2. @Just_Jitse *Sigh* This is why people have to learn Java beforehand.
    It's in another class. You need to make an instance of that class, or use a static method to be able to invoke it.

    Code:
    new Broadcast().broadcast(); //Making an instance of the glass
    Broadcast.broadcast(); //Static method[code]
     
  3. Offline

    Agentleader1

    Agreed

    Put "static" in front of the return type, then you can access the method by typing in the class then it's method name;

    "OtherClass.method();"
     
  4. Offline

    Just_Jitse

Thread Status:
Not open for further replies.

Share This Page