Fix: Truncate UUID to fit varchar(16) column when handling duplicate player names#469
Fix: Truncate UUID to fit varchar(16) column when handling duplicate player names#469JobsonMarinho wants to merge 18 commits intoRoinujNosde:masterfrom
Conversation
…player names When a duplicate player name is detected, the code was attempting to set the name to the full UUID string (36 characters), which exceeded the database column limit of varchar(16). This caused a MysqlDataTruncation error. The fix uses a shortened version by taking the first 15 characters of the UUID and prefixing with '~', resulting in a 16-character string that fits within the database constraint. Fixes the error: Data too long for column 'name' at row 1
There was a problem hiding this comment.
Pull request overview
This PR addresses a database truncation error that occurred when handling duplicate player names. The fix prevents a MysqlDataTruncation error by truncating the UUID string to fit within the existing varchar(16) database column constraint, rather than attempting to store the full 36-character UUID.
Key Changes:
- Implemented UUID truncation logic (first 15 characters + tilde prefix) when renaming duplicate players
- Added inline comment explaining the varchar(16) constraint
- Maintains existing duplicate detection and resolution workflow
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/main/java/net/sacredlabyrinth/phaed/simpleclans/listeners/SCPlayerListener.java
Outdated
Show resolved
Hide resolved
src/main/java/net/sacredlabyrinth/phaed/simpleclans/listeners/SCPlayerListener.java
Outdated
Show resolved
Hide resolved
src/main/java/net/sacredlabyrinth/phaed/simpleclans/listeners/SCPlayerListener.java
Outdated
Show resolved
Hide resolved
|
Increasing the column size is probably a better solution |
I think the best approach would be to convert legacy data to support the new account format.
This might not be ideal for every server, but in my case it works well because my network supports premium, cracked and Bedrock players. I already handle this logic across all of my plugins. However, since SimpleClans is a public plugin, I felt it was better to apply a minimal change by adjusting the name to UUID using: This resolved the warnings/errors that appeared in the console and I thought this solution could be beneficial for all SimpleClans users, not just for my specific setup. |
That would be perfect, indeed. I tried to implement this once, but had some problems with race conditions IIRC, so I settled for this workaround. |
|
@RoinujNosde i completely refactored the player name/UUID handling system to properly manage duplicate and outdated player records in the database. This addresses the What ChangedInstead of trying to rename duplicate players with truncated UUIDs (which was causing database errors), we now implement a comprehensive synchronization system that:
Why This MattersThis approach:
Implementation Details
I think this is the best solution for handling duplicate records. Does this approach align with your vision for SimpleClans? Is there any suggestion or improvement you’d like to see? |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 13 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/main/java/net/sacredlabyrinth/phaed/simpleclans/managers/StorageManager.java
Outdated
Show resolved
Hide resolved
src/main/java/net/sacredlabyrinth/phaed/simpleclans/managers/StorageManager.java
Outdated
Show resolved
Hide resolved
src/main/java/net/sacredlabyrinth/phaed/simpleclans/managers/StorageManager.java
Show resolved
Hide resolved
src/main/java/net/sacredlabyrinth/phaed/simpleclans/managers/StorageManager.java
Outdated
Show resolved
Hide resolved
src/main/java/net/sacredlabyrinth/phaed/simpleclans/managers/StorageManager.java
Show resolved
Hide resolved
src/main/java/net/sacredlabyrinth/phaed/simpleclans/managers/StorageManager.java
Show resolved
Hide resolved
src/main/java/net/sacredlabyrinth/phaed/simpleclans/managers/StorageManager.java
Show resolved
Hide resolved
src/main/java/net/sacredlabyrinth/phaed/simpleclans/managers/StorageManager.java
Show resolved
Hide resolved
src/main/java/net/sacredlabyrinth/phaed/simpleclans/managers/StorageManager.java
Show resolved
Hide resolved
src/main/java/net/sacredlabyrinth/phaed/simpleclans/managers/StorageManager.java
Show resolved
Hide resolved
…torageManager.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…torageManager.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…torageManager.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
… better duplicate handling
…ndling for player data synchronization
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.
Comments suppressed due to low confidence (1)
src/main/java/net/sacredlabyrinth/phaed/simpleclans/listeners/SCPlayerListener.java:179
- @param tag "cp" does not match any actual parameter of method "updatePlayerName()".
* @param cp to update
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/main/java/net/sacredlabyrinth/phaed/simpleclans/managers/StorageManager.java
Show resolved
Hide resolved
src/main/java/net/sacredlabyrinth/phaed/simpleclans/listeners/SCPlayerListener.java
Show resolved
Hide resolved
src/main/java/net/sacredlabyrinth/phaed/simpleclans/managers/StorageManager.java
Show resolved
Hide resolved
src/main/java/net/sacredlabyrinth/phaed/simpleclans/managers/StorageManager.java
Show resolved
Hide resolved
src/main/java/net/sacredlabyrinth/phaed/simpleclans/managers/StorageManager.java
Show resolved
Hide resolved
src/main/java/net/sacredlabyrinth/phaed/simpleclans/managers/StorageManager.java
Show resolved
Hide resolved
|
@RoinujNosde can u review it? |
src/main/java/net/sacredlabyrinth/phaed/simpleclans/managers/StorageManager.java
Show resolved
Hide resolved
|
@RoinujNosde I reversed the line breaks, anything else? |
| ClanPlayer byName = retrieveClanPlayerByName(currentName); | ||
| ClanPlayer byUuid = retrieveOneClanPlayer(currentUuid); |
There was a problem hiding this comment.
This is calling database code in the main thread, it's going to cause lag.
| if (byName == null && byUuid == null) { | ||
| plugin.getLogger().info(String.format("No existing records for %s (%s)", currentName, currentUuid)); | ||
| return; | ||
| } |
There was a problem hiding this comment.
This will never happen. The object is already created here:


Problem
When a duplicate player name is detected, the code was attempting to set the name to the full UUID string (36 characters), which exceeded the database column limit of varchar(16). This caused a MysqlDataTruncation error.
Solution
The fix uses a shortened version by taking the first 15 characters of the UUID and prefixing with '~', resulting in a 16-character string that fits within the database constraint.
Error Fixed
Fixes the error: Data too long for column 'name' at row 1
Changes
src/main/java/net/sacredlabyrinth/phaed/simpleclans/listeners/SCPlayerListener.java