Java Code Examples for protocolsupport.api.events.PlayerProfileCompleteEvent#isLoginDenied()

The following examples show how to use protocolsupport.api.events.PlayerProfileCompleteEvent#isLoginDenied() . 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: PSInitialHandler.java    From ProtocolSupportBungee with GNU Affero General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
protected void finishLogin() {
	GameProfile profile = connection.getProfile();

	PlayerProfileCompleteEvent profileCompleteEvent = new PlayerProfileCompleteEvent(connection);
	BungeeCord.getInstance().getPluginManager().callEvent(profileCompleteEvent);
	if (profileCompleteEvent.isLoginDenied()) {
		disconnect(profileCompleteEvent.getDenyLoginMessage());
		return;
	}

	if (profileCompleteEvent.getForcedName() != null) {
		updateUsername(profileCompleteEvent.getForcedName(), false);
	}
	if (profileCompleteEvent.getForcedUUID() != null) {
		updateUUID(profileCompleteEvent.getForcedUUID(), false);
	}
	profile.setProperties(profileCompleteEvent.getProperties());

	loginProfile = new LoginResult(
		getName(), getUUID(),
		profile.getProperties().values().stream()
		.flatMap(Collection::stream)
		.map(psprop -> new LoginResult.Property(psprop.getName(), psprop.getValue(), psprop.getSignature()))
		.collect(Collectors.toList()).toArray(new LoginResult.Property[0])
	);

	ProxiedPlayer oldName = BungeeCord.getInstance().getPlayer(getName());
	if (oldName != null) {
		oldName.disconnect(BungeeCord.getInstance().getTranslation("already_connected_proxy"));
	}
	ProxiedPlayer oldID = BungeeCord.getInstance().getPlayer(getUniqueId());
	if (oldID != null) {
		oldID.disconnect(BungeeCord.getInstance().getTranslation("already_connected_proxy"));
	}

	Callback<LoginEvent> complete = new Callback<LoginEvent>() {
		@Override
		public void done(LoginEvent result, Throwable error) {
			if (result.isCancelled()) {
				disconnect(result.getCancelReasonComponents());
				return;
			}
			if (!isConnected()) {
				return;
			}
			channel.getHandle().eventLoop().execute(() -> processLoginFinish());
		}
	};
	BungeeCord.getInstance().getPluginManager().callEvent(new LoginEvent(this, complete));
}
 
Example 2
Source File: AbstractLoginListener.java    From ProtocolSupport with GNU Affero General Public License v3.0 4 votes vote down vote up
protected void finishLogin() throws InterruptedException, ExecutionException  {
	if (!networkManager.isConnected()) {
		return;
	}

	cancelTimeoutTask();

	LoginProfile profile = connection.getLoginProfile();
	InetSocketAddress saddress = networkManager.getAddress();

	InetAddress address = saddress.getAddress();

	PlayerProfileCompleteEvent event = new PlayerProfileCompleteEvent(connection);
	Bukkit.getPluginManager().callEvent(event);
	if (event.isLoginDenied()) {
		disconnect(event.getDenyLoginMessage());
		return;
	}
	if (event.getForcedName() != null) {
		profile.setName(event.getForcedName());
	}
	if (event.getForcedUUID() != null) {
		profile.setUUID(event.getForcedUUID());
	}
	event.getProperties().values().forEach(c -> c.forEach(profile::addProperty));

	AsyncPlayerPreLoginEvent asyncEvent = new AsyncPlayerPreLoginEvent(profile.getName(), address, profile.getUUID());
	Bukkit.getPluginManager().callEvent(asyncEvent);

	PlayerPreLoginEvent syncEvent = new PlayerPreLoginEvent(profile.getName(), address, profile.getUUID());
	if (asyncEvent.getResult() != PlayerPreLoginEvent.Result.ALLOWED) {
		syncEvent.disallow(asyncEvent.getResult(), asyncEvent.getKickMessage());
	}
	if (PlayerPreLoginEvent.getHandlerList().getRegisteredListeners().length != 0) {
		if (ServerPlatform.get().getMiscUtils().callSyncTask(() -> {
			Bukkit.getPluginManager().callEvent(syncEvent);
			return syncEvent.getResult();
		}).get() != PlayerPreLoginEvent.Result.ALLOWED) {
			disconnect(syncEvent.getKickMessage());
			return;
		}
	}

	if (syncEvent.getResult() != PlayerPreLoginEvent.Result.ALLOWED) {
		disconnect(syncEvent.getKickMessage());
		return;
	}

	Bukkit.getLogger().info("UUID of player " + connection.getProfile().getName() + " is " + connection.getProfile().getUUID());

	if (hasCompression(connection.getVersion())) {
		int threshold = ServerPlatform.get().getMiscUtils().getCompressionThreshold();
		if (threshold >= 0) {
			CountDownLatch waitpacketsend = new CountDownLatch(1);
			connection.submitIOTask(() -> networkManager.sendPacket(
				ServerPlatform.get().getPacketFactory().createSetCompressionPacket(threshold),
				future -> {
					ServerPlatform.get().getMiscUtils().enableCompression(networkManager.getChannel().pipeline(), threshold);
					waitpacketsend.countDown();
				}
			));
			try {
				if (!waitpacketsend.await(5, TimeUnit.SECONDS)) {
					disconnect("Timeout while waiting for login success send");
					return;
				}
			} catch (InterruptedException e) {
				disconnect("Exception while waiting for login success send");
				return;
			}
		}
	}

	AbstractLoginListenerPlay listener = getLoginListenerPlay();
	networkManager.setPacketListener(listener);
	listener.finishLogin();
}