本文整理匯總了Java中org.bukkit.scoreboard.Objective.getDisplayName方法的典型用法代碼示例。如果您正苦於以下問題:Java Objective.getDisplayName方法的具體用法?Java Objective.getDisplayName怎麽用?Java Objective.getDisplayName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.bukkit.scoreboard.Objective
的用法示例。
在下文中一共展示了Objective.getDisplayName方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: get
import org.bukkit.scoreboard.Objective; //導入方法依賴的package包/類
@Override
@Nullable
protected String[] get(Event evt) {
if (player != null
&& player.getSingle(evt).getScoreboard().getObjective("sidebarHold") != null) {
Objective objective = player.getSingle(evt).getScoreboard().getObjective(DisplaySlot.SIDEBAR);
return new String[] {objective.getDisplayName()};
}
return null;
}
示例2: run
import org.bukkit.scoreboard.Objective; //導入方法依賴的package包/類
@Override
public void run() {
if(_trackedPlayerBoards == null || playerID == null || scoreInfo == null){
dispose();
return;
}
Scoreboard board = _trackedPlayerBoards.get(playerID);
if(board == null){
dispose();
return;
}
Objective objective = board.getObjective(SIDEBOARD_OBJECTIVE_NAME);
if(objective == null){
dispose();
return;
}
String oldTitle = scoreInfo.getTitle().tick();
String newTitle = scoreInfo.getTitle().toString();
if(objective.getDisplayName() != oldTitle && objective.getDisplayName() != newTitle){
objective.setDisplayName(newTitle);
}else if(oldTitle != newTitle /* Don't change the title unless we really have to*/){
objective.setDisplayName(newTitle);
}
}
示例3: update
import org.bukkit.scoreboard.Objective; //導入方法依賴的package包/類
private void update(Player player) {
List<ScoreboardElement> elements = getElements(player);
if (elements == null || elements.isEmpty() || !isVisible(player)) {
// Player has no elements to show
return;
}
Scoreboard board = player.getScoreboard();
Objective objective = board.getObjective(DUMMY_PREFIX);
boolean forceUpdate = false;
if (objective == null) {
// objective not yet created for this player; will force add all elements to scoreboard
forceUpdate = true;
objective = board.registerNewObjective(DUMMY_PREFIX, "dummy");
}
if (objective.getDisplaySlot() != DisplaySlot.SIDEBAR) {
objective.setDisplaySlot(DisplaySlot.SIDEBAR);
}
// title always the last element because of sorting: -ve < +ve
ScoreboardElement titleElement = elements.get(elements.size() - 1);
if (titleElement.isTitle() && titleElement.getSize() > 0) {
String title = fixFormat(titleElement.getContents(player).get(0));
if (!title.equals(objective.getDisplayName())) {
objective.setDisplayName(title);
}
} else if (objective.getDisplayName() != null || !objective.getDisplayName().isEmpty()) {
// remove title if there isn't one
objective.setDisplayName("");
}
// list of elements to remove after; can't remove in iterator for CopyOnWriteArrayList
List<ScoreboardElement> removals = null;
int i = 24; // 24 -> 10 all double digit for less annoying score placement
Iterator<ScoreboardElement> it = elements.iterator();
while (it.hasNext()) {
ScoreboardElement element = it.next();
if (element.isTitle() || element.getSize() == 0) {
continue;
}
if (!element.getPlugin().isEnabled()) {
// may cause errors to display so remove this element
removals = Optional.ofNullable(removals).orElse(Lists.newArrayList());
removals.add(element);
continue;
}
if (!forceUpdate && !hasUpdate(element)) {
i -= element.getSize();
continue;
}
for (String text : element.getContents(player)) {
if (i < 10) {
break;
}
// set text for current line
setLine(board, objective, i, text);
--i;
}
}
// clear up scoreboard if nothing there
while (i >= 10) {
removeLine(board, i);
--i;
}
Optional.ofNullable(removals).ifPresent(r -> r.stream().forEach(elements::remove));
}