Skip to main content
Proper code formatting is essential for maintaining Paper’s codebase. This guide covers all formatting requirements, including Paper-specific markers, imports, and style conventions.

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.
Paper code markers are required for all Vanilla file modifications. They remain crucial even a decade later for understanding what changed and why.

Comment Format

Every Paper modification needs a descriptive comment:
The description should explain:
  • Why the change was made
  • What it was before
  • What the change does
You can add additional details after a semicolon (;) 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)

When adding new types to a Vanilla class, use the fully qualified class name instead of adding imports to the top of the file.
Correct approach:
Why? This prevents future patch conflicts in the import section.

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
For only a couple of uses, always prefer FQN.

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

Usage of the var keyword is discouraged.
Why?
  • Makes patch files harder to read
  • Can cause confusion during updates due to changed return types
Exception: Use 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
Example of acceptable var usage:

Nullability Annotations

Paper is transitioning between nullability annotation libraries:

For New Classes You Create

Use org.jspecify.annotations:
See the JSpecify documentation for advanced usage on generics and arrays.

For Existing Classes

Keep using org.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 the Preconditions class from Guava.

Checking Method Arguments

Use Preconditions.checkArgument() to validate method parameters:
Do not use Preconditions.checkNotNull()—it throws NullPointerException, making it harder to distinguish between internal errors and invalid arguments.
Throws: IllegalArgumentException when conditions fail

Checking Object State

Use Preconditions.checkState() to validate object state inside methods:
Throws: 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)
  • var keyword is avoided unless absolutely necessary
  • Correct nullability annotations are used
  • API validation uses appropriate Preconditions methods
  • 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:
  1. IntelliJ IDEA: Use the default Java code style
  2. Eclipse: Use the default Java formatter
  3. VS Code: Install the Java extension pack
Paper may apply minor formatting fixes during PR review, but following these guidelines reduces review time.