I need Some Help With My First Plugin

Discussion in 'Plugin Development' started by killerzz1, Apr 18, 2014.

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

    killerzz1

    Hi there i have just started Java so i started to make a small plugin so if a player done /test it would say "You ran the test command well done" but when i exported the plugin and done a reload the plugin was not there but it was in the plugins folder

    Here is my code and yes i do have a plugin.yml

    package me.killerzz1.test;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.plugin.java.JavaPlugin;

    public class test extends JavaPlugin{

    public void onEnable(){
    Bukkit.getServer().getLogger().info("Test Was Enabled");
    }

    public void onDisable(){
    Bukkit.getServer().getLogger().info("Test Was Disnabled");
    }

    public boolean onCommand(CommandSender sender, Command cmd, String commandLable, String[] args) {
    if (cmd.getName().equalsIgnoreCase("test")) {
    sender.sendMessage(ChatColor.DARK_PURPLE + "You Ran The Test Command WellDone");
    }
    return true;
    }
    }
    Here is my plugin.yml
    name: Test
    version: 0.1
    main: me.killerzz1.test.test
    author: killerzz1
    Description: A test plugin
    commands:
    test:
    usage: /<command>
    description: A test command!
     
  2. Offline

    CarPet

    Your plugin.yml is wrong, set mine like:

    Code:
    name: Test
    version: 0.1
    main: me.killerzz1.test.test
    Description: A test plugin
    commands:
      test:
        description: plugin test command
     
  3. Offline

    xTigerRebornx

    killerzz1 Are there any errors in the console?
    CarPet His plugin.yml looks fine (as the only required things are name, version, and main), unless he didn't space it properly, but I believe the spacing in the OP is just the forums being derpy as usual when it comes to editing w/ spacing and whatnot.
     
  4. Offline

    CarPet

    xTigerRebornx I don't know but when I changed his yml it worked correctly... Maybe I missed something else though
     
  5. Offline

    xMrPoi

    You have to implement CommandExecutor.

    Next to your "extends JavaPlugin", put
    Code:java
    1. implements CommandExecutor
     
  6. Offline

    chris8787878787

    I see a few errors but let's go from top to bottom. You dont need the ondisable stuff just do this.
    Code:
    public void onEnable(){
     
    }
    You also made a spelling error.
    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String commandLable, String[] args) {
    You spelt commandLabel wrong. And change it to String label not String commandLabel. So it should look like this;
    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    In the next line after your boolean, Declare Player and sender by doing this.
    Code:
    Player p = (Player) sender;
    Then, change sender.Sendmessage to this;
    Code:
    p.sendMessage(Insert string here)
    And finally change return true to return false. If that does not work, put return true under return false like so;
    Code:
    }
    return false;
    }
    return true;
    }
    }
    So in the end your code should look like this.
    Code:
    public class test extends JavaPlugin{
     
    public void onEnable(){
    Bukkit.getServer().getLogger().info("Test Was Enabled");
    }
     
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    Player p = (Player) sender;
    if (cmd.getName().equalsIgnoreCase("test")) {
    p.sendMessage(ChatColor.DARK_PURPLE + "You Ran The Test Command Well Done");
    }
    return false;
    }
    }
    And ps, your plugin.yml has way too much uneeded fluff. Use this;
    Code:
    name: Test
    version: 0.1
    main: me.killerzz1.test.test
    commands:
    test:
    usage: /<command>
    description: Outputs a test command
    Ik TLDR but I hope I helped in someway, I know how it feels to start out. It's pretty hard.
     
  7. Offline

    minoneer

    No, you don't have to implement CommandExecutor. JavaPlugin, to be exact a super class of JavaPlugin, already implements CommandExecutor. So there is no point in doing it again.
     
  8. Offline

    xTigerRebornx

    chris8787878787 Most of the things you've suggested are incorrect suggestions. First off, the spelling of the args doesn't matter. 2nd, you are simply inferring that he wants this command to be Player only, and then suggesting that he automatically assume that the sender is a Player (when it can be other things).
    While the statements about him not requiring his own debug messages, allowing him to remove onEnable and onDisable, are true, giving help that isn't correct will simply cause more problems.
    Both his code and his plugin.yml (if it is spaced properly) appear to be fine, but since he has yet to respond, we can't tell what the problem is.
     
Thread Status:
Not open for further replies.

Share This Page