下面列出了org.bukkit.ChatColor#GRAY 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@EventHandler(priority = EventPriority.MONITOR)
public void onStateChange(MatchPhaseChangeEvent event) {
switch (event.getNewPhase()) {
case STARTING:
phaseColor = ChatColor.YELLOW;
break;
case RUNNING:
phaseColor = ChatColor.GREEN;
break;
case FINISHED:
phaseColor = ChatColor.RED;
break;
default:
phaseColor = ChatColor.GRAY;
}
}
/**
* Sends info about the other accounts owned by the given player to the configured users.
*
* @param auths the names of the accounts also owned by the player
* @param player the player
*/
private void displayOtherAccounts(List<String> auths, Player player) {
if (!service.getProperty(RestrictionSettings.DISPLAY_OTHER_ACCOUNTS) || auths.size() <= 1) {
return;
}
List<String> formattedNames = new ArrayList<>(auths.size());
for (String currentName : auths) {
Player currentPlayer = bukkitService.getPlayerExact(currentName);
if (currentPlayer != null && currentPlayer.isOnline()) {
formattedNames.add(ChatColor.GREEN + currentPlayer.getName() + ChatColor.GRAY);
} else {
formattedNames.add(currentName);
}
}
String message = ChatColor.GRAY + String.join(", ", formattedNames) + ".";
logger.fine("The user " + player.getName() + " has " + auths.size() + " accounts:");
logger.fine(message);
for (Player onlinePlayer : bukkitService.getOnlinePlayers()) {
if (onlinePlayer.getName().equalsIgnoreCase(player.getName())
&& service.hasPermission(onlinePlayer, PlayerPermission.SEE_OWN_ACCOUNTS)) {
service.send(onlinePlayer, MessageKey.ACCOUNTS_OWNED_SELF, Integer.toString(auths.size()));
onlinePlayer.sendMessage(message);
} else if (service.hasPermission(onlinePlayer, AdminPermission.SEE_OTHER_ACCOUNTS)) {
service.send(onlinePlayer, MessageKey.ACCOUNTS_OWNED_OTHER,
player.getName(), Integer.toString(auths.size()));
onlinePlayer.sendMessage(message);
}
}
}
@Override
public String renderSidebarStatusText(@Nullable Competitor competitor, Party viewer) {
if (this.getShowProgress() || viewer.isObserving()) {
String text = this.renderCompletion();
if (PGM.get().getConfiguration().showProximity()) {
String precise = this.renderPreciseCompletion();
if (precise != null) {
text += " " + ChatColor.GRAY + precise;
}
}
return text;
} else {
return super.renderSidebarStatusText(competitor, viewer);
}
}
private String renderScore(Competitor competitor, Party viewingParty) {
ScoreMatchModule smm = match.needModule(ScoreMatchModule.class);
String text = ChatColor.WHITE.toString() + (int) smm.getScore(competitor);
if (smm.hasScoreLimit()) {
text += ChatColor.DARK_GRAY + "/" + ChatColor.GRAY + smm.getScoreLimit();
}
return text;
}
public MotdListener() {
this.phaseColor = ChatColor.GRAY;
MapInfo map = PGM.get().getMapOrder().getNextMap();
if (map == null) {
map = PGM.get().getMapLibrary().getMaps().next();
}
this.mapName = map.getName();
}
public static void broadcastCommandMessage(CommandSender source, String message, boolean sendToSource) {
String result = source.getName() + ": " + message;
if (source instanceof BlockCommandSender) {
BlockCommandSender blockCommandSender = (BlockCommandSender) source;
if (blockCommandSender.getBlock().getWorld().getGameRuleValue("commandBlockOutput").equalsIgnoreCase("false")) {
Bukkit.getConsoleSender().sendMessage(result);
return;
}
} else if (source instanceof CommandMinecart) {
CommandMinecart commandMinecart = (CommandMinecart) source;
if (commandMinecart.getWorld().getGameRuleValue("commandBlockOutput").equalsIgnoreCase("false")) {
Bukkit.getConsoleSender().sendMessage(result);
return;
}
}
Set<Permissible> users = Bukkit.getPluginManager().getPermissionSubscriptions(Server.BROADCAST_CHANNEL_ADMINISTRATIVE);
String colored = ChatColor.GRAY + "" + ChatColor.ITALIC + "[" + result + ChatColor.GRAY + ChatColor.ITALIC + "]";
if (sendToSource && !(source instanceof ConsoleCommandSender)) {
source.sendMessage(message);
}
for (Permissible user : users) {
if (user instanceof CommandSender && user.hasPermission(Server.BROADCAST_CHANNEL_ADMINISTRATIVE)) {
CommandSender target = (CommandSender) user;
if (target instanceof ConsoleCommandSender) {
target.sendMessage(result);
} else if (target != source) {
target.sendMessage(colored);
}
}
}
}
public static ChatColor convertBannerColorToChatColor(DyeColor dye) {
switch (dye) {
case WHITE:
return ChatColor.WHITE;
case ORANGE:
return ChatColor.GOLD;
case MAGENTA:
return ChatColor.LIGHT_PURPLE;
case LIGHT_BLUE:
return ChatColor.BLUE;
case YELLOW:
return ChatColor.YELLOW;
case LIME:
return ChatColor.GREEN;
case PINK:
return ChatColor.RED;
case GRAY:
return ChatColor.DARK_GRAY;
case SILVER:
return ChatColor.GRAY;
case CYAN:
return ChatColor.DARK_AQUA;
case PURPLE:
return ChatColor.DARK_PURPLE;
case BLUE:
return ChatColor.BLUE;
case BROWN:
return ChatColor.GOLD;
case GREEN:
return ChatColor.DARK_GREEN;
case RED:
return ChatColor.DARK_RED;
case BLACK:
return ChatColor.BLACK;
}
return ChatColor.WHITE;
}
@Override
public String renderSidebarStatusText(@Nullable Competitor competitor, Party viewer) {
if(this.getShowProgress() || Parties.isObservingType(viewer)) {
String text = this.renderCompletion();
if(Config.Scoreboard.preciseProgress()) {
String precise = this.renderPreciseCompletion();
if(precise != null) {
text += " " + ChatColor.GRAY + precise;
}
}
return text;
} else {
return super.renderSidebarStatusText(competitor, viewer);
}
}
private void spy(Player player, String message) {
String spyMessage = ChatColor.GOLD + "[Spy] " + ChatColor.GRAY + player.getName() + ": " + ChatColor.WHITE + message;
for (Player looped : Bukkit.getOnlinePlayers()) {
if (User.get(looped).getCache().isSpy()) {
looped.sendMessage(spyMessage);
}
}
}
private void prSysU(String s) {
if (broadcastUpdates) {
String message = ChatColor.AQUA + "[" + plugin.getName() + ": Update] " + ChatColor.GRAY + s;
Bukkit.broadcast(message, plugin.getName() + ".update");
}
skUtilities.prSysI(s);
}
@EventHandler
public void onSnowflakeChange(SnowflakeChangeEvent event) {
if (event.getFinalAmount() != 0) {
String reason;
if (event.getChangeReason().equals(ChangeReason.PLAYER_KILL)) {
reason = "killed " + Teams.getTeamColorByPlayer(Bukkit.getOfflinePlayer(event.get(0))) + event.get(0);
} else if (event.getChangeReason().equals(ChangeReason.WOOL_TOUCH)) {
reason = "picked up " + event.get(0);
} else if (event.getChangeReason().equals(ChangeReason.WOOL_PLACE)) {
reason = "placed " + event.get(0);
} else if (event.getChangeReason().equals(ChangeReason.CORE_LEAK)) {
reason = "you broke a piece of " + event.get(0);
} else if (event.getChangeReason().equals(ChangeReason.MONUMENT_DESTROY)) {
reason = "you destroyed " + event.get(0) + "% of " + event.get(1);
} else if (event.getChangeReason().equals(ChangeReason.TEAM_WIN)) {
reason = "your team (" + event.get(0) + ChatColor.GRAY + ") won";
} else if (event.getChangeReason().equals(ChangeReason.TEAM_LOYAL)) {
reason = "you were loyal to your team (" + event.get(0) + ChatColor.GRAY + ")";
} else if (event.getChangeReason().equals(ChangeReason.DESTROY_WOOL)) {
reason = "you destroyed " + event.get(0);
} else {
reason = "unknown reason";
}
event.getPlayer().sendMessage(new UnlocalizedChatMessage(ChatColor.GREEN + "" + ChatColor.BOLD + "+" + event.getFinalAmount() + ChatColor.WHITE + " Snowflakes" + ChatColor.DARK_PURPLE + " | " + ChatColor.GOLD + "" + ChatColor.ITALIC + event.getMultiplier() + "x" + ChatColor.DARK_PURPLE + " | " + ChatColor.GRAY + reason).getMessage(event.getPlayer().getLocale()));
event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 1.5F);
if (Settings.getSettingByName("Sounds") != null && Settings.getSettingByName("Sounds").getValueByPlayer(event.getPlayer()).getValue().equalsIgnoreCase("on")) {
event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 1.5F);
}
if (Cardinal.getCardinalDatabase().get(event.getPlayer(), "snowflakes").equals("")) {
Cardinal.getCardinalDatabase().put(event.getPlayer(), "snowflakes", event.getFinalAmount() + "");
} else {
Cardinal.getCardinalDatabase().put(event.getPlayer(), "snowflakes", (Numbers.parseInt(Cardinal.getCardinalDatabase().get(event.getPlayer(), "snowflakes")) + event.getFinalAmount()) + "");
}
if (Settings.getSettingByName("Snowflakes").getValueByPlayer(event.getPlayer()).getValue().equalsIgnoreCase("on"))
spawnSnowflakes(event.getPlayer(), event.getFinalAmount());
}
}
@Override
public String toString() {
String str = "\u00a7bIsland Info:\n";
str += ChatColor.GRAY + " - level: " + ChatColor.DARK_AQUA + String.format("%5.2f", getLevel()) + "\n";
str += ChatColor.GRAY + " - location: " + ChatColor.DARK_AQUA + name + "\n";
str += ChatColor.GRAY + " - biome: " + ChatColor.DARK_AQUA + getBiome() + "\n";
str += ChatColor.GRAY + " - schematic: " + ChatColor.DARK_AQUA + getSchematicName() + "\n";
str += ChatColor.GRAY + " - warp: " + ChatColor.DARK_AQUA + hasWarp() + "\n";
if (hasWarp()) {
str += ChatColor.GRAY + " loc: " + ChatColor.DARK_AQUA + LocationUtil.asString(getWarpLocation()) + "\n";
}
str += ChatColor.GRAY + " - locked: " + ChatColor.DARK_AQUA + isLocked() + "\n";
str += ChatColor.GRAY + " - ignore: " + ChatColor.DARK_AQUA + ignore() + "\n";
str += ChatColor.DARK_AQUA + "Party:\n";
str += ChatColor.GRAY + " - leader: " + ChatColor.DARK_AQUA + getLeader() + "\n";
str += ChatColor.GRAY + " - members: " + ChatColor.DARK_AQUA + getMembers() + "\n";
str += ChatColor.GRAY + " - size: " + ChatColor.DARK_AQUA + getPartySize() + "\n";
str += ChatColor.DARK_AQUA + "Limits:\n";
str += ChatColor.GRAY + " - maxParty: " + ChatColor.DARK_AQUA + getMaxPartySize() + "\n";
str += ChatColor.GRAY + " - animals: " + ChatColor.DARK_AQUA + getMaxAnimals() + "\n";
str += ChatColor.GRAY + " - monsters: " + ChatColor.DARK_AQUA + getMaxMonsters() + "\n";
str += ChatColor.GRAY + " - villagers: " + ChatColor.DARK_AQUA + getMaxVillagers() + "\n";
str += ChatColor.DARK_AQUA + "Bans:\n";
for (String ban : getBans()) {
str += ChatColor.GRAY + " - " + ban + "\n";
}
str += ChatColor.DARK_AQUA + "Log:\n";
for (String log : getLog()) {
str += ChatColor.GRAY + " - " + log + "\n";
}
return str;
}
private static String getObjective(GameObjective objective, GameObjectiveProximityHandler proximityHandler) {
String message = " ";
if (objective instanceof WoolObjective) message += MiscUtil.convertDyeColorToChatColor(((WoolObjective)objective).getColor());
if (objective instanceof FlagObjective) message += ((FlagObjective) objective).getChatColor();
message += WordUtils.capitalizeFully(objective.getName().replaceAll("_", " ")) + " ";
message += objective.isComplete() ? ChatColor.GREEN + "COMPLETE " : objective.isTouched() ? ChatColor.YELLOW + "TOUCHED " : ChatColor.RED + "UNTOUCHED ";
if (proximityHandler != null && !objective.isComplete()) {
message += ChatColor.GRAY + proximityHandler.getProximityName() + ": ";
message += ChatColor.AQUA + proximityHandler.getProximityAsString();
}
return message;
}
public String toShortMessage(String color, boolean showId, boolean showVersion) {
return (showId ? ChatColor.YELLOW + "#" + id + " " : "") +
color + getName() + (showVersion ? " " + ChatColor.GRAY + getVersion() : "");
}
@Override
protected final boolean runCommand(CommandSender sender, OptionSet options) {
final List<Map.Entry<String, Module>> entries = moduleSpec.values(options);
if (entries.size() == 0) {
sender.sendMessage(messages.evalTemplate(
"provide modules",
ImmutableMap.of(
"modules",
Joiner.on(", ").join(Iterables.transform(registry.getModules(), FETCH_KEY_AS_STRING))
)
));
return true;
}
final List<String> newStates = Lists.newArrayListWithCapacity(entries.size());
int count = 0;
for (final Map.Entry<String, Module> entry : entries) {
final Module module = entry.getValue();
final String id = entry.getKey();
final ChatColor stateColour;
if (module instanceof DisableableModule) {
final DisableableModule disableable = (DisableableModule) module;
switch (type) {
case ENABLE:
if (!disableable.isEnabled() && disableable.enable()) {
disableable.announceState();
count++;
}
break;
case DISABLE:
if (disableable.isEnabled() && disableable.disable()) {
disableable.announceState();
count++;
}
break;
case TOGGLE:
if (disableable.toggle()) {
disableable.announceState();
count++;
}
break;
default:
}
stateColour = disableable.isEnabled() ? ChatColor.GREEN : ChatColor.RED;
} else {
stateColour = ChatColor.GRAY;
}
newStates.add(stateColour + id);
}
sender.sendMessage(messages.evalTemplate(
"processed",
ImmutableMap.of(
"completed", count,
"total", entries.size(),
"states", Joiner.on(", ").join(newStates)
)
));
return true;
}
/**
* Displays a hologram, and automatically delete it after a given delay.
*
* @param player
* @param owner
* @param tameable
*/
@SuppressWarnings("deprecation")
private void displayHologramAndMessage(Player player, AnimalTamer owner, Tameable tameable) {
if (hologramMessage) {
double offset = HORSE_OFFSET;
if (tameable instanceof Ocelot || version >= 14 && tameable instanceof Cat) {
if (!displayCat || !player.hasPermission("petmaster.showowner.cat")) {
return;
}
offset = CAT_OFFSET;
} else if (tameable instanceof Wolf) {
if (!displayDog || !player.hasPermission("petmaster.showowner.dog")) {
return;
}
offset = DOG_OFFSET;
} else if (version >= 11 && tameable instanceof Llama) {
if (!displayLlama || !player.hasPermission("petmaster.showowner.llama")) {
return;
}
offset = LLAMA_OFFSET;
} else if (version >= 12 && tameable instanceof Parrot) {
if (!displayParrot || !player.hasPermission("petmaster.showowner.parrot")) {
return;
}
offset = PARROT_OFFSET;
} else if (!displayHorse || !player.hasPermission("petmaster.showowner.horse")) {
return;
}
Location eventLocation = tameable.getLocation();
// Create location with offset.
Location hologramLocation = new Location(eventLocation.getWorld(), eventLocation.getX(),
eventLocation.getY() + offset, eventLocation.getZ());
final Hologram hologram = HologramsAPI.createHologram(plugin, hologramLocation);
hologram.appendTextLine(
ChatColor.GRAY + plugin.getPluginLang().getString("petmaster-hologram", "Pet owned by ")
+ ChatColor.GOLD + owner.getName());
// Runnable to delete hologram.
new BukkitRunnable() {
@Override
public void run() {
hologram.delete();
}
}.runTaskLater(plugin, hologramDuration);
}
String healthInfo = "";
if (showHealth) {
Animals animal = (Animals) tameable;
String currentHealth = String.format("%.1f", animal.getHealth());
String maxHealth = version < 9 ? String.format("%.1f", animal.getMaxHealth())
: String.format("%.1f", animal.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue());
healthInfo = ChatColor.GRAY + ". " + plugin.getPluginLang().getString("petmaster-health", "Health: ")
+ ChatColor.GOLD + currentHealth + "/" + maxHealth;
}
if (chatMessage) {
player.sendMessage(plugin.getChatHeader() + plugin.getPluginLang().getString("petmaster-chat", "Pet owned by ")
+ ChatColor.GOLD + owner.getName() + healthInfo);
}
if (actionBarMessage) {
try {
FancyMessageSender.sendActionBarMessage(player, "&o" + ChatColor.GRAY
+ plugin.getPluginLang().getString("petmaster-action-bar", "Pet owned by ") + ChatColor.GOLD
+ owner.getName() + healthInfo);
} catch (Exception e) {
plugin.getLogger().warning("Errors while trying to display action bar message for pet ownership.");
}
}
}
public String toChatMessage() {
return getDisplayName() +
(contribution != null ? ChatColor.GRAY + " - " + ChatColor.ITALIC + getContribution() : "");
}
public void open(Player p, Block b) {
if (users.remove(p.getUniqueId())) {
return;
}
CustomBookInterface book = new CustomBookInterface(SlimefunPlugin.instance);
ChatComponent page = null;
List<Block> floors = getFloors(b);
if (floors.size() < 2) {
SlimefunPlugin.getLocalization().sendMessage(p, "machines.ELEVATOR.no-destinations", true);
}
for (int i = 0; i < floors.size(); i++) {
if (i % 10 == 0) {
if (page != null) {
book.addPage(page);
}
page = new ChatComponent(ChatColors.color(SlimefunPlugin.getLocalization().getMessage(p, "machines.ELEVATOR.pick-a-floor")) + "\n");
}
Block block = floors.get(i);
String floor = ChatColors.color(BlockStorage.getLocationInfo(block.getLocation(), DATA_KEY));
ChatComponent line;
if (block.getY() == b.getY()) {
line = new ChatComponent("\n" + ChatColor.GRAY + "> " + (floors.size() - i) + ". " + ChatColor.RESET + floor);
line.setHoverEvent(new HoverEvent(ChatColors.color(SlimefunPlugin.getLocalization().getMessage(p, "machines.ELEVATOR.current-floor")), "", ChatColor.RESET + floor, ""));
}
else {
line = new ChatComponent("\n" + ChatColor.GRAY.toString() + (floors.size() - i) + ". " + ChatColor.RESET + floor);
line.setHoverEvent(new HoverEvent(ChatColors.color(SlimefunPlugin.getLocalization().getMessage(p, "machines.ELEVATOR.click-to-teleport")), "", ChatColor.RESET + floor, ""));
line.setClickEvent(new ClickEvent(new NamespacedKey(SlimefunPlugin.instance, DATA_KEY + i), player -> Slimefun.runSync(() -> {
users.add(player.getUniqueId());
float yaw = player.getEyeLocation().getYaw() + 180;
if (yaw > 180) {
yaw = -180 + (yaw - 180);
}
player.teleport(new Location(player.getWorld(), block.getX() + 0.5, block.getY() + 0.4, block.getZ() + 0.5, yaw, player.getEyeLocation().getPitch()));
player.sendTitle(ChatColor.RESET + ChatColors.color(floor), " ", 20, 60, 20);
})));
}
page.append(line);
}
if (page != null) {
book.addPage(page);
}
book.open(p);
}
public LightningRod() {
super("lightning-rod", ChatColor.GRAY + "Lightning Rod", Material.IRON_INGOT);
setLore("§bLeft-click to throw the rod.",
"§bLightning will strike after a few seconds.");
setDefaultConfig("fuse", 40);
}
/**
* Builds the topic preamble. Override this method to change how the index
* preamble looks.
*
* @param sender The command sender requesting the preamble.
* @return The topic preamble.
*/
protected String buildPreamble(CommandSender sender) {
return ChatColor.GRAY + preamble;
}