My First Bukkit Plugin_Bug :(

Discussion in 'Plugin Development' started by SkyGlue, Dec 13, 2014.

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

    SkyGlue

    Hi i am creating my first plugin. I have done the code but everytime i type it in minecraft, Minecraft says"An internal error occured while attempting to perform this command". However in the cmd it says "The method getname() is undefined for the type Player". This is my code... ... Can someone help me?

    package me.SkyGlue;

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

    public class MyFirstPlugin extends JavaPlugin {

    @Override
    public void onEnable() {
    getLogger().info("This Option Has Been Enabled Young One!");
    }

    @Override
    public void onDisable() {

    }


    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {

    if (cmd.getName().equalsIgnoreCase("hello") && sender instanceof Player) {

    Player player = (Player) sender;

    Player.sendMessage("Hello, " + Player.getname() + "!");

    return true;

    }

    return false;

    }

    }
     
  2. Offline

    Gingerbreadman

    @SkyGlue the problem is Player, you declared it as "player" but you used Player.class
    You will have to change Player.sendMessage("Hello, " + Player.getname() + "!");
    to
    player.sendMessage("Hello, " + player.getName() + "!");
     
  3. Offline

    Tehmaker

    @SkyGlue
    Everything in java is case sensitive, so you have to make sure that you aren't using a class instead of your variable, like gingerbreadman pointed out.

    There is also a "insert code" button in the text editor on this website, so you can post your code and it will be somewhat formatted.
     
  4. Offline

    SkyGlue

    Thanks @Gingerbreadman @Tehmaker Thanks for the help

    @Gingerbreadman @Tehmaker tHanks but im getting this error now...
    Cannot make a static reference to the non-static method sendMessage(String) from the type CommandSender
    Could someone help me please???

    EDIT by Timtower: merged post
     
    Last edited by a moderator: Dec 13, 2014
  5. Online

    timtower Administrator Administrator Moderator

    @SkyGlue That means that you are using the class name instead of the variable name.
     
  6. Offline

    SkyGlue

  7. Online

    timtower Administrator Administrator Moderator

    Jaaakee224 likes this.
  8. Offline

    SkyGlue

  9. Online

    timtower Administrator Administrator Moderator

    @SkyGlue Make sure to put it in code tags: [code] < your code here > [/code]
     
  10. Offline

    SkyGlue

  11. Online

    timtower Administrator Administrator Moderator

    @SkyGlue
    Code:
    Player.sendMessage ("Hello, " + player.getName() + "!");
    You are using the uppercase Player here, while that is the class, not the player object that you are using in player.getName()
     
  12. Offline

    SkyGlue

  13. Offline

    ChipDev

    @SkyGlue
    Instead of using Player.class, use your variable for your player:
    Code:
    Player variable = yourplayer;
    variable.sendMessage("Yay!");
    not using Player.sendMessage, or else it would come up with Player.(class)
     
  14. Offline

    es359

    Learn how to use java first. It will make your life much easier if you actually know what you are doing.
     
  15. Offline

    Gingerbreadman

  16. Offline

    WampyCakes

    @SkyGlue Just use this:
    Code:
    package me.SkyGlue;
    
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class MyFirstPlugin extends JavaPlugin {
    
    public void onEnable() {
    getLogger().info("This Option Has Been Enabled Young One!");
    }
    
    public void onDisable() {
    
    }
    
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    
    if (commandLabel.equalsIgnoreCase("hello") && sender instanceof Player) {
    
    Player player = (Player) sender;
    
    player.sendMessage("Hello, " + player.getname() + "!");
    }
    return false;
    }
    
    }
    
    
    I didn't test it, but it should work!
     
  17. Offline

    SkyGlue

    Thank You All
     
  18. Offline

    Jaaakee224

    @WampyCakes
    Why did you spoonfeed code...

    Problem has probably already been taken care of. The reply was not needed.
     
  19. Offline

    Tommy Raids

  20. Offline

    Dragonphase

    @SkyGlue

    For your first plugin, you seem to be following coding standards better than most. The only thing I see that could be improved on is the removal of the plugin log on enable, as Bukkit already displays a message for each plugin once it is enabled.

    If you need additional help regarding plugin development, check out this thread.
     
  21. Offline

    WampyCakes

    Are you questioning me helping? ,_,
     
  22. Offline

    thekillamon

    Your issue is that you casted Player to player and you used Player.getname where as you need to do player.getName
     
  23. Offline

    mariusvnh

    player.getName()
    warning N
     
  24. Offline

    Jaaakee224

    @WampyCakes
    They have already been helped. I don't see why you needed to restate the problem again.

    Same for @thekillamon.

    First response should've just ended the thread.
     
Thread Status:
Not open for further replies.

Share This Page