Set hunger level

Discussion in 'Archived: Plugin Requests' started by jeffro1001, Nov 9, 2012.

  1. Offline

    jeffro1001

    Hello Bukkit community.

    I'm looking for a way to be able to set the hunger level of my players.

    I've spent the better part of the evening trying to find the Bukkit command to set hunger level but I haven't had any luck.

    Is there a server command to set someone's hunger level? Or perhaps an addon out there somewhere that will do it?

    I wan't to make my players starve on command!

    Hopefully someone can help me out.
    Thanks.
     
  2. Offline

    william9518

    this is, by far, the easiest to make plugin i have seen in the plugin requests.
    Code:
    @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if(cmd.getName().equalsIgnoreCase("starve")){
                Player player = (Player)sender;
                Player target = (Bukkit.getServer().getPlayer(args[0]));
                target.setExhaustion(0);
                return true;
            }
            return false;
        }
    Do I have to make a plugin for this or can you copy paste this?
     
  3. Offline

    jacklin213

    I'm sure he wants to be able to set the hunger value to what he wants, and u should pass an argue ment check for that. You made the sender a player but that will return a NPE because u didn't do a
    If (sender instanceof player)
     
  4. Offline

    jeffro1001

    Hi William.
    I can copy / paste easily enough, except that I have no idea where I would paste it.
    I have variable triggers running, so would it just be a simple matter of creating a script file and calling it from a trigger?
     
  5. Offline

    jacklin213

    ive done the whole plugin for u. Heres the link: https://www.dropbox.com/s/zwxh2h613fzx6ft/HungerCmd.jar

    HOW TO USE:
    Permissions:
    - hungercmd.use //allows usage of command
    Commands:
    /hungercmd [Target player] [Hungerlevel]
    you can use /hc as well

    Hunger level is between 1-10 as you c on the hunger bar, if you want something like 9.5 then type that
     
  6. Offline

    jeffro1001

    awesome thanks
     
  7. Offline

    william9518

    how did you manage to get the 2nd arg without using a cast on the player? i decompiled ur plugin soz im not using it just seeing the code
     
  8. Offline

    jacklin213

    All good and what do u mean without using a cast on the player? I hope the plugin works

    Does it work?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016
  9. Offline

    jeffro1001

    I haven't had a chance to install it yet.
    I'll be testing it out later today and I'll let you know.

    It seems to work fine.
    One thing I've noticed is if I set my hunger to 10 it will return:
    You have set CraftPlayer{name=jeffro1001}'s hunger level to 20

    The return seems to be double what it was set at.

    The food bar seems to work properly though.
    Im guessing that there are actually 20 levels of hunger ( represented by 10 chicken legs )

    Another thing, I can set the level to above 10, but I'm not really sure if it has any impact ( like if the hunger bar will remain full longer than normal if I set it really high. I haven't tested that yet.

    It would be nice to be able to disable the return message, since I'll be using the addon in a challenge dungeon, where the command will be executed via a VT walk trigger.
    With the return message my players will be wondering what it means, instead of them just noticing ( or not noticing ) that they are now starving.

    It does exactly what I need it to do though, so awesome job.

    Thanks a ton.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016
  10. Offline

    jacklin213

    Whoops it's ment to print out the value u type XD and yeh food levels are count to 20 . Anyway I'll add a config so u can disable the message when I get back home
     
  11. Offline

    william9518

    i mean how did you get an int for the type player? (args[1])
     
  12. Offline

    jacklin213

    Ah you miss under standing , in programing everything starts at 0, so args[0] is the player where as args[1] is the food level. This goes for all programing languages like c++, java etc.
     
  13. Offline

    Lactem

    In MySQL and other databases, things actually do start at one.
     

Share This Page