Examples of ScriptEnvironment


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

   * @return
   */
  @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
  public void replaceChat(AsyncPlayerChatEvent e) {
    try {
      ScriptEnvironment env = new ScriptEnvironment(); {
        env.setCommandSender(e.getPlayer());
        env.setServer(e.getPlayer().getServer());
      }
      ArrayList<ReplacementPair> preparedEffects = new ArrayList<ReplacementPair>(); //holds all effects until all replacements done

      for (ReplacementPair rp : pairs) {
        StringBuffer sb = new StringBuffer();
        Matcher m = rp.getRegex().matcher(e.getMessage());
        if (!m.find()) continue;
        env.setMatcher(m);

        if (rp.playerWillVanish()) { //the player will vanish as a result of this, special handling
          int cutlen = CommandsEX.getConf().getInt("replacements.cutoff.length", 1);
          String cuttext = CommandsEX.getConf().getString("replacements.cutoff.indicator", "--*");
 
          String rep = m.group().substring(0, cutlen).concat(cuttext);
          m.appendReplacement(sb, rep);
          e.setMessage(sb.toString());
          //e.setCancelled(true);
          //e.getPlayer().chat(sb.toString()); //chat first
 
          rp.executeEffects(env); //then execute the replacement
          return;
        }

        //loop through with find/replace
        do { //use do while, due to the find() invocation above
          // test if it is all upper, and replace with all upper (if we have this set up in the regex itself - in config file)
          if (rp.getSameOutputCase() && allUpper && m.group().toUpperCase().equals(m.group())) {
            m.appendReplacement(sb, rp.executeString(env).toUpperCase());
          } else {
            m.appendReplacement(sb, rp.executeString(env));
          }
        } while (m.find());
        m.appendTail(sb);

        if (!preparedEffects.contains(rp)) {
          preparedEffects.add(rp);
        }
        e.setMessage(sb.toString());
      }
     
      //after all replacements are in: execute the effects
      if (!preparedEffects.isEmpty()) {
        //e.setCancelled(true);
        //e.getPlayer().chat(sb.toString()); //chat first
 
        env.setMatcher(null);
        for (ReplacementPair rp : preparedEffects){
          rp.executeEffects(env);
        }
      }
    } catch (Exception ex){
View Full Code Here

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

   * @return
   */
  @EventHandler(priority = EventPriority.LOWEST)
  public static void replaceCommand(PlayerCommandPreprocessEvent e) {
    try {
      ScriptEnvironment env = new ScriptEnvironment(); {
        env.setCommandSender(e.getPlayer());
        env.setServer(e.getPlayer().getServer());
      }

      for (ReplacementPair rp : pairs) {
        Matcher m = rp.getRegex().matcher(e.getMessage().substring(1));
        if (m.matches()){
          env.setMatcher(m);
          rp.executeEffects(env);
          e.setCancelled(true);
          return;
        }
      }
View Full Code Here

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

   * @return
   */
  @EventHandler(priority = EventPriority.LOWEST)
  public void replaceCommand(ServerCommandEvent e) {
    try {
      ScriptEnvironment env = new ScriptEnvironment(); {
        env.setCommandSender(e.getSender());
        env.setServer(e.getSender().getServer());
      }
     
      for (ReplacementPair rp : pairs) {
        Matcher m = rp.getRegex().matcher(e.getCommand());
        if (m.matches()){
          env.setMatcher(m);
          rp.executeEffects(env);
          e.setCommand("cex null"); //does nothing, prints nothing
          return;
        }
      }
View Full Code Here

Examples of gri.gridp.modules.ScriptEnvironment

  public Object read(Element elem) {
    return readScript(elem);
  }

  public void writeScript(Script script, Element elem) {
    ScriptEnvironment env = script.getEnvironment();

    //os:
    String os = env.getOperatingSystem();
    if (os != null && !os.equals(ScriptEnvironment.UNKNOWN_OS))
      elem.setAttribute("os", os);

    //shell:
    String shell = env.getShell();
    if (shell != null && !shell.equals(ScriptEnvironment.UNKNOWN_SHELL))
      elem.setAttribute("shell", shell);

    //script:
    elem.addContent(new CDATA(script.getText()));
View Full Code Here

Examples of gri.gridp.modules.ScriptEnvironment

  }

  public Script readScript(Element element) {
    Script s = new Script();
    ScriptEnvironment e = s.getEnvironment();

    Attribute a;
    //os:
    a = element.getAttribute("os");
    if (a != null)
      e.setOperatingSystem(a.getValue());

    //shell:
    a = element.getAttribute("shell");
    if (a != null)
      e.setShell(a.getValue());

    //script:
    s.setText(element.getValue());

    return s;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.