Need help for a feed command

Discussion in 'Plugin Development' started by JaydonManders, May 8, 2015.

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

    JaydonManders

    So, I am making an essentials for my own server and I am trying to make a feed command.

    How is this possible?

    My first prediction was this:

    playerToFeed.SetHunger = 20.0

    Well, this did not work. playerToFeed is my variable name for the player which is about to be fed. Anyone have any ideas? Thanks!
     
  2. Offline

    JaydonManders

  3. Offline

    Drtro

    Make a command that sets the sender's food level to 20
     
  4. Offline

    killerzz1

    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
             Player p = (Player)sender;
    //Permissions here
    if(cmd.getName().equalsIgnoreCase("feed")){
            p.setFoodLevel(20);
            p.sendMessage(ChatColor.GREEN + "You were fed!");
        }
    }
    This is the code that i used when i made it for a server hope this helps :D
     
  5. @killerzz1
    1. Spoonfeeding
    2. This code wouldn't even compile
    3. Don't cast sender to Player before even knowing if it is a Player! It can be ConsoleCommandSender, too!
     
  6. Offline

    FloppehDeesk

    You should really check
    Code:java
    1. if (sender instanceof Player)
    before you cast it.
     
  7. Offline

    stormneo7

    OP already knows what he's doing. He just doesn't know what the constructor's method is called.
    It's not really considered spoon feeding if he's just giving away the method .setFoodLevel(int arg0)
     
  8. Offline

    nbrandwine

    [​IMG]
    Just make sure to cast your Player/Sender crap.
    I see why they said spoonfeeding, but I agree with both you and them.
     
Thread Status:
Not open for further replies.

Share This Page