Advertisement
retrodaredevil

RainbowText [(Minecraft Plugin) API] 1.0.1

Feb 1st, 2016
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. package com.yoshiplex.rainbow;
  2.  
  3. import java.util.Arrays;
  4. import java.util.List;
  5.  
  6. public class RainbowText {
  7. private int place = 0;
  8. private String text = "You did not provide any text.";
  9. private String fancyText = "";
  10. private static final List<String> RAINBOW = Arrays.asList("§4", "§c", "§6", "§e", "§a", "§2", "§b", "§3" /**/, "§9", "§1",/**/ "§5", "§d"); // size is 12
  11. private List<String> rainbowArray = null;
  12. private String prefix = "";
  13.  
  14. public RainbowText(String text){
  15. place = 0;
  16. if(text != null){
  17. this.text = text;
  18. }
  19. if(rainbowArray == null){
  20. rainbowArray = RAINBOW;
  21. }
  22. updateFancy();
  23. }
  24.  
  25. public RainbowText(String text, String formatCode){
  26. place = 0;
  27. if(text != null){
  28. this.text = text;
  29. }
  30. if(formatCode != null){
  31. prefix = formatCode;
  32. }
  33. if(rainbowArray == null){
  34. rainbowArray = RAINBOW;
  35. }
  36. updateFancy();
  37. }
  38. public RainbowText(String text, List<String> rainbowArray){
  39. place = 0;
  40. if(text != null){
  41. this.text = text;
  42. }
  43.  
  44. if(this.rainbowArray == null){
  45. this.rainbowArray = rainbowArray;
  46. }
  47. updateFancy();
  48. }
  49. private void updateFancy(){
  50. int spot = place;
  51. String fancyText = "";
  52. for(char l : text.toCharArray()){
  53. String letter = Character.toString(l);
  54. String t1 = fancyText;
  55. if(!letter.equalsIgnoreCase(" ")){
  56. fancyText = t1 + rainbowArray.get(spot) + prefix + letter;
  57. if(spot == rainbowArray.size() - 1){
  58. spot = 0;
  59. } else {
  60. spot++;
  61. }
  62. } else {
  63. fancyText = t1 + letter;
  64. }
  65. }
  66. this.fancyText = fancyText;
  67. }
  68.  
  69. public void moveRainbow(){
  70. if(rainbowArray.size() - 1 == place){
  71. place = 0;
  72. } else {
  73. place++;
  74. }
  75. updateFancy();
  76. }
  77. public void moveRainbowRight(){
  78. if(place == 0){
  79. place = rainbowArray.size() - 1;
  80. } else {
  81. place--;
  82. }
  83. updateFancy();
  84. }
  85. public String getOrigonalText(){
  86. return this.text;
  87. }
  88. public String getText(){
  89. return this.fancyText;
  90. }
  91. public void setPlace(int place){
  92. if(place > RAINBOW.size() - 1 || place < 0){
  93. return;
  94. }
  95. this.place = place;
  96. updateFancy();
  97. }
  98. public int getPlace(){
  99. return this.place;
  100. }
  101. public List<String> getRainbow(){
  102. return rainbowArray;
  103. }
  104. public String getFormatPrefix(){
  105. return this.prefix;
  106. }
  107. public void setFormatPrefix(String prefix){
  108. this.prefix = prefix;
  109. }
  110. public static List<String> getDefaultRainbow(){
  111. return RAINBOW;
  112. }
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement