Search in sources :

Example 1 with RewardRarity

use of au.com.mineauz.minigames.minigame.reward.RewardRarity in project Minigames by AddstarMC.

the class SetRewardCommand method onCommand.

@Override
public boolean onCommand(CommandSender sender, Minigame minigame, String label, String[] args) {
    if (args != null) {
        RewardsModule module = RewardsModule.getModule(minigame);
        if (!(module.getScheme() instanceof StandardRewardScheme)) {
            sender.sendMessage(ChatColor.RED + "This command can only be used on minigames that use the standard reward scheme");
            return true;
        }
        Rewards rewards = ((StandardRewardScheme) module.getScheme()).getPrimaryReward();
        int quantity = 1;
        double money = -1;
        if (args.length >= 2 && args[1].matches("[0-9]+")) {
            quantity = Integer.parseInt(args[1]);
        }
        ItemStack item = null;
        if (args[0].startsWith("$")) {
            try {
                money = Double.parseDouble(args[0].replace("$", ""));
            } catch (NumberFormatException e) {
            }
        } else {
            item = MinigameUtils.stringToItemStack(args[0], quantity);
        }
        if (item != null && item.getType() != Material.AIR) {
            RewardRarity rarity = RewardRarity.NORMAL;
            if (args.length == 3) {
                rarity = RewardRarity.valueOf(args[2].toUpperCase());
            }
            ItemReward ir = (ItemReward) RewardTypes.getRewardType("ITEM", rewards);
            ir.setRewardItem(item);
            ir.setRarity(rarity);
            rewards.addReward(ir);
            sender.sendMessage(ChatColor.GRAY + "Added " + item.getAmount() + " of " + MinigameUtils.getItemStackName(item) + " to primary rewards of \"" + minigame.getName(false) + "\" " + "with a rarity of \"" + rarity.toString().toLowerCase().replace("_", " ") + "\"");
            return true;
        } else if (sender instanceof Player && args[0].equals("SLOT")) {
            item = ((Player) sender).getInventory().getItemInMainHand();
            RewardRarity rarity = RewardRarity.NORMAL;
            if (args.length == 2) {
                rarity = RewardRarity.valueOf(args[1].toUpperCase());
            }
            ItemReward ir = (ItemReward) RewardTypes.getRewardType("ITEM", rewards);
            ir.setRewardItem(item);
            ir.setRarity(rarity);
            rewards.addReward(ir);
            sender.sendMessage(ChatColor.GRAY + "Added " + item.getAmount() + " of " + MinigameUtils.getItemStackName(item) + " to primary rewards of \"" + minigame.getName(false) + "\" " + "with a rarity of " + rarity.toString().toLowerCase().replace("_", " "));
            return true;
        } else if (item != null && item.getType() == Material.AIR) {
            sender.sendMessage(ChatColor.RED + "Primary rewards for \"" + minigame.getName(false) + "\" cannot be Air!");
            return true;
        } else if (money != -1 && plugin.hasEconomy()) {
            RewardRarity rarity = RewardRarity.NORMAL;
            if (args.length == 2) {
                rarity = RewardRarity.valueOf(args[1].toUpperCase());
            }
            MoneyReward mr = (MoneyReward) RewardTypes.getRewardType("MONEY", rewards);
            mr.setRewardMoney(money);
            mr.setRarity(rarity);
            rewards.addReward(mr);
            sender.sendMessage(ChatColor.GRAY + "Added $" + money + " to primary rewards of \"" + minigame.getName(false) + "\" " + "with a rarity of " + rarity.toString().toLowerCase().replace("_", " "));
            return true;
        } else if (!plugin.hasEconomy()) {
            sender.sendMessage(ChatColor.RED + "Vault required to set a money reward! Download from dev.bukkit.org");
            return true;
        }
    }
    return false;
}
Also used : Player(org.bukkit.entity.Player) Rewards(au.com.mineauz.minigames.minigame.reward.Rewards) ItemReward(au.com.mineauz.minigames.minigame.reward.ItemReward) MoneyReward(au.com.mineauz.minigames.minigame.reward.MoneyReward) RewardRarity(au.com.mineauz.minigames.minigame.reward.RewardRarity) ItemStack(org.bukkit.inventory.ItemStack) RewardsModule(au.com.mineauz.minigames.minigame.reward.RewardsModule) StandardRewardScheme(au.com.mineauz.minigames.minigame.reward.scheme.StandardRewardScheme)

Example 2 with RewardRarity

use of au.com.mineauz.minigames.minigame.reward.RewardRarity in project Minigames by AddstarMC.

the class RewardSign method signUse.

@Override
public boolean signUse(Sign sign, MinigamePlayer player) {
    Location loc = sign.getLocation();
    if (!MinigameUtils.isMinigameTool(player.getPlayer().getInventory().getItemInMainHand())) {
        String label = sign.getLine(2).toLowerCase();
        if (player.isInMinigame()) {
            if (!player.hasTempClaimedReward(label)) {
                if (mdata.hasRewardSign(loc)) {
                    Rewards rew = mdata.getRewardSign(loc);
                    for (RewardType r : rew.getReward()) {
                        r.giveReward(player);
                    }
                }
                player.addTempClaimedReward(label);
            }
        } else {
            if (!player.hasClaimedReward(label)) {
                if (mdata.hasRewardSign(loc)) {
                    Rewards rew = mdata.getRewardSign(loc);
                    for (RewardType r : rew.getReward()) {
                        r.giveReward(player);
                    }
                    player.updateInventory();
                }
                player.addClaimedReward(label);
            }
        }
    } else if (player.getPlayer().hasPermission("minigame.tool")) {
        Rewards rew = null;
        if (!mdata.hasRewardSign(loc)) {
            mdata.addRewardSign(loc);
        }
        rew = mdata.getRewardSign(loc);
        Menu rewardMenu = new Menu(5, getName(), player);
        rewardMenu.addItem(new MenuItemRewardGroupAdd("Add Group", Material.ITEM_FRAME, rew), 42);
        rewardMenu.addItem(new MenuItemRewardAdd("Add Item", Material.ITEM_FRAME, rew), 43);
        final MenuItemCustom mic = new MenuItemCustom("Save Rewards", Material.REDSTONE_TORCH_ON);
        final Location floc = loc;
        mic.setClick(new InteractionInterface() {

            @Override
            public Object interact(Object object) {
                mdata.saveRewardSign(MinigameUtils.createLocationID(floc), true);
                mic.getContainer().getViewer().sendMessage("Saved rewards for this sign.", null);
                mic.getContainer().getViewer().getPlayer().closeInventory();
                return null;
            }
        });
        rewardMenu.addItem(mic, 44);
        List<String> list = new ArrayList<String>();
        for (RewardRarity r : RewardRarity.values()) {
            list.add(r.toString());
        }
        List<MenuItem> mi = new ArrayList<MenuItem>();
        for (RewardType item : rew.getRewards()) {
            mi.add(item.getMenuItem());
        }
        List<String> des = new ArrayList<String>();
        des.add("Double Click to edit");
        for (RewardGroup group : rew.getGroups()) {
            MenuItemRewardGroup rwg = new MenuItemRewardGroup(group.getName() + " Group", des, Material.CHEST, group, rew);
            mi.add(rwg);
        }
        rewardMenu.addItems(mi);
        rewardMenu.displayMenu(player);
    }
    return true;
}
Also used : MenuItemRewardAdd(au.com.mineauz.minigames.menu.MenuItemRewardAdd) MenuItem(au.com.mineauz.minigames.menu.MenuItem) MenuItemCustom(au.com.mineauz.minigames.menu.MenuItemCustom) InteractionInterface(au.com.mineauz.minigames.menu.InteractionInterface) MenuItemRewardGroup(au.com.mineauz.minigames.menu.MenuItemRewardGroup) RewardGroup(au.com.mineauz.minigames.minigame.reward.RewardGroup) RewardType(au.com.mineauz.minigames.minigame.reward.RewardType) MenuItemRewardGroupAdd(au.com.mineauz.minigames.menu.MenuItemRewardGroupAdd) Rewards(au.com.mineauz.minigames.minigame.reward.Rewards) ArrayList(java.util.ArrayList) List(java.util.List) Menu(au.com.mineauz.minigames.menu.Menu) RewardRarity(au.com.mineauz.minigames.minigame.reward.RewardRarity) MenuItemRewardGroup(au.com.mineauz.minigames.menu.MenuItemRewardGroup) Location(org.bukkit.Location)

Example 3 with RewardRarity

use of au.com.mineauz.minigames.minigame.reward.RewardRarity in project Minigames by AddstarMC.

the class SetSecondaryRewardCommand method onCommand.

@Override
public boolean onCommand(CommandSender sender, Minigame minigame, String label, String[] args) {
    if (args != null) {
        RewardsModule module = RewardsModule.getModule(minigame);
        if (!(module.getScheme() instanceof StandardRewardScheme)) {
            sender.sendMessage(ChatColor.RED + "This command can only be used on minigames that use the standard reward scheme");
            return true;
        }
        Rewards rewards = ((StandardRewardScheme) module.getScheme()).getSecondaryReward();
        int quantity = 1;
        double money = -1;
        if (args.length >= 2 && args[1].matches("[0-9]+")) {
            quantity = Integer.parseInt(args[1]);
        }
        ItemStack item = null;
        if (args[0].startsWith("$")) {
            try {
                money = Double.parseDouble(args[0].replace("$", ""));
            } catch (NumberFormatException e) {
            }
        } else {
            item = MinigameUtils.stringToItemStack(args[0], quantity);
        }
        if (item != null && item.getType() != Material.AIR) {
            RewardRarity rarity = RewardRarity.NORMAL;
            if (args.length == 3) {
                rarity = RewardRarity.valueOf(args[2].toUpperCase());
            }
            ItemReward ir = (ItemReward) RewardTypes.getRewardType("ITEM", rewards);
            ir.setRewardItem(item);
            ir.setRarity(rarity);
            rewards.addReward(ir);
            sender.sendMessage(ChatColor.GRAY + "Added " + item.getAmount() + " of " + MinigameUtils.getItemStackName(item) + " to secondary rewards of \"" + minigame.getName(false) + "\" " + "with a rarity of " + rarity.toString().toLowerCase().replace("_", " "));
            return true;
        } else if (sender instanceof Player && args[0].equals("SLOT")) {
            item = ((Player) sender).getInventory().getItemInMainHand();
            RewardRarity rarity = RewardRarity.NORMAL;
            if (args.length == 2) {
                rarity = RewardRarity.valueOf(args[1].toUpperCase());
            }
            ItemReward ir = (ItemReward) RewardTypes.getRewardType("ITEM", rewards);
            ir.setRewardItem(item);
            ir.setRarity(rarity);
            rewards.addReward(ir);
            sender.sendMessage(ChatColor.GRAY + "Added " + item.getAmount() + " of " + MinigameUtils.getItemStackName(item) + " to secondary rewards of \"" + minigame.getName(false) + "\" " + "with a rarity of " + rarity.toString().toLowerCase().replace("_", " "));
            return true;
        } else if (item != null && item.getType() == Material.AIR) {
            sender.sendMessage(ChatColor.RED + "Secondary reward for \"" + minigame.getName(false) + "\" cannot be Air!");
            return true;
        } else if (money != -1 && plugin.hasEconomy()) {
            RewardRarity rarity = RewardRarity.NORMAL;
            if (args.length == 2) {
                rarity = RewardRarity.valueOf(args[1].toUpperCase());
            }
            MoneyReward mr = (MoneyReward) RewardTypes.getRewardType("MONEY", rewards);
            mr.setRewardMoney(money);
            mr.setRarity(rarity);
            rewards.addReward(mr);
            sender.sendMessage(ChatColor.GRAY + "Added $" + money + " to secondary rewards of \"" + minigame.getName(false) + "\" " + "with a rarity of " + rarity.toString().toLowerCase().replace("_", " "));
            return true;
        } else if (!plugin.hasEconomy()) {
            sender.sendMessage(ChatColor.RED + "Vault required to set a money reward! Download from dev.bukkit.org");
            return true;
        }
    }
    return false;
}
Also used : Player(org.bukkit.entity.Player) Rewards(au.com.mineauz.minigames.minigame.reward.Rewards) ItemReward(au.com.mineauz.minigames.minigame.reward.ItemReward) MoneyReward(au.com.mineauz.minigames.minigame.reward.MoneyReward) RewardRarity(au.com.mineauz.minigames.minigame.reward.RewardRarity) ItemStack(org.bukkit.inventory.ItemStack) RewardsModule(au.com.mineauz.minigames.minigame.reward.RewardsModule) StandardRewardScheme(au.com.mineauz.minigames.minigame.reward.scheme.StandardRewardScheme)

Example 4 with RewardRarity

use of au.com.mineauz.minigames.minigame.reward.RewardRarity in project Minigames by AddstarMC.

the class MenuItemRewardGroup method onDoubleClick.

@Override
public ItemStack onDoubleClick() {
    Menu rewardMenu = new Menu(5, getName(), getContainer().getViewer());
    rewardMenu.setPreviousPage(getContainer());
    List<String> des = new ArrayList<String>();
    des.add("Click this with an item");
    des.add("to add it to rewards.");
    des.add("Click without an item");
    des.add("to add a money reward.");
    rewardMenu.addItem(new MenuItemRewardAdd("Add Item", des, Material.ITEM_FRAME, group), 43);
    rewardMenu.addItem(new MenuItemPage("Save " + getName(), Material.REDSTONE_TORCH_ON, rewardMenu.getPreviousPage()), 44);
    List<String> list = new ArrayList<String>();
    for (RewardRarity r : RewardRarity.values()) {
        list.add(r.toString());
    }
    List<MenuItem> mi = new ArrayList<MenuItem>();
    for (RewardType item : group.getItems()) {
        mi.add(item.getMenuItem());
    }
    rewardMenu.addItems(mi);
    rewardMenu.displayMenu(getContainer().getViewer());
    return null;
}
Also used : RewardType(au.com.mineauz.minigames.minigame.reward.RewardType) ArrayList(java.util.ArrayList) RewardRarity(au.com.mineauz.minigames.minigame.reward.RewardRarity)

Aggregations

RewardRarity (au.com.mineauz.minigames.minigame.reward.RewardRarity)4 Rewards (au.com.mineauz.minigames.minigame.reward.Rewards)3 ItemReward (au.com.mineauz.minigames.minigame.reward.ItemReward)2 MoneyReward (au.com.mineauz.minigames.minigame.reward.MoneyReward)2 RewardType (au.com.mineauz.minigames.minigame.reward.RewardType)2 RewardsModule (au.com.mineauz.minigames.minigame.reward.RewardsModule)2 StandardRewardScheme (au.com.mineauz.minigames.minigame.reward.scheme.StandardRewardScheme)2 ArrayList (java.util.ArrayList)2 Player (org.bukkit.entity.Player)2 ItemStack (org.bukkit.inventory.ItemStack)2 InteractionInterface (au.com.mineauz.minigames.menu.InteractionInterface)1 Menu (au.com.mineauz.minigames.menu.Menu)1 MenuItem (au.com.mineauz.minigames.menu.MenuItem)1 MenuItemCustom (au.com.mineauz.minigames.menu.MenuItemCustom)1 MenuItemRewardAdd (au.com.mineauz.minigames.menu.MenuItemRewardAdd)1 MenuItemRewardGroup (au.com.mineauz.minigames.menu.MenuItemRewardGroup)1 MenuItemRewardGroupAdd (au.com.mineauz.minigames.menu.MenuItemRewardGroupAdd)1 RewardGroup (au.com.mineauz.minigames.minigame.reward.RewardGroup)1 List (java.util.List)1 Location (org.bukkit.Location)1