Trouble With Scoreboards...

Discussion in 'Plugin Development' started by ThePaperRobot, Dec 23, 2016.

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

    ThePaperRobot

    So I am trying to create teams and objectives through a plugin, then check them and set them. I'm not getting any actual errors, but the hasPlayer and getScore lines are getting crossed out. I have done some research but haven't been able to fix the problem. Besides that, it just doesn't work.
    Code:
    package me.ThePaperRobot;
    
    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
    import org.bukkit.scoreboard.DisplaySlot;
    import org.bukkit.scoreboard.Objective;
    import org.bukkit.scoreboard.Scoreboard;
    import org.bukkit.scoreboard.ScoreboardManager;
    import org.bukkit.scoreboard.Team;
    
    public class Accuracy extends JavaPlugin {   
    
        @Override
       
        public void onEnable() {
    
            getLogger().info("Accuracy Plugin Enabled!");
           
        }
       
        @Override
        public void onDisable() {
           
        }
       
        @SuppressWarnings("deprecation")
        @EventHandler
       
        public void onJoin(PlayerJoinEvent event) {
           
            ScoreboardManager manager = Bukkit.getScoreboardManager();
            Scoreboard board = manager.getNewScoreboard();
           
            Objective acc = board.registerNewObjective("accuracy","dummy");
            acc.setDisplaySlot(DisplaySlot.SIDEBAR);
            acc.setDisplayName("ACC");
           
            Objective speed = board.registerNewObjective("speed","dummy");
            speed.setDisplaySlot(DisplaySlot.SIDEBAR);
            speed.setDisplayName("SPD");
    
            Objective strength = board.registerNewObjective("strength","dummy");
            strength.setDisplaySlot(DisplaySlot.SIDEBAR);
            strength.setDisplayName("STR");
           
            Team ang = board.registerNewTeam("angle");
            ang.setDisplayName("Angle");
           
            Team hum = board.registerNewTeam("human");
            hum.setDisplayName("Human");
           
            Team dem = board.registerNewTeam("demon");
            dem.setDisplayName("Demon");
           
            for(Player online : Bukkit.getOnlinePlayers()) {
               
                String spst = speed.getScore(online).toString();
                int sp = Integer.parseInt(spst);
               
                String stst = strength.getScore(online).toString();
                int st = Integer.parseInt(stst);
               
                String accst = strength.getScore(online).toString();
                int accint = Integer.parseInt(accst);
               
               
                if(ang.hasPlayer(online)) {
                   
                    online.addPotionEffect(new PotionEffect(PotionEffectType.SPEED,1000000,3+sp));
                    online.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE,1000000,1+st));
                    online.addPotionEffect(new PotionEffect(PotionEffectType.HEALTH_BOOST,1000000,5));
                   
                }
               
                if(dem.hasPlayer(online)) {
                   
                    online.addPotionEffect(new PotionEffect(PotionEffectType.SPEED,1000000,1+sp));
                    online.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE,1000000,3+st));
                    online.addPotionEffect(new PotionEffect(PotionEffectType.HEALTH_BOOST,1000000,5));
                   
                }
               
                if(hum.hasPlayer(online)) {
                   
                    online.addPotionEffect(new PotionEffect(PotionEffectType.SPEED,1000000,2+sp));
                    online.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE,1000000,2+st));
                   
    
                   
                }
            }
        }
       
    }
    
    I am fairly new to plugin development, so please cut me some slack. :p Thanks in advance!
     
  2. Offline

    Zombie_Striker

    @ThePaperRobot
    That just means they are deprecated. Deprecation is meant to bring awareness to something, in this case, that those methods still use names instead of uuids. Since you need to get those values using a player name, you can just ignore them.
     
  3. Offline

    ThePaperRobot

    I am still confused as to why this is not working in-game.
     
  4. Offline

    timtower Administrator Administrator Moderator

  5. Offline

    ThePaperRobot

    Can you please elaborate?
     
  6. Offline

    timtower Administrator Administrator Moderator

    @ThePaperRobot You never call registerEvents which is needed for events to start working.
     
  7. Offline

    Wispyy

    And implement Listener
     
  8. Offline

    ThePaperRobot

    Ok, so I added an event listener, but it still doesn't seen to be working. :confused: Here is the updated code:

    Code:
    package me.ThePaperRobot;
    
    import org.bukkit.Bukkit;
    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.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
    import org.bukkit.scoreboard.DisplaySlot;
    import org.bukkit.scoreboard.Objective;
    import org.bukkit.scoreboard.Scoreboard;
    import org.bukkit.scoreboard.ScoreboardManager;
    import org.bukkit.scoreboard.Team;
    
    public class Accuracy extends JavaPlugin implements Listener{   
    
        @Override
        public void onEnable() {
    
            this.getServer().getPluginManager().registerEvents(this, this);
            getLogger().info("Accuracy Plugin Enabled!");
           
        }
       
        @Override
        public void onDisable() {
           
        }
       
        @EventHandler
        public void onJoin(PlayerJoinEvent event) {
           
            ScoreboardManager manager = Bukkit.getScoreboardManager();
            Scoreboard board = manager.getNewScoreboard();
           
            Objective acc = board.registerNewObjective("accuracy","dummy");
            acc.setDisplaySlot(DisplaySlot.SIDEBAR);
            acc.setDisplayName("ACC");
           
            Objective speed = board.registerNewObjective("speed","dummy");
            speed.setDisplaySlot(DisplaySlot.SIDEBAR);
            speed.setDisplayName("SPD");
    
            Objective strength = board.registerNewObjective("strength","dummy");
            strength.setDisplaySlot(DisplaySlot.SIDEBAR);
            strength.setDisplayName("STR");
           
            Team ang = board.registerNewTeam("angle");
            ang.setDisplayName("Angle");
           
            Team hum = board.registerNewTeam("human");
            hum.setDisplayName("Human");
           
            Team dem = board.registerNewTeam("demon");
            dem.setDisplayName("Demon");
           
            for(Player online : Bukkit.getOnlinePlayers()) {
               
                String spst = speed.getScore(online).toString();
                int sp = Integer.parseInt(spst);
               
                String stst = strength.getScore(online).toString();
                int st = Integer.parseInt(stst);
               
                String accst = strength.getScore(online).toString();
                int accint = Integer.parseInt(accst);
               
               
                if(ang.hasPlayer(online)) {
                   
                    online.addPotionEffect(new PotionEffect(PotionEffectType.SPEED,1000000,3+sp));
                    online.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE,1000000,1+st));
                    online.addPotionEffect(new PotionEffect(PotionEffectType.HEALTH_BOOST,1000000,5));
                   
                }
               
                if(dem.hasPlayer(online)) {
                   
                    online.addPotionEffect(new PotionEffect(PotionEffectType.SPEED,1000000,1+sp));
                    online.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE,1000000,3+st));
                    online.addPotionEffect(new PotionEffect(PotionEffectType.HEALTH_BOOST,1000000,5));
                   
                }
               
                if(hum.hasPlayer(online)) {
                   
                    online.addPotionEffect(new PotionEffect(PotionEffectType.SPEED,1000000,2+sp));
                    online.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE,1000000,2+st));
                   
    
                   
                }
            }
        }
       
    }
    
     
  9. Offline

    timtower Administrator Administrator Moderator

    @ThePaperRobot Does the event not run or does the scoreboard code not function?
     
  10. Offline

    ThePaperRobot

    Neither...

    I mean, none of them work...
     
    Last edited: Dec 24, 2016
  11. Offline

    iCancer

    @ThePaperRobot I think you forgot to add the scoreboard to the player.
     
  12. @iCancer @timtower If that is actually his code, then yeah he forgot to add the scoreboard to the player.
    Code:
    player.setScoreboard(scoreboard);
    EDIT: He is also creating a new Team object ever login, thus hasPlayer(player) does nothing.
     
  13. Offline

    ThePaperRobot

    Well, there's that, which I have just added, but also it isn't even any objectives or teams when i do either; /scoreboard objectives list or /scoreboard teams list...

    Oh, ok, the makes sense. I'll see what I can do.

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

Share This Page