Solved Need help for a delay

Discussion in 'Plugin Development' started by Stupeflip, Mar 16, 2014.

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

    Stupeflip

    Hello there is no errors here but it won't work, a man tell me that I must add a delay but i don't know how, can you please help me?

    Code:java
    1. // Message on server start (french)
    2. public class UltraHardOpium extends JavaPlugin implements Listener {
    3. private Logger logger = Logger.getLogger("Minecraft");
    4. public void onEnable() {
    5. getServer().getPluginManager().registerEvents(this, this);
    6. logger.info("[UltraHard] Plugin operationnel");}
    7.  
    8. // Add effects to the player after he die and boost his life to the maximum
    9. @EventHandler
    10. public void onPlayerRespawn(final PlayerRespawnEvent r){
    11. final Player player = r.getPlayer();
    12. player.addPotionEffect(new PotionEffect(PotionEffectType.HEALTH_BOOST, Integer.MAX_VALUE, 9));
    13. player.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, Integer.MAX_VALUE, 2));
    14. player.setHealth(player.getMaxHealth());
    15. player.sendMessage("[Respawn] Vous gagnez 30 coeurs et de la resistance, bon jeu!");}
    16.  
    17. // Checking if this is the first join of a player and add him effects and boost his life to the maximum
    18. @EventHandler
    19. public void firstJoinDetection(PlayerJoinEvent fj)
    20. {
    21. Player player = fj.getPlayer();
    22. boolean existingPlayer = player.hasPlayedBefore();
    23. if (!existingPlayer) {
    24. player.addPotionEffect(new PotionEffect(PotionEffectType.HEALTH_BOOST, Integer.MAX_VALUE, 9));
    25. player.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, Integer.MAX_VALUE, 2));
    26. player.setHealth(player.getMaxHealth());
    27. player.sendMessage("Vous gagnez 30 coeurs et de la resistance, bon jeu!");}
    28. return;}
    29.  
    30. // Message on server close (french)
    31. public void onDisable() {
    32. logger.info("[UltraHard]: Extinction des feux...");}}

    sorry for my bad english
    thanks you
     
  2. Offline

    Gater12

  3. Offline

    Compressions

    Stupeflip likes this.
  4. Offline

    Stupeflip

    Gater12
    I had tried with this but there is errors:
    Code:java
    1. // Add effects to the player after he die and boost his life to the maximum
    2. @EventHandler
    3. public void onPlayerRespawn(final PlayerRespawnEvent r){
    4. Bukkit.getScheduler().scheduleSyncDelayedTask(UltraHardOpium, new Runnable() {
    5. @Override
    6. public void run() {
    7. final Player player = r.getPlayer();
    8. player.addPotionEffect(new PotionEffect(PotionEffectType.HEALTH_BOOST, Integer.MAX_VALUE, 9));
    9. player.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, Integer.MAX_VALUE, 2));
    10. player.setHealth(player.getMaxHealth());
    11. player.sendMessage("[Respawn] Vous gagnez 30 coeurs et de la resistance, bon jeu!");
    12. }, 200);}
    13.  
    14. // Checking if this is the first join of a player and add him effects and boost his life to the maximum
    15. @EventHandler
    16. public void firstJoinDetection(PlayerJoinEvent fj)
    17. {
    18. Player player = fj.getPlayer();
    19. boolean existingPlayer = player.hasPlayedBefore();
    20. if (!existingPlayer) {
    21. player.addPotionEffect(new PotionEffect(PotionEffectType.HEALTH_BOOST, Integer.MAX_VALUE, 9));
    22. player.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, Integer.MAX_VALUE, 2));
    23. player.setHealth(player.getMaxHealth());
    24. player.sendMessage("Vous gagnez 30 coeurs et de la resistance, bon jeu!");}
    25. return;}


    Compressions
    The man said that i need a delay for potion effect on respawn ^^
    Because when i respawn it show me the message but don't apply effects

    Thanks for helping me and sorry for my english!

    Push

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
Thread Status:
Not open for further replies.

Share This Page