Search in sources :

Example 1 with RegionExecutor

use of au.com.mineauz.minigamesregions.executors.RegionExecutor 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 RegionExecutor

use of au.com.mineauz.minigamesregions.executors.RegionExecutor 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 RegionExecutor

use of au.com.mineauz.minigamesregions.executors.RegionExecutor in project Minigames by AddstarMC.

the class RegionEvents method playerQuit.

@EventHandler(ignoreCancelled = true)
private void playerQuit(QuitMinigameEvent event) {
    MinigamePlayer ply = event.getMinigamePlayer();
    if (ply == null)
        return;
    Minigame mg = ply.getMinigame();
    for (Region r : RegionModule.getMinigameModule(mg).getRegions()) {
        if (r.hasPlayer(ply))
            r.removePlayer(ply);
    }
    for (Node node : RegionModule.getMinigameModule(event.getMinigame()).getNodes()) {
        node.execute(Triggers.getTrigger("GAME_QUIT"), event.getMinigamePlayer());
        if (event.getMinigame().getPlayers().size() > 1) {
            for (NodeExecutor exec : node.getExecutors()) exec.removeTrigger(event.getMinigamePlayer());
        } else {
            for (NodeExecutor exec : node.getExecutors()) exec.clearTriggers();
            node.setEnabled(true);
        }
    }
    for (Region region : RegionModule.getMinigameModule(event.getMinigame()).getRegions()) {
        if (region.playerInRegion(ply))
            region.execute(Triggers.getTrigger("GAME_QUIT"), event.getMinigamePlayer());
        if (event.getMinigame().getPlayers().size() > 1) {
            for (RegionExecutor exec : region.getExecutors()) exec.removeTrigger(event.getMinigamePlayer());
        } else {
            for (RegionExecutor exec : region.getExecutors()) {
                exec.clearTriggers();
            }
            region.removeTickTask();
            region.setEnabled(true);
        }
    }
}
Also used : MinigamePlayer(au.com.mineauz.minigames.MinigamePlayer) RegionExecutor(au.com.mineauz.minigamesregions.executors.RegionExecutor) Minigame(au.com.mineauz.minigames.minigame.Minigame) NodeExecutor(au.com.mineauz.minigamesregions.executors.NodeExecutor) EventHandler(org.bukkit.event.EventHandler)

Example 4 with RegionExecutor

use of au.com.mineauz.minigamesregions.executors.RegionExecutor in project Minigames by AddstarMC.

the class RegionEvents method playerJoin.

@EventHandler(ignoreCancelled = true)
private void playerJoin(JoinMinigameEvent event) {
    final MinigamePlayer ply = event.getMinigamePlayer();
    if (ply == null)
        return;
    final Minigame mg = event.getMinigame();
    Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {

        @Override
        public void run() {
            executeRegionChanges(mg, ply);
            for (Node node : RegionModule.getMinigameModule(mg).getNodes()) {
                node.execute(Triggers.getTrigger("GAME_JOIN"), ply);
            }
            for (Region region : RegionModule.getMinigameModule(mg).getRegions()) {
                if (region.hasPlayer(ply))
                    region.execute(Triggers.getTrigger("GAME_JOIN"), ply);
            }
        }
    });
    if (event.getMinigame().getPlayers().size() == 0) {
        for (Region region : RegionModule.getMinigameModule(event.getMinigame()).getRegions()) {
            for (RegionExecutor ex : region.getExecutors()) {
                if (ex.getTrigger().getName().equalsIgnoreCase("TICK")) {
                    region.startTickTask();
                    break;
                }
            }
        }
    }
}
Also used : MinigamePlayer(au.com.mineauz.minigames.MinigamePlayer) RegionExecutor(au.com.mineauz.minigamesregions.executors.RegionExecutor) Minigame(au.com.mineauz.minigames.minigame.Minigame) EventHandler(org.bukkit.event.EventHandler)

Example 5 with RegionExecutor

use of au.com.mineauz.minigamesregions.executors.RegionExecutor in project Minigames by AddstarMC.

the class MenuItemRegion method createMenu.

public static Menu createMenu(MinigamePlayer viewer, Menu previousPage, Region region) {
    Menu m = new Menu(3, "Region: " + region.getName(), viewer);
    m.setPreviousPage(previousPage);
    List<MenuItem> items = new ArrayList<>();
    for (RegionExecutor ex : region.getExecutors()) {
        items.add(new MenuItemRegionExecutor(region, ex));
    }
    if (previousPage != null) {
        m.addItem(new MenuItemPage("Back", Material.REDSTONE_TORCH_ON, previousPage), m.getSize() - 9);
    }
    m.addItem(new MenuItemRegionExecutorAdd("Add Executor", Material.ITEM_FRAME, region), m.getSize() - 1);
    m.addItems(items);
    return m;
}
Also used : RegionExecutor(au.com.mineauz.minigamesregions.executors.RegionExecutor) MenuItemPage(au.com.mineauz.minigames.menu.MenuItemPage) ArrayList(java.util.ArrayList) MenuItem(au.com.mineauz.minigames.menu.MenuItem) Menu(au.com.mineauz.minigames.menu.Menu)

Aggregations

RegionExecutor (au.com.mineauz.minigamesregions.executors.RegionExecutor)7 NodeExecutor (au.com.mineauz.minigamesregions.executors.NodeExecutor)4 MinigamePlayer (au.com.mineauz.minigames.MinigamePlayer)2 Minigame (au.com.mineauz.minigames.minigame.Minigame)2 ActionInterface (au.com.mineauz.minigamesregions.actions.ActionInterface)2 ConditionInterface (au.com.mineauz.minigamesregions.conditions.ConditionInterface)2 MenuItemNode (au.com.mineauz.minigamesregions.menuitems.MenuItemNode)2 MenuItemRegion (au.com.mineauz.minigamesregions.menuitems.MenuItemRegion)2 ArrayList (java.util.ArrayList)2 EventHandler (org.bukkit.event.EventHandler)2 Menu (au.com.mineauz.minigames.menu.Menu)1 MenuItem (au.com.mineauz.minigames.menu.MenuItem)1 MenuItemPage (au.com.mineauz.minigames.menu.MenuItemPage)1 Location (org.bukkit.Location)1 World (org.bukkit.World)1