onProjectileHit Need help!

Discussion in 'Plugin Development' started by mrgreen33gamer, Jul 5, 2014.

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

    mrgreen33gamer

    Hello,

    I need help, I cannot get the egg grenade to destroy multiple blocks when hitting. It only destroys one block, while checking for other blocks to NOT destroy.

    Here is my code:

    Code:java
    1.  
    2. @SuppressWarnings("deprecation")
    3. @EventHandler
    4. public void onGrenadeHit(ProjectileHitEvent event) {
    5. if(!(event.getEntity() instanceof Egg) || (event.getEntity().hasMetadata("Spleef-Grenade"))) return;
    6. Egg egg = (Egg)event.getEntity();
    7. World world = egg.getWorld();
    8. Player p = (Player) egg.getShooter();
    9. if(playersleft.contains(p.getName())){
    10. BlockIterator bi = new BlockIterator(world, egg.getLocation().toVector(), egg.getVelocity().normalize(), 0, 4);
    11. Block hit = null;
    12.  
    13. while(bi.hasNext()){
    14. hit = bi.next();
    15. if(hit.getTypeId()!=0){
    16. break;
    17. }
    18. }
    19.  
    20. int x = egg.getLocation().getBlockX();
    21. int y = egg.getLocation().getBlockY();
    22. int z = egg.getLocation().getBlockZ();
    23.  
    24. if(hit.getType() == Material.SNOW_BLOCK){
    25. restore.add(hit.getState());
    26. hit.setType(Material.AIR);
    27.  
    28. Block pos1 = Bukkit.getWorld("World").getBlockAt(x + 1, y, z);
    29. if(hit.getType() == Material.WOOL && hit.getType() == Material.GLOWSTONE && hit.getType() == Material.BEDROCK){
    30. }else{
    31. restore.add(pos1.getState());
    32. pos1.setType(Material.AIR);
    33. }
    34. Block pos2 = Bukkit.getWorld("World").getBlockAt(x + 1, y, z + 1);
    35. if(hit.getType() == Material.WOOL && hit.getType() == Material.GLOWSTONE && hit.getType() == Material.BEDROCK){
    36. }else{
    37. restore.add(pos2.getState());
    38. pos2.setType(Material.AIR);
    39. }
    40. Block pos3 = Bukkit.getWorld("World").getBlockAt(x - 1, y, z);
    41. if(hit.getType() == Material.WOOL && hit.getType() == Material.GLOWSTONE && hit.getType() == Material.BEDROCK){
    42. }else{
    43. restore.add(pos3.getState());
    44. pos3.setType(Material.AIR);
    45. }
    46. Block pos4 = Bukkit.getWorld("World").getBlockAt(x - 1, y, z - 1);
    47. if(hit.getType() == Material.WOOL && hit.getType() == Material.GLOWSTONE && hit.getType() == Material.BEDROCK){
    48. }else{
    49. restore.add(pos4.getState());
    50. pos4.setType(Material.AIR);
    51. }
    52. Block pos5 = Bukkit.getWorld("World").getBlockAt(x, y, z - 1);
    53. if(hit.getType() == Material.WOOL && hit.getType() == Material.GLOWSTONE && hit.getType() == Material.BEDROCK){
    54. }else{
    55. restore.add(pos5.getState());
    56. pos5.setType(Material.AIR);
    57. }
    58. Block pos6 = Bukkit.getWorld("World").getBlockAt(x, y, z + 1);
    59. if(hit.getType() == Material.WOOL && hit.getType() == Material.GLOWSTONE && hit.getType() == Material.BEDROCK){
    60. }else{
    61. restore.add(pos6.getState());
    62. pos6.setType(Material.AIR);
    63. }
    64. Block pos7 = Bukkit.getWorld("World").getBlockAt(x + 1, y, z - 1);
    65. if(hit.getType() == Material.WOOL && hit.getType() == Material.GLOWSTONE && hit.getType() == Material.BEDROCK){
    66. }else{
    67. restore.add(pos7.getState());
    68. pos7.setType(Material.AIR);
    69. }
    70. Block pos8 = Bukkit.getWorld("World").getBlockAt(x - 1, y, z + 1);
    71. if(hit.getType() == Material.WOOL && hit.getType() == Material.GLOWSTONE && hit.getType() == Material.BEDROCK){
    72. }else{
    73. restore.add(pos8.getState());
    74. pos8.setType(Material.AIR);
    75. }
    76.  
    77. }
    78. }
    79. }
    80.  


    Much help please :D!
     
  2. Offline

    indyetoile

    mrgreen33gamer

    The location you define is only one block.

    Code:java
    1. Block pos1 = Bukkit.getWorld("World").getBlockAt(x +1, y, z);
    2.  

    This means you get the block at the location, and you set it to air afterwards. You should set multiple block locations if you want to break multiple blocks.
     
  3. Offline

    mrgreen33gamer

    Well that's the only way I know to do it. Just get the location of the block.

    indyetoile
     
  4. Offline

    indyetoile

    mrgreen33gamer

    Yes, but you wanted to destroy multiple blocks when the egg hits the blocks right? You've only defined one location in your code.
     
  5. Offline

    mrgreen33gamer

    indyetoile How would i get multiple block locations then?
     
  6. Offline

    mrgreen33gamer

Thread Status:
Not open for further replies.

Share This Page