Files
Plugin_Code_Quality_Standards.md
Code
1 3,258
Plugin_Code_Quality_Standards.md
# Minecraft Plugin Code Quality & Polish Standards
## Paper 1.21.4 — Production-Ready Code Review Checklist
> This document is a living reference for plugin developers and code reviewers. Every rule here exists because real production plugins have broken in real servers due to violations of these principles. Read it once, then keep it open during every review.
---
## Table of Contents
1. [Naming Conventions](#1-naming-conventions)
2. [Code Organization & Readability](#2-code-organization--readability)
3. [Documentation Standards](#3-documentation-standards)
4. [Error Handling Elegance](#4-error-handling-elegance)
5. [Resource Management](#5-resource-management)
6. [Plugin Lifecycle Discipline](#6-plugin-lifecycle-discipline)
7. [Configuration & Messaging Standards](#7-configuration--messaging-standards)
8. [Common AI Polish Failures](#8-common-ai-polish-failures-30-examples)
9. [Appendix A: 30-Point Pre-Commit Checklist](#appendix-a-30-point-pre-commit-checklist)
10. [Appendix B: Code Review Red Flags](#appendix-b-code-review-red-flags-visual-scanning-guide)
11. [Appendix C: AI Prompt Engineering Phrases](#appendix-c-ai-prompt-engineering-phrases-for-better-output)
12. [Appendix D: Auto-Format Configuration](#appendix-d-auto-format-configuration)
---
## 1. Naming Conventions
Naming is the single highest-leverage quality investment in any codebase. A well-named class or method communicates intent without requiring the reader to open the implementation. Poor naming forces every reviewer, every future maintainer, and every AI tool to guess — and guessing introduces bugs.
---
### 1.1 Class Naming Strategy
#### Main Plugin Class
**Rule:** The main class should be named exactly after the plugin, in PascalCase, with no suffix.
| Pattern | Verdict | Reason |
|---|---|---|
| `MyPlugin` | ✅ Correct | Clean, unambiguous, matches plugin name |
| `MyPluginPlugin` | ❌ Wrong | Redundant suffix, reads awkwardly |
| `MyPluginMain` | ❌ Wrong | "Main" is an implementation detail, not a concept |
| `Main` | ❌ Wrong | Completely non-descriptive, conflicts with Java convention |
| `PluginCore` | ❌ Wrong | Vague, doesn't identify the plugin |
**Why it matters:** The main class is the entry point that other plugins reference via `JavaPlugin.getPlugin(MyPlugin.class)`. If it's named `MyPluginMain`, every external reference looks like `JavaPlugin.getPlugin(MyPluginMain.class)` — which is confusing and inconsistent with the plugin's identity.
**Common AI mistake:**
```java
// AI often generates this
public class MyPluginMain extends JavaPlugin {
private static MyPluginMain instance;
```
**Corrected version:**
```java
// Correct
public class MyPlugin extends JavaPlugin {
private static MyPlugin instance;
```
**Edge case:** If your plugin name is a reserved Java keyword or conflicts with a Bukkit class (unlikely but possible), append `Plugin` as a last resort. Document why.
---
#### Manager Classes
**Rule:** Use the `Manager` suffix for classes that own and coordinate a domain's lifecycle. Use `Service` for stateless operation classes. Use `Repository` for data access classes.
| Suffix | When to Use | Example |
|---|---|---|
| `Manager` | Owns lifecycle, holds state, coordinates subsystems | `PlayerDataManager`, `ArenaManager` |
| `Service` | Stateless operations, business logic, no lifecycle | `EconomyService`, `PermissionService` |
| `Repository` | Data access only — reads/writes to storage | `PlayerRepository`, `ShopRepository` |
| `Handler` | Processes a single type of event or request | `ChatHandler`, `PaymentHandler` |
| `Factory` | Creates instances of complex objects | `ItemFactory`, `ArenaFactory` |
**Why it matters:** When a class is named `PlayerManager`, a reviewer immediately knows it holds a `Map<UUID, PlayerData>` and has `load()`, `save()`, `get()`, and `remove()` methods. When it's named `PlayerUtils`, the reviewer has no idea what to expect.
**Common AI mistake:**
```java
// AI conflates all three concepts into one class
public class PlayerUtils {
private Map<UUID, PlayerData> players = new HashMap<>();
public void saveToDatabase(PlayerData data) { ... }
public PlayerData loadFromDatabase(UUID uuid) { ... }
public void giveReward(Player player) { ... }
public String formatName(Player player) { ... }
}
```
**Corrected version:**
```java
// Split by responsibility
public class PlayerDataManager { // owns lifecycle
private final Map<UUID, PlayerData> cache = new HashMap<>();
}
public class PlayerRepository { // data access only
public void save(PlayerData data) { ... }
public PlayerData load(UUID uuid) { ... }
}
public class PlayerService { // business logic
public void giveReward(Player player) { ... }
}
public class PlayerFormatter { // pure utility
public static String formatName(Player player) { ... }
}
```
---
#### Listener Classes
**Rule:** Name listeners after the domain they cover, not the specific event. Group related events into one listener class.
| Pattern | Verdict | Reason |
|---|---|---|
| `PlayerJoinListener` | ⚠️ Acceptable for small plugins | Fine if only one join-related event |
| `PlayerListener` | ✅ Preferred | Groups all player-related events |
| `CombatListener` | ✅ Preferred | Groups all combat events |
| `EventListener` | ❌ Wrong | Completely non-descriptive |
| `Listeners` | ❌ Wrong | Plural class names are a code smell |
**Why it matters:** If you have `PlayerJoinListener`, `PlayerQuitListener`, `PlayerMoveListener`, and `PlayerChatListener` as four separate classes, you have four files to open to understand player behavior. Group them into `PlayerListener` and the domain is self-contained.
**Exception:** If a listener class exceeds ~150 lines, split it. A `CombatListener` handling 15 different combat events is too large — split into `MeleeCombatListener` and `ProjectileCombatListener`.
**Common AI mistake:**
```java
// AI creates one listener per event
public class OnPlayerJoinListener implements Listener { ... }
public class OnPlayerQuitListener implements Listener { ... }
public class OnPlayerDeathListener implements Listener { ... }
```
**Corrected version:**
```java
// Group by domain
public class PlayerLifecycleListener implements Listener {
@EventHandler public void onJoin(PlayerJoinEvent event) { ... }
@EventHandler public void onQuit(PlayerQuitEvent event) { ... }
@EventHandler public void onDeath(PlayerDeathEvent event) { ... }
}
```
---
#### Command Classes
**Rule:** Use the `Command` suffix, not prefix. Name after the command's action.
| Pattern | Verdict | Reason |
|---|---|---|
| `ReloadCommand` | ✅ Correct | Noun-first, action-second, sorts alphabetically by domain |
| `HomeCommand` | ✅ Correct | Clear, concise |
| `CommandReload` | ❌ Wrong | Prefix convention makes alphabetical sorting useless |
| `ReloadCmd` | ❌ Wrong | Abbreviations reduce readability |
| `ReloadCommandExecutor` | ❌ Wrong | Redundant — it's obviously an executor |
**Why it matters:** In a plugin with 20 commands, `Command`-prefixed classes sort as `CommandBan`, `CommandHome`, `CommandKick` — all together, not grouped by domain. `BanCommand`, `HomeCommand`, `KickCommand` sort by domain, which is how developers think about them.
**Common AI mistake:**
```java
public class CommandHandler implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (cmd.getName().equalsIgnoreCase("home")) { ... }
if (cmd.getName().equalsIgnoreCase("sethome")) { ... }
if (cmd.getName().equalsIgnoreCase("delhome")) { ... }
// 300 more lines
}
}
```
**Corrected version:**
```java
// One class per command
public class HomeCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { ... }
}
public class SetHomeCommand implements CommandExecutor { ... }
public class DeleteHomeCommand implements CommandExecutor { ... }
```
---
#### Utility Classes
**Rule:** Static utility classes are acceptable only when the methods are truly stateless, domain-agnostic, and reusable across the entire plugin. Name them `[Domain]Utils` or `[Domain]Helper`.
| Pattern | Verdict | Reason |
|---|---|---|
| `StringUtils` | ✅ Correct | Domain-specific, clear scope |
| `ItemUtils` | ✅ Correct | Clear what it operates on |
| `Utils` | ❌ Wrong | Becomes a dumping ground for everything |