HELP

Discussion in 'Spigot Plugin Development' started by Unravel, May 15, 2016.

  1. Hello iv'e been trying to create plugins for SO long but when i finally learned it failed! :( please help here is the coding behind it as well as the yml: Coding for main plugin:
    package Test;

    import java.util.logging.Logger;

    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;

    public class Test extends JavaPlugin{
    public final Logger logger = Logger.getLogger("Minecraft");




    public void onEnable(){
    PluginDescriptionFile pdfFile = this.getDescription();
    this.logger.info(pdfFile.getName() + "Has been enabled!'");


    }


    public void onDisable(){
    PluginDescriptionFile pdffile = this.getDescription();
    this.logger.info(pdffile.getName() + "Has been disabled!");
    }
    public boolean onCommand(Command cmd, CommandSender sender, String label, String[] args){
    if(label.equalsIgnoreCase("Hi")){
    Player p = (Player) sender;
    p.sendMessage("Hi");
    }
    return true;}
    }




    YML:
    name: Testing
    description: My first plugin taught to me by Pokemonzr
    authour:xUnravel
    commands:
    Hi:
    description: sends a message of "hi" to the player
    version: 1.0
    main: me.xunravel.testing.Testingmain
     
  2. Use insert code to make this easier to read

    But I have a feeling its your package
     
    • Agree Agree x 1
  3. Register the command in the main class onEnable
     
    • Agree Agree x 1
  4. Also don't use label thats the alias of the command, use cmd.getName() instead it works for aliases as well.
     
  5. He doesn't need to as the class extends plugin
     
    • Informative Informative x 1
  6. He still needs to set the commands executor
     
  7. Your "Main:" in plugin.yml is different to package in the class extending javaplugin
     
    • Agree Agree x 1
  8. You are not putting your onEnable within your main class? I have a feeling you have mistaken the package name for the route directory to your actual main class.

    • Your class, which doesn't seem to be the main class according to the plugin YAML, is extending JavaPlugin
    • Your class, which doesn't seem to be the main class according to the plugin YAML, is utilizing main class methods (i.e #onEnable(), #onDisable())
    • You should cast Player to the CommandSender before checking the command arguments, name, or label, that way you can have more logical and savvy condition checks
    • You are not registering the command(s) on the plugin's activation, in this case, #onEnable()
    • You do not necessarily need to get a custom predefined logger. You can simply use Bukkit's implemented #getLogger() method
    • Unless you want to log custom debugging messages or other messages to the console, I don't see any reason to log the activation of the plugin to the console. This is already shown when the plugin is successfully enabled
    Java conventions are poorly used. You should try to have somewhat package/class related names to your project.

    However, considering many flaws in your provided code snippet, I would highly recommend viewing Bukkit's tutorials on command creating, plugin YAML, and basic plugin boot-up methods.

    http://wiki.bukkit.org/Plugin_Tutorial
     
    #8 ChefJava, May 15, 2016
    Last edited: May 15, 2016
    • Agree Agree x 2
  9. He does not need to do this. The command is inside the main class.
     
    • Informative Informative x 1
  10. Either use one class, or go learn how to use command executors.
    Code (Text):
    package me.BiastGaming.TestPlugin.Commands
    <imports here>

    public class hiCommand implements CommandExecutor {
    public boolean on command(CommandSender sender, Command cmd, String label, String[] args{
    sender.sendMessage("hi);
    return true;



    Main Class on enable

    getCommand("hi").setExecutor(new hiCommand();
    It may extend Executor not sure
     
    • You should follow Java coding conventions when making plugins as well. For example, using a package name "Test" doesn't follow. Instead, you should read about the correct conventions to follow, and use them here.
    • Don't use Minecraft's logger. Instead, if you need to use a Logger, use the one Bukkit provides for you using getLogger().
    • No need to broadcast to the console when your plugin is enabled and disabled, Bukkit does this for you.
    • Don't use the command label, instead check if the command name is equal to what you want.
    • Don't cast the sender to a player. If the player isn't a sender, it will throw an error (i.e. when the console executes the command).
    • You set your command executor/path to a completely different package name than your actual class.
    • Even if you did need the PluginDescriptionFile (in this case you don't), instead of creating the same variable twice, create an instance level variable.
    • DON'T WATCH THEBCBROZ

    For your info, your YML is also invalid.

    [​IMG]
     
    #11 GamerzKing, May 15, 2016
    Last edited: May 15, 2016
    • Agree Agree x 1
    • Funny Funny x 1
  11. You say you have been coding for "SO long" however you still can't follow simple Java conventions and created a plugin that tells a player "Hi". On a side note, please read the first thread in this forum that says "[READ ME] For everyone asking questions on here" as the thread name "HELP" doesn't do anyone any good.
     
    • Agree Agree x 1
  12. @Unravel Your main issue is your package. Allow me to explain.

    Your plugin.yml is looking for your main class. In this case, your main class name is Test
    Code (Text):
    public class Test extends JavaPlugin{
    For example, in my Plugin PlayerLock, this is what the complete package setup looks like.

    [​IMG]

    The package will break down into three parts + the main class.

    Here is what it correctly looks like inside my plugin.yml
    [​IMG]

    Once you set up your package and you write it into your yml file, you must make sure to add the Main class name in exactly or you will run into errors.


    Dude. If you are going to offer help, it least put some effort into it. I don't even know what you are trying to do. Don't make it more complicated then it already is.
     
  13. I don't get how that code is complicated but OK :)
     
  14. Why spoon feed him when there are already wikis such as this one that shows him exactly what to do, and saves you time.
     
    • There is no formatting.
    • The code literally is all over the place.
    • The type of command implementation is not what the author is trying to do, and is probably above his skill level at the current time.
    • You just throw a bunch of code together without explaining it. No one will learn that way.
     
  15. This is not spoon feeding. I did not give him any code, I showed him examples of how to do it. Ultimately, it is up to him to understand and implement it correctly.
     
    • Agree Agree x 1
  16. Ok thanks for all the help :D i will be sure to test out of your fixes on my coding and see if they work!
     
  17. Also i did get it to work i was watching a WAY outdated video on how to do this! thank you so much you guys!