Solved Bug with firework spawn

Discussion in 'Plugin Development' started by kingstar64, Jan 14, 2013.

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

    kingstar64

    I am getting a error when I die at Location loc = (Location) event.getEntity().getWorld();
    the error says that org.bukkit.craftworld cannot cast to org.bukkit.Location

    Code:
        @EventHandler
        public void onPlayerDeath(PlayerDeathEvent event){   
            if(event.getEntity().getLastDamageCause() instanceof EntityDamageByEntityEvent){
                EntityDamageByEntityEvent nEvent = (EntityDamageByEntityEvent) event.getEntity().getLastDamageCause();
                if ((nEvent.getDamager() instanceof Creeper)) {
                    Location loc = (Location) event.getEntity().getWorld();
                    World world = event.getEntity().getWorld();
                    Firework fw = (Firework) world.spawn(loc, Firework.class);
                    FireworkMeta data = (FireworkMeta) fw.getFireworkMeta();
                    data.clearEffects();
                    data.setPower(2);
                    data.addEffect(FireworkEffect.builder().withColor(Color.BLACK).with(Type.BALL_LARGE).build());
                    fw.setFireworkMeta(data);
                    return;
                    }
                }
            }
     
    }
     
  2. Offline

    DarkBladee12

    kingstar64 You try to cast a world into a location... Just do it like this:

    Code:
    Location loc = event.getEntity().getLocation();
     
  3. Offline

    kingstar64

    Thanks that worked. That was a stupid mistake xD
     
Thread Status:
Not open for further replies.

Share This Page