@@ -37,17 +37,17 @@ public static List<StringReplacer> getStringReplacers() {
3737 }
3838
3939 /**
40- * Get the operator to replace the string
40+ * Create the map template based on the unique id
4141 *
4242 * @param uuid the unique id
4343 * @param menuElement the menu element
4444 *
45- * @return the item builder
45+ * @return the map template
4646 */
47- public static UnaryOperator < String > getReplaceOperator (UUID uuid , MenuElement menuElement ) {
47+ public static MapTemplate createMapTemplate (UUID uuid , MenuElement menuElement ) {
4848 VariableManager variableManager = BetterGUI .getInstance ().get (VariableManager .class );
4949
50- MapTemplate mapTemplate = MapTemplate .builder ()
50+ return MapTemplate .builder ()
5151 .setVariableFunction (s -> {
5252 MenuElement currentMenuElement = menuElement ;
5353 while (currentMenuElement != null ) {
@@ -61,6 +61,18 @@ public static UnaryOperator<String> getReplaceOperator(UUID uuid, MenuElement me
6161 return variableManager .tryReplace (s , uuid );
6262 })
6363 .build ();
64+ }
65+
66+ /**
67+ * Get the operator to replace the string
68+ *
69+ * @param uuid the unique id
70+ * @param menuElement the menu element
71+ *
72+ * @return the item builder
73+ */
74+ public static UnaryOperator <String > getReplaceOperator (UUID uuid , MenuElement menuElement ) {
75+ MapTemplate mapTemplate = createMapTemplate (uuid , menuElement );
6476
6577 List <StringReplacer > replacers = new ArrayList <>(STRING_REPLACERS );
6678 replacers .add (COLORIZE );
@@ -93,22 +105,7 @@ public static UnaryOperator<String> getReplaceOperator(UUID uuid) {
93105 * @return the replaced string
94106 */
95107 public static String replace (String string , UUID uuid , MenuElement menuElement ) {
96- VariableManager variableManager = BetterGUI .getInstance ().get (VariableManager .class );
97-
98- MapTemplate mapTemplate = MapTemplate .builder ()
99- .setVariableFunction (s -> {
100- MenuElement currentMenuElement = menuElement ;
101- while (currentMenuElement != null ) {
102- String replaced = currentMenuElement .getStringReplacer ().tryReplace (s , uuid );
103- if (replaced != null ) {
104- return replaced ;
105- }
106- currentMenuElement = currentMenuElement .getParent ();
107- }
108-
109- return variableManager .tryReplace (s , uuid );
110- })
111- .build ();
108+ MapTemplate mapTemplate = createMapTemplate (uuid , menuElement );
112109
113110 string = Objects .toString (mapTemplate .apply (string ));
114111
0 commit comments