下面列出了怎么用org.bukkit.event.player.AsyncPlayerPreLoginEvent.Result的API类实例代码及写法,或者点击链接到github查看源代码。
@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());
}
@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)));
}
}
@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);
}
@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);
}
}
@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));
}