Solved PlayerRespawnEvent not working

Discussion in 'Plugin Development' started by mattmcmullen1, Jul 23, 2013.

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

    mattmcmullen1

    I'm making a plugin that when a player dies, their health is set to 10 and their food level is set to 10. Heres my code:
    Code:java
    1. package me.mattmcmullen1.notworthit;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.command.Command;
    7. import org.bukkit.command.CommandSender;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.event.EventHandler;
    10. import org.bukkit.event.player.PlayerRespawnEvent;
    11. import org.bukkit.plugin.PluginDescriptionFile;
    12. import org.bukkit.plugin.java.JavaPlugin;
    13.  
    14. public class notworthit extends JavaPlugin{
    15. public final Logger logger = Logger.getLogger("Minecraft");
    16. public static notworthit plugin;
    17.  
    18. public void onDisable(){
    19. PluginDescriptionFile pdfFile = this.getDescription();
    20. this.logger.info(pdfFile.getName() + " NotWorthIt has been disabled");
    21. }
    22.  
    23. public void onEnable(){
    24. PluginDescriptionFile pdfFile = this.getDescription();
    25. this.logger.info(pdfFile.getName() + " Version " + pdfFile.getVersion() + " has been enabled");
    26. }
    27.  
    28. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
    29. return false;
    30. }
    31. @EventHandler
    32. public void onPlayerRespawn(PlayerRespawnEvent event){
    33. Player player = event.getPlayer();
    34. player.setHealth(10.0);
    35. player.setFoodLevel(10);
    36. player.sendMessage(ChatColor.RED + "You have died and respawned with half health.");
    37. }
    38.  
    39. }


    The public void onPlayerRespawn(PlayerRespawnEvent event){ isn't working possibly?
    I'm new at this, so fancy names for things won't click in my head.
    Thanks for the help!
     
  2. Offline

    BajanAmerican

    1. public class notworthit extends JavaPlugin implements Listener{
     
  3. Offline

    mattmcmullen1

    Still doesn't work

    Might I add, the message "You have died and respawned with half health" doesn't get displayed.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  4. Offline

    mattmcmullen1

    I've read it and it doesn't make sense, to me. How would I add time to the event?
     
  5. You couldn't possibly have read it all and tried it out in 9 minutes...
    a delayed task is something that makes you able to wait x amount of ticks before it does what you want.
     
  6. Offline

    mattmcmullen1

    Like I said, I'm new at this. I don't even know how to extend to JavaPlugin and BukkitRunnable

    So how could I add like 1 tick to the event? Anyone?

    EDIT: Again, I'm new with coding and such. So, like basic explanations would be greatly appreciated as well!

    Bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  7. Offline

    Adriano3ds

    Try add this in onEnable():
    Code:java
    1. Bukkit.getPluginManager().registerEvents(this, this);


    and add:
    Code:java
    1.  
    2. public class notworthit extends JavaPlugin implements Listener
    3.  
     
  8. Offline

    mattmcmullen1

    Okay, so with the help from Compressions, I added a delay task to the event. Still doesn't do anything.
    There aren't any errors. So here's the new code:
    Code:java
    1. package me.mattmcmullen1.notworthit;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.command.Command;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.event.EventHandler;
    11. import org.bukkit.event.Listener;
    12. import org.bukkit.event.player.PlayerRespawnEvent;
    13. import org.bukkit.plugin.PluginDescriptionFile;
    14. import org.bukkit.plugin.java.JavaPlugin;
    15. import org.bukkit.scheduler.BukkitRunnable;
    16.  
    17. public class notworthit extends JavaPlugin implements Listener{
    18. public final Logger logger = Logger.getLogger("Minecraft");
    19. public static notworthit plugin;
    20.  
    21. public void onDisable(){
    22. PluginDescriptionFile pdfFile = this.getDescription();
    23. this.logger.info(pdfFile.getName() + " NotWorthIt has been disabled");
    24. }
    25.  
    26. public void onEnable(){
    27. this.getServer().getPluginManager().registerEvents(this, this);
    28. PluginDescriptionFile pdfFile = this.getDescription();
    29. this.logger.info(pdfFile.getName() + " Version " + pdfFile.getVersion() + " has been enabled");
    30. }
    31.  
    32. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
    33. return false;
    34. }
    35. @EventHandler
    36. public void onPlayerRespawn(PlayerRespawnEvent event){
    37. final Player player = event.getPlayer();
    38. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new BukkitRunnable(){
    39. public void run(){
    40. player.setHealth(10.0);
    41. player.setFoodLevel(10);
    42. player.sendMessage(ChatColor.RED + "You have died and respawned with half health.");
    43. }
    44. }, 20);
    45. }
    46. }
     
  9. Offline

    wreed12345

    Just so you know standard java code writing states that class names begin with an uppercase letter.
     
  10. Offline

    mattmcmullen1

    Ok, but that's not the problem is it?

    SOLVED! I'm so stupid.
    I was exporting it to a different plugin I was working on :(
    So, READ EVERY BOX THAT POPS UP!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  11. Offline

    duker02


    :eek:
     
Thread Status:
Not open for further replies.

Share This Page