Search in sources :

Example 1 with AbstractTriggerManager

use of io.github.wysohn.triggerreactor.core.manager.trigger.AbstractTriggerManager in project TriggerReactor by wysohn.

the class TriggerReactorCore method onCommand.

public boolean onCommand(ICommandSender sender, String command, String[] args) {
    if (command.equalsIgnoreCase("triggerreactor")) {
        if (!sender.hasPermission(PERMISSION))
            return true;
        if (!isEnabled()) {
            sender.sendMessage("&cTriggerReactor is disabled. Check your latest.log to see why the plugin is not" + " loaded properly. If there was an error while loading, please report it through github issue" + " or our discord channel.");
            return true;
        }
        if (args.length > 0) {
            if (args[0].equalsIgnoreCase("debug")) {
                debugging = !debugging;
                String color;
                if (debugging) {
                    color = "a";
                } else {
                    color = "c";
                }
                sender.sendMessage("Debugging is set to &" + color + debugging);
                getLogger().info("Debugging state: " + debugging);
                return true;
            } else if (args[0].equalsIgnoreCase("version")) {
                sender.sendMessage("Current version: " + getVersion());
                return true;
            } else if (args[0].equalsIgnoreCase("click") || args[0].equalsIgnoreCase("c")) {
                if (args.length == 1) {
                    getScriptEditManager().startEdit(sender, "Click Trigger", "", new SaveHandler() {

                        @Override
                        public void onSave(String script) {
                            if (getClickManager().startLocationSet((IPlayer) sender, script)) {
                                sender.sendMessage("&7Now click the block to set click trigger.");
                            } else {
                                sender.sendMessage("&7Already on progress.");
                            }
                        }
                    });
                } else {
                    StringBuilder builder = new StringBuilder();
                    for (int i = 1; i < args.length; i++) builder.append(args[i]).append(" ");
                    if (getClickManager().startLocationSet((IPlayer) sender, builder.toString())) {
                        sender.sendMessage("&7Now click the block to set click trigger.");
                    } else {
                        sender.sendMessage("&7Already on progress.");
                    }
                }
                return true;
            } else if (args[0].equalsIgnoreCase("walk") || args[0].equalsIgnoreCase("w")) {
                if (args.length == 1) {
                    getScriptEditManager().startEdit(sender, "Walk Trigger", "", new SaveHandler() {

                        @Override
                        public void onSave(String script) {
                            if (getWalkManager().startLocationSet((IPlayer) sender, script)) {
                                sender.sendMessage("&7Now click the block to set walk trigger.");
                            } else {
                                sender.sendMessage("&7Already on progress.");
                            }
                        }
                    });
                } else {
                    StringBuilder builder = new StringBuilder();
                    for (int i = 1; i < args.length; i++) builder.append(args[i]).append(" ");
                    if (getWalkManager().startLocationSet((IPlayer) sender, builder.toString())) {
                        sender.sendMessage("&7Now click the block to set walk trigger.");
                    } else {
                        sender.sendMessage("&7Already on progress.");
                    }
                }
                return true;
            } else if (args.length > 1 && (args[0].equalsIgnoreCase("command") || args[0].equalsIgnoreCase("cmd"))) {
                if (args.length == 3 && getCmdManager().has(args[1]) && args[2].equals("sync")) {
                    Trigger trigger = getCmdManager().get(args[1]);
                    trigger.setSync(!trigger.isSync());
                    sender.sendMessage("&7Sync mode: " + (trigger.isSync() ? "&a" : "&c") + trigger.isSync());
                    saveAsynchronously(getCmdManager());
                } else if (args.length > 2 && getCmdManager().has(args[1]) && (args[2].equals("p") || args[2].equals("permission"))) {
                    CommandTrigger trigger = getCmdManager().get(args[1]);
                    // if no permission is given, delete all permission required
                    String[] permissions = null;
                    if (args.length == 3) {
                        trigger.setPermissions(null);
                    } else {
                        permissions = new String[args.length - 3];
                        for (int i = 3; i < args.length; i++) {
                            permissions[i - 3] = args[i];
                        }
                        trigger.setPermissions(permissions);
                    }
                    if (permissions == null) {
                        sender.sendMessage("&7Cleared permissions");
                    } else {
                        sender.sendMessage("&7Set permissions.");
                    }
                    saveAsynchronously(getCmdManager());
                } else if (args.length > 2 && getCmdManager().has(args[1]) && (args[2].equals("a") || args[2].equals("aliases"))) {
                    CommandTrigger trigger = getCmdManager().get(args[1]);
                    // if no aliases are given, delete all aliases
                    String[] aliases = null;
                    if (args.length == 3) {
                        trigger.setAliases(null);
                    } else {
                        aliases = new String[args.length - 3];
                        for (int i = 3; i < args.length; i++) {
                            aliases[i - 3] = args[i];
                        }
                        trigger.setAliases(aliases);
                    }
                    if (aliases == null) {
                        sender.sendMessage("&7Cleared aliases");
                    } else {
                        sender.sendMessage("&7Set Aliases");
                    }
                    saveAsynchronously(getCmdManager());
                    getCmdManager().reregisterCommand(args[1]);
                } else if (args.length > 2 && getCmdManager().has(args[1]) && (args[2].equals("tab") || args[2].equals("settab"))) {
                    TriggerInfo info = Optional.of(getCmdManager()).map(man -> man.get(args[1])).map(Trigger::getInfo).orElseThrow(() -> new RuntimeException("Missing TriggerInfo"));
                    // trg cmd <name> settab a b c
                    List<Map<String, Object>> tabs = new ArrayList<>();
                    for (int i = 3; i < args.length; i++) {
                        String[] split = args[i].split(":", 2);
                        String hint = split.length == 2 ? split[0] : null;
                        String values = split.length == 2 ? split[1] : split[0];
                        Map<String, Object> tab = new LinkedHashMap<>();
                        if (hint != null)
                            tab.put(AbstractCommandTriggerManager.HINT, hint);
                        tab.put(AbstractCommandTriggerManager.CANDIDATES, values);
                        tabs.add(tab);
                    }
                    info.getConfig().put(AbstractCommandTriggerManager.TABS, tabs);
                    getCmdManager().reload(args[1]);
                    sender.sendMessage("&7Set tab-completer");
                } else if (getCmdManager().has(args[1])) {
                    Trigger trigger = getCmdManager().get(args[1]);
                    getScriptEditManager().startEdit(sender, trigger.getInfo().getTriggerName(), trigger.getScript(), new SaveHandler() {

                        @Override
                        public void onSave(String script) {
                            try {
                                trigger.setScript(script);
                            } catch (Exception e) {
                                handleException(sender, e);
                            }
                            sender.sendMessage("&aScript is updated!");
                            saveAsynchronously(getCmdManager());
                        }
                    });
                } else {
                    if (args.length == 2) {
                        getScriptEditManager().startEdit(sender, "Command Trigger", "", new SaveHandler() {

                            @Override
                            public void onSave(String script) {
                                getCmdManager().addCommandTrigger(sender, args[1], script);
                                sender.sendMessage("&aCommand trigger is binded!");
                                saveAsynchronously(getCmdManager());
                            }
                        });
                    } else {
                        StringBuilder builder = new StringBuilder();
                        for (int i = 2; i < args.length; i++) builder.append(args[i] + " ");
                        getCmdManager().addCommandTrigger(sender, args[1], builder.toString());
                        sender.sendMessage("&aCommand trigger is binded!");
                        saveAsynchronously(getCmdManager());
                    }
                }
                return true;
            } else if ((args[0].equalsIgnoreCase("variables") || args[0].equalsIgnoreCase("vars"))) {
                if (args.length == 3) {
                    if (args[1].equalsIgnoreCase("Item")) {
                        String name = args[2];
                        if (!GlobalVariableManager.isValidName(name)) {
                            sender.sendMessage("&c" + name + " is not a valid key!");
                            return true;
                        }
                        IItemStack IS = ((IPlayer) sender).getItemInMainHand();
                        if (IS == null) {
                            sender.sendMessage("&c" + "You are holding nothing on your main hand!");
                            return true;
                        }
                        try {
                            getVariableManager().put(name, IS.get());
                        } catch (Exception e) {
                            this.handleException(sender, e);
                        }
                        sender.sendMessage("&aItem saved!");
                    } else if (args[1].equalsIgnoreCase("Location")) {
                        String name = args[2];
                        if (!GlobalVariableManager.isValidName(name)) {
                            sender.sendMessage("&c" + name + " is not a valid key!");
                            return true;
                        }
                        ILocation loc = ((IPlayer) sender).getLocation();
                        try {
                            getVariableManager().put(name, loc.get());
                        } catch (Exception e) {
                            this.handleException(sender, e);
                        }
                        sender.sendMessage("&aLocation saved!");
                    } else {
                        String name = args[1];
                        String value = args[2];
                        if (!GlobalVariableManager.isValidName(name)) {
                            sender.sendMessage("&c" + name + " is not a valid key!");
                            return true;
                        }
                        if (INTEGER_PATTERN.matcher(value).matches()) {
                            try {
                                getVariableManager().put(name, Integer.parseInt(value));
                            } catch (Exception e) {
                                this.handleException(sender, e);
                            }
                        } else if (DECIMAL_PATTERN.matcher(value).matches()) {
                            try {
                                getVariableManager().put(name, Double.parseDouble(value));
                            } catch (Exception e) {
                                this.handleException(sender, e);
                            }
                        } else if (value.equals("true") || value.equals("false")) {
                            try {
                                getVariableManager().put(name, Boolean.parseBoolean(value));
                            } catch (Exception e) {
                                this.handleException(sender, e);
                            }
                        } else {
                            try {
                                getVariableManager().put(name, value);
                            } catch (Exception e) {
                                this.handleException(sender, e);
                            }
                        }
                        sender.sendMessage("&aVariable saved!");
                    }
                    return true;
                } else if (args.length == 2) {
                    String name = args[1];
                    sender.sendMessage("&7Value of " + name + ": " + getVariableManager().get(name));
                    return true;
                }
            } else if (args.length > 1 && args[0].equalsIgnoreCase("run")) {
                String script = mergeArguments(args, 1, args.length - 1);
                try {
                    Trigger trigger = getCmdManager().createTempCommandTrigger(script);
                    trigger.activate(createEmptyPlayerEvent(sender), new HashMap<>());
                } catch (Exception e) {
                    handleException(sender, e);
                }
                return true;
            } else if (args.length > 2 && args[0].equalsIgnoreCase("sudo")) {
                String playerName = args[1];
                String script = mergeArguments(args, 2, args.length - 1);
                IPlayer targetPlayer = getPlayer(playerName);
                if (targetPlayer == null) {
                    sender.sendMessage("&cNo such player named &6" + playerName + "&c!");
                    return true;
                }
                try {
                    Trigger trigger = getCmdManager().createTempCommandTrigger(script);
                    trigger.activate(createEmptyPlayerEvent(targetPlayer), new HashMap<>());
                } catch (Exception e) {
                    handleException(sender, e);
                }
                return true;
            } else if (args.length > 1 && args[0].equalsIgnoreCase("call")) {
                String namedTriggerName = args[1];
                String script = args.length > 2 ? mergeArguments(args, 2, args.length - 1) : "";
                try {
                    Trigger trigger = getCmdManager().createTempCommandTrigger(script);
                    Trigger targetTrigger = getNamedTriggerManager().get(namedTriggerName);
                    if (targetTrigger == null) {
                        sender.sendMessage("&cCannot find &6" + namedTriggerName + "&c! &7Remember that the folder" + " hierarchy is represented with ':' sign. (ex. FolderA:FolderB:Trigger)");
                        return true;
                    }
                    // shares same variable space
                    Map<String, Object> variables = new HashMap<>();
                    trigger.activate(createEmptyPlayerEvent(sender), variables);
                    targetTrigger.activate(createEmptyPlayerEvent(sender), variables);
                } catch (Exception e) {
                    handleException(sender, e);
                }
                return true;
            } else if (args[0].equalsIgnoreCase("inventory") || args[0].equalsIgnoreCase("i")) {
                if (args.length > 3 && args[2].equalsIgnoreCase("create")) {
                    String name = args[1];
                    int size = -1;
                    try {
                        size = Integer.parseInt(args[3]);
                    } catch (NumberFormatException e) {
                        sender.sendMessage("&c" + "" + size + " is not a valid number");
                        return true;
                    }
                    if (size > 54 || size < 9) {
                        sender.sendMessage("&csize must be between 9 and 54");
                        return true;
                    }
                    if (size % 9 != 0) {
                        sender.sendMessage("&csize must be a multiple of 9");
                        return true;
                    }
                    if (args.length == 4) {
                        final int sizeCopy = size;
                        getScriptEditManager().startEdit(sender, "Inventory Trigger", "", new SaveHandler() {

                            @Override
                            public void onSave(String script) {
                                try {
                                    if (getInvManager().createTrigger(sizeCopy, name, script)) {
                                        sender.sendMessage("&aInventory Trigger created!");
                                        saveAsynchronously(getInvManager());
                                    } else {
                                        sender.sendMessage("&7Another Inventory Trigger with that name already exists");
                                    }
                                } catch (Exception e) {
                                    handleException(sender, e);
                                }
                            }
                        });
                    } else {
                        String script = mergeArguments(args, 4, args.length - 1);
                        try {
                            if (getInvManager().createTrigger(size, name, script)) {
                                sender.sendMessage("&aInventory Trigger created!");
                                saveAsynchronously(getInvManager());
                            } else {
                                sender.sendMessage("&7Another Inventory Trigger with that name already exists");
                            }
                        } catch (Exception e) {
                            handleException(sender, e);
                        }
                    }
                } else if (args.length == 3 && args[2].equalsIgnoreCase("delete")) {
                    String name = args[1];
                    if (getInvManager().remove(name) != null) {
                        sender.sendMessage("&aDeleted!");
                        saveAsynchronously(getInvManager());
                    } else {
                        sender.sendMessage("&7No such inventory trigger found.");
                    }
                } else if (args.length == 4 && args[2].equals("item")) {
                    IItemStack IS = ((IPlayer) sender).getItemInMainHand();
                    IS = IS == null ? null : IS.clone();
                    String name = args[1];
                    int index;
                    try {
                        index = Integer.parseInt(args[3]);
                    } catch (NumberFormatException e) {
                        sender.sendMessage("&c" + "" + args[3] + " is not a valid number.");
                        return true;
                    }
                    InventoryTrigger trigger = getInvManager().get(name);
                    if (trigger == null) {
                        sender.sendMessage("&7No such Inventory Trigger named " + name);
                        return true;
                    }
                    if (index > trigger.getItems().length || index < 1) {
                        sender.sendMessage("&c" + "" + index + " is out of bounds. (Size: " + (trigger.getItems().length) + ")");
                        return true;
                    }
                    trigger.getItems()[index - 1] = IS;
                    saveAsynchronously(getInvManager());
                    sender.sendMessage("Successfully set item " + index);
                } else if (args.length > 2 && args[2].equalsIgnoreCase("open")) {
                    String name = args[1];
                    IPlayer forWhom = null;
                    if (args.length == 3) {
                        forWhom = (IPlayer) sender;
                    } else {
                        IPlayer p = getPlayer(args[3]);
                        if (p != null)
                            forWhom = p;
                    }
                    if (forWhom == null) {
                        sender.sendMessage("&7Can't find that player.");
                        return true;
                    }
                    IInventory opened = getInvManager().openGUI(forWhom, name);
                    if (opened == null) {
                        sender.sendMessage("&7No such Inventory Trigger named " + name);
                        return true;
                    }
                } else if (args.length == 3 && args[2].equalsIgnoreCase("edit")) {
                    String name = args[1];
                    InventoryTrigger trigger = getInvManager().get(name);
                    if (trigger == null) {
                        sender.sendMessage("&7No such Inventory Trigger named " + name);
                        return true;
                    }
                    getScriptEditManager().startEdit(sender, trigger.getInfo().getTriggerName(), trigger.getScript(), new SaveHandler() {

                        @Override
                        public void onSave(String script) {
                            try {
                                trigger.setScript(script);
                            } catch (Exception e) {
                                handleException(sender, e);
                            }
                            sender.sendMessage("&aScript is updated!");
                            saveAsynchronously(getInvManager());
                        }
                    });
                } else if (args.length == 4 && args[2].equals("row")) {
                    IItemStack IS = ((IPlayer) sender).getItemInMainHand();
                    IS = IS == null ? null : IS.clone();
                    String name = args[1];
                    int index;
                    try {
                        index = Integer.parseInt(args[3]);
                    } catch (NumberFormatException e) {
                        sender.sendMessage("&c" + "" + args[3] + " is not a valid number.");
                        return true;
                    }
                    InventoryTrigger trigger = getInvManager().get(name);
                    if (trigger == null) {
                        sender.sendMessage("&7No such Inventory Trigger named " + name);
                        return true;
                    }
                    int rows = trigger.getItems().length / 9;
                    if (index > rows || index < 1) {
                        sender.sendMessage("&c" + "" + index + " is out of bounds. (Maximum: " + rows + ")");
                        return true;
                    }
                    for (int i = 0; i < 9; i++) {
                        trigger.getItems()[(index - 1) * 9 + i] = IS;
                    }
                    saveAsynchronously(getInvManager());
                    sender.sendMessage("Successfully filled row " + index);
                } else if (args.length == 4 && args[2].equals("column")) {
                    IItemStack IS = ((IPlayer) sender).getItemInMainHand();
                    IS = IS == null ? null : IS.clone();
                    String name = args[1];
                    int index;
                    try {
                        index = Integer.parseInt(args[3]);
                    } catch (NumberFormatException e) {
                        sender.sendMessage("&c" + "" + args[3] + " is not a valid number.");
                        return true;
                    }
                    InventoryTrigger trigger = getInvManager().get(name);
                    if (trigger == null) {
                        sender.sendMessage("&7No such Inventory Trigger named " + name);
                        return true;
                    }
                    int rows = trigger.getItems().length / 9;
                    if (index > 9 || index < 1) {
                        sender.sendMessage("&c" + "" + index + " is out of bounds. (Maximum: 9)");
                        return true;
                    }
                    for (int i = 0; i < rows; i++) {
                        trigger.getItems()[index - 1 + i * 9] = IS;
                    }
                    saveAsynchronously(getInvManager());
                    sender.sendMessage("Successfully filled column " + index);
                } else if (args.length == 3 && args[2].equalsIgnoreCase("edititems")) {
                    String name = args[1];
                    InventoryTrigger trigger = getInvManager().get(name);
                    if (trigger == null) {
                        sender.sendMessage("&7No such Inventory Trigger named " + name);
                        return true;
                    }
                    getInvEditManager().startEdit((IPlayer) sender, trigger);
                    return true;
                } else {
                    sendCommandDesc(sender, "/triggerreactor[trg] inventory[i] <inventory name> create <size> [...]", "create a new inventory. <size> must be multiple of 9." + " The <size> cannot be larger than 54");
                    sendDetails(sender, "/trg i MyInventory create 54");
                    sendCommandDesc(sender, "/triggerreactor[trg] inventory[i] <inventory name> delete", "delete this inventory");
                    sendDetails(sender, "/trg i MyInventory delete");
                    sendCommandDesc(sender, "/triggerreactor[trg] inventory[i] <inventory name> item <index>", "sets item of inventory to the held item. " + "Clears the slot if you are holding nothing.");
                    sendDetails(sender, "/trg i MyInventory item 0");
                    sendCommandDesc(sender, "/triggerreactor[trg] inventory[i] <inventory name> column <index>", "same as the item subcommand, but applied to an entire column." + "Clears the slot if you are holding nothing.");
                    sendCommandDesc(sender, "/triggerreactor[trg] inventory[i] <inventory name> row <index>", "same as the item subcommand, but applied to an entire row.");
                    sendCommandDesc(sender, "/triggerreactor[trg] inventory[i] <inventory name> open", "Preview the inventory");
                    sendCommandDesc(sender, "/triggerreactor[trg] inventory[i] <inventory name> open <player name>", "Send <player name> a preview of the inventory");
                    sendCommandDesc(sender, "/triggerreactor[trg] inventory[i] <inventory name> edit", "Edit the inventory trigger.");
                }
                return true;
            } else if (args[0].equalsIgnoreCase("item")) {
                if (args.length > 2 && args[1].equalsIgnoreCase("title")) {
                    IItemStack IS = ((IPlayer) sender).getItemInMainHand();
                    if (IS == null) {
                        sender.sendMessage("&c" + "You are holding nothing.");
                        return true;
                    }
                    String title = mergeArguments(args, 2, args.length - 1);
                    setItemTitle(IS, title);
                    ((IPlayer) sender).setItemInMainHand(IS);
                    return true;
                } else if (args.length > 3 && args[1].equalsIgnoreCase("lore") && args[2].equalsIgnoreCase("add")) {
                    IItemStack IS = ((IPlayer) sender).getItemInMainHand();
                    if (IS == null) {
                        sender.sendMessage("&c" + "You are holding nothing.");
                        return true;
                    }
                    String lore = mergeArguments(args, 3, args.length - 1);
                    addItemLore(IS, lore);
                    ((IPlayer) sender).setItemInMainHand(IS);
                    return true;
                } else if (args.length > 4 && args[1].equalsIgnoreCase("lore") && args[2].equalsIgnoreCase("set")) {
                    IItemStack IS = ((IPlayer) sender).getItemInMainHand();
                    if (IS == null) {
                        sender.sendMessage("&c" + "You are holding nothing.");
                        return true;
                    }
                    int index = -1;
                    try {
                        index = Integer.parseInt(args[3]);
                    } catch (NumberFormatException e) {
                        sender.sendMessage("&c" + "" + index + " is not a valid number");
                        return true;
                    }
                    String lore = mergeArguments(args, 4, args.length - 1);
                    if (!setLore(IS, index - 1, lore)) {
                        sender.sendMessage("&c" + "" + index + " is out of bounds.");
                        return true;
                    }
                    ((IPlayer) sender).setItemInMainHand(IS);
                    return true;
                } else if (args.length == 4 && args[1].equalsIgnoreCase("lore") && args[2].equalsIgnoreCase("remove")) {
                    IItemStack IS = ((IPlayer) sender).getItemInMainHand();
                    if (IS == null) {
                        sender.sendMessage("&c" + "You are holding nothing.");
                        return true;
                    }
                    int index = -1;
                    try {
                        index = Integer.parseInt(args[3]);
                    } catch (NumberFormatException e) {
                        sender.sendMessage("&c" + "" + index + " is not a valid number");
                        return true;
                    }
                    if (!removeLore(IS, index - 1)) {
                        sender.sendMessage("&7No lore at index " + index);
                        return true;
                    }
                    ((IPlayer) sender).setItemInMainHand(IS);
                    return true;
                } else {
                    sendCommandDesc(sender, "/triggerreactor[trg] item title <item title>", "Change the title of holding item");
                    sendCommandDesc(sender, "/triggerreactor[trg] item lore add <line>", "Append lore to the holding item");
                    sendCommandDesc(sender, "/triggerreactor[trg] item lore set <index> <line>", "Replace lore at the specified index." + "(Index start from 0)");
                    sendCommandDesc(sender, "/triggerreactor[trg] item lore remove <index>", "Delete lore at the specified index.");
                }
                return true;
            } else if (args.length > 0 && (args[0].equalsIgnoreCase("area") || args[0].equalsIgnoreCase("a"))) {
                if (args.length == 2 && args[1].equalsIgnoreCase("toggle")) {
                    boolean result = getSelectionManager().toggleSelection(((IPlayer) sender).getUniqueId());
                    sender.sendMessage("&7Area selection mode enabled: &6" + result);
                } else if (args.length == 3 && args[2].equals("create")) {
                    String name = args[1];
                    // validate the name
                    if (!NAME_PATTERN.matcher(name).matches()) {
                        sender.sendMessage("&cThe name " + name + " has not allowed character!");
                        sender.sendMessage("&7Use only character, number, and underscore(_).");
                        return true;
                    }
                    AreaTrigger trigger = getAreaManager().get(name);
                    if (trigger != null) {
                        sender.sendMessage("&c" + "Area Trigger " + name + " is already exists!");
                        return true;
                    }
                    Area selected = getSelectionManager().getSelection(((IPlayer) sender).getUniqueId());
                    if (selected == null) {
                        sender.sendMessage("&7Invalid or incomplete area selection.");
                        return true;
                    }
                    Set<Area> conflicts = getAreaManager().getConflictingAreas(selected, selected::equals);
                    if (!conflicts.isEmpty()) {
                        sender.sendMessage("&7Found [" + conflicts.size() + "] conflicting areas:");
                        for (Area conflict : conflicts) {
                            sender.sendMessage("&d  " + conflict);
                        }
                        return true;
                    }
                    if (getAreaManager().createArea(name, selected.getSmallest(), selected.getLargest())) {
                        sender.sendMessage("&aCreated area trigger: " + name);
                        saveAsynchronously(getAreaManager());
                        getSelectionManager().resetSelections(((IPlayer) sender).getUniqueId());
                    } else {
                        sender.sendMessage("&7Area Trigger " + name + " already exists.");
                    }
                } else if (args.length == 3 && args[2].equals("delete")) {
                    String name = args[1];
                    if (getAreaManager().remove(name) != null) {
                        sender.sendMessage("&aArea Trigger deleted");
                        saveAsynchronously(getAreaManager());
                        getSelectionManager().resetSelections(((IPlayer) sender).getUniqueId());
                    } else {
                        sender.sendMessage("&7Area Trigger " + name + " does not exist.");
                    }
                } else if (args.length > 2 && args[2].equals("enter")) {
                    String name = args[1];
                    AreaTrigger trigger = getAreaManager().get(name);
                    if (trigger == null) {
                        sender.sendMessage("&7No Area Trigger found with that name.");
                        return true;
                    }
                    if (trigger.getEnterTrigger() != null) {
                        getScriptEditManager().startEdit(sender, trigger.getInfo().getTriggerName(), trigger.getEnterTrigger().getScript(), new SaveHandler() {

                            @Override
                            public void onSave(String script) {
                                try {
                                    trigger.setEnterTrigger(script);
                                    saveAsynchronously(getAreaManager());
                                    sender.sendMessage("&aScript is updated!");
                                } catch (Exception e) {
                                    handleException(sender, e);
                                }
                            }
                        });
                    } else {
                        if (args.length == 3) {
                            getScriptEditManager().startEdit(sender, "Area Trigger [Enter]", "", new SaveHandler() {

                                @Override
                                public void onSave(String script) {
                                    try {
                                        trigger.setEnterTrigger(script);
                                        saveAsynchronously(getAreaManager());
                                    } catch (Exception e) {
                                        handleException(sender, e);
                                    }
                                }
                            });
                        } else {
                            try {
                                trigger.setEnterTrigger(mergeArguments(args, 3, args.length - 1));
                                saveAsynchronously(getAreaManager());
                            } catch (Exception e) {
                                handleException(sender, e);
                            }
                        }
                    }
                } else if (args.length > 2 && args[2].equals("exit")) {
                    String name = args[1];
                    AreaTrigger trigger = getAreaManager().get(name);
                    if (trigger == null) {
                        sender.sendMessage("&7No Area Trigger found with that name.");
                        return true;
                    }
                    if (trigger.getExitTrigger() != null) {
                        getScriptEditManager().startEdit(sender, trigger.getInfo().getTriggerName(), trigger.getExitTrigger().getScript(), new SaveHandler() {

                            @Override
                            public void onSave(String script) {
                                try {
                                    trigger.setExitTrigger(script);
                                    saveAsynchronously(getAreaManager());
                                    sender.sendMessage("&aScript is updated!");
                                } catch (Exception e) {
                                    handleException(sender, e);
                                }
                            }
                        });
                    } else {
                        if (args.length == 3) {
                            getScriptEditManager().startEdit(sender, "Area Trigger [Exit]", "", new SaveHandler() {

                                @Override
                                public void onSave(String script) {
                                    try {
                                        trigger.setExitTrigger(script);
                                        saveAsynchronously(getAreaManager());
                                    } catch (Exception e) {
                                        handleException(sender, e);
                                    }
                                }
                            });
                        } else {
                            try {
                                trigger.setExitTrigger(mergeArguments(args, 3, args.length - 1));
                                saveAsynchronously(getAreaManager());
                            } catch (Exception e) {
                                handleException(sender, e);
                            }
                        }
                    }
                } else if (args.length == 3 && args[2].equals("sync")) {
                    String name = args[1];
                    AreaTrigger trigger = getAreaManager().get(name);
                    if (trigger == null) {
                        sender.sendMessage("&7No Area Trigger found with that name.");
                        return true;
                    }
                    trigger.setSync(!trigger.isSync());
                    saveAsynchronously(getAreaManager());
                    sender.sendMessage("&7Sync mode: " + (trigger.isSync() ? "&a" : "&c") + trigger.isSync());
                } else {
                    sendCommandDesc(sender, "/triggerreactor[trg] area[a] toggle", "Enable/Disable area selection mode.");
                    sendCommandDesc(sender, "/triggerreactor[trg] area[a] <name> create", "Create area trigger out of selected region.");
                    sendCommandDesc(sender, "/triggerreactor[trg] area[a] <name> delete", "Delete area trigger. BE CAREFUL!");
                    sendCommandDesc(sender, "/triggerreactor[trg] area[a] <name> enter [...]", "Enable/Disable area selection mode.");
                    sendDetails(sender, "/trg a TestingArea enter #MESSAGE \"Welcome\"");
                    sendCommandDesc(sender, "/triggerreactor[trg] area[a] <name> exit [...]", "Enable/Disable area selection mode.");
                    sendDetails(sender, "/trg a TestingArea exit #MESSAGE \"Bye\"");
                    sendCommandDesc(sender, "/triggerreactor[trg] area[a] <name> sync", "Enable/Disable sync mode.");
                    sendDetails(sender, "Setting it to true when you want to cancel event (with #CANCELEVENT)." + " However, setting sync mode will make the trigger run on server thread; keep in mind that" + " it can lag the server if you have too much things going on within the code." + " Set it to false always if you are not sure.");
                }
                return true;
            } else if (args.length > 2 && args[0].equalsIgnoreCase("custom")) {
                String eventName = args[1];
                String name = args[2];
                CustomTrigger trigger = getCustomManager().get(name);
                if (trigger != null) {
                    getScriptEditManager().startEdit(sender, trigger.getInfo().getTriggerName(), trigger.getScript(), new SaveHandler() {

                        @Override
                        public void onSave(String script) {
                            try {
                                trigger.setScript(script);
                            } catch (Exception e) {
                                handleException(sender, e);
                            }
                            sender.sendMessage("&aScript is updated!");
                            saveAsynchronously(getCustomManager());
                        }
                    });
                } else {
                    if (args.length == 3) {
                        getScriptEditManager().startEdit(sender, "Custom Trigger[" + eventName.substring(Math.max(0, eventName.length() - 10)) + "]", "", new SaveHandler() {

                            @Override
                            public void onSave(String script) {
                                try {
                                    getCustomManager().createCustomTrigger(eventName, name, script);
                                    saveAsynchronously(getCustomManager());
                                    sender.sendMessage("&aCustom Trigger created!");
                                } catch (Exception e) {
                                    e.printStackTrace();
                                    sender.sendMessage("&c" + "Could not save! " + e.getMessage());
                                    sender.sendMessage("&c" + "See console for detailed messages.");
                                }
                            }
                        });
                    } else {
                        String script = mergeArguments(args, 3, args.length - 1);
                        try {
                            getCustomManager().createCustomTrigger(eventName, name, script);
                            saveAsynchronously(getCustomManager());
                            sender.sendMessage("&aCustom Trigger created!");
                        } catch (ClassNotFoundException e2) {
                            sender.sendMessage("&c" + "Could not save! " + e2.getMessage());
                            sender.sendMessage("&c" + "Provided event name is not valid.");
                        } catch (Exception e) {
                            handleException(sender, e);
                        }
                    }
                }
                return true;
            } else if (args.length > 0 && (args[0].equalsIgnoreCase("repeat") || args[0].equalsIgnoreCase("r"))) {
                if (args.length == 2) {
                    String name = args[1];
                    Trigger trigger = getRepeatManager().get(name);
                    if (trigger != null) {
                        getScriptEditManager().startEdit(sender, trigger.getInfo().getTriggerName(), trigger.getScript(), new SaveHandler() {

                            @Override
                            public void onSave(String script) {
                                try {
                                    trigger.setScript(script);
                                } catch (Exception e) {
                                    handleException(sender, e);
                                }
                                sender.sendMessage("&aScript is updated!");
                                saveAsynchronously(getRepeatManager());
                            }
                        });
                    } else {
                        this.getScriptEditManager().startEdit(sender, "Repeating Trigger", "", new SaveHandler() {

                            @Override
                            public void onSave(String script) {
                                try {
                                    getRepeatManager().createTrigger(name, script);
                                } catch (Exception e) {
                                    handleException(sender, e);
                                }
                                saveAsynchronously(getRepeatManager());
                            }
                        });
                    }
                } else if (args.length == 4 && args[2].equalsIgnoreCase("interval")) {
                    String name = args[1];
                    RepeatingTrigger trigger = getRepeatManager().get(name);
                    if (trigger == null) {
                        sender.sendMessage("&7No Repeating Trigger with name " + name);
                        return true;
                    }
                    String intervalValue = args[3];
                    long interval = TimeUtil.parseTime(intervalValue);
                    trigger.setInterval(interval);
                    saveAsynchronously(getRepeatManager());
                    sender.sendMessage("&aNow " + "&6[" + name + "]" + "&a will run every " + "&6[" + TimeUtil.milliSecondsToString(interval) + "]");
                } else if (args.length == 3 && args[2].equalsIgnoreCase("autostart")) {
                    String name = args[1];
                    RepeatingTrigger trigger = getRepeatManager().get(name);
                    if (trigger == null) {
                        sender.sendMessage("&7No Repeating Trigger with name " + name);
                        return true;
                    }
                    trigger.setAutoStart(!trigger.isAutoStart());
                    saveAsynchronously(getRepeatManager());
                    sender.sendMessage("Auto start: " + (trigger.isAutoStart() ? "&a" : "&c") + trigger.isAutoStart());
                } else if (args.length == 3 && args[2].equalsIgnoreCase("toggle")) {
                    String name = args[1];
                    RepeatingTrigger trigger = getRepeatManager().get(name);
                    if (trigger == null) {
                        sender.sendMessage("&7No Repeating Trigger with name " + name);
                        return true;
                    }
                    if (getRepeatManager().isRunning(name)) {
                        getRepeatManager().stopTrigger(name);
                        sender.sendMessage("&aScheduled stop. It may take some time depends on CPU usage.");
                    } else {
                        getRepeatManager().startTrigger(name);
                        sender.sendMessage("&aScheduled start up. It may take some time depends on CPU usage.");
                    }
                } else if (args.length == 3 && args[2].equalsIgnoreCase("pause")) {
                    String name = args[1];
                    RepeatingTrigger trigger = getRepeatManager().get(name);
                    if (trigger == null) {
                        sender.sendMessage("&7No Repeating Trigger with name " + name);
                        return true;
                    }
                    trigger.setPaused(!trigger.isPaused());
                    sender.sendMessage("Paused: " + (trigger.isPaused() ? "&a" : "&c") + trigger.isPaused());
                } else if (args.length == 3 && args[2].equalsIgnoreCase("status")) {
                    String name = args[1];
                    RepeatingTrigger trigger = getRepeatManager().get(name);
                    if (trigger == null) {
                        sender.sendMessage("&7No Repeating Trigger with name " + name);
                        return true;
                    }
                    getRepeatManager().showTriggerInfo(sender, trigger);
                } else if (args.length == 3 && args[2].equalsIgnoreCase("delete")) {
                    String name = args[1];
                    RepeatingTrigger trigger = getRepeatManager().get(name);
                    if (trigger == null) {
                        sender.sendMessage("&7No Repeating Trigger with name " + name);
                        return true;
                    }
                    getRepeatManager().remove(name);
                } else {
                    sendCommandDesc(sender, "/triggerreactor[trg] repeat[r] <name>", "Create Repeating Trigger.");
                    sendDetails(sender, "&4Quick create is not supported.");
                    sendDetails(sender, "This creates a Repeating Trigger with default settings. You probably will want to change default values" + " using other commands below. Also, creating Repeating Trigger doesn't start it automatically.");
                    sendCommandDesc(sender, "/triggerreactor[trg] repeat[r] <name> interval <time format>", "Change the interval of this trigger.");
                    sendDetails(sender, "Notice the <time format> is not just a number but has specific format for it. For example, you first" + " type what number you want to set and also define the unit of it. If you want it to repeat it every 1 hour, 20 minutes," + " 50seconds, and 10ticks, then it will be &6" + "/trg r BlahBlah interval 1h20m50s10t." + "&7 Currently only h, m," + " s, and t are supported for this format. Also notice that if you have two numbers with same format, they will add up as well. For example," + "&6 /trg r BlahBlah interval 30s40s" + "&7 will be added up to 70seconds total. All units other than" + " h, m, s, or t will be ignored.");
                    sendCommandDesc(sender, "/triggerreactor[trg] repeat[r] <name> autostart", "Enable/Disable automatic start for this trigger.");
                    sendDetails(sender, "By setting this to " + "&atrue" + "&7, this trigger will start on plugin enables itself. " + "Otherwise, you have to start it yourself every time.");
                    sendCommandDesc(sender, "/triggerreactor[trg] repeat[r] <name> toggle", "Start or stop the Repeating Trigger.");
                    sendCommandDesc(sender, "/triggerreactor[trg] repeat[r] <name> pause", "Pause or unpause the Repeating Trigger.");
                    sendCommandDesc(sender, "/triggerreactor[trg] repeat[r] <name> status", "See brief information about this trigger.");
                    sendCommandDesc(sender, "/triggerreactor[trg] repeat[r] <name> delete", "Delete repeating trigger.");
                }
                return true;
            } else if (args.length == 2 && (args[0].equalsIgnoreCase("synccustom") || args[0].equalsIgnoreCase("sync"))) {
                String name = args[1];
                CustomTrigger trigger = getCustomManager().get(name);
                if (trigger == null) {
                    sender.sendMessage("&7No Custom Trigger found with that name.");
                    return true;
                }
                trigger.setSync(!trigger.isSync());
                saveAsynchronously(getCustomManager());
                sender.sendMessage("&7Sync mode: " + (trigger.isSync() ? "&a" : "&c") + trigger.isSync());
                return true;
            } else if (args.length == 3 && (args[0].equalsIgnoreCase("delete") || args[0].equalsIgnoreCase("del"))) {
                String key = args[2];
                switch(args[1]) {
                    case "vars":
                    case "variables":
                        getVariableManager().remove(key);
                        sender.sendMessage("&aRemoved the variable &6" + key);
                        break;
                    case "cmd":
                    case "command":
                        if (getCmdManager().remove(key) != null) {
                            sender.sendMessage("&aRemoved the command trigger &6" + key);
                            saveAsynchronously(getCmdManager());
                        } else {
                            sender.sendMessage("&7Command trigger &6" + key + "&7 does not exist");
                        }
                        break;
                    case "custom":
                        if (getCustomManager().remove(key) != null) {
                            sender.sendMessage("&aRemoved the custom trigger &6" + key);
                            saveAsynchronously(getCustomManager());
                        } else {
                            sender.sendMessage("&7Custom Trigger &6" + key + "&7 does not exist");
                        }
                        break;
                    default:
                        sender.sendMessage("Ex) /trg del vars player.count");
                        sender.sendMessage("List: variables[vars], command[cmd], custom");
                        break;
                }
                return true;
            } else if (args[0].equalsIgnoreCase("search")) {
                SimpleChunkLocation scloc = ((IPlayer) sender).getChunk();
                showGlowStones(sender, getClickManager().getTriggersInChunk(scloc));
                showGlowStones(sender, getWalkManager().getTriggersInChunk(scloc));
                sender.sendMessage("&7Now trigger blocks will be shown as &6" + "glowstone");
                return true;
            } else if (args[0].equalsIgnoreCase("list")) {
                sender.sendMessage("- - - - - Result - - - - ");
                for (Manager manager : Manager.getManagers()) {
                    if (!(manager instanceof AbstractTriggerManager<?>))
                        continue;
                    for (String val : ((AbstractTriggerManager<? extends Trigger>) manager).getTriggerList((name) -> {
                        for (int i = 1; i < args.length; i++) {
                            if (!name.contains(args[i]))
                                return false;
                        }
                        return true;
                    })) {
                        sender.sendMessage("&d" + val);
                    }
                }
                sender.sendMessage(" ");
                return true;
            } else if (args[0].equalsIgnoreCase("timings")) {
                if (args.length == 2 && args[1].equalsIgnoreCase("toggle")) {
                    Timings.on = !Timings.on;
                    if (Timings.on) {
                        sender.sendMessage("&aEnabled");
                    } else {
                        sender.sendMessage("&cDisabled");
                    }
                } else if (args.length == 2 && args[1].equalsIgnoreCase("reset")) {
                    Timings.reset();
                    sender.sendMessage("&aReset Complete.");
                } else if (args.length > 1 && args[1].equalsIgnoreCase("print")) {
                    OutputStream os;
                    if (args.length > 2) {
                        String fileName = args[2];
                        File folder = new File(getDataFolder(), "timings");
                        if (!folder.exists())
                            folder.mkdirs();
                        File file = new File(folder, fileName + ".timings");
                        if (file.exists())
                            file.delete();
                        try {
                            file.createNewFile();
                            os = new FileOutputStream(file);
                        } catch (IOException ex) {
                            ex.printStackTrace();
                            sender.sendMessage("&cCould not create log file. Check console for details.");
                            return true;
                        }
                    } else {
                        os = new SenderOutputStream(sender);
                    }
                    try {
                        Timings.printAll(os);
                    } catch (IOException ex) {
                        ex.printStackTrace();
                    }
                } else {
                    sendCommandDesc(sender, "/triggerreactor[trg] timings toggle", "turn on/off timings analysis. Also analysis will be reset.");
                    sendCommandDesc(sender, "/triggerreactor[trg] timings reset", "turn on/off timings analysis. Also analysis will be reset.");
                    sendCommandDesc(sender, "/triggerreactor[trg] timings print", "Show analysis result.");
                    sendCommandDesc(sender, "/triggerreactor[trg] timings print xx", "Save analysis to file named xx.timings");
                }
                return true;
            } else if (args[0].equalsIgnoreCase("saveall")) {
                for (Manager manager : Manager.getManagers()) manager.saveAll();
                sender.sendMessage("Save complete!");
                return true;
            } else if (args[0].equalsIgnoreCase("reload")) {
                for (Manager manager : Manager.getManagers()) manager.reload();
                getExecutorManager().reload();
                getPlaceholderManager().reload();
                sender.sendMessage("Reload Complete!");
                return true;
            } else if (args[0].equalsIgnoreCase("help")) {
                int page = 0;
                if (args.length > 1) {
                    if (!args[1].matches("[0-9]+")) {
                        sender.sendMessage("&c" + args[1] + " is not a valid page number.");
                        return true;
                    }
                    page = Integer.parseInt(args[1]);
                }
                showHelp(sender, page);
                return true;
            } else if (args[0].equalsIgnoreCase("links")) {
                if (args.length < 2) {
                    return true;
                }
                AbstractInventoryEditManager manager = getInvEditManager();
                IPlayer player = (IPlayer) sender;
                switch(args[1]) {
                    case "inveditsave":
                        manager.saveEdit(player);
                        return true;
                    case "inveditcontinue":
                        manager.continueEdit(player);
                        return true;
                    case "inveditdiscard":
                        manager.discardEdit(player);
                        return true;
                }
            }
        }
        showHelp(sender);
    }
    return true;
}
Also used : IPlayer(io.github.wysohn.triggerreactor.core.bridge.entity.IPlayer) CustomTrigger(io.github.wysohn.triggerreactor.core.manager.trigger.custom.CustomTrigger) AbstractRepeatingTriggerManager(io.github.wysohn.triggerreactor.core.manager.trigger.repeating.AbstractRepeatingTriggerManager) AbstractAPISupport(io.github.wysohn.triggerreactor.core.manager.trigger.share.api.AbstractAPISupport) java.util(java.util) io.github.wysohn.triggerreactor.core.manager(io.github.wysohn.triggerreactor.core.manager) AbstractLocationBasedTriggerManager(io.github.wysohn.triggerreactor.core.manager.trigger.location.AbstractLocationBasedTriggerManager) SaveHandler(io.github.wysohn.triggerreactor.tools.ScriptEditor.SaveHandler) ICommandSender(io.github.wysohn.triggerreactor.core.bridge.ICommandSender) AbstractInventoryTriggerManager(io.github.wysohn.triggerreactor.core.manager.trigger.inventory.AbstractInventoryTriggerManager) AreaTrigger(io.github.wysohn.triggerreactor.core.manager.trigger.area.AreaTrigger) IItemStack(io.github.wysohn.triggerreactor.core.bridge.IItemStack) Trigger(io.github.wysohn.triggerreactor.core.manager.trigger.Trigger) TriggerInfo(io.github.wysohn.triggerreactor.core.manager.trigger.TriggerInfo) AbstractAreaTriggerManager(io.github.wysohn.triggerreactor.core.manager.trigger.area.AbstractAreaTriggerManager) CommandTrigger(io.github.wysohn.triggerreactor.core.manager.trigger.command.CommandTrigger) Timings(io.github.wysohn.triggerreactor.tools.timings.Timings) AbstractCustomTriggerManager(io.github.wysohn.triggerreactor.core.manager.trigger.custom.AbstractCustomTriggerManager) ProcessInterrupter(io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.ProcessInterrupter) OutputStream(java.io.OutputStream) AbstractCommandTriggerManager(io.github.wysohn.triggerreactor.core.manager.trigger.command.AbstractCommandTriggerManager) Area(io.github.wysohn.triggerreactor.core.manager.location.Area) AbstractTriggerManager(io.github.wysohn.triggerreactor.core.manager.trigger.AbstractTriggerManager) IInventory(io.github.wysohn.triggerreactor.core.bridge.IInventory) java.util.concurrent(java.util.concurrent) SenderOutputStream(io.github.wysohn.triggerreactor.tools.stream.SenderOutputStream) FileOutputStream(java.io.FileOutputStream) InventoryTrigger(io.github.wysohn.triggerreactor.core.manager.trigger.inventory.InventoryTrigger) IOException(java.io.IOException) IEvent(io.github.wysohn.triggerreactor.core.bridge.event.IEvent) Interpreter(io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter) Logger(java.util.logging.Logger) AbstractNamedTriggerManager(io.github.wysohn.triggerreactor.core.manager.trigger.named.AbstractNamedTriggerManager) IPlayer(io.github.wysohn.triggerreactor.core.bridge.entity.IPlayer) File(java.io.File) TimeUtil(io.github.wysohn.triggerreactor.tools.TimeUtil) SimpleLocation(io.github.wysohn.triggerreactor.core.manager.location.SimpleLocation) TaskSupervisor(io.github.wysohn.triggerreactor.core.script.interpreter.TaskSupervisor) SimpleChunkLocation(io.github.wysohn.triggerreactor.core.manager.location.SimpleChunkLocation) RepeatingTrigger(io.github.wysohn.triggerreactor.core.manager.trigger.repeating.RepeatingTrigger) Entry(java.util.Map.Entry) ILocation(io.github.wysohn.triggerreactor.core.bridge.ILocation) SelfReference(io.github.wysohn.triggerreactor.core.script.wrapper.SelfReference) Pattern(java.util.regex.Pattern) SenderOutputStream(io.github.wysohn.triggerreactor.tools.stream.SenderOutputStream) OutputStream(java.io.OutputStream) SenderOutputStream(io.github.wysohn.triggerreactor.tools.stream.SenderOutputStream) FileOutputStream(java.io.FileOutputStream) SimpleChunkLocation(io.github.wysohn.triggerreactor.core.manager.location.SimpleChunkLocation) AbstractRepeatingTriggerManager(io.github.wysohn.triggerreactor.core.manager.trigger.repeating.AbstractRepeatingTriggerManager) AbstractLocationBasedTriggerManager(io.github.wysohn.triggerreactor.core.manager.trigger.location.AbstractLocationBasedTriggerManager) AbstractInventoryTriggerManager(io.github.wysohn.triggerreactor.core.manager.trigger.inventory.AbstractInventoryTriggerManager) AbstractAreaTriggerManager(io.github.wysohn.triggerreactor.core.manager.trigger.area.AbstractAreaTriggerManager) AbstractCustomTriggerManager(io.github.wysohn.triggerreactor.core.manager.trigger.custom.AbstractCustomTriggerManager) AbstractCommandTriggerManager(io.github.wysohn.triggerreactor.core.manager.trigger.command.AbstractCommandTriggerManager) AbstractTriggerManager(io.github.wysohn.triggerreactor.core.manager.trigger.AbstractTriggerManager) AbstractNamedTriggerManager(io.github.wysohn.triggerreactor.core.manager.trigger.named.AbstractNamedTriggerManager) CommandTrigger(io.github.wysohn.triggerreactor.core.manager.trigger.command.CommandTrigger) RepeatingTrigger(io.github.wysohn.triggerreactor.core.manager.trigger.repeating.RepeatingTrigger) InventoryTrigger(io.github.wysohn.triggerreactor.core.manager.trigger.inventory.InventoryTrigger) CustomTrigger(io.github.wysohn.triggerreactor.core.manager.trigger.custom.CustomTrigger) AreaTrigger(io.github.wysohn.triggerreactor.core.manager.trigger.area.AreaTrigger) Trigger(io.github.wysohn.triggerreactor.core.manager.trigger.Trigger) CommandTrigger(io.github.wysohn.triggerreactor.core.manager.trigger.command.CommandTrigger) InventoryTrigger(io.github.wysohn.triggerreactor.core.manager.trigger.inventory.InventoryTrigger) RepeatingTrigger(io.github.wysohn.triggerreactor.core.manager.trigger.repeating.RepeatingTrigger) IInventory(io.github.wysohn.triggerreactor.core.bridge.IInventory) TriggerInfo(io.github.wysohn.triggerreactor.core.manager.trigger.TriggerInfo) AreaTrigger(io.github.wysohn.triggerreactor.core.manager.trigger.area.AreaTrigger) IOException(java.io.IOException) IOException(java.io.IOException) CustomTrigger(io.github.wysohn.triggerreactor.core.manager.trigger.custom.CustomTrigger) SaveHandler(io.github.wysohn.triggerreactor.tools.ScriptEditor.SaveHandler) Area(io.github.wysohn.triggerreactor.core.manager.location.Area) ILocation(io.github.wysohn.triggerreactor.core.bridge.ILocation) IItemStack(io.github.wysohn.triggerreactor.core.bridge.IItemStack) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 2 with AbstractTriggerManager

use of io.github.wysohn.triggerreactor.core.manager.trigger.AbstractTriggerManager in project TriggerReactor by wysohn.

the class TriggerReactor method migrateOldConfig.

private void migrateOldConfig() {
    new ContinuingTasks.Builder().append(() -> {
    // if (getPluginConfigManager().isMigrationNeeded()) {
    // File file = new File(getDataFolder(), "config.yml");
    // ConfigurationLoader<CommentedConfigurationNode> varFileConfigLoader
    // = HoconConfigurationLoader.builder().setPath(file.toPath()).build();
    // ConfigurationNode confFileConfig = null;
    // try {
    // confFileConfig = varFileConfigLoader.load();
    // } catch (IOException e) {
    // e.printStackTrace();
    // return;
    // }
    // getPluginConfigManager().migrate(new SpongeMigrationHelper(confFileConfig, file));
    // }
    }).append(() -> {
        if (getVariableManager().isMigrationNeeded()) {
            File file = new File(getDataFolder(), "var.yml");
            ConfigurationLoader<CommentedConfigurationNode> varFileConfigLoader = HoconConfigurationLoader.builder().setPath(file.toPath()).build();
            ConfigurationNode varFileConfig = null;
            try {
                varFileConfig = varFileConfigLoader.load();
            } catch (IOException e) {
                e.printStackTrace();
                return;
            }
            getVariableManager().migrate(new VariableMigrationHelper(varFileConfig, file));
        }
    }).append(() -> Optional.of(getInvManager()).map(AbstractTriggerManager::getTriggerInfos).ifPresent(triggerInfos -> Arrays.stream(triggerInfos).filter(TriggerInfo::isMigrationNeeded).forEach(triggerInfo -> {
        File folder = triggerInfo.getSourceCodeFile().getParentFile();
        File oldFile = new File(folder, triggerInfo.getTriggerName() + ".yml");
        ConfigurationLoader<CommentedConfigurationNode> loader = HoconConfigurationLoader.builder().setPath(oldFile.toPath()).build();
        ConfigurationNode oldConfig = null;
        try {
            oldConfig = loader.load();
        } catch (IOException e) {
            e.printStackTrace();
            return;
        }
        triggerInfo.migrate(new InvTriggerMigrationHelper(oldFile, oldConfig));
    }))).append(() -> Manager.getManagers().stream().filter(AbstractTriggerManager.class::isInstance).map(AbstractTriggerManager.class::cast).map(AbstractTriggerManager::getTriggerInfos).forEach(triggerInfos -> Arrays.stream(triggerInfos).filter(TriggerInfo::isMigrationNeeded).forEach(triggerInfo -> {
        File folder = triggerInfo.getSourceCodeFile().getParentFile();
        File oldFile = new File(folder, triggerInfo.getTriggerName() + ".yml");
        ConfigurationLoader<CommentedConfigurationNode> loader = HoconConfigurationLoader.builder().setPath(oldFile.toPath()).build();
        ConfigurationNode oldConfig = null;
        try {
            oldConfig = loader.load();
        } catch (IOException e) {
            e.printStackTrace();
            return;
        }
        triggerInfo.migrate(new NaiveMigrationHelper(oldConfig, oldFile));
    }))).run();
}
Also used : AbstractRepeatingTriggerManager(io.github.wysohn.triggerreactor.core.manager.trigger.repeating.AbstractRepeatingTriggerManager) ConsoleSource(org.spongepowered.api.command.source.ConsoleSource) EventContextKeys(org.spongepowered.api.event.cause.EventContextKeys) Inject(com.google.inject.Inject) io.github.wysohn.triggerreactor.core.manager(io.github.wysohn.triggerreactor.core.manager) GameInitializationEvent(org.spongepowered.api.event.game.state.GameInitializationEvent) CommandCallable(org.spongepowered.api.command.CommandCallable) GsonConfigSource(io.github.wysohn.triggerreactor.core.config.source.GsonConfigSource) APISupport(io.github.wysohn.triggerreactor.sponge.manager.trigger.share.api.APISupport) AbstractLocationBasedTriggerManager(io.github.wysohn.triggerreactor.core.manager.trigger.location.AbstractLocationBasedTriggerManager) ConfigurationLoader(ninja.leaping.configurate.loader.ConfigurationLoader) SpongeDataSerializer(io.github.wysohn.triggerreactor.sponge.main.serialize.SpongeDataSerializer) ICommandSender(io.github.wysohn.triggerreactor.core.bridge.ICommandSender) ItemStack(org.spongepowered.api.item.inventory.ItemStack) Future(java.util.concurrent.Future) AbstractInventoryTriggerManager(io.github.wysohn.triggerreactor.core.manager.trigger.inventory.AbstractInventoryTriggerManager) IItemStack(io.github.wysohn.triggerreactor.core.bridge.IItemStack) ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) AbstractAreaTriggerManager(io.github.wysohn.triggerreactor.core.manager.trigger.area.AbstractAreaTriggerManager) MetricsLite2(org.bstats.sponge.MetricsLite2) Path(java.nio.file.Path) AbstractCustomTriggerManager(io.github.wysohn.triggerreactor.core.manager.trigger.custom.AbstractCustomTriggerManager) ScriptException(javax.script.ScriptException) Location(org.spongepowered.api.world.Location) AbstractTriggerManager(io.github.wysohn.triggerreactor.core.manager.trigger.AbstractTriggerManager) GameReloadEvent(org.spongepowered.api.event.game.GameReloadEvent) CommandSource(org.spongepowered.api.command.CommandSource) IInventory(io.github.wysohn.triggerreactor.core.bridge.IInventory) BlockTypes(org.spongepowered.api.block.BlockTypes) Sponge(org.spongepowered.api.Sponge) Carrier(org.spongepowered.api.item.inventory.Carrier) Logger(java.util.logging.Logger) IPlayer(io.github.wysohn.triggerreactor.core.bridge.entity.IPlayer) Cause(org.spongepowered.api.event.cause.Cause) NaiveMigrationHelper(io.github.wysohn.triggerreactor.sponge.tools.migration.NaiveMigrationHelper) Cancellable(org.spongepowered.api.event.Cancellable) CarriedInventory(org.spongepowered.api.item.inventory.type.CarriedInventory) World(org.spongepowered.api.world.World) GameStartedServerEvent(org.spongepowered.api.event.game.state.GameStartedServerEvent) Entry(java.util.Map.Entry) InvTriggerMigrationHelper(io.github.wysohn.triggerreactor.sponge.tools.migration.InvTriggerMigrationHelper) SelfReference(io.github.wysohn.triggerreactor.core.script.wrapper.SelfReference) Player(org.spongepowered.api.entity.living.player.Player) EventContext(org.spongepowered.api.event.cause.EventContext) Inventory(org.spongepowered.api.item.inventory.Inventory) AbstractAPISupport(io.github.wysohn.triggerreactor.core.manager.trigger.share.api.AbstractAPISupport) java.util(java.util) Keys(org.spongepowered.api.data.key.Keys) GameStoppingServerEvent(org.spongepowered.api.event.game.state.GameStoppingServerEvent) Callable(java.util.concurrent.Callable) SpongeInventory(io.github.wysohn.triggerreactor.sponge.bridge.SpongeInventory) DelegatedPlayer(io.github.wysohn.triggerreactor.sponge.tools.DelegatedPlayer) DataSerializable(org.spongepowered.api.data.DataSerializable) TriggerReactorStopEvent(io.github.wysohn.triggerreactor.sponge.manager.event.TriggerReactorStopEvent) ContinuingTasks(io.github.wysohn.triggerreactor.tools.ContinuingTasks) Text(org.spongepowered.api.text.Text) TabCompleteEvent(org.spongepowered.api.event.command.TabCompleteEvent) Trigger(io.github.wysohn.triggerreactor.core.manager.trigger.Trigger) TriggerInfo(io.github.wysohn.triggerreactor.core.manager.trigger.TriggerInfo) CauseStackManager(org.spongepowered.api.event.CauseStackManager) PluginContainer(org.spongepowered.api.plugin.PluginContainer) ProcessInterrupter(io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.ProcessInterrupter) io.github.wysohn.triggerreactor.sponge.manager.trigger(io.github.wysohn.triggerreactor.sponge.manager.trigger) Node(io.github.wysohn.triggerreactor.core.script.parser.Node) CommandResult(org.spongepowered.api.command.CommandResult) AbstractCommandTriggerManager(io.github.wysohn.triggerreactor.core.manager.trigger.command.AbstractCommandTriggerManager) SpongeCommandSender(io.github.wysohn.triggerreactor.sponge.bridge.SpongeCommandSender) HoconConfigurationLoader(ninja.leaping.configurate.hocon.HoconConfigurationLoader) CommentedConfigurationNode(ninja.leaping.configurate.commented.CommentedConfigurationNode) Event(org.spongepowered.api.event.Event) SpongeExecutorService(org.spongepowered.api.scheduler.SpongeExecutorService) ConfigDir(org.spongepowered.api.config.ConfigDir) InventoryTrigger(io.github.wysohn.triggerreactor.core.manager.trigger.inventory.InventoryTrigger) InteractInventoryEvent(org.spongepowered.api.event.item.inventory.InteractInventoryEvent) IOException(java.io.IOException) IEvent(io.github.wysohn.triggerreactor.core.bridge.event.IEvent) CommonFunctions(io.github.wysohn.triggerreactor.sponge.manager.trigger.share.CommonFunctions) VariableMigrationHelper(io.github.wysohn.triggerreactor.sponge.tools.migration.VariableMigrationHelper) Interpreter(io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter) AbstractNamedTriggerManager(io.github.wysohn.triggerreactor.core.manager.trigger.named.AbstractNamedTriggerManager) Lag(io.github.wysohn.triggerreactor.tools.Lag) Entity(org.spongepowered.api.entity.Entity) io.github.wysohn.triggerreactor.sponge.manager(io.github.wysohn.triggerreactor.sponge.manager) File(java.io.File) TriggerReactorStartEvent(io.github.wysohn.triggerreactor.sponge.manager.event.TriggerReactorStartEvent) CommandException(org.spongepowered.api.command.CommandException) SimpleLocation(io.github.wysohn.triggerreactor.core.manager.location.SimpleLocation) Plugin(org.spongepowered.api.plugin.Plugin) SpongePlayer(io.github.wysohn.triggerreactor.sponge.bridge.entity.SpongePlayer) SpongeWrapper(io.github.wysohn.triggerreactor.sponge.bridge.SpongeWrapper) GameAboutToStartServerEvent(org.spongepowered.api.event.game.state.GameAboutToStartServerEvent) Listener(org.spongepowered.api.event.Listener) SendCommandEvent(org.spongepowered.api.event.command.SendCommandEvent) TriggerInfo(io.github.wysohn.triggerreactor.core.manager.trigger.TriggerInfo) VariableMigrationHelper(io.github.wysohn.triggerreactor.sponge.tools.migration.VariableMigrationHelper) InvTriggerMigrationHelper(io.github.wysohn.triggerreactor.sponge.tools.migration.InvTriggerMigrationHelper) IOException(java.io.IOException) AbstractTriggerManager(io.github.wysohn.triggerreactor.core.manager.trigger.AbstractTriggerManager) NaiveMigrationHelper(io.github.wysohn.triggerreactor.sponge.tools.migration.NaiveMigrationHelper) ContinuingTasks(io.github.wysohn.triggerreactor.tools.ContinuingTasks) ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) CommentedConfigurationNode(ninja.leaping.configurate.commented.CommentedConfigurationNode) CommentedConfigurationNode(ninja.leaping.configurate.commented.CommentedConfigurationNode) File(java.io.File) ConfigurationLoader(ninja.leaping.configurate.loader.ConfigurationLoader) HoconConfigurationLoader(ninja.leaping.configurate.hocon.HoconConfigurationLoader)

Example 3 with AbstractTriggerManager

use of io.github.wysohn.triggerreactor.core.manager.trigger.AbstractTriggerManager in project TriggerReactor by wysohn.

the class AbstractJavaPlugin method migrateOldConfig.

private void migrateOldConfig() {
    new ContinuingTasks.Builder().append(() -> {
        if (core.getPluginConfigManager().isMigrationNeeded()) {
            core.getPluginConfigManager().migrate(new NaiveMigrationHelper(getConfig(), new File(getDataFolder(), "config.yml")));
        }
    }).append(() -> {
        if (core.getVariableManager().isMigrationNeeded()) {
            File file = new File(getDataFolder(), "var.yml");
            FileConfiguration conf = new Utf8YamlConfiguration();
            try {
                conf.load(file);
            } catch (IOException | InvalidConfigurationException e) {
                e.printStackTrace();
            }
            core.getVariableManager().migrate(new NaiveMigrationHelper(conf, file));
        }
    }).append(() -> {
        Optional.of(core.getInvManager()).map(AbstractTriggerManager::getTriggerInfos).ifPresent(triggerInfos -> Arrays.stream(triggerInfos).filter(TriggerInfo::isMigrationNeeded).forEach(triggerInfo -> {
            File folder = triggerInfo.getSourceCodeFile().getParentFile();
            File oldFile = new File(folder, triggerInfo.getTriggerName() + ".yml");
            FileConfiguration oldFileConfig = YamlConfiguration.loadConfiguration(oldFile);
            triggerInfo.migrate(new InvTriggerMigrationHelper(oldFile, oldFileConfig));
        }));
    }).append(() -> {
        Manager.getManagers().stream().filter(AbstractTriggerManager.class::isInstance).map(AbstractTriggerManager.class::cast).map(AbstractTriggerManager::getTriggerInfos).forEach(triggerInfos -> Arrays.stream(triggerInfos).filter(TriggerInfo::isMigrationNeeded).forEach(triggerInfo -> {
            File folder = triggerInfo.getSourceCodeFile().getParentFile();
            File oldFile = new File(folder, triggerInfo.getTriggerName() + ".yml");
            FileConfiguration oldFileConfig = YamlConfiguration.loadConfiguration(oldFile);
            triggerInfo.migrate(new NaiveMigrationHelper(oldFileConfig, oldFile));
        }));
    }).run();
}
Also used : FileConfiguration(org.bukkit.configuration.file.FileConfiguration) Utf8YamlConfiguration(io.github.wysohn.triggerreactor.bukkit.tools.Utf8YamlConfiguration) Connection(java.sql.Connection) BukkitConfigurationSerializer(io.github.wysohn.triggerreactor.bukkit.main.serialize.BukkitConfigurationSerializer) Event(org.bukkit.event.Event) GsonConfigSource(io.github.wysohn.triggerreactor.core.config.source.GsonConfigSource) Player(org.bukkit.entity.Player) ConfigurationSerializable(org.bukkit.configuration.serialization.ConfigurationSerializable) Inventory(org.bukkit.inventory.Inventory) ICommandSender(io.github.wysohn.triggerreactor.core.bridge.ICommandSender) Future(java.util.concurrent.Future) Location(org.bukkit.Location) ResultSet(java.sql.ResultSet) IItemStack(io.github.wysohn.triggerreactor.core.bridge.IItemStack) BukkitUtil(io.github.wysohn.triggerreactor.bukkit.tools.BukkitUtil) Method(java.lang.reflect.Method) ByteArrayDataOutput(com.google.common.io.ByteArrayDataOutput) Material(org.bukkit.Material) BlockEvent(org.bukkit.event.block.BlockEvent) Bukkit(org.bukkit.Bukkit) BukkitCommandSender(io.github.wysohn.triggerreactor.bukkit.bridge.BukkitCommandSender) MiniConnectionPoolManager(io.github.wysohn.triggerreactor.tools.mysql.MiniConnectionPoolManager) CommandSender(org.bukkit.command.CommandSender) MysqlConnectionPoolDataSource(com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource) AbstractTriggerManager(io.github.wysohn.triggerreactor.core.manager.trigger.AbstractTriggerManager) Entity(org.bukkit.entity.Entity) IInventory(io.github.wysohn.triggerreactor.core.bridge.IInventory) NaiveMigrationHelper(io.github.wysohn.triggerreactor.bukkit.tools.migration.NaiveMigrationHelper) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) EntityEvent(org.bukkit.event.entity.EntityEvent) PreparedStatement(java.sql.PreparedStatement) PluginCommand(org.bukkit.command.PluginCommand) Sets(com.google.common.collect.Sets) IPlayer(io.github.wysohn.triggerreactor.core.bridge.entity.IPlayer) ItemStack(org.bukkit.inventory.ItemStack) InvocationTargetException(java.lang.reflect.InvocationTargetException) JavaPlugin(org.bukkit.plugin.java.JavaPlugin) TriggerReactorStartEvent(io.github.wysohn.triggerreactor.bukkit.manager.event.TriggerReactorStartEvent) PlayerDeathEvent(org.bukkit.event.entity.PlayerDeathEvent) org.bukkit.event.inventory(org.bukkit.event.inventory) ByteStreams(com.google.common.io.ByteStreams) Command(org.bukkit.command.Command) SelfReference(io.github.wysohn.triggerreactor.core.script.wrapper.SelfReference) InvalidConfigurationException(org.bukkit.configuration.InvalidConfigurationException) TriggerReactorStopEvent(io.github.wysohn.triggerreactor.bukkit.manager.event.TriggerReactorStopEvent) HandlerList(org.bukkit.event.HandlerList) InvTriggerMigrationHelper(io.github.wysohn.triggerreactor.bukkit.tools.migration.InvTriggerMigrationHelper) Iterables(com.google.common.collect.Iterables) java.util(java.util) Cancellable(org.bukkit.event.Cancellable) ItemMeta(org.bukkit.inventory.meta.ItemMeta) ICommandMapHandler(io.github.wysohn.triggerreactor.bukkit.manager.trigger.ICommandMapHandler) Callable(java.util.concurrent.Callable) FileConfiguration(org.bukkit.configuration.file.FileConfiguration) PluginMessageListener(org.bukkit.plugin.messaging.PluginMessageListener) SQLException(java.sql.SQLException) ContinuingTasks(io.github.wysohn.triggerreactor.tools.ContinuingTasks) ByteArrayDataInput(com.google.common.io.ByteArrayDataInput) Trigger(io.github.wysohn.triggerreactor.core.manager.trigger.Trigger) TriggerInfo(io.github.wysohn.triggerreactor.core.manager.trigger.TriggerInfo) PlayerCommandPreprocessEvent(org.bukkit.event.player.PlayerCommandPreprocessEvent) Node(io.github.wysohn.triggerreactor.core.script.parser.Node) Listener(org.bukkit.event.Listener) HumanEntity(org.bukkit.entity.HumanEntity) ScriptEngineManager(javax.script.ScriptEngineManager) InventoryTrigger(io.github.wysohn.triggerreactor.core.manager.trigger.inventory.InventoryTrigger) IEvent(io.github.wysohn.triggerreactor.core.bridge.event.IEvent) Interpreter(io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter) SimpleLocation(io.github.wysohn.triggerreactor.core.manager.location.SimpleLocation) Manager(io.github.wysohn.triggerreactor.core.manager.Manager) java.io(java.io) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) PlayerEvent(org.bukkit.event.player.PlayerEvent) Utf8YamlConfiguration(io.github.wysohn.triggerreactor.bukkit.tools.Utf8YamlConfiguration) NaiveMigrationHelper(io.github.wysohn.triggerreactor.bukkit.tools.migration.NaiveMigrationHelper) AbstractTriggerManager(io.github.wysohn.triggerreactor.core.manager.trigger.AbstractTriggerManager) ContinuingTasks(io.github.wysohn.triggerreactor.tools.ContinuingTasks) TriggerInfo(io.github.wysohn.triggerreactor.core.manager.trigger.TriggerInfo) InvTriggerMigrationHelper(io.github.wysohn.triggerreactor.bukkit.tools.migration.InvTriggerMigrationHelper)

Example 4 with AbstractTriggerManager

use of io.github.wysohn.triggerreactor.core.manager.trigger.AbstractTriggerManager in project TriggerReactor by wysohn.

the class TriggerReactorCore method onTabComplete.

// only for /trg command
public static List<String> onTabComplete(ICommandSender sender, String[] args) {
    if (!sender.hasPermission(PERMISSION))
        return Collections.singletonList("permission denied.");
    switch(args.length) {
        case 1:
            return filter(Arrays.asList("area", "click", "cmd", "command", "custom", "del", "delete", "help", "inventory", "item", "list", "reload", "repeat", "run", "call", "saveall", "search", "sudo", "synccustom", "timings", "variables", "version", "walk"), args[0]);
        case 2:
            switch(args[0].toLowerCase()) {
                case "area":
                case "a":
                    List<String> names = triggerNames(getInstance().getAreaManager());
                    // /trg area toggle
                    names.add("toggle");
                    return filter(names, args[1]);
                case "cmd":
                case "command":
                    return filter(triggerNames(getInstance().getCmdManager()), args[1]);
                case "custom":
                    // event list
                    return filter(new ArrayList<String>(getInstance().getCustomManager().getAbbreviations()), args[1]);
                case "delete":
                case "del":
                    return filter(Arrays.asList("cmd", "command", "custom", "vars", "variables"), args[1]);
                case "inventory":
                case "i":
                    return filter(triggerNames(getInstance().getInvManager()), args[1]);
                case "item":
                    return filter(Arrays.asList("lore", "title"), args[1]);
                case "repeat":
                case "r":
                    return filter(triggerNames(getInstance().getRepeatManager()), args[1]);
                case "sudo":
                    // player selection
                    return null;
                case "synccustom":
                    return filter(triggerNames(getInstance().getCustomManager()), args[1]);
                case "timings":
                    return filter(Arrays.asList("print", "toggle", "reset"), args[1]);
                case "call":
                    return filter(triggerNames(getInstance().getNamedTriggerManager()), args[1]);
            }
        case 3:
            switch(args[0].toLowerCase()) {
                case "area":
                case "a":
                    if (!args[1].equalsIgnoreCase("toggle")) {
                        return filter(Arrays.asList("create", "delete", "enter", "exit", "sync"), args[2]);
                    }
                    return EMPTY;
                case "command":
                case "cmd":
                    return filter(Arrays.asList("aliases", "permission", "sync", "settab"), args[2]);
                case "custom":
                    return filter(triggerNames(getInstance().getCustomManager()), args[2]);
                case "delete":
                case "del":
                    AbstractTriggerManager manager;
                    switch(args[1]) {
                        case "cmd":
                        case "command":
                            manager = getInstance().getCmdManager();
                            break;
                        case "custom":
                            manager = getInstance().getCustomManager();
                            break;
                        // "vars" and "variables" also possible, but I won't be offering completions for these
                        default:
                            return EMPTY;
                    }
                    return filter(triggerNames(manager), args[2]);
                case "inventory":
                case "i":
                    return filter(Arrays.asList("column", "create", "delete", "edit", "edititems", "item", "open", "row"), args[2]);
                case "item":
                    if (args[1].equals("lore")) {
                        return filter(Arrays.asList("add", "set", "remove"), args[2]);
                    }
                case "repeat":
                case "r":
                    return filter(Arrays.asList("autostart", "delete", "interval", "pause", "status", "toggle"), args[2]);
            }
        case 4:
            switch(args[0].toLowerCase()) {
                case "inventory":
                case "i":
                    if (args[2].equalsIgnoreCase("open")) {
                        // player selection
                        return null;
                    }
                    if (args[2].equalsIgnoreCase("create")) {
                        return filter(Arrays.asList("9", "18", "27", "36", "45", "54"), args[3]);
                    }
            }
    }
    return EMPTY;
}
Also used : AbstractTriggerManager(io.github.wysohn.triggerreactor.core.manager.trigger.AbstractTriggerManager)

Aggregations

AbstractTriggerManager (io.github.wysohn.triggerreactor.core.manager.trigger.AbstractTriggerManager)4 ICommandSender (io.github.wysohn.triggerreactor.core.bridge.ICommandSender)3 IInventory (io.github.wysohn.triggerreactor.core.bridge.IInventory)3 IItemStack (io.github.wysohn.triggerreactor.core.bridge.IItemStack)3 IPlayer (io.github.wysohn.triggerreactor.core.bridge.entity.IPlayer)3 IEvent (io.github.wysohn.triggerreactor.core.bridge.event.IEvent)3 SimpleLocation (io.github.wysohn.triggerreactor.core.manager.location.SimpleLocation)3 Trigger (io.github.wysohn.triggerreactor.core.manager.trigger.Trigger)3 TriggerInfo (io.github.wysohn.triggerreactor.core.manager.trigger.TriggerInfo)3 InventoryTrigger (io.github.wysohn.triggerreactor.core.manager.trigger.inventory.InventoryTrigger)3 Interpreter (io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter)3 SelfReference (io.github.wysohn.triggerreactor.core.script.wrapper.SelfReference)3 java.util (java.util)3 GsonConfigSource (io.github.wysohn.triggerreactor.core.config.source.GsonConfigSource)2 io.github.wysohn.triggerreactor.core.manager (io.github.wysohn.triggerreactor.core.manager)2 AbstractAreaTriggerManager (io.github.wysohn.triggerreactor.core.manager.trigger.area.AbstractAreaTriggerManager)2 AbstractCommandTriggerManager (io.github.wysohn.triggerreactor.core.manager.trigger.command.AbstractCommandTriggerManager)2 AbstractCustomTriggerManager (io.github.wysohn.triggerreactor.core.manager.trigger.custom.AbstractCustomTriggerManager)2 AbstractInventoryTriggerManager (io.github.wysohn.triggerreactor.core.manager.trigger.inventory.AbstractInventoryTriggerManager)2 AbstractLocationBasedTriggerManager (io.github.wysohn.triggerreactor.core.manager.trigger.location.AbstractLocationBasedTriggerManager)2