use of com.mojang.authlib.GameProfileRepository in project SpongeVanilla by SpongePowered.
the class SpongeVanilla method start.
private static void start(String[] args) {
// Attempt to load metadata
MetadataContainer metadata = MetadataContainer.load();
// Register Minecraft plugin container
MinecraftPluginContainer.register();
OptionSet options = VanillaCommandLine.parse(args);
// Note: This launches the server instead of MinecraftServer.main
// Keep command line options up-to-date with Vanilla
Bootstrap.register();
File worldDir = options.has(WORLD_DIR) ? options.valueOf(WORLD_DIR) : new File(".");
YggdrasilAuthenticationService authenticationService = new YggdrasilAuthenticationService(Proxy.NO_PROXY, UUID.randomUUID().toString());
MinecraftSessionService sessionService = authenticationService.createMinecraftSessionService();
GameProfileRepository profileRepository = authenticationService.createProfileRepository();
PlayerProfileCache profileCache = new PlayerProfileCache(profileRepository, new File(worldDir, USER_CACHE_FILE.getName()));
DedicatedServer server = new DedicatedServer(worldDir, DataFixesManager.createFixer(), authenticationService, sessionService, profileRepository, profileCache);
// We force-load NetHandlerPlayServer here.
// Otherwise, VanillaChannelRegistrar causes it to be loaded from
// within the Guice injector (see SpongeVanillaModule), thus swallowing
// any Mixin exception that occurs.
//
// See https://github.com/SpongePowered/SpongeVanilla/issues/235 for a more
// in-depth explanation
NetHandlerPlayServer.class.getName();
final Stage stage = SpongeGuice.getInjectorStage(VanillaLaunch.ENVIRONMENT == DEVELOPMENT ? Stage.DEVELOPMENT : Stage.PRODUCTION);
SpongeImpl.getLogger().debug("Creating injector in stage '{}'", stage);
Guice.createInjector(stage, new SpongeModule(), new SpongeVanillaModule(server, metadata));
if (options.has(WORLD_NAME)) {
server.setFolderName(options.valueOf(WORLD_NAME));
}
if (options.has(PORT)) {
server.setServerPort(options.valueOf(PORT));
}
if (options.has(BONUS_CHEST)) {
server.canCreateBonusChest(true);
}
server.startServerThread();
Runtime.getRuntime().addShutdownHook(new Thread(server::stopServer, "Server Shutdown Thread"));
}
use of com.mojang.authlib.GameProfileRepository in project Citizens2 by CitizensDev.
the class ProfileFetcher method fetchRequests.
/**
* Fetch one or more profiles.
*
* @param requests
* The profile requests.
*/
void fetchRequests(final Collection<ProfileRequest> requests) {
Preconditions.checkNotNull(requests);
final GameProfileRepository repo = NMS.getGameProfileRepository();
String[] playerNames = new String[requests.size()];
int i = 0;
for (ProfileRequest request : requests) {
playerNames[i++] = request.getPlayerName();
}
repo.findProfilesByNames(playerNames, Agent.MINECRAFT, new ProfileLookupCallback() {
@Override
public void onProfileLookupFailed(GameProfile profile, Exception e) {
if (Messaging.isDebugging()) {
Messaging.debug("Profile lookup for player '" + profile.getName() + "' failed2: " + getExceptionMsg(e));
Messaging.debug(Throwables.getStackTraceAsString(e));
}
ProfileRequest request = findRequest(profile.getName(), requests);
if (request == null)
return;
if (isProfileNotFound(e)) {
request.setResult(null, ProfileFetchResult.NOT_FOUND);
} else if (isTooManyRequests(e)) {
request.setResult(null, ProfileFetchResult.TOO_MANY_REQUESTS);
} else {
request.setResult(null, ProfileFetchResult.FAILED);
}
}
@Override
public void onProfileLookupSucceeded(final GameProfile profile) {
if (Messaging.isDebugging()) {
Messaging.debug("Fetched profile " + profile.getId() + " for player " + profile.getName());
}
ProfileRequest request = findRequest(profile.getName(), requests);
if (request == null)
return;
try {
request.setResult(NMS.fillProfileProperties(profile, true), ProfileFetchResult.SUCCESS);
} catch (Exception e) {
if (Messaging.isDebugging()) {
Messaging.debug("Profile lookup for player '" + profile.getName() + "' failed: " + getExceptionMsg(e) + " " + isTooManyRequests(e));
Messaging.debug(Throwables.getStackTraceAsString(e));
}
if (isTooManyRequests(e)) {
request.setResult(null, ProfileFetchResult.TOO_MANY_REQUESTS);
} else {
request.setResult(null, ProfileFetchResult.FAILED);
}
}
}
});
}
Aggregations