Search in sources :

Example 1 with ActionInterface

use of au.com.mineauz.minigamesregions.actions.ActionInterface 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 ActionInterface

use of au.com.mineauz.minigamesregions.actions.ActionInterface 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 ActionInterface

use of au.com.mineauz.minigamesregions.actions.ActionInterface in project Minigames by AddstarMC.

the class MenuItemActionAdd method onClick.

@Override
public ItemStack onClick() {
    Menu m = new Menu(6, "Actions", getContainer().getViewer());
    m.setPreviousPage(getContainer());
    Map<String, Menu> cats = new HashMap<>();
    List<String> acts = new ArrayList<>(Actions.getAllActionNames());
    Collections.sort(acts);
    for (String act : acts) {
        if ((Actions.getActionByName(act).useInNodes() && exec != null) || (Actions.getActionByName(act).useInRegions() && exec != null)) {
            String catname = Actions.getActionByName(act).getCategory();
            if (catname == null)
                catname = "misc actions";
            catname = catname.toLowerCase();
            Menu cat;
            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(act), Material.PAPER);
            final String fact = act;
            c.setClick(new InteractionInterface() {

                @Override
                public Object interact(Object object) {
                    ActionInterface action = Actions.getActionByName(fact);
                    if (exec == null) {
                        exec.addAction(action);
                        getContainer().addItem(new MenuItemAction(MinigameUtils.capitalize(fact), Material.PAPER, exec, action));
                        getContainer().displayMenu(getContainer().getViewer());
                    } else {
                        exec.addAction(action);
                        getContainer().addItem(new MenuItemAction(MinigameUtils.capitalize(fact), Material.PAPER, exec, action));
                        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) ActionInterface(au.com.mineauz.minigamesregions.actions.ActionInterface) Menu(au.com.mineauz.minigames.menu.Menu)

Aggregations

ActionInterface (au.com.mineauz.minigamesregions.actions.ActionInterface)3 ConditionInterface (au.com.mineauz.minigamesregions.conditions.ConditionInterface)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