Search in sources :

Example 16 with StoredProfile

use of com.github.games647.fastlogin.core.StoredProfile in project FastLogin by games647.

the class CrackedCommand method onCrackedOther.

private void onCrackedOther(CommandSender sender, Command command, String[] args) {
    if (!hasOtherPermission(sender, command)) {
        return;
    }
    if (forwardCrackedCommand(sender, args[0])) {
        return;
    }
    // todo: load async
    StoredProfile profile = plugin.getCore().getStorage().loadProfile(args[0]);
    if (profile == null) {
        sender.sendMessage("Error occurred");
        return;
    }
    // existing player is already cracked
    if (profile.isSaved() && !profile.isPremium()) {
        plugin.getCore().sendLocaleMessage("not-premium-other", sender);
    } else {
        plugin.getCore().sendLocaleMessage("remove-premium", sender);
        profile.setPremium(false);
        plugin.getScheduler().runAsync(() -> {
            plugin.getCore().getStorage().save(profile);
            plugin.getServer().getPluginManager().callEvent(new BukkitFastLoginPremiumToggleEvent(profile, PremiumToggleReason.COMMAND_OTHER));
        });
    }
}
Also used : StoredProfile(com.github.games647.fastlogin.core.StoredProfile) BukkitFastLoginPremiumToggleEvent(com.github.games647.fastlogin.bukkit.event.BukkitFastLoginPremiumToggleEvent)

Example 17 with StoredProfile

use of com.github.games647.fastlogin.core.StoredProfile 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 18 with StoredProfile

use of com.github.games647.fastlogin.core.StoredProfile 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 19 with StoredProfile

use of com.github.games647.fastlogin.core.StoredProfile in project FastLogin by games647.

the class PluginMessageListener method onSuccessMessage.

private void onSuccessMessage(ProxiedPlayer forPlayer) {
    boolean shouldPersist = forPlayer.getPendingConnection().isOnlineMode();
    FloodgateService floodgateService = plugin.getFloodgateService();
    if (!shouldPersist && floodgateService != null) {
        // always save floodgate players to lock this username
        shouldPersist = floodgateService.isBedrockPlayer(forPlayer.getUniqueId());
    }
    if (shouldPersist) {
        // bukkit module successfully received and force logged in the user
        // update only on success to prevent corrupt data
        BungeeLoginSession loginSession = plugin.getSession().get(forPlayer.getPendingConnection());
        StoredProfile playerProfile = loginSession.getProfile();
        loginSession.setRegistered(true);
        if (!loginSession.isAlreadySaved()) {
            playerProfile.setPremium(true);
            plugin.getCore().getStorage().save(playerProfile);
            loginSession.setAlreadySaved(true);
        }
    }
}
Also used : StoredProfile(com.github.games647.fastlogin.core.StoredProfile) FloodgateService(com.github.games647.fastlogin.core.hooks.bedrock.FloodgateService) BungeeLoginSession(com.github.games647.fastlogin.bungee.BungeeLoginSession)

Example 20 with StoredProfile

use of com.github.games647.fastlogin.core.StoredProfile in project FastLogin by games647.

the class AsyncToggleMessage method turnOffPremium.

private void turnOffPremium() {
    StoredProfile playerProfile = core.getStorage().loadProfile(targetPlayer);
    // existing player is already cracked
    if (playerProfile.isSaved() && !playerProfile.isPremium()) {
        sendMessage("not-premium");
        return;
    }
    playerProfile.setPremium(false);
    playerProfile.setId(null);
    core.getStorage().save(playerProfile);
    PremiumToggleReason reason = (!isPlayerSender || !sender.getName().equalsIgnoreCase(playerProfile.getName())) ? PremiumToggleReason.COMMAND_OTHER : PremiumToggleReason.COMMAND_SELF;
    core.getPlugin().getProxy().getPluginManager().callEvent(new BungeeFastLoginPremiumToggleEvent(playerProfile, reason));
    sendMessage("remove-premium");
}
Also used : StoredProfile(com.github.games647.fastlogin.core.StoredProfile) PremiumToggleReason(com.github.games647.fastlogin.core.shared.event.FastLoginPremiumToggleEvent.PremiumToggleReason) BungeeFastLoginPremiumToggleEvent(com.github.games647.fastlogin.bungee.event.BungeeFastLoginPremiumToggleEvent)

Aggregations

StoredProfile (com.github.games647.fastlogin.core.StoredProfile)17 BukkitLoginSession (com.github.games647.fastlogin.bukkit.BukkitLoginSession)4 BukkitFastLoginPremiumToggleEvent (com.github.games647.fastlogin.bukkit.event.BukkitFastLoginPremiumToggleEvent)4 PremiumToggleReason (com.github.games647.fastlogin.core.shared.event.FastLoginPremiumToggleEvent.PremiumToggleReason)4 UUID (java.util.UUID)4 BungeeLoginSession (com.github.games647.fastlogin.bungee.BungeeLoginSession)3 VelocityLoginSession (com.github.games647.fastlogin.velocity.VelocityLoginSession)3 Profile (com.github.games647.craftapi.model.Profile)2 RateLimitException (com.github.games647.craftapi.resolver.RateLimitException)2 BukkitFastLoginPreLoginEvent (com.github.games647.fastlogin.bukkit.event.BukkitFastLoginPreLoginEvent)2 BungeeFastLoginPremiumToggleEvent (com.github.games647.fastlogin.bungee.event.BungeeFastLoginPremiumToggleEvent)2 LoginSession (com.github.games647.fastlogin.core.shared.LoginSession)2 VelocityFastLoginPremiumToggleEvent (com.github.games647.fastlogin.velocity.event.VelocityFastLoginPremiumToggleEvent)2 BukkitFastLoginAutoLoginEvent (com.github.games647.fastlogin.bukkit.event.BukkitFastLoginAutoLoginEvent)1 FloodgateService (com.github.games647.fastlogin.core.hooks.bedrock.FloodgateService)1 SQLStorage (com.github.games647.fastlogin.core.storage.SQLStorage)1 Subscribe (com.velocitypowered.api.event.Subscribe)1 IOException (java.io.IOException)1 Instant (java.time.Instant)1 PendingConnection (net.md_5.bungee.api.connection.PendingConnection)1