Can't save scoreboard globally.

Discussion in 'Plugin Development' started by CrazyGuy3000, Nov 6, 2013.

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

    CrazyGuy3000

    Using this code...

    Code:java
    1. package me.Twipply.Rift;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.Location;
    6. import org.bukkit.Sound;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.event.EventHandler;
    9. import org.bukkit.event.Listener;
    10. import org.bukkit.event.player.PlayerJoinEvent;
    11. import org.bukkit.plugin.java.JavaPlugin;
    12. import org.bukkit.scoreboard.DisplaySlot;
    13. import org.bukkit.scoreboard.Objective;
    14. import org.bukkit.scoreboard.Score;
    15. import org.bukkit.scoreboard.Scoreboard;
    16. import org.bukkit.scoreboard.ScoreboardManager;
    17.  
    18. public class Rift extends JavaPlugin implements Listener {
    19.  
    20. ScoreboardManager manager = Bukkit.getScoreboardManager();
    21. Scoreboard board = manager.getNewScoreboard();
    22. Objective objective = board.registerNewObjective("test", "sidebar");
    23.  
    24.  
    25.  
    26. @Override
    27. public void onEnable(){
    28. getServer().getPluginManager().registerEvents(this, this);
    29. objective.setDisplaySlot(DisplaySlot.SIDEBAR);
    30. Scroller scroller = new Scroller("thisissometextas", 10, 5, '&');
    31. objective.setDisplayName(scroller.next());
    32. Score score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.GREEN + "Twipply woz ere"));
    33. score.setScore(1);
    34. }
    35. }
    36.  


    and this is Scroller.java
    Code:java
    1. package me.Twipply.Rift;
    2.  
    3. import java.util.ArrayList;
    4. import java.util.List;
    5.  
    6. import org.bukkit.ChatColor;
    7.  
    8. /**
    9. * A util to scroll coloured Strings
    10. * @author Chinwe
    11. */
    12. public class Scroller
    13. {
    14. private static final char COLOUR_CHAR = '§';
    15. private int position;
    16. private List<String> line;
    17. private ChatColor colour = ChatColor.RESET;
    18.  
    19.  
    20. /**
    21. * @param message The String to scroll
    22. * @param width The width of the window to scroll across (i.e. 16 for signs)
    23. * @param spaceBetween The amount of spaces between each repetition
    24. * @param colourChar The colour code character you're using (i.e. & or §)
    25. */
    26. public Scroller(String message, int width, int spaceBetween, char colourChar)
    27. {
    28. line = new ArrayList<String>();
    29.  
    30. // Validation
    31. // String is too short for window
    32. if (message.length() < width)
    33. {
    34. StringBuilder sb = new StringBuilder(message);
    35. while (sb.length() < width)
    36. sb.append(" ");
    37. message = sb.toString();
    38. }
    39.  
    40. // Allow for colours which add 2 to the width
    41. width -= 2;
    42.  
    43. // Invalid width/space size
    44. if (width < 1)
    45. width = 1;
    46. if (spaceBetween < 0)
    47. spaceBetween = 0;
    48.  
    49. // Change to §
    50. if (colourChar != '§')
    51. message = ChatColor.translateAlternateColorCodes(colourChar, message);
    52.  
    53.  
    54. // Add substrings
    55. for (int i = 0; i < message.length() - width; i++)
    56. line.add(message.substring(i, i + width));
    57.  
    58. // Add space between repeats
    59. StringBuilder space = new StringBuilder();
    60. for (int i = 0; i < spaceBetween; ++i)
    61. {
    62. line.add(message.substring(message.length() - width + (i > width ? width : i), message.length()) + space);
    63. if (space.length() < width)
    64. space.append(" ");
    65. }
    66.  
    67. // Wrap
    68. for (int i = 0; i < width - spaceBetween; ++i)
    69. line.add(message.substring(message.length() - width + spaceBetween + i, message.length()) + space + message.substring(0, i));
    70.  
    71. // Join up
    72. for (int i = 0; i < spaceBetween; i++)
    73. {
    74. if (i > space.length())
    75. break;
    76. line.add(space.substring(0, space.length() - i) + message.substring(0, width - (spaceBetween > width ? width : spaceBetween) + i));
    77. }
    78. }
    79.  
    80. /**
    81. * @return Gets the next String to display
    82. */
    83. public String next()
    84. {
    85. StringBuilder sb = getNext();
    86. if (sb.charAt(sb.length() - 1) == COLOUR_CHAR)
    87. sb.setCharAt(sb.length() - 1, ' ');
    88.  
    89. if (sb.charAt(0) == COLOUR_CHAR)
    90. {
    91. ChatColor c = ChatColor.getByChar(sb.charAt(1));
    92. if (c != null)
    93. {
    94. colour = c;
    95. sb = getNext();
    96. if (sb.charAt(0) != ' ')
    97. sb.setCharAt(0, ' ');
    98. }
    99. }
    100.  
    101. return colour + sb.toString();
    102.  
    103. }
    104.  
    105. private StringBuilder getNext()
    106. {
    107. return new StringBuilder(line.get(position++ % line.size()).substring(0));
    108. }
    109.  
    110. }


    I need to do some scrolling text and I can't figure out where to save them so there accessible globally!

    bump!

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

    CraftBang

    CrazyGuy3000 you're not allowed to bump before 24 hours.
     
  3. Offline

    CrazyGuy3000

    CraftBang
    Sorry, I misread when it said "Yesterday at 6:26 PM". I had only just woken up :p
     
  4. Offline

    CraftBang

    CrazyGuy3000 sorry for saying it's not allowed and that I didn't response on your thread, I forgot to put the good information sometimes in my post xD
    What is your problem? I might be able to help you if I understand what you want :p.
    (And if it's inside my knowledge xD)

    What's not working? You're scoreboard?

    You should do this, replace :
    ScoreboardManager manager = Bukkit.getScoreboardManager();
    Scoreboard board = manager.getNewScoreboard();
    Objective objective = board.registerNewObjective("test", "sidebar");

    to :
    static ScoreboardManager manager;
    static Scoreboard board;
    static Objective objective;

    And the onEnable function add this :

    manager = Bukkit.getScoreboardManager();
    board = manager.getNewScoreboard();
    // I changed your objective because the string sidebar should be string dummy
    objective = board.registerNewObjective("SideBoard", "dummy");
     
Thread Status:
Not open for further replies.

Share This Page