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

    Yes, I know how to use ArrayLists. Would this work with an ArrayList? @teej107 @Skionz
     
  2. Offline

    teej107

    Generic type is the object you specify in the diamond like when using an ArrayList.
     
  3. Offline

    EnveRuleZZ

    How do Sets work? I tried:

    Code:
    Set<Material> set = new HashSet<Material>();
           
            Material mat = Material.SIGN;
            set.add(mat);
            Iterator<Material> iterator = set.iterator();
    
            while(iterator.hasNext()){
              Material aMat = iterator.next();
            }
    But I really don't know what I'm doing @teej107 @Skionz

    Please anyone? *Bump*

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

    teej107

    @EnveRuleZZ They are just like using a List. A difference being is that there is no get() method.
     
  5. Offline

    Burnett

    @EnveRuleZZ Firstly I would like to ask when you expect this event to fire. "SignChangeEvent" is triggered when the sign changes. I'll get the obvious out of the way first. Are you running this expecting it to change a sign that has already been placed, or are you placing a sign and then wanting it to start the timer. Next you check if line 0 on the sign is "[clock]" if it is you proceed to set line 0 of the sign to "[clock]" (all the logic here). Next you need to add a debug message, check where it gets to. Another pointer for checking if the sign is "[clock]", if you have a space on that line it wont work (as far as ik from an old plugin, correct me if I'm being dumb) try using getLine(n).toLowerCase().contains(string).

    Edit: Linking in with the when do you expect it to trigger, are you wanting these signs to start a timer on server start, command executed, even triggered etc... If you don't want to have to create them again each time you will need to save them into a config file, using the signs location. At start up load these signs and store them in a Set as stated before. Why a set you ask, well a Set does not allow any duplicate elements in it so if your config system is flawed then it wont load multiple signs into the Set.
     
    Last edited: Jan 20, 2015
  6. replace Bukkit.getPluginManager().getPlugin("BookshelfDrop") with your main class (which extends JavaPlugin).
    set the date to the second line (1 not 0) because there is [clock] on the first line already
     
  7. Offline

    EnveRuleZZ

    @Burnett Thank you very much for your response :)
    Basically, your solution would just be perfect. I'm really sorry to say this, but I just don't know how to do this thing with Sets and so... :(
    Hope you can help me :D
     
  8. Offline

    CraftCreeper6

    @EnveRuleZZ
    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);
            }
        }
    Would work. You just need to create an instance of your main class and pass it to the scheduler. If you don't know how. You should really learn Java first.
     
  9. Offline

    EnveRuleZZ

    Well, I guess I do not understand what exactly you mean. What sense would that have? I want the sign to update constantly every second. @CraftCreeper6
     
  10. Offline

    EnveRuleZZ

  11. Offline

    mythbusterma

  12. Offline

    Tecno_Wizard

  13. Offline

    EnveRuleZZ

    Come on man, I know that this code updates every second.... I want it to be triggered all the time not only at a SignChangeEvent... do you know what I mean? I do know Java and I watched several tutorials before even starting with it.... @Tecno_Wizard @mythbusterma
     
  14. Offline

    Tecno_Wizard

    @EnveRuleZZ, you need to watch more. A lot more. For goodness sake you didn't even know how to use a set. If it sounds like i'm angry I'm not. I'm just trying to prove a point. I took a year of java courses before working with Bukkit.
     
  15. Offline

    ChipDev

    Last edited: Jan 24, 2015
  16. Offline

    EnveRuleZZ

    Okay, well you're right I'm gonna take some lessons :) That website seems to be good thank you :) @Tecno_Wizard
     
  17. Offline

    Tecno_Wizard

    @EnveRuleZZ, not a problem. We always encourage people to program, but Bukkit requires intermediate skills, which those videos should give you. That site has some more advanced videos too that I still watch. And please watch the language.
    I decomplied your posted plugin to look over things. It really shows that you're inexperienced.
     
  18. Offline

    ChipDev

    I really mean it.
    Runnable {
    New location
    if sign block state
    set lines
    }20 ticks
     
  19. Offline

    EnveRuleZZ

    Yes, @ChipDev I just don't know when I should trigger it!
     
  20. Offline

    Gater12

    @EnveRuleZZ
    Triggered everytime? It's triggered when it needs to be triggered and that is when a new your 'special sign' is placed. To keep it persistent, you need to store your 'special sign' somewhere when your plugin is disabled, and then check on start up and schedule a task to update all your 'special signs'. You could have one 'central' repeating task dedicated to updating all your 'special signs' (where your 'special signs' are stored in a Collection of somesort).
     
Thread Status:
Not open for further replies.

Share This Page