Package com.github.zathrus_writer.commandsex.helpers.scripting

Examples of com.github.zathrus_writer.commandsex.helpers.scripting.ReplacementPair


          caseSensitive = false;
        }
       
        Matcher m = p.matcher(line);
        if (m.matches()) {
          ReplacementPair rp = null;
          success++;
         
          String regex = m.group(1);
          String opts = m.group(2);
          String methodstr = m.group(3);
          String scriptmode = m.group(4);
          String replopts = m.group(5);
          String repl = m.group(6);
          //LogHelper.logDebug("line: "+line+" > "+regex+" ==> "+repl);
         
          if (scriptmode.equals(">")){
            char method = ' ';
            if (!methodstr.isEmpty()) method = methodstr.charAt(0);
            switch (method){
            case 'c': //command method - to force command instead of chat replacement
              rp = new ReplacementCommand(regex, repl, replopts, caseSensitive, sameOutputCase); break;
            case 'r': //random method - choose from one of the ; separated list
              if (mc != MatchingContext.Chat) {
                LogHelper.logWarning(_("cmdRandomReplacementNotAllowed", "")+lineno);
                continue;
              }
              rp = new ReplacementRandom(regex, repl, caseSensitive, sameOutputCase); break;
            case ' ':
            default:
              switch (mc){
              case Command:
                rp = new ReplacementCommand(regex, repl, replopts, caseSensitive, sameOutputCase); break;
              case Chat: //only use ReplacementString for chat
                rp = new ReplacementString(regex, repl, replopts, caseSensitive, sameOutputCase); break;
              }
              break;
            }
           
          } else if (scriptmode.equals("{")){
            try {
              int blockDepth = 1;
              ArrayList<String> scriptblock = new ArrayList<String>();
             
              while ((line = br.readLine()) != null){
                //loop through input lines to get the script block
                lineno++;
                if (line.isEmpty() || line.startsWith("#")) continue;
               
                if (line.trim().equals("{")){
                  blockDepth++;
                } else if (line.trim().equals("}")) {
                  blockDepth--;
                }
                if (blockDepth == 0){
                  ScriptBlock block = new ScriptBlock(scriptblock, repl);
                  rp = new ReplacementScript(regex, block, replopts, caseSensitive, sameOutputCase);
                  setScriptForAlias(repl, block);
                  break;
                } else {
                  scriptblock.add(line);
                }
              }
              if (blockDepth != 0){
                //if the above loop broke without completing the script, it hit the end of line
                throw new BadScriptException("EOF reached before end of script reached! Please re-balance braces!");
              }
            } catch (BadScriptException e) {
              LogHelper.logWarning("[CommandsEX] " + _("fileListHelperBadScript", "") + lineno);
              LogHelper.logDebug("Message: " + e.getMessage() + ", cause: " + e.getCause());
            }
          }
          rp.setRegexOptions(opts);
          ret.add(rp);
        } else {
          LogHelper.logWarning("[CommandsEX] " + _("line", "") + " " + lineno + " " + _("fileListHelperLineBadFormat", ""));
        }
      }
View Full Code Here

TOP

Related Classes of com.github.zathrus_writer.commandsex.helpers.scripting.ReplacementPair

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.