Skip to content

Commit 18d4a8a

Browse files
authored
docs: clarify thread safety javadoc and fix typos in BmAPI (#953) (#1058)
Reword the contradictory "not thread safe and should not be called on the main thread" statement to clearly separate the two constraints: blocking I/O (don't call on the main thread) and lack of internal synchronization (caller must synchronize concurrent access). Applied to getWarnings, getPlayerNames, getPlayerHistory, getPlayerNameAt, getBanRecords(PlayerData), getMuteRecords, and getBanRecords(IPAddress). Also fixes: - "mutened" -> "muted" typo in three mute method javadocs - "warningss" -> "warnings" typo in getWarnings - misleading "IP to ban" @param on isBanned, getCurrentBan, and getBanRecords query methods
1 parent 2efe6b2 commit 18d4a8a

1 file changed

Lines changed: 43 additions & 13 deletions

File tree

  • common/src/main/java/me/confuser/banmanager/common/api

common/src/main/java/me/confuser/banmanager/common/api/BmAPI.java

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,12 @@ public static PlayerBanData getCurrentBan(UUID uuid) {
175175
}
176176

177177
/**
178+
* Retrieve previous ban records for a player.
179+
* <p>This method performs blocking database I/O and should not be called
180+
* from the main server thread. Use an asynchronous task instead.</p>
181+
* <p>This method is not internally synchronized. If called concurrently
182+
* from multiple threads, the caller is responsible for synchronization.</p>
183+
*
178184
* @param player BanManager's player record
179185
* @return An iterator of ban records
180186
* @throws SQLException
@@ -215,7 +221,7 @@ public static boolean mute(PlayerData player, PlayerData actor, String reason) t
215221
*
216222
* @param player Player to mute
217223
* @param actor Who the mute is by
218-
* @param reason Why they are mutened
224+
* @param reason Why they are muted
219225
* @param silent Whether the mute should be broadcast
220226
* @return Returns true if mute is successful
221227
* @throws SQLException
@@ -230,7 +236,7 @@ public static boolean mute(PlayerData player, PlayerData actor, String reason, b
230236
*
231237
* @param player Player to mute
232238
* @param actor Who the mute is by
233-
* @param reason Why they are mutened
239+
* @param reason Why they are muted
234240
* @param silent Whether the mute should be broadcast
235241
* @param isSoft Whether the player should be aware they are muted; they will still see their own messages but nobody else will
236242
* @return Returns true if the mute is successful
@@ -247,7 +253,7 @@ public static boolean mute(PlayerData player, PlayerData actor, String reason, b
247253
*
248254
* @param player Player to mute
249255
* @param actor Who the mute is by
250-
* @param reason Why they are mutened
256+
* @param reason Why they are muted
251257
* @param silent Whether the mute should be broadcast
252258
* @param isSoft Whether the player should be aware they are muted; they will still see their own messages but nobody else will
253259
* @param expires Unix Timestamp in seconds stating the time of when the mute ends
@@ -362,6 +368,12 @@ public static PlayerMuteData getCurrentMute(UUID uuid) {
362368
}
363369

364370
/**
371+
* Retrieve previous mute records for a player.
372+
* <p>This method performs blocking database I/O and should not be called
373+
* from the main server thread. Use an asynchronous task instead.</p>
374+
* <p>This method is not internally synchronized. If called concurrently
375+
* from multiple threads, the caller is responsible for synchronization.</p>
376+
*
365377
* @param player Player record
366378
* @return Iterator of previous mutes
367379
* @throws SQLException
@@ -437,7 +449,7 @@ public static boolean unban(IpBanData ban, PlayerData actor, boolean silent) thr
437449
/**
438450
* Thread safe
439451
*
440-
* @param ip IP to ban, use toIp to convert x.x.x.x to IPAddress
452+
* @param ip IP address to check, use toIp to convert x.x.x.x to IPAddress
441453
* @return Returns true if ip is banned
442454
*/
443455
public static boolean isBanned(IPAddress ip) {
@@ -447,16 +459,22 @@ public static boolean isBanned(IPAddress ip) {
447459
/**
448460
* Thread safe
449461
*
450-
* @param ip IP to ban, use toIp to convert x.x.x.x to IPAddress
451-
* @return Returns the active ban of an ip if the ip is not banned this returns null
462+
* @param ip IP address to check, use toIp to convert x.x.x.x to IPAddress
463+
* @return Returns the active ban of an ip; if the ip is not banned this returns null
452464
*/
453465
public static IpBanData getCurrentBan(IPAddress ip) {
454466
return BanManagerPlugin.getInstance().getIpBanStorage().getBan(ip);
455467
}
456468

457469
/**
458-
* @param ip IP to ban, use toIp to convert x.x.x.x to IPAddress
459-
* @return Returns previous bans of an ip
470+
* Retrieve previous bans of an IP address.
471+
* <p>This method performs blocking database I/O and should not be called
472+
* from the main server thread. Use an asynchronous task instead.</p>
473+
* <p>This method is not internally synchronized. If called concurrently
474+
* from multiple threads, the caller is responsible for synchronization.</p>
475+
*
476+
* @param ip IP address to look up, use toIp to convert x.x.x.x to IPAddress
477+
* @return Iterator of previous bans for the ip
460478
* @throws SQLException
461479
*/
462480
public static CloseableIterator<IpBanRecord> getBanRecords(IPAddress ip) throws SQLException {
@@ -522,10 +540,13 @@ public static boolean warn(PlayerWarnData data, boolean silent) throws SQLExcept
522540

523541
/**
524542
* Retrieve past warnings of a player.
525-
* This method is not thread safe and should not be called on the main thread.
543+
* <p>This method performs blocking database I/O and should not be called
544+
* from the main server thread. Use an asynchronous task instead.</p>
545+
* <p>This method is not internally synchronized. If called concurrently
546+
* from multiple threads, the caller is responsible for synchronization.</p>
526547
*
527548
* @param player Player record
528-
* @return Iterator containing previous player warningss
549+
* @return Iterator containing previous player warnings
529550
* @throws SQLException
530551
*/
531552
public static CloseableIterator<PlayerWarnData> getWarnings(PlayerData player) throws SQLException {
@@ -534,7 +555,10 @@ public static CloseableIterator<PlayerWarnData> getWarnings(PlayerData player) t
534555

535556
/**
536557
* Get all known names for a player (summary view with first/last seen).
537-
* This method is not thread safe and should not be called on the main thread.
558+
* <p>This method performs blocking database I/O and should not be called
559+
* from the main server thread. Use an asynchronous task instead.</p>
560+
* <p>This method is not internally synchronized. If called concurrently
561+
* from multiple threads, the caller is responsible for synchronization.</p>
538562
*
539563
* @param uuid Player UUID
540564
* @return List of PlayerNameSummary ordered by lastSeen descending (most recent first)
@@ -550,7 +574,10 @@ public static List<PlayerNameSummary> getPlayerNames(UUID uuid) throws SQLExcept
550574

551575
/**
552576
* Get the full session history for a player.
553-
* This method is not thread safe and should not be called on the main thread.
577+
* <p>This method performs blocking database I/O and should not be called
578+
* from the main server thread. Use an asynchronous task instead.</p>
579+
* <p>This method is not internally synchronized. If called concurrently
580+
* from multiple threads, the caller is responsible for synchronization.</p>
554581
*
555582
* @param uuid Player UUID
556583
* @param since Unix timestamp in seconds to get sessions since
@@ -568,7 +595,10 @@ public static CloseableIterator<PlayerHistoryData> getPlayerHistory(UUID uuid, l
568595

569596
/**
570597
* Get the name a player was using at a specific timestamp.
571-
* This method is not thread safe and should not be called on the main thread.
598+
* <p>This method performs blocking database I/O and should not be called
599+
* from the main server thread. Use an asynchronous task instead.</p>
600+
* <p>This method is not internally synchronized. If called concurrently
601+
* from multiple threads, the caller is responsible for synchronization.</p>
572602
*
573603
* @param uuid Player UUID
574604
* @param timestamp Unix timestamp in seconds

0 commit comments

Comments
 (0)