@@ -39,178 +39,145 @@ class EcoLprLangYml(plugin: EcoLprPlugin) : LangYml(plugin) {
3939 override fun getMessage (
4040 reference : String ,
4141 option : StringUtils .FormatOption
42- ) = this .getMessage(reference, option) { it }
42+ ) = this .getMessage(reference, option, null )
4343
4444 fun getMessage (
4545 reference : String ,
46- apply : (String ) -> String
46+ replace : (StringBuilder .( ) -> Unit ) ? = null
4747 ) = this .getMessage(
4848 reference,
4949 StringUtils .FormatOption .WITH_PLACEHOLDERS ,
50- apply
50+ replace
5151 )
5252
5353 fun getMessage (
5454 reference : String ,
5555 option : StringUtils .FormatOption ,
56- apply : (String ) -> String
56+ replace : (StringBuilder .( ) -> Unit ) ? = null
5757 ): String {
5858 var string = this .string(reference).also { if (it.isEmpty()) return " " }
59-
6059 if (option == StringUtils .FormatOption .WITH_PLACEHOLDERS )
6160 for (injection in placeholderInjections) {
6261 string = injection.tryTranslateQuickly(
6362 string,
6463 PlaceholderContext .EMPTY
6564 )
6665 }
67-
68- return StringUtils .format(apply (string) , option)
66+ val replaced = replace?. let { StringBuilder (string). apply (it).toString() } ? : string
67+ return StringUtils .format(replaced , option)
6968 }
7069
71- fun getMessage (
72- reference : String ,
73- player : Player
74- ) = getMessage(
75- reference,
76- player
77- ) { it }
78-
79- fun getMessage (
80- reference : String ,
81- context : PlaceholderContext
82- ) = getMessage(reference, context) { it }
83-
8470 fun getMessage (
8571 reference : String ,
8672 player : Player ,
87- apply : (String ) -> String
73+ replace : (StringBuilder .( ) -> Unit ) ? = null
8874 ) = getMessage(
8975 reference,
9076 PlaceholderContext (player),
91- apply
77+ replace
9278 )
9379
9480 fun getMessage (
9581 reference : String ,
9682 context : PlaceholderContext ,
97- apply : (String ) -> String
83+ replace : (StringBuilder .( ) -> Unit ) ? = null
9884 ): String {
9985 var string = this .string(reference).also { if (it.isEmpty()) return " " }
100-
10186 for (injection in placeholderInjections) {
10287 string = injection.tryTranslateQuickly(string, context)
10388 }
104-
105- return StringUtils .format(apply (string) , context)
89+ val replaced = replace?. let { StringBuilder (string). apply (it).toString() } ? : string
90+ return StringUtils .format(replaced , context)
10691 }
10792
10893 fun getMessages (
10994 reference : String ,
110- option : StringUtils .FormatOption
111- ) = this .getMessages(reference, option) { it }
112-
113- fun getMessages (
114- reference : String ,
115- apply : (String ) -> String
95+ replace : (StringBuilder .() -> Unit )? = null
11696 ) = this .getMessages(
11797 reference,
11898 StringUtils .FormatOption .WITH_PLACEHOLDERS ,
119- apply
99+ replace
120100 )
121101
122102 fun getMessages (
123103 reference : String ,
124104 option : StringUtils .FormatOption ,
125- apply : (String ) -> String
105+ replace : (StringBuilder .( ) -> Unit ) ? = null
126106 ): List <String > {
127107 val strings = this .strings(reference).also { if (it.isEmpty()) return emptyList() }
128-
129108 return strings.map { original ->
130- var str = original
109+ var string = original
131110 if (option == StringUtils .FormatOption .WITH_PLACEHOLDERS ) {
132111 for (injection in placeholderInjections) {
133- str = injection.tryTranslateQuickly(str , PlaceholderContext .EMPTY )
112+ string = injection.tryTranslateQuickly(string , PlaceholderContext .EMPTY )
134113 }
135114 }
136- StringUtils .format(apply (str), option)
115+ val replaced = replace?.let { StringBuilder (string).apply (it).toString() } ? : string
116+ StringUtils .format(replaced, option)
137117 }
138118 }
139119
140- fun getMessages (
141- reference : String ,
142- player : Player
143- ) = getMessages(
144- reference,
145- player
146- ) { it }
147-
148- fun getMessages (
149- reference : String ,
150- context : PlaceholderContext
151- ) = getMessages(reference, context) { it }
152-
153120 fun getMessages (
154121 reference : String ,
155122 player : Player ,
156- apply : (String ) -> String
123+ replace : (StringBuilder .( ) -> Unit ) ? = null
157124 ) = getMessages(
158125 reference,
159126 PlaceholderContext (player),
160- apply
127+ replace
161128 )
162129
163130 fun getMessages (
164131 reference : String ,
165132 context : PlaceholderContext ,
166- apply : (String ) -> String
133+ replace : (StringBuilder .( ) -> Unit ) ? = null
167134 ): List <String > {
168135 val strings = this .strings(reference).also { if (it.isEmpty()) return emptyList() }
169-
170136 return strings.map { original ->
171- var str = original
137+ var string = original
172138 for (injection in placeholderInjections) {
173- str = injection.tryTranslateQuickly(str , context)
139+ string = injection.tryTranslateQuickly(string , context)
174140 }
175- StringUtils .format(apply (str), context)
141+ val replaced = replace?.let { StringBuilder (string).apply (it).toString() } ? : string
142+ StringUtils .format(replaced, context)
176143 }
177144 }
178145
179146 fun sendMessage (
180147 recipient : CommandSender ,
181148 reference : String ,
182- apply : (String ) -> String = { it }
149+ replace : (StringBuilder .( ) -> Unit ) ? = null
183150 ) = if (recipient is Player ) sendMessage(
184151 recipient,
185152 reference,
186153 PlaceholderContext (recipient),
187- apply
154+ replace
188155 ) else sendMessage(
189156 recipient,
190157 reference,
191158 PlaceholderContext .EMPTY ,
192- apply
159+ replace
193160 )
194161
195162 fun sendMessage (
196163 recipient : CommandSender ,
197164 reference : String ,
198165 player : Player ,
199- apply : (String ) -> String = { it }
166+ replace : (StringBuilder .( ) -> Unit ) ? = null
200167 ) = sendMessage(
201168 recipient,
202169 reference,
203170 PlaceholderContext (player),
204- apply
171+ replace
205172 )
206173
207174 fun sendMessage (
208175 recipient : CommandSender ,
209176 reference : String ,
210177 context : PlaceholderContext ,
211- apply : (String ) -> String = { it }
178+ replace : (StringBuilder .( ) -> Unit ) ? = null
212179 ): Boolean {
213- val message = getMessage(reference, context, apply )
180+ val message = getMessage(reference, context, replace )
214181 if (message.isEmpty()) return false
215182 recipient.sendMessage(message)
216183 return true
@@ -219,38 +186,38 @@ class EcoLprLangYml(plugin: EcoLprPlugin) : LangYml(plugin) {
219186 fun sendMessages (
220187 recipient : CommandSender ,
221188 reference : String ,
222- apply : (String ) -> String = { it }
189+ replace : (StringBuilder .( ) -> Unit ) ? = null
223190 ): Boolean = if (recipient is Player ) sendMessages(
224191 recipient,
225192 reference,
226193 PlaceholderContext (recipient),
227- apply
194+ replace
228195 ) else sendMessages(
229196 recipient,
230197 reference,
231198 PlaceholderContext .EMPTY ,
232- apply
199+ replace
233200 )
234201
235202 fun sendMessages (
236203 recipient : CommandSender ,
237204 reference : String ,
238205 player : Player ,
239- apply : (String ) -> String = { it }
206+ replace : (StringBuilder .( ) -> Unit ) ? = null
240207 ): Boolean = sendMessages(
241208 recipient,
242209 reference,
243210 PlaceholderContext (player),
244- apply
211+ replace
245212 )
246213
247214 fun sendMessages (
248215 recipient : CommandSender ,
249216 reference : String ,
250217 context : PlaceholderContext ,
251- apply : (String ) -> String = { it }
218+ replace : (StringBuilder .( ) -> Unit ) ? = null
252219 ): Boolean {
253- val messages = getMessages(reference, context, apply )
220+ val messages = getMessages(reference, context, replace )
254221 if (messages.isEmpty()) return false
255222 messages.forEach { if (it.isNotEmpty()) recipient.sendMessage(it) }
256223 return true
0 commit comments