Respawn with X amount of hunger.

Discussion in 'Archived: Plugin Requests' started by jordan12345, Sep 13, 2012.

  1. Offline

    jordan12345

    I really hate it when players suicide and respawn with full hunger.
    Can anyone make it so that if a player dies, they respawn with a configurable amount of hunger?
     
  2. Offline

    Woobie

    I could do this, but i've never done anything with configs..
    What do you want the hunger level to be by default when player respawns?
     
  3. Offline

    jordan12345

    I mean, if you don't want to add a config, that's fine.
    I want them to have 5 meat bars upon death and respawn.
     
  4. Offline

    Woobie

    Okay, im a bit busy at the moment, if anyone havent made this when i wake up, then ill do this.
    Do you have any suggestions for a name?
     
  5. Offline

    jordan12345

    Let's see....
    Let's call it
    "HungerOndeath"
     
  6. Offline

    puyttre

    Woobie
    jordan12345
    I can probably do this within a few hours. What do you want to be in the config? Something like:
    respawn:
    hunger: 8
    health: 8
    ?
     
    chasechocolate likes this.
  7. Offline

    jordan12345

    Remove the " health " part.
    I only want the hunger.
     
  8. Offline

    Woobie

    If you do it, could i see the source code? I want to see what code you used for the config.
     
  9. Offline

    puyttre

    Sure! I'll add comments to help you.
     
    Woobie likes this.
  10. Offline

    JjPwN1

    This is be teh simplez

    Code:
        public void onEnable(){
            getLogger().info("version v" + this.getDescription().getVersion() + " is enabled!");
            getServer().getPluginManager().registerEvents(this, this);
            getConfig().options().copyDefaults(true);
            saveConfig();
        }
        public void onDisable(){
            getLogger().info("version v" + this.getDescription().getVersion() + " is disabled!");
        }
        public void onRespawn(PlayerRespawnEvent event){
            Player player = event.getPlayer();
            if(player.isOp() || player.hasPermission("hungerrespawn.bypass")){
               
            }else {
                player.setFoodLevel(getConfig().getInt("hunger_on_respawn"));
            }
        }
    }
     
  11. Offline

    jordan12345

    I don't even know the basics of plugins, so...
    Care to make the .Jar? :D
     
  12. Offline

    Woobie

    What would the config look like then?
     
  13. Offline

    JjPwN1

    Woobie
    You'd make a new file in the Java Project named "config.yml", and put this in it:

    Code:
    # Woobie's HungerRespawn v0.1
    hunger_on_respawn: 5
     
    Woobie likes this.
  14. Offline

    jordan12345

    :D
    I always wanted to learn how to make a plugin, but the ish never made sense to me.
    .-.
    >.<
    Jjpwn, do you haz skype?
     
  15. Offline

    Woobie

    I know how to make and load the config, but i never knew how to use it :D
    Thanks!
     
  16. Offline

    jordan12345

    Guys, I still need the plugin, unless anyone wants to teach me how to make one.
     
  17. Offline

    puyttre

    Im close to done >.< you can't make a plugin in 2 seconds
     
  18. Offline

    Woobie

    :D
    As i said, if anyone havent made this until i wake up, ill do this.

    It was actually 30 minutes.. I could've done this in few minutes, except the config :D

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

    jordan12345

    puyttre, can you teach me how to make a plugin later? :p
     
  20. Offline

    Woobie

    First of all, download Eclipse SDK (Classic)
     
  21. Offline

    jordan12345

    I have already downloaded it. :p
     
  22. Offline

    Woobie

    Well do you know anything about coding, or do i have to tell every single thing? :p
     
  23. Offline

    puyttre

    Just about to test it. Does anyone know what default max hunger is?
     
  24. Offline

    PogoStick29

    I believe that the hunger bar is from 1-20 where 2 = 1 chicken leg XD
    If that doesn't work, I can just write one for you in like 5 mins.
     
  25. Offline

    puyttre

    I can't get mine to work. Do you mind doing this for him?
    Ill give you my Listener:
    Code:java
    1. import org.bukkit.entity.Player;
    2. import org.bukkit.event.Listener;
    3. import org.bukkit.event.player.PlayerRespawnEvent;
    4.  
    5. public class RespawnListener implements Listener {
    6.  
    7. // Saves our HealthOnDeath.java to a variable that we can use to call methods.
    8. HealthOnDeath hod;
    9.  
    10. public void onRespawn(PlayerRespawnEvent event){
    11. // Gets the player that triggered the the PlayerRespawnEvent
    12. Player player = event.getPlayer();
    13. //If Player is an op or has permission to ignore this event, do nothing.
    14. if(player.isOp() || player.hasPermission("healthonrespawn.bypass")){
    15. // Don't do anything! Minecraft will take care of it :)
    16. }else{ // otherwise set the hunger and health to whatever!
    17. player.setFoodLevel(hod.getHunger());
    18. player.setHealth(hod.getHealth());
    19. }
    20. }
    21.  
    22. }
    23.  


    Hold on it works now. Give me another minute

    To all devs:
    I don't know why it doesn't work. Maybe you can fix it:
    HealthOnDeath.java
    Code:java
    1. import org.bukkit.plugin.PluginDescriptionFile;
    2. import org.bukkit.plugin.PluginManager;
    3. import org.bukkit.plugin.java.JavaPlugin;
    4.  
    5. public class HealthOnDeath extends JavaPlugin {
    6.  
    7. public RespawnListener respawn = new RespawnListener();
    8.  
    9.  
    10. @Override
    11. public void onEnable(){
    12. // Save the config inside the .jar
    13. this.saveDefaultConfig();
    14.  
    15. // Saving PluginManager and PDF to variables.
    16. PluginManager pm = getServer().getPluginManager();
    17. PluginDescriptionFile pdffile = this.getDescription();
    18.  
    19. // Calls log() method below.
    20. log("HealthOnDeath successfully enabled.");
    21. // Resgistering events.
    22. pm.registerEvents(this.respawn, this);
    23. }
    24.  
    25.  
    26.  
    27. public void log(String x){
    28. getServer().getLogger().info(x);
    29. }
    30.  
    31.  
    32.  
    33.  
    34. public int getHealth(){
    35. int health = getConfig().getInt("health");
    36. return health;
    37. }
    38. public int getHunger(){
    39. int hunger = getConfig().getInt("hunger");
    40. return hunger;
    41. }
    42.  
    43.  
    44. }

    RespawnListener.java
    Code:java
    1. import org.bukkit.entity.Player;
    2. import org.bukkit.event.Listener;
    3. import org.bukkit.event.player.PlayerRespawnEvent;
    4.  
    5. public class RespawnListener implements Listener {
    6.  
    7. // Saves our HealthOnDeath.java to a variable that we can use to call methods.
    8. HealthOnDeath hod;
    9.  
    10. public void onRespawn(PlayerRespawnEvent event){
    11. // Gets the player that triggered the the PlayerRespawnEvent
    12. Player player = event.getPlayer();
    13. //If Player is an op or has permission to ignore this event, do nothing.
    14. if(player.isOp() || player.hasPermission("healthonrespawn.bypass")){
    15. // Don't do anything! Minecraft will take care of it :)
    16. }else{ // otherwise set the hunger and health to whatever!
    17. player.setFoodLevel(hod.getHunger());
    18. player.setHealth(hod.getHealth());
    19. }
    20. }
    21.  
    22. }
    23.  

    config.yml
    Code:
    health: 10
    hunger: 10
    
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
  26. Offline

    ConanEdogawa

    xD, you got me good on your signature, i thought i like it and my mom like it and my dad like your post...i was clicking it and keep clicking it until i realized its just a sig

    hod variable in the listener class is not initialized

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
    chasechocolate and puyttre like this.
  27. Offline

    jordan12345

    Guis, it's been one hour. D:
    Anyday now.
    .-.
     
  28. Offline

    puyttre

    How do I initialize it without doing
    HealthOnDeath hod = new HealthOnDeath();
    Doing that returns a large error and the plugin doesn't work after that.

    I really don't even feel like releasing this plugin to you after seeing this but I'm a kind person, so I probably will.

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

    ConanEdogawa

    on your main class, replace 'public RespawnListener respawn = new RespawnListener();' to 'public RespawnListener respawn = new RespawnListener(this);'

    then make a new constructor in the listeners class with the parameter (HealthOnDeath hod)
    inside, put ' this.hod = hod'
     
  30. Offline

    Woobie

    Lol some people might wait days for their plugin to be done.
    If no one doesnt do this, then i will (i hope) :3
     

Share This Page