Code help... Referencing Classes

Discussion in 'Plugin Development' started by West_Dover, Jun 10, 2013.

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

    West_Dover

    Ok so im trying to make a plugin that does some stuff. I want to be able to Disable functions Completly thru the config file. I have this code:

    MAIN CLASS -
    Code:
    package org.westdover.main;
     
    import org.bukkit.Color;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.westdover.econ.EconMain;
    import org.westdover.listeners.PlayerLogin;
    import org.westdover.listeners.SignMunipulation;
    import java.util.logging.Logger;
     
    public class Life extends JavaPlugin{
          public final Logger Logger = java.util.logging.Logger.getLogger("Minecraft");
          public static Life plugin;
         
          @Override
          public void onDisable() {
              this.Logger.info(Color.TEAL + "[LIFE]" + " Life is shuting down.");
          }
         
          @Override
          public void onEnable() {
              this.Logger.info(Color.TEAL + "[LIFE]" + " Life is starting up!");
              this.Logger.info(Color.TEAL + "[LIFE]" + " Life is created by West_Dover.");
                getServer().getPluginManager().registerEvents(new PlayerLogin(), this);
                getServer().getPluginManager().registerEvents(new SignMunipulation(), this);
                this.saveDefaultConfig();
                String econ = "true";
                if(econ == getConfig().get("settings.econ")) {
                    EconMain.econ();
                    EconMain.onCommand();
                }
                else {
                    this.Logger.info(Color.TEAL + "[LIFE]" + " Econ is disabled. Change this in the config.yml File.");
                }
          }
     
    }

    ECONMAIN CLASS -
    Code:
    package org.westdover.econ;
     
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
     
    public class EconMain{
       
        public static void econ() {
           
        }
       
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
            Player Player = (Player) sender;
            if(commandLabel.equalsIgnoreCase("econ")) {
                Player.sendMessage("The Econ is enabled at the moment.");
            }
            return false;
        }
     
    }
    Can anyone tell me where im going wrong? Im getting a error on the EconMain.onCommand();

    Thanks,
    West
     
  2. Offline

    coldguy101

    The way you coded this goes completely against the way java works... You could make a static boolean that is changed depending on whether or not something is enabled or disabled, but you cant simply call a method like that, especially since it is not static, does not include the necessary data when you pass it, and literally would do nothing. Maybe youtube a tutorial for how to make a plugin?
     
  3. Offline

    Polaris29

    Code:
    EconMain.onCommand();
    //Your invocation provides zero parameters and onCommand() must take in four parameters
    onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { //Method
      // ...
    }
    
    Here are some of your problems:
    • Your invocation of the method onCommand() is missing about four parameters
    • You are trying to call a non-static method in a static way
    • You are casting sender to player without checking to see if the sender is an instanceof a Player
    • EconMain needs to implement CommandExecutor
    • getCommand("econ").setExecutor(new EconMain()); need to be used instead of trying to call onCommand() yourself
    • Two of your variables (Logger and Player) use UpperCamelCase, usually method and variable name should always use lowerCamelCase. If you don't use lowerCamelCase for variable and method names, people will hate you. Some exceptions for this are for enum values and constants which are sometimes in all caps
    I suggest you give this a read: http://wiki.bukkit.org/Plugin_Tutorial#Using_a_separate_CommandExecutor_class

    I assume something like this is what you want to do?: http://pastebin.com/n76U35Nr
     
    ferrybig likes this.
  4. You also comparing strings with ==, I recommend you get more experience with java before you start with the plugins
     
  5. I agree, but he's learning through experience, so telling him to use .equals() or .equalsignorecase() for comparing strings and explaining why may have been the better thing to do.
     
Thread Status:
Not open for further replies.

Share This Page