Solved Multiple Bukkit getScheduler events

Discussion in 'Plugin Development' started by ShadowSplicer, Sep 18, 2013.

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

    ShadowSplicer

    Hey all,

    I've been running my own server for a couple years now, and finally am getting into developing plugins myself. I started last week, and have been picking things up pretty quickly from the Forums and other resources, but I can't seem to find more information on
    Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable(){ }, #L);

    I need to create a list of timed events related to playSound, and it works, but I've only figured out how to make separate getScheduler blocks; it's a LOT of redundant code.

    This is what it looks like now:
    Code:java
    1. @EventHandler(priority = EventPriority.NORMAL)
    2. public void onPlayerCauseTeleport(PlayerTeleportEvent event) {
    3. final TeleportCause cause = event.getCause();
    4. if(cause.equals("END_PORTAL|ENDER_PEARL|NETHER_PORTAL")) {
    5. final Player player = event.getPlayer();
    6. final Location teleportTo = event.getTo();
    7. Bukkit.getWorld(player.getWorld().getName()).playSound(teleportTo, Sound.ENDERMAN_TELEPORT, 10, 0);
    8. Bukkit.getWorld(player.getWorld().getName()).playEffect(teleportTo, Effect.ENDER_SIGNAL, 2003);
    9. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
    10. public void run() {
    11. Bukkit.getWorld(player.getWorld().getName()).playEffect(teleportTo, Effect.ENDER_SIGNAL, 2003);
    12. }
    13. }, 10L);
    14. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
    15. public void run() {
    16. Bukkit.getWorld(player.getWorld().getName()).playEffect(teleportTo, Effect.ENDER_SIGNAL, 2003);
    17. }
    18. }, 20L);


    Is there a way to create multiple timed events within a parent getScheduler? I've searched all around, with no avail. Hope my question isn't completely stupid ;)

    Thanks, community!

    Okay, just as I exited my forum post, I saw this next to mine:
    http://forums.bukkit.org/threads/is-there-a-way-to-slowdown-sounds.175369/

    To clarify, even if this is the solution for sounds, I still need help with getting timed scheduler events running efficiently.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  2. Offline

    chasechocolate

  3. Offline

    ShadowSplicer

    Posting a link without explaining isn't really helping me. I read it through a few times, and tried it out, but can't figure out how to get it working like this. I'm still new to Java, so explaining something would be great. I get the concept, but not quite how to add the stuff I want to run into it. What kind of code is this referencing? A class? A type? I need more info here please...
    BukkitTask task = new ExampleTask(this.plugin).runTaskLater(this.plugin, 20);
     
  4. Offline

    Aengo

    You could use a repeating task, and make a 'counter' with it; say every 10 ticks it will add one to the counter value. Then once the counter value is what you want you could call the playsound method and reset the counter value, or obviously tailor it to your liking.

    As for the posting a link and it being vague, I agree because when I started out it happened to me. So if you need help feel free to PM me. :)
     
  5. Offline

    ShadowSplicer

    Thank you, Aengo. I'll PM ya with a couple simple questions :) This will really help me out!
    I'll mark this as "Solved", and then post back here when I figure it out, to help out aimless Googlers.
     
Thread Status:
Not open for further replies.

Share This Page