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

The following examples show how to use org.bukkit.event.player.PlayerLoginEvent#setKickMessage() . 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: PlayerEvents.java    From AntiVPN with MIT License 6 votes vote down vote up
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 2
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 3
Source File: PlayerListener.java    From AuthMeReloaded with GNU General Public License v3.0 6 votes vote down vote up
@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 4
Source File: ModerationCommand.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onPreLogin(PlayerLoginEvent event) {
  // Format kick screen for banned players
  if (event.getResult().equals(Result.KICK_BANNED)) {
    String formatted =
        getPunishmentScreenFromName(event.getPlayer(), event.getPlayer().getName());
    if (formatted != null) {
      event.setKickMessage(formatted);
    }
  }
}
 
Example 5
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 6
Source File: NPCMain.java    From AnnihilationPro with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOW)
public void onLogin(PlayerLoginEvent event)
{
    if(isTagged(event.getPlayer().getUniqueId()))
    {
        Boolean b = taggedPlayers.get(event.getPlayer().getUniqueId()).wasKilled();
        if(b == null)
        {
            event.setResult(Result.KICK_OTHER);
            event.setKickMessage(Lang.NPCALIVE.toString());
        }
    }
}
 
Example 7
Source File: UHPluginListener.java    From KTP with GNU General Public License v3.0 5 votes vote down vote up
@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 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: PlayerLoginListener.java    From ExploitFixer with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerLogin(final PlayerLoginEvent event) {
	final Player player = event.getPlayer();
	final InetAddress address = event.getAddress();
	final String locale = VersionUtil.getLocale(player);

	if (connectionModule.isNullAddressEnabled() && address == null) {
		final String nullAddressKickMessage = messagesModule.getKickMessage("nulladdress", locale);

		event.setKickMessage(nullAddressKickMessage);
		event.setResult(PlayerLoginEvent.Result.KICK_OTHER);
	} else {
		final UUID uuid = player.getUniqueId();
		final String playerName = player.getName();
		final ExploitPlayer exploitPlayer = exploitPlayerManager.get(player);

		if (connectionModule.isUUIDSpoofEnabled()) {
			final BukkitScheduler scheduler = plugin.getServer().getScheduler();

			scheduler.runTaskAsynchronously(plugin, () -> {
				final String originalUUID = uuid.toString().replace("-", "");
				final String offlineUUID = UUID.nameUUIDFromBytes(("OfflinePlayer:" + playerName).getBytes())
						.toString().replace("-", "");

				if (!originalUUID.contains(offlineUUID)) {
					final String onlineUUID = exploitPlayer.getOnlineUUID();

					if (onlineUUID == null || !onlineUUID.contains(originalUUID)) {
						final HamsterPlayer hamsterPlayer = HamsterAPI.getInstance().getHamsterPlayerManager()
								.get(player);
						final String uuidSpoofKickMessage = messagesModule.getKickMessage("uuidspoof", locale);

						event.setKickMessage(uuidSpoofKickMessage);
						event.setResult(PlayerLoginEvent.Result.KICK_OTHER);
						hamsterPlayer.disconnect(uuidSpoofKickMessage);
						hamsterPlayer.closeChannel();
					}
				}

				exploitPlayer.setLogged(true);
			});
		} else {
			exploitPlayer.setLogged(true);
		}
	}

	if (player.hasPermission("exploitfixer.notifications")) {
		notificationsModule.setNotifications(player, true);
	}
}
 
Example 10
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);
    }
}