Putting classes "link" in main

Discussion in 'Plugin Development' started by TGF, Apr 10, 2012.

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

    TGF

    Hi!
    I have 2 class files with another commands/functions, I want to make this in the one plugin without connecting with each and I want to plugin behaved like this classes was in one class.
    What I have to put in main class to do that?

    Can somebody help me? I really need help!!!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 25, 2016
  2. Offline

    Neodork

    I don't quite get what your asking but maybe this will help:

    add this to your fields:
    public ClassName cn = new Classname(this);
     
  3. Offline

    TGF

    I don't understand...

    For example i have:
    ----------------------------------------------------------------------------------
    main.class
    Code:
    
    
    first.class
    Code:
    package (...)
     
    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if(command.getName().equalsIgnoreCase("first"){
    player.sendMessage(ChatColor.YELLOW + "first! ");
    return true;
    (...)
    
    second.class
    Code:
    package(...)
     
    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if(command.getName().equalsIgnoreCase("second"){
    player.sendMessage(ChatColor.YELLOW + "second! ");
    return true;
    (...)
    
    ----------------------------------------------------------------------------------
    Now what I have to put in main to connect this classes to one?
    /I want a shortcut to both classes in main, not a code./



    /edit
    public ClassName cn = new Classname(this);
    What this doing?
     
  4. Offline

    kumpelblase2

    An empty main class, that's pretty good.
     
  5. Offline

    Dreeass

    Code:
    public static MAINCLASSNAME plugin;
       
        public CLASSNAME(MAINCLASSNAME instance) {
            plugin = instance;
        }
    Add this after public class... {
    To get the server from the main class you do: plugin.getServer();
     
  6. Offline

    TGF

    That is good?
    main.class (open)
    package (...)

    public class Main {
    public static Main plugin;

    public void czas(Main instance) {
    plugin = instance;
    }
    }

    If yes, where I have to put plugin.getServer();?
    Like that?
    first.class (open)
    package (...)

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if(command.getName().equalsIgnoreCase("first"){
    plugin.getServer();
    player.sendMessage(ChatColor.YELLOW + "first! ");
    return true;
    }
    (...)


    Then I recieve an error - plugin cannot be resolved.
     
  7. Offline

    Dreeass

    The plugin.getServer() is just an example on how to get something from the other class.

    Put this in the other class, not in the main class:
    Code:
     
    Public static MAINCLASSNAME plugin;
     
    public CLASSNAME(MAINCLASSNAME instance) {
        plugin = instance;
    }
     
     
    
     
    TGF likes this.
  8. Offline

    TGF

    Not working. When i write a command ingame nothing happen.
     
  9. Offline

    Dreeass

    Watch the playlist.
     
    TGF likes this.
  10. Offline

    TGF

    Which video?
    When i write command i receive the same command.
    For ex.: i write /first i receive /first

    Later i put here more code to show you my problem.
     
  11. Offline

    Dreeass

    All of them..
     
  12. Offline

    TGF

    hmm:p my net is sucks slow but I thank u in advance
     
Thread Status:
Not open for further replies.

Share This Page