ok, so I'm making it so when a player gets close to a giant, it will make an explosion, so that way its kinda like the giant is stomping the player, but when the explosion is called, it keeps repeating. How would I make it so it only explodes once every x ticks? Code: @EventHandler public void onPlayerMove(PlayerMoveEvent event) { Player player = event.getPlayer(); Location location = player.getLocation(); for (Entity entity : player.getNearbyEntities(5, 5, 5)) { if (API.isGiant(entity)) { if (entity.getNearbyEntities(5, 5, 5).contains(player)) { entity.getLocation().getWorld().createExplosion(location, 1F); } } } }
Can you give me an example, Never made a repeating task before. I looked up a tutorial, but it didn't work. This is what I got so far: Code: @EventHandler public void onPlayerMove(final PlayerMoveEvent event) { _giants.getServer().getScheduler().scheduleSyncDelayedTask(_giants, new Runnable() { public void run() { Player player = event.getPlayer(); Location location = player.getLocation(); for (Entity entity : player.getNearbyEntities(5, 5, 5)) { if (API.isGiant(entity)) { if (entity.getNearbyEntities(5, 5, 5).contains(player)) { entity.getLocation().getWorld().createExplosion(location, 1F); } } } } }, 60L); }
You wouldn't want it in the move event, rather in onEnable. Otherwise it'll create a new repeating task each time the player moves.
That kind of worked... it delayed the explosions, but it still creates more than 1 explosion because the event is checked every time a player moves How can I delay the check of a PlayerMoveEvent?
Have a hashmap of Strings(player names) and booleans (for weather or not they were blown up) then in the player move event if the hashmap either doesn't contain the player's name or the boolean retrieved by it is set to true blow up the player and set the boolean in the hashmap for the player to false. Then schedule a delayed task and in that set the boolean value to true.
Instead of HashMap<String, Boolean> use a HashSet<String>, which means: when you would do .put(name, true);, you do .add(name); when you would do .put(name, false);, you do .remove(name); when you would do .get(name) == true, you do .contains(name);
Oh great, another thing I'm inexperienced with xD Would you mind showing me an example or a tutorial?
when they explode: Code:java yourHashSet.add(player.getName());when the task ends:[syntax=java]yourHashSet.remove(player.getName());if they should explode:[syntax=java]yourHashSet.contains(player.getName());[/syntax][/syntax]