[Method] Timed changing objective text! Scrolling text, Animations, & Flashing Colors!

Discussion in 'Resources' started by Phasesaber, Jun 4, 2014.

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

    Phasesaber

    Hi p.getName()! MOMOTHEREAL suggested I make something that changes the text on a scoreboard! So, I made this! (PS: I coded this on my iPad, I will fix any errors and post a picture when I get home)

    NEW Version:
    Code:java
    1.  
    2. int changeText = 0;
    3. public void changeText(final Objective o, long time, final String... text){
    4. Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable(){
    5. public void run(){
    6. if(changeText >= text.length)
    7. changeText = 0;
    8. o.setDisplayName(text[changeText]);
    9. changeText++;
    10. }
    11. }
    12. , 0, time);
    13. }
    14. [I][/I]

    Old Version:
    Code:java
    1.  
    Code:java
    1.  
    2. [I]public void changeText(Objective o, int time, String... text){[/I]
    3. [I]new Thread(new Runnable(){[/I]
    4. [I]public void run(){[/I]
    5. [I]while(true){[/I]
    6. [I]for(String s : text){[/I]
    7. [I]o.setDisplayName(s);[/I]
    8. [I]try{Thread.sleep(time);[/I]
    9. [I]}catch(Exception e){ e.printStackTrace);}[/I]
    10. [I]}[/I]
    11. [I]}[/I]
    12. [I]}).start();[/I]
    13. [I]}[/I]
    14. [I][/I]


    If there are any errors, please tell me!

    Scrolling:
    Code:java
    1.  
    Code:java
    1.  
    2. [I]Objective o = ...[/I]
    3. [I]changeText(o, 1000, "This is", "his is ", "is is r", "s is re", " is rea", "is real", "s reall", " really", "really ", "eally c", "ally co", "lly coo", "ly cool", "y cool!", " cool! ", "cool! ", "ool! ", "ol! ", "l! ", "! ", " ", " T", " Th", " Thi", " This", " This ", " This i");[/I]
    4. [I][/I]

    That will scroll the text: This is really cool! every second. It will also repeat itself.

    Animations:
    Code:java
    1.  
    Code:java
    1.  
    2. [I]changeText(o, 100, "-=( )=-", " -=( )=- ", " -=( )=- ", " -=()=- ");[/I]
    3. [I][/I]


    Color Changing:
    Code:java
    1.  
    Code:java
    1.  
    2. [I]changeText(o, 100, ChatColor.RED+"TEST", ChatColor.BLUE+"TEST", ChatColor.GREEN+"TEST");[/I]
    3. [I][/I]
     
  2. Offline

    BungeeTheCookie

    To me, this is completely inconvenient. It would be better if you could to changeText(o, 1000, "This is really cool.") Anyone can develop a method that uses a Runnable, but coding a library that could be used as.. let's say a "scroller" would be more unique.
     
    GrandmaJam and AoH_Ruthless like this.
  3. Offline

    Phasesaber

    BungeeTheCookie I understand that, but this is mainly used for changing the text, not just scrollers. I could make a little animation if I wanted to (I probs will). The scrolling was just an example. You could have update messages be there, a timer, anything!
     
  4. Offline

    unforgiven5232

    I have an idea, make a for loop and make it loop through every letter of the string and make it go through that method
     
  5. Offline

    Phasesaber

    unforgiven5232 It would just print: T h i s r e a l l y c o o l ! (With each letter being it's own string)
     
  6. Offline

    Comphenix

    For one, you shouldn't use a thread here. It is generally not safe to call the Bukkit API from a different thread, not to mention that it is really a waste of resources in this case. Threads are not cheap.

    You should read up on using the scheduler, in particular the repeating example.
     
  7. Offline

    Phasesaber

    I know how to use schedulers, I've just always perfered Threads. I'll change it later.

    If you scroll up 2 inches, it will be right there. With my response.

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

    unforgiven5232

    Phasesaber sorry man, I'm on my phone and I saw all the other posts except mine so I resent that.
     
  9. Offline

    AoH_Ruthless

    Phasesaber
    Instead of making a resource with an iPad, why not at least take the time to make it halfway decent and readable by coding it with Eclipse? No, formatting corruption due to Java Syntax is not an excuse. I can think of several options off the top of my head to fix formatting:

    • Github Gists
    • Pastebin
    • Hastebin (I guess the same thing, whatever)
    • Regular code syntax (Not very pretty to read, but it works and doesn't break formatting on each edit)
    But in all seriousness, I can't even give feedback on the content because I can't read the code.
     
  10. Offline

    Phasesaber

    AoH_Ruthless Oh god.... Not sure what happened there :p I'll fix it later.
     
  11. Offline

    Onlineids

    Skyost likes this.
  12. Offline

    Cirno

    He declares a new Thread(new Runnable()) above it; which means it'll be waiting on a different thread...
     
  13. Offline

    Onlineids

    Cirno I was talking about in general, and completely unnecessary with bukkits features.
     
Thread Status:
Not open for further replies.

Share This Page