Java Code Examples for org.bukkit.event.player.PlayerLoginEvent#getResult()

The following examples show how to use org.bukkit.event.player.PlayerLoginEvent#getResult() . 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: PlayerConnectionListener.java    From UhcCore with GNU General Public License v3.0 6 votes vote down vote up
@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 2
Source File: SkinApplyListener.java    From FastLogin with MIT License 6 votes vote down vote up
@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: LoginListener.java    From ChangeSkin with MIT License 6 votes vote down vote up
@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 4
Source File: PGMListener.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onPlayerLogin(final PlayerLoginEvent event) {
  // allow premiums to join when the server is full
  if (event.getResult() == Result.KICK_FULL) {
    if (event.getPlayer().hasPermission(Permissions.JOIN_FULL)) {
      event.allow();
    } else {
      event.setKickMessage(TextTranslations.translate("misc.serverFull", event.getPlayer()));
    }
  }
}
 
Example 5
Source File: PlayerOnlineListener.java    From Plan with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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 6
Source File: BukkitConnectionListener.java    From LuckPerms with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerLoginMonitor(PlayerLoginEvent e) {
    /* Listen to see if the event was cancelled after we initially handled the login
       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. Even if it was denied at LOW, their data will still be present.
    if (this.deniedLogin.remove(e.getPlayer().getUniqueId())) {
        // This is a problem, as they were denied at low priority, but are now being allowed.
        if (e.getResult() == PlayerLoginEvent.Result.ALLOWED) {
            this.plugin.getLogger().severe("Player connection was re-allowed for " + e.getPlayer().getUniqueId());
            e.disallow(PlayerLoginEvent.Result.KICK_OTHER, "");
        }
    }
}
 
Example 7
Source File: ConnectionListener.java    From FastLogin with MIT License 5 votes vote down vote up
@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 8
Source File: OnJoinVerifier.java    From AuthMeReloaded with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 9
Source File: LoginListener.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void login(PlayerLoginEvent event) {
    try {
        final Player player = event.getPlayer();
        final UUID uuid = player.getUniqueId();

        this.logins.cleanUp();
        final LoginResponse response = this.logins.getIfPresent(uuid);
        this.logins.invalidate(uuid);

        if(response == null) {
            this.logger.warning("No login info for " + player.getName() + " " + uuid);
            event.disallow(PlayerLoginEvent.Result.KICK_OTHER, INTERNAL_SERVER_ERROR);
            return;
        }

        // TODO: Consider creating a PreUserLoginEvent that can be cancelled,
        // before things like sessions are started.

        userStore.addUser(player, response.user());

        applyPermissions(player, response.user());

        if(response.punishment() != null) {
            rejectLogin(event, punishmentFormatter.screen(response.punishment()));
        }

        if(!player.hasPermission(Permissions.LOGIN)) {
            rejectLogin(event, new TranslatableComponent("servers.notAllowed"));
        }

        if(event.getResult() == PlayerLoginEvent.Result.KICK_FULL) {
            // Allow privileged players to join when the server is full
            if(player.hasPermission("pgm.fullserver")) {
                event.allow();
            } else {
                rejectLogin(event, new TranslatableComponent("serverFull"));
            }
        }

        if(response.user().mc_locale() != null) {
            // If we have a saved locale for the player, apply it.
            // This should ensure that text displayed on join is properly
            // localized, as long as the player has connected once before.
            player.setLocale(response.user().mc_locale());
        }

        userService.update(response.user(), new UserDoc.ClientDetails() {
            @Override public String mc_client_version() {
                return MinecraftVersion.describeProtocol(player.getProtocolVersion());
            }

            @Override public String skin_blob() {
                return player.getSkin().getData();
            }
        });

        if(event.getResult() == PlayerLoginEvent.Result.KICK_OTHER) return;

        final UserLoginEvent ourEvent = new UserLoginEvent(
            player, response, event.getResult(),
            event.getKickMessage() == null || "".equals(event.getKickMessage()) ? null : new Component(event.getKickMessage())
        );

        eventBus.callEvent(ourEvent);

        event.setResult(ourEvent.getResult());
        event.setKickMessage(ourEvent.getKickMessage() == null ? "" : renderer.renderLegacy(ourEvent.getKickMessage(), player));
    }
    catch(Exception e) {
        this.logger.log(Level.SEVERE, e.toString(), e);
        event.disallow(PlayerLoginEvent.Result.KICK_OTHER, INTERNAL_SERVER_ERROR);
    }
}
 
Example 10
Source File: LoginListener.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
protected void rejectLogin(PlayerLoginEvent event, BaseComponent message) {
    if(event.getResult() != PlayerLoginEvent.Result.KICK_OTHER) {
        event.disallow(PlayerLoginEvent.Result.KICK_OTHER, renderer.renderLegacy(message, event.getPlayer()));
    }
}
 
Example 11
Source File: AbstractLoginListenerPlay.java    From ProtocolSupport with GNU Affero General Public License v3.0 4 votes vote down vote up
protected void joinWorld() {
	if (!ServerPlatform.get().getMiscUtils().isRunning()) {
		disconnect(org.spigotmc.SpigotConfig.restartMessage);
		return;
	}

	UUID uuid = connection.getProfile().getUUID();
	for (Player player : new ArrayList<>(Bukkit.getOnlinePlayers())) {
		if (player.getUniqueId().equals(uuid)) {
			player.kickPlayer("You logged in from another location");
		}
	}

	JoinData joindata = createJoinData();

	connection.setWrappedProfile(joindata.player);

	PlayerSyncLoginEvent syncloginevent = new PlayerSyncLoginEvent(connection, joindata.player);
	Bukkit.getPluginManager().callEvent(syncloginevent);
	if (syncloginevent.isLoginDenied()) {
		disconnect(syncloginevent.getDenyLoginMessage());
		joindata.close();
		return;
	}

	PlayerLoginEvent bukkitevent = new PlayerLoginEvent(
		joindata.player,
		connection.getVirtualHost().toString(),
		networkManager.getAddress().getAddress(),
		networkManager.getRawAddress().getAddress()
	);
	checkBans(bukkitevent, joindata.data);
	Bukkit.getPluginManager().callEvent(bukkitevent);
	if (bukkitevent.getResult() != PlayerLoginEvent.Result.ALLOWED) {
		disconnect(bukkitevent.getKickMessage());
		joindata.close();
		return;
	}

	networkManager.sendPacket(ServerPlatform.get().getPacketFactory().createEmptyCustomPayloadPacket("finishlogin"));

	joinGame(joindata.data);
}