Java Code Examples for org.bukkit.entity.Player#getDisplayName()
The following examples show how to use
org.bukkit.entity.Player#getDisplayName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ListCommand.java From CardinalPGM with MIT License | 6 votes |
@Command(aliases = {"list"}, desc = "Lists all online players.", flags = "v") public static void list(final CommandContext args, CommandSender sender) { boolean version = args.hasFlag('v'); String result = ChatColor.GRAY + ChatConstant.MISC_ONLINE.asMessage().getMessage(ChatUtil.getLocale(sender)) + " (" + Bukkit.getOnlinePlayers().size() + "/" + Bukkit.getMaxPlayers() + "): " + ChatColor.RESET; for (Player player : Bukkit.getOnlinePlayers()) { result += player.getDisplayName(); if (version) { result += ChatColor.GRAY + " (" + Protocols.getName(player.getProtocolVersion()) + ")"; } result += ChatColor.RESET + ", "; } if (result.endsWith(", ")) { result = result.substring(0, result.length() - 2); } sender.sendMessage(result); }
Example 2
Source File: ChannelPlayerUUID.java From LunaChat with GNU Lesser General Public License v3.0 | 5 votes |
/** * プレイヤー表示名を返す * @return プレイヤー表示名 * @see com.github.ucchyocean.lc.channel.ChannelPlayer#getDisplayName() */ @Override public String getDisplayName() { Player player = getPlayer(); if ( player != null ) { return player.getDisplayName(); } return getName(); }
Example 3
Source File: CommandUtils.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
public static String getDisplayName(@Nullable PlayerId target, CommandSender viewer) { if(target == null) { return CONSOLE_DISPLAY_NAME; } else { Player targetPlayer = Bukkit.getPlayerExact(target.username(), viewer); if(targetPlayer == null) { return ChatColor.DARK_AQUA + target.username(); } else { return targetPlayer.getDisplayName(viewer); } } }
Example 4
Source File: CommandUtils.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
public static String getDisplayName(@Nullable String username, CommandSender viewer) { if(username == null || username.trim().length() == 0 || username.trim().equalsIgnoreCase("CONSOLE")) { return CONSOLE_DISPLAY_NAME; } else { Player targetPlayer = Bukkit.getPlayerExact(username, viewer); if(targetPlayer == null) { return ChatColor.DARK_AQUA + username; } else { return targetPlayer.getDisplayName(viewer); } } }
Example 5
Source File: PWIPlayer.java From PerWorldInventory with GNU General Public License v3.0 | 5 votes |
PWIPlayer(Player player, Group group, double bankBalance, double balance, boolean useAttributes) { this.uuid = player.getUniqueId(); this.name = player.getName(); this.location = player.getLocation(); this.group = group; this.saved = false; this.armor = player.getInventory().getArmorContents(); this.enderChest = player.getEnderChest().getContents(); this.inventory = player.getInventory().getContents(); this.canFly = player.getAllowFlight(); this.displayName = player.getDisplayName(); this.exhaustion = player.getExhaustion(); this.experience = player.getExp(); this.isFlying = player.isFlying(); this.foodLevel = player.getFoodLevel(); if (useAttributes) { this.maxHealth = player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getBaseValue(); } else { this.maxHealth = player.getMaxHealth(); } this.health = player.getHealth(); this.gamemode = player.getGameMode(); this.level = player.getLevel(); this.saturationLevel = player.getSaturation(); this.potionEffects = player.getActivePotionEffects(); this.fallDistance = player.getFallDistance(); this.fireTicks = player.getFireTicks(); this.maxAir = player.getMaximumAir(); this.remainingAir = player.getRemainingAir(); this.bankBalance = bankBalance; this.balance = balance; }
Example 6
Source File: ChatListener.java From Plan with GNU Lesser General Public License v3.0 | 5 votes |
private void actOnChatEvent(AsyncPlayerChatEvent event) { long time = System.currentTimeMillis(); Player player = event.getPlayer(); UUID uuid = player.getUniqueId(); String displayName = player.getDisplayName(); dbSystem.getDatabase().executeTransaction(new NicknameStoreTransaction( uuid, new Nickname(displayName, time, serverInfo.getServerUUID()), (playerUUID, name) -> nicknameCache.getDisplayName(playerUUID).map(name::equals).orElse(false) )); }
Example 7
Source File: ChannelMemberPlayer.java From LunaChat with GNU Lesser General Public License v3.0 | 5 votes |
/** * プレイヤー表示名を返す * @return プレイヤー表示名 * @see com.github.ucchyocean.lc.channel.ChannelPlayer#getDisplayName() */ @Override public String getDisplayName() { Player player = getPlayer(); if ( player != null ) { return player.getDisplayName(); } return getName(); }
Example 8
Source File: PWIPlayer.java From PerWorldInventory with GNU General Public License v3.0 | 5 votes |
PWIPlayer(Player player, Group group, double bankBalance, double balance, boolean useAttributes) { this.uuid = player.getUniqueId(); this.name = player.getName(); this.location = player.getLocation(); this.group = group; this.saved = false; this.armor = player.getInventory().getArmorContents(); this.enderChest = player.getEnderChest().getContents(); this.inventory = player.getInventory().getContents(); this.canFly = player.getAllowFlight(); this.displayName = player.getDisplayName(); this.exhaustion = player.getExhaustion(); this.experience = player.getExp(); this.isFlying = player.isFlying(); this.foodLevel = player.getFoodLevel(); if (useAttributes) { this.maxHealth = player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getBaseValue(); } else { this.maxHealth = player.getMaxHealth(); } this.health = player.getHealth(); this.gamemode = player.getGameMode(); this.level = player.getLevel(); this.saturationLevel = player.getSaturation(); this.potionEffects = player.getActivePotionEffects(); this.fallDistance = player.getFallDistance(); this.fireTicks = player.getFireTicks(); this.maxAir = player.getMaximumAir(); this.remainingAir = player.getRemainingAir(); this.bankBalance = bankBalance; this.balance = balance; }
Example 9
Source File: ChannelPlayerName.java From LunaChat with GNU Lesser General Public License v3.0 | 5 votes |
/** * プレイヤー表示名を返す * @return プレイヤー表示名 * @see com.github.ucchyocean.lc.channel.ChannelPlayer#getDisplayName() */ @Override public String getDisplayName() { Player player = getPlayer(); if ( player != null ) { return player.getDisplayName(); } return name; }
Example 10
Source File: RelativePlaceholder.java From HolographicDisplays with GNU General Public License v3.0 | 4 votes |
@Override public String getReplacement(Player player) { return player.getDisplayName(); }
Example 11
Source File: PlayerComponent.java From PGM with GNU Affero General Public License v3.0 | 4 votes |
static TextComponent.Builder formatColor(Player player) { String displayName = player.getDisplayName(); char colorChar = displayName.charAt((displayName.indexOf(player.getName()) - 1)); TextColor color = TextFormatter.convert(ChatColor.getByChar(colorChar)); return TextComponent.builder().append(player.getName()).color(color); }
Example 12
Source File: PlayerNameVariable.java From BetonQuest with GNU General Public License v3.0 | 4 votes |
@Override public String getValue(String playerID) { Player player = PlayerConverter.getPlayer(playerID); return (display) ? player.getDisplayName() : player.getName(); }
Example 13
Source File: BukkitPlayerDB.java From uSkyBlock with GNU General Public License v3.0 | 4 votes |
@Override public String getDisplayName(String playerName) { //noinspection deprecation Player player = Bukkit.getPlayer(playerName); return player != null ? player.getDisplayName() : null; }
Example 14
Source File: Team.java From BedwarsRel with GNU General Public License v3.0 | 4 votes |
@SuppressWarnings("deprecation") public boolean addPlayer(Player player) { BedwarsPlayerJoinTeamEvent playerJoinTeamEvent = new BedwarsPlayerJoinTeamEvent(this, player); BedwarsRel.getInstance().getServer().getPluginManager().callEvent(playerJoinTeamEvent); if (playerJoinTeamEvent.isCancelled()) { return false; } if (BedwarsRel.getInstance().isSpigot()) { if (this.getScoreboardTeam().getEntries().size() >= this.getMaxPlayers()) { return false; } } else { if (this.getScoreboardTeam().getPlayers().size() >= this.getMaxPlayers()) { return false; } } String displayName = player.getDisplayName(); String playerListName = player.getPlayerListName(); if (BedwarsRel.getInstance().getBooleanConfig("overwrite-names", false)) { displayName = this.getChatColor() + ChatColor.stripColor(player.getName()); playerListName = this.getChatColor() + ChatColor.stripColor(player.getName()); } if (BedwarsRel.getInstance().getBooleanConfig("teamname-on-tab", true)) { playerListName = this.getChatColor() + this.getName() + ChatColor.WHITE + " | " + this.getChatColor() + ChatColor.stripColor(player.getDisplayName()); } BedwarsPlayerSetNameEvent playerSetNameEvent = new BedwarsPlayerSetNameEvent(this, displayName, playerListName, player); BedwarsRel.getInstance().getServer().getPluginManager().callEvent(playerSetNameEvent); if (!playerSetNameEvent.isCancelled()) { player.setDisplayName(playerSetNameEvent.getDisplayName()); player.setPlayerListName(playerSetNameEvent.getPlayerListName()); } if (BedwarsRel.getInstance().isSpigot()) { this.getScoreboardTeam().addEntry(player.getName()); } else { this.getScoreboardTeam().addPlayer(player); } this.equipPlayerWithLeather(player); return true; }
Example 15
Source File: PlayerTabItem.java From tabbed with MIT License | 4 votes |
@Override public String get(Player player) { return player.getDisplayName(); }
Example 16
Source File: PlayerJoinLeaveListener.java From DiscordSRV with GNU General Public License v3.0 | 4 votes |
@EventHandler //priority needs to be different to MONITOR to avoid problems with permissions check when PEX is used public void PlayerQuitEvent(PlayerQuitEvent event) { MessageFormat messageFormat = DiscordSRV.getPlugin().getMessageFromConfiguration("MinecraftPlayerLeaveMessage"); // make sure quit messages enabled if (messageFormat == null) return; final Player player = event.getPlayer(); final String name = player.getName(); // no quit message, user shouldn't have one from permission if (GamePermissionUtil.hasPermission(event.getPlayer(), "discordsrv.silentquit")) { DiscordSRV.info(LangUtil.InternalMessage.SILENT_QUIT.toString() .replace("{player}", name) ); return; } final String displayName = StringUtils.isNotBlank(player.getDisplayName()) ? player.getDisplayName() : ""; final String message = StringUtils.isNotBlank(event.getQuitMessage()) ? event.getQuitMessage() : ""; String avatarUrl = DiscordSRV.getPlugin().getEmbedAvatarUrl(event.getPlayer()); String botAvatarUrl = DiscordUtil.getJda().getSelfUser().getEffectiveAvatarUrl(); String botName = DiscordSRV.getPlugin().getMainGuild() != null ? DiscordSRV.getPlugin().getMainGuild().getSelfMember().getEffectiveName() : DiscordUtil.getJda().getSelfUser().getName(); BiFunction<String, Boolean, String> translator = (content, needsEscape) -> { if (content == null) return null; content = content .replaceAll("%time%|%date%", TimeUtil.timeStamp()) .replace("%message%", DiscordUtil.strip(needsEscape ? DiscordUtil.escapeMarkdown(message) : message)) .replace("%username%", DiscordUtil.strip(needsEscape ? DiscordUtil.escapeMarkdown(name) : name)) .replace("%displayname%", DiscordUtil.strip(needsEscape ? DiscordUtil.escapeMarkdown(displayName) : displayName)) .replace("%embedavatarurl%", avatarUrl) .replace("%botavatarurl%", botAvatarUrl) .replace("%botname%", botName); content = PlaceholderUtil.replacePlaceholdersToDiscord(content, player); return content; }; Message discordMessage = DiscordSRV.getPlugin().translateMessage(messageFormat, translator); if (discordMessage == null) return; String webhookName = translator.apply(messageFormat.getWebhookName(), true); String webhookAvatarUrl = translator.apply(messageFormat.getWebhookAvatarUrl(), true); // player doesn't have silent quit, show quit message if (messageFormat.isUseWebhooks()) { WebhookUtil.deliverMessage(DiscordSRV.getPlugin().getMainTextChannel(), webhookName, webhookAvatarUrl, discordMessage.getContentRaw(), discordMessage.getEmbeds().stream().findFirst().orElse(null)); } else { DiscordUtil.queueMessage(DiscordSRV.getPlugin().getMainTextChannel(), discordMessage); } }
Example 17
Source File: PlayerDeathListener.java From DiscordSRV with GNU General Public License v3.0 | 4 votes |
@EventHandler(priority = EventPriority.MONITOR) public void onPlayerDeath(PlayerDeathEvent event) { if (event.getEntityType() != EntityType.PLAYER) return; String deathMessage = event.getDeathMessage(); if (StringUtils.isBlank(deathMessage)) return; Player player = event.getEntity(); // respect invisibility plugins if (PlayerUtil.isVanished(player)) return; String channelName = DiscordSRV.getPlugin().getMainChatChannel(); MessageFormat messageFormat = DiscordSRV.getPlugin().getMessageFromConfiguration("MinecraftPlayerDeathMessage"); if (messageFormat == null) return; DeathMessagePreProcessEvent preEvent = DiscordSRV.api.callEvent(new DeathMessagePreProcessEvent(channelName, messageFormat, player, deathMessage)); if (preEvent.isCancelled()) { DiscordSRV.debug("DeathMessagePreProcessEvent was cancelled, message send aborted"); return; } // Update from event in case any listeners modified parameters channelName = preEvent.getChannel(); messageFormat = preEvent.getMessageFormat(); deathMessage = preEvent.getDeathMessage(); if (messageFormat == null) return; String finalDeathMessage = StringUtils.isNotBlank(deathMessage) ? deathMessage : ""; String avatarUrl = DiscordSRV.getPlugin().getEmbedAvatarUrl(event.getEntity()); String botAvatarUrl = DiscordUtil.getJda().getSelfUser().getEffectiveAvatarUrl(); String botName = DiscordSRV.getPlugin().getMainGuild() != null ? DiscordSRV.getPlugin().getMainGuild().getSelfMember().getEffectiveName() : DiscordUtil.getJda().getSelfUser().getName(); String webhookName = messageFormat.getWebhookName(); String webhookAvatarUrl = messageFormat.getWebhookAvatarUrl(); String displayName = StringUtils.isNotBlank(player.getDisplayName()) ? player.getDisplayName() : ""; BiFunction<String, Boolean, String> translator = (content, needsEscape) -> { if (content == null) return null; content = content .replaceAll("%time%|%date%", TimeUtil.timeStamp()) .replace("%username%", player.getName()) .replace("%displayname%", DiscordUtil.strip(needsEscape ? DiscordUtil.escapeMarkdown(displayName) : displayName)) .replace("%world%", player.getWorld().getName()) .replace("%deathmessage%", DiscordUtil.strip(needsEscape ? DiscordUtil.escapeMarkdown(finalDeathMessage) : finalDeathMessage)) .replace("%embedavatarurl%", avatarUrl) .replace("%botavatarurl%", botAvatarUrl) .replace("%botname%", botName); content = PlaceholderUtil.replacePlaceholdersToDiscord(content, player); return content; }; Message discordMessage = DiscordSRV.getPlugin().translateMessage(messageFormat, translator); if (discordMessage == null) return; webhookName = translator.apply(webhookName, true); webhookAvatarUrl = translator.apply(webhookAvatarUrl, true); if (DiscordSRV.getPlugin().getLength(discordMessage) < 3) { DiscordSRV.debug("Not sending death message, because it's less than three characters long. Message: " + messageFormat); return; } DeathMessagePostProcessEvent postEvent = DiscordSRV.api.callEvent(new DeathMessagePostProcessEvent(channelName, discordMessage, player, deathMessage, messageFormat.isUseWebhooks(), webhookName, webhookAvatarUrl, preEvent.isCancelled())); if (postEvent.isCancelled()) { DiscordSRV.debug("DeathMessagePostProcessEvent was cancelled, message send aborted"); return; } // Update from event in case any listeners modified parameters channelName = postEvent.getChannel(); discordMessage = postEvent.getDiscordMessage(); TextChannel textChannel = DiscordSRV.getPlugin().getDestinationTextChannelForGameChannelName(channelName); if (messageFormat.isUseWebhooks()) { WebhookUtil.deliverMessage(textChannel, postEvent.getWebhookName(), postEvent.getWebhookAvatarUrl(), discordMessage.getContentRaw(), discordMessage.getEmbeds().stream().findFirst().orElse(null)); } else { DiscordUtil.queueMessage(textChannel, discordMessage); } }
Example 18
Source File: PlayerOnlineListener.java From Plan with GNU Lesser General Public License v3.0 | 4 votes |
private void actOnJoinEvent(PlayerJoinEvent event) { Player player = event.getPlayer(); UUID playerUUID = player.getUniqueId(); UUID serverUUID = serverInfo.getServerUUID(); long time = System.currentTimeMillis(); JSONCache.invalidate(DataID.SERVER_OVERVIEW, serverUUID); JSONCache.invalidate(DataID.GRAPH_PERFORMANCE, serverUUID); BukkitAFKListener.AFK_TRACKER.performedAction(playerUUID, time); String world = player.getWorld().getName(); String gm = player.getGameMode().name(); Database database = dbSystem.getDatabase(); database.executeTransaction(new WorldNameStoreTransaction(serverUUID, world)); InetAddress address = player.getAddress().getAddress(); String playerName = player.getName(); String displayName = player.getDisplayName(); boolean gatheringGeolocations = config.isTrue(DataGatheringSettings.GEOLOCATIONS); if (gatheringGeolocations) { database.executeTransaction( new GeoInfoStoreTransaction(playerUUID, address, time, geolocationCache::getCountry) ); } database.executeTransaction(new PlayerServerRegisterTransaction(playerUUID, player::getFirstPlayed, playerName, serverUUID)); Session session = new Session(playerUUID, serverUUID, time, world, gm); session.putRawData(SessionKeys.NAME, playerName); session.putRawData(SessionKeys.SERVER_NAME, serverInfo.getServer().getIdentifiableName()); sessionCache.cacheSession(playerUUID, session) .ifPresent(previousSession -> database.executeTransaction(new SessionEndTransaction(previousSession))); database.executeTransaction(new NicknameStoreTransaction( playerUUID, new Nickname(displayName, time, serverUUID), (uuid, name) -> nicknameCache.getDisplayName(playerUUID).map(name::equals).orElse(false) )); processing.submitNonCritical(() -> extensionService.updatePlayerValues(playerUUID, playerName, CallEvents.PLAYER_JOIN)); if (config.isTrue(ExportSettings.EXPORT_ON_ONLINE_STATUS_CHANGE)) { processing.submitNonCritical(() -> exporter.exportPlayerPage(playerUUID, playerName)); } }
Example 19
Source File: AI.java From Civs with GNU General Public License v3.0 | 4 votes |
private boolean invitePlayer(Player player) { if (town.getRawPeople().containsKey(player.getUniqueId())) { return false; } if (town.getHousing() <= town.getPopulation()) { return false; } UUID uuid = hasTownMemberOnline(); if (uuid == null) { return false; } // TODO add player to list of already invited players String[] args = new String[1]; args[0] = player.getDisplayName(); Bukkit.getScheduler().scheduleSyncDelayedTask(Civs.getInstance(), new Runnable() { @Override public void run() { broadcastToAllPlayers("ai-invite", args, getDisplayName()); } }, 100); Bukkit.getScheduler().scheduleSyncDelayedTask(Civs.getInstance(), new Runnable() { @Override public void run() { Civilian inviteCiv = CivilianManager.getInstance().getCivilian(player.getUniqueId()); player.sendMessage(Civs.getPrefix() + LocaleManager.getInstance().getTranslationWithPlaceholders(player, "invite-player").replace("$1", getDisplayName() + ChatColor.GREEN) .replace("$2", town.getType()) .replace("$3", townName)); TownManager.getInstance().addInvite(player.getUniqueId(), town); } }, 120); String[] args2 = new String[1]; args2[0] = Bukkit.getPlayer(uuid).getDisplayName(); Bukkit.getScheduler().scheduleSyncDelayedTask(Civs.getInstance(), new Runnable() { @Override public void run() { broadcastToAllPlayers("ai-help", args2, getDisplayName()); } }, 130); return true; }
Example 20
Source File: HealthUtil.java From ActionHealth with MIT License | 4 votes |
public String getOutput(double health, String output, Player receiver, LivingEntity entity) { double maxHealth = entity.getMaxHealth(); if (health < 0.0 || entity.isDead()) health = 0.0; String name = getName(entity, receiver); if (plugin.healthUtil.isBlacklisted(entity, name)) return null; if (plugin.configStore.stripName) name = ChatColor.stripColor(name); if (plugin.configStore.isUsingWhiteList()) { if (!plugin.healthUtil.isWhiteListed(entity, name)) { return null; } } if (entity instanceof Player) { String displayName; Player player = (Player) entity; if (player.getDisplayName() == null) { displayName = name; } else { displayName = player.getDisplayName(); } output = output.replace("{displayname}", displayName); // Placeholder apis if (plugin.configStore.hasMVdWPlaceholderAPI) { output = be.maximvdw.placeholderapi.PlaceholderAPI.replacePlaceholders(player, output); } if (plugin.configStore.hasPlaceholderAPI) { output = me.clip.placeholderapi.PlaceholderAPI.setPlaceholders(player, output); output = me.clip.placeholderapi.PlaceholderAPI.setRelationalPlaceholders(receiver, player, output); } } else { if (!plugin.configStore.healthMessageOther.isEmpty()) { output = plugin.configStore.healthMessageOther; } output = output.replace("{displayname}", name); } output = output.replace("{name}", name); output = output.replace("{health}", String.valueOf((int) health)); output = output.replace("{maxhealth}", String.valueOf((int) maxHealth)); output = output.replace("{percenthealth}", String.valueOf((int) ((health / maxHealth) * 100.0))); output = output.replace("{opponentlastdamage}", String.valueOf((int) entity.getLastDamage())); if (output.contains("{usestyle}")) { StringBuilder style = new StringBuilder(); int left = plugin.configStore.limitHealth; double heart = maxHealth / plugin.configStore.limitHealth; double halfHeart = heart / 2; double tempHealth = health; if (maxHealth != health && health >= 0 && !entity.isDead()) { for (int i = 0; i < plugin.configStore.limitHealth; i++) { if (tempHealth - heart > 0) { tempHealth = tempHealth - heart; style.append(plugin.configStore.filledHeartIcon); left--; } else { break; } } if (tempHealth > halfHeart) { style.append(plugin.configStore.filledHeartIcon); left--; } else if (tempHealth > 0 && tempHealth <= halfHeart) { style.append(plugin.configStore.halfHeartIcon); left--; } } if (maxHealth != health) { for (int i = 0; i < left; i++) { style.append(plugin.configStore.emptyHeartIcon); } } else { for (int i = 0; i < left; i++) { style.append(plugin.configStore.filledHeartIcon); } } output = output.replace("{usestyle}", style.toString()); } HealthSendEvent healthSendEvent = new HealthSendEvent(receiver, entity, output); Bukkit.getPluginManager().callEvent(healthSendEvent); if (healthSendEvent.isCancelled()) output = null; else output = healthSendEvent.getMessage(); return output; }