Bug Fixing

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

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

    NDUGAR

    So I created this plugin which creates random meteors around the player. but I don't think that this is going to work and I'm guessing since it destroys blocks, I should probably check :p

    Code:java
    1. package me.Schnel.BetterExplosions;
    2.  
    3. import java.util.Random;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.Location;
    7. import org.bukkit.Material;
    8. import org.bukkit.World;
    9. import org.bukkit.block.Block;
    10. import org.bukkit.entity.Entity;
    11. import org.bukkit.entity.EntityType;
    12. import org.bukkit.entity.FallingBlock;
    13. import org.bukkit.entity.Player;
    14. import org.bukkit.event.EventHandler;
    15. import org.bukkit.event.Listener;
    16. import org.bukkit.event.entity.EntityExplodeEvent;
    17. import org.bukkit.plugin.java.JavaPlugin;
    18. import org.bukkit.scheduler.BukkitScheduler;
    19. import org.bukkit.util.Vector;
    20.  
    21. public class main extends JavaPlugin implements Listener{
    22.  
    23.  
    24. public void onEnable(){
    25. getServer().getPluginManager().registerEvents(this, this);
    26. getLogger().info("Better Explosions Enabled");
    27. getLogger().severe("Uh oh! The plugin is DEAD!!! (or broken)");
    28. getConfig().options().copyDefaults(true);
    29. saveConfig();
    30. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    31. }
    32.  
    33. public void onDisable(){
    34. getLogger().info("Better Explosions Disabled");
    35. getLogger().severe("Uh oh! The plugin is DEAD!!! (or broken)");
    36. }
    37.  
    38. @EventHandler
    39. public void onEntityExplode(final EntityExplodeEvent event) {
    40. for(Block b : event.blockList()){
    41. /*Generates random location to spray blocks*/
    42. float x = (float) -2 + (float) (Math.random() * ((2- -2) +1));
    43. float y = (float) -3 + (float) (Math.random() * ((3- -3) +1));
    44. float z = (float) -2 + (float) (Math.random() * ((2- -2) +1));
    45.  
    46. @SuppressWarnings("deprecation")/*Creates the blocks flying module*/
    47. FallingBlock fallingBlock = b.getWorld().spawnFallingBlock(
    48. b.getLocation(), b.getType(), b.getData());
    49. fallingBlock.setDropItem(false);
    50. fallingBlock.setVelocity(new Vector(x, y, z));
    51.  
    52. b.setType(Material.AIR);
    53. }
    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. Location tntloc = TNT.getLocation();
    76. ParticleEffect.EXPLODE.display(tntloc, 2, 3, 1, 100, 100);
    77. if (TNT.getLocation().subtract(0,1,0).getBlock().getType() != Material.AIR){
    78. Entity tnt = tntloc.getWorld().spawnEntity(tntloc, EntityType.PRIMED_TNT);
    79. tnt.setTicksLived(7);
    80. TNT.remove();
    81. }
    82. }
    83. }, (long) rand.nextInt(567));
    84.  
    85. }
    86. }


    Would this work, above :D?

    Also I'm trying to add a config which allows the player to pick whether they want the blocks to scatter and stay scattered or not, any help on that; I'm new to configs :D

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

    thomasb454


    Google:

    http://wiki.bukkit.org/Configuration_API_Reference

    And as to your initial question, try it?
     
  3. Offline

    NDUGAR

    thomasb454 I tried it, but now it's just spamming me that it works, but I don't see any meteors anywhere :(

    And that too the scheduler seems to be broken :(

    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. Location tntloc = TNT.getLocation();
    76. ParticleEffect.EXPLODE.display(tntloc, 2, 3, 1, 100, 100);
    77. if (TNT.getLocation().subtract(0,1,0).getBlock().getType() != Material.AIR){
    78. Entity tnt = tntloc.getWorld().spawnEntity(tntloc, EntityType.PRIMED_TNT);
    79. tnt.setTicksLived(7);
    80. TNT.remove();
    81. player.sendMessage(ChatColor.LIGHT_PURPLE + "Test, this means the plugin works ;D");
    82. }
    83. }
    84. }, (long) rand.nextInt(567));
    85.  
    86. }
    87. }
    88.  


    Please help ;(
     
  4. Offline

    thomasb454

    Add some debug messages? Note: I have not read the code
     
  5. Offline

    NDUGAR

    debug messages? It doesn't error in the console, I added a test function so it sends me a message when the meteor has gone and it works first time, but then it just goes on an infinite loop :(

    Someone help! It should work, at least I think so, please tell what I'm doing wrong; no stacktrace...

    Here's my new code, I use a particle effect file and reflection handler file in this, but 2 problems:

    1. Once the random integer has been reached, it just spams the player... Infinitely; someone tell me why?
    2. Also the primed tnt isn't working nor is the effect, nor the falling block :(

    Main:

    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.  



    Bump I guess? Anyone please help, I can't see what's wrong?

    Bump for today?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  6. Offline

    NDUGAR

    Bump, Someone help plz?

    Bump, I really need some help, anyone :?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  7. Offline

    NDUGAR

    Bump again, I guess :(
     
  8. Offline

    NDUGAR

    Bump still :(
     
Thread Status:
Not open for further replies.

Share This Page