当前位置: 首页>>代码示例>>Java>>正文


Java GameProfile.getName方法代码示例

本文整理汇总了Java中org.spongepowered.api.profile.GameProfile.getName方法的典型用法代码示例。如果您正苦于以下问题:Java GameProfile.getName方法的具体用法?Java GameProfile.getName怎么用?Java GameProfile.getName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.spongepowered.api.profile.GameProfile的用法示例。


在下文中一共展示了GameProfile.getName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createScoreLine

import org.spongepowered.api.profile.GameProfile; //导入方法依赖的package包/类
private Text createScoreLine(int rank, Clause<Optional<GameProfile>, Integer> clause, ScoreType scoreType) {
  String playerName = "Unknown";
  Optional<GameProfile> optOwningProfile = clause.getKey();
  if (optOwningProfile.isPresent()) {
    GameProfile owningProfile = optOwningProfile.get();
    Optional<String> optName = owningProfile.getName();
    if (optName.isPresent()) {
      playerName = optName.get();
    }
  }

  return Text.of(
      TextColors.YELLOW, '#', rank, ' ',
      TextColors.BLUE, StringUtils.rightPad(playerName, ChatConstants.MAX_PLAYER_NAME_LENGTH), "   ",
      (rank == 1 ? TextColors.GOLD : TextColors.WHITE), scoreType.format(clause.getValue())
  );
}
 
开发者ID:Skelril,项目名称:Skree,代码行数:18,代码来源:HighScoreCommand.java

示例2: handle

import org.spongepowered.api.profile.GameProfile; //导入方法依赖的package包/类
@Override
public void handle(NetworkContext context, MessageStatusInRequest message) {
    final NetworkSession session = context.getSession();
    final LanternServer server = session.getServer();
    final Gson gson = new Gson();

    final Text description = server.getMotd();

    final InetSocketAddress address = session.getAddress();
    final InetSocketAddress virtualAddress = session.getVirtualHost();

    final int protocol = session.getProtocolVersion();
    final MinecraftVersion clientVersion = Lantern.getGame().getMinecraftVersionCache().getVersionOrUnknown(protocol, false);
    if (clientVersion == LanternMinecraftVersion.UNKNOWN) {
        Lantern.getLogger().debug("Client with unknown protocol version {} pinged the server.", protocol);
    }

    final LanternStatusClient client = new LanternStatusClient(address, clientVersion, virtualAddress);
    final ClientPingServerEvent.Response.Players players = LanternStatusHelper.createPlayers(server);
    final LanternStatusResponse response = new LanternStatusResponse(Lantern.getGame().getPlatform().getMinecraftVersion(),
            server.getFavicon(), description, players);

    final Cause cause = Cause.of(EventContext.empty(), new WrappedRemoteConnection(session));
    final ClientPingServerEvent event = SpongeEventFactory.createClientPingServerEvent(cause, client, response);
    Sponge.getEventManager().post(event);

    // Cancelled, we are done here
    if (event.isCancelled()) {
        context.getChannel().close();
        return;
    }

    final JsonObject rootObject = new JsonObject();
    final JsonObject versionObject = new JsonObject();

    checkState(response.getVersion() instanceof LanternMinecraftVersion);
    final LanternMinecraftVersion serverVersion = (LanternMinecraftVersion) response.getVersion();
    versionObject.addProperty("name", serverVersion.getName());
    versionObject.addProperty("protocol", serverVersion.getProtocol());

    if (response.getPlayers().isPresent()) {
        final JsonObject playersObject = new JsonObject();
        playersObject.addProperty("max", players.getMax());
        playersObject.addProperty("online", players.getOnline());

        List<GameProfile> profiles = players.getProfiles();
        if (!profiles.isEmpty()) {
            final JsonArray array = new JsonArray();
            for (GameProfile profile : profiles) {
                Optional<String> optName = profile.getName();
                if (!optName.isPresent()) {
                    continue;
                }
                final JsonObject profileObject = new JsonObject();
                profileObject.addProperty("name", optName.get());
                profileObject.addProperty("id", profile.getUniqueId().toString());
                array.add(profileObject);
            }
            playersObject.add("sample", array);
        }
        rootObject.add("players", playersObject);
    }

    rootObject.add("version", versionObject);
    rootObject.add("description", ((LanternJsonTextSerializer) TextSerializers.JSON).getGson().toJsonTree(response.getDescription()));

    response.getFavicon().ifPresent(icon -> rootObject.addProperty("favicon", ((LanternFavicon) icon).getEncoded()));

    final JsonObject fmlObject = new JsonObject();
    // Trick the client that the server is fml, we support fml channels anyway
    fmlObject.addProperty("type", "FML");
    // The client shouldn't know the plugins (mods) list
    fmlObject.add("modList", new JsonArray());

    // Add the fml info
    rootObject.add("modinfo", fmlObject);

    session.send(new MessageStatusOutResponse(gson.toJson(rootObject)));
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:80,代码来源:HandlerStatusRequest.java


注:本文中的org.spongepowered.api.profile.GameProfile.getName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。