Search in sources :

Example 1 with CrateCommandSource

use of com.codehusky.huskycrates.crate.CrateCommandSource in project HuskyCrates-Sponge by codeHusky.

the class CrateView method handleReward.

public void handleReward(CrateReward giveToPlayer) {
    for (Object reward : giveToPlayer.getRewards()) {
        // System.out.println(reward);
        if (reward instanceof String) {
            Sponge.getCommandManager().process(new CrateCommandSource(), reward.toString().replace("%p", ourplr.getName()));
        } else {
            // System.out.println(giveToPlayer.getReward().treatAsSingle());
            ourplr.getInventory().offer(((ItemStack) reward).copy());
        }
    }
    boolean mult = false;
    LangData thisData = giveToPlayer.getLangData();
    if (!giveToPlayer.treatAsSingle() && giveToPlayer.getRewards().size() == 1 && giveToPlayer.getRewards().get(0) instanceof ItemStack) {
        if (((ItemStack) giveToPlayer.getRewards().get(0)).getQuantity() > 1) {
            /*ourplr.sendMessage(Text.of("You won ", TextColors.YELLOW,
                            ((ItemStack) giveToPlayer.getReward().getReward()).getQuantity() + " ",
                            TextSerializers.FORMATTING_CODE.deserialize(giveToPlayer.getReward().getRewardName()), TextColors.RESET, " from a ",
                            TextSerializers.FORMATTING_CODE.deserialize(vc.displayName), TextColors.RESET, "!"));*/
            ourplr.sendMessage(TextSerializers.FORMATTING_CODE.deserialize(thisData.formatter(thisData.rewardMessage, ((ItemStack) giveToPlayer.getRewards().get(0)).getQuantity() + "", ourplr, vc, giveToPlayer, null, null)));
            if (giveToPlayer.shouldAnnounce()) {
                Sponge.getServer().getBroadcastChannel().send(TextSerializers.FORMATTING_CODE.deserialize(thisData.formatter(thisData.rewardAnnounceMessage, ((ItemStack) giveToPlayer.getRewards().get(0)).getQuantity() + "", ourplr, vc, giveToPlayer, null, null)));
            }
            mult = true;
        }
    }
    if (!mult) {
        String[] vowels = { "a", "e", "i", "o", "u" };
        if (Arrays.asList(vowels).contains(giveToPlayer.getRewardName().substring(0, 1).toLowerCase())) {
            ourplr.sendMessage(TextSerializers.FORMATTING_CODE.deserialize(thisData.formatter(thisData.rewardMessage, "an", ourplr, vc, giveToPlayer, null, null)));
            if (giveToPlayer.shouldAnnounce()) {
                Sponge.getServer().getBroadcastChannel().send(TextSerializers.FORMATTING_CODE.deserialize(thisData.formatter(thisData.rewardAnnounceMessage, "an", ourplr, vc, giveToPlayer, null, null)));
            }
        } else {
            ourplr.sendMessage(TextSerializers.FORMATTING_CODE.deserialize(thisData.formatter(thisData.rewardMessage, "a", ourplr, vc, giveToPlayer, null, null)));
            if (giveToPlayer.shouldAnnounce()) {
                Sponge.getServer().getBroadcastChannel().send(TextSerializers.FORMATTING_CODE.deserialize(thisData.formatter(thisData.rewardAnnounceMessage, "a", ourplr, vc, giveToPlayer, null, null)));
            }
        }
    }
}
Also used : CrateCommandSource(com.codehusky.huskycrates.crate.CrateCommandSource) ItemStack(org.spongepowered.api.item.inventory.ItemStack) LangData(com.codehusky.huskycrates.lang.LangData)

Aggregations

CrateCommandSource (com.codehusky.huskycrates.crate.CrateCommandSource)1 LangData (com.codehusky.huskycrates.lang.LangData)1 ItemStack (org.spongepowered.api.item.inventory.ItemStack)1