org.bukkit.event.player.AsyncPlayerPreLoginEvent Java Examples
The following examples show how to use
org.bukkit.event.player.AsyncPlayerPreLoginEvent.
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: BukkitConnectionListener.java From LuckPerms with MIT License | 7 votes |
@EventHandler(priority = EventPriority.MONITOR) public void onPlayerPreLoginMonitor(AsyncPlayerPreLoginEvent e) { /* Listen to see if the event was cancelled after we initially handled the connection If the connection was cancelled here, we need to do something to clean up the data that was loaded. */ // Check to see if this connection was denied at LOW. if (this.deniedAsyncLogin.remove(e.getUniqueId())) { // their data was never loaded at LOW priority, now check to see if they have been magically allowed since then. // This is a problem, as they were denied at low priority, but are now being allowed. if (e.getLoginResult() == AsyncPlayerPreLoginEvent.Result.ALLOWED) { this.plugin.getLogger().severe("Player connection was re-allowed for " + e.getUniqueId()); e.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, ""); } } }
Example #2
Source File: PlayerListenerTest.java From AuthMeReloaded with GNU General Public License v3.0 | 6 votes |
@Test public void shouldAbortPlayerJoinForInvalidName() throws FailedVerificationException { // given String name = "inval!dName"; UUID uniqueId = UUID.fromString("753493c9-33ba-4a4a-bf61-1bce9d3c9a71"); InetAddress ip = mockAddrWithIp("33.32.33.33"); AsyncPlayerPreLoginEvent event = spy(new AsyncPlayerPreLoginEvent(name, ip, uniqueId)); given(validationService.isUnrestricted(name)).willReturn(false); FailedVerificationException exception = new FailedVerificationException( MessageKey.INVALID_NAME_CHARACTERS, "[a-z]"); doThrow(exception).when(onJoinVerifier).checkIsValidName(name); String message = "Invalid characters!"; given(messages.retrieveSingle(name, exception.getReason(), exception.getArgs())).willReturn(message); // when listener.onAsyncPlayerPreLoginEventLowest(event); // then verify(validationService).isUnrestricted(name); verify(onJoinVerifier).checkIsValidName(name); // Check that we don't talk with the data source before performing checks that don't require it verifyNoInteractions(dataSource); verify(event).setKickMessage(message); verify(event).setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER); }
Example #3
Source File: PlayerListener.java From AuthMeReloaded with GNU General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.LOWEST) public void onAsyncPlayerPreLoginEventLowest(AsyncPlayerPreLoginEvent event) { if (event.getLoginResult() != AsyncPlayerPreLoginEvent.Result.ALLOWED) { return; } final String name = event.getName(); // NOTE: getAddress() sometimes returning null, we don't want to handle this race condition if (event.getAddress() == null) { event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, messages.retrieveSingle(name, MessageKey.KICK_UNRESOLVED_HOSTNAME)); return; } if (validationService.isUnrestricted(name)) { return; } // Non-blocking checks try { onJoinVerifier.checkIsValidName(name); } catch (FailedVerificationException e) { event.setKickMessage(messages.retrieveSingle(name, e.getReason(), e.getArgs())); event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER); } }
Example #4
Source File: PlayerListener.java From AuthMeReloaded with GNU General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void onAsyncPlayerPreLoginEventHighest(AsyncPlayerPreLoginEvent event) { if (event.getLoginResult() != AsyncPlayerPreLoginEvent.Result.ALLOWED) { return; } final String name = event.getName(); if (validationService.isUnrestricted(name)) { return; } // Slow, blocking checks try { final PlayerAuth auth = dataSource.getAuth(name); final boolean isAuthAvailable = auth != null; onJoinVerifier.checkKickNonRegistered(isAuthAvailable); onJoinVerifier.checkAntibot(name, isAuthAvailable); onJoinVerifier.checkNameCasing(name, auth); final String ip = event.getAddress().getHostAddress(); onJoinVerifier.checkPlayerCountry(name, ip, isAuthAvailable); } catch (FailedVerificationException e) { event.setKickMessage(messages.retrieveSingle(name, e.getReason(), e.getArgs())); event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER); } }
Example #5
Source File: PlayerListenerTest.java From AuthMeReloaded with GNU General Public License v3.0 | 6 votes |
@Test public void shouldPerformAllJoinVerificationsSuccessfullyPreLoginLowest() throws FailedVerificationException { // given String name = "someone"; UUID uniqueId = UUID.fromString("753493c9-33ba-4a4a-bf61-1bce9d3c9a71"); String ip = "12.34.56.78"; AsyncPlayerPreLoginEvent preLoginEvent = spy(new AsyncPlayerPreLoginEvent(name, mockAddrWithIp(ip), uniqueId)); given(validationService.isUnrestricted(name)).willReturn(false); // when listener.onAsyncPlayerPreLoginEventLowest(preLoginEvent); // then verify(validationService).isUnrestricted(name); verify(onJoinVerifier).checkIsValidName(name); verifyNoInteractions(dataSource); verifyNoModifyingCalls(preLoginEvent); }
Example #6
Source File: PlayerListenerTest.java From AuthMeReloaded with GNU General Public License v3.0 | 6 votes |
@Test public void shouldKickPreLoginLowestUnresolvedHostname() { // given String name = "someone"; UUID uniqueId = UUID.fromString("753493c9-33ba-4a4a-bf61-1bce9d3c9a71"); @SuppressWarnings("ConstantConditions") AsyncPlayerPreLoginEvent preLoginEvent = spy(new AsyncPlayerPreLoginEvent(name, null, uniqueId)); given(messages.retrieveSingle(name, MessageKey.KICK_UNRESOLVED_HOSTNAME)).willReturn("Unresolved hostname"); // when listener.onAsyncPlayerPreLoginEventLowest(preLoginEvent); // then verify(preLoginEvent).disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, "Unresolved hostname"); verifyNoMoreInteractions(onJoinVerifier); }
Example #7
Source File: RequireLinkModule.java From DiscordSRV with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void onEventHighest(AsyncPlayerPreLoginEvent event) { if (!event.getLoginResult().equals(AsyncPlayerPreLoginEvent.Result.ALLOWED)) { DiscordSRV.debug("PlayerLoginEvent event result for " + event.getName() + " = " + event.getLoginResult() + ", skipping"); return; } check(event.getClass().getSimpleName(), EventPriority.HIGHEST, event.getName(), event.getUniqueId(), event.getAddress().getHostAddress(), (result, message) -> event.disallow(AsyncPlayerPreLoginEvent.Result.valueOf(result), message)); }
Example #8
Source File: BukkitPlugin.java From ServerListPlus with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onPlayerLogin(AsyncPlayerPreLoginEvent event) { if (core == null) return; // Too early, we haven't finished initializing yet UUID uuid = null; try { uuid = event.getUniqueId(); } catch (NoSuchMethodError ignored) {} core.updateClient(event.getAddress(), uuid, event.getName()); }
Example #9
Source File: LoginListener.java From Bukkit-Connect with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.LOWEST) public void onAsyncPlayerPreLogin(AsyncPlayerPreLoginEvent event) { LoginPayload payload = payloadCache.getByName(event.getName()); if (payload == null) { event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, "LilyPad: Internal server error"); return; } }
Example #10
Source File: JoinQuitListener.java From BetonQuest with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void playerPreLogin(AsyncPlayerPreLoginEvent event) { // if player was kicked, don't load the data if (event.getLoginResult() != Result.ALLOWED) { return; } String playerID = event.getUniqueId().toString(); BetonQuest plugin = BetonQuest.getInstance(); plugin.putPlayerData(playerID, new PlayerData(playerID)); }
Example #11
Source File: LoginListener.java From ChangeSkin with MIT License | 5 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void onPreLogin(AsyncPlayerPreLoginEvent preLoginEvent) { if (preLoginEvent.getLoginResult() != Result.ALLOWED) { //in this event isCancelled option in the annotation doesn't work return; } UUID playerUuid = preLoginEvent.getUniqueId(); String playerName = preLoginEvent.getName(); UserPreference preferences = core.getStorage().getPreferences(playerUuid); if (preferences == null) { return; } plugin.startSession(playerUuid, preferences); Optional<SkinModel> optSkin = preferences.getTargetSkin(); if (optSkin.isPresent()) { SkinModel targetSkin = optSkin.get(); if (!preferences.isKeepSkin()) { targetSkin = core.checkAutoUpdate(targetSkin); } preferences.setTargetSkin(targetSkin); save(preferences); } else if (core.getConfig().getBoolean("restoreSkins")) { refetchSkin(playerName, preferences); } if (!preferences.getTargetSkin().isPresent()) { getRandomSkin().ifPresent(preferences::setTargetSkin); } }
Example #12
Source File: PlayerEvents.java From AntiVPN with MIT License | 5 votes |
public PlayerEvents(Plugin plugin) { events.add( BukkitEvents.subscribe(plugin, AsyncPlayerPreLoginEvent.class, EventPriority.HIGH) .handler(this::cachePlayer) ); events.add( BukkitEvents.subscribe(plugin, PlayerLoginEvent.class, EventPriority.LOWEST) .handler(this::checkPlayer) ); }
Example #13
Source File: ListenerLogin.java From CombatLogX with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority=EventPriority.NORMAL, ignoreCancelled=true) public void beforeLogin(AsyncPlayerPreLoginEvent e) { FileConfiguration config = this.expansion.getConfig("citizens-compatibility.yml"); if(!config.getBoolean("prevent-login", false)) return; UUID uuid = e.getUniqueId(); NPCManager npcManager = this.expansion.getNPCManager(); NPC npc = npcManager.getNPC(uuid); if(npc == null) return; String message = this.expansion.getPlugin().getLanguageMessageColored("citizens-join-deny"); e.setKickMessage(message); e.setLoginResult(Result.KICK_OTHER); }
Example #14
Source File: ConnectionEvent.java From MCAuthenticator with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.MONITOR) public void onConnect(AsyncPlayerPreLoginEvent e) { if (e.getLoginResult() != AsyncPlayerPreLoginEvent.Result.ALLOWED) return; try { UserData d = instance.getDataSource().getUser(e.getUniqueId()); if (d == null) return; userDataCache.put(e.getUniqueId(), d); } catch (IOException | SQLException e1) { instance.handleException(e1); } }
Example #15
Source File: RequireLinkModule.java From DiscordSRV with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.HIGH) public void onEventHigh(AsyncPlayerPreLoginEvent event) { if (!event.getLoginResult().equals(AsyncPlayerPreLoginEvent.Result.ALLOWED)) { DiscordSRV.debug("PlayerLoginEvent event result for " + event.getName() + " = " + event.getLoginResult() + ", skipping"); return; } check(event.getClass().getSimpleName(), EventPriority.HIGH, event.getName(), event.getUniqueId(), event.getAddress().getHostAddress(), (result, message) -> event.disallow(AsyncPlayerPreLoginEvent.Result.valueOf(result), message)); }
Example #16
Source File: RequireLinkModule.java From DiscordSRV with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.NORMAL) public void onEventNormal(AsyncPlayerPreLoginEvent event) { if (!event.getLoginResult().equals(AsyncPlayerPreLoginEvent.Result.ALLOWED)) { DiscordSRV.debug("PlayerLoginEvent event result for " + event.getName() + " = " + event.getLoginResult() + ", skipping"); return; } check(event.getClass().getSimpleName(), EventPriority.NORMAL, event.getName(), event.getUniqueId(), event.getAddress().getHostAddress(), (result, message) -> event.disallow(AsyncPlayerPreLoginEvent.Result.valueOf(result), message)); }
Example #17
Source File: RequireLinkModule.java From DiscordSRV with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.LOW) public void onEventLow(AsyncPlayerPreLoginEvent event) { if (!event.getLoginResult().equals(AsyncPlayerPreLoginEvent.Result.ALLOWED)) { DiscordSRV.debug("PlayerLoginEvent event result for " + event.getName() + " = " + event.getLoginResult() + ", skipping"); return; } check(event.getClass().getSimpleName(), EventPriority.LOW, event.getName(), event.getUniqueId(), event.getAddress().getHostAddress(), (result, message) -> event.disallow(AsyncPlayerPreLoginEvent.Result.valueOf(result), message)); }
Example #18
Source File: RequireLinkModule.java From DiscordSRV with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.LOWEST) public void onEventLowest(AsyncPlayerPreLoginEvent event) { if (!event.getLoginResult().equals(AsyncPlayerPreLoginEvent.Result.ALLOWED)) { DiscordSRV.debug("PlayerLoginEvent event result for " + event.getName() + " = " + event.getLoginResult() + ", skipping"); return; } check(event.getClass().getSimpleName(), EventPriority.LOWEST, event.getName(), event.getUniqueId(), event.getAddress().getHostAddress(), (result, message) -> event.disallow(AsyncPlayerPreLoginEvent.Result.valueOf(result), message)); }
Example #19
Source File: PlayerListenerTest.java From AuthMeReloaded with GNU General Public License v3.0 | 5 votes |
@Test public void shouldPerformAllJoinVerificationsSuccessfullyPreLoginHighest() throws FailedVerificationException { // given String name = "someone"; UUID uniqueId = UUID.fromString("753493c9-33ba-4a4a-bf61-1bce9d3c9a71"); String ip = "12.34.56.78"; AsyncPlayerPreLoginEvent preLoginEvent = spy(new AsyncPlayerPreLoginEvent(name, mockAddrWithIp(ip), uniqueId)); given(validationService.isUnrestricted(name)).willReturn(false); PlayerAuth auth = PlayerAuth.builder().name(name).build(); given(dataSource.getAuth(name)).willReturn(auth); // when listener.onAsyncPlayerPreLoginEventHighest(preLoginEvent); // then verify(validationService).isUnrestricted(name); verify(onJoinVerifier).checkKickNonRegistered(true); verify(onJoinVerifier).checkAntibot(name, true); verify(onJoinVerifier).checkNameCasing(name, auth); verify(onJoinVerifier).checkPlayerCountry(name, ip, true); verifyNoModifyingCalls(preLoginEvent); }
Example #20
Source File: UserListener.java From VoxelGamesLibv2 with MIT License | 5 votes |
@EventHandler public void onAsyncLogin(@Nonnull AsyncPlayerPreLoginEvent event) { if (!handler.login(event.getUniqueId())) { // something went horribly wrong // we don't have a locale here since the data was not loaded :/ event.disallow(Result.KICK_OTHER, Lang.legacyColors(Lang.string(LangKey.DATA_NOT_LOADED))); } }
Example #21
Source File: StartupListener.java From VoxelGamesLibv2 with MIT License | 5 votes |
@EventHandler(priority = EventPriority.LOWEST) public void onLogin(AsyncPlayerPreLoginEvent event) { if (!startupHandler.isReady()) { event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, "Server is starting, please gimme a second!"); } if (startupHandler.isInterrupted()) { event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, "Server start was interrupted, please try again later"); } }
Example #22
Source File: IdentityProviderImpl.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
/** * Clear any nickname that collides with the real name of a player logging in. * This ensures that usernames + nicknames together contain no duplicates. * The user who's nickname was cleared is not notified of this, but this * should be an extremely rare situation, so it's not a big problem. */ @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = false) public void clearConflictingNicks(AsyncPlayerPreLoginEvent event) { final String name = event.getName(); syncExecutor.execute(() -> { final Player player = nicknames.get(name); if(player != null) { changeIdentity(player, null); } }); }
Example #23
Source File: ThreadPlayerLookupUUID.java From Thermos with GNU General Public License v3.0 | 4 votes |
private void fireLoginEvents() throws Exception { // CraftBukkit start - fire PlayerPreLoginEvent if (!this.field_151292_a.field_147333_a.isChannelOpen()) { return; } String playerName = NetHandlerLoginServer.getGameProfile(this.field_151292_a).getName(); java.net.InetAddress address = ((java.net.InetSocketAddress) this.field_151292_a.field_147333_a.getSocketAddress()).getAddress(); java.util.UUID uniqueId = NetHandlerLoginServer.getGameProfile(this.field_151292_a).getId(); final org.bukkit.craftbukkit.CraftServer server = this.mcServer.server; AsyncPlayerPreLoginEvent asyncEvent = new AsyncPlayerPreLoginEvent(playerName, address, uniqueId); server.getPluginManager().callEvent(asyncEvent); if (PlayerPreLoginEvent.getHandlerList().getRegisteredListeners().length != 0) { final PlayerPreLoginEvent event = new PlayerPreLoginEvent(playerName, address, uniqueId); if (asyncEvent.getResult() != PlayerPreLoginEvent.Result.ALLOWED) { event.disallow(asyncEvent.getResult(), asyncEvent.getKickMessage()); } Waitable<PlayerPreLoginEvent.Result> waitable = new Waitable<PlayerPreLoginEvent.Result>() { @Override protected PlayerPreLoginEvent.Result evaluate() { server.getPluginManager().callEvent(event); return event.getResult(); } }; NetHandlerLoginServer.getMinecraftServer(this.field_151292_a).processQueue.add(waitable); if (waitable.get() != PlayerPreLoginEvent.Result.ALLOWED) { this.field_151292_a.func_147322_a(event.getKickMessage()); return; } } else { if (asyncEvent.getLoginResult() != AsyncPlayerPreLoginEvent.Result.ALLOWED) { this.field_151292_a.func_147322_a(asyncEvent.getKickMessage()); return; } } // CraftBukkit end NetHandlerLoginServer.getLogger().info("UUID of player " + NetHandlerLoginServer.getGameProfile(this.field_151292_a).getName() + " is " + NetHandlerLoginServer.getGameProfile(this.field_151292_a).getId());; NetHandlerLoginServer.setLoginState(this.field_151292_a, LoginState.READY_TO_ACCEPT); }
Example #24
Source File: PlayerListenerTest.java From AuthMeReloaded with GNU General Public License v3.0 | 4 votes |
private static void verifyNoModifyingCalls(AsyncPlayerPreLoginEvent event) { verify(event, atLeast(0)).getLoginResult(); verify(event, atLeast(0)).getAddress(); verify(event, atLeast(0)).getName(); verifyNoMoreInteractions(event); }
Example #25
Source File: BungeemodeListener.java From HeavySpleef with GNU General Public License v3.0 | 4 votes |
@EventHandler(priority = EventPriority.HIGH) public void onPlayerPreJoin(AsyncPlayerPreLoginEvent event) { BungeemodeConfig config = addon.getConfig(); if (!config.isEnabled()) { return; } if (!addon.getHeavySpleef().isGamesLoaded()) { event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER); event.setKickMessage(addon.getI18n().getString(BungeemodeMessages.KICK_MESSAGE_NOT_YET_READY)); return; } String gameName = config.getGame(); GameManager manager = addon.getHeavySpleef().getGameManager(); if (!manager.hasGame(gameName)) { addon.getLogger().log(Level.WARNING, "Cannot handle player pre login for '" + event.getName() + "': Game " + gameName + " does not exist!"); return; } Game game = manager.getGame(gameName); if (!game.getGameState().isGameEnabled()) { event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER); event.setKickMessage(addon.getI18n().getString(BungeemodeMessages.KICK_MESSAGE_DISABLED)); return; } boolean joinOnCountdown = game.getPropertyValue(GameProperty.JOIN_ON_COUNTDOWN); if (game.getGameState() == GameState.INGAME || ((game.getGameState() == GameState.STARTING || game.getGameState() == GameState.WARMUP) && !joinOnCountdown)) { if (config.getSpectateWhenIngame()) { if (game.isFlagPresent(FlagSpectate.class)) { return; } else { addon.getLogger().log(Level.WARNING, "Cannot transfer the player " + event.getName() + " into spectate mode: No spectate flag/point has been set"); } } event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER); event.setKickMessage(addon.getI18n().getString(BungeemodeMessages.KICK_MESSAGE_INGAME)); return; } }
Example #26
Source File: AbstractLoginListener.java From ProtocolSupport with GNU Affero General Public License v3.0 | 4 votes |
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(); }
Example #27
Source File: PlayerListener.java From civcraft with GNU General Public License v2.0 | 4 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void onPlayerPreLogin(AsyncPlayerPreLoginEvent event) { // THIS EVENT IS NOT RUN IN OFFLINE MODE }
Example #28
Source File: JoinQuitListener.java From SaneEconomy with GNU General Public License v3.0 | 4 votes |
@EventHandler public void onPlayerLogin(AsyncPlayerPreLoginEvent evt) { Bukkit.getServer().getScheduler().runTaskAsynchronously(this.plugin, () -> { this.plugin.getEconomyManager().getBackend().reloadEconomable(String.format("player:%s", evt.getUniqueId()), EconomyStorageBackend.EconomableReloadReason.PLAYER_JOIN); // TODO: If servers start to lag when lots of people join, this is why. }); }
Example #29
Source File: RequireLinkModule.java From DiscordSRV with GNU General Public License v3.0 | 4 votes |
private void check(String eventType, EventPriority priority, String playerName, UUID playerUuid, String ip, BiConsumer<String, String> disallow) { if (!isEnabled()) return; if (!eventType.equals(DiscordSRV.config().getString("Require linked account to play.Listener event"))) return; String requestedPriority = DiscordSRV.config().getString("Require linked account to play.Listener priority"); EventPriority targetPriority = Arrays.stream(EventPriority.values()) .filter(p -> p.name().equalsIgnoreCase(requestedPriority)) .findFirst().orElse(EventPriority.LOWEST); if (priority != targetPriority) return; try { if (getBypassNames().contains(playerName)) { DiscordSRV.debug("Player " + playerName + " is on the bypass list, bypassing linking checks"); return; } if (checkWhitelist()) { boolean whitelisted = Bukkit.getServer().getWhitelistedPlayers().stream().map(OfflinePlayer::getUniqueId).anyMatch(u -> u.equals(playerUuid)); if (whitelisted) { DiscordSRV.debug("Player " + playerName + " is bypassing link requirement, player is whitelisted"); return; } } if (Bukkit.getServer().getBannedPlayers().stream().anyMatch(p -> p.getUniqueId().equals(playerUuid))) { DiscordSRV.debug("Player " + playerName + " is banned, skipping linked check"); return; } if (Bukkit.getServer().getIPBans().stream().anyMatch(ip::equals)) { DiscordSRV.debug("Player " + playerName + " connecting with banned IP " + ip + ", skipping linked check"); return; } if (!DiscordSRV.isReady) { DiscordSRV.debug("Player " + playerName + " connecting before DiscordSRV is ready, denying login"); disallow.accept(AsyncPlayerPreLoginEvent.Result.KICK_OTHER.name(), ChatColor.translateAlternateColorCodes('&', getDiscordSRVStillStartingKickMessage())); return; } String discordId = DiscordSRV.getPlugin().getAccountLinkManager().getDiscordId(playerUuid); if (discordId == null) { Member botMember = DiscordSRV.getPlugin().getMainGuild().getSelfMember(); String botName = botMember.getEffectiveName() + "#" + botMember.getUser().getDiscriminator(); String code = DiscordSRV.getPlugin().getAccountLinkManager().generateCode(playerUuid); String inviteLink = DiscordSRV.config().getString("DiscordInviteLink"); DiscordSRV.debug("Player " + playerName + " is NOT linked to a Discord account, denying login"); disallow.accept( AsyncPlayerPreLoginEvent.Result.KICK_WHITELIST.name(), ChatColor.translateAlternateColorCodes('&', DiscordSRV.config().getString("Require linked account to play.Not linked message")) .replace("{BOT}", botName) .replace("{CODE}", code) .replace("{INVITE}", inviteLink) ); return; } List<String> subRoleIds = DiscordSRV.config().getStringList("Require linked account to play.Subscriber role.Subscriber roles"); if (isSubRoleRequired() && !subRoleIds.isEmpty()) { int failedRoleIds = 0; int matches = 0; for (String subRoleId : subRoleIds) { if (StringUtils.isBlank(subRoleId)) { failedRoleIds++; continue; } Role role = DiscordUtil.getJda().getRoleById(subRoleId); if (role == null) { failedRoleIds++; continue; } Member member = role.getGuild().getMemberById(discordId); if (member != null && member.getRoles().contains(role)) { matches++; } } if (failedRoleIds == subRoleIds.size()) { DiscordSRV.error("Tried to authenticate " + playerName + " but no valid subscriber role IDs are found and that's a requirement; login will be denied until this is fixed."); disallow.accept(AsyncPlayerPreLoginEvent.Result.KICK_OTHER.name(), ChatColor.translateAlternateColorCodes('&', getFailedToFindRoleKickMessage())); return; } if (getAllSubRolesRequired() ? matches < subRoleIds.size() : matches == 0) { DiscordSRV.debug("Player " + playerName + " does NOT match subscriber role requirements, denying login"); disallow.accept(AsyncPlayerPreLoginEvent.Result.KICK_WHITELIST.name(), ChatColor.translateAlternateColorCodes('&', getSubscriberRoleKickMessage())); } } } catch (Exception exception) { DiscordSRV.error("Failed to check player: " + playerName); exception.printStackTrace(); disallow.accept(AsyncPlayerPreLoginEvent.Result.KICK_OTHER.name(), ChatColor.translateAlternateColorCodes('&', getUnknownFailureKickMessage())); } }
Example #30
Source File: LoginListener.java From ProjectAres with GNU Affero General Public License v3.0 | 4 votes |
@EventHandler(priority = EventPriority.MONITOR) public void preLogin(final AsyncPlayerPreLoginEvent event) { this.logger.info(event.getName() + " pre-login: uuid=" + event.getUniqueId() + " ip=" + event.getAddress()); try(Locker _ = Locker.lock(connectedLock.readLock())) { this.logins.invalidate(event.getUniqueId()); if(!connected) { event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, SERVER_IS_RESTARTING); return; } LoginResponse response = this.userService.login( new LoginRequest(event.getName(), event.getUniqueId(), event.getAddress(), minecraftService.getLocalServer(), true) ).get(); if(response.kick() != null) switch(response.kick()) { case "error": this.logger.info(event.getName() + " login error: " + response.message()); event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, response.message()); break; case "banned": // Only used for IP bans right now this.logger.info(event.getName() + " is banned"); event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_BANNED, response.message()); break; } if(event.getLoginResult() != AsyncPlayerPreLoginEvent.Result.ALLOWED) return; this.logins.put(event.getUniqueId(), response); eventBus.callEvent(new AsyncUserLoginEvent(response)); } catch(Exception e) { this.logger.log(Level.SEVERE, e.toString(), e); event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, INTERNAL_SERVER_ERROR); } }