No scoreboard showing, but plugin works

Discussion in 'Plugin Development' started by Hsas4849, May 7, 2014.

Thread Status:
Not open for further replies.
  1. Hey dudes! i hava a problem: i made an scoreboard by tutorial and it still dosen't shows, when player connects :|

    Main class:
    Code:java
    1. package gamersplay;
    2. import org.bukkit.ChatColor;
    3. import org.bukkit.command.Command;
    4. import org.bukkit.command.CommandSender;
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.event.EventHandler;
    7. import org.bukkit.event.player.PlayerJoinEvent;
    8. import org.bukkit.plugin.java.JavaPlugin;
    9.  
    10.  
    11. public class GamersPlay extends JavaPlugin{
    12. public void onEnable(){
    13. getLogger().info("GAMERSPLAY IJUNGTAS!");
    14. }
    15. public void onDisable(){
    16. getLogger().info("GAMERSPLAY - ISJUNGTAS!");
    17. }
    18. @EventHandler
    19. public void event(PlayerJoinEvent event) {
    20. Player player = event.getPlayer();
    21. // create a new scoreboard with title
    22. SimpleScoreboard scoreboard = new SimpleScoreboard("§a§lGamersPlay:");
    23. // text with custom score
    24. scoreboard.add("§lTestinam", 1337);
    25. // also supports blank lines (up to 23 of them!)
    26. scoreboard.blankLine();
    27. scoreboard.add("§cTestuojam");
    28. scoreboard.blankLine();
    29. // if you dont specify a score it will display them in the order you add them in
    30. scoreboard.add("testas");
    31. scoreboard.add("§bin");
    32. scoreboard.add("§edescending");
    33. scoreboard.add("§2order");
    34. scoreboard.add(":) lol");
    35. scoreboard.blankLine();
    36. // the text can be up to 48 characters long (including color codes)
    37. scoreboard.add("bla bla bla §l48 :eek:");
    38. // call this to create the scoreboard, nothing will happen if you forget to call this
    39. scoreboard.build();
    40. // send the scoreboard to the player(s), takes an array
    41. scoreboard.send(player);
    42. player.sendMessage("testinam");
    43. }
    44. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    45. Player player = (Player) sender;
    46. if(cmd.getName().equalsIgnoreCase("rangas")){
    47. if(player.hasPermission("extra.narys")) {
    48. player.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "Jūs esate: " + ChatColor.YELLOW + "" + ChatColor.BOLD + "EXTRA" + ChatColor.GOLD + "" + ChatColor.BOLD + " narys!");
    49. } else {
    50. player.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "Jūs esate: " + ChatColor.BLUE + "ŽAIDĖJAS");
    51. }
    52. }
    53. return false;
    54. }
    55. }


    SimpleScoreboard class:

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

    pleasse help me to fix this :/
     
  2. Offline

    zDylann

    Register. Events.
     
  3. zDylann
    Can you help me to do that? :D
     
  4. Offline

    ZodiacTheories

    Hsas4849

    in your onEnable() {

    type

    getServer().getPluginManager().registerEvents(new YourEventsClass, this);

    and of course, if the the events class is your main class, just put this.
     
  5. Offline

    ZodiacTheories

    Hsas4849

    What do you mean, which class did you type @EventHandler ?
     
  6. Offline

    TGRHavoc

    Really? No @EventHandler?
     
  7. Offline

    ZodiacTheories

    Hsas4849

    Well then type getServer().getPluginManager().registerEvents(this, this); under getLogger().info("GAMERSPLAY IJUNGTAS");
     
  8. TGRHavoc
    look up, i edited the post ( mistake sorry ), so how i can fix this :? pleasse help me :(
     
  9. Offline

    ZodiacTheories

  10. Offline

    ZodiacTheories

    Hsas4849

    Stack-Trace?

    Also, show me where you typed it please.
     
  11. ZodiacTheories
    I typed it here:
    Code:java
    1. public void onEnable(){
    2. getLogger().info("GAMERSPLAY IJUNGTAS!");
    3. getServer().getPluginManager().registerEvents(this, this);
    4. }
     
  12. Offline

    ZodiacTheories

  13. ZodiacTheories
    What you mean whith "Stack trace?" ( if i translate to Lithuania it i get "footprint" ) :D
     
  14. Offline

    TGRHavoc

    Hsas4849
    "Stack Trace" is the error that you get in the console when something in the code goes wrong.
     
  15. Oh okey :
    Code:
    [14:03:07 ERROR]: Could not pass event PlayerJoinEvent to GamersPlay v1.7
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:294) ~[spigot.jar:git-Spigot-1463]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-1463]
            at org.bukkit.plugin.TimedRegisteredListener.callEvent(TimedRegisteredListener.java:30) ~[spigot.jar:git-Spigot-1463]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot.jar:git-Spigot-1463]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot.jar:git-Spigot-1463]
            at net.minecraft.server.v1_7_R3.PlayerList.c(PlayerList.java:265) [spigot.jar:git-Spigot-1463]
            at net.minecraft.server.v1_7_R3.PlayerList.a(PlayerList.java:152) [spigot.jar:git-Spigot-1463]
            at net.minecraft.server.v1_7_R3.LoginListener.c(LoginListener.java:105) [spigot.jar:git-Spigot-1463]
            at net.minecraft.server.v1_7_R3.LoginListener.a(LoginListener.java:43) [spigot.jar:git-Spigot-1463]
            at net.minecraft.server.v1_7_R3.NetworkManager.a(NetworkManager.java:183) [spigot.jar:git-Spigot-1463]
            at net.minecraft.server.v1_7_R3.ServerConnection.c(ServerConnection.java:81) [spigot.jar:git-Spigot-1463]
            at net.minecraft.server.v1_7_R3.MinecraftServer.v(MinecraftServer.java:713) [spigot.jar:git-Spigot-1463]
            at net.minecraft.server.v1_7_R3.DedicatedServer.v(DedicatedServer.java:283) [spigot.jar:git-Spigot-1463]
            at net.minecraft.server.v1_7_R3.MinecraftServer.u(MinecraftServer.java:576) [spigot.jar:git-Spigot-1463]
            at net.minecraft.server.v1_7_R3.MinecraftServer.run(MinecraftServer.java:482) [spigot.jar:git-Spigot-1463]
            at net.minecraft.server.v1_7_R3.ThreadServerApplication.run(SourceFile:628) [spigot.jar:git-Spigot-1463]
    Caused by: java.lang.IllegalArgumentException: Name cannot be blank
            at com.google.common.base.Preconditions.checkArgument(Preconditions.java:88) ~[spigot.jar:git-Spigot-1463]
            at org.bukkit.craftbukkit.v1_7_R3.CraftServer.getOfflinePlayer(CraftServer.java:1326) ~[spigot.jar:git-Spigot-1463]
            at org.bukkit.Bukkit.getOfflinePlayer(Bukkit.java:420) ~[spigot.jar:git-Spigot-1463]
            at gamersplay.SimpleScoreboard.build(SimpleScoreboard.java:82) ~[?:?]
            at gamersplay.GamersPlay.event(GamersPlay.java:41) ~[?:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_51]
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[?:1.7.0_51]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.7.0_51]
            at java.lang.reflect.Method.invoke(Method.java:606) ~[?:1.7.0_51]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:292) ~[spigot.jar:git-Spigot-1463]
            ... 15 more
    
    TGRHavoc ZodiacTheories
     
  16. Offline

    ZodiacTheories

    Hsas4849

    We don't support Spigot sorry :p
     
  17. Offline

    TnT

    Locked. If you need help with plugins for software we do not make, please request support on the forums where you found the software you use.
     
Thread Status:
Not open for further replies.

Share This Page