Update a sign every second

Discussion in 'Plugin Development' started by EnveRuleZZ, Jan 17, 2015.

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

    EnveRuleZZ

    Hey Bukkit Community :D
    I am trying to make a sign update every second, but I just don't know what to do.
    I already tried with a Scheduler but I think I'm doing it wrong, because it doesn't work.
    It would be very very nice if someone could help me or even give me an example code...

    Thanks a lot.
    ~ EnveRuleZZ
     
  2. Why you wanna update the sign every second ?
     
  3. Offline

    EnveRuleZZ

    I want to make a clock on a sign which displays the real world time @MaTaMoR_
     
  4. You can do it with a runnable, it should work .
     
  5. Offline

    EnveRuleZZ

  6. Offline

    drpk

  7. Offline

    EnveRuleZZ

    Yes, I know how to use a scheduled task, but how do I change the line on the sign every second?
    .setLine is part of an Event so how would that work?
     
  8. Offline

    ChipDev

    .setLine is a sign method. Not a event.
     
  9. Offline

    EnveRuleZZ

    Could you give me an example code? I tried everything....
    Please @ChipDev :D

    @MaTaMoR_ Could you maybe give me an example code? :)

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

    MordorKing78

    @EnveRuleZZ
    Get an Scheduler I would recommend an Repeating Task. Repeat it every 20L ticks (= 1 second).
    Code:
                    Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
                            public void run() {
    //Your code here
                            }
                    }, 0, 20L);
     
  11. Offline

    EnveRuleZZ

    @MordorKing78 Thanks for your reply, it's very useful but could you give me an example how to change the line of a sign in the scheduled Sync repeated task. My problem is, I can't get the sign, because it doesn't fire an event... I hope you understand what I mean.... :D
     
  12. Offline

    MordorKing78

    @EnveRuleZZ Well, You could run it after your signchangevent..
     
  13. Offline

    EnveRuleZZ

  14. Offline

    Skionz

    @EnveRuleZZ Store the Sign however you like then get the sign from within the scheduler. No, I will not give you "Example code."
     
  15. Offline

    EnveRuleZZ

    How should I save the Sign? @Skionz
     
  16. Offline

    Skionz

    However you like.
     
  17. Offline

    EnveRuleZZ

    Right now, I have this code, but it doesn't seem to update:

    Code:
    @EventHandler
        public void onChange(SignChangeEvent event) {
            if (event.getLine(0).equalsIgnoreCase("[clock]")) {
                Sign s = (Sign) event.getBlock().getState();
                Bukkit.getServer()
                        .getScheduler()
                        .scheduleSyncRepeatingTask(
                                Bukkit.getPluginManager().getPlugin("BookshelfDrop"),
                                new Runnable() {
                                    public void run() {
                                        s.setLine(0, "§a" + dFormat.format(d));
                                        s.update(true);
                                    }
                                }, 0, 20L);
            }
        }
    @Krizeh
    @Skionz
     
  18. Offline

    Krizeh

    @EnveRuleZZ

    Once you set the line it will no longer be [clock] so your code won't run.
    Try
    Code:
    s.setLine(1, "§a" + dFormat.format(d));
     
  19. Offline

    EnveRuleZZ

    Wait, I want the time to update and I already have the same exact, code don't I? @Krizeh
     
  20. Offline

    Krizeh

    @EnveRuleZZz

    Your code is
    Code:
     s.setLine(0, "§a" + dFormat.format(d));
    But you're checking if the line 0 is [event]
    once you set line 0 to dFormat.format(d); line 0 will no longer be [event] and therefore it won't update.
     
  21. Offline

    EnveRuleZZ

    Hmm, still doesn't seem to update... @Krizeh
    Maybe it's because the plugin doesn't even check what the time is anymore, because everything is in SignChangeEvent...

    Code:
    @EventHandler
        public void onChange(SignChangeEvent event) {
            if (event.getLine(0).equalsIgnoreCase("[clock]")) {
                Sign s = (Sign) event.getBlock().getState();
                s.setLine(0, "[clock]");
                Bukkit.getServer()
                        .getScheduler()
                        .scheduleSyncRepeatingTask(
                                Bukkit.getPluginManager().getPlugin("BookshelfDrop"),
                                new Runnable() {
                                    public void run() {
                                        s.setLine(1, "§a" + dFormat.format(d));
                                        s.update();
                                    }
                                }, 0, 20L);
            }
        }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 13, 2016
  22. Offline

    Skionz

    @EnveRuleZZ Create a Set of Signs and iterate through them in a scheduler created when the onEnable method is invoked.
     
  23. Offline

    Krizeh

    @EnveRuleZZ

    Ahh, that's probably it.
    What @Skionz said would work for sure. Try doing that.
     
  24. Offline

    EnveRuleZZ

    What do you mean by create a Set of Signs? :oops: @Skionz
     
  25. Offline

    Skionz

    @EnveRuleZZ I mean create a new Set, set the generic type to Sign, add signs to it.
     
  26. Offline

    EnveRuleZZ

    I'm totally clueless....Can you or anyone else give me an example? :( @Skionz
     
  27. Offline

    teej107

  28. Offline

    EnveRuleZZ

    Thanks bro :D
    But how should I set the generic type to a Sign/Material?
    @teej107
     
  29. Offline

    Skionz

    @EnveRuleZZ Java is an obvious prerequisite to Bukkit. You can't learn to ride a bike before you learn to walk.
     
  30. Offline

    teej107

    @EnveRuleZZ Do you know how to make an ArrayList? (not saying you should, just asking) It's one of the popular Collections
     
Thread Status:
Not open for further replies.

Share This Page