Search in sources :

Example 1 with StandardRewardScheme

use of au.com.mineauz.minigames.minigame.reward.scheme.StandardRewardScheme 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 ignored) {
            }
        } 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) ItemStack(org.bukkit.inventory.ItemStack) StandardRewardScheme(au.com.mineauz.minigames.minigame.reward.scheme.StandardRewardScheme)

Example 2 with StandardRewardScheme

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

the class RewardsModule method load.

@Override
public void load(FileConfiguration config) {
    ConfigurationSection root = config.getConfigurationSection(getMinigame().getName(false));
    if (root != null) {
        String name = root.getString("reward-scheme", "standard");
        if (name != null) {
            scheme = RewardSchemes.createScheme(name);
            if (scheme == null) {
                scheme = new StandardRewardScheme();
            }
        }
        ConfigurationSection rewards = root.getConfigurationSection("rewards");
        scheme.load(rewards);
    }
}
Also used : StandardRewardScheme(au.com.mineauz.minigames.minigame.reward.scheme.StandardRewardScheme) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 3 with StandardRewardScheme

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

the class TreasureHuntMechanic method spawnTreasure.

public static void spawnTreasure(final Minigame mgm) {
    final TreasureHuntModule thm = TreasureHuntModule.getMinigameModule(mgm);
    if (thm.hasTreasureLocation())
        removeTreasure(mgm);
    if (!thm.getCurrentHints().isEmpty())
        thm.clearHints();
    thm.setTreasureFound(false);
    Location tcpos = mgm.getStartLocations().get(0).clone();
    final Location rpos = tcpos;
    double rx;
    double ry;
    double rz;
    final int maxradius;
    if (thm.getMaxRadius() == 0) {
        maxradius = 1000;
    } else {
        maxradius = thm.getMaxRadius();
    }
    final int maxheight = thm.getMaxHeight();
    Random rand = new Random();
    int rrad = rand.nextInt(maxradius);
    double randCir = 2 * Math.PI * rand.nextInt(360) / 360;
    rx = tcpos.getX() - 0.5 + Math.round(rrad * Math.cos(randCir));
    rz = tcpos.getZ() - 0.5 + Math.round(rrad * Math.sin(randCir));
    ry = tcpos.getY() + rand.nextInt(maxheight);
    rpos.setX(rx);
    rpos.setY(ry);
    rpos.setZ(rz);
    // TODO: Improve so no invalid spawns (Not over void, Strict containment)
    switch(rpos.getBlock().getType()) {
        case AIR:
        case CAVE_AIR:
        case VOID_AIR:
            while (rpos.getBlock().getType() == Material.AIR && rpos.getY() > 1) {
                rpos.setY(rpos.getY() - 1);
            }
            rpos.setY(rpos.getY() + 1);
            Bukkit.getScheduler().runTaskLater(plugin, () -> rpos.getBlock().setType(Material.CHEST), 1L);
            break;
        default:
            while (rpos.getBlock().getType() != Material.AIR && rpos.getY() < 255) {
                rpos.setY(rpos.getY() + 1);
            }
            Bukkit.getScheduler().runTaskLater(plugin, () -> rpos.getBlock().setType(Material.CHEST), 1L);
            break;
    }
    // Fill new chest
    Bukkit.getScheduler().runTaskLater(plugin, () -> {
        if (rpos.getBlock().getState() instanceof Chest) {
            final Chest chest = (Chest) rpos.getBlock().getState();
            // TODO: Treasure hunt needs own rewards specification
            RewardsModule rewards = RewardsModule.getModule(mgm);
            if (rewards.getScheme() instanceof StandardRewardScheme) {
                if (!((StandardRewardScheme) rewards.getScheme()).getPrimaryReward().getRewards().isEmpty()) {
                    int numitems = (int) Math.round(Math.random() * (thm.getMaxTreasure() - thm.getMinTreasure())) + thm.getMinTreasure();
                    final ItemStack[] items = new ItemStack[27];
                    for (int i = 0; i < numitems; i++) {
                        RewardType rew = ((StandardRewardScheme) rewards.getScheme()).getPrimaryReward().getReward().get(0);
                        if (rew instanceof ItemReward) {
                            ItemReward irew = (ItemReward) rew;
                            items[i] = irew.getRewardItem();
                        }
                    }
                    Collections.shuffle(Arrays.asList(items));
                    chest.getInventory().setContents(items);
                }
            }
        }
    }, 0L);
    thm.setTreasureLocation(rpos);
    plugin.getLogger().info(MinigameUtils.formStr("minigame.treasurehunt.consSpawn", mgm.getName(false), rpos.getBlockX() + ", " + rpos.getBlockY() + ", " + rpos.getBlockZ()));
    MinigameUtils.broadcast(MinigameUtils.formStr("minigame.treasurehunt.plySpawn", maxradius, thm.getLocation()), mgm, "minigame.treasure.announce");
    mgm.setMinigameTimer(new MinigameTimer(mgm, mgm.getTimer()));
}
Also used : Chest(org.bukkit.block.Chest) ItemReward(au.com.mineauz.minigames.minigame.reward.ItemReward) MinigameTimer(au.com.mineauz.minigames.MinigameTimer) RewardsModule(au.com.mineauz.minigames.minigame.reward.RewardsModule) TreasureHuntModule(au.com.mineauz.minigames.minigame.modules.TreasureHuntModule) RewardType(au.com.mineauz.minigames.minigame.reward.RewardType) ItemStack(org.bukkit.inventory.ItemStack) StandardRewardScheme(au.com.mineauz.minigames.minigame.reward.scheme.StandardRewardScheme)

Example 4 with StandardRewardScheme

use of au.com.mineauz.minigames.minigame.reward.scheme.StandardRewardScheme 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 ignored) {
            }
        } 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) ItemStack(org.bukkit.inventory.ItemStack) StandardRewardScheme(au.com.mineauz.minigames.minigame.reward.scheme.StandardRewardScheme)

Aggregations

StandardRewardScheme (au.com.mineauz.minigames.minigame.reward.scheme.StandardRewardScheme)4 ItemStack (org.bukkit.inventory.ItemStack)3 Player (org.bukkit.entity.Player)2 MinigameTimer (au.com.mineauz.minigames.MinigameTimer)1 TreasureHuntModule (au.com.mineauz.minigames.minigame.modules.TreasureHuntModule)1 ItemReward (au.com.mineauz.minigames.minigame.reward.ItemReward)1 RewardType (au.com.mineauz.minigames.minigame.reward.RewardType)1 RewardsModule (au.com.mineauz.minigames.minigame.reward.RewardsModule)1 Chest (org.bukkit.block.Chest)1 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)1