Help with Animate Sign to make my plugin

Discussion in 'Spigot Plugin Development' started by KhoaHoangVN, Jun 25, 2016.

  1. Hello, I'm currently working on The Herobrine plugin. :)
    I want to make an animated sign pls.
    And import the frames in the config like:
    Code (Text):
    signAnimation:
      time: 3
      frames: 2
      animation:
         frame1:
         - 'This is line 1'
         - 'This is line 2'
         - 'This is line 3'
         - 'This is line 4'
         frame2:
         - ''
         - ''
         - 'No content'
         - 'LOL'
     
  2. Choco

    Moderator

    You'll need a BukkitRunnable, and a location for what sign you want to modify. The Sign class has .setLine() method in which you can change lines to whatever you want.
     
  3. I don't feel like explaining, so here is some example code. (sorry for the spood-feed I just feel lazy :p)

    NOTE - I didn't test this what-so-ever so this may or may not work (but it should work)

    Code (Text):
        private HashMap<Sign, Integer> frame = new HashMap<Sign, Integer>();
        public void animate(Sign sign) {
        frame.put(sign, 1);
            new BukkitRunnable() {

                @Override
                public void run() {
                    int frames = getConfig().getInt("signAnimation.frames");
                        sign.setLine(0, getConfig().getStringList("signAnimation.animation.frame" + Integer.toString(frame.get(sign))).get(1));
                        sign.setLine(1, getConfig().getStringList("signAnimation.animation.frame" + Integer.toString(frame.get(sign))).get(2));
                        sign.setLine(2, getConfig().getStringList("signAnimation.animation.frame" + Integer.toString(frame.get(sign))).get(3));
                        sign.setLine(3, getConfig().getStringList("signAnimation.animation.frame" + Integer.toString(frame.get(sign))).get(4));
                        frame.put(sign, frame.get(sign) + 1);
                        if (frame.get(sign)==frames) {
                            frame.remove(sign);
                            this.cancel();
                            return;
                        }
                 
                }
             
            }.runTaskTimer(this, 0, getConfig().getInt("signAnimation.time"));
        }
    EDIT - Basically what the almighty coding god @2008Choco said, except I probably did something wrong :c
     
  4. May I just add that when animating anything, also note not to animate it if there are no players around to see it. So doing a quick entity check around the signs location will be a good thing. And try not to animate the sign when the chunk it's in isn't loaded. Those are two thing to keep in mind when making this sort of thing and I hope you don't skip them
     
    • Like Like x 1
    • Agree Agree x 1
  5. @LeePMC yes those are two keen factors to keep in mind. I was just assuming that players would be watching, but if not follow what he said :)
     
  6. Thanks!
    Anyway do you want the plugin minigame - The Herobrine - release? It's gonna great! :D