This one event won't register no matter what...

Discussion in 'Plugin Development' started by supersonicsauce, May 2, 2014.

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

    supersonicsauce

    I'm trying to make a plugin that teleports a player to the spawn once they touch lava. Simple stuff, and I got it working back in 1.7.4. Now I have the same code and it won't work. Here the excerpt from my main class:


    Code:java
    1. public class Main extends JavaPlugin implements Listener{
    2. World world = Bukkit.getWorld("world");
    3. Location parkour = new Location(world,-71, 71, 57);
    4.  
    5.  
    6. public void onEnable(){
    7. getServer().getPluginManager().registerEvents(this, this);
    8. getLogger().info("SauceX version "+getDescription().getVersion()+" has been initialized successfully!");
    9.  
    10. }
    11.  
    12. public void onDisable(){
    13. getLogger().info("SauceX Version "+getDescription().getVersion()+" has been disabled.");
    14. }
    15.  
    16. @SuppressWarnings("deprecation")
    17. @EventHandler
    18. public void onLava(EntityDamageEvent event){
    19. getLogger().info("Damage event is registering");
    20. if(event.getEntity() instanceof Player){
    21. if(event.getCause()==DamageCause.LAVA){
    22.  
    23. getLogger().info("Player is being damaged by lava");
    24. Player player = (Player) event.getEntity();
    25.  
    26.  
    27. if (player.getLocation().getWorld().equals(world) && player.getLocation().distanceSquared(parkour) <= 600){
    28. getLogger().info("Player is within 600 units of spawn");
    29. player.teleport(parkour);
    30. player.setHealth(20);
    31. player.setFireTicks(0);
    32. }
    33. }
    34. }
    35.  
    36. }


    None of it works. It enables and everything, and I think I set up the event correctly, and I even have another event farther down that works perfectly, so it's nothing wrong with the on Enable().
     
  2. Offline

    Superckl1

    supersonicsauce

    What is deprecated in your onLava method? Do any of the logs show up (the "event is registering" one)?
     
  3. Offline

    supersonicsauce


    None of the loggers show up in the console, and the .setDamage() method is deprecated.
    Also, I realized that I had a duplicate EntityDamageEvent farther down, so I combined the two, hoping that would work. No dice :(
    EDIT: Here's the new code (lines 32 and down have the problem)
    Code:java
    1. public class Main extends JavaPlugin implements Listener{
    2. World world = Bukkit.getWorld("world");
    3. Location parkour = new Location(world, -71, 71, 57);
    4.  
    5.  
    6. public void onEnable(){
    7. getServer().getPluginManager().registerEvents(this, this);
    8. getLogger().info("SauceX version "+getDescription().getVersion()+" has been initialized successfully!");
    9.  
    10. }
    11.  
    12. public void onDisable(){
    13. getLogger().info("SauceX Version "+getDescription().getVersion()+" has been disabled.");
    14. }
    15.  
    16.  
    17. @SuppressWarnings("deprecation")
    18. @EventHandler
    19. public void onDamage(EntityDamageEvent event){
    20. if(event.getEntity() instanceof Player){
    21. Player player = (Player) event.getEntity();
    22. if(player.isSneaking()!=true){
    23. if(event.getCause() == DamageCause.FALL){
    24.  
    25. Location loc = player.getPlayer().getLocation();
    26. loc.setY(loc.getY() -1);
    27. int block = loc.getWorld().getBlockTypeIdAt(loc);
    28. if (block == 19){
    29. event.setDamage(0);
    30. Vector up = new Vector(0, 1, 0);
    31. player.setVelocity(up);
    32. }else if(event.getCause()== DamageCause.LAVA){{
    33. player.teleport(parkour);
    34. player.sendMessage("You fell!");
    35. }
    36.  
    37.  
    38. }
    39. }
    40. }
    41. }
    42. }
    43. }
    44.  
     
Thread Status:
Not open for further replies.

Share This Page