Java Code Examples for org.bukkit.event.player.AsyncPlayerPreLoginEvent.Result

The following are top voted examples for showing how to use org.bukkit.event.player.AsyncPlayerPreLoginEvent.Result. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: SamaGamesCore   File: JoinManagerImplement.java   View source code 5 votes vote down vote up
public void onLogin(AsyncPlayerPreLoginEvent event)
{
    UUID player = event.getUniqueId();

    if (moderatorsExpected.contains(player)) // On traite après
        return;

    if(!playersExpected.contains(player))
    {
        JoinResponse response = requestJoin(event.getUniqueId(), true);
        if (!response.isAllowed())
        {
            event.disallow(Result.KICK_OTHER, ChatColor.RED + response.getReason());
            return;
        }
    }

    playersExpected.remove(player);

    for (IJoinHandler handler : this.joiners.values())
        handler.onLogin(player, event.getName());
}
 
Example 2
Project: ExilePearl   File: TestBukkit.java   View source code 5 votes vote down vote up
/**
 * Creates a new player instance and adds it to the server
 * @param name The player name
 * @param uid The player UUID
 * @return The player instance
 */
public static TestPlayer createOnlinePlayer(String name, UUID uid) {    	
	TestPlayer p = TestPlayer.create(name);
	
	final InetSocketAddress address = new InetSocketAddress("localhost", 25565);
	final AsyncPlayerPreLoginEvent preLoginEvent = new AsyncPlayerPreLoginEvent(name, address.getAddress(), uid);
	getPluginManager().callEvent(preLoginEvent);
	if (preLoginEvent.getLoginResult() != Result.ALLOWED) {
		return null;
	}
	
	final PlayerLoginEvent loginEvent = new PlayerLoginEvent(p, "localhost", address.getAddress());
	getPluginManager().callEvent(loginEvent);

	if (loginEvent.getResult() != PlayerLoginEvent.Result.ALLOWED) {
		return null;
	}
	
	final PlayerJoinEvent joinEvent = new PlayerJoinEvent(p, "");
	getPluginManager().callEvent(joinEvent);
	
	p.goOnline();
	return p;
}
 
Example 3
Project: NeverLag   File: AntiDoubleLogin.java   View source code 4 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH)
public void onLogin(AsyncPlayerPreLoginEvent e) {
	if (!cm.isAntiDoubleLogin) {
		return;
	}
	String username = e.getName();
	if (username == null) {
		return;
	}
	if (this.checkOnline(username)) {
		e.disallow(Result.KICK_OTHER, i18n.tr("antiDoubleLoginMessage"));
	}
}
 
Example 4
Project: VoxelGamesLibv2   File: UserListener.java   View source code 4 votes vote down vote up
@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 5
Project: ZentrelaCore   File: PunishmentManager.java   View source code 4 votes vote down vote up
@EventHandler
public void onAsyncPrelogin(AsyncPlayerPreLoginEvent event) {
    InetAddress address = event.getAddress();
    String name = event.getName();
    String uuid = event.getUniqueId().toString();
    String ip = PunishmentManager.parseIP(address);
    PunishmentManager.registerIP(event.getUniqueId(), ip);
    /*
     * Check if user has a ban in effect matching either UUID or IP
     */
    AutoCloseable[] ac_dub = SQLManager.prepare("SELECT * FROM punishments WHERE uuid = ? OR ip = ?");
    try {
        PreparedStatement request_punishment_status = (PreparedStatement) ac_dub[0];
        request_punishment_status.setString(1, uuid);
        request_punishment_status.setString(2, ip);
        AutoCloseable[] ac_trip = SQLManager.executeQuery(request_punishment_status);
        ResultSet rs = (ResultSet) ac_trip[0];
        while (rs.next()) {
            Punishment pun = new Punishment();
            pun.load(rs);
            if (pun.isValid()) {
                if (pun.type == PunishmentType.BAN || pun.type == PunishmentType.IPBAN) {
                    System.out.println("Kicking " + name + " for active ban.");
                    event.disallow(Result.KICK_OTHER, pun.getReason());
                } else if (pun.type == PunishmentType.MUTE) {
                    muted_byUUID.put(uuid, pun);
                }
            }
        }
        SQLManager.close(ac_dub);
        SQLManager.close(ac_trip);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 6
Project: ZentrelaCore   File: LoginLogoutManager.java   View source code 4 votes vote down vote up
@EventHandler
public void onAsyncPrelogin(AsyncPlayerPreLoginEvent event) {
    if (MaintenanceCommand.maintenanceMode && !MaintenanceCommand.allowed.contains(event.getUniqueId().toString())) {
        if (MotdManager.getMotd() != null)
            event.disallow(Result.KICK_OTHER, MotdManager.getMotd());
        else
            event.disallow(Result.KICK_OTHER, ChatColor.RED + "Zentrela is down for maintenance. Please check the MOTD (server list) for details!");
    }
}
 
Example 7
Project: RedProtect   File: RPPlayerListener.java   View source code 4 votes vote down vote up
@EventHandler
public void PlayerLogin(AsyncPlayerPreLoginEvent e){ 
	if (!RPConfig.getBool("server-protection.nickname-cap-filter.enabled")){
		return;
	}
	
	if (RedProtect.get().Ess){
		User essp = RedProtect.get().pless.getOfflineUser(e.getName());        	
    	if (essp != null && !essp.getConfigUUID().equals(e.getUniqueId())){
        	e.setKickMessage(RPLang.get("playerlistener.capfilter.kickmessage").replace("{nick}", essp.getName()));
        	e.setLoginResult(Result.KICK_OTHER);
    	}
	}
}
 
Example 8
Project: MiniMiniGames   File: PaloozaPlugin.java   View source code 4 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerJoin(AsyncPlayerPreLoginEvent event) {
   String ip = event.getAddress().getHostAddress();
   if (!ip.equals("127.0.0.1")) {
      event.disallow(Result.KICK_OTHER, ChatColor.RED + "Eh?");
   }
}
 
Example 9
Project: BetonQuest   File: JoinQuitListener.java   View source code 4 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
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 10
Project: ProtectPlugin   File: PlayerLogin.java   View source code 4 votes vote down vote up
private void work(AsyncPlayerPreLoginEvent event) {
	InetAddress addr = event.getAddress();
	if (this.segment.contains(addr)) {
		event.setLoginResult(Result.KICK_BANNED);
		event.setKickMessage("您的IP已被服务器封禁");
	} else if (addr.getHostAddress().equals(LOCAL_HOST)) {
		// DO NOTHING
	} else if (checkAddr(addr.getHostAddress())) {
		event.setLoginResult(Result.KICK_OTHER);
		event.setKickMessage("请稍后尝试登陆服务器");
	}
	this.addrLast.put(addr.getHostAddress(), System.currentTimeMillis());
}
 
Example 11
Project: BOHA   File: BlockerBukkit.java   View source code 3 votes vote down vote up
@EventHandler
public void login(AsyncPlayerPreLoginEvent event) {
    if(Blocker.isBlocked(event.getUniqueId())) {
        event.disallow(Result.KICK_OTHER, Blocker.MESSAGE);
    }
}
 
Example 12
Project: SupaCommons   File: ServerShutdown.java   View source code 3 votes vote down vote up
@EventHandler
public void onPlayerLogin(AsyncPlayerPreLoginEvent event) {
  if (isInProgress()) {
    event.disallow(Result.KICK_OTHER, ServerShutdown.this.kickMessage);
  }
}
 
Example 13
Project: PV-Star   File: ModuleLoader.java   View source code 3 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
private void onPlayerJoin(AsyncPlayerPreLoginEvent event) {

    if (!_isModulesLoaded)
        event.disallow(Result.KICK_OTHER, "PV-Star is still loading.");
}
 
Example 14
Project: ProtectPlugin   File: PlayerLogin.java   View source code 3 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void login(AsyncPlayerPreLoginEvent event) {
	if (event.getLoginResult().equals(Result.ALLOWED)) {
		work(event);
	}
}