-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/spawnloc creation #5
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
base: main
Are you sure you want to change the base?
Conversation
…world creation This reduces world creation for vanilla worlds from ~1 second to 20ms.
|
CodeAnt AI is reviewing your PR. Thanks for using CodeAnt! 🎉We're free for open-source projects. if you're enjoying it, help us grow by sharing. Share on X · |
|
Warning Rate limit exceeded@visz11 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 3 minutes and 24 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (8)
✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary of ChangesHello @visz11, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces advanced customization options for world creation, allowing users to precisely define a new world's initial spawn point, its associated dimension type, and where its data files will be stored. These changes empower developers with more granular control over the world generation process, moving beyond standard defaults. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
Refacto PR SummaryEnhanced Minecraft world creation system with forced spawn positioning, custom dimension support, and flexible world file storage. The implementation adds comprehensive spawn location control during world creation, allowing server administrators to override vanilla spawn generation with precise coordinates and rotation values. Key Changes:
Change HighlightsClick to expand
Sequence DiagramsequenceDiagram
participant A as Admin/Plugin
participant WC as WorldCreator
participant CS as CraftServer
participant MS as MinecraftServer
participant SL as ServerLevel
A->>WC: forcedSpawnPosition(position, yaw, pitch)
A->>WC: dimensionKeyOverride(key)
A->>WC: worldFileStorage(directory)
A->>WC: createWorld()
WC->>CS: Create world with overrides
CS->>CS: Resolve dimension key via PaperAdventure
CS->>MS: initWorld(level, data, options, position, pitch, yaw)
alt Forced position provided
MS->>SL: setSpawn(forcedPosition, yaw, pitch)
else No forced position
MS->>SL: setInitialSpawn(vanilla generation)
end
MS-->>CS: World initialized
CS-->>A: World created successfully
Testing GuideClick to expand
|
|
Refacto is reviewing this PR. Please wait for the review comments to be posted. |
Sequence DiagramShows how a WorldCreator's new overrides (world storage path, dimension key, forced spawn position/yaw/pitch) flow through CraftServer into the server/world init so the spawn can be set without chunk loads. sequenceDiagram
participant Plugin
participant CraftServer
participant LevelStorage
participant MinecraftServer
Plugin->>CraftServer: createWorld(WorldCreator{worldFileStorage, dimensionKeyOverride, forcedSpawnPosition})
CraftServer->>LevelStorage: createDefault(access using WorldCreator.getWorldFileStorage())
LevelStorage-->>CraftServer: LevelStorageAccess
CraftServer->>MinecraftServer: prepare LevelStem (apply dimensionKeyOverride if present) and create ServerLevel
CraftServer->>MinecraftServer: initWorld(serverLevel, ..., forcedSpawnPosition, forcedPitch, forcedYaw)
alt forcedSpawnPosition set
MinecraftServer->>MinecraftServer: set spawn directly (no chunk loads)
else
MinecraftServer->>MinecraftServer: setInitialSpawn (generator/vanilla behavior)
end
MinecraftServer-->>CraftServer: world initialized
CraftServer-->>Plugin: return created World
Generated by CodeAnt AI |
Code Review: WorldCreator File Path Security EnhancementPR Confidence Score: 🟨 4 / 5👍 Well Done
📁 Selected files for review (8)
🎯 Custom Instructions
|
| public WorldCreator worldFileStorage(@NotNull File override) { | ||
| this.worldFileOverride = override; | ||
| return this; | ||
| } |
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.
Unsafe File Path
Method accepts arbitrary file paths without validation enabling path traversal attacks. Malicious users could specify paths like '../../../etc/passwd' to access sensitive system files or overwrite critical server data. Path canonicalization and directory traversal prevention required.
public WorldCreator worldFileStorage(@NotNull File override) {
Preconditions.checkNotNull(override, "World file storage cannot be null");
try {
File canonicalFile = override.getCanonicalFile();
File worldContainer = Bukkit.getWorldContainer().getCanonicalFile();
if (!canonicalFile.toPath().startsWith(worldContainer.toPath())) {
throw new IllegalArgumentException("World storage path must be within server world container");
}
this.worldFileOverride = canonicalFile;
} catch (java.io.IOException e) {
throw new IllegalArgumentException("Invalid world storage path: " + override.getPath(), e);
}
return this;
}
Commitable Suggestion
| public WorldCreator worldFileStorage(@NotNull File override) { | |
| this.worldFileOverride = override; | |
| return this; | |
| } | |
| public WorldCreator worldFileStorage(@NotNull File override) { | |
| Preconditions.checkNotNull(override, "World file storage cannot be null"); | |
| try { | |
| File canonicalFile = override.getCanonicalFile(); | |
| File worldContainer = Bukkit.getWorldContainer().getCanonicalFile(); | |
| if (!canonicalFile.toPath().startsWith(worldContainer.toPath())) { | |
| throw new IllegalArgumentException("World storage path must be within server world container"); | |
| } | |
| this.worldFileOverride = canonicalFile; | |
| } catch (java.io.IOException e) { | |
| throw new IllegalArgumentException("Invalid world storage path: " + override.getPath(), e); | |
| } | |
| return this; | |
| } |
Standards
- CWE-22
- OWASP-A01
- NIST-SSDF-PW.1
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.
Code Review
This pull request introduces a new API in WorldCreator to override the spawn location, dimension type, and world storage location. The changes are well-implemented across the API and server logic. I've found a couple of issues in WorldCreator.java related to representation exposure and API consistency that should be addressed. My review includes suggestions to fix these issues by ensuring defensive copies of Position objects are used and by making the behavior of forcedSpawnPosition more consistent.
| public WorldCreator forcedSpawnPosition(@Nullable Position position, float yaw, float pitch | ||
| ) { | ||
| if (position == null) { | ||
| this.spawnPositionOverride = null; | ||
| this.spawnYawOverride = yaw; | ||
| this.spawnPitchOverride = pitch; | ||
| return this; | ||
| } | ||
|
|
||
| this.spawnPositionOverride = position; | ||
| this.spawnYawOverride = yaw; | ||
| this.spawnPitchOverride = pitch; | ||
| return this; | ||
| } |
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.
This method contains a redundant if block, as the logic is identical in both branches. This can be simplified.
Additionally, there are two other concerns:
- Representation Exposure: The method stores the passed
positionobject directly. If the caller modifies this object after calling the method, the internal state of thisWorldCreatorwill be changed. A defensive copy should be stored instead. - API Inconsistency: If
positionisnull,spawnPositionOverrideis set tonull, butspawnYawOverrideandspawnPitchOverrideare still set. This is inconsistent with the Javadoc forforcedSpawnYaw()andforcedSpawnPitch(), which state that yaw/pitch are only meaningful if a spawn position is present. Whenpositionisnull, yaw and pitch overrides should also be cleared to reflect that vanilla behavior is being used for the entire spawn location.
Here is a suggested implementation that addresses these points:
public WorldCreator forcedSpawnPosition(@Nullable Position position, float yaw, float pitch
) {
if (position != null) {
this.spawnPositionOverride = Position.fine(position.x(), position.y(), position.z());
this.spawnYawOverride = yaw;
this.spawnPitchOverride = pitch;
} else {
this.spawnPositionOverride = null;
this.spawnYawOverride = null;
this.spawnPitchOverride = null;
}
return this;
}| public Position forcedSpawnPosition() { | ||
| return this.spawnPositionOverride == null ? null : this.spawnPositionOverride; | ||
| } |
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.
This method can be simplified by removing the redundant ternary operator. More importantly, the Javadoc states that a clone is returned, but the implementation returns the internal object directly. This is a representation exposure issue and violates the API contract. A defensive copy should be returned to prevent external modifications.
public Position forcedSpawnPosition() {
return this.spawnPositionOverride != null ? Position.fine(this.spawnPositionOverride.x(), this.spawnPositionOverride.y(), this.spawnPositionOverride.z()) : null;
}
Nitpicks 🔍
|
|
CodeAnt AI finished reviewing your PR. |
CodeAnt-AI Description
Set spawn, dimension, and world-storage overrides and skip spawn computation to speed world creation
What Changed
Impact
✅ Faster world creation (vanilla worlds: ~1s → ~20ms)✅ Create worlds in a custom folder✅ Create worlds with an explicit dimension and spawn without chunk loads💡 Usage Guide
Checking Your Pull Request
Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.
Talking to CodeAnt AI
Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:
This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.
Example
Preserve Org Learnings with CodeAnt
You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:
This helps CodeAnt AI learn and adapt to your team's coding style and standards.
Example
Retrigger review
Ask CodeAnt AI to review the PR again, by typing:
Check Your Repository Health
To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.