Placing Block

Discussion in 'Plugin Development' started by ProxyZ, Oct 20, 2014.

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

    ProxyZ

    I got an code that works fine there is only one problem with it it places a block in another block it needs to be on top of anotherblock someone know a solution to this (Sorry for my bad english xD)


    The Code
    Code:java
    1. package me.jay.jenavaopnamens.Rainbow;
    2.  
    3. import me.jay.jenavaopnamens.wands.FireworkEffectPlayer;
    4. import me.jay.jenavaopnamens.wands.Main;
    5. import me.jay.jenavaopnamens.wands.Spell;
    6. import org.bukkit.Bukkit;
    7. import org.bukkit.Color;
    8. import org.bukkit.Effect;
    9. import org.bukkit.FireworkEffect;
    10. import org.bukkit.FireworkEffect.Builder;
    11. import org.bukkit.FireworkEffect.Type;
    12. import org.bukkit.Location;
    13. import org.bukkit.Material;
    14. import org.bukkit.Server;
    15. import org.bukkit.World;
    16. import org.bukkit.block.Block;
    17. import org.bukkit.block.BlockFace;
    18. import org.bukkit.entity.FallingBlock;
    19. import org.bukkit.entity.Player;
    20. import org.bukkit.scheduler.BukkitRunnable;
    21. import org.bukkit.scheduler.BukkitScheduler;
    22. import org.bukkit.util.Vector;
    23.  
    24. public class SandBlock
    25. implements Spell
    26. {
    27. boolean alBlock = false;
    28. Location bl = null;
    29. Location bl1 = null;
    30.  
    31. public void castSpell(Player player)
    32. {
    33. if (this.alBlock)
    34. {
    35. this.bl1 = player.getTargetBlock(null, 50).getLocation();
    36. final FallingBlock block = player.getWorld().spawnFallingBlock(this.bl, Material.SANDSTONE, (byte)0);
    37. block.setDropItem(false);
    38. block.setVelocity(new Vector(0, 2, 0));
    39. this.bl.getBlock().setType(Material.AIR);
    40.  
    41. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Main.plugin, new Runnable()
    42. {
    43. public void run()
    44. {
    45. block.setVelocity(new Vector(0, 0, 0));
    46. block.setVelocity(SandBlock.this.bl1.subtract(block.getLocation()).toVector().normalize().multiply(1));
    47. new BukkitRunnable()
    48. {
    49. public int timer = 0;
    50.  
    51. public void run()
    52. {
    53. if (this.timer++ > 100) {
    54. cancel();
    55. }
    56. Location loc = block.getLocation();
    57. try
    58. {
    59. int id = 55;
    60. loc.getWorld().playEffect(loc, Effect.STEP_SOUND, Material.SAND);
    61. loc.getWorld().playEffect(loc, Effect.STEP_SOUND, Material.SAND);
    62. loc.getWorld().playEffect(loc, Effect.STEP_SOUND, Material.SAND);
    63. loc.getWorld().playEffect(loc, Effect.STEP_SOUND, Material.SAND);
    64. block.setDropItem(false);
    65. }
    66. catch (Exception e)
    67. {
    68. e.printStackTrace();
    69. }
    70. if (!block.isValid()) {
    71. cancel();
    72. }
    73. }
    74. }.runTaskTimer(Main.plugin, 5L, 2L);
    75. }
    76. }, 20L);
    77.  
    78. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Main.plugin, new Runnable()
    79. {
    80. public void run()
    81. {
    82. new BukkitRunnable()
    83. {
    84. public int timer = 0;
    85.  
    86. public void run()
    87. {
    88. if (this.timer++ > 300) {
    89. cancel();
    90. }
    91. if ((!block.getLocation().add(0.0D, -2.0D, 0.0D).getBlock().getRelative(BlockFace.DOWN).getType().equals(Material.AIR)) && (!block.getLocation().add(0.0D, -2.0D, 0.0D).getBlock().getRelative(BlockFace.DOWN).getType().equals(Material.WATER)))
    92. {
    93. block.setDropItem(false);
    94. block.getWorld().createExplosion(block.getLocation().getX(), block.getLocation().getY() + 1.0D, block.getLocation().getZ(), 2.0F, false, false);
    95. block.remove();
    96. cancel();
    97. }
    98. }
    99. }.runTaskTimer(Main.plugin, 1L, 1L);
    100. }
    101. }, 20L);
    102. }
    103. else if (!this.alBlock)
    104. {
    105. this.bl = player.getTargetBlock(null, 50).getLocation();
    106. Player p = player;
    107. final Block bl = p.getTargetBlock(null, 50);
    108. bl.setType(Material.SANDSTONE);
    109. new BukkitRunnable()
    110. {
    111. public int timer = 0;
    112.  
    113. public void run()
    114. {
    115. if (this.timer++ > 60) {
    116. cancel();
    117. }
    118. if (bl.getType() == Material.SANDSTONE)
    119. {
    120. bl.getWorld().playEffect(bl.getLocation(), Effect.STEP_SOUND, Material.SANDSTONE.getId());
    121. }
    122. else
    123. {
    124. cancel();
    125. SandBlock.this.alBlock = false;
    126. }
    127. }
    128. }.runTaskTimer(Main.plugin, 1L, 5L);
    129. }
    130. this.alBlock = (!this.alBlock);
    131. }
    132. }
    133.  
     
  2. Offline

    eyamaz

    Moved to Development
     
  3. Offline

    tcvs

    ProxyZ If you are trying to set the block above just add 1 point to your y coord.
     
  4. Offline

    ProxyZ

    tcvs I already tried that maby an other solution or maby an example
     
  5. Offline

    tcvs

    ProxyZ I will try to create an example for you maybe tonight or tomorrow. Just tahg me tomorrow at some point to remind me if I forget.
     
  6. On line 91 try this:

    Code:
    if ((!block.getLocation().add(0.0D, -2.0D, 0.0D).getBlock().getRelative(BlockFace.DOWN).getType().equals(Material.AIR)) && (!block.getLocation().add(0.0D, -2.0D, 0.0D).getBlock().getRelative(BlockFace.DOWN).getType().equals(Material.WATER)) || !(block.getLocation().getBlock().getRelative(BlockFace.WEST).getType() == Material.AIR) || !(block.getLocation().getBlock().getRelative(BlockFace.NORTH).getType() == Material.AIR) || !(block.getLocation().getBlock().getRelative(BlockFace.EAST).getType() == Material.AIR) || !(block.getLocation().getBlock().getRelative(BlockFace.SOUTH).getType() == Material.AIR) )
    
     
Thread Status:
Not open for further replies.

Share This Page