Search in sources :

Example 1 with Objective

use of pixelssky.objects.objectives.Objective in project PixelsSkyblock by dudullle.

the class ChallengesManager method init_subChallenges.

public static void init_subChallenges() {
    for (Challenge categ : challenges) {
        File folder = new File("plugins/PixelsSky/Challenges/" + categ.getName());
        for (File f : folder.listFiles()) {
            if (!f.isDirectory()) {
                ArrayList<String> lines = FileManager.ReadAllText(f.getAbsolutePath());
                ArrayList<Objective> obj = new ArrayList<Objective>();
                ArrayList<Reward> rewards = new ArrayList<Reward>();
                String c_name = null;
                int type = -1;
                boolean can_redo = false;
                Material m = null;
                int subid = 0;
                boolean isUnlocked = false;
                for (String l : lines) {
                    if (l.split("=")[0].equals("name")) {
                        c_name = l.split("=")[1];
                    } else if (l.split("=")[0].equals("unlocked_by_default")) {
                        isUnlocked = Boolean.parseBoolean(l.split("=")[1]);
                    } else if (l.split("=")[0].equals("type")) {
                        type = Integer.parseInt(l.split("=")[1]);
                    } else if (l.split("=")[0].equals("material")) {
                        m = Material.getMaterial(Integer.parseInt(l.split("=")[1]));
                    } else if (l.split("=")[0].equals("subid")) {
                        subid = Integer.parseInt(l.split("=")[1]);
                    } else if (l.split("=")[0].equals("can_redo")) {
                        can_redo = Boolean.parseBoolean((l.split("=")[1]));
                    } else if (l.split("=")[0].equals("objective")) {
                        String[] s = l.split("=")[1].split(",");
                        if (s[0].equals("inventory")) {
                            obj.add(new InventoryObjective(Integer.parseInt(s[1]), Integer.parseInt(s[2]), Integer.parseInt(s[3]), s[4].equals("take")));
                        } else if (s[0].equals("onisland")) {
                            if (s[1].equals("block")) {
                                obj.add(new OnislandObjective(s[1].equals("entity"), Integer.parseInt(s[2]), Integer.parseInt(s[3]), Integer.parseInt(s[4])));
                            } else {
                                obj.add(new OnislandObjective(s[1].equals("entity"), s[2], Integer.parseInt(s[3]), Integer.parseInt(s[4])));
                            }
                        } else if (s[0].equals("stats")) {
                            obj.add(new StatsObjective(s[1], s[2], s[3]));
                        }
                    } else if (l.split("=")[0].equals("reward")) {
                        String[] s = l.split("=")[1].split(",");
                        if (s[0].equals("give")) {
                            if (s[4].split(":").length > 1) {
                                TreeMap<String, Integer> e = new TreeMap<String, Integer>();
                                for (String ench : s[4].split(":")[1].split(";")) {
                                    e.put(ench.split("/")[0], Integer.parseInt(ench.split("/")[1]));
                                }
                                rewards.add(new GiveReward(Integer.parseInt(s[1]), Integer.parseInt(s[2]), Integer.parseInt(s[3]), e));
                            } else {
                                rewards.add(new GiveReward(Integer.parseInt(s[1]), Integer.parseInt(s[2]), Integer.parseInt(s[3])));
                            }
                        } else if (s[0].equals("command")) {
                            rewards.add(new CommandReward(s[1], s[2]));
                        } else if (s[0].equals("stats")) {
                            rewards.add(new StatsReward(s[1], s[2], s[3]));
                        }
                    }
                }
                categ.getSubChallenges().add(new Challenge(type, c_name, obj, rewards, can_redo, m, subid, isUnlocked));
            }
        }
    }
}
Also used : StatsObjective(pixelssky.objects.objectives.StatsObjective) GiveReward(pixelssky.rewards.GiveReward) ArrayList(java.util.ArrayList) OnislandObjective(pixelssky.objects.objectives.OnislandObjective) Material(org.bukkit.Material) StatsReward(pixelssky.rewards.StatsReward) TreeMap(java.util.TreeMap) Challenge(pixelssky.objects.Challenge) InventoryObjective(pixelssky.objects.objectives.InventoryObjective) Objective(pixelssky.objects.objectives.Objective) OnislandObjective(pixelssky.objects.objectives.OnislandObjective) InventoryObjective(pixelssky.objects.objectives.InventoryObjective) StatsObjective(pixelssky.objects.objectives.StatsObjective) CommandReward(pixelssky.rewards.CommandReward) CommandReward(pixelssky.rewards.CommandReward) StatsReward(pixelssky.rewards.StatsReward) GiveReward(pixelssky.rewards.GiveReward) Reward(pixelssky.rewards.Reward) File(java.io.File)

Example 2 with Objective

use of pixelssky.objects.objectives.Objective in project PixelsSkyblock by dudullle.

the class Challenge method getItem.

public ItemStack getItem(Island i) {
    if (!isUnlocked(i)) {
        return Items.get("§4Challenge / niveau bloqué ! §c" + name, Material.BARRIER, (byte) 0);
    }
    ArrayList<String> lore = new ArrayList<String>();
    lore.add("§b▊▊▊▊▊▊▊▊   Objectif(s) ▊▊▊▊▊▊▊▊");
    for (Objective o : obj) {
        lore.add(o.getDescription());
    }
    lore.add("§b▊▊▊▊▊▊▊   Récompense(s) ▊▊▊▊▊▊▊");
    for (Reward r : rewards) {
        lore.add(r.getDescription());
    }
    if (this.isCompleted(i)) {
        if (can_redo) {
            lore.add("§7Vous avez déjà complété ce challenge");
            lore.add("§7§lMAIS vous pouvez le refaire !");
        } else {
            lore.add("§7Ce challenge n'est pas refaisable §l:/");
        }
        ItemStack it = Items.get(this.name, m, (byte) this.i, lore);
        it.addUnsafeEnchantment(Enchantements.VALIDATED_CHALLENGE, 1);
        return it;
    } else {
        return Items.get(this.name, m, (byte) this.i, lore);
    }
}
Also used : Objective(pixelssky.objects.objectives.Objective) ArrayList(java.util.ArrayList) CommandReward(pixelssky.rewards.CommandReward) Reward(pixelssky.rewards.Reward) ItemStack(org.bukkit.inventory.ItemStack)

Example 3 with Objective

use of pixelssky.objects.objectives.Objective in project PixelsSkyblock by dudullle.

the class Challenge method complete.

@SuppressWarnings("deprecation")
public void complete(Player p, Island i) {
    if ((!isCompleted(i) && isUnlocked(i)) || (isCompleted(i) && can_redo)) {
        Bukkit.getScheduler().runTaskAsynchronously(Bukkit.getPluginManager().getPlugin("PixelsSkyblock"), new Runnable() {

            @Override
            public void run() {
                p.sendTitle("§c⚠§4§lCalcul en cours§c⚠", "§eVeuillez patienter", 10, 1000, 10);
                p.playSound(p.getLocation(), Sound.BLOCK_LAVA_EXTINGUISH, 100, 100);
                boolean ok = true;
                for (Objective o : obj) {
                    if (!o.check(p, i)) {
                        ok = false;
                        p.sendMessage(o.getFailMessage(p));
                    }
                }
                if (ok) {
                    for (Objective o : obj) {
                        o.run(p, i);
                    }
                    for (Reward r : rewards) {
                        if (!(r instanceof CommandReward)) {
                            r.run(p, i);
                        }
                    }
                    p.sendTitle("§aChallenge complété !", "§2" + name, 10, 10, 100);
                    i.addOrSetData("completed" + getName(), "" + true);
                    p.playSound(p.getLocation(), Sound.BLOCK_END_PORTAL_SPAWN, 100, 100);
                    for (int k = 0; k < 10; k++) {
                        p.playEffect(p.getLocation().subtract(k, k, k), Effect.SMOKE, k);
                        p.playEffect(p.getLocation().subtract(-k, -k, -k), Effect.SMOKE, k);
                        p.playEffect(p.getLocation().subtract(-k, k, k), Effect.SMOKE, k);
                        p.playEffect(p.getLocation().subtract(k, k, -k), Effect.SMOKE, k);
                        p.playEffect(p.getLocation().subtract(-k, -k, k), Effect.SMOKE, k);
                        p.playEffect(p.getLocation().subtract(k, -k, -k), Effect.SMOKE, k);
                        p.playEffect(p.getLocation().subtract(-k, k, -k), Effect.SMOKE, k);
                        p.playEffect(p.getLocation().subtract(k, -k, k), Effect.SMOKE, k);
                    }
                } else {
                    p.sendTitle("§cChallenge raté :/", "§4" + name, 10, 10, 100);
                    p.playSound(p.getLocation(), Sound.ENTITY_ENDERDRAGON_GROWL, 100, 100);
                }
            }
        });
        for (Reward r : rewards) {
            if (r instanceof CommandReward) {
                r.run(p, i);
            }
        }
    } else {
        p.sendTitle("§c⚠§4§lImpossible de faire§c⚠", "§eCe challenge n'est pas refaisable ou débloqué", 10, 1000, 10);
        p.playSound(p.getLocation(), Sound.ENTITY_ENDERDRAGON_GROWL, 100, 100);
    }
}
Also used : Objective(pixelssky.objects.objectives.Objective) CommandReward(pixelssky.rewards.CommandReward) CommandReward(pixelssky.rewards.CommandReward) Reward(pixelssky.rewards.Reward)

Aggregations

Objective (pixelssky.objects.objectives.Objective)3 CommandReward (pixelssky.rewards.CommandReward)3 Reward (pixelssky.rewards.Reward)3 ArrayList (java.util.ArrayList)2 File (java.io.File)1 TreeMap (java.util.TreeMap)1 Material (org.bukkit.Material)1 ItemStack (org.bukkit.inventory.ItemStack)1 Challenge (pixelssky.objects.Challenge)1 InventoryObjective (pixelssky.objects.objectives.InventoryObjective)1 OnislandObjective (pixelssky.objects.objectives.OnislandObjective)1 StatsObjective (pixelssky.objects.objectives.StatsObjective)1 GiveReward (pixelssky.rewards.GiveReward)1 StatsReward (pixelssky.rewards.StatsReward)1