Search in sources :

Example 1 with PerkOwnerService

use of gg.projecteden.nexus.models.perkowner.PerkOwnerService in project Nexus by ProjectEdenGG.

the class MinigamesCommand method getTokens.

@Path("tokens [user]")
void getTokens(@Arg("self") Nerd nerd) {
    PerkOwnerService service = new PerkOwnerService();
    PerkOwner perkOwner = service.get(nerd);
    String username = nerd.getUuid().equals(player().getUniqueId()) ? "You have" : (perkOwner.getNickname() + " has");
    send(PREFIX + username + " " + perkOwner.getTokens() + plural(" token", perkOwner.getTokens()));
}
Also used : PerkOwner(gg.projecteden.nexus.models.perkowner.PerkOwner) PerkOwnerService(gg.projecteden.nexus.models.perkowner.PerkOwnerService) Path(gg.projecteden.nexus.framework.commands.models.annotations.Path)

Example 2 with PerkOwnerService

use of gg.projecteden.nexus.models.perkowner.PerkOwnerService in project Nexus by ProjectEdenGG.

the class BankCommand method wallet.

@Path("[player]")
@Description("Displays all currencies owned by the player")
void wallet(@Arg("self") Nerd nerd) {
    send(PREFIX + "&e" + nerd.getNickname() + "&3's Wallet: ");
    // Store Credit
    Contributor contributor = new ContributorService().get(nerd);
    send("&3Store Credit: &e" + contributor.getCreditFormatted());
    // Vote Points
    Voter voter = new VoterService().get(nerd);
    send("&3Vote Points: &e" + voter.getPoints());
    // Event Store
    EventUser eventUser = new EventUserService().get(nerd);
    send("&3Event Tokens: &e" + eventUser.getTokens());
    // Minigames
    PerkOwner perkOwner = new PerkOwnerService().get(nerd);
    send("&3Minigame Tokens: &e" + perkOwner.getTokens());
    // Economy
    send("&3Economy Balances: &e");
    Banker banker = new BankerService().get(nerd);
    Map<ShopGroup, BigDecimal> balances = banker.getBalances();
    for (ShopGroup shopGroup : balances.keySet()) {
        String name = StringUtils.camelCase(shopGroup);
        String bal = banker.getBalanceFormatted(shopGroup);
        send("&3 - " + name + ": &e" + bal);
    }
    line();
}
Also used : PerkOwner(gg.projecteden.nexus.models.perkowner.PerkOwner) Banker(gg.projecteden.nexus.models.banker.Banker) Contributor(gg.projecteden.nexus.models.store.Contributor) VoterService(gg.projecteden.nexus.models.voter.VoterService) BigDecimal(java.math.BigDecimal) PerkOwnerService(gg.projecteden.nexus.models.perkowner.PerkOwnerService) ShopGroup(gg.projecteden.nexus.models.shop.Shop.ShopGroup) ContributorService(gg.projecteden.nexus.models.store.ContributorService) EventUser(gg.projecteden.nexus.models.eventuser.EventUser) Voter(gg.projecteden.nexus.models.voter.Voter) BankerService(gg.projecteden.nexus.models.banker.BankerService) EventUserService(gg.projecteden.nexus.models.eventuser.EventUserService) Path(gg.projecteden.nexus.framework.commands.models.annotations.Path) Description(gg.projecteden.nexus.framework.commands.models.annotations.Description)

Example 3 with PerkOwnerService

use of gg.projecteden.nexus.models.perkowner.PerkOwnerService in project Nexus by ProjectEdenGG.

the class CategoryMenu method init.

@Override
public void init(Player player, InventoryContents contents) {
    addBackItem(contents, 1, 1, $ -> new PerkMenu().open(player));
    if (menu.equals(BuyPerksMenu.class)) {
        PerkOwner perkOwner = new PerkOwnerService().get(player);
        contents.set(0, 8, ClickableItem.empty(new ItemBuilder(Material.EMERALD).name("&2&lBalance").lore("&f" + FORMATTER.format(perkOwner.getTokens()) + plural(" token", perkOwner.getTokens())).build()));
    }
    int col = 2;
    for (PerkCategory perkCategory : PerkCategory.values()) {
        contents.set(1, col, ClickableItem.from(perkCategory.getMenuItem(), $ -> {
            try {
                menu.getConstructor(PerkCategory.class).newInstance(perkCategory).open(player);
            } catch (Exception e) {
                throw new RuntimeException("Could not open menu");
            }
        }));
        col += 1;
    }
}
Also used : ItemBuilder(gg.projecteden.nexus.utils.ItemBuilder) StringUtils.plural(gg.projecteden.nexus.utils.StringUtils.plural) Getter(lombok.Getter) SmartInventory(fr.minuskube.inv.SmartInventory) RequiredArgsConstructor(lombok.RequiredArgsConstructor) DecimalFormat(java.text.DecimalFormat) PerkOwnerService(gg.projecteden.nexus.models.perkowner.PerkOwnerService) Player(org.bukkit.entity.Player) PerkCategory(gg.projecteden.nexus.features.minigames.models.perks.PerkCategory) InventoryProvider(fr.minuskube.inv.content.InventoryProvider) InventoryContents(fr.minuskube.inv.content.InventoryContents) MenuUtils(gg.projecteden.nexus.features.menus.MenuUtils) PerkMenu(gg.projecteden.nexus.features.minigames.menus.PerkMenu) PerkOwner(gg.projecteden.nexus.models.perkowner.PerkOwner) Material(org.bukkit.Material) ClickableItem(fr.minuskube.inv.ClickableItem) PerkOwner(gg.projecteden.nexus.models.perkowner.PerkOwner) ItemBuilder(gg.projecteden.nexus.utils.ItemBuilder) PerkCategory(gg.projecteden.nexus.features.minigames.models.perks.PerkCategory) PerkMenu(gg.projecteden.nexus.features.minigames.menus.PerkMenu) PerkOwnerService(gg.projecteden.nexus.models.perkowner.PerkOwnerService)

Example 4 with PerkOwnerService

use of gg.projecteden.nexus.models.perkowner.PerkOwnerService in project Nexus by ProjectEdenGG.

the class PerkMenu method init.

@Override
public void init(Player player, InventoryContents contents) {
    ClickableItem yourPerks = ClickableItem.from(new ItemBuilder(Material.PLAYER_HEAD).skullOwner(player).name("&6&lYour Perks").build(), e -> new CategoryMenu<>(PlayerPerksMenu.class).open(player));
    ClickableItem buyPerks = ClickableItem.from(new ItemBuilder(Material.EMERALD).name("&a&lBuy Perks").build(), e -> new CategoryMenu<>(BuyPerksMenu.class).open(player));
    contents.set(SlotPos.of(1, 3), yourPerks);
    contents.set(SlotPos.of(1, 5), buyPerks);
    PerkOwner perkOwner = new PerkOwnerService().get(player);
    contents.set(0, 8, ClickableItem.empty(new ItemBuilder(Material.EMERALD).name("&2&lBalance").lore("&f" + FORMATTER.format(perkOwner.getTokens()) + plural(" token", perkOwner.getTokens())).build()));
}
Also used : ItemBuilder(gg.projecteden.nexus.utils.ItemBuilder) CategoryMenu(gg.projecteden.nexus.features.minigames.menus.perks.CategoryMenu) PerkOwner(gg.projecteden.nexus.models.perkowner.PerkOwner) ClickableItem(fr.minuskube.inv.ClickableItem) PerkOwnerService(gg.projecteden.nexus.models.perkowner.PerkOwnerService)

Example 5 with PerkOwnerService

use of gg.projecteden.nexus.models.perkowner.PerkOwnerService in project Nexus by ProjectEdenGG.

the class MultiplayerMechanic method giveRewards.

public final void giveRewards(@NotNull Match match) {
    PerkOwnerService service = new PerkOwnerService();
    if (RandomUtils.randomInt(1, 50) == 1) {
        List<Minigamer> minigamers = new ArrayList<>(match.getMinigamers());
        Collections.shuffle(minigamers);
        // iterates until we find a player who is missing at least 1 collectible
        for (Minigamer minigamer : minigamers) {
            PerkOwner perkOwner = service.get(minigamer.getPlayer());
            if (LocalDate.now().isBefore(perkOwner.getRandomGiftDate().plusWeeks(1)))
                continue;
            // get a random perk the player doesn't own
            Map<PerkType, Double> weights = new HashMap<>();
            List<PerkType> unownedPerks = Arrays.stream(PerkType.values()).filter(type -> !perkOwner.getPurchasedPerks().containsKey(type)).collect(Collectors.toList());
            if (unownedPerks.isEmpty())
                continue;
            // weights should be inverse of the cost (i.e. cheapest is most common/highest number)
            int maxPrice = (int) Utils.getMax(unownedPerks, PerkType::getPrice).getValue();
            int minPrice = (int) Utils.getMin(unownedPerks, PerkType::getPrice).getValue();
            unownedPerks.forEach(perkType -> weights.put(perkType, (double) (maxPrice - perkType.getPrice() + minPrice)));
            PerkType perkType = RandomUtils.getWeightedRandom(weights);
            // failsafe (this shouldn't happen but just in case)
            if (perkType == null)
                continue;
            perkOwner.getPurchasedPerks().put(perkType, false);
            perkOwner.setRandomGiftDate(LocalDate.now());
            service.save(perkOwner);
            Minigames.broadcast("&e" + minigamer.getNickname() + "&3 randomly won the collectible &e" + perkType.getPerk().getName());
            break;
        }
    }
    match.getMinigamers().forEach(minigamer -> {
        PerkOwner perkOwner = new PerkOwnerService().get(minigamer.getPlayer());
        // max of 1 in 2 chance of getting a reward (dependant on score)
        int multiplier = getMultiplier(match, minigamer);
        if (multiplier == 0)
            return;
        if (RandomUtils.randomInt(1, 2 * multiplier) == 1)
            perkOwner.reward(match.getArena());
    });
}
Also used : Arrays(java.util.Arrays) JsonBuilder(gg.projecteden.nexus.utils.JsonBuilder) HashMap(java.util.HashMap) PerkOwnerService(gg.projecteden.nexus.models.perkowner.PerkOwnerService) Match(gg.projecteden.nexus.features.minigames.models.Match) ArrayList(java.util.ArrayList) MatchEndEvent(gg.projecteden.nexus.features.minigames.models.events.matches.MatchEndEvent) RandomUtils(gg.projecteden.nexus.utils.RandomUtils) Component(net.kyori.adventure.text.Component) Mechanic(gg.projecteden.nexus.features.minigames.models.mechanics.Mechanic) Map(java.util.Map) PerkType(gg.projecteden.nexus.features.minigames.models.perks.PerkType) AdventureUtils(gg.projecteden.nexus.utils.AdventureUtils) PerkOwner(gg.projecteden.nexus.models.perkowner.PerkOwner) Minigames(gg.projecteden.nexus.features.minigames.Minigames) TextComponent(net.kyori.adventure.text.TextComponent) MatchBeginEvent(gg.projecteden.nexus.features.minigames.models.events.matches.MatchBeginEvent) TextColor(net.kyori.adventure.text.format.TextColor) Minigamer(gg.projecteden.nexus.features.minigames.models.Minigamer) Collectors(java.util.stream.Collectors) Nicknamed(gg.projecteden.interfaces.Nicknamed) NamedTextColor(net.kyori.adventure.text.format.NamedTextColor) Arena(gg.projecteden.nexus.features.minigames.models.Arena) Utils(gg.projecteden.nexus.utils.Utils) MinigamerDeathEvent(gg.projecteden.nexus.features.minigames.models.events.matches.minigamers.MinigamerDeathEvent) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Named(gg.projecteden.interfaces.Named) LocalDate(java.time.LocalDate) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) PerkOwner(gg.projecteden.nexus.models.perkowner.PerkOwner) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Minigamer(gg.projecteden.nexus.features.minigames.models.Minigamer) PerkOwnerService(gg.projecteden.nexus.models.perkowner.PerkOwnerService) PerkType(gg.projecteden.nexus.features.minigames.models.perks.PerkType)

Aggregations

PerkOwner (gg.projecteden.nexus.models.perkowner.PerkOwner)10 PerkOwnerService (gg.projecteden.nexus.models.perkowner.PerkOwnerService)10 Path (gg.projecteden.nexus.framework.commands.models.annotations.Path)5 ParticleBuilder (com.destroystokyo.paper.ParticleBuilder)2 ClickableItem (fr.minuskube.inv.ClickableItem)2 Permission (gg.projecteden.nexus.framework.commands.models.annotations.Permission)2 ItemBuilder (gg.projecteden.nexus.utils.ItemBuilder)2 SmartInventory (fr.minuskube.inv.SmartInventory)1 InventoryContents (fr.minuskube.inv.content.InventoryContents)1 InventoryProvider (fr.minuskube.inv.content.InventoryProvider)1 Named (gg.projecteden.interfaces.Named)1 Nicknamed (gg.projecteden.interfaces.Nicknamed)1 MenuUtils (gg.projecteden.nexus.features.menus.MenuUtils)1 Minigames (gg.projecteden.nexus.features.minigames.Minigames)1 PerkMenu (gg.projecteden.nexus.features.minigames.menus.PerkMenu)1 CategoryMenu (gg.projecteden.nexus.features.minigames.menus.perks.CategoryMenu)1 Arena (gg.projecteden.nexus.features.minigames.models.Arena)1 Match (gg.projecteden.nexus.features.minigames.models.Match)1 Minigamer (gg.projecteden.nexus.features.minigames.models.Minigamer)1 MatchBeginEvent (gg.projecteden.nexus.features.minigames.models.events.matches.MatchBeginEvent)1