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?
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"); Why do this everytime? Make a variable on the top of the class an load it. But besides that, everything seems to be OK.
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
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.
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?
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 :/