44import net .kyori .adventure .text .minimessage .MiniMessage ;
55import net .kyori .adventure .text .minimessage .tag .resolver .Formatter ;
66import net .kyori .adventure .text .minimessage .tag .resolver .Placeholder ;
7+ import org .bukkit .OfflinePlayer ;
78import org .bukkit .configuration .file .FileConfiguration ;
89import org .jetbrains .annotations .NotNull ;
910
10- import java .util .ArrayList ;
1111import java .util .HashMap ;
1212import java .util .List ;
1313import java .util .Map ;
@@ -54,14 +54,14 @@ public PluginConfig(final @NotNull FileConfiguration config) {
5454 * <li>{@code <message>} - the message text</li>
5555 * </ul>
5656 *
57- * @param sender The username of the message sender
58- * @param recipient The username of the message recipient
57+ * @param sender The message sender
58+ * @param recipient The message recipient
5959 * @param message The message text
6060 */
61- public @ NotNull Component incoming (final @ NotNull String sender , final @ NotNull String recipient , final @ NotNull Component message ) {
61+ public @ NotNull Component incoming (final @ NotNull OfflinePlayer sender , final @ NotNull OfflinePlayer recipient , final @ NotNull Component message ) {
6262 return MiniMessage .miniMessage ().deserialize (Objects .requireNonNull (config .getString ("incoming" ))
63- .replace ("<sender>" , sender )
64- .replace ("<recipient>" , recipient ),
63+ .replace ("<sender>" , Message . name ( sender ) )
64+ .replace ("<recipient>" , Message . name ( recipient ) ),
6565 Placeholder .component ("message" , message )
6666 );
6767 }
@@ -70,19 +70,19 @@ public PluginConfig(final @NotNull FileConfiguration config) {
7070 * Outgoing message format (sender's point of view)
7171 * <p>Placeholders:</p>
7272 * <ul>
73- * <li>{@code <sender>} - the username of the message sender</li>
73+ * <li>{@code <sender>} - the message sender</li>
7474 * <li>{@code <recipient>} - the username of the message recipient</li>
7575 * <li>{@code <message>} - the message text</li>
7676 * </ul>
7777 *
78- * @param sender The username of the message sender
79- * @param recipient The username of the message recipient
78+ * @param sender The message sender
79+ * @param recipient The message recipient
8080 * @param message The message text
8181 */
82- public @ NotNull Component outgoing (final @ NotNull String sender , final @ NotNull String recipient , final @ NotNull Component message ) {
82+ public @ NotNull Component outgoing (final @ NotNull OfflinePlayer sender , final @ NotNull OfflinePlayer recipient , final @ NotNull Component message ) {
8383 return MiniMessage .miniMessage ().deserialize (Objects .requireNonNull (config .getString ("outgoing" ))
84- .replace ("<sender>" , sender )
85- .replace ("<recipient>" , recipient ),
84+ .replace ("<sender>" , Message . name ( sender ) )
85+ .replace ("<recipient>" , Message . name ( recipient ) ),
8686 Placeholder .component ("message" , message )
8787 );
8888 }
@@ -96,14 +96,14 @@ public PluginConfig(final @NotNull FileConfiguration config) {
9696 * <li>{@code <message>} - the message text</li>
9797 * </ul>
9898 *
99- * @param sender The username of the message sender
100- * @param recipient The username of the message recipient
99+ * @param sender The message sender
100+ * @param recipient The message recipient
101101 * @param message The message text
102102 */
103- public @ NotNull Component spy (final @ NotNull String sender , final @ NotNull String recipient , final @ NotNull Component message ) {
103+ public @ NotNull Component spy (final @ NotNull OfflinePlayer sender , final @ NotNull OfflinePlayer recipient , final @ NotNull Component message ) {
104104 return MiniMessage .miniMessage ().deserialize (Objects .requireNonNull (config .getString ("spy" ))
105- .replace ("<sender>" , sender )
106- .replace ("<recipient>" , recipient ),
105+ .replace ("<sender>" , Message . name ( sender ) )
106+ .replace ("<recipient>" , Message . name ( recipient ) ),
107107 Placeholder .component ("message" , message )
108108 );
109109 }
@@ -113,11 +113,11 @@ public PluginConfig(final @NotNull FileConfiguration config) {
113113 * <p>Placeholders:</p>
114114 * <ul><li>{@code <player>} - the username of the player</li></ul>
115115 *
116- * @param player The username of the player
116+ * @param player The player
117117 */
118- public @ NotNull Component ignored (final @ NotNull String player ) {
118+ public @ NotNull Component ignored (final @ NotNull OfflinePlayer player ) {
119119 return MiniMessage .miniMessage ().deserialize (Objects .requireNonNull (config .getString ("ignored" )),
120- Placeholder .unparsed ("player" , player )
120+ Placeholder .unparsed ("player" , Message . name ( player ) )
121121 );
122122 }
123123
@@ -126,11 +126,11 @@ public PluginConfig(final @NotNull FileConfiguration config) {
126126 * <p>Placeholders:</p>
127127 * <ul><li>{@code <player>} - the username of the player</li></ul>
128128 *
129- * @param player The username of the player
129+ * @param player The player
130130 */
131- public @ NotNull Component unignored (final @ NotNull String player ) {
131+ public @ NotNull Component unignored (final @ NotNull OfflinePlayer player ) {
132132 return MiniMessage .miniMessage ().deserialize (Objects .requireNonNull (config .getString ("unignored" )),
133- Placeholder .unparsed ("player" , player )
133+ Placeholder .unparsed ("player" , Message . name ( player ) )
134134 );
135135 }
136136
@@ -143,14 +143,14 @@ public PluginConfig(final @NotNull FileConfiguration config) {
143143 * <li>{@code <command>} - the command used, e.g. `msg`, `dm`, etc.</li>
144144 * </ul>
145145 *
146- * @param sender The username of the message sender
147- * @param recipient The username of the message recipient
146+ * @param sender The message sender
147+ * @param recipient The message recipient
148148 * @param command The command used, e.g. `msg`, `dm`, etc.
149149 */
150- public @ NotNull Component channelCreated (final @ NotNull String sender , final @ NotNull String recipient , final @ NotNull String command ) {
150+ public @ NotNull Component channelCreated (final @ NotNull OfflinePlayer sender , final @ NotNull OfflinePlayer recipient , final @ NotNull String command ) {
151151 return MiniMessage .miniMessage ().deserialize (Objects .requireNonNull (config .getString ("channel.created" ))
152- .replace ("<sender>" , sender )
153- .replace ("<recipient>" , recipient )
152+ .replace ("<sender>" , Message . name ( sender ) )
153+ .replace ("<recipient>" , Message . name ( recipient ) )
154154 .replace ("<command>" , command ));
155155 }
156156
@@ -163,14 +163,14 @@ public PluginConfig(final @NotNull FileConfiguration config) {
163163 * <li>{@code <command>} - the command used, e.g. `msg`, `dm`, etc.</li>
164164 * </ul>
165165 *
166- * @param sender The username of the message sender
167- * @param recipient The username of the message recipient
166+ * @param sender The message sender
167+ * @param recipient The message recipient
168168 * @param command The command used, e.g. `msg`, `dm`, etc.
169169 */
170- public @ NotNull Component channelClosed (final @ NotNull String sender , final @ NotNull String recipient , final @ NotNull String command ) {
170+ public @ NotNull Component channelClosed (final @ NotNull OfflinePlayer sender , final @ NotNull OfflinePlayer recipient , final @ NotNull String command ) {
171171 return MiniMessage .miniMessage ().deserialize (Objects .requireNonNull (config .getString ("channel.closed" ))
172- .replace ("<sender>" , sender )
173- .replace ("<recipient>" , recipient )
172+ .replace ("<sender>" , Message . name ( sender ) )
173+ .replace ("<recipient>" , Message . name ( recipient ) )
174174 .replace ("<command>" , command ));
175175 }
176176
@@ -182,13 +182,13 @@ public PluginConfig(final @NotNull FileConfiguration config) {
182182 * <li>{@code <recipient>} - the username of the message recipient</li>
183183 * </ul>
184184 *
185- * @param sender The username of the message sender
186- * @param recipient The username of the message recipient
185+ * @param sender The message sender
186+ * @param recipient The message recipient
187187 */
188- public @ NotNull Component channelOffline (final @ NotNull String sender , final @ NotNull String recipient ) {
188+ public @ NotNull Component channelOffline (final @ NotNull OfflinePlayer sender , final @ NotNull OfflinePlayer recipient ) {
189189 return MiniMessage .miniMessage ().deserialize (Objects .requireNonNull (config .getString ("channel.offline" ))
190- .replace ("<sender>" , sender )
191- .replace ("<recipient>" , recipient ));
190+ .replace ("<sender>" , Message . name ( sender ) )
191+ .replace ("<recipient>" , Message . name ( recipient ) ));
192192 }
193193
194194 /**
@@ -223,6 +223,13 @@ public PluginConfig(final @NotNull FileConfiguration config) {
223223 return Objects .requireNonNull (config .getString ("console-name" ));
224224 }
225225
226+ /**
227+ * Name for player when name not found (usually very unlikely to happen)
228+ */
229+ public @ NotNull String unknownName () {
230+ return Objects .requireNonNull (config .getString ("unknown-name" ));
231+ }
232+
226233 public @ NotNull Component toggleDisable () {
227234 return MiniMessage .miniMessage ().deserialize (Objects .requireNonNull (config .getString ("toggle.disable.message" )));
228235 }
@@ -232,11 +239,11 @@ public PluginConfig(final @NotNull FileConfiguration config) {
232239 * <p>Placeholders:</p>
233240 * <ul><li>{@code <player>} - the player's username</li></ul>
234241 *
235- * @param player the player's username
242+ * @param player the player
236243 */
237- public @ NotNull Component toggleDisableOther (final @ NotNull String player ) {
244+ public @ NotNull Component toggleDisableOther (final @ NotNull OfflinePlayer player ) {
238245 return MiniMessage .miniMessage ().deserialize (Objects .requireNonNull (config .getString ("toggle.disable.other" )),
239- Placeholder .unparsed ("player" , player )
246+ Placeholder .unparsed ("player" , Message . name ( player ) )
240247 );
241248 }
242249
@@ -249,11 +256,11 @@ public PluginConfig(final @NotNull FileConfiguration config) {
249256 * <p>Placeholders:</p>
250257 * <ul><li>{@code <player>} - the player's username</li></ul>
251258 *
252- * @param player the player's username
259+ * @param player the player
253260 */
254- public @ NotNull Component toggleEnableOther (final @ NotNull String player ) {
261+ public @ NotNull Component toggleEnableOther (final @ NotNull OfflinePlayer player ) {
255262 return MiniMessage .miniMessage ().deserialize (Objects .requireNonNull (config .getString ("toggle.enable.other" )),
256- Placeholder .unparsed ("player" , player )
263+ Placeholder .unparsed ("player" , Message . name ( player ) )
257264 );
258265 }
259266
@@ -325,11 +332,11 @@ public int mailNotifyInterval() {
325332 * <p>Placeholders:</p>
326333 * <ul><li>{@code <player>} - the player's username</li></ul>
327334 *
328- * @param player The player's username
335+ * @param player The player
329336 */
330- public @ NotNull Component playerNotFound (final @ NotNull String player ) {
337+ public @ NotNull Component playerNotFound (final @ NotNull OfflinePlayer player ) {
331338 return MiniMessage .miniMessage ().deserialize (Objects .requireNonNull (config .getString ("errors.player-not-found" )),
332- Placeholder .unparsed ("player" , player )
339+ Placeholder .unparsed ("player" , Message . name ( player ) )
333340 );
334341 }
335342
@@ -346,11 +353,11 @@ public int mailNotifyInterval() {
346353 * <p>Placeholders:</p>
347354 * <ul><li>{@code <player>} - the player's username</li></ul>
348355 *
349- * @param player The player's username
356+ * @param player The player
350357 */
351- public @ NotNull Component replyOffline (final @ NotNull String player ) {
358+ public @ NotNull Component replyOffline (final @ NotNull OfflinePlayer player ) {
352359 return MiniMessage .miniMessage ().deserialize (Objects .requireNonNull (config .getString ("errors.reply-offline" )),
353- Placeholder .unparsed ("player" , player )
360+ Placeholder .unparsed ("player" , Message . name ( player ) )
354361 );
355362 }
356363
@@ -366,11 +373,11 @@ public int mailNotifyInterval() {
366373 * <p>Placeholders:</p>
367374 * <ul><li>{@code <player>} - the player's username</li></ul>
368375 *
369- * @param player The player's username
376+ * @param player The player
370377 */
371- public @ NotNull Component notIgnored (final @ NotNull String player ) {
378+ public @ NotNull Component notIgnored (final @ NotNull OfflinePlayer player ) {
372379 return MiniMessage .miniMessage ().deserialize (Objects .requireNonNull (config .getString ("errors.not-ignored" )),
373- Placeholder .unparsed ("player" , player )
380+ Placeholder .unparsed ("player" , Message . name ( player ) )
374381 );
375382 }
376383
@@ -379,11 +386,11 @@ public int mailNotifyInterval() {
379386 * <p>Placeholders:</p>
380387 * <ul><li>{@code <player>} - the player's username</li></ul>
381388 *
382- * @param player The player's username
389+ * @param player The player
383390 */
384- public @ NotNull Component cannotIgnore (final @ NotNull String player ) {
391+ public @ NotNull Component cannotIgnore (final @ NotNull OfflinePlayer player ) {
385392 return MiniMessage .miniMessage ().deserialize (Objects .requireNonNull (config .getString ("errors.cannot-ignore" )),
386- Placeholder .unparsed ("player" , player )
393+ Placeholder .unparsed ("player" , Message . name ( player ) )
387394 );
388395 }
389396
@@ -392,11 +399,11 @@ public int mailNotifyInterval() {
392399 * <p>Placeholders:</p>
393400 * <ul><li>{@code <player>} - the player's username</li></ul>
394401 *
395- * @param player The player's username
402+ * @param player The player
396403 */
397- public @ NotNull Component neverJoined (final @ NotNull String player ) {
404+ public @ NotNull Component neverJoined (final @ NotNull OfflinePlayer player ) {
398405 return MiniMessage .miniMessage ().deserialize (Objects .requireNonNull (config .getString ("errors.never-joined" )),
399- Placeholder .unparsed ("player" , player )
406+ Placeholder .unparsed ("player" , Message . name ( player ) )
400407 );
401408 }
402409
@@ -405,11 +412,11 @@ public int mailNotifyInterval() {
405412 * <p>Placeholders:</p>
406413 * <ul><li>{@code <player>} - the player's username</li></ul>
407414 *
408- * @param player The player's username
415+ * @param player The player
409416 */
410- public @ NotNull Component incomingDisabled (final @ NotNull String player ) {
417+ public @ NotNull Component incomingDisabled (final @ NotNull OfflinePlayer player ) {
411418 return MiniMessage .miniMessage ().deserialize (Objects .requireNonNull (config .getString ("errors.incoming-disabled" )),
412- Placeholder .unparsed ("player" , player )
419+ Placeholder .unparsed ("player" , Message . name ( player ) )
413420 );
414421 }
415422}
0 commit comments