Пример #1
0
    public String getString(Context c) {
      try {
        if (mMessage != null) {
          return mMessage;
        } else {
          if (c != null) {
            if (mRessourceId == com.openvpn.Durai.R.string.mobile_info)
              return getMobileInfoString(c);
            if (mArgs == null) return c.getString(mRessourceId);
            else return c.getString(mRessourceId, mArgs);
          } else {
            String str = String.format(Locale.ENGLISH, "Log (no context) resid %d", mRessourceId);
            if (mArgs != null) str += TextUtils.join("|", mArgs);

            return str;
          }
        }
      } catch (UnknownFormatConversionException e) {
        if (c != null)
          throw new UnknownFormatConversionException(e.getLocalizedMessage() + getString(null));
        else throw e;
      } catch (java.util.FormatFlagsConversionMismatchException e) {
        if (c != null)
          throw new FormatFlagsConversionMismatchException(
              e.getLocalizedMessage() + getString(null), e.getConversion());
        else throw e;
      }
    }
Пример #2
0
 @Subroutine(value = "format")
 public static LispString format(LispString formatString, @Optional LispObject... objects) {
   checkFormatCharacters(formatString.getData());
   try {
     Object[] data = new Object[objects.length];
     for (int i = 0; i != objects.length; i++) {
       LispObject object = objects[i];
       data[i] =
           object instanceof LispNumber
               ? ((LispNumber) object).getData()
               : (object instanceof LispString
                   ? ((LispString) object).getData()
                   : object.toString());
     }
     return new LispString(String.format(formatString.getData(), data));
   } catch (MissingFormatArgumentException e1) {
     throw new LispException(JelispBundle.message("few.args.for.format.string"));
   } catch (UnknownFormatConversionException e2) {
     char c = e2.getMessage().charAt(e2.getMessage().length() - 2);
     if (c < 'A') throw new LispException(JelispBundle.message("unexpected.format.string.end"));
     throw new InvalidFormatOperationException(c);
   } catch (IllegalFormatConversionException e3) {
     throw new LispException(JelispBundle.message("format.arg.types.mismatch"));
   }
 }
Пример #3
0
  @Override
  public void onPlayerChat(PlayerChatEvent event) {
    if (event.isCancelled()) {
      return;
    }

    Player talkingPlayer = event.getPlayer();
    String msg = event.getMessage();

    // ... it was not a command. This means that it is a chat message!
    FPlayer me = FPlayer.get(talkingPlayer);

    // Are we to insert the Faction tag into the format?
    // If we are not to insert it - we are done.
    if (!Conf.chatTagEnabled || Conf.chatTagHandledByAnotherPlugin) {
      return;
    }

    int InsertIndex = 0;
    String eventFormat = event.getFormat();

    if (!Conf.chatTagReplaceString.isEmpty() && eventFormat.contains(Conf.chatTagReplaceString)) {
      // we're using the "replace" method of inserting the faction tags
      // if they stuck "{FACTION_TITLE}" in there, go ahead and do it too
      if (eventFormat.contains("{FACTION_TITLE}")) {
        eventFormat = eventFormat.replace("{FACTION_TITLE}", me.getTitle());
      }
      InsertIndex = eventFormat.indexOf(Conf.chatTagReplaceString);
      eventFormat = eventFormat.replace(Conf.chatTagReplaceString, "");
      Conf.chatTagPadAfter = false;
      Conf.chatTagPadBefore = false;
    } else if (!Conf.chatTagInsertAfterString.isEmpty()
        && eventFormat.contains(Conf.chatTagInsertAfterString)) {
      // we're using the "insert after string" method
      InsertIndex =
          eventFormat.indexOf(Conf.chatTagInsertAfterString)
              + Conf.chatTagInsertAfterString.length();
    } else if (!Conf.chatTagInsertBeforeString.isEmpty()
        && eventFormat.contains(Conf.chatTagInsertBeforeString)) {
      // we're using the "insert before string" method
      InsertIndex = eventFormat.indexOf(Conf.chatTagInsertBeforeString);
    } else {
      // we'll fall back to using the index place method
      InsertIndex = Conf.chatTagInsertIndex;
      if (InsertIndex > eventFormat.length()) return;
    }

    String formatStart =
        eventFormat.substring(0, InsertIndex)
            + ((Conf.chatTagPadBefore && !me.getChatTag().isEmpty()) ? " " : "");
    String formatEnd =
        ((Conf.chatTagPadAfter && !me.getChatTag().isEmpty()) ? " " : "")
            + eventFormat.substring(InsertIndex);

    String nonColoredMsgFormat = formatStart + me.getChatTag().trim() + formatEnd;

    // Relation Colored?
    if (Conf.chatTagRelationColored) {
      // We must choke the standard message and send out individual messages to all players
      // Why? Because the relations will differ.
      event.setCancelled(true);

      for (Player listeningPlayer : event.getRecipients()) {
        FPlayer you = FPlayer.get(listeningPlayer);
        String yourFormat = formatStart + me.getChatTag(you).trim() + formatEnd;
        try {
          listeningPlayer.sendMessage(
              String.format(yourFormat, talkingPlayer.getDisplayName(), msg));
        } catch (UnknownFormatConversionException ex) {
          Factions.log(
              Level.SEVERE,
              "Critical error in chat message formatting! Complete format string: " + yourFormat);
          Factions.log(Level.SEVERE, "First half of event.getFormat() string: " + formatStart);
          Factions.log(Level.SEVERE, "Second half of event.getFormat() string: " + formatEnd);
          Factions.log(
              Level.SEVERE,
              "NOTE: To fix this quickly, running this command should work: f config chatTagInsertIndex 0");
          Factions.log(
              Level.SEVERE,
              "For a more proper fix, please read the chat configuration notes on the configuration page of the Factions user guide.");
          ex.printStackTrace();
          return;
        }
      }

      // Write to the log... We will write the non colored message.
      String nonColoredMsg =
          ChatColor.stripColor(
              String.format(nonColoredMsgFormat, talkingPlayer.getDisplayName(), msg));
      Logger.getLogger("Minecraft").info(nonColoredMsg);
    } else {
      // No relation color.
      event.setFormat(nonColoredMsgFormat);
    }
  }