Scrolling Text Not Working!

Discussion in 'Plugin Development' started by HeavyMine13, Jun 18, 2014.

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

    HeavyMine13

    Hey! I have this method using and Chinwe scrolling class, and It is NOT scrolling the text in the sidebar numbered scoreboard!

    Code:java
    1. Scroller scroller = new Scroller("§lWelcome to My Happy Server :D", 12, 1, '§');
    2. String welcome = scroller.next();
     
  2. Offline

    Gater12

    HeavyMine13
    How are you implementing it?

    The code you provided is correct usage.
     
  3. Offline

    HeavyMine13

    onPlayerJoin, I add That. The Problem Is, It Is NOT Scrolling at all ._.
     
  4. Offline

    Gater12

    HeavyMine13
    You have to put in a repeating task that will keep scrolling and displaying the String to the scoreboard.
     
  5. Offline

    HeavyMine13

    Gater12
    That will give a null exception to the scoreboard im using. Im using this scoreboard class:

    Method In My Join:
    Code:java
    1. final SimpleScoreboard scoreboard = new SimpleScoreboard("§a§lMain Lob");
    2.  
    3. final Scroller scroller = new Scroller(
    4. "§lWelcome to My Happy Server :D", 12, 1, '§');
    5. Bukkit.getScheduler().runTaskTimer(plugin, new Runnable() {
    6.  
    7. @Override
    8. public void run() {
    9. test = scroller.next();
    10. }
    11. }, 0L, 3L);
    12. scoreboard.add(test);


    Error:
    SimpleScoreboard Class:
    Code:java
    1. public class SimpleScoreboard {
    2.  
    3. private Scoreboard scoreboard;
    4.  
    5. private String title;
    6. private Map<String, Integer> scores;
    7. private List<Team> teams;
    8.  
    9. public SimpleScoreboard(String title) {
    10. this.scoreboard = Bukkit.getScoreboardManager().getNewScoreboard();
    11. this.title = title;
    12. this.scores = Maps.newLinkedHashMap();
    13. this.teams = Lists.newArrayList();
    14. }
    15.  
    16. public void blankLine() {
    17. add(" ");
    18. }
    19.  
    20. public void add(String text) {
    21. add(text, null);
    22. }
    23.  
    24. public void add(String text, Integer score) {
    25. Preconditions.checkArgument(text.length() < 48,
    26. "text cannot be over 48 characters in length");
    27. text = fixDuplicates(text);
    28. scores.put(text, score);
    29. }
    30.  
    31. private String fixDuplicates(String text) {
    32. while (scores.containsKey(text))
    33. text += "§r";
    34. if (text.length() > 48)
    35. text = text.substring(0, 47);
    36. return text;
    37. }
    38.  
    39. private Map.Entry<Team, String> createTeam(String text) {
    40. String result = "";
    41. if (text.length() <= 16)
    42. return new AbstractMap.SimpleEntry<>(null, text);
    43. Team team = scoreboard.registerNewTeam("text-"
    44. + scoreboard.getTeams().size());
    45. Iterator<String> iterator = Splitter.fixedLength(16).split(text)
    46. .iterator();
    47. team.setPrefix(iterator.next());
    48. result = iterator.next();
    49. if (text.length() > 32)
    50. team.setSuffix(iterator.next());
    51. teams.add(team);
    52. return new AbstractMap.SimpleEntry<>(team, result);
    53. }
    54.  
    55. public void build() {
    56. Objective obj = scoreboard
    57. .registerNewObjective(
    58. (title.length() > 16 ? title.substring(0, 15) : title),
    59. "dummy");
    60. obj.setDisplayName(title);
    61. obj.setDisplaySlot(DisplaySlot.SIDEBAR);
    62.  
    63. int index = scores.size();
    64.  
    65. for (Map.Entry<String, Integer> text : scores.entrySet()) {
    66. Map.Entry<Team, String> team = createTeam(text.getKey());
    67. Integer score = text.getValue() != null ? text.getValue() : index;
    68. @SuppressWarnings("deprecation")
    69. OfflinePlayer player = Bukkit.getOfflinePlayer(team.getValue());
    70. if (team.getKey() != null)
    71. team.getKey().addPlayer(player);
    72. obj.getScore(player).setScore(score);
    73. index -= 1;
    74. }
    75. }
    76.  
    77. public void reset() {
    78. title = null;
    79. scores.clear();
    80. for (Team t : teams)
    81. t.unregister();
    82. teams.clear();
    83. }
    84.  
    85. public Scoreboard getScoreboard() {
    86. return scoreboard;
    87. }
    88.  
    89. public void send(Player... players) {
    90. for (Player p : players)
    91. p.setScoreboard(scoreboard);
    92. }
    93.  
    94. }


    RainoBoy97 This is ur api.. is it the issue?

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

    RainoBoy97

  7. Offline

    HeavyMine13

    Here is a version with fixed NPE (so no more NPE), but the first line does not appear:

    Code:java
    1. package me.HeavyMine13.hub.events;
    2.  
    3. import java.util.ArrayList;
    4. import java.util.List;
    5.  
    6. import me.HeavyMine13.hub.Main;
    7. import me.HeavyMine13.hub.utils.BossBar;
    8. import me.HeavyMine13.hub.utils.Scroller;
    9. import me.HeavyMine13.hub.utils.SimpleScoreboard;
    10.  
    11. import org.bukkit.Bukkit;
    12. import org.bukkit.ChatColor;
    13. import org.bukkit.GameMode;
    14. import org.bukkit.Location;
    15. import org.bukkit.Material;
    16. import org.bukkit.World;
    17. import org.bukkit.entity.Player;
    18. import org.bukkit.event.EventHandler;
    19. import org.bukkit.event.EventPriority;
    20. import org.bukkit.event.Listener;
    21. import org.bukkit.event.player.PlayerJoinEvent;
    22. import org.bukkit.inventory.ItemStack;
    23. import org.bukkit.inventory.meta.ItemMeta;
    24.  
    25. public class Join implements Listener {
    26. private Main plugin;
    27. private String welcome = "§lWelcome to Heavys Server :D";
    28. public Join(Main plugin) {
    29. this.plugin = plugin;
    30. }
    31.  
    32. @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = false)
    33. public void join(PlayerJoinEvent e) {
    34. final Player player = e.getPlayer();
    35.  
    36. BossBar.setStatusBar(player, ChatColor.GREEN
    37. + "Welcome To Heavys Server!", 25F);
    38.  
    39. player.sendMessage(ChatColor.AQUA + "------------------------------");
    40. player.sendMessage(" ");
    41. player.sendMessage(ChatColor.GOLD + "Welcome To "
    42. + ChatColor.DARK_GREEN + "heavys" + ChatColor.GOLD
    43. + " Server");
    44. player.sendMessage(" ");
    45. player.sendMessage(ChatColor.AQUA + "------------------------------");
    46. final SimpleScoreboard scoreboard = new SimpleScoreboard("§a§lHub");
    47.  
    48. final Scroller scroller = new Scroller(
    49. welcome, 12, 1, '§');
    50.  
    51. try {
    52. doaScrool(scoreboard, scroller);
    53. } catch (Exception e2) {
    54. e2.printStackTrace();
    55. }
    56.  
    57. // also supports blank lines (up to 23 of them!)
    58. scoreboard.blankLine();
    59. scoreboard.add("§cYou are at Central Hub!");
    60. scoreboard.blankLine();
    61. // if you dont specify a score it will display them in the order you add
    62. // them in
    63. scoreboard.add("Today:");
    64. scoreboard.add("§b1. Patch 1.2");
    65. scoreboard.add("§e2. Some Build Fun");
    66. scoreboard.add("§23. Yeah!");
    67.  
    68. // the text can be up to 48 characters long (including color codes)
    69. // call this to create the scoreboard, nothing will happen if you forget
    70. // to call this
    71. scoreboard.build();
    72. // send the scoreboard to the player(s), takes an array
    73. scoreboard.send(player);
    74.  
    75. if (player.isOp() == false) {
    76. player.setGameMode(GameMode.SURVIVAL);
    77. }
    78. player.setAllowFlight(true);
    79.  
    80. e.getPlayer().getInventory().clear();
    81. Main.i = new ItemStack(Material.SLIME_BALL);
    82. // Scroller s = new Scroller("&aNavigation Map", 7, 5, '&');
    83. ItemMeta m = Main.i.getItemMeta();
    84. List<String> lore = new ArrayList<String>();
    85. lore.add(ChatColor.GRAY + "Use to move around easier.");
    86. m.setLore(lore);
    87.  
    88. m.setDisplayName(ChatColor.DARK_GREEN + "Slime Telepad");
    89.  
    90. Main.i.setItemMeta(m);
    91. e.getPlayer().getInventory().setItem(0, Main.i);
    92. ItemStack playerson = new ItemStack(Material.BLAZE_ROD);
    93. ItemMeta meta = playerson.getItemMeta();
    94. meta.setDisplayName(ChatColor.GRAY + "Players: " + ChatColor.GREEN
    95. + "On");
    96. playerson.setItemMeta(meta);
    97. e.getPlayer().getInventory().setItem(8, playerson);
    98. World w = Bukkit.getServer().getWorld(
    99. plugin.getConfig().getString("spawn.world"));
    100. double x = plugin.getConfig().getDouble("spawn.x");
    101. double y = plugin.getConfig().getDouble("spawn.y");
    102. double z = plugin.getConfig().getDouble("spawn.z");
    103. player.teleport(new Location(w, x, y, z));
    104. }
    105.  
    106.  
    107. public void doaScrool(final SimpleScoreboard scoreboard, final Scroller scroller){
    108. Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
    109.  
    110. @Override
    111. public void run() {
    112. scoreboard.add(scroller.next().toString());
    113.  
    114. }
    115. }, 20L, 20L);
    116. }
    117.  
    118. }
    119.  
     
  8. Offline

    RainoBoy97

    HeavyMine13
    Because you add the scrolling line after you .build() it, you have to make a new scoreboard each time you want it to scroll.
     
  9. Offline

    HeavyMine13

    RainoBoy97 How will i do that? How can I make a new scoreboard each time?

    RainoBoy97 I tried a scheduler with the normal stuff but didnt work. I mean I placed it all in a BukkitRunnable but no difference

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

    HeavyMine13

  11. Offline

    HeavyMine13

    Bump help me please!
     
Thread Status:
Not open for further replies.

Share This Page