Search in sources :

Example 1 with LuckPerms

use of net.luckperms.api.LuckPerms in project AuthMeReloaded by AuthMe.

the class PermissionsManagerInitializationTest method setUpForPermissionSystemTest.

private void setUpForPermissionSystemTest() {
    if (permissionsSystemType == LUCK_PERMS) {
        LuckPerms api = mock(LuckPerms.class);
        ReflectionTestUtils.setField(LuckPermsProvider.class, null, "instance", api);
    } else if (permissionsSystemType == PERMISSIONS_EX) {
        throw new AssumptionViolatedException("PermissionsEx instance cannot be mocked because of missing dependencies -- skipping");
    } else if (permissionsSystemType == Z_PERMISSIONS) {
        ZPermissionsService zPermissionsService = mock(ZPermissionsService.class);
        given(servicesManager.load(ZPermissionsService.class)).willReturn(zPermissionsService);
    } else if (permissionsSystemType == VAULT) {
        setUpForVault();
    } else {
        throw new IllegalStateException("Unhandled permission systems type: " + permissionsSystemType);
    }
}
Also used : LuckPerms(net.luckperms.api.LuckPerms) AssumptionViolatedException(org.junit.AssumptionViolatedException) ZPermissionsService(org.tyrannyofheaven.bukkit.zPermissions.ZPermissionsService)

Example 2 with LuckPerms

use of net.luckperms.api.LuckPerms in project Almura by AlmuraDev.

the class MembershipHandler method handleMembershipSkills.

public void handleMembershipSkills(Player player, int newMembershipLevel) {
    if (skillsManager == null) {
        return;
    }
    int currentSkillLevel = skillsManager.getTotalSkillLevel(player);
    final LuckPerms permService = Sponge.getServiceManager().provide(LuckPerms.class).orElse(null);
    if (permService == null) {
        return;
    }
    final String currentGroup = permService.getUserManager().getUser(player.getUniqueId()).getPrimaryGroup();
    final String command = "lp user " + player.getName() + " promote members";
    if (newMembershipLevel == 1 && currentSkillLevel >= 250 && currentGroup.equalsIgnoreCase("survivor")) {
        this.commandManager.process(Sponge.getServer().getConsole(), command);
        serverNotificationManager.sendPopupNotification(player, Text.of("Membership Upgrade"), Text.of("You've been upgraded to: Citizen!"), 5);
        return;
    }
    if (newMembershipLevel == 2 && currentSkillLevel >= 375 && (currentGroup.equalsIgnoreCase("survivor") || currentGroup.equalsIgnoreCase("citizen"))) {
        if (currentGroup.equalsIgnoreCase("survivor")) {
            this.commandManager.process(Sponge.getServer().getConsole(), command);
        }
        this.commandManager.process(Sponge.getServer().getConsole(), command);
        serverNotificationManager.sendPopupNotification(player, Text.of("Membership Upgrade"), Text.of("You've been upgraded to: Explorer!"), 5);
        return;
    }
    if (newMembershipLevel == 3 && currentSkillLevel >= 400 && (currentGroup.equalsIgnoreCase("survivor") || currentGroup.equalsIgnoreCase("citizen") || currentGroup.equalsIgnoreCase("explorer"))) {
        if (currentGroup.equalsIgnoreCase("survivor")) {
            this.commandManager.process(Sponge.getServer().getConsole(), command);
            this.commandManager.process(Sponge.getServer().getConsole(), command);
        }
        if (currentGroup.equalsIgnoreCase("citizen")) {
            this.commandManager.process(Sponge.getServer().getConsole(), command);
        }
        this.commandManager.process(Sponge.getServer().getConsole(), command);
        serverNotificationManager.sendPopupNotification(player, Text.of("Membership Upgrade"), Text.of("You've been upgraded to: Pioneer!"), 5);
        return;
    }
    System.out.println("Exception: skills level check failed.  Player not upgraded. " + player.getName() + " Skill level: " + currentSkillLevel);
}
Also used : LuckPerms(net.luckperms.api.LuckPerms)

Example 3 with LuckPerms

use of net.luckperms.api.LuckPerms 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)

Example 4 with LuckPerms

use of net.luckperms.api.LuckPerms in project Almura by AlmuraDev.

the class MembershipHandler method handleMembershipPurchase.

public void handleMembershipPurchase(Player player, int newMembershipLevel) {
    // Typically only thing that fails here is if someone is running a hacked client.  This method double checks that.
    if (!player.hasPermission("almura.membership.purchase")) {
        serverNotificationManager.sendWindowMessage(player, Text.of("Permission Denied"), Text.of("Missing: almura.membership.purchase"));
        return;
    }
    final EconomyService econService = Sponge.getServiceManager().provide(EconomyService.class).orElse(null);
    final LuckPerms permService = Sponge.getServiceManager().provide(LuckPerms.class).orElse(null);
    if (econService != null && permService != null) {
        final Account account = econService.getOrCreateAccount(player.getUniqueId()).orElse(null);
        if (account != null) {
            BigDecimal balance;
            final Currency currency = econService.getDefaultCurrency();
            balance = account.getBalance(currency);
            double fee = 0;
            if (newMembershipLevel == 1) {
                fee = 2500000;
                if (!(balance.doubleValue() >= fee)) {
                    serverNotificationManager.sendWindowMessage(player, Text.of("Insufficient Funds"), Text.of("Insufficient Funds to purchase Citizen Membership."));
                    return;
                }
            }
            if (newMembershipLevel == 2) {
                fee = 5000000;
                if (!(balance.doubleValue() >= fee)) {
                    serverNotificationManager.sendWindowMessage(player, Text.of("Insufficient Funds"), Text.of("Insufficient Funds to purchase Explorer Membership."));
                    return;
                }
            }
            if (newMembershipLevel == 3) {
                fee = 10000000;
                if (!(balance.doubleValue() >= fee)) {
                    serverNotificationManager.sendWindowMessage(player, Text.of("Insufficient Funds"), Text.of("Insufficient Funds to purchase Pioneer Membership."));
                    return;
                }
            }
            String currentGroup = permService.getUserManager().getUser(player.getUniqueId()).getPrimaryGroup();
            String newMembership = "";
            if (newMembershipLevel == 1)
                newMembership = "Citizen";
            if (newMembershipLevel == 2)
                newMembership = "Explorer";
            if (newMembershipLevel == 3)
                newMembership = "Pioneer";
            BigDecimal deduct = new BigDecimal(fee);
            final String command = "lp user " + player.getName() + " promote members";
            if (newMembershipLevel == 1 && currentGroup.equalsIgnoreCase("survivor")) {
                this.commandManager.process(Sponge.getServer().getConsole(), command);
                account.withdraw(currency, deduct, Sponge.getCauseStackManager().getCurrentCause());
                this.network.sendTo(player, new ClientboundMembershipSuccessPacket(newMembership));
                return;
            }
            if (newMembershipLevel == 2 && (currentGroup.equalsIgnoreCase("survivor") || currentGroup.equalsIgnoreCase("citizen"))) {
                if (currentGroup.equalsIgnoreCase("survivor")) {
                    this.commandManager.process(Sponge.getServer().getConsole(), command);
                }
                this.commandManager.process(Sponge.getServer().getConsole(), command);
                account.withdraw(currency, deduct, Sponge.getCauseStackManager().getCurrentCause());
                this.network.sendTo(player, new ClientboundMembershipSuccessPacket(newMembership));
                return;
            }
            if (newMembershipLevel == 3 && (currentGroup.equalsIgnoreCase("survivor") || currentGroup.equalsIgnoreCase("citizen") || currentGroup.equalsIgnoreCase("explorer"))) {
                if (currentGroup.equalsIgnoreCase("survivor")) {
                    this.commandManager.process(Sponge.getServer().getConsole(), command);
                    this.commandManager.process(Sponge.getServer().getConsole(), command);
                }
                if (currentGroup.equalsIgnoreCase("citizen")) {
                    this.commandManager.process(Sponge.getServer().getConsole(), command);
                }
                this.commandManager.process(Sponge.getServer().getConsole(), command);
                account.withdraw(currency, deduct, Sponge.getCauseStackManager().getCurrentCause());
                this.network.sendTo(player, new ClientboundMembershipSuccessPacket(newMembership));
                return;
            }
            // This should be impossible, leaving this debug line.
            System.out.println("Current Group: " + currentGroup + " Failed to upgrade, no path found");
        }
    } else {
        serverNotificationManager.sendWindowMessage(player, Text.of("Error"), Text.of("Economy or Permission Service offline!"));
    }
}
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) ClientboundMembershipSuccessPacket(com.almuradev.almura.feature.membership.network.ClientboundMembershipSuccessPacket) BigDecimal(java.math.BigDecimal)

Aggregations

LuckPerms (net.luckperms.api.LuckPerms)4 BigDecimal (java.math.BigDecimal)2 Currency (org.spongepowered.api.service.economy.Currency)2 EconomyService (org.spongepowered.api.service.economy.EconomyService)2 Account (org.spongepowered.api.service.economy.account.Account)2 ClientboundMembershipGuiOpenPacket (com.almuradev.almura.feature.membership.network.ClientboundMembershipGuiOpenPacket)1 ClientboundMembershipSuccessPacket (com.almuradev.almura.feature.membership.network.ClientboundMembershipSuccessPacket)1 AssumptionViolatedException (org.junit.AssumptionViolatedException)1 ZPermissionsService (org.tyrannyofheaven.bukkit.zPermissions.ZPermissionsService)1