-
Notifications
You must be signed in to change notification settings - Fork 0
fix(mongo): disable implicit player document initialization #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,294 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| # NetworkDataAPI - Implementation Notes | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| **Date:** November 14, 2025 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| **Version:** 1.0-SNAPSHOT | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| --- | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| ## ✅ Core Principles | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| NetworkDataAPI is designed with ONE primary purpose: | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| **Provide a shared MongoDB connection pool for all plugins on a Minecraft server.** | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| ### What NetworkDataAPI IS: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| - ✅ A **shared MongoDB connection pool** manager | ||||||||||||||||||||||||||||||||||||||||||||||||||
| - ✅ A **connection layer** between plugins and MongoDB | ||||||||||||||||||||||||||||||||||||||||||||||||||
| - ✅ A **high-level API** for common database operations | ||||||||||||||||||||||||||||||||||||||||||||||||||
| - ✅ An **automatic reconnection** handler | ||||||||||||||||||||||||||||||||||||||||||||||||||
| - ✅ A **caching layer** to reduce database load | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| ### What NetworkDataAPI IS NOT: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| - ❌ An automatic player data manager | ||||||||||||||||||||||||||||||||||||||||||||||||||
| - ❌ A player tracking system | ||||||||||||||||||||||||||||||||||||||||||||||||||
| - ❌ A statistics/economy/cosmetics plugin | ||||||||||||||||||||||||||||||||||||||||||||||||||
| - ❌ A system that creates default data | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| --- | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| ## 🎯 Design Philosophy | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| ### 1. **No Automatic Data Creation** | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| NetworkDataAPI does NOT create any player data automatically. There are no default documents, no automatic player tracking, and no pre-defined data structures. | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| **Why?** | ||||||||||||||||||||||||||||||||||||||||||||||||||
| - Each plugin should control its own data | ||||||||||||||||||||||||||||||||||||||||||||||||||
| - Prevents unwanted data in the database | ||||||||||||||||||||||||||||||||||||||||||||||||||
| - Avoids conflicts between plugins | ||||||||||||||||||||||||||||||||||||||||||||||||||
| - Gives developers complete flexibility | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| ### 2. **Action-Based Data Creation** | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| Data should only be created when it's actually needed: | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| ```java | ||||||||||||||||||||||||||||||||||||||||||||||||||
| // ❌ WRONG: Create empty data on player join | ||||||||||||||||||||||||||||||||||||||||||||||||||
| @EventHandler | ||||||||||||||||||||||||||||||||||||||||||||||||||
| public void onPlayerJoin(PlayerJoinEvent event) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Document data = new Document("uuid", uuid).append("coins", 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| collection.insertOne(data); // Why create empty data? | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| // ✅ CORRECT: Create data when relevant | ||||||||||||||||||||||||||||||||||||||||||||||||||
| public void claimCosmetic(Player player, String cosmeticId) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Document data = collection.find(Filters.eq("uuid", uuid)).first(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if (data == null) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| // First cosmetic - NOW create the document | ||||||||||||||||||||||||||||||||||||||||||||||||||
| data = new Document("uuid", uuid).append("cosmetics", List.of(cosmeticId)); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+49
to
+58
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| Document data = new Document("uuid", uuid).append("coins", 0); | |
| collection.insertOne(data); // Why create empty data? | |
| } | |
| // ✅ CORRECT: Create data when relevant | |
| public void claimCosmetic(Player player, String cosmeticId) { | |
| Document data = collection.find(Filters.eq("uuid", uuid)).first(); | |
| if (data == null) { | |
| // First cosmetic - NOW create the document | |
| data = new Document("uuid", uuid).append("cosmetics", List.of(cosmeticId)); | |
| UUID uuid = event.getPlayer().getUniqueId(); | |
| Document data = new Document("uuid", uuid.toString()).append("coins", 0); | |
| collection.insertOne(data); // Why create empty data? | |
| } | |
| // ✅ CORRECT: Create data when relevant | |
| public void claimCosmetic(Player player, String cosmeticId) { | |
| UUID uuid = player.getUniqueId(); | |
| Document data = collection.find(Filters.eq("uuid", uuid.toString())).first(); | |
| if (data == null) { | |
| // First cosmetic - NOW create the document | |
| data = new Document("uuid", uuid.toString()).append("cosmetics", List.of(cosmeticId)); |
Copilot
AI
Nov 14, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable uuid should be converted to String when storing in the document:
data = new Document("uuid", uuid.toString()).append("cosmetics", List.of(cosmeticId));| data = new Document("uuid", uuid).append("cosmetics", List.of(cosmeticId)); | |
| data = new Document("uuid", uuid.toString()).append("cosmetics", List.of(cosmeticId)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable
uuidis used but not defined in this code snippet. It should be: