Stop block damage from createExplosion()

Discussion in 'Plugin Development' started by the_merciless, Mar 3, 2013.

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

    the_merciless

    How do i stop blocks being damaged when using createExplosion() ?
     
  2. Offline

    minoneer

    boolean createExplosion (double x, double y, double z, float power, boolean setFire, boolean breakBlocks)


    just set the last parameter to false :)
     
  3. Offline

    the_merciless

    Doesnt let me. Even though im selecting the last 'createexplosion' which takes 2 booleans. I still get this.

    The method createExplosion(Location, float, boolean) in the type World is not applicable for the arguments (Location, float, boolean, boolean)

    nvm i have to use doubles on the location
     
  4. Offline

    teunie75

    You can also set the floatpower to -<power>F
     
  5. Offline

    minoneer

    True, but wouldn't that also cancle any Entity damage the explosion might cause?
     
  6. Offline

    teunie75

    minoneer I don't think so, you should try it. :)
     
  7. Offline

    the_merciless

    im using 4F which is the same as tnt. Entities are still damaged.

    New question:

    What im doing is making a player explode, now i want to find out which players have died because of that explosion, how can i do this?
     
  8. Offline

    minoneer

    I think you'll have to listen for all dying players, then compare location, time and death cause (or last damage cause, not sure) to your explosion.
     
  9. Offline

    iWareWolf

    the_merciless
    This is from a plugin request I did not too long ago.
    Code:
        @EventHandler
        public void onDeathByExplosion(PlayerDeathEvent e) {
            if (e.getEntity().getLastDamageCause() instanceof EntityDamageEvent) {
                EntityDamageEvent event = (EntityDamageEvent) e.getEntity().getLastDamageCause();
                if (event.getCause().equals(DamageCause.BLOCK_EXPLOSION) || event.getCause().equals(DamageCause.ENTITY_EXPLOSION)) {
                    Player p = (Player) e.getEntity();
                    Bukkit.getServer().dispatchCommand(getServer().getConsoleSender(),
                            getConfig().getString("DeathByExplosion").replace("PLAYERNAME", p.getName()));
                }
            }
        }
     
  10. Offline

    minoneer

    That looks like a nice approach to it
     
  11. Offline

    the_merciless

    Thanks but this wont get the results i want. I want to reward the player that exploded for each player he killed. this way would prove difficult to get the player that exploded. Instead, i never checked damage event i just created the explosion then followed that up by getting nearbyentities and checking if they were dead, works pretty well. Heres the code if your interested.

    Code:
    @EventHandler (priority = EventPriority.HIGHEST)
        public void oninvclick(InventoryClickEvent e){
            final Player p = (Player) e.getWhoClicked();
            if (!p.getWorld().getName().equalsIgnoreCase("world")){
                if (plugin.getClass(p).equalsIgnoreCase("creeper")){
                    if (e.getSlotType() == InventoryType.SlotType.ARMOR && e.getSlot() == 39){
                        ItemStack skull = new ItemStack(Material.SKULL_ITEM, 1, (short)4);
                        ItemStack cursor = e.getCursor();
                        if (cursor.equals(skull)){
                            p.sendMessage("CRAZY FOOL!");
                            p.getWorld().playSound(p.getLocation(), Sound.FUSE, 3F, 1F);
                            Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){
                                public void run(){
                                    p.getWorld().createExplosion(p.getLocation(), 4F, true);
                                    List <Entity> near = p.getNearbyEntities(5, 5, 5);
                                    for (int i = 0; i < near.size(); i++ ){
                                        Entity dead = near.get(i);
                                        if (dead instanceof Player){
                                            Player victim = (Player) dead;
                                            if (victim.isDead()){
                                                FileConfiguration pfile = null;
                                                File file = new File("plugins"+File.separator+"MercilessPvp"+File.separator+"Players"+File.separator+p.getName()+".yml");
                                                pfile = YamlConfiguration.loadConfiguration(file); 
                                                pfile.set("Kills", pfile.getInt("Kills")+1);
                                                pfile.set("Mp", pfile.getInt("Mp")+1);
                                                pfile.set("Money", pfile.getInt("Money") + 25);
                                                try {
                                                    pfile.save(file);
                                                } catch (IOException e1) {
                                                    e1.printStackTrace();
                                                }
                                                p.sendMessage(ChatColor.AQUA + "[MercilessPvp] You killed " + victim + " & gained $25");
                                                p.sendMessage(ChatColor.AQUA + "[MercilessPvp] Balance: $" + pfile.getInt("Money"));
                                                plugin.setRank(p);         
                                            }
                                        }
                                    }
                                }
                            },60L);
                        }
                    }
                }
            }
        }
    To sum that up:

    place a creeper skull on your head, and you hear the creeper hiss, 2 seconds later BOOM. Killing yourself and anyone nearby.
     
  12. Offline

    minoneer

    I guess that's another way of doing it, although the above approach would have worked for you aswell :)

    Edit: 60 ticks (=3 seconds) seems a rather long delay to me. Most player will have hit the respawn button by then
     
  13. Offline

    the_merciless

    I could have done it with damage event but seemed easier to continue it on from the explosion, that way i already had the player exploding.
     
Thread Status:
Not open for further replies.

Share This Page