下面列出了org.bukkit.ChatColor#translateAlternateColorCodes ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static String format(String input, boolean limitChars) {
String colored = ChatColor.translateAlternateColorCodes('&', input);
if(VersionChecker.getBukkitVersion() == BukkitVersion.v1_13_R1) {
return limitChars && colored.length() > 128 ? colored.substring(0, 128) : colored;
} else if(VersionChecker.getBukkitVersion() == BukkitVersion.v1_14_R1) {
return limitChars && colored.length() > 128 ? colored.substring(0, 128) : colored;
} else if(VersionChecker.getBukkitVersion() == BukkitVersion.v1_14_R2) {
return limitChars && colored.length() > 128 ? colored.substring(0, 128) : colored;
} else if(VersionChecker.getBukkitVersion() == BukkitVersion.v1_15_R1) {
return limitChars && colored.length() > 128 ? colored.substring(0, 128) : colored;
} else if(VersionChecker.getBukkitVersion() == BukkitVersion.v1_15_R2) {
return limitChars && colored.length() > 128 ? colored.substring(0, 128) : colored;
} else if(VersionChecker.getBukkitVersion() == BukkitVersion.v1_16_R1) {
return limitChars && colored.length() > 128 ? colored.substring(0, 128) : colored;
} else {
return limitChars && colored.length() > 16 ? colored.substring(0, 16) : colored;
}
}
@SubCommand(value = "setlore", permission = "nu.setlore")
public void setlore(CommandSender sender, Arguments args) {
if (!(args.length() > 1)) {
msg(sender, "manual.setlore.usage");
return;
}
String lore = args.next().replace("§", "");
Player p = asPlayer(sender);
lore = ChatColor.translateAlternateColorCodes('&', lore);
ItemStack item = p.getInventory().getItemInMainHand();
if (item == null || item.getType().equals(Material.AIR)) {
msg(sender, "user.info.no_item_hand");
return;
}
String[] line = lore.split("/n");
List<String> lines = new ArrayList<>();
for (String s : line) {
lines.add(ChatColor.translateAlternateColorCodes('&', s));
}
ItemMeta itemStackMeta = item.getItemMeta();
itemStackMeta.setLore(lines);
item.setItemMeta(itemStackMeta);
msg(sender, "user.setlore.success", lore);
}
private static String getFormattedMessage(final IChannel origin, final String username) {
String format = (String) DiscordMC.getUserFormats().get(username, "-");
String formattedMessage;
if (!useIngameFormat || Objects.equals(format, "-")) {
formattedMessage =
ChatColor.translateAlternateColorCodes('&', DiscordMC.get().getConfig().getString("settings.templates.chat_message_minecraft")
.replace("%user", username)
.replace("%channel", origin.getName()));
} else {
formattedMessage = format.replace("%1$s", username).replace("%2$s", "%message");
}
return formattedMessage;
}
private String formatTags(String format, UCChannel ch, MessageReceivedEvent e, String sender, String message) {
format = format.replace("{ch-color}", ch.getColor())
.replace("{ch-alias}", ch.getAlias())
.replace("{ch-name}", ch.getName());
if (e != null) {
sender = ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', e.getMember().getEffectiveName()));
format = format.replace("{sender}", sender)
.replace("{dd-channel}", e.getChannel().getName())
.replace("{message}", e.getMessage().getContentRaw());
if (!e.getMember().getRoles().isEmpty()) {
Role role = e.getMember().getRoles().get(0);
if (role.getColor() != null) {
format = format.replace("{dd-rolecolor}", fromRGB(
role.getColor().getRed(),
role.getColor().getGreen(),
role.getColor().getBlue()).toString());
}
format = format.replace("{dd-rolename}", role.getName());
}
if (e.getMember().getNickname() != null) {
format = format.replace("{nickname}", ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', e.getMember().getNickname())));
} else {
format = format.replace("{nickname}", sender);
}
}
//if not filtered
format = format
.replace("{sender}", sender)
.replace("{message}", message);
format = format.replaceAll("\\{.*\\}", "");
return ChatColor.translateAlternateColorCodes('&', format);
}
public static String color(String string) {
StringBuilder xmas = new StringBuilder("");
for (int i = 0; i < string.length(); i++) {
xmas.append((i % 2 == 0 ? "&a": "&c"));
xmas.append(string.charAt(i));
}
return ChatColor.translateAlternateColorCodes('&', xmas.toString());
}
private Stage parseStage(Element stage) {
String title = ChatColor.translateAlternateColorCodes('`', stage.getAttributeValue("title"));
List<String> lines = new ArrayList<>();
RegionModule region = null;
for (Element line : stage.getChild("message").getChildren("line")) {
lines.add(ChatColor.translateAlternateColorCodes('`', line.getValue()));
}
Element teleport = stage.getChild("teleport");
if (teleport != null) {
region = RegionModuleBuilder.getRegion(teleport.getChildren().get(0));
}
return new Stage(title, lines, region);
}
@Override
public String translate(String key, String def) {
if (config.isSet(key)) {
return ChatColor.translateAlternateColorCodes('&', config.getString(key));
} else if (fallback != null) {
return fallback.translate(key, def);
} else if (def != null) {
return ChatColor.translateAlternateColorCodes('&', def);
}
return ChatColor.RED.toString() + key;
}
/**
* Get name of the island owned by owner
* @param owner island owner UUID
* @return Returns the name of owner's island, or the owner's name if there is none.
*/
public String getIslandName(UUID owner) {
if (owner == null) {
return "";
}
return ChatColor.translateAlternateColorCodes('&', islandNames.getString(owner.toString(), plugin.getPlayers().getName(owner))) + ChatColor.RESET;
}
public String getProtMsg(String key) {
return ChatColor.translateAlternateColorCodes('&', Prots.getString(key));
}
public void loadModules() {
getLogger().info("Loading modules...");
USING_PLIB = getServer().getPluginManager().isPluginEnabled("ProtocolLib");
new File(plugin.getDataFolder().getAbsolutePath()).mkdirs();
messages = YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder().getAbsolutePath() + File.separator + "messages.yml"));
checksConfig = YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder().getAbsolutePath() + File.separator + "checks.yml"));
FLAG_PREFIX = ChatColor.translateAlternateColorCodes('&', ConfigHelper.getOrSetDefault("&cHAWK: &7", messages, "prefix"));
sendJSONMessages = ConfigHelper.getOrSetDefault(false, getConfig(), "sendJSONMessages");
playSoundOnFlag = ConfigHelper.getOrSetDefault(false, getConfig(), "playSoundOnFlag");
FLAG_CLICK_COMMAND = ConfigHelper.getOrSetDefault("tp %player%", getConfig(), "flagClickCommand");
if (sendJSONMessages && getServerVersion() == 7) {
sendJSONMessages = false;
Bukkit.getLogger().warning("Hawk cannot send JSON flag messages on a 1.7.10 server! Please use 1.8.8 to use this feature.");
}
hawkSyncTaskScheduler = new HawkSyncTaskScheduler(this);
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, hawkSyncTaskScheduler, 0L, 1L);
profiles = new ConcurrentHashMap<>();
getServer().getPluginManager().registerEvents(new PlayerEventListener(this), this);
sqlModule = new SQLModule(this);
sqlModule.createTableIfNotExists();
commandExecutor = new CommandExecutor(this);
punishmentScheduler = new PunishmentScheduler(this);
punishmentScheduler.load();
punishmentScheduler.start();
guiManager = new GUIManager(this);
lagCompensator = new LagCompensator(this);
banManager = new BanManager(this);
banManager.loadBannedPlayers();
muteManager = new MuteManager(this);
muteManager.loadMutedPlayers();
startLoggerFile();
bungeeBridge = new BungeeBridge(this, ConfigHelper.getOrSetDefault(false, getConfig(), "enableBungeeAlerts"));
checkManager = new CheckManager(plugin);
checkManager.loadChecks();
packetHandler = new PacketHandler(this);
packetHandler.startListener();
packetHandler.setupListenerForOnlinePlayers();
mouseRecorder = new MouseRecorder(this);
registerCommand();
saveConfigs();
}
public static void sendActionBar(Player player, String message) {
String s = ChatColor.translateAlternateColorCodes('&', message.replace("_", " "));
IChatBaseComponent icbc = ChatSerializer.a("{\"text\": \"" + s + "\"}");
PacketPlayOutChat bar = new PacketPlayOutChat(icbc, (byte) 2);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(bar);
}
public static String colorize(String message) {
if (message == null || message.isEmpty()) return message;
return ChatColor.translateAlternateColorCodes('&', message);
}
private static String getConfigStringWithColor(ConfigurationSection section, String key) {
return ChatColor.translateAlternateColorCodes('&', section.getString(key));
}
public String colorize(String message)
{
return ChatColor.translateAlternateColorCodes('&', message);
}
public String getColoredLockedLore() {
return ChatColor.translateAlternateColorCodes('&', lockedLore);
}
public SidebarConfig(String displayName) {
this.displayName = ChatColor.translateAlternateColorCodes('&', displayName);
}
TextLine(Hologram parent, String raw, String text) {
super(parent, raw);
this.text = ChatColor.translateAlternateColorCodes('&', text);
}
public static String format(String string) {
return ChatColor.translateAlternateColorCodes('&', string);
}
/**
* Gets a string at a location. This will either return a String or null, with
* null meaning that no configuration value exists at that location. If the
* object at the particular location is not actually a string, it will be
* converted to its string representation.
*
* @param path
* path to node (dot notation)
* @return string or null
*/
public String getString(String path) {
Object o = getProperty(path);
if (o == null) {
return null;
}
//return o.toString();
return ChatColor.translateAlternateColorCodes('&', o.toString());
}
/**
* Root text to show with the colors parsed, close the last text properties and start a new text block.
*
* @param text
* @return instance of same {@link UltimateFancy}.
*/
public UltimateFancy coloredTextAndNext(String text) {
text = ChatColor.translateAlternateColorCodes('&', text);
return this.textAndNext(text);
}