下面列出了怎么用net.minecraft.util.com.mojang.authlib.GameProfile的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Creates a new PacketStatusOutServerInfo packet from the data found in a PingReply instance
* @param reply The PingReply instance
* @return A PacketStatusOutServerInfo packet
*/
public static PacketStatusOutServerInfo constructPacket(PingReply reply) {
GameProfile[] sample = new GameProfile[reply.getPlayerSample().size()];
List<String> list = reply.getPlayerSample();
for(int i = 0; i < list.size(); i++) {
sample[i] = new GameProfile(UUID.randomUUID(), list.get(i));
}
ServerPingPlayerSample playerSample = new ServerPingPlayerSample(reply.getMaxPlayers(), reply.getOnlinePlayers());
playerSample.a(sample);
ServerPing ping = new ServerPing();
ping.setMOTD(new ChatComponentText(reply.getMOTD()));
ping.setPlayerSample(playerSample);
ping.setServerInfo(new ServerPingServerData(reply.getProtocolName(), reply.getProtocolVersion()));
ping.setFavicon(((CraftIconCache) reply.getIcon()).value);
return new PacketStatusOutServerInfo(ping);
}
/**
* Creates a new PingReply instance from the data found in a PacketStatusOutServerInfo packet
* @param packet The PacketStatusOutServerInfo instance
* @param ctx The ChannelHandlerContext instance
* @return A PingReply instance
*/
public static PingReply constructReply(PacketStatusOutServerInfo packet, ChannelHandlerContext ctx) {
try {
ServerPing ping = (ServerPing) SERVER_PING_FIELD.get(packet);
String motd = ChatSerializer.a(ping.a());
int max = ping.b().a();
int online = ping.b().b();
int protocolVersion = ping.c().b();
String protocolName = ping.c().a();
GameProfile[] profiles = ping.b().c();
List<String> list = new ArrayList<String>();
for(int i = 0; i < profiles.length; i++) {
list.add(profiles[i].getName());
}
PingReply reply = new PingReply(ctx, motd, online, max, protocolVersion, protocolName, list);
return reply;
} catch(IllegalAccessException e) {
e.printStackTrace();
}
return null;
}
/**
* Creates a new PacketStatusOutServerInfo packet from the data found in a PingReply instance
* @param reply The PingReply instance
* @return A PacketStatusOutServerInfo packet
*/
public static PacketStatusOutServerInfo constructPacket(PingReply reply) {
GameProfile[] sample = new GameProfile[reply.getPlayerSample().size()];
List<String> list = reply.getPlayerSample();
for(int i = 0; i < list.size(); i++) {
sample[i] = new GameProfile(UUID.randomUUID(), list.get(i));
}
ServerPingPlayerSample playerSample = new ServerPingPlayerSample(reply.getMaxPlayers(), reply.getOnlinePlayers());
playerSample.a(sample);
ServerPing ping = new ServerPing();
ping.setMOTD(new ChatComponentText(reply.getMOTD()));
ping.setPlayerSample(playerSample);
ping.setServerInfo(new ServerPingServerData(reply.getProtocolName(), reply.getProtocolVersion()));
ping.setFavicon(((CraftIconCache) reply.getIcon()).value);
return new PacketStatusOutServerInfo(ping);
}
/**
* Creates a new PingReply instance from the data found in a PacketStatusOutServerInfo packet
* @param packet The PacketStatusOutServerInfo instance
* @param ctx The ChannelHandlerContext instance
* @return A PingReply instance
*/
public static PingReply constructReply(PacketStatusOutServerInfo packet, ChannelHandlerContext ctx) {
try {
ServerPing ping = (ServerPing) SERVER_PING_FIELD.get(packet);
String motd = ChatSerializer.a(ping.a());
int max = ping.b().a();
int online = ping.b().b();
int protocolVersion = ping.c().b();
String protocolName = ping.c().a();
GameProfile[] profiles = ping.b().c();
List<String> list = new ArrayList<String>();
for(int i = 0; i < profiles.length; i++) {
list.add(profiles[i].getName());
}
PingReply reply = new PingReply(ctx, motd, online, max, protocolVersion, protocolName, list);
return reply;
} catch(IllegalAccessException e) {
e.printStackTrace();
}
return null;
}
/**
* Creates a new PacketStatusOutServerInfo packet from the data found in a PingReply instance
* @param reply The PingReply instance
* @return A PacketStatusOutServerInfo packet
*/
public static PacketStatusOutServerInfo constructPacket(PingReply reply) {
GameProfile[] sample = new GameProfile[reply.getPlayerSample().size()];
List<String> list = reply.getPlayerSample();
for(int i = 0; i < list.size(); i++) {
sample[i] = new GameProfile(UUID.randomUUID(), list.get(i));
}
ServerPingPlayerSample playerSample = new ServerPingPlayerSample(reply.getMaxPlayers(), reply.getOnlinePlayers());
playerSample.a(sample);
ServerPing ping = new ServerPing();
ping.setMOTD(new ChatComponentText(reply.getMOTD()));
ping.setPlayerSample(playerSample);
ping.setServerInfo(new ServerPingServerData(reply.getProtocolName(), reply.getProtocolVersion()));
ping.setFavicon(((CraftIconCache) reply.getIcon()).value);
return new PacketStatusOutServerInfo(ping);
}
/**
* Creates a new PingReply instance from the data found in a PacketStatusOutServerInfo packet
* @param packet The PacketStatusOutServerInfo instance
* @param ctx The ChannelHandlerContext instance
* @return A PingReply instance
*/
public static PingReply constructReply(PacketStatusOutServerInfo packet, ChannelHandlerContext ctx) {
try {
ServerPing ping = (ServerPing) SERVER_PING_FIELD.get(packet);
String motd = ChatSerializer.a(ping.a());
int max = ping.b().a();
int online = ping.b().b();
int protocolVersion = ping.c().b();
String protocolName = ping.c().a();
GameProfile[] profiles = ping.b().c();
List<String> list = new ArrayList<String>();
for(int i = 0; i < profiles.length; i++) {
list.add(profiles[i].getName());
}
PingReply reply = new PingReply(ctx, motd, online, max, protocolVersion, protocolName, list);
return reply;
} catch(IllegalAccessException e) {
e.printStackTrace();
}
return null;
}
@Override
public GameProfile getProfile(String name) {
String playername = name.toLowerCase(Locale.ROOT);
UserCacheEntry entry = stringToProfile.get(playername);
if (entry != null && entry.isExpired()) {
stringToProfile.remove(playername);
uuidToProfile.remove(entry.getProfile().getId());
return null;
}
if (entry != null) {
uuidToProfile.get(entry.getProfile().getId()); //push profile to the top of access ordered linkedhashmap, do not remove this
return entry.getProfile();
} else {
GameProfile profile = lookupProfile(MinecraftServer.getServer(), playername);
if (profile != null) {
a(profile);
return profile;
}
return null;
}
}
@Override
public ControllablePlayerHandle createPlayerHandle(ControllablePlayer player, Location location, String name, UUID uuid) {
WorldServer worldServer = ((CraftWorld) location.getWorld()).getHandle();
if (name.length() > 16)
name = name.substring(0, 16);
GameProfile profile = new GameProfile(uuid.toString().replaceAll("-", ""), name);
ControllablePlayerEntity handle = new ControllablePlayerEntity(worldServer.getMinecraftServer(), worldServer, profile, new PlayerInteractManager(worldServer), player);
handle.setPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
worldServer.addEntity(handle);
handle.world.players.remove(handle);
if (location.getBlock().getRelative(BlockFace.DOWN).getType().isBlock())
handle.onGround = true;
return handle;
}
@Override
public ControllablePlayerHandle createPlayerHandle(ControllablePlayer player, Location location, String name, UUID uuid) {
WorldServer worldServer = ((CraftWorld) location.getWorld()).getHandle();
if (name.length() > 16)
name = name.substring(0, 16);
GameProfile profile = new GameProfile(uuid.toString().replaceAll("-", ""), name);
ControllablePlayerEntity handle = new ControllablePlayerEntity(worldServer.getMinecraftServer(), worldServer, profile, new PlayerInteractManager(worldServer), player);
handle.setPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
worldServer.addEntity(handle);
handle.world.players.remove(handle);
if (location.getBlock().getRelative(BlockFace.DOWN).getType().isBlock())
handle.onGround = true;
return handle;
}
public static GameProfile makeProfile(String name, UUID skinId) {
GameProfile profile = new GameProfile(UUID.randomUUID(), name);
if (skinId != null) {
GameProfile skin = new GameProfile(skinId, null);
skin = NMS.getServer().av().fillProfileProperties(skin, true); //Srg = func_147130_as
if (skin.getProperties().get("textures") == null || !skin.getProperties().get("textures").isEmpty()) {
Property textures = skin.getProperties().get("textures").iterator().next();
profile.getProperties().put("textures", textures);
}
}
return profile;
}
@Override
public void a(GameProfile gameProfile) {
String playername = gameProfile.getName().toLowerCase(Locale.ROOT);
UUID uuid = gameProfile.getId();
UserCacheEntry entry = new UserCacheEntry(gameProfile);
if (uuidToProfile.containsKey(uuid)) {
stringToProfile.remove(uuidToProfile.get(uuid).getProfile().getName().toLowerCase(Locale.ROOT));
stringToProfile.put(playername, entry);
} else {
uuidToProfile.put(uuid, entry);
stringToProfile.put(playername, entry);
}
}
private GameProfile lookupProfile(MinecraftServer minecraftserver, String name) {
GameProfile[] gameProfileArrayHolder = new GameProfile[1];
GameProfileLookup gameProfileLookup = new GameProfileLookup(gameProfileArrayHolder);
minecraftserver.getGameProfileRepository().findProfilesByNames(new String[] { name }, Agent.MINECRAFT, gameProfileLookup);
if ((!minecraftserver.getOnlineMode()) && (gameProfileArrayHolder[0] == null)) {
UUID uuid = EntityHuman.a(new GameProfile(null, name));
GameProfile gameprofile = new GameProfile(uuid, name);
gameProfileLookup.onProfileLookupSucceeded(gameprofile);
}
return gameProfileArrayHolder[0];
}
@Override
public UserCacheEntry deserialize(JsonElement element, Type type, JsonDeserializationContext ctx) throws JsonParseException {
if (element.isJsonObject()) {
JsonObject jsonobject = element.getAsJsonObject();
JsonElement nameElement = jsonobject.get("name");
JsonElement uuidElement = jsonobject.get("uuid");
JsonElement expireDateElement = jsonobject.get("expiresOn");
if ((nameElement != null) && (uuidElement != null)) {
String name = uuidElement.getAsString();
String uuidstring = nameElement.getAsString();
Date date = null;
if (expireDateElement != null) {
try {
date = UserCache.a.parse(expireDateElement.getAsString());
} catch (ParseException parseexception) {
date = null;
}
}
if ((uuidstring != null) && (name != null)) {
UUID uuid;
try {
uuid = UUID.fromString(name);
} catch (Throwable throwable) {
return null;
}
UserCacheEntry usercacheentry = new UserCacheEntry(new GameProfile(uuid, uuidstring), date);
return usercacheentry;
}
return null;
}
return null;
}
return null;
}
public UserCacheEntry(GameProfile profile) {
this.profile = profile;
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
calendar.add(Calendar.MONTH, 1);
expireDate = calendar.getTime();
}
public ControllablePlayerEntity(MinecraftServer minecraftserver, WorldServer worldserver, GameProfile gameprofile, PlayerInteractManager playerinteractmanager) {
super(minecraftserver, worldserver, gameprofile, playerinteractmanager);
NetworkManager manager = new FixedNetworkManager();
playerConnection = new NullPlayerConnection(server, manager, this);
manager.a(playerConnection);
noDamageTicks = 1;
this.navigation = new PlayerNavigation(this, this.world);
this.moveController = new PlayerControllerMove(this);
this.lookController = new PlayerControllerLook(this);
this.jumpController = new PlayerControllerJump(this);
}
public ControllablePlayerEntity(MinecraftServer minecraftserver, WorldServer worldserver, GameProfile gameprofile, PlayerInteractManager playerinteractmanager) {
super(minecraftserver, worldserver, gameprofile, playerinteractmanager);
NetworkManager manager = new FixedNetworkManager();
playerConnection = new NullPlayerConnection(server, manager, this);
manager.a(playerConnection);
noDamageTicks = 1;
this.navigation = new PlayerNavigation(this, this.world);
this.moveController = new PlayerControllerMove(this);
this.lookController = new PlayerControllerLook(this);
this.jumpController = new PlayerControllerJump(this);
}
public ControllablePlayerEntity(MinecraftServer minecraftServer, WorldServer worldServer, GameProfile gameProfile, PlayerInteractManager playerInteractManager, ControllablePlayer controllablePlayer) {
this(minecraftServer, worldServer, gameProfile, playerInteractManager);
this.controllableEntity = controllablePlayer;
if (this.controllableEntity != null)
initialise(minecraftServer);
}
public ControllablePlayerEntity(MinecraftServer minecraftserver, WorldServer worldserver, GameProfile gameprofile, PlayerInteractManager playerinteractmanager) {
super(minecraftserver, worldserver, gameprofile, playerinteractmanager);
initialise(minecraftserver);
playerinteractmanager.b(EnumGamemode.SURVIVAL);
this.noDamageTicks = 1;
this.X = 1;
this.fauxSleeping = true;
}
public ControllablePlayerEntity(MinecraftServer minecraftServer, WorldServer worldServer, GameProfile gameProfile, PlayerInteractManager playerInteractManager, ControllablePlayer controllablePlayer) {
this(minecraftServer, worldServer, gameProfile, playerInteractManager);
this.controllableEntity = controllablePlayer;
if (this.controllableEntity != null)
initialise(minecraftServer);
}
public ControllablePlayerEntity(MinecraftServer minecraftserver, WorldServer worldserver, GameProfile gameprofile, PlayerInteractManager playerinteractmanager) {
super(minecraftserver, worldserver, gameprofile, playerinteractmanager);
initialise(minecraftserver);
playerinteractmanager.b(EnumGamemode.SURVIVAL);
this.noDamageTicks = 1;
this.X = 1;
this.fauxSleeping = true;
}
@Override
public GameProfile a(UUID uuid) {
UserCacheEntry entry = uuidToProfile.get(uuid);
return entry == null ? null : entry.getProfile();
}
public UserCacheEntry(GameProfile profile, Date date) {
this.profile = profile;
this.expireDate = date;
}
public GameProfile getProfile() {
return profile;
}
public GameProfileLookup(GameProfile[] gameProfileHolderArray) {
this.gameProfileHolderArray = gameProfileHolderArray;
}
@Override
public void onProfileLookupFailed(GameProfile profile, Exception exception) {
this.gameProfileHolderArray[0] = null;
}
@Override
public void onProfileLookupSucceeded(GameProfile profile) {
this.gameProfileHolderArray[0] = profile;
}
public ControllablePlayerEntity(MinecraftServer minecraftServer, WorldServer worldServer, GameProfile gameProfile, PlayerInteractManager playerInteractManager, ControllablePlayer controllablePlayer) {
this(minecraftServer, worldServer, gameProfile, playerInteractManager);
this.controllablePlayer = controllablePlayer;
}
public ControllablePlayerEntity(MinecraftServer minecraftServer, WorldServer worldServer, GameProfile gameProfile, PlayerInteractManager playerInteractManager, ControllablePlayer controllablePlayer) {
this(minecraftServer, worldServer, gameProfile, playerInteractManager);
this.controllablePlayer = controllablePlayer;
}