Problem with something, no stacktrace

Discussion in 'Plugin Development' started by NDUGAR, May 29, 2014.

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

    NDUGAR

    So I have a problem in my plugin where it is meant to randomly spawn meteors which are fallingBlocks which have explosion particles around them and once the server detects the block is above something that isn't air, it creates a primed tnt entity at that location, but for some reason it doesn't work; any help?

    Code:java
    1. package me.Schnel.BetterExplosions;
    2.  
    3. import java.util.Random;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.Location;
    8. import org.bukkit.Material;
    9. import org.bukkit.World;
    10. import org.bukkit.block.Block;
    11. import org.bukkit.entity.Entity;
    12. import org.bukkit.entity.EntityType;
    13. import org.bukkit.entity.FallingBlock;
    14. import org.bukkit.entity.Player;
    15. import org.bukkit.event.EventHandler;
    16. import org.bukkit.event.Listener;
    17. import org.bukkit.event.entity.EntityExplodeEvent;
    18. import org.bukkit.plugin.java.JavaPlugin;
    19. import org.bukkit.scheduler.BukkitScheduler;
    20. import org.bukkit.util.Vector;
    21.  
    22. public class main extends JavaPlugin implements Listener{
    23.  
    24.  
    25. public void onEnable(){
    26. getServer().getPluginManager().registerEvents(this, this);
    27. getLogger().info("Better Explosions Enabled");
    28. getLogger().severe("Uh oh! The plugin is DEAD!!! (or broken)");
    29. getConfig().options().copyDefaults(true);
    30. saveConfig();
    31. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    32. }
    33.  
    34. public void onDisable(){
    35. getLogger().info("Better Explosions Disabled");
    36. getLogger().severe("Uh oh! The plugin is DEAD!!! (or broken)");
    37. }
    38.  
    39. @EventHandler
    40. public void onEntityExplode(final EntityExplodeEvent event) {
    41. for(Block b : event.blockList()){
    42. /*Generates random location to spray blocks*/
    43. float x = (float) -2 + (float) (Math.random() * ((2- -2) +1));
    44. float y = (float) -3 + (float) (Math.random() * ((3- -3) +1));
    45. float z = (float) -2 + (float) (Math.random() * ((2- -2) +1));
    46.  
    47. @SuppressWarnings("deprecation")/*Creates the blocks flying module*/
    48. FallingBlock fallingBlock = b.getWorld().spawnFallingBlock(
    49. b.getLocation(), b.getType(), b.getData());
    50. fallingBlock.setDropItem(false);
    51. fallingBlock.setVelocity(new Vector(x, y, z));
    52.  
    53. b.setType(Material.AIR);
    54. }
    55.  
    56. Random rand = new Random();
    57.  
    58. BukkitScheduler scheduler = Bukkit.getServer().getScheduler();/*Schedules random event*/
    59. scheduler.scheduleSyncDelayedTask(this, new Runnable() {
    60. @Override
    61. public void run() {
    62. int random = new Random().nextInt(Bukkit.getOnlinePlayers().length);
    63. Player player = Bukkit.getOnlinePlayers()[random];
    64. Location location = player.getLocation();
    65. World world = player.getWorld();
    66. Location center = location;
    67. Random rand = new Random();
    68. double angle = rand.nextDouble()*360; //Generate a random angle
    69. double x = center.getX() + (rand.nextDouble()*100*Math.cos(Math.toRadians(angle)));
    70. double z = center.getZ() + (rand.nextDouble()*100*Math.sin(Math.toRadians(angle)));
    71. double y = center.getY() + 700; /*Finds new location*/
    72. Location newloc = new Location(world, x, y, z);
    73. FallingBlock TNT = location.getWorld().spawnFallingBlock(newloc, Material.TNT, (byte)0); //creates the falling block
    74. TNT.setVelocity(new Vector());
    75. TNT.setDropItem(false);
    76. Location tntloc = TNT.getLocation();
    77. ParticleEffect.EXPLODE.display(tntloc, 2, 3, 1, 100, 100);
    78. if (TNT.getLocation().subtract(0,1,0).getBlock().getType() != Material.AIR){
    79. Entity tnt = tntloc.getWorld().spawnEntity(tntloc, EntityType.PRIMED_TNT);
    80. tnt.setTicksLived(7);
    81. TNT.remove();
    82. player.sendMessage(ChatColor.LIGHT_PURPLE + "Test, this means the plugin works ;D");
    83. }
    84. }
    85. }, (long) rand.nextInt(567));
    86.  
    87. }
    88. }
    89.  


    I also use this particle lib: https://forums.bukkit.org/threads/lib-1-7-particleeffect-v1-4.154406/

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jul 1, 2016
  2. Offline

    1Rogue

    Use debug statements, see where it stops executing.
     
Thread Status:
Not open for further replies.

Share This Page