Stop Items Burning

Discussion in 'Spigot Plugin Development' started by Futurize, May 27, 2017.

  1. Is there a way to stop items from burning? I have tried this:
    Code (Text):
        @EventHandler
        public void onEntityDamage(EntityDamageEvent e) {
                Entity ent = e.getEntity();
                if (ent instanceof Item) {
                    if (e.getCause() == DamageCause.FIRE || e.getCause() == DamageCause.LAVA) {
                        e.setCancelled(true);
                    }
            }
        }
    But it does not work and have thought about cancelling item despawns but it would lag the server if they never despawn. Any help would be appreciated. Thanks!
     
  2. The event (I think) you'll have to use is the EntityCombustEvent. Basically the same implementation, but you'll just have to remove the event cause.
     
  3. Canceling item despawns won't stop them from burning, as TeeePeee said, "you'll have to use is the EntityCombustEvent."
     
  4. Still does not work :(.
     
  5. May we see your new code?
     
  6. Code (Text):
        @EventHandler
        public void onItemBurn(EntityCombustEvent e) {
                if (e.getEntity().getType() == EntityType.DROPPED_ITEM) {
                    e.setCancelled(true);
            }
        }
    Was unsure if getEntity() returned the entity that combusted or the entity that caused it.
     
  7. Do you get an error? Or does it simply not do anything? Are you sure your event listener is registered?
     
  8. The event is registered, no error messages.
     
  9. I'm actually looking into the source code right now and two things immediately pop out.

    1. Can you listen to item drop events and if they're items, set Entity#setFireProof(true)? This may not exist in the Bukkit API I'm not sure.
    2. The event seems to be EntityCombustByBlockEvent.
     
  10. WAS

    WAS

    Maybe try the provided
    Code (Java):
    e.getEntityType() == EntityType.DROPPED_ITEM
    Code (Java):
        @EventHandler(priority = EventPriority.LOWEST)
        public void onItemBurn(EntityCombustEvent e) {
                if (e.getEntityType() == EntityType.DROPPED_ITEM) {
                    e.setCancelled(true);
            }
        }
    Additionally, maybe try setting the burn duration to 0.
     
  11. Still does not work.
    Still does not work :(.
     
  12. don't believe it's possible using the bukkit api. maybe through NMS. you'll have to do more research as to what actually causes the item to 'die'
     
  13. Is there a way to just make the item invincible to everything but plugins that clear all drops when it spawns?
     
  14. WAS

    WAS

    It's odd, the code provided has been used in numerous plugins and available all over code creek. They don't tend to host snippets that never worked to begin with.

    Perhaps if you can detect the burning, or when they are a'burn, and just dupe all the items, kill them all, and re-spawn, hoping there is no more file. Or you can kill the fire, and re-spawn the list of items.

    Curious question, are the dropped items coming from some place, or just any dropped item?
     
    • Like Like x 1
  15. I am just dropping items out of my inventory and using flint and steel to burn them.
     
  16. I haven't had much on this other than a issue with a Camera packet, but check out when the Combust event is triggered, like printing a message in console. If it is triggered correctly make sure that the entity isn't null for some reason like the server has already removed it.