Package org.bukkit.scoreboard

Examples of org.bukkit.scoreboard.Objective


    this.bombThieves.clear();
    this.cakeThieves.clear();
    if (this.getScoreboardType() != ScoreboardType.NONE) {
      this.scoreboard = Bukkit.getScoreboardManager().getNewScoreboard();
      scoreboard.registerNewObjective(this.getScoreboardType().getDisplayName(), "dummy");
      Objective obj = scoreboard.getObjective(this.getScoreboardType().getDisplayName());
      Validate.isTrue(obj.isModifiable(), "Cannot modify players' scores on the " + this.name + " scoreboard.");
      for (Team team : this.getTeams()) {
        String teamName = team.getKind().getColor() + team.getName() + ChatColor.RESET;
        if (this.getScoreboardType() == ScoreboardType.POINTS) {
          obj.getScore(Bukkit.getOfflinePlayer(teamName)).setScore(team.getPoints());
        } else if (this.getScoreboardType() == ScoreboardType.LIFEPOOL) {
          obj.getScore(Bukkit.getOfflinePlayer(teamName)).setScore(team.getRemainingLifes());
        }
      }
      obj.setDisplaySlot(DisplaySlot.SIDEBAR);
      for (Team team : this.getTeams()) {
        for (Player player : team.getPlayers()) {
          player.setScoreboard(scoreboard);
        }
      }
View Full Code Here


    }
    if (attackerTeam.getTeamConfig().resolveBoolean(TeamConfig.KILLSTREAK)) {
      War.war.getKillstreakReward().rewardPlayer(attacker, this.getKillCount(attacker.getName()));
    }
    if (this.getScoreboard() != null && this.getScoreboardType() == ScoreboardType.TOPKILLS) {
      Objective obj = this.getScoreboard().getObjective("Top kills");
      obj.getScore(attacker).setScore(this.getKillCount(attacker.getName()));
    }
    if (defenderTeam.getTeamConfig().resolveBoolean(TeamConfig.INVENTORYDROP)) {
      dropItems(defender.getLocation(), defender.getInventory().getContents());
      dropItems(defender.getLocation(), defender.getInventory().getArmorContents());
    }
View Full Code Here

  public void setRemainingLives(int remainingLives) {
    this.remainingLives = remainingLives;
    if (this.warzone.getScoreboard() != null && this.warzone.getScoreboardType() == ScoreboardType.LIFEPOOL) {
      String teamName = kind.getColor() + name + ChatColor.RESET;
      OfflinePlayer teamPlayer = Bukkit.getOfflinePlayer(teamName);
      Objective obj = this.warzone.getScoreboard().getObjective("Lifepool");
      obj.getScore(teamPlayer).setScore(remainingLives);
    }
  }
View Full Code Here

        if (board == null) {
            dB.echoError(scriptEntry.getResidingQueue(), "Scoreboard " + id.asString() + " does not exist!");
            return;
        }

        Objective obj = null;

        if (act.equals(Action.ADD)) {

            if (objective != null) {
                // Try getting the objective from the board
                obj = board.getObjective(objective.asString());

                // Create the objective if it does not already exist
                if (obj == null) {
                    obj = board.registerNewObjective(objective.asString(), criteria.asString());
                }
                // If a different criteria has been set for this objective,
                // recreate the objective
                else if (criteria != null && !obj.getCriteria().equals(criteria.asString())) {
                    obj.unregister();
                    obj = board.registerNewObjective(objective.asString(), criteria.asString());
                }

                // Change the objective's display slot
                if (!displaySlot.asString().equalsIgnoreCase("none")) {
                    obj.setDisplaySlot(DisplaySlot.valueOf(displaySlot.asString().toUpperCase()));
                }

                obj.setDisplayName(objective.asString());

                if (!lines.isEmpty()) {
                    // If we've gotten this far, but the score is null,
                    // use a score of 0
                    if (score == null) score = new Element(0);

                    // Set all the score lines in the scoreboard, creating fake players
                    // for those lines that are not meant to track players
                    //
                    // Read https://forums.bukkit.org/threads/help-with-multi-line-scoreboards.181149/
                    // for clarifications
                    for (String line : lines) {
                        line = line.replaceAll("[pP]@", "");
                        if (line.length() > 48) {
                            line = line.substring(0, 48);
                        }
                        ScoreboardHelper.addScore(obj, getOfflinePlayer(line), score.asInt());
                    }
                }
            }
            // If there is no objective and no viewers, but there are some lines,
            // the command cannot do anything at all, so print a message about that
            else if (viewers == null && !lines.isEmpty()) {
                dB.echoDebug(scriptEntry, "Cannot add lines without specifying an objective!");
            }
        }
        else if (act.equals(Action.REMOVE)) {
            if (objective != null) {
                // Try getting the objective from the board
                obj = board.getObjective(objective.asString());

                if (obj != null) {
                    // Remove the entire objective if no lines have been specified
                    if (lines.isEmpty()) {
                        dB.echoDebug(scriptEntry, "Removing objective " + obj.getName() +
                                " from scoreboard " + id.asString());
                        obj.unregister();
                    }
                    else {
                        for (String line : lines) {
                            line = line.replaceAll("[pP]@", "");
                            ScoreboardHelper.removeScore(obj, getOfflinePlayer(line));
View Full Code Here

    /**
     * @return false if power levels are disabled
     */
    public static boolean powerLevelHeartbeat() {
        Objective mainObjective = getPowerLevelObjective();

        if (mainObjective == null) {
            return false; // indicates
        }

        for (String playerName : dirtyPowerLevels) {
            McMMOPlayer mcMMOPlayer = UserManager.getOfflinePlayer(playerName);

            if (mcMMOPlayer == null) {
                continue;
            }

            Player player = mcMMOPlayer.getPlayer();
            int power = mcMMOPlayer.getPowerLevel();

            mainObjective.getScore(playerName).setScore(power);

            for (ScoreboardWrapper wrapper : PLAYER_SCOREBOARDS.values()) {
                wrapper.updatePowerLevel(player, power);
            }
        }
View Full Code Here

     *
     * @return the main scoreboard objective, or null if disabled
     */
    public static Objective getPowerLevelObjective() {
        if (!Config.getInstance().getPowerLevelTagsEnabled()) {
            Objective objective = mcMMO.p.getServer().getScoreboardManager().getMainScoreboard().getObjective(POWER_OBJECTIVE);

            if (objective != null) {
                objective.unregister();
                mcMMO.p.debug("Removed leftover scoreboard objects from Power Level Tags.");
            }

            return null;
        }

        Objective powerObjective = mcMMO.p.getServer().getScoreboardManager().getMainScoreboard().getObjective(POWER_OBJECTIVE);

        if (powerObjective == null) {
            powerObjective = mcMMO.p.getServer().getScoreboardManager().getMainScoreboard().registerNewObjective(POWER_OBJECTIVE, "dummy");
            powerObjective.setDisplayName(TAG_POWER_LEVEL);
            powerObjective.setDisplaySlot(DisplaySlot.BELOW_NAME);
        }

        return powerObjective;
    }
View Full Code Here

                        if (displayName.length() > 32) {
                            sender.sendMessage(ChatColor.RED + "The name '" + displayName + "' is too long for an objective, it can be at most 32 characters long");
                            return false;
                        }
                    }
                    Objective objective = mainScoreboard.registerNewObjective(name, criteria);
                    if (displayName != null && displayName.length() > 0) {
                        objective.setDisplayName(displayName);
                    }
                    sender.sendMessage("Added new objective '" + name + "' successfully");
                }
            } else if (args[1].equalsIgnoreCase("remove")) {
                if (args.length != 3) {
                    sender.sendMessage(ChatColor.RED + "/scoreboard objectives remove <name>");
                    return false;
                }
                String name = args[2];
                Objective objective = mainScoreboard.getObjective(name);
                if (objective == null) {
                    sender.sendMessage(ChatColor.RED + "No objective was found by the name '" + name + "'");
                } else {
                    objective.unregister();
                    sender.sendMessage("Removed objective '" + name + "' successfully");
                }
            } else if (args[1].equalsIgnoreCase("setdisplay")) {
                if (args.length != 3 && args.length != 4) {
                    sender.sendMessage(ChatColor.RED + "/scoreboard objectives setdisplay <slot> [objective]");
                    return false;
                }
                String slotName = args[2];
                DisplaySlot slot = OBJECTIVES_DISPLAYSLOT.get(slotName);
                if (slot == null) {
                    sender.sendMessage(ChatColor.RED + "No such display slot '" + slotName + "'");
                } else {
                    if (args.length == 4) {
                        String objectiveName = args[3];
                        Objective objective = mainScoreboard.getObjective(objectiveName);
                        if (objective == null) {
                            sender.sendMessage(ChatColor.RED + "No objective was found by the name '" + objectiveName + "'");
                            return false;
                        }

                        objective.setDisplaySlot(slot);
                        sender.sendMessage("Set the display objective in slot '" + slotName + "' to '" + objective.getName() + "'");
                    } else {
                        Objective objective = mainScoreboard.getObjective(slot);
                        if (objective != null) {
                            objective.setDisplaySlot(null);
                        }
                        sender.sendMessage("Cleared objective display slot '" + slotName + "'");
                    }
                }
            }
        } else if (args[0].equalsIgnoreCase("players")) {
            if (args.length == 1) {
                sender.sendMessage(ChatColor.RED + "/scoreboard players <set|add|remove|reset|list>");
                return false;
            }
            if (args[1].equalsIgnoreCase("set") || args[1].equalsIgnoreCase("add") || args[1].equalsIgnoreCase("remove")) {
                if (args.length != 5) {
                    if (args[1].equalsIgnoreCase("set")) {
                        sender.sendMessage(ChatColor.RED + "/scoreboard players set <player> <objective> <score>");
                    } else if (args[1].equalsIgnoreCase("add")) {
                        sender.sendMessage(ChatColor.RED + "/scoreboard players add <player> <objective> <count>");
                    } else {
                        sender.sendMessage(ChatColor.RED + "/scoreboard players remove <player> <objective> <count>");
                    }
                    return false;
                }
                String objectiveName = args[3];
                Objective objective = mainScoreboard.getObjective(objectiveName);
                if (objective == null) {
                    sender.sendMessage(ChatColor.RED + "No objective was found by the name '" + objectiveName + "'");
                    return false;
                } else if (!objective.isModifiable()) {
                    sender.sendMessage(ChatColor.RED + "The objective '" + objectiveName + "' is read-only and cannot be set");
                    return false;
                }

                String valueString = args[4];
                int value;
                try {
                    value = Integer.parseInt(valueString);
                } catch (NumberFormatException e) {
                    sender.sendMessage(ChatColor.RED + "'" + valueString + "' is not a valid number");
                    return false;
                }
                if (value < 1 && !args[1].equalsIgnoreCase("set")) {
                    sender.sendMessage(ChatColor.RED + "The number you have entered (" + value + ") is too small, it must be at least 1");
                    return false;
                }

                String playerName = args[2];
                if (playerName.length() > 16) {
                    sender.sendMessage(ChatColor.RED + "'" + playerName + "' is too long for a player name");
                    return false;
                }
                Score score = objective.getScore(playerName);
                int newScore;
                if (args[1].equalsIgnoreCase("set")) {
                    newScore = value;
                } else if (args[1].equalsIgnoreCase("add")) {
                    newScore = score.getScore() + value;
View Full Code Here

            if (displayName.length() > 32) {
              sender.sendMessage(ChatColor.RED + "The name '" + displayName + "' is too long for an objective, it can be at most 32 characters long");
              return false;
            }
          }
          Objective objective = scoreboard.registerNewObjective(name, criteria);
          if (displayName != null && displayName.length() > 0) {
            objective.setDisplayName(displayName);
          }
          sender.sendMessage("Added new objective '" + name + "' successfully");
        }
      } else if (args[1].equalsIgnoreCase("remove")) {
        if (args.length != 3) {
          sender.sendMessage(ChatColor.RED + "/scoreboard objectives remove <name>");
          return false;
        }
        String name = args[2];
        Objective objective = scoreboard.getObjective(name);
        if (objective == null) {
          sender.sendMessage(ChatColor.RED + "No objective was found by the name '" + name + "'");
        } else {
          objective.unregister();
          sender.sendMessage("Removed objective '" + name + "' successfully");
        }
      } else if (args[1].equalsIgnoreCase("setdisplay")) {
        if (args.length != 3 && args.length != 4) {
          sender.sendMessage(ChatColor.RED + "/scoreboard objectives setdisplay <slot> [objective]");
          return false;
        }
        String slotName = args[2];
        DisplaySlot slot = OBJECTIVES_DISPLAYSLOT.get(slotName);
        if (slot == null) {
          sender.sendMessage(ChatColor.RED + "No such display slot '" + slotName + "'");
        } else {
          if (args.length == 4) {
            String objectiveName = args[3];
            Objective objective = scoreboard.getObjective(objectiveName);
            if (objective == null) {
              sender.sendMessage(ChatColor.RED + "No objective was found by the name '" + objectiveName + "'");
              return false;
            }

            objective.setDisplaySlot(slot);
            sender.sendMessage("Set the display objective in slot '" + slotName + "' to '" + objective.getName() + "'");
          } else {
            Objective objective = scoreboard.getObjective(slot);
            if (objective != null) {
              objective.setDisplaySlot(null);
            }
            sender.sendMessage("Cleared objective display slot '" + slotName + "'");
          }
        }
      }
    } else if (args[0].equalsIgnoreCase("players")) {
      if (args.length == 1) {
        sender.sendMessage(ChatColor.RED + "/scoreboard players <set|add|remove|reset|list>");
        return false;
      }
      if (args[1].equalsIgnoreCase("set") || args[1].equalsIgnoreCase("add") || args[1].equalsIgnoreCase("remove")) {
        if (args.length != 5) {
          if (args[1].equalsIgnoreCase("set")) {
            sender.sendMessage(ChatColor.RED + "/scoreboard players set <player> <objective> <score>");
          } else if (args[1].equalsIgnoreCase("add")) {
            sender.sendMessage(ChatColor.RED + "/scoreboard players add <player> <objective> <count>");
          } else {
            sender.sendMessage(ChatColor.RED + "/scoreboard players remove <player> <objective> <count>");
          }
          return false;
        }
        String objectiveName = args[3];
        Objective objective = scoreboard.getObjective(objectiveName);
        if (objective == null) {
          sender.sendMessage(ChatColor.RED + "No objective was found by the name '" + objectiveName + "'");
          return false;
        } else if (!objective.isModifiable()) {
          sender.sendMessage(ChatColor.RED + "The objective '" + objectiveName + "' is read-only and cannot be set");
          return false;
        }

        String valueString = args[4];
        int value;
        try {
          value = Integer.parseInt(valueString);
        } catch (NumberFormatException e) {
          sender.sendMessage(ChatColor.RED + "'" + valueString + "' is not a valid number");
          return false;
        }
        if (value < 1 && !args[1].equalsIgnoreCase("set")) {
          sender.sendMessage(ChatColor.RED + "The number you have entered (" + value + ") is too small, it must be at least 1");
          return false;
        }

        String playerName = args[2];
        if (playerName.length() > 16) {
          sender.sendMessage(ChatColor.RED + "'" + playerName + "' is too long for a player name");
          return false;
        }
        Score score = objective.getScore(Bukkit.getOfflinePlayer(playerName));
        int newScore;
        if (args[1].equalsIgnoreCase("set")) {
          newScore = value;
        } else if (args[1].equalsIgnoreCase("add")) {
          newScore = score.getScore() + value;
View Full Code Here

    long randx = System.currentTimeMillis() % (1L << 16);
    infoboardObjective = infoboard.registerNewObjective(
      String.format("ar#scores_%x", randx), "dummy");

    // kill count objective
    Objective infoKillCount = infoboard.registerNewObjective(
      String.format("ar#kills_%x", randx), "playerKillCount");
    infoKillCount.setDisplayName(ChatColor.BOLD + "Kills");

    // death count objective
    Objective infoDeathCount = infoboard.registerNewObjective(
      String.format("ar#deaths_%x", randx), "deathCount");
    infoDeathCount.setDisplayName(ChatColor.BOLD + "Deaths");

    // objectives list (for cycling through after the match)
    allInfoObjectives = Lists.newArrayList(infoboardObjective, infoKillCount, infoDeathCount);

    try
    {
      File dataFolder = new File(primaryWorld.getWorldFolder(), "data");
      File scoreboardFile = new File(dataFolder, "scoreboard.xml");
      Element sbroot = new SAXBuilder().build(scoreboardFile).getRootElement();

      for (Element teamnode : sbroot.getChild("teams").getChildren("team"))
      {
        Team team = scoreboard.registerNewTeam(teamnode.getAttributeValue("name"));
        team.setPrefix(teamnode.getAttributeValue("prefix"));
        team.setSuffix(teamnode.getAttributeValue("suffix"));
      }

      for (Element objroot : sbroot.getChild("objectives").getChildren("objective"))
      {
        Objective obj = scoreboard.registerNewObjective(
            objroot.getAttributeValue("name"),
            objroot.getAttributeValue("criteria"));

        if (objroot.getAttributeValue("display") != null)
          obj.setDisplaySlot(DisplaySlot.valueOf(objroot.getAttributeValue("display")));
      }

      AutoReferee.log("Loaded custom scoreboard data.");
    }
    catch (FileNotFoundException ignored)
View Full Code Here

TOP

Related Classes of org.bukkit.scoreboard.Objective

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.