So I am trying to make it so that you first spawn, and wait 4 seconds, then the messages will greet you, how would I wait for that long, I tried wait(80); surrounded by try/catch, that didn't work. Here is my code, I want it to execute before the greetings: PHP: @EventHandler public void onJoinLogin(PlayerJoinEvent e) { Player player = e.getPlayer(); // Check if it's their first join. World w = player.getWorld(); File file = new File(w.getName() + "/players/" + player.getName() + ".dat"); boolean exists = file.exists(); if (!exists) { teleportToFirstSpawn(player); Bukkit.broadcastMessage(ChatColor.DARK_PURPLE + player.getDisplayName() + " has joined the server for the first time!"); }else{ Bukkit.broadcastMessage(ChatColor.YELLOW + player.getDisplayName() + ", welcome again!"); } }
Freeze the player with one the methods in the other thread on this forum and make a delayed task that unfreezes him after 80 ticks. Never, ever, ever, ever, ever freeze the main CraftBukkit thread! Ever.
You can also use player.hasPlayedBefore() (javadocs) to see if the player has been on your server before. No need to check for physical file locations.
I am trying to do a FUS RO DAH! chat command, and I want the explosions to wait ~5 ticks before exploding so they do not explode at the exact same time. This is my event: PHP: @EventHandler public void onPlayerChatting(final PlayerChatEvent e) { if(e.getMessage().equals("FUS RO DAH!")){ final World world = e.getPlayer().getWorld(); final Location location = e.getPlayer().getLocation(); final Location location1 = location.add(4, 4, 4); final Location location2 = location1.add(2, 3, 2); final Location location3 = location2.add(4, 5, 2); final Location location4 = location3.add(2, 4, 3); final Location location5 = location4.add(4, 4, 4); getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {public void run() {world.createExplosion(location, 0F);}}, 5L); getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {public void run() {world.createExplosion(location1, 0F);}}, 5L); getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {public void run() {world.createExplosion(location2, 0F);}}, 5L); getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {public void run() {world.createExplosion(location3, 0F);}}, 5L); getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {public void run() {world.createExplosion(location4, 0F);}}, 5L); getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {public void run() {world.createExplosion(location5, 0F);}}, 5L); } } I am getting an error, any ideas?
Since you don't say what error you're getting, it's kind of hard to know. But I can see one problem: your usage of .add() on those Locations is incorrect. Unfortunately, Location objects are mutable (poor design!), and .add() modifies the object in-place (as well as returning the modified object, not a new object). So location1 = location.add(4, 4, 4) ends up setting both location1 and location to the same thing. All of your locations are going to end up pointing to the same place. The simplest way around this is to do location1 = location.clone().add(4,4,4). (Also, if you want the explosion not to happen at the same time, you probably want a different delay for each delayed task you schedule) That's essential if you're passing an object into a Runnable like that. Since it's code that will be executed in the future, the compiler needs to know that the object isn't going to change in the meantime.
I recommend doing like this: Code:java @EventHandlerpublic void onPlayerChatting(final PlayerChatEvent e){if(e.getMessage().equals("FUS RO DAH!")){ final World world = e.getPlayer().getWorld();final Location location = e.getPlayer().getLocation();final Location location1 = location.clone().add(4, 4, 4);final Location location2 = location1.clone().add(2, 3, 2);final Location location3 = location2.clone().add(4, 5, 2);final Location location4 = location3.clone().add(2, 4, 3);final Location location5 = location4.clone().add(4, 4, 4);Schedular sd = getServer().getScheduler();sd.scheduleSyncDelayedTask(plugin, new ExplotionTask(location), 5L);sd.scheduleSyncDelayedTask(plugin, new ExplotionTask(location1), 10L);sd.scheduleSyncDelayedTask(plugin, new ExplotionTask(location2), 15L);sd.scheduleSyncDelayedTask(plugin, new ExplotionTask(location3), 20L);sd.scheduleSyncDelayedTask(plugin, new ExplotionTask(location4), 25L);sd.scheduleSyncDelayedTask(plugin, new ExplotionTask(location5), 30L);}} private class ExplotionTask implements Runnable{Location loc;ExplotionTask(Location loc){this.loc = loc;}public void run(){} loc.getWorld().createExplosion(loc, 0F);} ^^ may contain bugs