本文整理汇总了Java中org.bukkit.ChatColor.translateAlternateColorCodes方法的典型用法代码示例。如果您正苦于以下问题:Java ChatColor.translateAlternateColorCodes方法的具体用法?Java ChatColor.translateAlternateColorCodes怎么用?Java ChatColor.translateAlternateColorCodes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bukkit.ChatColor
的用法示例。
在下文中一共展示了ChatColor.translateAlternateColorCodes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import org.bukkit.ChatColor; //导入方法依赖的package包/类
@Override
public void execute(CommandSender sender, String[] args) {
String[] lines = new String[] { "", "" };
if (args.length > 0) {
StringBuilder sb = new StringBuilder();
for (int k = 0; k < args.length; k++)
sb.append(args[k] + " ");
String[] data = sb.toString().trim().split("@");
for (int k = 0; k < data.length; k++) {
lines[k] = ChatColor.translateAlternateColorCodes('&', data[k]);
}
}
for (Player p2 : plugin.getServer().getOnlinePlayers()) {
RMessages.sendTitle(p2, lines[0], lines[1], 20, 100, 20);
}
}
示例2: get
import org.bukkit.ChatColor; //导入方法依赖的package包/类
/**
* Get text from the yml file for this locale
* @param reference - the YAML node where the text is
* @return Text for this locale reference or the reference is nothing has been found
*/
public String get(String reference) {
// TODO: add placeholder conversion?
//plugin.getLogger().info("DEBUG: default lang = " + Settings.defaultLanguage);
//plugin.getLogger().info("DEBUG: this locale = " + languageTag);
//plugin.getLogger().info("DEBUG: reference = " + reference);
if (rb.containsKey(reference)) {
//plugin.getLogger().info("DEBUG: contains key");
return ChatColor.translateAlternateColorCodes('&', rb.getString(reference));
} else if (!Settings.defaultLanguage.equals(languageTag)){
//plugin.getLogger().info("DEBUG: try default");
// TODO: Try default lang
return reference;
}
plugin.getLogger().severe(reference + " not found in " + languageTag + " or default lang " + Settings.defaultLanguage);
return reference; // Return reference for debug purposes, like for the mods.
}
示例3: onPlaceholderRequest
import org.bukkit.ChatColor; //导入方法依赖的package包/类
@Override
public String onPlaceholderRequest(Player player, String s) {
if (player == null)
return "";
try {
if (PlaceHolderType.getTypeFromName(s) != null) {
final PlaceHolderRequestEvent event;
if (s.split("_")[0].equals("player")) {
event = new PlaceHolderRequestEvent(player, PlaceHolderType.getTypeFromName(s), -1);
} else {
event = new PlaceHolderRequestEvent(player, PlaceHolderType.getTypeFromName(s), Integer.parseInt(s.split("_")[0]));
}
Bukkit.getPluginManager().callEvent(event);
return ChatColor.translateAlternateColorCodes('&', event.getResult());
}
} catch (final Exception ignored) {
}
return "";
}
示例4: executePlayer
import org.bukkit.ChatColor; //导入方法依赖的package包/类
@Override
public void executePlayer(Player p, PlayerDataRPG pd, String[] args) {
ItemStack item = p.getInventory().getItemInMainHand();
if (item.hasItemMeta()) {
ItemMeta im = item.getItemMeta();
StringBuilder sb = new StringBuilder();
for (int k = 1; k < args.length; k++) {
sb.append(args[k]);
sb.append(' ');
}
String name = ChatColor.translateAlternateColorCodes('&', sb.toString().trim());
im.setDisplayName(name);
item.setItemMeta(im);
p.sendMessage("Updated item.");
}
}
示例5: onEnable
import org.bukkit.ChatColor; //导入方法依赖的package包/类
@Override
protected void onEnable() {
EventExecutor.getInstance().register(this);
// load config
this.config = Moo.getInstance().loadConfig(Lightning.getInstance().getDataFolder());
this.languageManager = new LanguageManager(Lightning.getInstance().getDataFolder(),
s -> ChatColor.translateAlternateColorCodes('&', s));
this.languageManager.load("language");
// if disabled stop enabling
if(!((boolean) config.get("activated"))) {
Lightning.getInstance().getLogs().info("*** Lightning disabled. ***");
return;
}
// register handler
Moo.getInstance().registerHandler(o -> {
if(o instanceof Listener) Bukkit.getServer().getPluginManager().registerEvents((Listener) o, Lightning.getInstance());
}, new ChatListener(), new ServerListener());
// connect to cloud
if(config.isLoaded()) {
Moo.getInstance().connect(config.get("group-id"), ClientType.SERVER, config.get("cloud-ip"), config.get("cloud-port"));
}
}
示例6: onChat
import org.bukkit.ChatColor; //导入方法依赖的package包/类
@EventHandler
public void onChat(AsyncPlayerChatEvent event) {
event.setCancelled(true);
Player player = event.getPlayer();
String message = event.getMessage();
String playerNameWithPrefixSuffix = ChatColor.RED + "(ERROR FORMATTING NAME) " + ChatColor.WHITE + player.getName() + ": ";
try {
if (RankManager.isPrisoner(player)) {
RankManager.updateWantedLevel(player);
} else if (RankManager.isGuard(player) || RankManager.isWarden(player)) {
RankManager.setWantedLevel(player, 0);
}
playerNameWithPrefixSuffix = ChatColor.translateAlternateColorCodes('&', (!RankManager.getRankPrefix(player).equals(" ") ? RankManager.getRankPrefix(player) : "") + ChatColor.GRAY + RankManager.wantedLevelParser(RankManager.getWantedLevel(player)) + ChatColor.GOLD + RankManager.guardLevelParser(RankManager.getGuardLevel(player)) + RankManager.getRankNameColor(player) + " " + player.getName() + (!RankManager.getRankSuffix(player).equals(" ") ? " " + RankManager.getRankSuffix(player) : "") + ChatColor.GRAY + ": ");
} catch (SQLException e) {
e.printStackTrace();
}
for (Player p : event.getRecipients()) {
p.sendMessage(playerNameWithPrefixSuffix + ChatColor.WHITE + message);
}
}
示例7: onCommand
import org.bukkit.ChatColor; //导入方法依赖的package包/类
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{
if (args.length < 1)
{
sender.sendMessage(ChatColor.RED + "Usage: " + "/rawcast");
return true;
}
String arg;
String requiredNode;
int position = 0;
if ((args.length > 2) && ((arg = args[0]).startsWith("-p")))
{
int position1 = 1;
requiredNode = arg.substring(2, arg.length());
}
else
{
position = 0;
requiredNode = null;
}
String message = StringUtils.join(args, ' ', position, args.length);
if (message.length() < 3)
{
sender.sendMessage(ChatColor.RED + "Broadcasts must be at least 3 characters.");
return true;
}
message = ChatColor.translateAlternateColorCodes('&', message);
if (requiredNode != null) {
Bukkit.broadcast(message, requiredNode);
} else {
Bukkit.broadcastMessage(message);
}
return true;
}
示例8: DragonTemplate
import org.bukkit.ChatColor; //导入方法依赖的package包/类
/**
* Construct a new DragonTemplate object
*
* @param file the file holding this template data
* @param name the name of the dragon. Can be null
* @param barStyle the style of the bar. Can be null
* @param barColour the colour of the bar. Can be null
*/
public DragonTemplate(File file, String name, BarStyle barStyle, BarColor barColour) {
Validate.notNull(file, "File cannot be null. See DragonTemplate(String, String, BarStyle, BarColor) for null files");
this.file = file;
this.configFile = YamlConfiguration.loadConfiguration(file);
this.identifier = file.getName().substring(0, file.getName().lastIndexOf('.'));
this.name = (name != null ? ChatColor.translateAlternateColorCodes('&', name) : null);
this.barStyle = (barStyle != null ? barStyle : BarStyle.SOLID);
this.barColour = (barColour != null ? barColour : BarColor.PINK);
this.loot = new DragonLoot(this);
}
示例9: initMessages
import org.bukkit.ChatColor; //导入方法依赖的package包/类
public void initMessages(CustomConfig config){
karmaResetSender = ChatColor.translateAlternateColorCodes('&', config.getCustomFile().getString("karmareset.sender"));
karmaResetReceiver = ChatColor.translateAlternateColorCodes('&', config.getCustomFile().getString("karmareset.receiver"));
karmaAddSender = ChatColor.translateAlternateColorCodes('&', config.getCustomFile().getString("karmaadd.sender"));
karmaAddReceiver = ChatColor.translateAlternateColorCodes('&', config.getCustomFile().getString("karmaadd.receiver"));
karmaRemoveSender = ChatColor.translateAlternateColorCodes('&', config.getCustomFile().getString("karmaremove.sender"));
karmaRemoveReceiver = ChatColor.translateAlternateColorCodes('&', config.getCustomFile().getString("karmaremove.receiver"));
illegalKarmaAmmount = ChatColor.translateAlternateColorCodes('&', config.getCustomFile().getString("commanderrors.illegalkarmaammount"));
karmaLoss = ChatColor.translateAlternateColorCodes('&', config.getCustomFile().getString("karmaloss"));
karmaGain = ChatColor.translateAlternateColorCodes('&', config.getCustomFile().getString("karmagain"));
karmaLevelChange = ChatColor.translateAlternateColorCodes('&', config.getCustomFile().getString("karmalevelchange"));
}
示例10: getGeneralTopics
import org.bukkit.ChatColor; //导入方法依赖的package包/类
/**
* Extracts a list of all general help topics from help.yml
*
* @return A list of general topics.
*/
public List<HelpTopic> getGeneralTopics() {
List<HelpTopic> topics = new LinkedList<HelpTopic>();
ConfigurationSection generalTopics = helpYaml.getConfigurationSection("general-topics");
if (generalTopics != null) {
for (String topicName : generalTopics.getKeys(false)) {
ConfigurationSection section = generalTopics.getConfigurationSection(topicName);
String shortText = ChatColor.translateAlternateColorCodes(ALT_COLOR_CODE, section.getString("shortText", ""));
String fullText = ChatColor.translateAlternateColorCodes(ALT_COLOR_CODE, section.getString("fullText", ""));
String permission = section.getString("permission", "");
topics.add(new CustomHelpTopic(topicName, shortText, fullText, permission));
}
}
return topics;
}
示例11: getTopicAmendments
import org.bukkit.ChatColor; //导入方法依赖的package包/类
/**
* Extracts a list of topic amendments from help.yml
*
* @return A list of amendments.
*/
public List<HelpTopicAmendment> getTopicAmendments() {
List<HelpTopicAmendment> amendments = new LinkedList<HelpTopicAmendment>();
ConfigurationSection commandTopics = helpYaml.getConfigurationSection("amended-topics");
if (commandTopics != null) {
for (String topicName : commandTopics.getKeys(false)) {
ConfigurationSection section = commandTopics.getConfigurationSection(topicName);
String description = ChatColor.translateAlternateColorCodes(ALT_COLOR_CODE, section.getString("shortText", ""));
String usage = ChatColor.translateAlternateColorCodes(ALT_COLOR_CODE, section.getString("fullText", ""));
String permission = section.getString("permission", "");
amendments.add(new HelpTopicAmendment(topicName, description, usage, permission));
}
}
return amendments;
}
示例12: sendCenteredMessage
import org.bukkit.ChatColor; //导入方法依赖的package包/类
public static void sendCenteredMessage(Player player, String message){
if(message == null || message.equals("")) player.sendMessage("");
message = ChatColor.translateAlternateColorCodes('&', message);
int messagePxSize = 0;
boolean previousCode = false;
boolean isBold = false;
for(char c : message.toCharArray()){
if(c == '§'){
previousCode = true;
continue;
}else if(previousCode == true){
previousCode = false;
if(c == 'l' || c == 'L'){
isBold = true;
continue;
}else isBold = false;
}else{
DefaultFontInfo dFI = DefaultFontInfo.getDefaultFontInfo(c);
messagePxSize += isBold ? dFI.getBoldLength() : dFI.getLength();
messagePxSize++;
}
}
int halvedMessageSize = messagePxSize / 2;
int toCompensate = CENTER_PX - halvedMessageSize;
int spaceLength = DefaultFontInfo.SPACE.getLength() + 1;
int compensated = 0;
StringBuilder sb = new StringBuilder();
while(compensated < toCompensate){
sb.append(" ");
compensated += spaceLength;
}
player.sendMessage(sb.toString() + message);
}
示例13: colorize
import org.bukkit.ChatColor; //导入方法依赖的package包/类
public static String colorize(String str) {
return ChatColor.translateAlternateColorCodes('&', str);
}
示例14: toJson
import org.bukkit.ChatColor; //导入方法依赖的package包/类
private static String toJson(Collection<String> text) {
return "{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', StringUtils.join(text, "\n")) + "\"}";
}
示例15: getAlias
import org.bukkit.ChatColor; //导入方法依赖的package包/类
@Override
public String getAlias() {
if (this.alias != null)
return ChatColor.translateAlternateColorCodes('&', this.alias) + ChatColor.RESET;
return null;
}