Proper code formatting is essential for maintaining Paper’s codebase. This guide covers all formatting requirements, including Paper-specific markers, imports, and style conventions.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/PaperMC/Paper/llms.txt
Use this file to discover all available pages before exploring further.
Paper Code Markers
All modifications to Vanilla Minecraft files must be marked with Paper comments. These markers help track changes across files and maintain them long-term.Comment Format
Every Paper modification needs a descriptive comment:- Why the change was made
- What it was before
- What the change does
;) or on the next line.
Single-Line Changes
For one-line modifications, add the marker at the end:Multi-Line Changes
For multi-line modifications, wrap the code with start/end markers:The end marker should use the same description as the start marker for easy matching.
Complete Example
Import Guidelines
Paper has specific rules for imports in Vanilla Minecraft classes to prevent patch conflicts.Use Fully Qualified Names (FQN)
Correct approach:When to Add Imports
You can add an import with a comment if:- The type is used a significant number of times
- Using FQN would make the code too verbose
Java Style Guide
Paper generally follows the Oracle Java style (default in most IDEs) with a few modifications:Line Length
- 80 characters is not a hard limit
- Go over 80 lines if it improves readability
- Exception: Some Spigot-related files have stricter limits
Match Surrounding Code
When in doubt, or if the surrounding code uses a clearly different style, match the existing style.
Avoid var Keyword
Why?
- Makes patch files harder to read
- Can cause confusion during updates due to changed return types
var only when:
- The line would be extremely long without it
- It’s filled with hard-to-parse generics
- The base type is already obvious from context
var usage:
Nullability Annotations
Paper is transitioning between nullability annotation libraries:For New Classes You Create
Useorg.jspecify.annotations:
See the JSpecify documentation for advanced usage on generics and arrays.
For Existing Classes
Keep usingorg.jetbrains.annotations:
These will be migrated to JSpecify later. Don’t convert them yourself.
API Validation with Preconditions
When validating API inputs or object state, use thePreconditions class from Guava.
Checking Method Arguments
UsePreconditions.checkArgument() to validate method parameters:
IllegalArgumentException when conditions fail
Checking Object State
UsePreconditions.checkState() to validate object state inside methods:
IllegalStateException when conditions fail
Preconditions Best Practices
- Use
checkArgument()for validating input parameters - Use
checkState()for validating object state - Include descriptive error messages
- Use format strings (
%s) for dynamic values
Obfuscation Helpers
Obfuscation helpers improve readability for unmapped variables or poorly-named parameters.Purpose
- Make code more readable
- Aid future maintenance
- Should be easy for the JVM to inline
Example
Use your best judgment and do what fits best in your situation. The goal is always readability and maintainability.
Formatting Checklist
Before submitting your PR, verify:- All Vanilla file changes have Paper start/end markers
- Markers include descriptive commit descriptions
- End markers match their corresponding start markers
- New types in Vanilla classes use FQN instead of imports
- Code follows Oracle Java style (or matches surrounding code)
-
varkeyword is avoided unless absolutely necessary - Correct nullability annotations are used
- API validation uses appropriate
Preconditionsmethods - Obfuscation helpers are used where they improve readability
Common Mistakes
Missing Paper Markers
Adding Unnecessary Imports
Mismatched Start/End Markers
Using checkNotNull
IDE Configuration
Most Java IDEs are pre-configured with Oracle Java style. For best results:- IntelliJ IDEA: Use the default Java code style
- Eclipse: Use the default Java formatter
- VS Code: Install the Java extension pack
Paper may apply minor formatting fixes during PR review, but following these guidelines reduces review time.