Search in sources :

Example 1 with ClientboundMembershipGuiOpenPacket

use of com.almuradev.almura.feature.membership.network.ClientboundMembershipGuiOpenPacket in project Almura by AlmuraDev.

the class MembershipHandler method requestClientGui.

public void requestClientGui(Player player) {
    final EconomyService service = Sponge.getServiceManager().provide(EconomyService.class).orElse(null);
    final LuckPerms permService = Sponge.getServiceManager().provide(LuckPerms.class).orElse(null);
    int currentMembershipLevel = -1;
    if (player.hasPermission("almura.membership.gui.open")) {
        if (service != null && skillsManager != null && permService != null) {
            final Account account = service.getOrCreateAccount(player.getUniqueId()).orElse(null);
            BigDecimal balance;
            if (account != null) {
                final Currency currency = service.getDefaultCurrency();
                balance = account.getBalance(currency);
                String currentGroup = permService.getUserManager().getUser(player.getUniqueId()).getPrimaryGroup();
                if (currentGroup.equalsIgnoreCase("default")) {
                    currentMembershipLevel = -1;
                // should be impossible to reach this unless permissions system is screwed up.
                } else if (currentGroup.equalsIgnoreCase("survivor")) {
                    currentMembershipLevel = 0;
                } else if (currentGroup.equalsIgnoreCase("citizen")) {
                    currentMembershipLevel = 1;
                } else if (currentGroup.equalsIgnoreCase("explorer")) {
                    currentMembershipLevel = 2;
                } else if (currentGroup.equalsIgnoreCase("pioneer")) {
                    currentMembershipLevel = 3;
                }
                this.network.sendTo(player, new ClientboundMembershipGuiOpenPacket(player.hasPermission("almura.membership.admin"), skillsManager.getTotalSkillLevel(player), balance.doubleValue(), currentMembershipLevel));
            }
        } else {
            serverNotificationManager.sendWindowMessage(player, Text.of("Init Error"), Text.of("Economy Service offline!"));
        }
    } else {
        serverNotificationManager.sendPopupNotification(player, Text.of("Insufficient Permissions"), Text.of("Missing [almura.membership.gui.open]"), 5);
    }
}
Also used : Account(org.spongepowered.api.service.economy.account.Account) LuckPerms(net.luckperms.api.LuckPerms) EconomyService(org.spongepowered.api.service.economy.EconomyService) Currency(org.spongepowered.api.service.economy.Currency) BigDecimal(java.math.BigDecimal) ClientboundMembershipGuiOpenPacket(com.almuradev.almura.feature.membership.network.ClientboundMembershipGuiOpenPacket)

Aggregations

ClientboundMembershipGuiOpenPacket (com.almuradev.almura.feature.membership.network.ClientboundMembershipGuiOpenPacket)1 BigDecimal (java.math.BigDecimal)1 LuckPerms (net.luckperms.api.LuckPerms)1 Currency (org.spongepowered.api.service.economy.Currency)1 EconomyService (org.spongepowered.api.service.economy.EconomyService)1 Account (org.spongepowered.api.service.economy.account.Account)1