> {
+
+ /**
+ * Used to match the message insertion
+ *
+ * format:
+ *
- to insert parsed line {prefix}#content-id#{offset-above,offset-down}
+ *
- to insert original line {prefix}@content-id@{offset-above,offset-down}
+ *
example:
+ *
+ * - {- }#content-id#{1,1}
+ * - @content-id@{1,1}
+ *
+ */
+ public static final @NotNull Pattern INSERT_PATTERN = Pattern.compile(
+ "^(?:\\{(?.*)})?(?[#@])(?.*)[#@](?:\\{(?-?\\d+)(?:,(?-?\\d+))?})?$"
+ );
+
+ protected final @NotNull TextContents texts;
+
+ protected BiFunction parser = (receiver, value) -> value;
+ protected String lineSeparator = System.lineSeparator();
+
+ /**
+ * Used to store the placeholders of the message
+ */
+ protected @NotNull Map placeholders = new HashMap<>();
+ protected @NotNull UnaryOperator paramBuilder = s -> "%(" + s + ")";
+ protected @NotNull String[] params;
+
+ /**
+ * Used to store the insertion of the message
+ */
+ protected @NotNull Map> insertion = new HashMap<>();
+ protected boolean disableInsertion = false;
+
+ protected TextParser(@NotNull TextContents texts, @NotNull String... params) {
+ this.texts = texts;
+ this.params = params;
+ }
+
+ public abstract SELF self();
+
+ /**
+ * Disable the insertion of the text.
+ *
If the insertion is disabled, the text will be parsed directly.
+ *
+ * @return the current {@link TextParser} instance
+ */
+ public SELF disableInsertion() {
+ this.disableInsertion = true;
+ return self();
+ }
+
+ /**
+ * Enable the insertion of the text.
+ *
+ * @return the current {@link TextParser} instance
+ */
+ public SELF enableInsertion() {
+ this.disableInsertion = false;
+ return self();
+ }
+
+ /**
+ * Set the line separator for the text.
+ *
+ * @param lineSeparator the line separator, default is {@link System#lineSeparator()}
+ * @return the current {@link TextParser} instance
+ */
+ public SELF lineSeparator(@NotNull String lineSeparator) {
+ this.lineSeparator = lineSeparator;
+ return self();
+ }
+
+ /**
+ * Set all the placeholders for the text.
+ *
Will override the previous placeholders modifications.
+ *
+ * @param placeholders the placeholders
+ * @return the current {@link TextParser} instance
+ */
+ public SELF placeholders(@NotNull Map placeholders) {
+ this.placeholders = placeholders;
+ return self();
+ }
+
+ /**
+ * Set the placeholders for the text.
+ *
+ * @param consumer the placeholders
+ * @return the current {@link TextParser} instance
+ */
+ public SELF placeholders(@NotNull Consumer