Solved Scoreboard Bukkit API Problems...

Discussion in 'Plugin Development' started by LCAnton, May 8, 2013.

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

    LCAnton

    Hi,
    I need some help with the new Scoreboard-Bukkit API. I've found this tutorial but can't get it work!
    Please help me. :)

    Code:
    package me.ant0n.Crysis;
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.block.Sign;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.scoreboard.Scoreboard;
    import org.bukkit.scoreboard.ScoreboardManager;
    import org.bukkit.scoreboard.Team;
     
    public class Crysis extends JavaPlugin implements Listener{
       
        public static Crysis instance;
       
        private ScoreboardManager manager = null;
        private Scoreboard board = null;
        private Team ingame = null;
       
        @Override
        public void onDisable() {
            System.out.println("[Crysis] Plugin disabled!");
           
        }
       
        @Override
        public void onEnable() {
            instance = this;
            System.out.println("[Crysis] Plugin enabled!");
           
            getServer().getPluginManager().registerEvents(this, this);
                   
            ScoreboardManager manager = Bukkit.getScoreboardManager();
            Scoreboard board = manager.getNewScoreboard();
            Team ingame = board.registerNewTeam("InGame");
            ingame.setCanSeeFriendlyInvisibles(true);
            ingame.setSuffix("InGame");
        }
       
        @EventHandler
        public void onInteract(PlayerInteractEvent e) {
           
            Player p = e.getPlayer();
            if(e.getAction() == Action.RIGHT_CLICK_BLOCK) {
               
                if(e.getClickedBlock().getState() instanceof Sign) {
                   
                    Sign s = (Sign) e.getClickedBlock().getState();
                   
                    if(s.getLine(0).equalsIgnoreCase("[Crysis]")) {
                       
                        p.sendMessage("Sign activated!");
                        s.setLine(0, ChatColor.DARK_PURPLE + "" + ChatColor.BOLD +"[Crysis]");
                        s.update();
                        //Doesn't working part
                        ingame.addPlayer(p);
                       
                        p.sendMessage("Entered Crymode!");
                       
                    }
                   
                    if(s.getLine(0).equalsIgnoreCase(ChatColor.DARK_PURPLE + "" + ChatColor.BOLD +"[Crysis]")) {
                       
                        //Doesn't working part
                        ingame.addPlayer(p);
                       
                        p.sendMessage("Entered Crymode!");
                       
                    }
                   
                }
               
            }
           
        }   
     
    }
    
     
  2. Offline

    Suraski

    Don't forget to register an objective and set the players board!

    Code:
    player.setScoreboard(board);
    Code:
    board.registerNewObjective("showhealth", "dummy");
     
  3. Offline

    LCAnton

    But I don't want to have an objective or a sidebar! I only want to use the teams!
    I want a sign that lets you Joint a team if you right Click in it.
     
  4. Offline

    chasechocolate

    LCAnton I believe you also have to set the players scoreboard along with adding them to the team because teams are just a sub-feature of scoreboards.
     
  5. Offline

    LCAnton

    Ok I'll try it. Should I create a onPlayerJoinEvent for it?
     
  6. Offline

    chasechocolate

    Depends on what you want to do :)
     
  7. Offline

    LCAnton

    chasechocolate I tried to pur it in onEnable() (like your example) but it still doesn't works...
    I think I put the code to the Wong place?! :/

    Ok guys,
    I finally did it ->> IT WORKS!!!
    Thanks for your help :D

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
Thread Status:
Not open for further replies.

Share This Page