org.bukkit.event.player.PlayerLoginEvent Java Examples
The following examples show how to use
org.bukkit.event.player.PlayerLoginEvent.
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: TeamListener.java From ProjectAres with GNU Affero General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.LOWEST) public void onPlayerLogin(UserLoginEvent event) { TeamManager teamManager = teamManagerProvider.get(); Entrant participation = teamManager.getEntrant(event.getUser()); if(participation == null) return; final int playerCount = (int) onlinePlayers.all() .stream() .filter(player -> !player.equals(event.getPlayer()) && participation.members().contains(userStore.playerId(player))) .count(); int maxPlayers = tournament.max_players_per_match(); if(playerCount >= maxPlayers) { event.disallow(PlayerLoginEvent.Result.KICK_WHITELIST, new Component(new TranslatableComponent("tourney.kick.maxPlayers", String.valueOf(maxPlayers)), ChatColor.RED)); } else { if(event.getResult().equals(PlayerLoginEvent.Result.KICK_WHITELIST)) { event.allow(); // explicitly allow players on teams but not whitelist } } }
Example #2
Source File: SkinApplyListener.java From FastLogin with MIT License | 6 votes |
@EventHandler(priority = EventPriority.LOW) //run this on the loginEvent to let skins plugins see the skin like in normal Minecraft behaviour public void onPlayerLogin(PlayerLoginEvent loginEvent) { if (loginEvent.getResult() != Result.ALLOWED) { return; } Player player = loginEvent.getPlayer(); if (plugin.getConfig().getBoolean("forwardSkin")) { //go through every session, because player.getAddress is null //loginEvent.getAddress is just a InetAddress not InetSocketAddress, so not unique enough for (BukkitLoginSession session : plugin.getLoginSessions().values()) { if (session.getUsername().equals(player.getName())) { session.getSkin().ifPresent(skin -> applySkin(player, skin.getValue(), skin.getSignature())); break; } } } }
Example #3
Source File: PlayerConnectionListener.java From UhcCore with GNU General Public License v3.0 | 6 votes |
@EventHandler(priority=EventPriority.HIGHEST) public void onPlayerLogin(PlayerLoginEvent event){ GameManager gm = GameManager.getGameManager(); // Player is not allowed to join so don't create UhcPlayer. (Server full, whitelist, ban, ...) if (event.getResult() != Result.ALLOWED){ return; } try{ boolean allowedToJoin = gm.getPlayersManager().isPlayerAllowedToJoin(event.getPlayer()); if (allowedToJoin){ // Create player if not existent. gm.getPlayersManager().getOrCreateUhcPlayer(event.getPlayer()); }else{ throw new UhcPlayerJoinException("An unexpected error as occured."); } }catch(final UhcPlayerJoinException e){ event.setKickMessage(e.getMessage()); event.setResult(Result.KICK_OTHER); } }
Example #4
Source File: LoginListener.java From ChangeSkin with MIT License | 6 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void onPlayerLogin(PlayerLoginEvent loginEvent) { if (loginEvent.getResult() != PlayerLoginEvent.Result.ALLOWED) { //in this event isCancelled option in the annotation doesn't work return; } Player player = loginEvent.getPlayer(); //updates to the chosen one UserPreference preferences = plugin.getLoginSession(player.getUniqueId()); if (preferences != null) { preferences.getTargetSkin().ifPresent(skin -> plugin.getApi().applySkin(player, skin)); } plugin.endSession(player.getUniqueId()); }
Example #5
Source File: EffCancelEvent.java From Skript with GNU General Public License v3.0 | 6 votes |
@SuppressWarnings("null") @Override public boolean init(final Expression<?>[] vars, final int matchedPattern, final Kleenean isDelayed, final ParseResult parser) { if (isDelayed == Kleenean.TRUE) { Skript.error("Can't cancel an event anymore after it has already passed", ErrorQuality.SEMANTIC_ERROR); return false; } cancel = matchedPattern == 0; final Class<? extends Event>[] es = ScriptLoader.getCurrentEvents(); if (es == null) return false; for (final Class<? extends Event> e : es) { if (Cancellable.class.isAssignableFrom(e) || BlockCanBuildEvent.class.isAssignableFrom(e)) return true; // TODO warning if some event(s) cannot be cancelled even though some can (needs a way to be suppressed) } if (ScriptLoader.isCurrentEvent(PlayerLoginEvent.class)) Skript.error("A connect event cannot be cancelled, but the player may be kicked ('kick player by reason of \"...\"')", ErrorQuality.SEMANTIC_ERROR); else Skript.error(Utils.A(ScriptLoader.getCurrentEventName()) + " event cannot be cancelled", ErrorQuality.SEMANTIC_ERROR); return false; }
Example #6
Source File: PlayerListener.java From AuthMeReloaded with GNU General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.LOW) public void onPlayerLogin(PlayerLoginEvent event) { final Player player = event.getPlayer(); final String name = player.getName(); try { onJoinVerifier.checkSingleSession(name); } catch (FailedVerificationException e) { event.setKickMessage(messages.retrieveSingle(name, e.getReason(), e.getArgs())); event.setResult(PlayerLoginEvent.Result.KICK_OTHER); return; } if (validationService.isUnrestricted(name)) { return; } onJoinVerifier.refusePlayerForFullServer(event); }
Example #7
Source File: PlayerListenerTest.java From AuthMeReloaded with GNU General Public License v3.0 | 6 votes |
@Test public void shouldNotInterfereWithUnrestrictedUser() throws FailedVerificationException { // given String name = "Player01"; Player player = mockPlayerWithName(name); PlayerLoginEvent event = spy(new PlayerLoginEvent(player, "", null)); given(validationService.isUnrestricted(name)).willReturn(true); // when listener.onPlayerLogin(event); // then verify(validationService).isUnrestricted(name); verify(onJoinVerifier).checkSingleSession(name); verifyNoModifyingCalls(event); verifyNoMoreInteractions(onJoinVerifier); }
Example #8
Source File: PlayerListenerTest.java From AuthMeReloaded with GNU General Public License v3.0 | 6 votes |
@Test public void shouldStopHandlingForFullServer() throws FailedVerificationException { // given String name = "someone"; Player player = mockPlayerWithName(name); PlayerLoginEvent event = spy(new PlayerLoginEvent(player, "", null)); given(validationService.isUnrestricted(name)).willReturn(false); given(onJoinVerifier.refusePlayerForFullServer(event)).willReturn(true); // when listener.onPlayerLogin(event); // then verify(validationService).isUnrestricted(name); verify(onJoinVerifier).checkSingleSession(name); verify(onJoinVerifier).refusePlayerForFullServer(event); verifyNoMoreInteractions(onJoinVerifier); verifyNoModifyingCalls(event); }
Example #9
Source File: PlayerEvents.java From AntiVPN with MIT License | 6 votes |
private void tryKickPlayer(String message, Player player, PlayerLoginEvent event) { Optional<PlaceholderAPIHook> placeholderapi; try { placeholderapi = ServiceLocator.getOptional(PlaceholderAPIHook.class); } catch (InstantiationException | IllegalAccessException ex) { logger.error(ex.getMessage(), ex); placeholderapi = Optional.empty(); } event.setResult(PlayerLoginEvent.Result.KICK_OTHER); if (placeholderapi.isPresent()) { event.setKickMessage(placeholderapi.get().withPlaceholders(player, message)); } else { event.setKickMessage(message); } }
Example #10
Source File: PlayerListenerTest.java From AuthMeReloaded with GNU General Public License v3.0 | 6 votes |
@Test public void shouldStopHandlingEventForBadResult() throws FailedVerificationException { // given String name = "someone"; Player player = mockPlayerWithName(name); PlayerLoginEvent event = new PlayerLoginEvent(player, "", null); event.setResult(PlayerLoginEvent.Result.KICK_BANNED); event = spy(event); given(validationService.isUnrestricted(name)).willReturn(false); given(onJoinVerifier.refusePlayerForFullServer(event)).willReturn(false); // when listener.onPlayerLogin(event); // then verify(validationService).isUnrestricted(name); verify(onJoinVerifier).checkSingleSession(name); verify(onJoinVerifier).refusePlayerForFullServer(event); verifyNoModifyingCalls(event); }
Example #11
Source File: PlayerListenerTest.java From AuthMeReloaded with GNU General Public License v3.0 | 6 votes |
@Test public void shouldPerformAllJoinVerificationsSuccessfullyLogin() { // given String name = "someone"; Player player = mockPlayerWithName(name); String ip = "12.34.56.78"; PlayerLoginEvent loginEvent = spy(new PlayerLoginEvent(player, "", mockAddrWithIp(ip))); given(validationService.isUnrestricted(name)).willReturn(false); given(onJoinVerifier.refusePlayerForFullServer(loginEvent)).willReturn(false); // when listener.onPlayerLogin(loginEvent); // then verify(validationService).isUnrestricted(name); verify(onJoinVerifier).refusePlayerForFullServer(loginEvent); verifyNoInteractions(dataSource); verifyNoModifyingCalls(loginEvent); }
Example #12
Source File: OnJoinVerifierTest.java From AuthMeReloaded with GNU General Public License v3.0 | 6 votes |
@Test public void shouldRefuseNonVipPlayerForFullServer() { // given Player player = mock(Player.class); PlayerLoginEvent event = new PlayerLoginEvent(player, "hostname", null); event.setResult(PlayerLoginEvent.Result.KICK_FULL); given(permissionsManager.hasPermission(player, PlayerStatePermission.IS_VIP)).willReturn(false); String serverFullMessage = "server is full"; given(messages.retrieveSingle(player, MessageKey.KICK_FULL_SERVER)).willReturn(serverFullMessage); // when boolean result = onJoinVerifier.refusePlayerForFullServer(event); // then assertThat(result, equalTo(true)); assertThat(event.getResult(), equalTo(PlayerLoginEvent.Result.KICK_FULL)); assertThat(event.getKickMessage(), equalTo(serverFullMessage)); verifyNoInteractions(bukkitService, dataSource); }
Example #13
Source File: OnJoinVerifierTest.java From AuthMeReloaded with GNU General Public License v3.0 | 6 votes |
@Test public void shouldKickNonVipForJoiningVipPlayer() { // given Player player = mock(Player.class); PlayerLoginEvent event = new PlayerLoginEvent(player, "hostname", null); event.setResult(PlayerLoginEvent.Result.KICK_FULL); given(permissionsManager.hasPermission(player, PlayerStatePermission.IS_VIP)).willReturn(true); List<Player> onlinePlayers = Arrays.asList(mock(Player.class), mock(Player.class)); given(permissionsManager.hasPermission(onlinePlayers.get(0), PlayerStatePermission.IS_VIP)).willReturn(true); given(permissionsManager.hasPermission(onlinePlayers.get(1), PlayerStatePermission.IS_VIP)).willReturn(false); given(bukkitService.getOnlinePlayers()).willReturn(onlinePlayers); given(server.getMaxPlayers()).willReturn(onlinePlayers.size()); given(messages.retrieveSingle(player, MessageKey.KICK_FOR_VIP)).willReturn("kick for vip"); // when boolean result = onJoinVerifier.refusePlayerForFullServer(event); // then assertThat(result, equalTo(false)); assertThat(event.getResult(), equalTo(PlayerLoginEvent.Result.ALLOWED)); // First player is VIP, so expect no interactions there and second player to have been kicked verifyNoInteractions(onlinePlayers.get(0)); verify(onlinePlayers.get(1)).kickPlayer("kick for vip"); }
Example #14
Source File: OnJoinVerifierTest.java From AuthMeReloaded with GNU General Public License v3.0 | 6 votes |
@Test public void shouldKickVipPlayerIfNoPlayerCanBeKicked() { // given Player player = mock(Player.class); PlayerLoginEvent event = new PlayerLoginEvent(player, "hostname", null); event.setResult(PlayerLoginEvent.Result.KICK_FULL); given(permissionsManager.hasPermission(player, PlayerStatePermission.IS_VIP)).willReturn(true); List<Player> onlinePlayers = Collections.singletonList(mock(Player.class)); given(permissionsManager.hasPermission(onlinePlayers.get(0), PlayerStatePermission.IS_VIP)).willReturn(true); given(bukkitService.getOnlinePlayers()).willReturn(onlinePlayers); given(server.getMaxPlayers()).willReturn(onlinePlayers.size()); given(messages.retrieveSingle(player, MessageKey.KICK_FULL_SERVER)).willReturn("kick full server"); // when boolean result = onJoinVerifier.refusePlayerForFullServer(event); // then assertThat(result, equalTo(true)); assertThat(event.getResult(), equalTo(PlayerLoginEvent.Result.KICK_FULL)); assertThat(event.getKickMessage(), equalTo("kick full server")); verifyNoInteractions(onlinePlayers.get(0)); }
Example #15
Source File: MaxHealthBoost.java From EliteMobs with GNU General Public License v3.0 | 5 votes |
@EventHandler public void playerLogin(PlayerLoginEvent event) { new BukkitRunnable() { @Override public void run() { if (!PlayerData.playerMaxGuildRank.containsKey(event.getPlayer().getUniqueId())) return; if (PlayerData.playerMaxGuildRank.get(event.getPlayer().getUniqueId()) < 11) return; event.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue((PlayerData.playerMaxGuildRank.get(event.getPlayer().getUniqueId()) - 10) * 2 + 20); } }.runTaskLater(MetadataHandler.PLUGIN, 5); }
Example #16
Source File: PlayerOnlineListener.java From Plan with GNU Lesser General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.MONITOR) public void onPlayerLogin(PlayerLoginEvent event) { try { PlayerLoginEvent.Result result = event.getResult(); UUID playerUUID = event.getPlayer().getUniqueId(); boolean operator = event.getPlayer().isOp(); boolean banned = result == PlayerLoginEvent.Result.KICK_BANNED; dbSystem.getDatabase().executeTransaction(new BanStatusTransaction(playerUUID, () -> banned)); dbSystem.getDatabase().executeTransaction(new OperatorStatusTransaction(playerUUID, operator)); } catch (Exception e) { errorLogger.log(L.ERROR, e, ErrorContext.builder().related(event, event.getResult()).build()); } }
Example #17
Source File: RequireLinkModule.java From DiscordSRV with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.LOW) public void onEventLow(PlayerLoginEvent event) { if (!event.getResult().equals(PlayerLoginEvent.Result.ALLOWED)) { DiscordSRV.debug("PlayerLoginEvent event result for " + event.getPlayer().getName() + " = " + event.getResult() + ", skipping"); return; } check(event.getClass().getSimpleName(), EventPriority.LOW, event.getPlayer().getName(), event.getPlayer().getUniqueId(), event.getAddress().getHostAddress(), (result, message) -> event.disallow(PlayerLoginEvent.Result.valueOf(result), message)); }
Example #18
Source File: RequireLinkModule.java From DiscordSRV with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.NORMAL) public void onEventNormal(PlayerLoginEvent event) { if (!event.getResult().equals(PlayerLoginEvent.Result.ALLOWED)) { DiscordSRV.debug("PlayerLoginEvent event result for " + event.getPlayer().getName() + " = " + event.getResult() + ", skipping"); return; } check(event.getClass().getSimpleName(), EventPriority.NORMAL, event.getPlayer().getName(), event.getPlayer().getUniqueId(), event.getAddress().getHostAddress(), (result, message) -> event.disallow(PlayerLoginEvent.Result.valueOf(result), message)); }
Example #19
Source File: RequireLinkModule.java From DiscordSRV with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.LOWEST) public void onEventLowest(PlayerLoginEvent event) { if (!event.getResult().equals(PlayerLoginEvent.Result.ALLOWED)) { DiscordSRV.debug("PlayerLoginEvent event result for " + event.getPlayer().getName() + " = " + event.getResult() + ", skipping"); return; } check(event.getClass().getSimpleName(), EventPriority.LOWEST, event.getPlayer().getName(), event.getPlayer().getUniqueId(), event.getAddress().getHostAddress(), (result, message) -> event.disallow(PlayerLoginEvent.Result.valueOf(result), message)); }
Example #20
Source File: RequireLinkModule.java From DiscordSRV with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.HIGH) public void onEventHigh(PlayerLoginEvent event) { if (!event.getResult().equals(PlayerLoginEvent.Result.ALLOWED)) { DiscordSRV.debug("PlayerLoginEvent event result for " + event.getPlayer().getName() + " = " + event.getResult() + ", skipping"); return; } check(event.getClass().getSimpleName(), EventPriority.HIGH, event.getPlayer().getName(), event.getPlayer().getUniqueId(), event.getAddress().getHostAddress(), (result, message) -> event.disallow(PlayerLoginEvent.Result.valueOf(result), message)); }
Example #21
Source File: RequireLinkModule.java From DiscordSRV with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void onEventHighest(PlayerLoginEvent event) { if (!event.getResult().equals(PlayerLoginEvent.Result.ALLOWED)) { DiscordSRV.debug("PlayerLoginEvent event result for " + event.getPlayer().getName() + " = " + event.getResult() + ", skipping"); return; } check(event.getClass().getSimpleName(), EventPriority.HIGHEST, event.getPlayer().getName(), event.getPlayer().getUniqueId(), event.getAddress().getHostAddress(), (result, message) -> event.disallow(PlayerLoginEvent.Result.valueOf(result), message)); }
Example #22
Source File: ConnectionListener.java From FastLogin with MIT License | 5 votes |
@EventHandler(priority = EventPriority.LOWEST) public void onPlayerLogin(PlayerLoginEvent loginEvent) { removeBlacklistStatus(loginEvent.getPlayer()); if (loginEvent.getResult() == Result.ALLOWED && !plugin.isServerFullyStarted()) { loginEvent.disallow(Result.KICK_OTHER, plugin.getCore().getMessage("not-started")); } }
Example #23
Source File: PlayerListener.java From civcraft with GNU General Public License v2.0 | 5 votes |
@EventHandler(priority = EventPriority.MONITOR) public void onPlayerLogin(PlayerLoginEvent event) { CivLog.info("Scheduling on player login task for player:"+event.getPlayer().getName()); TaskMaster.asyncTask("onPlayerLogin-"+event.getPlayer().getName(), new PlayerLoginAsyncTask(event.getPlayer().getUniqueId()), 0); CivGlobal.playerFirstLoginMap.put(event.getPlayer().getName(), new Date()); PlayerLocationCacheUpdate.playerQueue.add(event.getPlayer().getName()); MobSpawnerTimer.playerQueue.add((event.getPlayer().getName())); }
Example #24
Source File: PvPLogger.java From civcraft with GNU General Public License v2.0 | 5 votes |
@EventHandler(priority = EventPriority.LOWEST) public void onPlayerLogin(PlayerLoginEvent event) { ZombiePlayer zombiePlayer = zombiePlayers.get(event.getPlayer().getName()); if (zombiePlayer == null) { return; } //CivGlobal.entityManager.removeEntity(zombiePlayer.id, true); MobLib.removeEntity(zombiePlayer.id); zombiePlayers.remove(event.getPlayer().getName()); }
Example #25
Source File: PlayerLogin.java From FunnyGuilds with Apache License 2.0 | 5 votes |
@EventHandler public void onLogin(PlayerLoginEvent event) { if (Bukkit.hasWhitelist()) { return; } String name = event.getPlayer().getName(); if (name.length() < 2) { event.disallow(Result.KICK_OTHER, ChatUtils.colored("&cNick jest za krotki!")); } if (name.length() > 16) { event.disallow(Result.KICK_OTHER, ChatUtils.colored("&cNick jest za dlugi!")); } if (!name.matches(GuildRegex.LETTERS_DIGITS_UNDERSCORE.getPattern())) { event.disallow(Result.KICK_OTHER, ChatUtils.colored("&cNick zawiera niedozwolone znaki!")); } User user = User.get(event.getPlayer()); if (user == null) { return; } BanUtils.checkIfBanShouldExpire(user); if (!user.isBanned()) { return; } event.disallow(Result.KICK_BANNED, BanUtils.getBanMessage(user)); }
Example #26
Source File: ObserverModule.java From CardinalPGM with MIT License | 5 votes |
@EventHandler public void onPlayerConnect(PlayerLoginEvent event) { if (Bukkit.getBanList(BanList.Type.NAME).isBanned(event.getPlayer().getName())) { event.disallow(PlayerLoginEvent.Result.KICK_BANNED, Bukkit.getBanList(BanList.Type.NAME).getBanEntry(event.getPlayer().getName()).getReason()); } else if (Rank.whitelistBypass(event.getPlayer().getUniqueId())) { event.allow(); } }
Example #27
Source File: UHPluginListener.java From KTP with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onPlayerLogin(PlayerLoginEvent ev) { if (this.p.isPlayerDead(ev.getPlayer().getName()) && !this.p.getConfig().getBoolean("allow-reconnect", true)) { ev.setResult(Result.KICK_OTHER); ev.setKickMessage("Vous ĂȘtes mort !"); } }
Example #28
Source File: BukkitPlugin.java From ServerListPlus with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onPlayerLogin(PlayerLoginEvent event) { if (core == null) return; // Too early, we haven't finished initializing yet UUID uuid = null; try { uuid = event.getPlayer().getUniqueId(); } catch (NoSuchMethodError ignored) {} core.updateClient(event.getAddress(), uuid, event.getPlayer().getName()); }
Example #29
Source File: OnJoinVerifier.java From AuthMeReloaded with GNU General Public License v3.0 | 5 votes |
/** * Handles the case of a full server and verifies if the user's connection should really be refused * by adjusting the event object accordingly. Attempts to kick a non-VIP player to make room if the * joining player is a VIP. * * @param event the login event to verify * * @return true if the player's connection should be refused (i.e. the event does not need to be processed * further), false if the player is not refused */ public boolean refusePlayerForFullServer(PlayerLoginEvent event) { final Player player = event.getPlayer(); if (event.getResult() != PlayerLoginEvent.Result.KICK_FULL) { // Server is not full, no need to do anything return false; } else if (!permissionsManager.hasPermission(player, PlayerStatePermission.IS_VIP)) { // Server is full and player is NOT VIP; set kick message and proceed with kick event.setKickMessage(messages.retrieveSingle(player, MessageKey.KICK_FULL_SERVER)); return true; } // Server is full and player is VIP; attempt to kick a non-VIP player to make room Collection<Player> onlinePlayers = bukkitService.getOnlinePlayers(); if (onlinePlayers.size() < server.getMaxPlayers()) { event.allow(); return false; } Player nonVipPlayer = generateKickPlayer(onlinePlayers); if (nonVipPlayer != null) { nonVipPlayer.kickPlayer(messages.retrieveSingle(player, MessageKey.KICK_FOR_VIP)); event.allow(); return false; } else { logger.info("VIP player " + player.getName() + " tried to join, but the server was full"); event.setKickMessage(messages.retrieveSingle(player, MessageKey.KICK_FULL_SERVER)); return true; } }
Example #30
Source File: OnJoinVerifierTest.java From AuthMeReloaded with GNU General Public License v3.0 | 5 votes |
@Test public void shouldNotDoAnythingForNormalEvent() { // given PlayerLoginEvent event = mock(PlayerLoginEvent.class); given(event.getResult()).willReturn(PlayerLoginEvent.Result.ALLOWED); // when boolean result = onJoinVerifier.refusePlayerForFullServer(event); // then assertThat(result, equalTo(false)); verify(event).getResult(); verifyNoMoreInteractions(event); verifyNoInteractions(bukkitService, dataSource, permissionsManager); }