下面列出了怎么用org.bukkit.boss.BarStyle的API类实例代码及写法,或者点击链接到github查看源代码。
private static BossBarStyle convertStyle(BarStyle style) {
switch (style) {
case SOLID:
return BossBarStyle.SOLID;
case SEGMENTED_6:
return BossBarStyle.SEGMENTED_6;
case SEGMENTED_10:
return BossBarStyle.SEGMENTED_10;
case SEGMENTED_12:
return BossBarStyle.SEGMENTED_12;
case SEGMENTED_20:
return BossBarStyle.SEGMENTED_20;
default:
return BossBarStyle.defaultStyle();
}
}
private static BarStyle convertStyle(BossBarStyle style) {
switch (style) {
case SOLID:
return BarStyle.SOLID;
case SEGMENTED_6:
return BarStyle.SEGMENTED_6;
case SEGMENTED_10:
return BarStyle.SEGMENTED_10;
case SEGMENTED_12:
return BarStyle.SEGMENTED_12;
case SEGMENTED_20:
return BarStyle.SEGMENTED_20;
default:
return convertStyle(BossBarStyle.defaultStyle());
}
}
private void updateArena(Arena arena) {
final Game game = games.byId(arena.game_id());
int minPlayers = 0;
if(arena.next_server_id() != null) {
minPlayers = servers.byId(arena.next_server_id()).min_players();
}
final BaseComponent text;
final double progress;
if(minPlayers > 0 && arena.num_queued() < minPlayers) {
text = gameFormatter.queued(game, minPlayers - arena.num_queued());
progress = (double) arena.num_queued() / (double) minPlayers;
} else {
text = gameFormatter.joining(game);
progress = 1;
}
bars.getUnchecked(arena).update(text, progress, BarColor.YELLOW, BarStyle.SOLID, Collections.emptySet());
}
public CraftBossBar(String title, BarColor color, BarStyle style, BarFlag... flags) {
this.flags = flags.length > 0 ? EnumSet.of(flags[0], flags) : EnumSet.noneOf(BarFlag.class);
this.color = color;
this.style = style;
handle = new BossInfoServer(
CraftChatMessage.fromString(title, true)[0],
convertColor(color),
convertStyle(style)
);
updateFlags();
}
private BossInfo.Overlay convertStyle(BarStyle style) {
switch (style) {
default:
case SOLID:
return BossInfo.Overlay.PROGRESS;
case SEGMENTED_6:
return BossInfo.Overlay.NOTCHED_6;
case SEGMENTED_10:
return BossInfo.Overlay.NOTCHED_10;
case SEGMENTED_12:
return BossInfo.Overlay.NOTCHED_12;
case SEGMENTED_20:
return BossInfo.Overlay.NOTCHED_20;
}
}
public static void sendBossBarMessage(final World world, final String message, final String color, final double percentage) {
if (!Config.getBoolean("messages.bossbar.enabled") || message.length() < 1) return;
BossBar bar = Bukkit.createBossBar(Messages.prepareMessage(world, message), getBarColor(color), BarStyle.SOLID);
bar.setProgress(percentage);
world.getPlayers().forEach(bar::addPlayer);
Bukkit.getScheduler().runTaskLater(Harbor.getHarbor(), bar::removeAll, Config.getInteger("interval") * 20);
}
View(BossBarSource source, Player viewer) {
this.source = source;
this.viewer = viewer;
this.bar = bossBarFactory.createBossBar(Components.blank(), BarColor.WHITE, BarStyle.SOLID);
render();
bar.addPlayer(viewer);
}
@EventHandler(priority = EventPriority.HIGHEST)
public void join(final PlayerJoinEvent event) {
Player player = event.getPlayer();
resetPlayer(player);
event.getPlayer().addAttachment(lobby, Permissions.OBSERVER, true);
if (player.hasPermission("lobby.overhead-news")) {
final String datacenter = minecraftService.getLocalServer().datacenter();
final Component news = new Component(ChatColor.GREEN)
.extra(new TranslatableComponent(
"lobby.news",
new Component(ChatColor.GOLD, ChatColor.BOLD).extra(generalFormatter.publicHostname())
));
final BossBar bar = bossBarFactory.createBossBar(renderer.render(news, player), BarColor.BLUE, BarStyle.SOLID);
bar.setProgress(1);
bar.addPlayer(player);
bar.show();
}
if(!player.hasPermission("lobby.disabled-permissions-exempt")) {
for(PermissionAttachmentInfo attachment : player.getEffectivePermissions()) {
if(config.getDisabledPermissions().contains(attachment.getPermission())) {
attachment.getAttachment().setPermission(attachment.getPermission(), false);
}
}
}
int count = lobby.getServer().getOnlinePlayers().size();
if(!lobby.getServer().getOnlinePlayers().contains(event.getPlayer())) count++;
minecraftService.updateLocalServer(new SignUpdate(count));
}
@Override
public void update(BaseComponent title, double progress, BarColor color, BarStyle style, Set<BarFlag> flags) {
this.title = title;
this.progress = progress;
this.color = color;
this.style = style;
this.flags.clear();
this.flags.addAll(flags);
views.entrySet().forEach(entry -> entry.getValue().update(renderer.render(title, entry.getKey()), progress, color, style, flags));
}
@Override
public void enable() {
super.enable();
originalTicks = ticks;
log.finer("enable timed phase with name " + getName());
bossBar = Bukkit.createBossBar(getName(), BarColor.BLUE, BarStyle.SEGMENTED_20);
getGame().getPlayers().forEach(u -> bossBar.addPlayer(u.getPlayer()));
getGame().getSpectators().forEach(u -> bossBar.addPlayer(u.getPlayer()));
started = true;
}
/**
* Creates a boss bar if doesn't exist
*
* @param player the player
* @return the boss bar
*/
private BossBar createIfNotExists(Player player) {
if(bossBars.containsKey(player.getUniqueId())) {
return getBossBar(player);
}
BossBar bossBar = Bukkit.getServer().createBossBar("", Config.BOSSBAR_RAIDBAR_COLOR.toEnum(BarColor.class), Config.BOSSBAR_RAIDBAR_STYLE.toEnum(BarStyle.class));
bossBar.addPlayer(player);
bossBars.put(player.getUniqueId(), bossBar);
return bossBar;
}
/**
* Changed the style of a bossbar from the BossBarManager through the stored ID.
*
* @param id The ID text for the bossbar.
* @param style The BarStyle to be used.
*/
void changeStyle(String id, BarStyle style) {
BossBar bar = barMap.get(id);
if (bar != null) {
bar.setStyle(style);
barMap.put(id, bar);
}
}
@Override
protected void execute(Event evt) {
BarStyle barStyle = BarStyle.SOLID;
BarColor barColor = BarColor.PURPLE;
if (style != null) {
barStyle = style.getSingle(evt).getKey();
}
if (color != null) {
barColor = color.getSingle(evt).getKey();
}
BossBar bar;
if (flag != null) {
bar = Bukkit.createBossBar(title.getSingle(evt).replace("\"", ""), barColor, barStyle,
flag.getSingle(evt).getKey());
} else {
bar = Bukkit.createBossBar(title.getSingle(evt).replace("\"", ""), barColor, barStyle);
}
if (value != null) {
double vol = value.getSingle(evt).doubleValue();
if (vol > 100) {
vol = 100;
} else if (vol < 0) {
vol = 0;
}
bar.setProgress(vol / 100);
}
for (Player p : players.getAll(evt)) {
bar.addPlayer(p);
}
Core.bossbarManager.createBossBar(id.getSingle(evt).replace("\"", ""), bar);
}
public Builder style(String barStyle) {
for (BarStyle loopStyle : BarStyle.values()) {
if (loopStyle.name().equalsIgnoreCase(barStyle)) {
this.barStyle = loopStyle;
break;
}
}
return this;
}
public MonumentModes(int after, final Pair<Material, Integer> material, final String name, int showBefore) {
this.after = after;
this.material = material;
this.name = name;
this.showBefore = showBefore;
this.ran = false;
this.bossBar = BossBars.addBroadcastedBossBar(new UnlocalizedChatMessage(""), BarColor.BLUE, BarStyle.SOLID, false);
}
public LocalizedBossBar(ChatMessage bossBarTitle, BarColor color, BarStyle style, BarFlag... flags) {
this.bossBarTitle = bossBarTitle;
this.color = color;
this.style = style;
this.shown = true;
this.flags = flags.length > 0 ? EnumSet.of(flags[0], flags):EnumSet.noneOf(BarFlag.class);
}
public static UUID addBroadcastedBossBar(ChatMessage bossBarTitle, BarColor color, BarStyle style, Boolean shown, BarFlag... flags) {
UUID id = UUID.randomUUID();
LocalizedBossBar bossBar = new LocalizedBossBar(bossBarTitle, color, style, flags);
bossBar.setVisible(shown);
for (Player player : Bukkit.getOnlinePlayers()) {
bossBar.addPlayer(player);
}
broadcastedBossBars.put(id, bossBar);
return id;
}
protected Poll(int id, CommandSender sender, String command, int time, boolean any) {
this.id = id;
this.sender = sender;
this.command = command;
this.any = any;
this.time = time * 20;
this.originalTime = this.time;
this.bossBar = BossBars.addBroadcastedBossBar(new UnlocalizedChatMessage(""), BarColor.YELLOW, BarStyle.SOLID, true);
taskId = Bukkit.getScheduler().scheduleSyncRepeatingTask(Cardinal.getInstance(), new Runnable() {
@Override
public void run() {
Poll.this.update();
}
}, 0L, 1L);
}
@Override
public void onFlagAdd(Game game) {
baseTitle = getI18N().getVarString(Messages.Broadcast.BOSSBAR_PLAYING_ON)
.setVariable("game", game.getName())
.toString();
baseColor = new SafeContainer<>(BarColor.GREEN);
bossBar = new SafeContainer<>(Bukkit.getServer().createBossBar(baseTitle, baseColor.value, BarStyle.SOLID));
bossBar.value.setProgress(DEFAULT_PROGRESS);
}
public BarConfig(String title, BarColor color, BarStyle style, BarFlag[] flags) {
this.title = Objects.requireNonNull(title, "title");
this.color = Objects.requireNonNull(color, "color");
this.style = Objects.requireNonNull(style, "style");
this.flags = Objects.requireNonNull(flags, "flags");
}
public BarStyle style() {
return this.style;
}
private boolean migrate(ConfigurationSection section, int protocol) {
Objects.requireNonNull(section, "section");
Logger logger = this.getLogger();
if (protocol > CURRENT_PROTOCOL_VERSION) {
logger.severe("Your configuration file's protocol version \"" + protocol +
"\" is invalid. Are you trying to load it using a newer version of the plugin?");
return false;
}
if (protocol < 0) {
section.set("lugols-iodine-bar.title", "Działanie Płynu Lugola");
section.set("lugols-iodine-bar.color", BarColor.GREEN.name());
section.set("lugols-iodine-bar.style", BarStyle.SEGMENTED_20.name());
section.set("lugols-iodine-bar.flags", Collections.emptyList());
section.set("lugols-iodine-potion.name", "Płyn Lugola");
section.set("lugols-iodine-potion.description", "Odporność na promieniowanie ({0})");
section.set("lugols-iodine-potion.duration", TimeUnit.MINUTES.toSeconds(section.getInt("potion-duration", 10)));
section.set("lugols-iodine-potion.drink-message", "{0}" + ChatColor.RED + " wypił/a {1}.");
section.set("radiation.bar.title", "Strefa radiacji");
section.set("radiation.bar.color", BarColor.RED.name());
section.set("radiation.bar.style", BarStyle.SOLID.name());
section.set("radiation.bar.flags", Collections.singletonList(BarFlag.DARKEN_SKY.name()));
section.set("radiation.effects.wither.level", 5);
section.set("radiation.effects.wither.ambient", false);
section.set("radiation.effects.wither.has-particles", false);
section.set("radiation.effects.wither.has-icon", false);
section.set("radiation.effects.hunger.level", 1);
section.set("radiation.effects.hunger.ambient", false);
section.set("radiation.effects.hunger.has-particles", false);
section.set("radiation.effects.hunger.has-icon", false);
section.set("radiation.escape-message", "{0}" + ChatColor.RED + " uciekł/a do strefy radiacji.");
// Migrate from the old region-ID based system.
String legacyRegionId = section.getString("region-name", "km_safe_from_radiation");
AtomicBoolean logged = new AtomicBoolean();
section.getStringList("world-names").forEach(worldName -> {
if (logged.compareAndSet(false, true)) {
logger.warning(
"Enabling in legacy region-name mode! The plugin will try to automatically migrate to the new flag-based system.\n" +
"If everything went fine please completely remove your config.yml file.");
}
this.migrateFromRegionId(worldName, legacyRegionId);
});
}
if (protocol < 1) {
section.set("lugols-iodine-potion.recipe.enabled", true);
section.set("lugols-iodine-potion.recipe.base-potion", LugolsIodinePotion.Config.Recipe.DEFAULT_BASE_POTION.name());
section.set("lugols-iodine-potion.recipe.ingredient", LugolsIodinePotion.Config.Recipe.DEFAULT_INGREDIENT.getKey().getKey());
section.set("lugols-iodine-potion.color", null);
}
return true;
}
public BossBar19() {
this.boss = Bukkit.createBossBar("", BarColor.PURPLE, BarStyle.SOLID);
}
@Override
public BarStyle getStyle() {
return boss.getStyle();
}
@Override
public void setStyle(BarStyle style) {
boss.setStyle(style);
}
public BossBar19() {
this.boss = Bukkit.createBossBar("", BarColor.PURPLE, BarStyle.SOLID);
}
@Override
public BarStyle getStyle() {
return boss.getStyle();
}
@Override
public void setStyle(BarStyle style) {
boss.setStyle(style);
}
@Override
public BossBar createBossBar(String title, BarColor color, BarStyle style, BarFlag... flags) {
return new CraftBossBar(title, color, style, flags);
}
@Override
public BarStyle getStyle() {
return style;
}