World.CreateExplosion - Invalid usage?

Discussion in 'Plugin Development' started by ITGeist, Aug 17, 2012.

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

    ITGeist

    Hello everyone,

    I try to make a visual explosion by using :
    But it gives me :

    How do I fix that?

    ~ ITGeist.
     
  2. Instead of using the World Object, use the world you want to create the explosion in. Like this: player.getWorld().createExplosion(...);
     
    Metal Julien likes this.
  3. Offline

    ITGeist

    Isn't working.
     
  4. Offline

    Timr

    Try this:

    Code:
    Player p;
     
    if(sender instanceof Player) {
        p = (Player) sender;
    } else {
        //Error
    }
     
    p.getWorld().createExplosion(p.getLocation(), 0.0F);
     
  5. Offline

    sd5

    With explosion power 0.0F it can't work... Simply do this:
    Code:
    if(sender instanceof Player) {
        Player player = (Player) sender;
        player.getWorld().createExplosion(player.getLocation(), 4);
    }
     
  6. Offline

    JDigital1337

    i wasn't aware that sender was an interface for player...

    I think you should be more like this (from memory):

    Code:
    Player player = getServer().getPlayer(sender.getName());
     
    if (player instanceof Player)  player.getWorld().createExplosion(player.getLocation(), 4);
     
  7. Offline

    sd5

    Code:
    sender.getPlayer();
    ???
    Code:
    player instanceof Player
    ???
     
    Firefly likes this.
  8. Offline

    Firefly

    sd5
    1. 0.0F for explosion power gives off the smoke/sound effect but doesn't damage blocks.

    JDigital1337
    1. sender.getPlayer() is completely wrong.
    2. sender can be an instance of Player, and then casted to Player if it is.
     
  9. Offline

    JDigital1337


    Yea I was going from memory.. i forgot the pattern I use..

    was thinking.


    Player player = getServer().getPlayer(sender.getName());

    then the instance check...

    now that I know that sender can be a instance of Player already.. thanks... save me a step.

    (edited my above post to be correct code of the same concept, although I do agree with the above now)
     
  10. Offline

    Firefly

    JDigital1337, actually if (player instanceof Player) will always return true, since player is a Player object. You need to check if player != null instead.
     
  11. Offline

    ITGeist

    Worked. Thanks :)
     
  12. Offline

    JDigital1337

    that block of code is kinda bad, here fixed it up for you:

    Code:
     
    if(sender instanceof Player) {
      Player p = (Player) sender;
      p.getWorld().createExplosion(p.getLocation(), 0.0F);
    } else {
    //Error
    }
     
    
     
Thread Status:
Not open for further replies.

Share This Page