Need help with organizing my plugin

Discussion in 'Plugin Development' started by jakemaster2003, May 11, 2017.

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

    jakemaster2003

    Dear poeple of the forum,

    I've been trying to make a method with what i just have to make a class for a command or listener and import the message settings, data settings and config settings in the command class and give the method of the messages etc. to a register in a public void method and then giving that public void method from the register class to the Main class in the onEnable the settingsmanager i got that to work but that is a static but i heard that you do not want that many static classes.

    So short and easy what i want to know is:

    - How do i make a seperate class that registers the commands and then gives them to the main class.
    - How do i make a seperate class that registers from every command class its(Messages, Options and Data) what are all stored in seperate public void methods in the command class.

    Thanks in advance
     
  2. Offline

    ipodtouch0218

    So what I can understand you want to get information from other classes without using static?

    What you want is Constructors. Pass an instance of the main class (extended JavaPlugin one) to each of your Command Handlers and Event Listeners.
    You can then use Getter and Setter methods from the main class to get the other instances of classes.
     
  3. Offline

    jakemaster2003

    Yes, but(NOOBY QUESTION) can you provide me an example because i am really new to multi class plugins, and i also wanna know how to make a class where al my commands are registerd.

    And can you please show me an example in bukkit of the constructoer one i think i do get the getter and setter but how do i get the information from that method to another class?


    And is this correct?:

    Code:
    private String mes;
       
        public void Messages(String mes){
    
           
        }
       
        public String getMessages(){
            return mes;
        }
     
    Last edited: May 11, 2017
  4. Offline

    ipodtouch0218

    Here's a quick example. It uses 3 classes to listen to an event, and compare it to a value set by a command.

    Code:
    public class Main extends JavaPlugin {
    
        private int valueOfSpoonfeed; //The value we want to store
    
        method onEnable {
            getCommand("spoon").setExecutor(new SpoonFeedCMD(this)); //Provide a this instance, etc.
            Bukkit.getPlugin.....registerEvents(this, new EventClass(this));  //Provide a "this" instance of the main class
        }
     
        method setSpoonfeedValue(int val) { //Used to set the spoonfeed value
            valueOfSpoonfeed = val;
        }
    
        method getSpoonfeedValue { //Used to get the spoonfeed value
            return valueOfSpoonfeed;
        }
    }
    Code:
    public class SpoonFeedCMD implements CommandExec... { //Command Class
    
        private Main main; //Stores the instance of the main plugin
    
        public SpoonFeedCMD(Main mainInst) { //Constructor, gets called when using "new Class()", does not have "void"
            main = mainInst; //Set the main variable to the main class instance
        }
    
        method onCommand {
            main.setSpoonfeedValue( 5 ); //We set the spoonfeed value of the main class to 5.
        }
    }
    Code:
    public class EventClass implements Liste... {
    
        private Main main; //Stores the instance of the main plugin
    
        public SpoonFeedCMD(Main mainInst) { //Constructor, gets called when using "new Class()", does not have "void"
            main = mainInst; //Set the main variable to the main class instance
        }
    
        method onBukkitPost(BukkitPostSentEvent ev) {
            if ev.getAmtOfCode > main.getSpoonfeedValue; //We get the value of the spoonfeedValue & test it.
                ev.postMessage("don't spoonfeed code!");
        }
    }
    This was a bit more spoon-feedy than I wanted it to be, but I had to make at least 3 classes. Don't hate me forever k thx <3
     
  5. Offline

    jakemaster2003

    @ipodtouch0218 Its realy hard to make my own version of what you gave me, and i still dont know how to use methods from main in a other class(I want to use: getCommand("command").set......(new Fly(This)); ) in another class where i put it in a void and that that void gets runned in the main class.

    Wel i figured out how to get the getcommand method in another class so thank you but now i want to get the method from other classes into the main class
     
  6. Offline

    ipodtouch0218

    @jakemaster2003
    I can't get any more detailed than the code already is, if so that'd be spoonfeeding.
    What's the point in setting a new CommandExecutor for a command from another class?
     
  7. Offline

    jakemaster2003

    @ipodtouch0218 okay so i understand of getting methods that only origanily can run in the class that extends JavaPlugin but:
    eclipse gives an error at the getCommand method:

    Code:
    package me.nl.YourPalJake.PixelPVPCraftEssentials.Registers;
    
    import me.nl.YourPalJake.PixelPVPCraftEssentials.Main;
    import me.nl.YourPalJake.PixelPVPCraftEssentials.Commands.Fly;
    
    public class CommandRegister {
     
        private Main main;
     
        public CommandRegister(Main mainInst){
            main = mainInst;
        }
     
        public void commandList(){
            main.getCommand("fly").setExecutor(new Fly(this));
        }
    
    }
    
    *I've think i got it!!!*
     
    Last edited: May 11, 2017
  8. Offline

    Zombie_Striker

    @jakemaster2003
    What is the error? What are the recommended options for fixing the problem?
     
Thread Status:
Not open for further replies.

Share This Page