Solved Delay between actions

Discussion in 'Plugin Development' started by loman, Feb 26, 2020.

  1. Offline

    loman

    Hi there everyone
    I am new to the plugin so I don't know how can I make a countdown between commands and commands : (
    Can anyone give me some advice or make me a sample to see? : )
    I want to add a 1-second countdown between the two potion effect
    What should I do : )

    Code:
        @EventHandler
        public void onBowShot(EntityShootBowEvent e) {
    
            Player player = (Player) e.getEntity();
    
            if (e.getEntity() instanceof Player && e.getProjectile() instanceof Arrow) {
                player.addPotionEffect(new PotionEffect(PotionEffectType.LEVITATION, 20, 6));
                player.addPotionEffect(new PotionEffect(PotionEffectType.LEVITATION, 20, 6));
            }
        }
     
  2. Online

    timtower Moderator Moderator

    @loman Make a BukkitRunnable.
    Run it 20 ticks later with runTaskLater.
    Put everything you want to delay in it.
     
  3. Offline

    loman

    @timtower
    Am I doing right on the BukkitRunable?
    I'm sorry to disturb you : (
    But I need your help very much : )
    And thank you for your generous help anyway

    Code:
        @EventHandler
        public void onBowShot(EntityShootBowEvent e) {
    
            Player player = (Player) e.getEntity();
          
            if (e.getEntity() instanceof Player && e.getProjectile() instanceof Arrow) {
                player.addPotionEffect(new PotionEffect(PotionEffectType.LEVITATION, 20, 6));
                new BukkitRunnable(){
                    @Override
                    public void run() {
                        player.addPotionEffect(new PotionEffect(PotionEffectType.LEVITATION, 20, 254));
                        this.cancel();
                    }
                }.runTaskTimer(this,20L);
    
            }
        }
     
  4. Online

    timtower Moderator Moderator

    You asked a question, I responded on a forum that is made for this. No need to be sorry.
    runTaskLater, not runTaskTimer.
    Then you don't need the cancel.
     
  5. Offline

    loman

    @timtower
    so doing like this will be fine ?
    But why when I shoot an arrow and there is nothing happened? : )
    Maybe some of my commands are wrong?

    Code:
        @EventHandler
        public void onBowShot(EntityShootBowEvent e) {
    
            Player player = (Player) e.getEntity();
    
            if (e.getEntity() instanceof Player && e.getProjectile() instanceof Arrow) {
                player.addPotionEffect(new PotionEffect(PotionEffectType.LEVITATION, 20, 6));
                new BukkitRunnable(){
                    @Override
                    public void run() {
                        player.addPotionEffect(new PotionEffect(PotionEffectType.LEVITATION, 20, 254));
                    }
                }.runTaskLater(this,20L);
    
            }
        }
     
    Last edited: Feb 26, 2020
  6. Online

    timtower Moderator Moderator

    @loman Probably, did you test it?
     
  7. Offline

    loman

    @timtower
    Yes, But just when I shoot an arrow out
    It supposed I have LEVITATION effects
    However I don't get any of these
    Maybe some of my commands are wrong? :thinking:
     
  8. Online

    timtower Moderator Moderator

    Did you register the event?
    Does the event get called?
    Are your checks working?
     
  9. Offline

    loman

    @timtower
    I have register the event inside the plugin.yml file already by the following codes
    Code:
    name: JumpShoot
    main: com.blackhat.jumpshoot.main
    version: 1.0
    description: jump and shoot
    author: BlackHat707
    But how can I know if the event gets called? : )

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Feb 26, 2020
  10. Online

    timtower Moderator Moderator

    @loman Please post your onEnable
    And you do that by sending a message to the server.
     
  11. Offline

    loman

    @timtower
    onEnbale:
    Code:
    @Override
        public void onEnable() {
            getLogger().info("Hello World!");
        }
    [23:24:17 INFO]: [JumpShoot] Enabling JumpShoot v1.0
    [23:24:17 INFO]: [JumpShoot] Hello World!
     
  12. Online

    timtower Moderator Moderator

  13. Offline

    KarimAKL

    @loman Is the method inside the main class, or is it in another class?
     
  14. Offline

    loman

    I just open 1 class : )
    so it should be in the main one
     
  15. Offline

    KarimAKL

    @loman Okay, i just wanted to make sure because the BukkitRunnable requires the main class instance.

    Did you register the listener as @timtower told you? If so, did you get it working or do you still have issues?
     
  16. Offline

    loman

Share This Page