下面列出了org.bukkit.Skin#com.mojang.authlib.GameProfile 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* 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.getServerData().getProtocolVersion();
String protocolName = ping.getServerData().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 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 ServerData(reply.getProtocolName(), reply.getProtocolVersion()));
ping.setFavicon(((CraftIconCache) reply.getIcon()).value);
return new PacketStatusOutServerInfo(ping);
}
static PacketPlayOutPlayerInfo.PlayerInfoData playerListPacketData(
PacketPlayOutPlayerInfo packet,
UUID uuid,
String name,
@Nullable BaseComponent displayName,
GameMode gamemode,
int ping,
@Nullable Skin skin) {
GameProfile profile = new GameProfile(uuid, name);
if (skin != null) {
for (Map.Entry<String, Collection<Property>> entry :
Skins.toProperties(skin).asMap().entrySet()) {
profile.getProperties().putAll(entry.getKey(), entry.getValue());
}
}
PacketPlayOutPlayerInfo.PlayerInfoData data =
packet.constructData(
profile,
ping,
gamemode == null ? null : WorldSettings.EnumGamemode.getById(gamemode.getValue()),
null); // ELECTROID
data.displayName = displayName == null ? null : new BaseComponent[] {displayName};
return data;
}
private int checkPing() {
long l = System.currentTimeMillis();
if (l - lastPinged < 1000) {
return ping;
}
lastPinged = l;
GameProfile gameProfile = The5zigMod.getDataManager().getGameProfile();
for (NetworkPlayerInfo networkPlayerInfo : The5zigMod.getVars().getServerPlayers()) {
if (gameProfile.equals(networkPlayerInfo.getGameProfile()) || gameProfile.getName().equals(ChatColor.stripColor(networkPlayerInfo.getDisplayName()))
|| (networkPlayerInfo.getGameProfile() != null && gameProfile.getName().equals(networkPlayerInfo.getGameProfile().getName()))) {
if (networkPlayerInfo.getPing() <= 0) {
ping = 0;
} else {
ping = networkPlayerInfo.getPing();
}
break;
}
}
return ping;
}
public boolean renderInPersonMode(Object instance, Object itemStackObject, Object entityPlayerObject, Object cameraTransformTypeObject, boolean leftHand) {
if (!MinecraftFactory.getClassProxyCallback().isRenderCustomModels()) {
return false;
}
adz itemStack = (adz) itemStackObject;
if (!(entityPlayerObject instanceof zs)) {
return false;
}
zs entityPlayer = (zs) entityPlayerObject;
bpl.b cameraTransformType = (bpl.b) cameraTransformTypeObject;
GameProfile profile = entityPlayer.cP();
PlayerResource playerResource = playerProfile.getName().equals(profile.getName()) ? ownPlayerResource : playerResources.getIfPresent(profile.getId());
if (playerResource == null || playerResource.getItemModelResources() == null) {
return false;
}
for (ItemModelResource itemModelResource : playerResource.getItemModelResources()) {
if (shouldRender(itemModelResource, entityPlayer, itemStack)) {
render(instance, itemStack, itemModelResource, cameraTransformType, leftHand);
return true;
}
}
return false;
}
private static boolean cantSpawn(CommandContext<ServerCommandSource> context)
{
String playerName = StringArgumentType.getString(context, "player");
MinecraftServer server = context.getSource().getMinecraftServer();
PlayerManager manager = server.getPlayerManager();
PlayerEntity player = manager.getPlayer(playerName);
if (player != null)
{
Messenger.m(context.getSource(), "r Player ", "rb " + playerName, "r is already logged on");
return true;
}
GameProfile profile = server.getUserCache().findByName(playerName);
if (manager.getUserBanList().contains(profile))
{
Messenger.m(context.getSource(), "r Player ", "rb " + playerName, "r is banned");
return true;
}
if (manager.isWhitelistEnabled() && profile != null && manager.isWhitelisted(profile) && !context.getSource().hasPermissionLevel(2))
{
Messenger.m(context.getSource(), "r Whitelisted players can only be spawned by operators");
return true;
}
return false;
}
@Nonnull
public static SkullMeta getSkullByValue(@Nonnull SkullMeta head, @Nonnull String value) {
Validate.notEmpty(value, "Skull value cannot be null or empty");
GameProfile profile = new GameProfile(UUID.randomUUID(), null);
profile.getProperties().put("textures", new Property("textures", value));
try {
Field profileField = head.getClass().getDeclaredField("profile");
profileField.setAccessible(true);
profileField.set(head, profile);
} catch (SecurityException | NoSuchFieldException | IllegalAccessException ex) {
ex.printStackTrace();
}
return head;
}
public static String getURL(ItemStack is) {
if (is.getType() !=MultiVersionLookup.getSkull())
return null;
ItemMeta headMeta = is.getItemMeta();
Class<?> headMetaClass = headMeta.getClass();
GameProfile prof = ReflectionsUtil.getField(headMetaClass, "profile", GameProfile.class).get(headMeta);
PropertyMap propertyMap = prof.getProperties();
Collection<Property> textures64 = propertyMap.get("textures");
String tex64 = null;
for (Property p : textures64) {
if (p.getName().equals("textures")) {
tex64 = p.getValue();
break;
}
}
if (tex64 != null) {
byte[] decode = null;
decode = Base64.getDecoder().decode(tex64);
String string = new String(decode);
String parsed = string.split("SKIN:{url:\"")[1].split("\"}}}")[0];
return parsed;
}
return null;
}
/**
* 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.getServerData().getProtocolVersion();
String protocolName = ping.getServerData().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;
}
private static boolean extract(
String message, Pattern[] patterns, BiConsumer<GameProfile, String> callback) {
for (Pattern pattern : patterns) {
Matcher matcher = pattern.matcher(message);
if (matcher.find()) {
final String messageSender = matcher.group(1);
final String messageOnly = matcher.group(2);
if (!Strings.isNullOrEmpty(messageSender)) {
for (NetworkPlayerInfo data : getLocalPlayer().connection.getPlayerInfoMap()) {
if (
String.CASE_INSENSITIVE_ORDER
.compare(messageSender, data.getGameProfile().getName())
== 0) {
callback.accept(data.getGameProfile(), messageOnly);
return true;
}
}
}
}
}
return false;
}
@Override
public void renderItem(ItemRenderType type, ItemStack stack, Object... data) {
GameProfile profile = stack.hasTagCompound() ? profile = getGameProfile(stack) : null;
switch (type) {
case ENTITY:
renderSkull(-0.25F, -0.5F, -0.5F, stack.getItemDamage(), profile);
break;
case EQUIPPED:
renderSkull(0.5F, 0.0F, 0.0F, stack.getItemDamage(), profile);
break;
case EQUIPPED_FIRST_PERSON:
renderSkull(0.5F, 0.35F, 0.25F, stack.getItemDamage(), profile);
break;
case INVENTORY:
OpenGLHelper.scale(1.5, 1.5, 1.5);
renderSkull(0.75F, 0.30F, 0.5F, stack.getItemDamage(), profile);
break;
default:
break;
}
}
/**
* 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 ServerData(reply.getProtocolName(), reply.getProtocolVersion()));
ping.setFavicon(((CraftIconCache) reply.getIcon()).value);
return new PacketStatusOutServerInfo(ping);
}
private void queueEvent(String event, EntityPlayer user, IEventArgsSource source) {
final GameProfile gameProfile = user.getGameProfile();
final UUID userId = gameProfile.getId();
final String idString = userId != null? userId.toString() : null;
final String userName = gameProfile.getName();
for (IArchitectureAccess computer : computers) {
final Object[] extra = source.getArgs(computer);
final Object[] args = new Object[3 + extra.length];
System.arraycopy(extra, 0, args, 3, extra.length);
args[0] = computer.peripheralName();
args[1] = userName;
args[2] = idString;
computer.signal(event, args);
}
}
private void fireEvents(
SPacketPlayerListItem.Action action, PlayerInfo info, GameProfile profile) {
if (ignore || info == null) {
return;
}
switch (action) {
case ADD_PLAYER: {
MinecraftForge.EVENT_BUS.post(new PlayerConnectEvent.Join(info, profile));
break;
}
case REMOVE_PLAYER: {
MinecraftForge.EVENT_BUS.post(new PlayerConnectEvent.Leave(info, profile));
break;
}
}
}
public boolean renderInPersonMode(Object instance, Object itemStackObject, Object entityPlayerObject, Object cameraTransformTypeObject, boolean leftHand) {
if (!MinecraftFactory.getClassProxyCallback().isRenderCustomModels()) {
return false;
}
adq itemStack = (adq) itemStackObject;
if (!(entityPlayerObject instanceof zj)) {
return false;
}
zj entityPlayer = (zj) entityPlayerObject;
bos.b cameraTransformType = (bos.b) cameraTransformTypeObject;
GameProfile profile = entityPlayer.cK();
PlayerResource playerResource = playerProfile.getName().equals(profile.getName()) ? ownPlayerResource : playerResources.getIfPresent(profile.getId());
if (playerResource == null || playerResource.getItemModelResources() == null) {
return false;
}
for (ItemModelResource itemModelResource : playerResource.getItemModelResources()) {
if (shouldRender(itemModelResource, entityPlayer, itemStack)) {
render(instance, itemStack, itemModelResource, cameraTransformType, leftHand);
return true;
}
}
return false;
}
/**
* 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;
}
@Inject(InjectionType.OVERRIDE)
void applyToItem(final NBTTagCompound tag) {
super_applyToItem(tag);
if (this.profile != null) {
NBTTagCompound owner = new NBTTagCompound();
GameProfileSerializer.serialize(owner, this.profile);
tag.set("SkullOwner", owner);
System.out.println("Set owner to " + owner);
TileEntitySkull.b(this.profile, new Predicate<GameProfile>() {
@Override
public boolean apply(@Nullable GameProfile gameProfile) {
NBTTagCompound newOwner = new NBTTagCompound();
GameProfileSerializer.serialize(newOwner, gameProfile);
tag.set("SkullOwner", newOwner);
System.out.println("Received game profile!");
return false;
}
});
}
}
/**
* 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.getServerData().getProtocolVersion();
String protocolName = ping.getServerData().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 Identifier getSkinResource(@Nullable GameProfile profile) {
deadMau5.setVisible(profile != null && "deadmau5".equals(profile.getName()));
if (profile != null) {
Identifier skin = SkinsProxy.instance.getSkinTexture(profile);
if (skin != null) {
return skin;
}
return DefaultSkinHelper.getTexture(PlayerEntity.getUuidFromProfile(profile));
}
return DefaultSkinHelper.getTexture();
}
@Override
public void joinServer(GameProfile profile, String accessToken, String serverID) throws AuthenticationException {
// Join server
String username = profile.getName();
if (LogHelper.isDebugEnabled()) {
LogHelper.debug("joinServer, Username: '%s', Access token: %s, Server ID: %s", username, accessToken, serverID);
}
// Make joinServer request
boolean success;
try {
success = new JoinServerRequest(username, accessToken, serverID).request().allow;
} catch (Exception e) {
LogHelper.error(e);
throw new AuthenticationUnavailableException(e);
}
// Verify is success
if (!success)
throw new AuthenticationException("Bad Login (Clientside)");
}
private static String getUriUuid() {
return Optional.of(MC.getSession().getProfile())
.map(GameProfile::getId)
.map(UUID::toString)
.map(id -> id.replaceAll("-", ""))
.orElse(null);
}
@Override
public void pardon(String target) {
Validate.notNull(target, "Target cannot be null");
GameProfile profile = MinecraftServer.getServer().func_152358_ax().func_152655_a(target);
list.func_152684_c(profile);
}
public CraftProfileBanEntry(GameProfile profile, UserListBansEntry entry, UserListBans list) {
this.list = list;
this.profile = profile;
this.created = entry.getCreated() != null ? new Date(entry.getCreated().getTime()) : null;
this.source = entry.getSource();
this.expiration = entry.getBanEndDate() != null ? new Date(entry.getBanEndDate().getTime()) : null;
this.reason = entry.getBanReason();
}
@Override
public UUID getUUID(String name) {
try {
GameProfile profile = FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerProfileCache().getGameProfileForUsername(name);
return profile.getId();
} catch (Throwable e) {
return null;
}
}
@Asynchronous
@ScriptCallable(returnTypes = ReturnType.TABLE, description = "Get the names of all the users linked up to this bridge")
public List<GameProfile> getUsers() {
List<GameProfile> result = Lists.newArrayList();
for (PlayerInfo info : knownPlayersByUUID.values())
result.add(info.profile);
return result;
}
@Override
public void test() throws Exception {
UUID uuid = UUID.randomUUID();
GameProfile profile = new GameProfile(uuid, "random");
NBTCompound nbt = NBTGameProfile.toNBT(profile);
profile = null;
profile = NBTGameProfile.fromNBT(nbt);
if (profile == null || !profile.getId().equals(uuid)) {
throw new NbtApiException("Error when converting a GameProfile from/to NBT!");
}
}
@Override
public Object getCapeLocation(Object player) {
GameProfile profile = ((bpp) player).cS();
if (playerProfile.getName().equals(profile.getName())) {
return getCapeLocation(ownPlayerResource);
} else {
return getCapeLocation(playerResources.getIfPresent(profile.getId()));
}
}
@Override
public boolean isBanned(String target) {
Validate.notNull(target, "Target cannot be null");
GameProfile profile = MinecraftServer.getServerCB().getPlayerProfileCache().getGameProfileForUsername(target);
if (profile == null) {
return false;
}
return list.isBanned(profile);
}
/**
* @author Sk1er
* @reason Not proper null checks
*/
@Overwrite
public static GameProfile readGameProfileFromNBT(NBTTagCompound compound) {
String s = null;
String s1 = null;
if (compound.hasKey("Name", 8)) s = compound.getString("Name");
if (compound.hasKey("Id", 8)) s1 = compound.getString("Id");
if (StringUtils.isNullOrEmpty(s) && StringUtils.isNullOrEmpty(s1)) {
return null;
} else {
UUID uuid = null;
if (s1 != null)
try {
uuid = UUID.fromString(s1);
} catch (Throwable ignored) {
}
GameProfile gameprofile = new GameProfile(uuid, s);
if (compound.hasKey("Properties", 10)) {
NBTTagCompound nbttagcompound = compound.getCompoundTag("Properties");
for (String s2 : nbttagcompound.getKeySet()) {
NBTTagList nbttaglist = nbttagcompound.getTagList(s2, 10);
int bound = nbttaglist.tagCount();
for (int i = 0; i < bound; i++) {
NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
String s3 = nbttagcompound1.getString("Value");
gameprofile.getProperties().put(s2, nbttagcompound1.hasKey("Signature", 8) ?
new Property(s2, s3, nbttagcompound1.getString("Signature")) : new Property(s2, s3));
}
}
}
return gameprofile;
}
}