net.minecraft.util.com.mojang.authlib.GameProfile Java Examples

The following examples show how to use net.minecraft.util.com.mojang.authlib.GameProfile. 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: ServerInfoPacketHandler.java    From PingAPI with MIT License 6 votes vote down vote up
/**
 * 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);
}
 
Example #2
Source File: ServerInfoPacketHandler.java    From PingAPI with MIT License 6 votes vote down vote up
/**
 * 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;
}
 
Example #3
Source File: ServerInfoPacketHandler.java    From PingAPI with MIT License 6 votes vote down vote up
/**
 * 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);
}
 
Example #4
Source File: ServerInfoPacketHandler.java    From PingAPI with MIT License 6 votes vote down vote up
/**
 * 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;
}
 
Example #5
Source File: ServerInfoPacketHandler.java    From PingAPI with MIT License 6 votes vote down vote up
/**
 * 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);
}
 
Example #6
Source File: ServerInfoPacketHandler.java    From PingAPI with MIT License 6 votes vote down vote up
/**
 * 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;
}
 
Example #7
Source File: OptimizedUserCache.java    From Carbon with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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;
	}
}
 
Example #8
Source File: EntitySpawnHandler.java    From EntityAPI with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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;
}
 
Example #9
Source File: EntitySpawnHandler.java    From EntityAPI with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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;
}
 
Example #10
Source File: ControllablePlayerEntity.java    From EntityAPI with GNU Lesser General Public License v3.0 5 votes vote down vote up
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;
}
 
Example #11
Source File: EntityNPCPlayer.java    From AnnihilationPro with MIT License 5 votes vote down vote up
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;	
}
 
Example #12
Source File: ControllablePlayerEntity.java    From EntityAPI with GNU Lesser General Public License v3.0 5 votes vote down vote up
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);
}
 
Example #13
Source File: ControllablePlayerEntity.java    From EntityAPI with GNU Lesser General Public License v3.0 5 votes vote down vote up
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;
}
 
Example #14
Source File: ControllablePlayerEntity.java    From EntityAPI with GNU Lesser General Public License v3.0 5 votes vote down vote up
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);
}
 
Example #15
Source File: ControllablePlayerEntity.java    From EntityAPI with GNU Lesser General Public License v3.0 5 votes vote down vote up
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);
}
 
Example #16
Source File: ControllablePlayerEntity.java    From EntityAPI with GNU Lesser General Public License v3.0 5 votes vote down vote up
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);
}
 
Example #17
Source File: UserCacheEntry.java    From Carbon with GNU Lesser General Public License v3.0 5 votes vote down vote up
public UserCacheEntry(GameProfile profile) {
	this.profile = profile;
	Calendar calendar = Calendar.getInstance();
	calendar.setTime(new Date());
	calendar.add(Calendar.MONTH, 1);
	expireDate = calendar.getTime();
}
 
Example #18
Source File: UserCacheEntryJsonSerializer.java    From Carbon with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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;
}
 
Example #19
Source File: OptimizedUserCache.java    From Carbon with GNU Lesser General Public License v3.0 5 votes vote down vote up
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];
}
 
Example #20
Source File: OptimizedUserCache.java    From Carbon with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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);
	}
}
 
Example #21
Source File: GameProfileLookup.java    From Carbon with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void onProfileLookupFailed(GameProfile profile, Exception exception) {
	this.gameProfileHolderArray[0] = null;
}
 
Example #22
Source File: GameProfileLookup.java    From Carbon with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void onProfileLookupSucceeded(GameProfile profile) {
	this.gameProfileHolderArray[0] = profile;
}
 
Example #23
Source File: ControllablePlayerEntity.java    From EntityAPI with GNU Lesser General Public License v3.0 4 votes vote down vote up
public ControllablePlayerEntity(MinecraftServer minecraftServer, WorldServer worldServer, GameProfile gameProfile, PlayerInteractManager playerInteractManager, ControllablePlayer controllablePlayer) {
    this(minecraftServer, worldServer, gameProfile, playerInteractManager);
    this.controllablePlayer = controllablePlayer;
}
 
Example #24
Source File: GameProfileLookup.java    From Carbon with GNU Lesser General Public License v3.0 4 votes vote down vote up
public GameProfileLookup(GameProfile[] gameProfileHolderArray) {
	this.gameProfileHolderArray = gameProfileHolderArray;
}
 
Example #25
Source File: ControllablePlayerEntity.java    From EntityAPI with GNU Lesser General Public License v3.0 4 votes vote down vote up
public ControllablePlayerEntity(MinecraftServer minecraftServer, WorldServer worldServer, GameProfile gameProfile, PlayerInteractManager playerInteractManager, ControllablePlayer controllablePlayer) {
    this(minecraftServer, worldServer, gameProfile, playerInteractManager);
    this.controllablePlayer = controllablePlayer;
}
 
Example #26
Source File: UserCacheEntry.java    From Carbon with GNU Lesser General Public License v3.0 4 votes vote down vote up
public GameProfile getProfile() {
	return profile;
}
 
Example #27
Source File: UserCacheEntry.java    From Carbon with GNU Lesser General Public License v3.0 4 votes vote down vote up
public UserCacheEntry(GameProfile profile, Date date) {
	this.profile = profile;
	this.expireDate = date;
}
 
Example #28
Source File: OptimizedUserCache.java    From Carbon with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public GameProfile a(UUID uuid) {
	UserCacheEntry entry = uuidToProfile.get(uuid);
	return entry == null ? null : entry.getProfile();
}