Help scoreboard not appearing

Discussion in 'Spigot Plugin Development' started by liwaa, Jun 16, 2015.

  1. Code (Text):
        BukkitScheduler Scheduler = Bukkit.getServer().getScheduler();
        Scheduler.scheduleSyncRepeatingTask(this, new Runnable()
        {
          public void run()
          {
            Integer i = Integer.valueOf(Main.A.size());
            if (i.intValue() == 1)
            {
              objective.setDisplayName(Main.Format("�6�lM�e�lC�f�lDIGITAL"));
              Main.A.add("A");
            }
            if (i.intValue() == 2)
            {
              objective.setDisplayName(Main.Format("�f�lM�6�lC�e�lD�f�lIGITAL"));
              Main.A.add("B");
            }
            if (i.intValue() == 3)
            {
              objective.setDisplayName(Main.Format("�f�lMC�6�lD�e�lI�f�lGITAL"));
              Main.A.add("C");
            }
            if (i.intValue() == 4)
            {
              objective.setDisplayName(Main.Format("�f�lMCD�6�lI�e�lG�f�lITAL"));
              Main.A.add("D");
            }
            if (i.intValue() == 5)
            {
              objective.setDisplayName(Main.Format("�f�lMCDI�6�lG�e�lI�f�lTAL"));
              Main.A.add("E");
            }
            if (i.intValue() == 6)
            {
              objective.setDisplayName(Main.Format("�f�lMCDIG�6�lI�e�lT�f�lAL"));
              Main.A.add("F");
            }
            if (i.intValue() == 7)
            {
              objective.setDisplayName(Main.Format("�f�lMCDIGI�6�lT�e�lA�f�lL"));
              Main.A.add("G");
            }
            if (i.intValue() == 8)
            {
              objective.setDisplayName(Main.Format("�f�lMCDIGIT�6�lA�e�lL"));
              Main.A.add("H");
            }
            if (i.intValue() == 9)
            {
              objective.setDisplayName(Main.Format("�f�lMCDIGITA�6�lL"));
              Main.A.add("I");
            }
            if (i.intValue() == 9)
            {
              Main.A.clear();
              Main.A.add("1");
            }
          }
        }, 0L, 15L);
       
        player.setScoreboard((org.bukkit.scoreboard.Scoreboard)board);
      }
     
      public static String Format(String string)
      {
        String text = null;
        return text.replaceAll("&", "�");
      }
     
      @EventHandler
      public void onJoin(PlayerJoinEvent ev)
      {
        Player p = ev.getPlayer();
        add(p);
      }
     
      public void onEnable()
      {
        Bukkit.getPluginManager().registerEvents(this, this);
      }
     
      public void onDisable() {}
    }
     


    i get an error of
    could not pass event PlayerJoinEvent to Scoreboard v1.0
     
  2. sothatsit

    Patron

    Please post the full stack trace, we cant help you with just a message you get saying there was an error, we need the error.
     
  3. EDIT: full code

    Code (Text):
    package me.liwaa.SCOREBOARD;

    import java.util.ArrayList;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Server;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.scheduler.BukkitScheduler;
    import org.bukkit.scoreboard.DisplaySlot;
    import org.bukkit.scoreboard.Objective;
    import org.bukkit.scoreboard.Score;
    import org.bukkit.scoreboard.ScoreboardManager;

    public class Main
      extends JavaPlugin
      implements Listener
    {
      static ArrayList<String> A = new ArrayList();
     
      public void add(Player player)
      {
        ScoreboardManager manager = Bukkit.getScoreboardManager();
        net.minecraft.server.v1_8_R1.Scoreboard board = (net.minecraft.server.v1_8_R1.Scoreboard)manager.getNewScoreboard();
       
        final Objective objective = ((org.bukkit.scoreboard.Scoreboard)board).registerNewObjective("test", "dummy");
        objective.setDisplaySlot(DisplaySlot.SIDEBAR);
       
        Score score = objective.getScore(ChatColor.AQUA + "Available Games   ");
        score.setScore(9);
        Score score1 = objective.getScore(ChatColor.DARK_GREEN + "SurvivalGames   ");
        score1.setScore(8);
        Score score11 = objective.getScore(ChatColor.DARK_RED + "SkyWars   ");
        score11.setScore(7);
        Score score111 = objective.getScore(ChatColor.YELLOW + "ZombieEscape   ");
        score111.setScore(8);
        Score score1111 = objective.getScore(ChatColor.RED + "Spleef   ");
        score1111.setScore(8);
        Score score11111 = objective.getScore(ChatColor.BLUE + "Prison   ");
        score11111.setScore(8);
        Score score111111 = objective.getScore(ChatColor.DARK_PURPLE + "KitPvP   ");
        score111111.setScore(8);
        Score score1111111 = objective.getScore(ChatColor.GREEN + "Factions   ");
        score1111111.setScore(8);
        Score score11111111 = objective.getScore(ChatColor.MAGIC + "SkyBlock   ");
        score11111111.setScore(8);
       
        A.clear();
        A.add("1");
       
        BukkitScheduler Scheduler = Bukkit.getServer().getScheduler();
        Scheduler.scheduleSyncRepeatingTask(this, new Runnable()
        {
          public void run()
          {
            Integer i = Integer.valueOf(Main.A.size());
            if (i.intValue() == 1)
            {
              objective.setDisplayName(Main.Format("�6�lM�e�lC�f�lDIGITAL"));
              Main.A.add("A");
            }
            if (i.intValue() == 2)
            {
              objective.setDisplayName(Main.Format("�f�lM�6�lC�e�lD�f�lIGITAL"));
              Main.A.add("B");
            }
            if (i.intValue() == 3)
            {
              objective.setDisplayName(Main.Format("�f�lMC�6�lD�e�lI�f�lGITAL"));
              Main.A.add("C");
            }
            if (i.intValue() == 4)
            {
              objective.setDisplayName(Main.Format("�f�lMCD�6�lI�e�lG�f�lITAL"));
              Main.A.add("D");
            }
            if (i.intValue() == 5)
            {
              objective.setDisplayName(Main.Format("�f�lMCDI�6�lG�e�lI�f�lTAL"));
              Main.A.add("E");
            }
            if (i.intValue() == 6)
            {
              objective.setDisplayName(Main.Format("�f�lMCDIG�6�lI�e�lT�f�lAL"));
              Main.A.add("F");
            }
            if (i.intValue() == 7)
            {
              objective.setDisplayName(Main.Format("�f�lMCDIGI�6�lT�e�lA�f�lL"));
              Main.A.add("G");
            }
            if (i.intValue() == 8)
            {
              objective.setDisplayName(Main.Format("�f�lMCDIGIT�6�lA�e�lL"));
              Main.A.add("H");
            }
            if (i.intValue() == 9)
            {
              objective.setDisplayName(Main.Format("�f�lMCDIGITA�6�lL"));
              Main.A.add("I");
            }
            if (i.intValue() == 9)
            {
              Main.A.clear();
              Main.A.add("1");
            }
          }
        }, 0L, 15L);
       
        player.setScoreboard((org.bukkit.scoreboard.Scoreboard)board);
      }
     
      public static String Format(String string)
      {
        String text = null;
        return text.replaceAll("&", "�");
      }
     
      @EventHandler
      public void onJoin(PlayerJoinEvent ev)
      {
        Player p = ev.getPlayer();
        add(p);
      }
     
      public void onEnable()
      {
        Bukkit.getPluginManager().registerEvents(this, this);
      }
     
      public void onDisable() {}
    }
     
    ERROR: could not pass event PlayerJoinEvent to Scoreboard v1.0
     
  4. sothatsit

    Patron

    We need the Full Error not the Full code. The error should be logged to console, if it isn't im not sure why and you should check the log files.
     
  5. sothatsit

    Patron

    Also, why do so many people not follow the java naming conventions?

    method names should be lowerCamelCase, e.g. Format should be format.
    package names should be all lowercase e.g. me.liwaa.SCOREBOARD should be me.liwaa.scoreboard

    You should also use ChatColor.translateAlternateColorCodes('&', string) instead of replacing "&" manually.

    Also, this code is completely wrong and will always throw a NullPointerException:
    Code (Text):

      public static String Format(String string)
      {
        String text = null;
        return text.replaceAll("&", "�");
      }
     
     
  6. how can i fix the code??
     
  7. sothatsit

    Patron

    Oh god, another one. Learn java. Where did you get this code from if you don't know programming?
     
  8. im new to coding and dont know alot, i saw that code and tried it
     
  9. sothatsit

    Patron

  10. sothatsit

    Patron

    If you want to make plugins which work well either learn java (I learnt from this guy, yeaars ago https://www.thenewboston.com/videos.php?cat=31) or hire someone to make a plugin for you. Those are your only options i am afraid, leaching off of people for everything you do is not fun :(.