RespawnEvent

Discussion in 'Plugin Development' started by TheFl4me, Mar 7, 2015.

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

    TheFl4me

    Im having a small problem with my respawnevent, basically whenever a player respawns the foodlevel is supossed to be 14, however its somehow not doing so.

    Code:
    package Listeners;
    
    import java.io.File;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.World;
    import org.bukkit.configuration.file.YamlConfiguration;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerRespawnEvent;
    
    public class RespawnListener implements Listener {
       
        @EventHandler
        public void onRespawn(PlayerRespawnEvent e) {
            Player p = e.getPlayer();
           
            p.setFoodLevel(14);
            p.setExp(0);
           
            File file = new File("plugins//KitPvP//spawn.yml");
            if(!file.exists()){
                return;
            }
            YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
            Location loc = p.getLocation();
            double x = cfg.getDouble("X");
            double y = cfg.getDouble("Y");
            double z = cfg.getDouble("Z");
            double yaw = cfg.getDouble("Yaw");
            double pitch = cfg.getDouble("Pitch");
            String worldname = cfg.getString("Worldname");
           
            World world = Bukkit.getWorld(worldname);
           
            loc.setX(x);
            loc.setY(y);
            loc.setZ(z);
            loc.setYaw((float) yaw);
            loc.setPitch((float) pitch);
            loc.setWorld(world);
           
            e.setRespawnLocation(loc);
        }
    }
    Could someone tell me what im missing here?
     
  2. Offline

    nuno1212sss

    1. File file = new File("plugins//KitPvP//spawn.yml");
    2. if(!file.exists()){
    3. return;
    4. }
    5. YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
    6. Location loc = p.getLocation();
    7. double x = cfg.getDouble("X");
    8. double y = cfg.getDouble("Y");
    9. double z = cfg.getDouble("Z");
    10. double yaw = cfg.getDouble("Yaw");
    11. double pitch = cfg.getDouble("Pitch");
    12. String worldname = cfg.getString("Worldname");
    13. Why do this everytime? Make a variable on the top of the class an load it.
    14. But besides that, everything seems to be OK.
     
  3. Offline

    TheFl4me

    Your missing the point my problem is not the respawn itself its the fact that the

    Code:
    p.setFoodLevel(14);
    p.setExp(0);
    is not kicking in. Whenever i respawn i have full foodbar
     
  4. Offline

    nuno1212sss

    @TheFl4me Is any other plugin running code to set the hunger bar to full?
     
  5. Offline

    TheFl4me

    The only other plugins i have installed are PermissionsEX and WorldEdit
     
  6. Offline

    Signatured

    Maybe try putting the p.setFoodLevel(14); in a runTaskLater scheduler and delay it by 2 ticks. This sometimes solves issues for me with the playerrespawn and playerjoin events.
     
  7. Offline

    TheFl4me

    i will do this but only as a last resort im not such a fan on schedulers if they are not 100% needed :/

    any other options?
     
  8. Offline

    teej107

    @TheFl4me Are you sure that the code is running? Did you register the event?
     
  9. Offline

    TheFl4me

    yes it is, because the respawn itself (the player gets tped to the indicated spawn) works fine
     
  10. Offline

    RROD

    Try cancelling the event. That has been said to work in the past.
     
  11. Offline

    TheFl4me

    you cannot cancel respawn event and even if it worked it would still break the the rest of my code + the way people said they use it in the past was that they bypass the death of the player but this i think is stupid since the player never dies and would break half of my plugin :/
     
  12. Offline

    Konato_K

    @TheFl4me Try setting the food 1 tick later.
     
  13. Offline

    TheFl4me

     
  14. Offline

    TheFl4me

  15. Offline

    Signatured

    Have you at least tried it to see if it works? Looks like you need a last resort :X
     
  16. Offline

    TheFl4me

    Nvm, i "fixed" it by only setting the players foodlevel when he chooses a kit.
     
Thread Status:
Not open for further replies.

Share This Page