Search in sources :

Example 1 with ConditionInterface

use of au.com.mineauz.minigamesregions.conditions.ConditionInterface in project Minigames by AddstarMC.

the class RegionModule method save.

@Override
public void save(FileConfiguration config) {
    Set<String> rs = regions.keySet();
    for (String name : rs) {
        Region r = regions.get(name);
        Map<String, Object> sloc = MinigameUtils.serializeLocation(r.getFirstPoint());
        for (String i : sloc.keySet()) {
            if (!i.equals("yaw") && !i.equals("pitch"))
                config.set(getMinigame() + ".regions." + name + ".point1." + i, sloc.get(i));
        }
        sloc = MinigameUtils.serializeLocation(r.getSecondPoint());
        for (String i : sloc.keySet()) {
            if (!i.equals("yaw") && !i.equals("pitch"))
                config.set(getMinigame() + ".regions." + name + ".point2." + i, sloc.get(i));
        }
        if (r.getTickDelay() != 20) {
            config.set(getMinigame() + ".regions." + name + ".tickDelay", r.getTickDelay());
        }
        int c = 0;
        for (RegionExecutor ex : r.getExecutors()) {
            String path = getMinigame() + ".regions." + name + ".executors." + c;
            config.set(path + ".trigger", ex.getTrigger().getName());
            int acc = 0;
            for (ActionInterface act : ex.getActions()) {
                config.set(path + ".actions." + acc + ".type", act.getName());
                act.saveArguments(config, path + ".actions." + acc + ".arguments");
                acc++;
            }
            acc = 0;
            for (ConditionInterface con : ex.getConditions()) {
                config.set(path + ".conditions." + acc + ".type", con.getName());
                con.saveArguments(config, path + ".conditions." + acc + ".arguments");
                acc++;
            }
            if (ex.isTriggerPerPlayer())
                config.set(path + ".isTriggeredPerPlayer", ex.isTriggerPerPlayer());
            if (ex.getTriggerCount() != 0)
                config.set(path + ".triggerCount", ex.getTriggerCount());
            c++;
        }
    }
    Set<String> ns = nodes.keySet();
    for (String name : ns) {
        Node n = nodes.get(name);
        Map<String, Object> sloc = MinigameUtils.serializeLocation(n.getLocation());
        for (String i : sloc.keySet()) {
            config.set(getMinigame() + ".nodes." + name + ".point." + i, sloc.get(i));
        }
        int c = 0;
        for (NodeExecutor ex : n.getExecutors()) {
            String path = getMinigame() + ".nodes." + name + ".executors." + c;
            config.set(path + ".trigger", ex.getTrigger().getName());
            int acc = 0;
            for (ActionInterface act : ex.getActions()) {
                config.set(path + ".actions." + acc + ".type", act.getName());
                act.saveArguments(config, path + ".actions." + acc + ".arguments");
                acc++;
            }
            acc = 0;
            for (ConditionInterface con : ex.getConditions()) {
                config.set(path + ".conditions." + acc + ".type", con.getName());
                con.saveArguments(config, path + ".conditions." + acc + ".arguments");
                acc++;
            }
            if (ex.isTriggerPerPlayer())
                config.set(path + ".isTriggeredPerPlayer", ex.isTriggerPerPlayer());
            if (ex.getTriggerCount() != 0)
                config.set(path + ".triggerCount", ex.getTriggerCount());
            c++;
        }
    }
}
Also used : RegionExecutor(au.com.mineauz.minigamesregions.executors.RegionExecutor) ActionInterface(au.com.mineauz.minigamesregions.actions.ActionInterface) ConditionInterface(au.com.mineauz.minigamesregions.conditions.ConditionInterface) MenuItemNode(au.com.mineauz.minigamesregions.menuitems.MenuItemNode) MenuItemRegion(au.com.mineauz.minigamesregions.menuitems.MenuItemRegion) NodeExecutor(au.com.mineauz.minigamesregions.executors.NodeExecutor)

Example 2 with ConditionInterface

use of au.com.mineauz.minigamesregions.conditions.ConditionInterface in project Minigames by AddstarMC.

the class RegionModule method load.

@Override
public void load(FileConfiguration config) {
    if (config.contains(getMinigame() + ".regions")) {
        Set<String> rs = config.getConfigurationSection(getMinigame() + ".regions").getKeys(false);
        for (String name : rs) {
            String cloc1 = getMinigame() + ".regions." + name + ".point1.";
            String cloc2 = getMinigame() + ".regions." + name + ".point2.";
            World w1 = Minigames.plugin.getServer().getWorld(config.getString(cloc1 + "world"));
            World w2 = Minigames.plugin.getServer().getWorld(config.getString(cloc2 + "world"));
            double x1 = config.getDouble(cloc1 + "x");
            double x2 = config.getDouble(cloc2 + "x");
            double y1 = config.getDouble(cloc1 + "y");
            double y2 = config.getDouble(cloc2 + "y");
            double z1 = config.getDouble(cloc1 + "z");
            double z2 = config.getDouble(cloc2 + "z");
            Location loc1 = new Location(w1, x1, y1, z1);
            Location loc2 = new Location(w2, x2, y2, z2);
            regions.put(name, new Region(name, loc1, loc2));
            Region r = regions.get(name);
            if (config.contains(getMinigame() + ".regions." + name + ".tickDelay")) {
                r.changeTickDelay(config.getLong(getMinigame() + ".regions." + name + ".tickDelay"));
            }
            if (config.contains(getMinigame() + ".regions." + name + ".executors")) {
                Set<String> ex = config.getConfigurationSection(getMinigame() + ".regions." + name + ".executors").getKeys(false);
                for (String i : ex) {
                    String path = getMinigame() + ".regions." + name + ".executors." + i;
                    RegionExecutor rex = new RegionExecutor(Triggers.getTrigger(config.getString(path + ".trigger")));
                    if (config.contains(path + ".actions")) {
                        for (String a : config.getConfigurationSection(path + ".actions").getKeys(false)) {
                            ActionInterface ai = Actions.getActionByName(config.getString(path + ".actions." + a + ".type"));
                            ai.loadArguments(config, path + ".actions." + a + ".arguments");
                            rex.addAction(ai);
                        }
                    }
                    if (config.contains(path + ".conditions")) {
                        for (String c : config.getConfigurationSection(path + ".conditions").getKeys(false)) {
                            ConditionInterface ci = Conditions.getConditionByName(config.getString(path + ".conditions." + c + ".type"));
                            ci.loadArguments(config, path + ".conditions." + c + ".arguments");
                            rex.addCondition(ci);
                        }
                    }
                    if (config.contains(path + ".isTriggeredPerPlayer"))
                        rex.setTriggerPerPlayer(config.getBoolean(path + ".isTriggeredPerPlayer"));
                    if (config.contains(path + ".triggerCount"))
                        rex.setTriggerCount(config.getInt(path + ".triggerCount"));
                    r.addExecutor(rex);
                }
            }
        }
    }
    if (config.contains(getMinigame() + ".nodes")) {
        Set<String> rs = config.getConfigurationSection(getMinigame() + ".nodes").getKeys(false);
        for (String name : rs) {
            String cloc1 = getMinigame() + ".nodes." + name + ".point.";
            World w1 = Minigames.plugin.getServer().getWorld(config.getString(cloc1 + "world"));
            double x1 = config.getDouble(cloc1 + "x");
            double y1 = config.getDouble(cloc1 + "y");
            double z1 = config.getDouble(cloc1 + "z");
            float yaw = 0f;
            float pitch = 0f;
            if (config.contains(cloc1 + "yaw")) {
                //TODO: Remove check after next dev build
                yaw = ((Double) config.getDouble(cloc1 + "yaw")).floatValue();
                pitch = ((Double) config.getDouble(cloc1 + "pitch")).floatValue();
            }
            Location loc1 = new Location(w1, x1, y1, z1, yaw, pitch);
            nodes.put(name, new Node(name, loc1));
            Node n = nodes.get(name);
            if (config.contains(getMinigame() + ".nodes." + name + ".executors")) {
                Set<String> ex = config.getConfigurationSection(getMinigame() + ".nodes." + name + ".executors").getKeys(false);
                for (String i : ex) {
                    String path = getMinigame() + ".nodes." + name + ".executors." + i;
                    NodeExecutor rex = new NodeExecutor(Triggers.getTrigger(config.getString(path + ".trigger")));
                    if (config.contains(path + ".actions")) {
                        for (String a : config.getConfigurationSection(path + ".actions").getKeys(false)) {
                            ActionInterface ai = Actions.getActionByName(config.getString(path + ".actions." + a + ".type"));
                            ai.loadArguments(config, path + ".actions." + a + ".arguments");
                            rex.addAction(ai);
                        }
                    }
                    if (config.contains(path + ".conditions")) {
                        for (String c : config.getConfigurationSection(path + ".conditions").getKeys(false)) {
                            ConditionInterface ci = Conditions.getConditionByName(config.getString(path + ".conditions." + c + ".type"));
                            ci.loadArguments(config, path + ".conditions." + c + ".arguments");
                            rex.addCondition(ci);
                        }
                    }
                    if (config.contains(path + ".isTriggeredPerPlayer"))
                        rex.setTriggerPerPlayer(config.getBoolean(path + ".isTriggeredPerPlayer"));
                    if (config.contains(path + ".triggerCount"))
                        rex.setTriggerCount(config.getInt(path + ".triggerCount"));
                    n.addExecutor(rex);
                }
            }
        }
    }
}
Also used : RegionExecutor(au.com.mineauz.minigamesregions.executors.RegionExecutor) ActionInterface(au.com.mineauz.minigamesregions.actions.ActionInterface) ConditionInterface(au.com.mineauz.minigamesregions.conditions.ConditionInterface) MenuItemNode(au.com.mineauz.minigamesregions.menuitems.MenuItemNode) MenuItemRegion(au.com.mineauz.minigamesregions.menuitems.MenuItemRegion) World(org.bukkit.World) Location(org.bukkit.Location) NodeExecutor(au.com.mineauz.minigamesregions.executors.NodeExecutor)

Example 3 with ConditionInterface

use of au.com.mineauz.minigamesregions.conditions.ConditionInterface in project Minigames by AddstarMC.

the class MenuItemConditionAdd method onClick.

@Override
public ItemStack onClick() {
    Menu m = new Menu(6, "Conditions", getContainer().getViewer());
    m.setPreviousPage(getContainer());
    Map<String, Menu> cats = new HashMap<String, Menu>();
    List<String> cons = new ArrayList<String>(Conditions.getAllConditionNames());
    Collections.sort(cons);
    for (String con : cons) {
        if ((Conditions.getConditionByName(con).useInNodes() && nexec != null) || (Conditions.getConditionByName(con).useInRegions() && rexec != null)) {
            String catname = Conditions.getConditionByName(con).getCategory();
            if (catname == null)
                catname = "misc conditions";
            catname.toLowerCase();
            Menu cat = null;
            if (!cats.containsKey(catname)) {
                cat = new Menu(6, MinigameUtils.capitalize(catname), getContainer().getViewer());
                cats.put(catname, cat);
                m.addItem(new MenuItemPage(MinigameUtils.capitalize(catname), Material.CHEST, cat));
                cat.addItem(new MenuItemPage("Back", Material.REDSTONE_TORCH_ON, m), cat.getSize() - 9);
            } else
                cat = cats.get(catname);
            MenuItemCustom c = new MenuItemCustom(MinigameUtils.capitalize(con), Material.PAPER);
            final String fcon = con;
            c.setClick(new InteractionInterface() {

                @Override
                public Object interact(Object object) {
                    ConditionInterface condition = Conditions.getConditionByName(fcon);
                    if (rexec != null) {
                        rexec.addCondition(condition);
                        getContainer().addItem(new MenuItemCondition(MinigameUtils.capitalize(fcon), Material.PAPER, rexec, condition));
                    } else {
                        nexec.addCondition(condition);
                        getContainer().addItem(new MenuItemCondition(MinigameUtils.capitalize(fcon), Material.PAPER, nexec, condition));
                    }
                    getContainer().displayMenu(getContainer().getViewer());
                    return null;
                }
            });
            cat.addItem(c);
        }
    }
    m.addItem(new MenuItemPage("Back", Material.REDSTONE_TORCH_ON, getContainer()), m.getSize() - 9);
    m.displayMenu(getContainer().getViewer());
    return null;
}
Also used : HashMap(java.util.HashMap) MenuItemPage(au.com.mineauz.minigames.menu.MenuItemPage) ArrayList(java.util.ArrayList) MenuItemCustom(au.com.mineauz.minigames.menu.MenuItemCustom) InteractionInterface(au.com.mineauz.minigames.menu.InteractionInterface) ConditionInterface(au.com.mineauz.minigamesregions.conditions.ConditionInterface) Menu(au.com.mineauz.minigames.menu.Menu)

Aggregations

ConditionInterface (au.com.mineauz.minigamesregions.conditions.ConditionInterface)3 ActionInterface (au.com.mineauz.minigamesregions.actions.ActionInterface)2 NodeExecutor (au.com.mineauz.minigamesregions.executors.NodeExecutor)2 RegionExecutor (au.com.mineauz.minigamesregions.executors.RegionExecutor)2 MenuItemNode (au.com.mineauz.minigamesregions.menuitems.MenuItemNode)2 MenuItemRegion (au.com.mineauz.minigamesregions.menuitems.MenuItemRegion)2 InteractionInterface (au.com.mineauz.minigames.menu.InteractionInterface)1 Menu (au.com.mineauz.minigames.menu.Menu)1 MenuItemCustom (au.com.mineauz.minigames.menu.MenuItemCustom)1 MenuItemPage (au.com.mineauz.minigames.menu.MenuItemPage)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Location (org.bukkit.Location)1 World (org.bukkit.World)1