Putting out fire

Discussion in 'Spigot Plugin Development' started by RandomRobinnnn, May 16, 2016.

  1. Hello everyone!

    I've been kinda screwing around with plugin development today, and i strumbled upon a problem I can't seem to solve myself:

    I need to extinguish a player I can't seem to do this. Maybe I'm doing something wrong. All i know is that it's not working. I've looked around on google for a bit, and i just find tons of answers saying we need to use setFireTicks(0). I'm using this, but it's not doing anything as far as I can see...

    Code:
    Code (Text):
    @EventHandler
        public void onPlayerDamage(EntityDamageEvent e){
            if (e.getEntity() instanceof Player){
                Player p = (Player) e.getEntity();
                if (p.getHealth() < e.getDamage()){
                    p.teleport(p.getWorld().getSpawnLocation());
                    p.setFireTicks(0);
                    p.setHealth(p.getMaxHealth());
                    p.setFoodLevel(20);
                }
            }
        }
    Any help is appriciated.

    Thanks in advance!

    - RandomRobinnnn
     
  2. register ur events.
     
  3. if (p.getHealth() < e.getDamage()) makes no sense.
    Check your logic - this will not be triggered reliably. Try death event instead, and cancel the event?
     
  4. Code (Text):
    public void registerEvents(){
            PluginManager pm = getServer().getPluginManager();
            pm.registerEvents(new OnPlayerDamage(this), this);
        }
    You mean like this in the Main class?

    It makes sense for me (Even though i changed it to <=). You can not cancle a death event. What I'm doing is canceling the damage that would've killed the player, and do all that other stuff like teleporting it to spawn.
     
  5. And you were correct, It wasn't reliable. I'm still doing tests at the moment, I keep getting "Killed" and teleported back to spawn. It used to actually kill me every once in a while. That's when i figured out < had to be <= :D
     
  6. Registering Events goes in the onEnable().
     
  7. Yeah, i know...
    Code (Text):
    registerEvents();
    That's in the enable. Works as well, and I find this more organized.

    Anyway... The event is registered. Everything works, apart from the extinguish part. I do get teleported, healed, and all that stuff.
     
  8. Are you trying to respawn players before they actually die?

    Guessing because youre teleporting, healing, removing fire and setting hunger..
     
    #9 aaron1998ish, May 17, 2016
    Last edited: May 17, 2016
  9. EntityCombustEvent

    if (entity instanceof Player) {
    event.setCancelled(true);
    }
     
  10. Yup. That's what I'm trying to achieve.

    Thanks! Finally a usefull reply ;3. Ill look into it when I'm home.
     
  11. No problem.
     
  12. Isnt there a player.spigot().respawn();
    Does all the work for you.
     
    • Agree Agree x 1
  13. Appearently there is... That would've saved me loads of time... Unfortunately, this does not put out the fire. I'm not sure why, because in my opinion that doesn't really make sense, but eitherway, this is not a solution. Thanks for pointing it out though! Also a thing to note is that when you use player.spigot().respawn(); it gives this small "loading" screen. Just a head up ;3

    I will now try out this solution. Hopefully I'll be back soon with good news :D
     
  14. This deffinently got me in the right direction. Altough it's not 100% what i need. Whenever I die by lava, fire_tick, or attack it extinguishes me. However, when I die by fire, it does not work... I find this strange. I tried to do some research on why it doesn't work, but couldnt find any answers. Got any clue? Maybe it's in a diffrent part of my code, like the part after e.setcancelled(true); in onPlayerDamage.

    Code:
    Code (Text):
    @EventHandler
        public void onPlayerDamage(EntityDamageEvent e) {
            if (e.getEntity() instanceof Player) {
                Player p = (Player) e.getEntity();
                if (p.getHealth() <= e.getDamage()) {
                    e.setCancelled(true);
                    p.teleport(p.getWorld().getSpawnLocation());
                    p.setFireTicks(0);
                    p.setHealth(p.getMaxHealth());
                    p.setFoodLevel(20);
                }
            }
        }

        @EventHandler
        public void onCombust(EntityCombustEvent e) {
            if (e.getEntity() instanceof Player) {
                e.setCancelled(true);
            }
        }
    Also... I've pasted this code exacly how it's in my plugin. The onCombust is right underneath onPlayerDamage, yet it only gets triggered whenever I "die" (die in quotations because I don't actually die). Is this suppost to happen? Is there any logic behind it?
     
  15. Combust is whenever an entity catches on fires, like lava or anything like that.
     
  16. Thanks for the explenation! However, this does not solve my problem ._. How can i make it so that the player stops being on fire even while standing in fire?
     
  17. Cancel the combust event, it's that simple.
     
  18. Wish it was... It's stopping every kind of fire, except when you're actually standing in fire. No idea why... But i kinda gave up on it... I'll deal with this later. Another solution i had was replacing the spawn block with water and then quickly changing it back to air. I did this, but I think it switches too fast. I'll just have to deal with a bit of water in the spawn for now. Thanks for your kindness and great help!