Search in sources :

Example 21 with Profile

use of com.github.games647.craftapi.model.Profile in project FastLogin by games647.

the class PremiumCommand method onPremiumSelf.

private void onPremiumSelf(CommandSender sender, Command cmd, String[] args) {
    if (isConsole(sender)) {
        return;
    }
    if (forwardPremiumCommand(sender, sender.getName())) {
        return;
    }
    UUID id = ((Player) sender).getUniqueId();
    if (plugin.getConfig().getBoolean("premium-warning") && !plugin.getCore().getPendingConfirms().contains(id)) {
        sender.sendMessage(plugin.getCore().getMessage("premium-warning"));
        plugin.getCore().getPendingConfirms().add(id);
        return;
    }
    plugin.getCore().getPendingConfirms().remove(id);
    // todo: load async
    StoredProfile profile = plugin.getCore().getStorage().loadProfile(sender.getName());
    if (profile.isPremium()) {
        plugin.getCore().sendLocaleMessage("already-exists", sender);
    } else {
        // todo: resolve uuid
        profile.setPremium(true);
        plugin.getScheduler().runAsync(() -> {
            plugin.getCore().getStorage().save(profile);
            plugin.getServer().getPluginManager().callEvent(new BukkitFastLoginPremiumToggleEvent(profile, PremiumToggleReason.COMMAND_SELF));
        });
        plugin.getCore().sendLocaleMessage("add-premium", sender);
    }
}
Also used : Player(org.bukkit.entity.Player) StoredProfile(com.github.games647.fastlogin.core.StoredProfile) BukkitFastLoginPremiumToggleEvent(com.github.games647.fastlogin.bukkit.event.BukkitFastLoginPremiumToggleEvent) UUID(java.util.UUID)

Example 22 with Profile

use of com.github.games647.craftapi.model.Profile in project FastLogin by games647.

the class FloodgateAuthTask method startLogin.

@Override
protected void startLogin() {
    BukkitLoginSession session = new BukkitLoginSession(player.getName(), isRegistered, profile);
    // enable auto login based on the value of 'autoLoginFloodgate' in config.yml
    session.setVerified(isAutoAuthAllowed(autoLoginFloodgate));
    // run login task
    Runnable forceLoginTask = new ForceLoginTask(core.getPlugin().getCore(), player, session);
    Bukkit.getScheduler().runTaskAsynchronously(core.getPlugin(), forceLoginTask);
}
Also used : BukkitLoginSession(com.github.games647.fastlogin.bukkit.BukkitLoginSession)

Example 23 with Profile

use of com.github.games647.craftapi.model.Profile in project FastLogin by games647.

the class ForceLoginTask method callFastLoginAutoLoginEvent.

@Override
public FastLoginAutoLoginEvent callFastLoginAutoLoginEvent(LoginSession session, StoredProfile profile) {
    BukkitFastLoginAutoLoginEvent event = new BukkitFastLoginAutoLoginEvent(session, profile);
    core.getPlugin().getServer().getPluginManager().callEvent(event);
    return event;
}
Also used : BukkitFastLoginAutoLoginEvent(com.github.games647.fastlogin.bukkit.event.BukkitFastLoginAutoLoginEvent)

Example 24 with Profile

use of com.github.games647.craftapi.model.Profile in project FastLogin by games647.

the class FloodgateAuthTask method startLogin.

@Override
protected void startLogin() {
    BungeeLoginSession session = new BungeeLoginSession(player.getName(), isRegistered, profile);
    core.getPlugin().getSession().put(player.getPendingConnection(), session);
    // run login task
    Runnable forceLoginTask = new ForceLoginTask(core.getPlugin().getCore(), player, server, session, isAutoAuthAllowed(autoLoginFloodgate));
    core.getPlugin().getScheduler().runAsync(forceLoginTask);
}
Also used : BungeeLoginSession(com.github.games647.fastlogin.bungee.BungeeLoginSession)

Example 25 with Profile

use of com.github.games647.craftapi.model.Profile in project FastLogin by games647.

the class FloodgateManagement method run.

@Override
public void run() {
    core.getPlugin().getLog().info("Player {} is connecting through Geyser Floodgate.", username);
    // check if the Bedrock player is linked to a Java account
    isLinked = floodgatePlayer.getLinkedPlayer() != null;
    // if that's the case, players will be logged in via plugin messages
    if (core.getStorage() == null) {
        return;
    }
    profile = core.getStorage().loadProfile(username);
    AuthPlugin<P> authPlugin = core.getAuthPluginHook();
    try {
        // maybe Bungee without auth plugin
        if (authPlugin == null) {
            if (profile != null) {
                isRegistered = profile.isPremium();
            } else {
                isRegistered = false;
            }
        } else {
            isRegistered = authPlugin.isRegistered(username);
        }
    } catch (Exception ex) {
        core.getPlugin().getLog().error("An error has occured while checking if player {} is registered", username, ex);
        return;
    }
    // decide if checks should be made for conflicting Java player names
    if (isNameCheckRequired()) {
        // check for conflicting Premium Java name
        Optional<Profile> premiumUUID = Optional.empty();
        try {
            premiumUUID = core.getResolver().findProfile(username);
        } catch (IOException | RateLimitException e) {
            core.getPlugin().getLog().error("Could not check whether Floodgate Player {}'s name conflicts a premium Java account's name.", username, e);
            return;
        }
        // stop execution if player's name is conflicting
        if (premiumUUID.isPresent()) {
            return;
        }
    }
    if (!isRegistered && !isAutoAuthAllowed(autoRegisterFloodgate)) {
        return;
    }
    // logging in from bedrock for a second time threw an error with UUID
    if (profile == null) {
        profile = new StoredProfile(getUUID(player), username, true, getAddress(player).toString());
    }
    // start Bukkit/Bungee specific tasks
    startLogin();
}
Also used : StoredProfile(com.github.games647.fastlogin.core.StoredProfile) RateLimitException(com.github.games647.craftapi.resolver.RateLimitException) IOException(java.io.IOException) RateLimitException(com.github.games647.craftapi.resolver.RateLimitException) IOException(java.io.IOException) Profile(com.github.games647.craftapi.model.Profile) StoredProfile(com.github.games647.fastlogin.core.StoredProfile)

Aggregations

Profile (com.github.games647.craftapi.model.Profile)8 StoredProfile (com.github.games647.fastlogin.core.StoredProfile)7 SkinPropertyTest (com.github.games647.craftapi.model.skin.SkinPropertyTest)5 BukkitLoginSession (com.github.games647.fastlogin.bukkit.BukkitLoginSession)5 Test (org.junit.Test)5 BukkitFastLoginPremiumToggleEvent (com.github.games647.fastlogin.bukkit.event.BukkitFastLoginPremiumToggleEvent)4 UUID (java.util.UUID)3 SkinModel (com.github.games647.changeskin.core.model.skin.SkinModel)2 SkinProperty (com.github.games647.craftapi.model.skin.SkinProperty)2 RateLimitException (com.github.games647.craftapi.resolver.RateLimitException)2 BukkitFastLoginPreLoginEvent (com.github.games647.fastlogin.bukkit.event.BukkitFastLoginPreLoginEvent)2 BungeeLoginSession (com.github.games647.fastlogin.bungee.BungeeLoginSession)2 IOException (java.io.IOException)2 ChangeSkinCore (com.github.games647.changeskin.core.ChangeSkinCore)1 SkinStorage (com.github.games647.changeskin.core.SkinStorage)1 GameProfile (com.github.games647.changeskin.core.model.GameProfile)1 UserPreference (com.github.games647.changeskin.core.model.UserPreference)1 Account (com.github.games647.changeskin.core.model.auth.Account)1 TextureType (com.github.games647.changeskin.core.model.skin.TextureType)1 SharedListener (com.github.games647.changeskin.core.shared.SharedListener)1