AutoBow - PlayerInteractEvent

Discussion in 'Plugin Development' started by ShadowLAX, Jul 24, 2013.

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

    soulofw0lf

    Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new BukkitRunnable() {
    int count = 10;
    public void run() {
    player.launchProjectile(Arrow.class);
    count--;
    if (count >= 0 || player.getWalkSpeed() >= 0.2) {
    cancel();
    count = 10;
    }
    }
    }, 30L, 5L);


    replace with
    new BukkitRunnable(){
    int count = 10;
    @Override
    public void run(){
    player.launchProjectile(Arrow.class);
    count--;
    if (count >= 0 || player.getWalkSpeed() >= 0.2) {
    cancel();
    count = 10;

    return;
    }
    }

    }.runTaskTimer(plugin, 30, 5);
     
  2. Offline

    xTrollxDudex

  3. Offline

    soulofw0lf

    though shouldn't it also be if count <= 0 not >= ?
     
  4. Offline

    Tarestudio

    ShadowLAX
    I think, there is no use in canceling the Runnable, the scheduler will start the next after intervall... You have to build an (inner) class extending Runnable, so you can store the id and implement a method to set this id after creating the schedule.
    Here is an example, how that can look like: http://forums.bukkit.org/threads/cooldown.162006/#post-1767527
     
  5. Offline

    HepoSys

    Code:java
    1. @EventHandler
    2. public void onPlayerInteract(final PlayerInteractEvent event) {
    3. final Player player = event.getPlayer();
    4. if (player.getItemInHand().getType() == Material.BOW && player.hasPermission("elitefun.autobow")) {
    5. int schedule1;
    6. class AutoBowTask implements Runnable {
    7. EliteFun plugin;
    8. int schedule;
    9. //Number of arrows it shoots
    10. int count = 20;
    11.  
    12. AutoBowTask(EliteFun p_plugin) {
    13. plugin = p_plugin;
    14. }
    15. @Override
    16. public void run(){
    17. player.launchProjectile(Arrow.class);
    18. count--;
    19. if(count <= 0) {
    20. plugin.getServer().getScheduler().cancelTask(schedule);
    21. }
    22. }
    23.  
    24. public void setSchedule(int p_schedule) {
    25. schedule = p_schedule;
    26. }
    27. }
    28. AutoBowTask task = new AutoBowTask(plugin);
    29. schedule1 = plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, task, 1, 1);
    30. task.setSchedule(schedule1);
    31. }
    32. }


    Enjoy,
     
Thread Status:
Not open for further replies.

Share This Page