Explosion Creation Help.

Discussion in 'Plugin Development' started by Unshakablefaith, Apr 22, 2014.

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

    Unshakablefaith

    Why doesn't this create and explosion when the player joins the server?

    The p.sendMessage() works perfectly.

    Code:
    @EventHandler
        public void onJoin(PlayerJoinEvent event) {
     
            Player p = (Player) event.getPlayer();
            p.getLocation().getWorld().createExplosion(p.getLocation(), 3);
            p.sendMessage(ChatColor.RED + "@--------------------------------------@");
            p.sendMessage(ChatColor.GREEN + "Welcome to Econocraft " + ChatColor.AQUA + p.getDisplayName() + ChatColor.GREEN + "!");
            p.sendMessage(ChatColor.YELLOW + "There is currently " + ChatColor.LIGHT_PURPLE + Bukkit.getOnlinePlayers().length + ChatColor.YELLOW + " player(s) online!");
            p.sendMessage(ChatColor.RED + "@--------------------------------------@");
     
        }
    }
     
  2. Offline

    rfsantos1996

    I would disable fire and block break (x, y, z, power, boolean fire, boolean breakblocks) instead of just exploding.

    Also, it'll return a boolean if the explosion is successful, so I recommend checking if it is. Maybe another event cancel it or something like that.
     
    WD_MUFFINFLUFFER likes this.
  3. Offline

    Unshakablefaith

    How can I check if it is successful?
     
  4. Offline

    rfsantos1996

    createExplosion returns a boolean. If true, it is successful.
     
  5. Offline

    Unshakablefaith

    What if it is false? What would that mean for the explosion?
     
  6. createExplosion might fire events that can be cancelled - just test it: listen to ExplosionPrimeEvent (not sure this one triggers, though) and EntityExplodeEvent, even if there is no entity.
     
  7. Offline

    rfsantos1996

    Just asking, do you know Java? World.createExplosion returns a boolean if explosion succeeded. Test it with:
    Code:java
    1. @EventHandler
    2. public void onJoin(PlayerJoinEvent event) {
    3.  
    4. Player p = (Player) event.getPlayer();
    5. Location loc = p.getLocation();
    6. p.sendMessage(ChatColor.RED + "Explosion were created? "+ p.getLocation().getWorld().createExplosion(loc.getX(), loc.getY(), loc.getZ(), 3, false, false));
    7. p.sendMessage(ChatColor.RED + "@--------------------------------------@");
    8. p.sendMessage(ChatColor.GREEN + "Welcome to Econocraft " + ChatColor.AQUA + p.getDisplayName() + ChatColor.GREEN + "!");
    9. p.sendMessage(ChatColor.YELLOW + "There is currently " + ChatColor.LIGHT_PURPLE + Bukkit.getOnlinePlayers().length + ChatColor.YELLOW + " player(s) online!");
    10. p.sendMessage(ChatColor.RED + "@--------------------------------------@");
    11.  
    12. }
     
  8. Offline

    Unshakablefaith

    You needed to make it a boolean:p :D Thanks for all the help!
     
  9. Offline

    rfsantos1996

    You don't need to, it just to check if it is successfull created
     
Thread Status:
Not open for further replies.

Share This Page