Search in sources :

Example 6 with NodeExecutor

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

the class TriggerRandomAction method executeNodeAction.

@Override
public void executeNodeAction(MinigamePlayer player, Node node) {
    List<NodeExecutor> exs = new ArrayList<>();
    for (NodeExecutor ex : node.getExecutors()) {
        if (ex.getTrigger().getName().equalsIgnoreCase("RANDOM"))
            exs.add(ex);
    }
    Collections.shuffle(exs);
    if (timesTriggered.getFlag() == 1) {
        if (node.checkConditions(exs.get(0), player) && exs.get(0).canBeTriggered(player))
            node.execute(exs.get(0), player);
    } else {
        for (int i = 0; i < timesTriggered.getFlag(); i++) {
            if (!randomPerTrigger.getFlag()) {
                if (i == timesTriggered.getFlag())
                    break;
                if (node.checkConditions(exs.get(i), player) && exs.get(i).canBeTriggered(player))
                    node.execute(exs.get(i), player);
            } else {
                if (node.checkConditions(exs.get(0), player) && exs.get(0).canBeTriggered(player))
                    node.execute(exs.get(0), player);
                Collections.shuffle(exs);
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) NodeExecutor(au.com.mineauz.minigamesregions.executors.NodeExecutor)

Aggregations

NodeExecutor (au.com.mineauz.minigamesregions.executors.NodeExecutor)6 RegionExecutor (au.com.mineauz.minigamesregions.executors.RegionExecutor)4 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 MinigamePlayer (au.com.mineauz.minigames.MinigamePlayer)1 Menu (au.com.mineauz.minigames.menu.Menu)1 MenuItem (au.com.mineauz.minigames.menu.MenuItem)1 MenuItemPage (au.com.mineauz.minigames.menu.MenuItemPage)1 Minigame (au.com.mineauz.minigames.minigame.Minigame)1 Location (org.bukkit.Location)1 World (org.bukkit.World)1 EventHandler (org.bukkit.event.EventHandler)1