Where did i did it wrong with "{"

Discussion in 'Spigot Plugin Development' started by JimmYTje, May 28, 2017.

  1. Where did i it wrong? heres my code
    Code (Text):

    package me.iDevq.TestPlugin;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.scoreboard.DisplaySlot;
    import org.bukkit.scoreboard.Objective;
    import org.bukkit.scoreboard.Score;
    import org.bukkit.scoreboard.Scoreboard;
    import org.bukkit.scoreboard.ScoreboardManager;

    public class Main extends JavaPlugin implements Listener {
       

       
       
        @Override
        public void onEnable() {
           
            getCommand("main").setExecutor(new BasisCommand());
            getCommand("hello").setExecutor(new CMessage());
            getCommand("fine").setExecutor(new Fine());
        }
        public void PlayerJoin(PlayerJoinEvent e) {
           
            Player p = e.getPlayer();
            ScoreboardManager manager = Bukkit.getScoreboardManager();
            Scoreboard board = manager.getNewScoreboard();
            Objective objective = board.registerNewObjective("test", "dummy");
            objective.setDisplaySlot(DisplaySlot.SIDEBAR);
            objective.setDisplayName(ChatColor.RED + "iDevq Scoreboard Test");
           
            Score score = objective.getScore(ChatColor.AQUA + "Naam:");
            score.setScore(10);
           
            Score score1 = objective.getScore(ChatColor.GRAY + p.getName());
            score1.setScore(8);
           
            long health = Math.round(p.getHealth());
           
            Score score3 = objective.getScore(ChatColor.GRAY + String.valueOf(health));
            score3.setScore(7);
           
            Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(Main.plugin, new Runnable() {
                public void run() {
                    p.setScoreboard(board);              
            }
                } <Getting there the message "Syntax error, insert ";" to complete Statement"
                   
        }
       
    }
     
     
  2. You need one more ); at the end of the runnable , and also don't forget to register the event and to use @EventHandler
     
    #2 JasperJH, May 28, 2017
    Last edited: May 28, 2017
  3. Code (Text):

    package me.iDevq.TestPlugin;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    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.java.JavaPlugin;
    import org.bukkit.scoreboard.DisplaySlot;
    import org.bukkit.scoreboard.Objective;
    import org.bukkit.scoreboard.Score;
    import org.bukkit.scoreboard.Scoreboard;
    import org.bukkit.scoreboard.ScoreboardManager;

    public class Main extends JavaPlugin implements Listener {
       

       
       
        @Override
        public void onEnable() {
           
            getCommand("main").setExecutor(new BasisCommand());
            getCommand("hello").setExecutor(new CMessage());
            getCommand("fine").setExecutor(new Fine());
        }
        @EventHandler
        public void PlayerJoin(PlayerJoinEvent e) {
           
            Player p = e.getPlayer();
            ScoreboardManager manager = Bukkit.getScoreboardManager();
            Scoreboard board = manager.getNewScoreboard();
            Objective objective = board.registerNewObjective("test", "dummy");
            objective.setDisplaySlot(DisplaySlot.SIDEBAR);
            objective.setDisplayName(ChatColor.RED + "iDevq Scoreboard Test");
           
            Score score = objective.getScore(ChatColor.AQUA + "Naam:");
            score.setScore(10);
           
            Score score1 = objective.getScore(ChatColor.GRAY + p.getName());
            score1.setScore(8);
           
            long health = Math.round(p.getHealth());
           
            Score score3 = objective.getScore(ChatColor.GRAY + String.valueOf(health));
            score3.setScore(7);
           
            Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(Main.plugin, new Runnable() {
                public void run() {
                    p.setScoreboard(board);              
            }
                }
                   
        }
       
    }
    }
     
    Still not working.
     
  4. Choco

    Moderator

    No, the OP's braces are just fine. What he's missing is a closing parenthesis and semi-colon at the end of the line in which he's receiving a warning. Keep mind mind that you're creating an anonymous inner class within a method call.
    Code (Java):
    Bukkit.getScheduler().runTaskTimer(plugin, new Runnable() {
        @Override
        public void run() {

        }
    }); // This is what you're missing
     
  5. Mas

    Mas

    You'll need to register your class as a listener using Bukkit.getPluginManager().registerEvents(this, this);