Stop item break on cactus

Discussion in 'Plugin Development' started by keeper317, Oct 7, 2014.

Thread Status:
Not open for further replies.
  1. BillyBobJoe168 "if entity isn't an instance of Player, and entity isn't an instance of Item, end the method" or in other words "if entity isn't a player or an item, end the method" :)
     
  2. Offline

    keeper317

    None of this helps me thou.
     
  3. Offline

    NonameSL

    AdamQpzm I don't understand why you quoted me when fixing BillyBobJoe168...
    He is wrong, but so are you. It is an 'and' statement -
    If the entity is not a player and the entity is not an item don't continue the code
    and not
    If the entity is a player or the entity is an item, do continue the code.
    These two are the same but the code contains the first one.
     
  4. NonameSL I don't doubt the fact that the if statement contains an and, I was simply making the point that it's not a "if the entity is a player and an item". And I quoted you to point out could have been checking for fall damage for a player, not fall damage for an item.
     
  5. Offline

    keeper317

    This is great that people are starting to understand what I already changed, but you two are arguing about the same side of the answer and it still doesnt help me find a solution.
     
  6. Offline

    teej107

    keeper317 Have you tried writing code to my pseudo code? Also, debug everything. Print out the cause, the material, everything you need to check for to make sure you are making the correct check.
     
  7. Offline

    keeper317

    My exact code is as follows:
    Code:java
    1. import org.bukkit.Bukkit;
    2. import org.bukkit.entity.Item;
    3. import org.bukkit.entity.Player;
    4. import org.bukkit.event.EventHandler;
    5. import org.bukkit.event.Listener;
    6. import org.bukkit.event.entity.EntityDamageEvent;
    7. import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
    8.  
    9. public class FallDamage implements Listener
    10. {
    11. @EventHandler
    12. public void onFallDamage(EntityDamageEvent e)
    13. {
    14. if((e.getEntity() instanceof Player) && e.getCause() == DamageCause.FALL)
    15. e.setCancelled(true);
    16. else if(e.getEntity() instanceof Item && (e.getCause() == DamageCause.FIRE || e.getCause() == DamageCause.FIRE_TICK || e.getCause() == DamageCause.CONTACT))
    17. e.setCancelled(true);
    18. else
    19. return;
    20. Bukkit.broadcastMessage("Entity is: " + e.getEntityType().toString());
    21. }
    22. }

    This is not working and says nothing about an entity taking damage when i drop an item on a cactus or into fire
     
  8. Offline

    teej107

    keeper317 That return; is blocking the broadcastMessage() method. And there is no need to put return; at the end of a method since the method ends naturally when all the code inside is executed.
    Did you register your event? Put in debug messages printing out everything you need to know. e.getCause(), getEntity, etc.
     
  9. Offline

    keeper317

    Without the return it still doesnt work and does not recognize the item as an entity taking damage
     
  10. Offline

    teej107

    keeper317
     
  11. Offline

    keeper317

    I have a check for the damage cause and the entity damaged. Neither thing prints because it is not calling that method. When a player takes damage on cactus it says player is the entity and was damaged by contact
     
  12. Offline

    teej107

  13. Offline

    keeper317


    Code:java
    1. @EventHandler
    2. public void onFallDamage(EntityDamageEvent e)
    3. {
    4. if((e.getEntity() instanceof Player) && e.getCause() == DamageCause.FALL)
    5. e.setCancelled(true);
    6. else if(e.getEntity() instanceof Item && (e.getCause() == DamageCause.FIRE || e.getCause() == DamageCause.FIRE_TICK || e.getCause() == DamageCause.CONTACT))
    7. e.setCancelled(true);
    8. Bukkit.broadcastMessage("Entity is: " + e.getEntityType().toString() + "\nEntity Damage: " + e.getCause().toString());
    9. }
     
  14. Offline

    teej107

    keeper317 So this
    Code:java
    1. Bukkit.broadcastMessage("Entity is: " + e.getEntityType().toString() + "\nEntity Damage: " + e.getCause().toString());
    isn't printing?
     
  15. Offline

    keeper317

    yea
     
  16. Offline

    teej107

    keeper317 What are you trying to do to fire the event? Are you sure you registered the event?
     
  17. Offline

    keeper317

    Yes i register the event. Fall Damage works just fine. The only problem is item. I test it by dropping an item on a cactus.
     
  18. Offline

    teej107

    keeper317 That broadcast message should go off since you don't have it inside any if statement.
     
  19. Offline

    keeper317

    The only reason it wouldnt be firing is the method isnt being called.
     
  20. Offline

    NonameSL

    keeper317 How about trying to use .equals() with the damagecauses? Try that.
    BTW, try to print in the begginging of the method something to the console or broadcast a message just to be 100% sure that the event does indeed fire.
     
  21. Offline

    keeper317

    I will try it but fall damage works with == so the rest should too and the broadcast that exist already will fire no matter where in that method it is so long as the method fires. nothing will break out.
     
  22. Offline

    keeper317

    It made no difference and the event doesnt even fire.
     
  23. Offline

    teej107

  24. Offline

    keeper317

    @teej107 So i still don't have this set up properly. Any chance you know how to do it now?
     
  25. Offline

    teej107

    @keeper317 Well I don't have it set up either. Is there a chance that you know how?
     
  26. Offline

    keeper317

    So i think i found a work around but i need to get the item damage value when an item spawns. I already have my item spawn event set up properly and it is set up to only see wool.
    Any idea how to get these values
    edit: so i got the data correctly but i need to spawn the associated item at a specific location
     
    Last edited: Jan 7, 2015
  27. Offline

    teej107

  28. Offline

    keeper317

Thread Status:
Not open for further replies.

Share This Page