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;