Util [Color Scroll+] Scroll some color in your text!

Discussion in 'Resources' started by xXBeLkAXx, Dec 27, 2014.

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

    xXBeLkAXx

    ColorScroll+
    Hello, guys! I searched a lot for this util, and can't find it, so, I make it myself. I thought, it will be hard, to make this util, but it was pretty simple! So, how it is looking:

    1.Scoreboard example

    [​IMG]

    2.Title example

    [​IMG]

    3. Scoreboard example [x2]
    [​IMG]

    4. Boss bar example
    [​IMG]


    CODE:

    Code:
    package me.belka.barmessage;
    
    import org.bukkit.ChatColor;
    
    public class ColorScrollPlus
    {
        private int position;
        private String str;
        private String colorBefore;
        private String colorAfter;
        private String colorMid;
        private boolean bold;
        private ChatColor textColor;
        private boolean upperCaseMid;
        private ScrollType scrollType;
       
        public ColorScrollPlus(ChatColor textColor, String str, String colorMid, String colorBefore, String colorAfter, boolean bold, boolean upperCaseMid, ScrollType scrollType) {
            this.str = str;   
            this.colorMid = colorMid;
            this.bold = bold;
            this.colorBefore = colorBefore;
            this.colorAfter = colorAfter;
            this.textColor = textColor;
            this.upperCaseMid = upperCaseMid;
            this.scrollType = scrollType;
            this.position = scrollType == ScrollType.FORWARD ? -1 : str.length();
        }
       
        public enum ScrollType {
            FORWARD, BACKWARD;
        }
       
        public String getString() {
            return str;
        }
       
        public String next() {
           
            if(position >= str.length()) {
                String one = str.substring(position - 1, str.length() - 1);
           
                if(bold) {
                    String two = upperCaseMid ? colorMid + ChatColor.BOLD + one.toUpperCase() : colorMid + ChatColor.BOLD + one;
                    String fin = textColor + "" + ChatColor.BOLD + str.substring(0, str.length() - 1) +
                            colorBefore + ChatColor.BOLD +
                            str.substring(str.length() - 1, str.length()) + two;
                   
                    if(getScrollType() == ScrollType.FORWARD) {
                        position = -1;
                    } else {
                        position--;
                    }
                   
                    return fin;
                } else {
                    String two = upperCaseMid ? colorMid + one.toUpperCase() : colorMid + one;
                    String fin = textColor + str.substring(0, str.length() - 1) +
                            colorBefore + str.substring(str.length() - 1, str.length()) + two;
                   
                    if(getScrollType() == ScrollType.FORWARD) {
                        position = -1;
                    } else {
                        position--;
                    }
                   
                    return fin;
                }
            }
       
            if(position <= -1) {
               
                if(getScrollType() == ScrollType.FORWARD) {
                    position++;
                } else {
                    position = str.length();
                }
               
                if(bold) {
                    return colorBefore + ChatColor.BOLD + str.substring(0, 1) + textColor + ChatColor.BOLD + str.substring(1, str.length());   
                } else {
                    return colorBefore + str.substring(0, 1) + textColor + str.substring(1, str.length());       
                }
            }   
               
            if(position == 0) {
                String one = str.substring(0, 1);
           
                if(bold) {
                    String two = upperCaseMid ? colorMid + ChatColor.BOLD + one.toUpperCase() : colorMid + ChatColor.BOLD + one;
                    String fin = two + colorAfter + ChatColor.BOLD +
                            str.substring(1, 2) + textColor + ChatColor.BOLD +
                            str.substring(2, str.length());
    
                    if(getScrollType() == ScrollType.FORWARD) {
                        position++;
                    } else {
                        position--;
                    }
                   
                    return fin;
                } else {
                    String two = upperCaseMid ? colorMid + one.toUpperCase() : colorMid + one;
                    String fin = two + colorAfter +
                            str.substring(1, 2) + textColor +
                            str.substring(2, str.length());
    
                    if(getScrollType() == ScrollType.FORWARD) {
                        position++;
                    } else {
                        position--;
                    }
                   
                    return fin;
                }
            }
       
            if(position >= 1) {
                String one = str.substring(0, position);
                String two = str.substring(position + 1, str.length());
           
                if(bold) {
                    String three = upperCaseMid ? colorMid + ChatColor.BOLD + str.substring(position, position + 1).toUpperCase() : colorMid + ChatColor.BOLD + str.substring(position, position + 1);
                    String fin = null;
               
                    int m = one.length();
                    int l = two.length();
                   
                    String first = m <= 1 ? colorBefore + ChatColor.BOLD + one : ChatColor.BOLD + one.substring(0, one.length() - 1) + colorBefore +
                        ChatColor.BOLD + one.substring(one.length() - 1, one.length());
               
                    String second = l <= 1 ? colorAfter + ChatColor.BOLD + two :
                        colorAfter + ChatColor.BOLD + two.substring(0, 1) +
                        textColor + ChatColor.BOLD + two.substring(1, two.length());
                   
                    fin = textColor + first + three + second;
                   
                    if(getScrollType() == ScrollType.FORWARD) {
                        position++;
                    } else {
                        position--;
                    }
                   
                    return fin;
               
                } else {
                    String three = upperCaseMid ? colorMid + str.substring(position, position + 1).toUpperCase() : colorMid + str.substring(position, position + 1);
               
                    String fin = null;
               
                    int m = one.length();
                    int l = two.length();
                   
                    String first = m <= 1 ? colorBefore + one : one.substring(0, one.length() - 1) + colorBefore +
                            one.substring(one.length() - 1, one.length());
                   
                    String second = l <= 1 ? colorAfter + two :
                        colorAfter + two.substring(0, 1) +
                        textColor + two.substring(1, two.length());
                   
                    fin = textColor + first + three + second;
               
                    if(getScrollType() == ScrollType.FORWARD) {
                        position++;
                    } else {
                        position--;
                    }
                   
                    return fin;
                }
            }
           
            return null;
        }
       
        public int getPosition() {
            return position;
        }
       
        public void setPosition(int position) {
            this.position = position;
        }
       
        public int stringLength() {
            return str.length();
        }
    
        public ChatColor getTextColor() {
            return textColor;
        }
    
        public void setTextColor(ChatColor textColor) {
            this.textColor = textColor;
        }
    
        public boolean isUpperCaseMid() {
            return upperCaseMid;
        }
    
        public void setUpperCaseMid(boolean upperCaseMid) {
            this.upperCaseMid = upperCaseMid;
        }
    
        public ScrollType getScrollType() {
            return scrollType;
        }
    
        public void setScrollType(ScrollType scrollType) {
            this.scrollType = scrollType;
        }
       
    }
    Code:
    ColorScrollPlus cs = new ColorScrollPlus(ChatColor.RED, // All text color
    "The Vertex Network",  // Text, what you want to achieve
    "§6", // Middle letter color
    "§c",  // Left shadow color
    "§e",  // Right shadow color
    true, // Do you want to get String bold or not
    true, // Set middle letter to upper case like in titles or not
    ScrollType.FORWARD); // Scroll type. Where do you want to scroll? Forward or backward? 
    Of course, an example with titles (TitleManager - http://www.spigotmc.org/resources/titlemanager.1049/):

    Code:
    final ColorScrollPlus cs = new ColorScrollPlus(ChatColor.GREEN, "color scroll", "§6", "§e", "§e", true, true, ScrollType.FORWARD);
    
            TitleManager.sendTimings(e.getPlayer(), 0, 3, 20);
    
            Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new BukkitRunnable() {
    
                @Override
                public void run() {
        
                    if(cs.getPosition() >= cs.stringLength()) {
                        return;
                    }
        
                    TitleManager.sendTitle(e.getPlayer(), "{\"text\":\"\",\"extra\":[{\"text\":\"" + cs.next() + "\"}]}");
                    TitleManager.sendSubTitle(e.getPlayer(), "{\"text\":\"\",\"extra\":[{\"text\":\"Welcome to the Survival World!\",\"color\":\"dark_aqua\"}]}");
                }
    
            }, 0, 2);
    And example with scoreboard (third gif):

    Code:
        @EventHandler
        public void onJoin(final PlayerJoinEvent e) {
        
            final ColorScrollPlus cs = new ColorScrollPlus(ChatColor.GREEN, "PAINTBALL", "§c", "§6", "§e", true, false, ScrollType.FORWARD);
        
            final ScoreboardAPI sbAPI = new ScoreboardAPI(cs.next(), e.getPlayer().getName());
        
            final int players = Bukkit.getOnlinePlayers().length;
        
            sbAPI.blankLine(); // 4
            sbAPI.add("§6§lPlayers online:"); // 3
            sbAPI.add("§a" + players); // 2
            sbAPI.blankLine(); // 1
            sbAPI.build();
        
            sbAPI.send(e.getPlayer());
        
            new BukkitRunnable() {
            
                public void run() {
                
                    if(cs.getScrollType() == ScrollType.FORWARD) {
                        if(cs.getPosition() >= cs.getString().length()) {
                            cs.setScrollType(ScrollType.BACKWARD);
                        }
                    } else {
                        if(cs.getPosition() <= -1) {
                            cs.setScrollType(ScrollType.FORWARD);
                        }
                    }
                
                    sbAPI.setTitle(cs.next());
                    sbAPI.replace(sbAPI.getByScore(2), "§a" + Bukkit.getOnlinePlayers().length);
                }
            
            }.runTaskTimer(this, 0, 3);
        
        }
    P.S ScoreboardAPI is my own class for scoreboard. But, I think, you are logical people, and can understand part of the join method, what we need, to scroll string forward or backward ;)

    Thanks for watchin'! ;)
     
    Last edited: Apr 19, 2015
  2. Offline

    Monkey_Swag

  3. Offline

    xXBeLkAXx

    But... I don't know why it is not working :D It's a gif.
     
  4. Offline

    Assist

  5. Offline

    xXBeLkAXx

  6. Offline

    Monkey_Swag

    Last edited: Dec 29, 2014
    GrandmaJam likes this.
  7. Offline

    xXBeLkAXx

    GrandmaJam likes this.
  8. Offline

    Freelix2000

    Cool! I made something like this for my server a long time ago, its actually fun to code. Maybe I should do it again some time. =P
     
    GrandmaJam likes this.
  9. Offline

    xXBeLkAXx

    UP! Code update! A new util, what scrolls color in other way, and looks beautiful!
     
    GrandmaJam likes this.
  10. Offline

    GrandmaJam

    Amazing! Going to use this with the new 1.8 tab-list.
     
    Last edited by a moderator: Jan 14, 2015
    ChipDev likes this.
  11. Offline

    ChipDev

    Smart!
     
    GrandmaJam likes this.
  12. Offline

    xXBeLkAXx

    Code update!
    - Fixed some small bugs
    - Added upper case middle letter mode
    - Added all text color
     
    GrandmaJam likes this.
  13. Offline

    GrandmaJam

    What happened to the example for the scoreboard?
     
  14. Offline

    xXBeLkAXx

    Title example broken :( Fix it now...
     
    GrandmaJam likes this.
  15. Offline

    ArthurHoeke

    When can you make the example?
     
  16. Offline

    xXBeLkAXx

    @ArthurHoeke Don't you see? All example you can see in title for 1 .8 versions example, so, I think, you can make a scoreboard code from this, don't you? If not, tell me, I will rewrite a code
     
  17. Offline

    ArthurHoeke

    Did it :D Have a question tho, how to let the color go backwards and let for example after 1 time forward and 1 time backward the scoreboard title change color a couple of times?
     
  18. Offline

    xXBeLkAXx

    @ArthurHoeke Oh, I'm sorry, I don't made scrolling to left :c
     
  19. Offline

    ArthurHoeke

    Can you please add a feature for that?
     
  20. Offline

    xXBeLkAXx

  21. Offline

    ArthurHoeke

    Are you going to add it / when do you think you release it? Or if you don't, how to do it myself?
     
  22. Offline

    xXBeLkAXx

  23. Offline

    ArthurHoeke

    You're awesome! Thank you!
     
  24. Offline

    xXBeLkAXx

  25. Offline

    VinexAx789

    I need help mine keeps freezing: http://gyazo.com/4492b29d725ef93b6de51e4d35fdbd78

    Here's my code:

    Code:
    @EventHandler
            public void onJoin(final PlayerJoinEvent e) {
           
                final ColorScrollPlus cs = new ColorScrollPlus(ChatColor.RED, "GETREKTMC", "§f", "§4", "§e", true, false, ScrollType.FORWARD);
              
                ScoreboardManager manager = Bukkit.getScoreboardManager();
                Scoreboard sb = manager.getNewScoreboard();
                final Objective obj = sb.registerNewObjective("this", "that");
                obj.setDisplaySlot(DisplaySlot.SIDEBAR);
              
                Score score = obj.getScore(" ");
                score.setScore(1);
              
                e.getPlayer().setScoreboard(sb);
              
                new BukkitRunnable() {
                  
                    public void run() {
                   
                        if(cs.getScrollType() == ScrollType.FORWARD) {
                            if(cs.getPosition() >= cs.getString().length()) {
                                cs.setScrollType(ScrollType.BACKWARD);
                            }
                        } else {
                            if(cs.getPosition() <= -1) {
                                cs.setScrollType(ScrollType.FORWARD);
                            }
                        }
                   
                        obj.setDisplayName(cs.next());
                    }
               
                }.runTaskTimer(this, 0, 3);
           
            }
    @xXBeLkAXx That scoreboard API would be nice ;)
     
    Last edited by a moderator: Apr 12, 2015
  26. Offline

    xXBeLkAXx

    @VinexAx789 But... What's the problem? In my gif scoreboard is scrolling same as yours c:
     
  27. Offline

    VinexAx789

    @xXBeLkAXx Mine freezes...

    @xXBeLkAXx Like it works but it will start to stop at the end and freeze then it will go again. Is there anyway I can do it like Mineplex has theirs and Hypixel? Will you ever release your ScoreboardAPI because that will make life easier xD

    @xXBeLkAXx Look http://gyazo.com/70d6857ac9ecfcdd09a2af0b11541be3 It's freezing/skippy

    Here's my code:
    Code:
            @SuppressWarnings("deprecation")
                        @EventHandler(priority = EventPriority.HIGHEST)
                        public void onPlayerJoin(final PlayerJoinEvent e) {
                        final ColorScrollPlus cs = new ColorScrollPlus(
                                ChatColor.RED, "GETREKTMC", "§f", "§4", "§e", true,
                                false, ScrollType.FORWARD);
    
                        ScoreboardManager manager = Bukkit.getScoreboardManager();
                        Scoreboard sb = manager.getNewScoreboard();
                        final Objective obj = sb.registerNewObjective("this",
                                "that");
                        obj.setDisplaySlot(DisplaySlot.SIDEBAR);
    
                        Score score = obj.getScore(ChatColor.GREEN
                                + "Gamers In Hub:");
                        score.setScore(Bukkit.getOnlinePlayers().length);
    
                        e.getPlayer().setScoreboard(sb);
    
                        new BukkitRunnable() {
    
                            public void run() {
    
                                if (cs.getScrollType() == ScrollType.FORWARD) {
                                    if (cs.getPosition() >= cs.getString().length()) {
                                        cs.setScrollType(ScrollType.BACKWARD);
                                    }
                                } else {
                                    if (cs.getPosition() <= -1) {
                                        cs.setScrollType(ScrollType.FORWARD);
                                    }
                                }
    
                                obj.setDisplayName(cs.next());
                            }
    
                        }.runTaskTimer(this, 0, 3);
                    }
        
    EDIT by Timtower: merged posts
     
    Last edited by a moderator: Apr 13, 2015
  28. Offline

    xXBeLkAXx

    @VinexAx789 Hmm... I saw it on my server when the internet was not good. Are you making it at the local server?

    @VinexAx789 Oh, wait. You want scroll it, and then freeze for x secs?

    @VinexAx789 Just search for this class in resources. I simply modified it in some places, that's all :)

    EDIT by Timtower: merged posts
     
    Last edited by a moderator: Apr 13, 2015
  29. Offline

    timtower Moderator Moderator

    To all:
    Please use the edit button instead of double or triple posting.
     
    bwfcwalshy likes this.
  30. Offline

    VinexAx789

    @xXBeLkAXx No I want it not to FREEZE + I'm running off a host.

    @timtower No offence but I can't even tell what he is trying to say to me since you merged the posts.
     
    Last edited by a moderator: Apr 19, 2015
Thread Status:
Not open for further replies.

Share This Page