本文整理匯總了Java中org.bukkit.scoreboard.Objective類的典型用法代碼示例。如果您正苦於以下問題:Java Objective類的具體用法?Java Objective怎麽用?Java Objective使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Objective類屬於org.bukkit.scoreboard包,在下文中一共展示了Objective類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: sendObjective
import org.bukkit.scoreboard.Objective; //導入依賴的package包/類
private void sendObjective(Objective obj, ObjectiveMode mode) {
try {
Object objHandle = NMS.getHandle(obj);
Object packetObj = NMS.PACKET_OBJ.newInstance(
objHandle,
mode.ordinal()
);
NMS.sendPacket(packetObj, player);
} catch(InstantiationException | IllegalAccessException
| InvocationTargetException | NoSuchMethodException e) {
LOGGER.error("Error while creating and sending objective packet. (Unsupported Minecraft version?)", e);
}
}
示例2: enableScoreboard
import org.bukkit.scoreboard.Objective; //導入依賴的package包/類
@Override
public void enableScoreboard() {
final Scoreboard board = Bukkit.getScoreboardManager().getNewScoreboard();
final Objective obj = board.registerNewObjective("Spigotboard", "dummy");
obj.setDisplaySlot(DisplaySlot.SIDEBAR);
obj.setDisplayName(ChatColor.translateAlternateColorCodes('&', Main.instance.getConfig().getString("title")));
new BukkitRunnable() {
@Override
public void run() {
for(Player p : Bukkit.getOnlinePlayers()) {
int count = Main.instance.getConfig().getList("text").size();
PlaceholderUtils placeholders = new PlaceholderUtils(p);
for(Object text : Main.instance.getConfig().getList("text")){
obj.getScore(ChatColor.translateAlternateColorCodes('&', placeholders.replace(text.toString()))).setScore(count);
count--;
}
p.setScoreboard(board);
}
}
}.runTaskTimer(Main.instance, 0, 20);
}
示例3: getOrCreateObjective
import org.bukkit.scoreboard.Objective; //導入依賴的package包/類
private static Objective getOrCreateObjective(Scoreboard scoreboard, String name, String criteria) {
Objective obj = scoreboard.getObjective(name);
if(obj == null) {
obj = scoreboard.registerNewObjective(name, criteria);
}
return obj;
}
示例4: displayScoreboard
import org.bukkit.scoreboard.Objective; //導入依賴的package包/類
@EventHandler(priority = EventPriority.MONITOR)
public void displayScoreboard(final PlayerJoinEvent event) {
final Player player = event.getPlayer();
final User user = userStore.getUser(player);
final PlayerId playerId = tc.oc.api.bukkit.users.Users.playerId(player);
final Scoreboard scoreboard = Bukkit.getScoreboardManager().getMainScoreboard();
final Objective objective = getOrCreateObjective(scoreboard, player.getName(), "dummy");
final String raindropsName = ChatColor.AQUA + "Raindrops";
objective.setDisplayName(renderer.renderLegacy(generalFormatter.brandName(), event.getPlayer()));
objective.getScore(raindropsName).setScore(2);
Utils.displayScoreboard(player, objective);
setRaindropsCount(player, user.raindrops());
GizmoUtils.setGizmo(player, Gizmos.emptyGizmo, true);
}
示例5: setRaindropsCount
import org.bukkit.scoreboard.Objective; //導入依賴的package包/類
private void setRaindropsCount(Player player, int count) {
if(player == null) return;
final Scoreboard scoreboard = Bukkit.getScoreboardManager().getMainScoreboard();
Objective objective = scoreboard.getObjective(player.getName());
Integer oldCount = raindrops.get(player);
if(oldCount != null) {
Utils.removeScore(player, String.format("%,d", oldCount));
}
Utils.addScore(player, objective, String.format("%,d", count), 1);
raindrops.put(player, count);
Utils.giveGhastTear(player, count);
}
示例6: setLine
import org.bukkit.scoreboard.Objective; //導入依賴的package包/類
/**
* Updates the given text for the line and given objectiveName
*
* @param objectiveName objectiveName
* @param line line
* @param text text
* @return scoreboard
*/
public SimpleScoreboard setLine(String objectiveName, int line, String text) {
final Objective objective = this.getObjective(objectiveName);
final Objective bufferObjective;
if (objective.getName().endsWith("_buf")) {
bufferObjective = this.scoreboard.registerNewObjective(objectiveName.substring(0, objective.getName().indexOf("_buf")), objective.getCriteria());
} else {
bufferObjective = this.scoreboard.registerNewObjective(objectiveName + "_buf", objective.getCriteria());
}
for (final String s : this.scoreboard.getEntries()) {
final Score score = objective.getScore(s);
if (score.getScore() != 0 && score.getScore() != line) {
bufferObjective.getScore(s).setScore(score.getScore());
}
}
if (text != null) {
bufferObjective.getScore(ChatColor.translateAlternateColorCodes('&', text)).setScore(line);
}
bufferObjective.setDisplayName(objective.getDisplayName());
bufferObjective.setDisplaySlot(objective.getDisplaySlot());
objective.unregister();
return this;
}
示例7: refreshScoreboard
import org.bukkit.scoreboard.Objective; //導入依賴的package包/類
private void refreshScoreboard(Player player)
{
if (getThirstString(player).length() > 40)
{
Thirst.getInstance().printPluginError("Error occurred while displaying scoreboard.", "The string "+getThirstString(player)+" is longer than 40 characters." +
"\nYou must have a thirst message under 40 characters to use the SCOREBOARD displaytype." +
"\n " +
"\nNOTE: This message will be displayed every time Thirst tries to update someones thirst (A lot!)");
return;
}
Scoreboard board = manager.getNewScoreboard();
Objective obj = board.registerNewObjective(player.getName().toUpperCase(), "dummy");
obj.setDisplaySlot(DisplaySlot.SIDEBAR);
obj.setDisplayName(ChatColor.translateAlternateColorCodes('&', Thirst.getInstance().getYAMLConfig().scoreboardName.replace("%player%", player.getName())));
obj.getScore(getThirstString(player)).setScore(-1);
player.setScoreboard(board);
}
示例8: createPlayerHealthObjective
import org.bukkit.scoreboard.Objective; //導入依賴的package包/類
/**
* Show the player's health under their nameplate
*/
private void createPlayerHealthObjective(Match match) {
Scoreboard board = boards.get(match);
Objective objective = board.registerNewObjective("playerhealth", "health");
objective.setDisplaySlot(DisplaySlot.BELOW_NAME);
objective.setDisplayName(ChatColor.RED + "❤");
//Force health objective to update health readout
for (Team team : match.getTeams().values()) {
for (Player player : team.getPlayers()) {
player.setHealth(player.getHealth());
}
}
}
示例9: createSidebarTeamScoreObjective
import org.bukkit.scoreboard.Objective; //導入依賴的package包/類
/**
* Set up the sidebar score box
*/
private void createSidebarTeamScoreObjective(Match match) {
Scoreboard board = boards.get(match);
Objective objective = board.registerNewObjective("matchscore", "dummy");
objective.setDisplaySlot(DisplaySlot.SIDEBAR);
objective.setDisplayName(String.format("Match %s(00:00)", ChatColor.AQUA));
// Create score lines for each team
for (Team team : match.getTeams().values()) {
if (!team.isSpectator()) {
Score score = objective.getScore(team.getChatColor() + team.getName());
score.setScore(0);
}
}
}
示例10: get
import org.bukkit.scoreboard.Objective; //導入依賴的package包/類
@Override
@Nullable
protected Objective[] get(Event e) {
Scoreboard board = Bukkit.getScoreboardManager().getMainScoreboard();
if (scoreboard != null) {
board = scoreboard.getSingle(e);
}
if (obj.getSingle(e).equals("BELOW_NAME")||obj.getSingle(e).equals("PLAYER_LIST")||obj.getSingle(e).equals("SIDEBAR")) {
DisplaySlot slot = DisplaySlot.valueOf(obj.getSingle(e).replace("\"", "").trim().replace(" ", "_").toUpperCase());
try {
slot = DisplaySlot.valueOf(slot.toString().replace("\"", "").trim().replace(" ", "_").toUpperCase());
} catch (IllegalArgumentException t) {
return null;
}
return new Objective[]{board.getObjective(slot)};
} else {
return new Objective[]{board.getObjective(obj.getSingle(e))};
}
}
示例11: setupScoreboard
import org.bukkit.scoreboard.Objective; //導入依賴的package包/類
private void setupScoreboard() {
Scoreboard scoreboard = Bukkit.getScoreboardManager().getMainScoreboard();
for(Team team : scoreboard.getTeams()) {
team.unregister();
}
for(Objective objective : scoreboard.getObjectives()) {
objective.unregister();
}
}
示例12: ShowThirst
import org.bukkit.scoreboard.Objective; //導入依賴的package包/類
@SuppressWarnings("deprecation")
public static List<String> ShowThirst(Player player)
{
Objective thirst = Survival.mainBoard.getObjective("Thirst");
String thirstBar = "";
for(int i = 0; i < thirst.getScore(player).getScore(); i++)
{
thirstBar += "|";
}
for(int i = thirst.getScore(player).getScore(); i < 20; i++)
{
thirstBar += ".";
}
if(thirst.getScore(player).getScore() >= 40)
thirstBar = ChatColor.GREEN + thirstBar;
else if(thirst.getScore(player).getScore() <= 6)
thirstBar = ChatColor.RED + thirstBar;
else
thirstBar = ChatColor.AQUA + thirstBar;
return Arrays.asList(ChatColor.AQUA + Words.get("Thirst"), (thirstBar.length() <= 22 ? thirstBar.substring(0) : thirstBar.substring(0, 22)), thirstBar.substring(0, 2) + (thirstBar.length() > 22 ? thirstBar.substring(22) : "") + ChatColor.RESET + ChatColor.RESET);
}
示例13: sendObjectiveDisplay
import org.bukkit.scoreboard.Objective; //導入依賴的package包/類
private void sendObjectiveDisplay(Objective obj) {
try {
Object objHandle = NMS.getHandle(obj);
Object packet = NMS.PACKET_DISPLAY.newInstance(
1,
objHandle
);
NMS.sendPacket(packet, player);
} catch(InstantiationException | IllegalAccessException
| InvocationTargetException | NoSuchMethodException e) {
LOGGER.error("Error while creating and sending display packet. (Unsupported Minecraft version?)", e);
}
}
示例14: ScoreHelper
import org.bukkit.scoreboard.Objective; //導入依賴的package包/類
private ScoreHelper(Player player, boolean healthName, boolean healthTab) {
this.player = player;
scoreboard = Bukkit.getScoreboardManager().getNewScoreboard();
sidebar = scoreboard.registerNewObjective("sidebar", "dummy");
sidebar.setDisplaySlot(DisplaySlot.SIDEBAR);
player.setScoreboard(scoreboard);
// Create Teams
for(int i=1; i<=15; i++) {
Team team = scoreboard.registerNewTeam("SLOT_" + i);
team.addEntry(genEntry(i));
}
if(healthName) {
Objective hName = scoreboard.registerNewObjective("hname", "health");
hName.setDisplaySlot(DisplaySlot.BELOW_NAME);
hName.setDisplayName(ChatColor.RED + "❤");
}
if(healthTab) {
Objective hTab = scoreboard.registerNewObjective("htab", "health");
hTab.setDisplaySlot(DisplaySlot.PLAYER_LIST);
}
players.put(player.getUniqueId(), this);
}
示例15: HUD
import org.bukkit.scoreboard.Objective; //導入依賴的package包/類
public HUD(Player player, FlightHUDPlugin plugin, FHManager manager) {
previousScoreboard = player.getScoreboard();
this.scoreboard = plugin.getServer().getScoreboardManager().getNewScoreboard();
this.player = player;
this.manager = manager;
Objective obj = scoreboard.registerNewObjective("hud", "dummy");
obj.setDisplaySlot(DisplaySlot.SIDEBAR);
obj.getScore(ChatColor.GREEN + "Airspeed b/s").setScore(0);
obj.getScore(ChatColor.GREEN + "Ground speed").setScore(0);
obj.getScore(ChatColor.GREEN + "Heading").setScore(0);
obj.getScore(ChatColor.GREEN + "Sink rate b/s").setScore(0);
player.setScoreboard(scoreboard);
taskID = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new HUDScheduler(this), 0, 2);
}