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 Code:java package me.Schnel.BetterExplosions; import java.util.Random; import org.bukkit.Bukkit;import org.bukkit.Location;import org.bukkit.Material;import org.bukkit.World;import org.bukkit.block.Block;import org.bukkit.entity.Entity;import org.bukkit.entity.EntityType;import org.bukkit.entity.FallingBlock;import org.bukkit.entity.Player;import org.bukkit.event.EventHandler;import org.bukkit.event.Listener;import org.bukkit.event.entity.EntityExplodeEvent;import org.bukkit.plugin.java.JavaPlugin;import org.bukkit.scheduler.BukkitScheduler;import org.bukkit.util.Vector; public class main extends JavaPlugin implements Listener{ public void onEnable(){ getServer().getPluginManager().registerEvents(this, this); getLogger().info("Better Explosions Enabled"); getLogger().severe("Uh oh! The plugin is DEAD!!! (or broken)"); getConfig().options().copyDefaults(true); saveConfig(); Bukkit.getServer().getPluginManager().registerEvents(this, this); } public void onDisable(){ getLogger().info("Better Explosions Disabled"); getLogger().severe("Uh oh! The plugin is DEAD!!! (or broken)"); } @EventHandler public void onEntityExplode(final EntityExplodeEvent event) { for(Block b : event.blockList()){ /*Generates random location to spray blocks*/ float x = (float) -2 + (float) (Math.random() * ((2- -2) +1)); float y = (float) -3 + (float) (Math.random() * ((3- -3) +1)); float z = (float) -2 + (float) (Math.random() * ((2- -2) +1)); @SuppressWarnings("deprecation")/*Creates the blocks flying module*/ FallingBlock fallingBlock = b.getWorld().spawnFallingBlock( b.getLocation(), b.getType(), b.getData()); fallingBlock.setDropItem(false); fallingBlock.setVelocity(new Vector(x, y, z)); b.setType(Material.AIR); } Random rand = new Random(); BukkitScheduler scheduler = Bukkit.getServer().getScheduler();/*Schedules random event*/ scheduler.scheduleSyncDelayedTask(this, new Runnable() { @Override public void run() { int random = new Random().nextInt(Bukkit.getOnlinePlayers().length); Player player = Bukkit.getOnlinePlayers()[random]; Location location = player.getLocation(); World world = player.getWorld(); Location center = location; Random rand = new Random(); double angle = rand.nextDouble()*360; //Generate a random angle double x = center.getX() + (rand.nextDouble()*100*Math.cos(Math.toRadians(angle))); double z = center.getZ() + (rand.nextDouble()*100*Math.sin(Math.toRadians(angle))); double y = center.getY() + 700; /*Finds new location*/ Location newloc = new Location(world, x, y, z); FallingBlock TNT = location.getWorld().spawnFallingBlock(newloc, Material.TNT, (byte)0); //creates the falling block TNT.setVelocity(new Vector()); Location tntloc = TNT.getLocation(); ParticleEffect.EXPLODE.display(tntloc, 2, 3, 1, 100, 100); if (TNT.getLocation().subtract(0,1,0).getBlock().getType() != Material.AIR){ Entity tnt = tntloc.getWorld().spawnEntity(tntloc, EntityType.PRIMED_TNT); tnt.setTicksLived(7); TNT.remove(); } } }, (long) rand.nextInt(567)); }} Would this work, above ? 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 EDIT by Moderator: merged posts, please use the edit button instead of double posting.
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 package me.Schnel.BetterExplosions; import java.util.Random; import org.bukkit.Bukkit;import org.bukkit.ChatColor;import org.bukkit.Location;import org.bukkit.Material;import org.bukkit.World;import org.bukkit.block.Block;import org.bukkit.entity.Entity;import org.bukkit.entity.EntityType;import org.bukkit.entity.FallingBlock;import org.bukkit.entity.Player;import org.bukkit.event.EventHandler;import org.bukkit.event.Listener;import org.bukkit.event.entity.EntityExplodeEvent;import org.bukkit.plugin.java.JavaPlugin;import org.bukkit.scheduler.BukkitScheduler;import org.bukkit.util.Vector; public class main extends JavaPlugin implements Listener{ public void onEnable(){getServer().getPluginManager().registerEvents(this, this);getLogger().info("Better Explosions Enabled");getLogger().severe("Uh oh! The plugin is DEAD!!! (or broken)");getConfig().options().copyDefaults(true);saveConfig();Bukkit.getServer().getPluginManager().registerEvents(this, this);} public void onDisable(){getLogger().info("Better Explosions Disabled");getLogger().severe("Uh oh! The plugin is DEAD!!! (or broken)");} @EventHandlerpublic void onEntityExplode(final EntityExplodeEvent event) {for(Block b : event.blockList()){/*Generates random location to spray blocks*/float x = (float) -2 + (float) (Math.random() * ((2- -2) +1));float y = (float) -3 + (float) (Math.random() * ((3- -3) +1));float z = (float) -2 + (float) (Math.random() * ((2- -2) +1)); @SuppressWarnings("deprecation")/*Creates the blocks flying module*/FallingBlock fallingBlock = b.getWorld().spawnFallingBlock(b.getLocation(), b.getType(), b.getData());fallingBlock.setDropItem(false);fallingBlock.setVelocity(new Vector(x, y, z)); b.setType(Material.AIR);} Random rand = new Random(); BukkitScheduler scheduler = Bukkit.getServer().getScheduler();/*Schedules random event*/scheduler.scheduleSyncDelayedTask(this, new Runnable() {@Overridepublic void run() {int random = new Random().nextInt(Bukkit.getOnlinePlayers().length);Player player = Bukkit.getOnlinePlayers()[random];Location location = player.getLocation();World world = player.getWorld();Location center = location;Random rand = new Random();double angle = rand.nextDouble()*360; //Generate a random angledouble x = center.getX() + (rand.nextDouble()*100*Math.cos(Math.toRadians(angle)));double z = center.getZ() + (rand.nextDouble()*100*Math.sin(Math.toRadians(angle)));double y = center.getY() + 700; /*Finds new location*/Location newloc = new Location(world, x, y, z);FallingBlock TNT = location.getWorld().spawnFallingBlock(newloc, Material.TNT, (byte)0); //creates the falling blockTNT.setVelocity(new Vector());Location tntloc = TNT.getLocation();ParticleEffect.EXPLODE.display(tntloc, 2, 3, 1, 100, 100);if (TNT.getLocation().subtract(0,1,0).getBlock().getType() != Material.AIR){Entity tnt = tntloc.getWorld().spawnEntity(tntloc, EntityType.PRIMED_TNT);tnt.setTicksLived(7);TNT.remove();player.sendMessage(ChatColor.LIGHT_PURPLE + "Test, this means the plugin works ;D");}}}, (long) rand.nextInt(567)); }} Please help ;(
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 package me.Schnel.BetterExplosions; import java.util.Random; import org.bukkit.Bukkit;import org.bukkit.ChatColor;import org.bukkit.Location;import org.bukkit.Material;import org.bukkit.World;import org.bukkit.block.Block;import org.bukkit.entity.Entity;import org.bukkit.entity.EntityType;import org.bukkit.entity.FallingBlock;import org.bukkit.entity.Player;import org.bukkit.event.EventHandler;import org.bukkit.event.Listener;import org.bukkit.event.entity.EntityExplodeEvent;import org.bukkit.plugin.java.JavaPlugin;import org.bukkit.scheduler.BukkitScheduler;import org.bukkit.util.Vector; public class main extends JavaPlugin implements Listener{ public void onEnable(){ getServer().getPluginManager().registerEvents(this, this); getLogger().info("Better Explosions Enabled"); getLogger().severe("Uh oh! The plugin is DEAD!!! (or broken)"); getConfig().options().copyDefaults(true); saveConfig(); Bukkit.getServer().getPluginManager().registerEvents(this, this); } public void onDisable(){ getLogger().info("Better Explosions Disabled"); getLogger().severe("Uh oh! The plugin is DEAD!!! (or broken)"); } @EventHandler public void onEntityExplode(final EntityExplodeEvent event) { for(Block b : event.blockList()){ /*Generates random location to spray blocks*/ float x = (float) -2 + (float) (Math.random() * ((2- -2) +1)); float y = (float) -3 + (float) (Math.random() * ((3- -3) +1)); float z = (float) -2 + (float) (Math.random() * ((2- -2) +1)); @SuppressWarnings("deprecation")/*Creates the blocks flying module*/ FallingBlock fallingBlock = b.getWorld().spawnFallingBlock( b.getLocation(), b.getType(), b.getData()); fallingBlock.setDropItem(false); fallingBlock.setVelocity(new Vector(x, y, z)); b.setType(Material.AIR); } Random rand = new Random(); BukkitScheduler scheduler = Bukkit.getServer().getScheduler();/*Schedules random event*/ scheduler.scheduleSyncDelayedTask(this, new Runnable() { @Override public void run() { int random = new Random().nextInt(Bukkit.getOnlinePlayers().length); Player player = Bukkit.getOnlinePlayers()[random]; Location location = player.getLocation(); World world = player.getWorld(); Location center = location; Random rand = new Random(); double angle = rand.nextDouble()*360; //Generate a random angle double x = center.getX() + (rand.nextDouble()*100*Math.cos(Math.toRadians(angle))); double z = center.getZ() + (rand.nextDouble()*100*Math.sin(Math.toRadians(angle))); double y = center.getY() + 700; /*Finds new location*/ Location newloc = new Location(world, x, y, z); FallingBlock TNT = location.getWorld().spawnFallingBlock(newloc, Material.TNT, (byte)0); //creates the falling block TNT.setVelocity(new Vector()); TNT.setDropItem(false); Location tntloc = TNT.getLocation(); ParticleEffect.EXPLODE.display(tntloc, 2, 3, 1, 100, 100); if (TNT.getLocation().subtract(0,1,0).getBlock().getType() != Material.AIR){ Entity tnt = tntloc.getWorld().spawnEntity(tntloc, EntityType.PRIMED_TNT); tnt.setTicksLived(7); TNT.remove(); player.sendMessage(ChatColor.LIGHT_PURPLE + "Test, this means the plugin works ;D"); } } }, (long) rand.nextInt(567)); }} 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.
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.