Player Explode on Death

Discussion in 'Plugin Development' started by srspore, Sep 18, 2015.

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

    srspore

    I think this is pretty simple and I'm just messing it up, but I want to make the player explode when they die this is what I have so far.
    Code:
    public class Kamikaze implements Listener {
        public static void kamikazeMaterials(Player p) {
            Commands.kit.put(p, "kamikaze");
            Util.give(p, Material.DIAMOND_SWORD, 1);
            p.getInventory().setHelmet(new ItemStack(Material.IRON_HELMET));
            p.getInventory().setChestplate(new ItemStack(Material.IRON_CHESTPLATE));
            p.getInventory().setLeggings(new ItemStack(Material.IRON_LEGGINGS));
            p.getInventory().setBoots(new ItemStack(Material.IRON_BOOTS));
        }
        public static void kamikaze(Player p) {
            kamikazeMaterials(p);
            for (int i=0;i<35;i++) {
                Util.give(p, Material.MUSHROOM_SOUP, 1);
            }
        }
        public void onPlayerDeath(PlayerDeathEvent e) {
            Player p = (Player) e.getEntity();
            if (!Commands.kit.get(p).equals("kamikaze")) return;
    // This is the code that I thought would cause an explosion
            final Double x = p.getLocation().getX();
            final Double y = p.getLocation().getY();
            final Double z = p.getLocation().getZ();
            p.getWorld().createExplosion(x,y,z, 4F, true, false);
        }
    }
    Thank you!
     
  2. if(!Commands.kit.get(p).equals("kamikaze"))return;
    Log if the player has the kit
    Did you register the events?
    And you're missing @EventHandler
     
  3. Offline

    FabeGabeMC

    @srspore
    Do you get any error in the console whenever this happens?
     
  4. Offline

    Xerox262

    Just a question, does anyone think it's because he forgot the @EventHandler annotation?
     
  5. Yes? Without it the event wouldn't even be called
     
  6. Offline

    Xerox262

    DAMN, I didn't even notice you commented the same thing, I was being sarcastic when I said it.
     
  7. @srspore
    I'm assuming since you didn't post a console error, your final code (the action stuff) isn't taking effect. That means that the only thing that could be preventing it from working at the given time is your conditions (if statements) not being met. In this case, you can easily diagnose the problem with a debugging process. Please read this: http://bukkit.org/threads/diagnosing-problems.385332/
     
  8. Offline

    boomboompower

    You really should add an eventhandler
    Code:
    @EventHandler
     
  9. Offline

    srspore

    @FisheyLP Yeah that was a silly mistake. oops. the explosion happens now but it doesn't damage players. Any idea why?
     
  10. Offline

    boomboompower

    Do damage to any players near the explosion.
     
  11. Offline

    srspore

    @boomboompower Well I suppose I could do that but I kinda would like it to like behave like an explosion, where the further the player is the less damage they take and I suppose I could like program that but, is there an easier way. to just make it behave like a normal explosion

    EDIT: never mind I found the solution. p.getWorld().createExplosion(x,y,z, 4F, true, false); the "true" value makes it so that the explosion deals damage, and the false makes it so there is not fire... if it was true there would be fire.... but that's not the point.
     
    Last edited: Sep 18, 2015
  12. Offline

    The_BloodHound

    I believe this can also work:
    Code:
    p.getWorld().spawnEntity(
    
                    new Location(p.getWorld(), p.getLocation().getX(), p.getLocation().getY(), p
    
                            .getLocation().getZ()), EntityType.PRIMED_TNT);
    
     

  13. You gotta be kidding me /.-
    Hint (open)
    just use p.getLocation() instead of remaking the same location

    And tnt explodes after 2-3 seconds and not instantly. And destroys blocks
     
  14. Offline

    RoboticPlayer

    If this is solved, please mark it as so.
     
Thread Status:
Not open for further replies.

Share This Page