Paper Plugin Guide
File mode0

Reference

Paper cheat sheet

Copy-ready one-liners for the things plugins do most.

BeginnerReference

205 short recipes for the things plugins do all the time: send messages, heal players, make items, open menus, spawn mobs, run tasks, save data and react to events. Every recipe was compiled against Paper 26.3, so what you copy works.

How to use this cheat sheet

Each recipe is a small method. A method is a named block of code that does one job. Read the name to see the job, look at the parentheses to see what you must have ready, and copy the lines inside the curly braces into your own method.

How to read a recipe A recipe is a method. Its name says the job, its parameters are the things you must have ready, and its body is the code to copy into your own plugin. void healFully (Player player) { player.setHealth(maxHealth); } The name: the job healFully means heal fully The parentheses: what to bring you need a variable named player The lines inside: the recipe copy these into your own method In your plugin, paste the lines inside your own method and make sure the variables from the parentheses exist there
Every recipe has a name, the things it needs, and the lines to copy

The recipes share a few variable names. When you paste a recipe, make sure a variable with that name exists in your code:

NameWhat it isWhere you usually get it
playerOne online Playerevent.getPlayer() inside an event handler
senderWhoever ran a command: a player or the consolesource.getSender() inside a command
pluginYour main class, the one that extends JavaPluginthis inside onEnable, or a field you pass to your other classes
locationA point in a worldplayer.getLocation() or block.getLocation()
itemAn ItemStackevent.getItem() or player.getInventory().getItemInMainHand()
entityAny mob, player or thing in the worldevent.getEntity() or a search such as player.getNearbyEntities(...)

A few things to know before you copy:

  • Recipes that return a value, such as findOnlinePlayer, can return null, which means "nothing found". Check for it before you use the result, or your plugin will throw a NullPointerException.
  • Time is counted in ticks. The server runs 20 ticks per second, so 20 ticks are one second and 200 ticks are ten seconds.
  • Recipes marked as event handlers need to live in a listener class that you register. The Events and listeners chapter shows how.
  • Do not copy blindly. Read the sentence above each recipe and make sure it does what you want.

Jump to a group

  • Messages, text and screen displays (20): Everything that shows words to players: chat, the action bar, titles and boss bars. Most examples use MiniMessage because it is the shortest way to write colors.
  • Players (20): Finding players and changing what they can do and how they are doing.
  • Items (19): Making items, changing their name, lore and enchantments, and checking what players hold.
  • Inventories and menus (15): Chests, menus and checking what players carry.
  • Worlds, blocks and locations (23): Positions, blocks, time and weather.
  • Entities and mobs (18): Spawning, finding and changing mobs and other entities.
  • Sounds, particles and potion effects (13): Things players see and hear.
  • Scheduling (11): Running code later, repeatedly, or away from the main thread. Remember: 20 ticks make one second.
  • Config files (13): Reading and writing config.yml and your own YAML files.
  • Saving data on things (12): PersistentDataContainer, the sticky notes you attach to players, items, entities and chunks.
  • Permissions (7): Checking and granting rights.
  • Commands (15): The modern way to make commands with Brigadier, and the classic way with plugin.yml.
  • Events (19): Reacting to things that happen. Methods marked with an annotation must live in a class that implements Listener and is registered.

Messages, text and screen displays

Everything that shows words to players: chat, the action bar, titles and boss bars. Most examples use MiniMessage because it is the shortest way to write colors.

Send a colored message. Sends one chat line written in MiniMessage. The tag in angle brackets sets the color. More in MiniMessage: easy formatted text.

MessageRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetMessageRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javayou are hereHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

25void sendColoredText(Player player) {26    player.sendRichMessage("<green>You found a secret!");27}
  1. Reads MiniMessage tags like green and bold. You do not need to build a Component yourself.
You found a secret!

Put a value into a message. The name in angle brackets is replaced by the value you pass in. Using unparsed means the value is shown as plain text, so a player cannot sneak in formatting tags. More in MiniMessage: easy formatted text.

MessageRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetMessageRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javayou are hereHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

29void sendWithPlaceholder(Player player, int coins) {30    player.sendRichMessage("<gold>You have <coins> coins.", Placeholder.unparsed("coins", String.valueOf(coins)));31}
  1. Inserts the value exactly as written, never as tags.
You have 25 coins.

Send a component. Builds the text in Java instead of MiniMessage. It works on any command sender, including the console. More in Text and colors with Adventure.

MessageRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetMessageRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javayou are hereHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

33void sendComponent(CommandSender sender) {34    sender.sendMessage(Component.text("Hello there!", NamedTextColor.GREEN));35}

Use an exact hex color. Any red-green-blue hex number works, here 0xFF8800 for orange. More in Text and colors with Adventure.

MessageRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetMessageRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javayou are hereHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

37Component hexColoredText() {38    return Component.text("Orange text", TextColor.color(0xFF8800));39}

Color and bold together. Extra text decorations come after the color. More in Text and colors with Adventure.

MessageRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetMessageRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javayou are hereHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

41Component boldWarning() {42    return Component.text("Warning!", NamedTextColor.RED, TextDecoration.BOLD);43}

Glue pieces of text together. append adds a component after another one, and each piece keeps its own color. More in Text and colors with Adventure.

MessageRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetMessageRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javayou are hereHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

45Component joinedPieces(Player player) {46    return Component.text("Welcome, ", NamedTextColor.GRAY)47            .append(Component.text(player.getName(), NamedTextColor.GOLD))48            .append(Component.text("!", NamedTextColor.GRAY));49}

Run a command when text is clicked. When the player clicks the text, the command runs as if they had typed it. More in Text and colors with Adventure.

MessageRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetMessageRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javayou are hereHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

51Component clickableCommand() {52    return Component.text("[Go to spawn]", NamedTextColor.AQUA).clickEvent(ClickEvent.runCommand("/spawn"));53}

Open a link when text is clicked. Minecraft asks the player to confirm before the website opens. More in Text and colors with Adventure.

MessageRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetMessageRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javayou are hereHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

55Component clickableLink() {56    return Component.text("[Open our website]", NamedTextColor.AQUA).clickEvent(ClickEvent.openUrl("https://papermc.io"));57}

Show a tooltip on hover. The hover text appears when the mouse rests on the text. More in Text and colors with Adventure.

MessageRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetMessageRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javayou are hereHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

59Component textWithHover() {60    return Component.text("Hover me").hoverEvent(HoverEvent.showText(Component.text("A helpful tip")));61}

Turn MiniMessage text into a component. Useful for text that comes from config.yml. More in MiniMessage: easy formatted text.

MessageRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetMessageRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javayou are hereHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

63Component parseMiniMessage(String text) {64    return MiniMessage.miniMessage().deserialize(text);65}

Join lines into one message. JoinConfiguration.newlines puts each component on its own line. More in Text and colors with Adventure.

MessageRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetMessageRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javayou are hereHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

67Component linesAsOneMessage(List<Component> lines) {68    return Component.join(JoinConfiguration.newlines(), lines);69}

Remove all formatting. Gives you the plain String, handy for comparing chat text. More in Text and colors with Adventure.

MessageRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetMessageRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javayou are hereHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

71String toPlainText(Component component) {72    return PlainTextComponentSerializer.plainText().serialize(component);73}

Read old ampersand color codes. Turns text like &aHello into a green component, for configs that still use the old codes. More in Text and colors with Adventure.

MessageRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetMessageRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javayou are hereHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

75Component fromAmpersandCodes(String text) {76    return LegacyComponentSerializer.legacyAmpersand().deserialize(text);77}

Tell everyone online. Sends the message to every player and the console. More in Text and colors with Adventure.

MessageRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetMessageRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javayou are hereHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

79void broadcastToEveryone() {80    Bukkit.broadcast(Component.text("The event starts now!", NamedTextColor.YELLOW));81}

Tell only players with a permission. Only those who have the permission receive it. More in Permissions.

MessageRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetMessageRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javayou are hereHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

83void broadcastToPermissionHolders() {84    Bukkit.broadcast(Component.text("Staff only message"), "myplugin.staff");85}

Show an action bar message. The text appears above the hotbar for a moment. More in Titles, action bars, boss bars and sounds.

MessageRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetMessageRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javayou are hereHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

87void showActionBar(Player player) {88    player.sendActionBar(Component.text("+5 coins", NamedTextColor.GOLD));89}
+5 coins

Show a title and subtitle. The big words in the middle of the screen. More in Titles, action bars, boss bars and sounds.

MessageRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetMessageRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javayou are hereHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

91void showTitle(Player player) {92    player.showTitle(Title.title(Component.text("Welcome!"), Component.text("Enjoy your stay")));93}
Welcome! Enjoy your stay

Control title timing. The three durations are fade in, stay on screen and fade out. More in Titles, action bars, boss bars and sounds.

MessageRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetMessageRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javayou are hereHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

95void showTitleWithTimes(Player player) {96    Title.Times times = Title.Times.times(Duration.ofMillis(500), Duration.ofSeconds(3), Duration.ofMillis(500));97    player.showTitle(Title.title(Component.text("Round 1"), Component.empty(), times));98}
  1. Fade in, stay and fade out, in that order.

Show a boss bar. Keep the returned bar if you want to change its progress or hide it later. Progress goes from 0.0 to 1.0. More in Titles, action bars, boss bars and sounds.

MessageRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetMessageRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javayou are hereHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

100BossBar showBossBar(Player player) {101    BossBar bar = BossBar.bossBar(Component.text("Boss fight"), 1.0f, BossBar.Color.RED, BossBar.Overlay.PROGRESS);102    player.showBossBar(bar);103    return bar;104}
Boss fight

Write to the server console. getComponentLogger prints colored text to the console and the log file. More in The main class and plugin lifecycle.

MessageRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetMessageRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javayou are hereHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

106void writeToConsole(JavaPlugin plugin) {107    plugin.getComponentLogger().info(Component.text("Plugin is running", NamedTextColor.GREEN));108}

Players

Finding players and changing what they can do and how they are doing.

Find a player by exact name. Gives null when nobody with that name is online, so always check the result before using it. More in Working with players.

PlayerRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetPlayerRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javayou are hereHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

18Player findOnlinePlayer(String name) {19    return Bukkit.getPlayerExact(name);20}

Find a player by UUID. A UUID never changes, even when a player renames their account. More in Time, UUIDs and randomness.

PlayerRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetPlayerRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javayou are hereHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

22Player findPlayerByUuid(UUID uuid) {23    return Bukkit.getPlayer(uuid);24}

List everyone online. Loop over the result with a for loop to do something for each player. More in Working with players.

PlayerRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetPlayerRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javayou are hereHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

26Collection<? extends Player> everyoneOnline() {27    return Bukkit.getOnlinePlayers();28}

Check if someone has joined before. Works for players who are offline right now. More in Working with players.

PlayerRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetPlayerRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javayou are hereHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

30boolean hasEverJoined(UUID uuid) {31    OfflinePlayer offline = Bukkit.getOfflinePlayer(uuid);32    return offline.hasPlayedBefore();33}

Heal to full health. Reads the player's maximum health and sets health to that value. More in Working with players.

PlayerRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetPlayerRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javayou are hereHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

35void healFully(Player player) {36    player.setHealth(player.getAttribute(Attribute.MAX_HEALTH).getValue());37}
  1. The player's maximum health. It is 20.0 normally, but other plugins can change it.

Fill the hunger bar. Food level 20 is a full bar. Saturation is the hidden buffer that keeps hunger from dropping. More in Working with players.

PlayerRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetPlayerRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javayou are hereHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

39void fillHunger(Player player) {40    player.setFoodLevel(20);41    player.setSaturation(20.0f);42}

Change the game mode. Survival, creative, adventure or spectator. More in Working with players.

PlayerRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetPlayerRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javayou are hereHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

44void changeGameMode(Player player) {45    player.setGameMode(GameMode.CREATIVE);46}

Teleport to the world spawn. Moves the player to the spawn point of the world they are in. More in Worlds, locations and movement.

PlayerRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetPlayerRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javayou are hereHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

48void teleportToSpawn(Player player) {49    player.teleport(player.getWorld().getSpawnLocation());50}

Teleport five blocks up. getLocation gives a copy, so changing it does not move the player until you call teleport. More in Worlds, locations and movement.

PlayerRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetPlayerRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javayou are hereHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

52void teleportAboveYourself(Player player) {53    Location above = player.getLocation().add(0, 5, 0);54    player.teleport(above);55}

Teleport and load the chunk first. teleportAsync loads the destination without freezing the server. It is the preferred way on Paper and the only way on Folia, a Paper fork that runs different parts of the world on different threads. More in Folia and regionized scheduling.

PlayerRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetPlayerRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javayou are hereHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

57void teleportSafelyWithAsync(Player player, Location target) {58    player.teleportAsync(target);59}

Kick a player with a message. The text is shown on the player's disconnect screen. More in Working with players.

PlayerRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetPlayerRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javayou are hereHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

61void kickWithReason(Player player) {62    player.kick(Component.text("You were removed.", NamedTextColor.RED));63}

Give experience points and levels. giveExp adds points, giveExpLevels adds whole levels. More in Working with players.

PlayerRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetPlayerRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javayou are hereHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

65void giveExperience(Player player) {66    player.giveExp(50);67    player.giveExpLevels(2);68}

Let a player fly. The player can double-tap jump to fly, even in survival mode. More in Working with players.

PlayerRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetPlayerRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javayou are hereHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

70void allowFlying(Player player) {71    player.setAllowFlight(true);72    player.setFlying(true);73}

Change walking speed. The normal speed is 0.2. The allowed range is -1.0 to 1.0. More in Working with players.

PlayerRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetPlayerRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javayou are hereHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

75void changeWalkSpeed(Player player) {76    player.setWalkSpeed(0.3f);77}

Change the name shown in chat. Changes how the player's name appears in chat messages, not the name used to find them. More in Working with players.

PlayerRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetPlayerRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javayou are hereHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

79void changeDisplayName(Player player) {80    player.displayName(Component.text("Captain " + player.getName(), NamedTextColor.GOLD));81}

Remove all potion effects. Loops over the active effects and removes each one by type. More in Potion effects, particles and effects.

PlayerRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetPlayerRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javayou are hereHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

83void clearAllEffects(Player player) {84    player.getActivePotionEffects().forEach(effect -> player.removePotionEffect(effect.getType()));85}

Remove one potion effect. Removes only the effect type you name. More in Potion effects, particles and effects.

PlayerRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetPlayerRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javayou are hereHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

87void removeOneEffect(Player player) {88    player.removePotionEffect(PotionEffectType.SLOWNESS);89}

Hide a player from everyone. Works like a vanish. Players who join later can still see them, so repeat this for new joiners. More in Working with players.

PlayerRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetPlayerRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javayou are hereHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

91void hideFromEveryone(JavaPlugin plugin, Player player) {92    for (Player other : Bukkit.getOnlinePlayers()) {93        other.hidePlayer(plugin, player);94    }95}

Read a player's ping. The round trip time between the server and the player, in milliseconds. More in Working with players.

PlayerRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetPlayerRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javayou are hereHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

97int pingInMilliseconds(Player player) {98    return player.getPing();99}

Check which world a player is in. Compare world names with equals, never with the == sign. More in Worlds, locations and movement.

PlayerRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetPlayerRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javayou are hereHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

101boolean isStandingInWorld(Player player, String worldName) {102    return player.getWorld().getName().equals(worldName);103}

Items

Making items, changing their name, lore and enchantments, and checking what players hold.

Make one item. ItemStack.of makes a stack of one item. More in Items and ItemStacks.

ItemRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetItemRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javayou are hereHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

19ItemStack makeOneDiamond() {20    return ItemStack.of(Material.DIAMOND);21}

Make a stack. The second number is the amount. More in Items and ItemStacks.

ItemRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetItemRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javayou are hereHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

23ItemStack makeStackOfArrows() {24    return ItemStack.of(Material.ARROW, 32);25}

Name an item. editMeta changes the item in place. The italic decoration is turned off because Minecraft italicizes custom names by default. More in Items and ItemStacks.

ItemRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetItemRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javayou are hereHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

27ItemStack nameAnItem(ItemStack item) {28    item.editMeta(meta -> meta.displayName(Component.text("Hero Sword", NamedTextColor.AQUA)29            .decoration(TextDecoration.ITALIC, false)));30    return item;31}
  1. Custom names are italic unless you switch it off.
Hero Sword

Add lore lines. Lore is the gray text under an item's name. Each line is one component. More in Items and ItemStacks.

ItemRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetItemRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javayou are hereHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

33ItemStack addLore(ItemStack item) {34    item.editMeta(meta -> meta.lore(List.of(35            Component.text("Forged in the deep", NamedTextColor.GRAY).decoration(TextDecoration.ITALIC, false),36            Component.text("Soulbound", NamedTextColor.DARK_PURPLE).decoration(TextDecoration.ITALIC, false))));37    return item;38}
Hero Sword

Add an enchantment. The true at the end allows levels above the normal maximum. More in Items and ItemStacks.

ItemRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetItemRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javayou are hereHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

40ItemStack enchantAnItem(ItemStack item) {41    item.editMeta(meta -> meta.addEnchant(Enchantment.SHARPNESS, 5, true));42    return item;43}

Make a tool unbreakable. The tool never loses durability. More in Items and ItemStacks.

ItemRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetItemRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javayou are hereHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

45ItemStack makeUnbreakable(ItemStack item) {46    item.editMeta(meta -> meta.setUnbreakable(true));47    return item;48}

Hide the enchantment list. Hides the enchantments from the tooltip, which is useful when you only want the glint. More in Items and ItemStacks.

ItemRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetItemRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javayou are hereHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

50ItemStack hideEnchantmentList(ItemStack item) {51    item.editMeta(meta -> meta.addItemFlags(ItemFlag.HIDE_ENCHANTS));52    return item;53}

Damage a tool. The damage number counts up from 0, so a high number means a nearly broken tool. More in Items and ItemStacks.

ItemRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetItemRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javayou are hereHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

55ItemStack wearDownATool(ItemStack tool) {56    tool.editMeta(Damageable.class, meta -> meta.setDamage(100));57    return tool;58}
  1. Tells editMeta which kind of meta you want, so you can use damage methods.

Pick a custom model. A resource pack reads this value to choose which model the item shows. More in Registries, keys and data components.

ItemRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetItemRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javayou are hereHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

60ItemStack pickModelWithComponent(ItemStack item) {61    item.setData(DataComponentTypes.CUSTOM_MODEL_DATA, CustomModelData.customModelData().addString("ruby_sword").build());62    return item;63}

Name an item with a data component. The data component way to set a name, with no ItemMeta needed. More in Registries, keys and data components.

ItemRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetItemRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javayou are hereHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

65ItemStack nameWithComponent(ItemStack item) {66    item.setData(DataComponentTypes.CUSTOM_NAME, Component.text("Lucky Charm", NamedTextColor.GREEN));67    return item;68}

Make a player head. setOwningPlayer chooses whose face the head shows. More in Items and ItemStacks.

ItemRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetItemRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javayou are hereHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

70ItemStack makePlayerHead(Player owner) {71    ItemStack head = ItemStack.of(Material.PLAYER_HEAD);72    head.editMeta(SkullMeta.class, meta -> meta.setOwningPlayer(owner));73    return head;74}

Get the held item. Gives the stack in the main hand. An empty hand gives an empty stack, not null. More in Items and ItemStacks.

ItemRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetItemRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javayou are hereHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

76ItemStack itemInMainHand(Player player) {77    return player.getInventory().getItemInMainHand();78}

Check what is held. Compare the material with the == sign. More in Items and ItemStacks.

ItemRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetItemRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javayou are hereHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

80boolean isHoldingSword(Player player) {81    return player.getInventory().getItemInMainHand().getType() == Material.DIAMOND_SWORD;82}

Check for an empty stack. Handles both null and an empty stack, because inventory slots can give either. More in Items and ItemStacks.

ItemRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetItemRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javayou are hereHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

84boolean isNothing(ItemStack item) {85    return item == null || item.isEmpty();86}

Compare two items. isSimilar ignores the amount and compares type and extra data. More in Items and ItemStacks.

ItemRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetItemRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javayou are hereHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

88boolean looksTheSame(ItemStack first, ItemStack second) {89    return first.isSimilar(second);90}

Copy an item with a new amount. clone makes a separate copy, so the original stack stays the same. More in Items and ItemStacks.

ItemRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetItemRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javayou are hereHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

92ItemStack copyWithNewAmount(ItemStack item, int amount) {93    ItemStack copy = item.clone();94    copy.setAmount(amount);95    return copy;96}

Take one item from the hand. Lowering the amount to 0 removes the item. More in Items and ItemStacks.

ItemRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetItemRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javayou are hereHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

98void takeOneFromHand(Player player) {99    ItemStack held = player.getInventory().getItemInMainHand();100    held.setAmount(held.getAmount() - 1);101}

Give an item, or drop what does not fit. addItem returns whatever did not fit, and this drops those items next to the player. More in Inventories.

ItemRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetItemRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javayou are hereHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

103void giveOrDropAtFeet(Player player, ItemStack item) {104    player.getInventory().addItem(item).values()105            .forEach(leftover -> player.getWorld().dropItemNaturally(player.getLocation(), leftover));106}

Read the stack limit. Most items stack to 64, some to 16 and tools to 1. More in Items and ItemStacks.

ItemRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetItemRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javayou are hereHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

108int maxStackSize(Material material) {109    return material.getMaxStackSize();110}

Inventories and menus

Chests, menus and checking what players carry.

Create a chest menu. The number is the slot count and must be a multiple of 9. Passing null means no special owner. More in Building GUI menus.

InventoryRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetInventoryRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javayou are hereListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

19Inventory createChestMenu() {20    return Bukkit.createInventory(null, 27, Component.text("My menu", NamedTextColor.DARK_GRAY));21}

Create a hopper-shaped menu. A five slot menu in the shape of a hopper. More in Building GUI menus.

InventoryRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetInventoryRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javayou are hereListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

23Inventory createHopperMenu() {24    return Bukkit.createInventory(null, InventoryType.HOPPER, Component.text("Pick one"));25}

Put an item in a slot. Slots count from 0 at the top left. Slot 13 is the middle of a 27 slot chest. More in Inventories.

InventoryRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetInventoryRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javayou are hereListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

27void putItemInMiddle(Inventory menu) {28    menu.setItem(13, ItemStack.of(Material.DIAMOND));29}

Fill empty slots. Loops over every slot and fills the empty ones. More in Building GUI menus.

InventoryRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetInventoryRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javayou are hereListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

31void fillEmptySlotsWithGlass(Inventory menu) {32    ItemStack filler = ItemStack.of(Material.GRAY_STAINED_GLASS_PANE);33    for (int slot = 0; slot < menu.getSize(); slot++) {34        if (menu.getItem(slot) == null) {35            menu.setItem(slot, filler);36        }37    }38}
13: diamond

Open an inventory for a player. The player sees the menu until they close it. More in Building GUI menus.

InventoryRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetInventoryRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javayou are hereListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

40void openMenu(Player player, Inventory menu) {41    player.openInventory(menu);42}

Open a menu with MenuType. MenuType makes a view for a player and picks the window shape. More in Building GUI menus.

InventoryRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetInventoryRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javayou are hereListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

44InventoryView openMenuWithMenuType(Player player) {45    InventoryView view = MenuType.GENERIC_9X3.create(player, Component.text("Fresh menu"));46    player.openInventory(view);47    return view;48}

Close the open menu. Closes whatever inventory the player is looking at. More in Inventories.

InventoryRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetInventoryRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javayou are hereListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

50void closeMenu(Player player) {51    player.closeInventory();52}

Check for an amount of an item. Counts across all stacks in the inventory. More in Inventories.

InventoryRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetInventoryRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javayou are hereListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

54boolean hasFiveDiamonds(Player player) {55    return player.getInventory().contains(Material.DIAMOND, 5);56}

Remove an amount of an item. Takes items from several stacks if needed. More in Inventories.

InventoryRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetInventoryRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javayou are hereListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

58void takeFiveDiamonds(Player player) {59    player.getInventory().removeItem(ItemStack.of(Material.DIAMOND, 5));60}

Count items of one kind. Adds up the amounts of every matching stack. More in Inventories.

InventoryRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetInventoryRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javayou are hereListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

62int countItems(Inventory inventory, Material material) {63    int total = 0;64    for (ItemStack stack : inventory.getContents()) {65        if (stack != null && stack.getType() == material) {66            total += stack.getAmount();67        }68    }69    return total;70}

Check for free space. firstEmpty gives -1 when there is no empty slot. More in Inventories.

InventoryRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetInventoryRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javayou are hereListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

72boolean hasRoomForMore(Inventory inventory) {73    return inventory.firstEmpty() != -1;74}

Put armor on a player. There are matching methods for chestplate, leggings and boots. More in Inventories.

InventoryRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetInventoryRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javayou are hereListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

76void putOnHelmet(Player player) {77    player.getInventory().setHelmet(ItemStack.of(Material.IRON_HELMET));78}

Empty a player's inventory. Removes every item the player carries. More in Inventories.

InventoryRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetInventoryRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javayou are hereListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

80void emptyPlayerInventory(Player player) {81    player.getInventory().clear();82}

Choose a hotbar slot. Hotbar slots are numbered 0 to 8. More in Inventories.

InventoryRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetInventoryRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javayou are hereListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

84void selectFirstHotbarSlot(Player player) {85    player.getInventory().setHeldItemSlot(0);86}

Stop players taking items from a menu. Cancels every click on the menu itself, so nothing can be taken out or moved around. Clicks in the player's own inventory below are still allowed. A shift-click from there can still push items into the menu, and the chapter shows the full guard. More in Building GUI menus.

InventoryRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetInventoryRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javayou are hereListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

88@EventHandler89public void lockMenuClicks(InventoryClickEvent event) {90    if (event.getClickedInventory() == event.getView().getTopInventory()) {91        event.setCancelled(true);92    }93}

Worlds, blocks and locations

Positions, blocks, time and weather.

Find a world by name. Gives null if no world has that name. More in Worlds, locations and movement.

WorldRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetWorldRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javayou are hereHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

17World findWorldByName() {18    return Bukkit.getWorld("world");19}

Get the block at a position. The three numbers are x, y and z. More in Blocks and block data.

WorldRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetWorldRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javayou are hereHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

21Block blockAtCoordinates(World world) {22    return world.getBlockAt(100, 64, -20);23}

Change a block. The block changes right away. More in Blocks and block data.

WorldRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetWorldRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javayou are hereHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

25void changeBlockType(Block block) {26    block.setType(Material.GOLD_BLOCK);27}

Get a neighboring block. BlockFace has NORTH, SOUTH, EAST, WEST, UP and DOWN. More in Blocks and block data.

WorldRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetWorldRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javayou are hereHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

29Block blockAboveThisOne(Block block) {30    return block.getRelative(BlockFace.UP);31}

Get the block under a player. Subtract 1 from the y coordinate of the player's location. More in Blocks and block data.

WorldRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetWorldRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javayou are hereHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

33Block blockPlayerStandsOn(Player player) {34    return player.getLocation().subtract(0, 1, 0).getBlock();35}

Get the highest block in a column. The top solid block at that x and z. More in Blocks and block data.

WorldRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetWorldRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javayou are hereHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

37Block highestBlockAt(World world, int x, int z) {38    return world.getHighestBlockAt(x, z);39}

Get the block a player looks at. Gives null when no block is within 5 blocks. More in Blocks and block data.

WorldRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetWorldRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javayou are hereHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

41Block blockPlayerLooksAt(Player player) {42    return player.getTargetBlockExact(5);43}

Shoot a ray from the eyes. The result says which block the ray hit and where. It is null when nothing was hit. More in Worlds, locations and movement.

WorldRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetWorldRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javayou are hereHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

45RayTraceResult shootRayFromEyes(Player player) {46    return player.rayTraceBlocks(10.0);47}

Make a location. Add 0.5 to x and z to land in the middle of a block. More in Worlds, locations and movement.

WorldRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetWorldRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javayou are hereHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

49Location makeLocation(World world) {50    return new Location(world, 100.5, 64, -20.5);51}

Move a location without changing the original. clone first, then add. Otherwise add would change the location you passed in. More in Worlds, locations and movement.

WorldRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetWorldRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javayou are hereHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

53Location oneBlockHigher(Location location) {54    return location.clone().add(0, 1, 0);55}

Measure the distance. Both locations must be in the same world, or Java throws an exception. More in Worlds, locations and movement.

WorldRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetWorldRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javayou are hereHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

57double distanceBetween(Location first, Location second) {58    return first.distance(second);59}

Get the direction a player faces. A vector of length 1 that points where the player looks. More in Worlds, locations and movement.

WorldRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetWorldRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javayou are hereHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

61Vector directionPlayerFaces(Player player) {62    return player.getLocation().getDirection();63}

Get a spot three blocks ahead. Starts at the eyes and moves along the look direction. More in Worlds, locations and movement.

WorldRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetWorldRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javayou are hereHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

65Location spotInFrontOfPlayer(Player player) {66    Location eyes = player.getEyeLocation();67    return eyes.add(eyes.getDirection().multiply(3));68}

Check if two locations are in the same block. Compares blocks instead of exact decimal positions. More in Worlds, locations and movement.

WorldRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetWorldRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javayou are hereHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

70boolean isSameBlock(Location first, Location second) {71    return first.getBlock().equals(second.getBlock());72}

Set the time of day. Time counts in ticks. 0 is sunrise, 6000 is noon and 13000 is night. More in Worlds, locations and movement.

WorldRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetWorldRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javayou are hereHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

74void setTimeToMorning(World world) {75    world.setTime(1000);76}

Make the weather clear. Turns rain and thunder off. More in Worlds, locations and movement.

WorldRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetWorldRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javayou are hereHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

78void clearTheWeather(World world) {79    world.setStorm(false);80    world.setThundering(false);81}

Strike harmless lightning. Looks and sounds like lightning but hurts nothing. More in Potion effects, particles and effects.

WorldRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetWorldRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javayou are hereHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

83void strikeLightningWithoutDamage(Location location) {84    location.getWorld().strikeLightningEffect(location);85}

Make an explosion. The numbers are the power, whether it sets fire and whether it breaks blocks. Here it hurts and pushes nearby entities but breaks no blocks. More in Potion effects, particles and effects.

WorldRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetWorldRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javayou are hereHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

87void makeExplosion(Location location) {88    location.getWorld().createExplosion(location, 4.0f, false, false);89}

Change the world border. Sets the border width in blocks. More in Worlds, locations and movement.

WorldRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetWorldRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javayou are hereHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

91void shrinkWorldBorder(World world) {92    world.getWorldBorder().setSize(500);93}

Move the world spawn. Where new players appear. More in Worlds, locations and movement.

WorldRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetWorldRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javayou are hereHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

95void moveWorldSpawn(World world, Location location) {96    world.setSpawnLocation(location);97}

Change the difficulty. Peaceful, easy, normal or hard. More in Worlds, locations and movement.

WorldRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetWorldRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javayou are hereHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

99void changeDifficulty(World world) {100    world.setDifficulty(Difficulty.HARD);101}

Change a game rule. GameRules lists the rules, and the type of the value matches the rule. More in Worlds, locations and movement.

WorldRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetWorldRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javayou are hereHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

103void keepInventoryOnDeath(World world) {104    world.setGameRule(GameRules.KEEP_INVENTORY, true);105}

Count blocks around a point. Three loops walk a cube. Keep radii small, because each step looks at one block. More in Blocks and block data.

WorldRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetWorldRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javayou are hereHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

107int countBlocksInRadius(Location center, Material material, int radius) {108    int found = 0;109    for (int x = -radius; x <= radius; x++) {110        for (int y = -radius; y <= radius; y++) {111            for (int z = -radius; z <= radius; z++) {112                if (center.clone().add(x, y, z).getBlock().getType() == material) {113                    found++;114                }115            }116        }117    }118    return found;119}

Entities and mobs

Spawning, finding and changing mobs and other entities.

Spawn a mob. spawnEntity returns the new entity. More in Entities and mobs.

EntityRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetEntityRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javayou are hereHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

23Entity spawnAZombie(Location location) {24    return location.getWorld().spawnEntity(location, EntityType.ZOMBIE);25}

Spawn a mob and set it up. The lambda runs before the mob appears, so there is no flicker. More in Entities and mobs.

EntityRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetEntityRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javayou are hereHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

27Zombie spawnNamedZombie(Location location) {28    return location.getWorld().spawn(location, Zombie.class, zombie -> {29        zombie.customName(Component.text("Gravedigger", NamedTextColor.RED));30        zombie.setCustomNameVisible(true);31    });32}
  1. Runs on the new zombie before it is added to the world.

Find entities nearby. The three numbers are how far to search along x, y and z. More in Entities and mobs.

EntityRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetEntityRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javayou are hereHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

34List<Entity> entitiesNearPlayer(Player player) {35    return player.getNearbyEntities(10, 10, 10);36}

Count one kind of entity nearby. instanceof checks what kind of entity each one is. More in Entities and mobs.

EntityRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetEntityRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javayou are hereHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

38int countNearbyZombies(Player player) {39    int zombies = 0;40    for (Entity entity : player.getNearbyEntities(20, 20, 20)) {41        if (entity instanceof Zombie) {42            zombies++;43        }44    }45    return zombies;46}

Give an entity a name. Shows the name above the entity. More in Entities and mobs.

EntityRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetEntityRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javayou are hereHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

48void giveANameTag(Entity entity) {49    entity.customName(Component.text("Fluffy", NamedTextColor.LIGHT_PURPLE));50    entity.setCustomNameVisible(true);51}

Make an entity glow. Draws a colored outline through walls. More in Entities and mobs.

EntityRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetEntityRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javayou are hereHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

53void makeGlow(Entity entity) {54    entity.setGlowing(true);55}

Remove an entity. Deletes it without drops or death animation. More in Entities and mobs.

EntityRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetEntityRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javayou are hereHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

57void removeFromWorld(Entity entity) {58    entity.remove();59}

Make an entity invulnerable. It takes no damage. More in Entities and mobs.

EntityRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetEntityRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javayou are hereHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

61void makeInvulnerable(Entity entity) {62    entity.setInvulnerable(true);63}

Launch an entity. A Vector is a direction and a strength. y is up. More in Worlds, locations and movement.

EntityRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetEntityRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javayou are hereHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

65void launchUpwards(Entity entity) {66    entity.setVelocity(new Vector(0, 1, 0));67}

Push an entity away from a player. Subtract positions to get the direction, normalize it to length 1, then scale it. More in Worlds, locations and movement.

EntityRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetEntityRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javayou are hereHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

69void pushAwayFromPlayer(Entity entity, Player player) {70    Vector away = entity.getLocation().toVector().subtract(player.getLocation().toVector()).normalize();71    entity.setVelocity(away.multiply(1.5));72}

Make a mob chase a player. The mob walks toward the target and attacks. More in Entities and mobs.

EntityRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetEntityRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javayou are hereHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

74void chasePlayer(Mob mob, Player player) {75    mob.setTarget(player);76}

Give a mob 100 health. Raise the maximum first, then fill up the current health. More in Entities and mobs.

EntityRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetEntityRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javayou are hereHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

78void makeBossTough(LivingEntity boss) {79    boss.getAttribute(Attribute.MAX_HEALTH).setBaseValue(100.0);80    boss.setHealth(100.0);81}

Put armor on a mob. getEquipment gives the slots a mob wears. More in Entities and mobs.

EntityRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetEntityRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javayou are hereHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

83void giveHelmet(Zombie zombie) {84    zombie.getEquipment().setHelmet(ItemStack.of(Material.IRON_HELMET));85}

Show floating text. A text display needs no armor stand and works as a hologram. More in Entities and mobs.

EntityRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetEntityRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javayou are hereHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

87TextDisplay floatingText(Location location) {88    return location.getWorld().spawn(location, TextDisplay.class, display ->89            display.text(Component.text("Shop", NamedTextColor.GOLD)));90}

Shoot an arrow. The arrow flies where the player looks. More in Entities and mobs.

EntityRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetEntityRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javayou are hereHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

92Arrow shootArrow(Player player) {93    return player.launchProjectile(Arrow.class);94}

Drop an item in the world. dropItemNaturally adds a little random sideways movement. More in Items and ItemStacks.

EntityRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetEntityRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javayou are hereHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

96void dropAnItem(World world, Location location) {97    world.dropItemNaturally(location, ItemStack.of(Material.EMERALD, 3));98}

Check what an entity is. Many events give you an Entity, and this tells you if it is a player. More in Entities and mobs.

EntityRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetEntityRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javayou are hereHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

100boolean isPlayer(Entity entity) {101    return entity instanceof Player;102}

Check and convert at once. The player variable is ready to use inside the if block. More in Entities and mobs.

EntityRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetEntityRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javayou are hereHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

104void ifPlayerThen(Entity entity) {105    if (entity instanceof Player player) {106        player.sendRichMessage("<green>You are a player!");107    }108}

Sounds, particles and potion effects

Things players see and hear.

Play a sound to one player. The numbers are volume and pitch. Only that player hears it. More in Potion effects, particles and effects.

EffectRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetEffectRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javayou are hereHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

19void playSoundToPlayer(Player player) {20    player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1.0f, 1.0f);21}

Play a sound at a place. Everyone close enough to the location hears it. More in Potion effects, particles and effects.

EffectRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetEffectRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javayou are hereHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

23void playSoundForEveryoneNearby(Location location) {24    location.getWorld().playSound(location, Sound.BLOCK_ANVIL_LAND, 1.0f, 0.8f);25}

Play a sound by its key. Use this for sounds from resource packs. More in Potion effects, particles and effects.

EffectRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetEffectRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javayou are hereHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

27void playSoundByName(Player player) {28    player.playSound(net.kyori.adventure.sound.Sound.sound(Key.key("entity.experience_orb.pickup"), Source.PLAYER, 1.0f, 1.0f));29}

Stop all sounds. Silences everything the player currently hears. More in Potion effects, particles and effects.

EffectRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetEffectRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javayou are hereHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

31void stopAllSounds(Player player) {32    player.stopAllSounds();33}

Spawn particles. The numbers are the count, the spread along x, y and z, and the speed. More in Potion effects, particles and effects.

EffectRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetEffectRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javayou are hereHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

35void sprinkleFlames(Location location) {36    location.getWorld().spawnParticle(Particle.FLAME, location, 20, 0.3, 0.3, 0.3, 0.01);37}

Show hearts above a player. Adds 2 to y so the hearts float over the head. More in Potion effects, particles and effects.

EffectRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetEffectRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javayou are hereHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

39void showHeartsOverPlayer(Player player) {40    player.getWorld().spawnParticle(Particle.HEART, player.getLocation().add(0, 2, 0), 5);41}

Spawn colored dust. DustOptions choose the color and the size. More in Potion effects, particles and effects.

EffectRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetEffectRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javayou are hereHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

43void spawnColoredDust(Location location) {44    Particle.DustOptions orange = new Particle.DustOptions(Color.ORANGE, 1.5f);45    location.getWorld().spawnParticle(Particle.DUST, location, 15, orange);46}

Show particles to one player. Other players do not see these. More in Potion effects, particles and effects.

EffectRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetEffectRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javayou are hereHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

48void showParticlesOnlyToOnePlayer(Player player) {49    player.spawnParticle(Particle.CLOUD, player.getLocation(), 10);50}

Draw a ring of particles. Sine and cosine turn an angle into a point on a circle. More in Potion effects, particles and effects.

EffectRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetEffectRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javayou are hereHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

52void drawRingOfParticles(Location center, double radius) {53    World world = center.getWorld();54    for (int step = 0; step < 36; step++) {55        double angle = Math.toRadians(step * 10);56        Location point = center.clone().add(Math.cos(angle) * radius, 0, Math.sin(angle) * radius);57        world.spawnParticle(Particle.END_ROD, point, 1, 0, 0, 0, 0);58    }59}

Add a potion effect. The numbers are the effect, the duration in ticks and the level minus one. More in Potion effects, particles and effects.

EffectRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetEffectRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javayou are hereHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

61void addSpeedForTenSeconds(Player player) {62    player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 200, 1));63}

Add an effect without swirls. The last two flags are ambient (the beacon style) and particles. Setting particles to false hides the swirls. More in Potion effects, particles and effects.

EffectRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetEffectRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javayou are hereHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

65void addInvisibleEffectWithoutParticles(Player player) {66    player.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 600, 0, false, false));67}

Check for an effect. True while the player has that effect. More in Potion effects, particles and effects.

EffectRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetEffectRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javayou are hereHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

69boolean hasNightVision(Player player) {70    return player.hasPotionEffect(PotionEffectType.NIGHT_VISION);71}

Launch a firework. FireworkEffect describes the burst and the power sets how high it flies. More in Potion effects, particles and effects.

EffectRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetEffectRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javayou are hereHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

73Firework launchFirework(Location location) {74    return location.getWorld().spawn(location, Firework.class, rocket -> {75        FireworkMeta meta = rocket.getFireworkMeta();76        meta.addEffect(FireworkEffect.builder().withColor(Color.RED).withFade(Color.YELLOW).flicker(true).build());77        meta.setPower(1);78        rocket.setFireworkMeta(meta);79    });80}

Scheduling

Running code later, repeatedly, or away from the main thread. Remember: 20 ticks make one second.

Run code after a delay. The last number is the delay in ticks, and 20 ticks are one second. More in Timing and tasks: the scheduler.

SchedulerRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetSchedulerRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javayou are hereHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

13void runOneSecondLater(JavaPlugin plugin, Player player) {14    plugin.getServer().getScheduler().runTaskLater(plugin, () -> player.sendRichMessage("<green>One second passed."), 20L);15}
  1. A lambda: the code to run later, written inline.

Run code on the next tick. Handy to get back onto the main thread. More in Timing and tasks: the scheduler.

SchedulerRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetSchedulerRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javayou are hereHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

17void runOnNextTick(JavaPlugin plugin, Runnable work) {18    plugin.getServer().getScheduler().runTask(plugin, work);19}

Repeat code. The numbers are the first delay and the time between runs, both in ticks. Keep the returned task so you can cancel it. More in Timing and tasks: the scheduler.

SchedulerRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetSchedulerRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javayou are hereHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

21BukkitTask repeatEveryTwoSeconds(JavaPlugin plugin, Player player) {22    return plugin.getServer().getScheduler().runTaskTimer(plugin, () -> player.sendActionBar(Component.text("Tick tock")), 0L, 40L);23}

Count down and stop. The task cancels itself when the counter reaches zero. AtomicInteger is a number you can change inside a lambda. More in Timing and tasks: the scheduler.

SchedulerRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetSchedulerRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javayou are hereHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

25void countdownFromTen(JavaPlugin plugin, Player player) {26    AtomicInteger secondsLeft = new AtomicInteger(10);27    plugin.getServer().getScheduler().runTaskTimer(plugin, task -> {28        if (secondsLeft.get() == 0) {29            player.sendRichMessage("<green>Go!");30            task.cancel();31            return;32        }33        player.sendRichMessage("<yellow>" + secondsLeft.getAndDecrement());34    }, 0L, 20L);35}
  1. Stops this repeating task for good.

Run slow work in the background. Use it for files, databases and web requests. Never touch the world from inside it. More in Threads, performance and lag.

SchedulerRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetSchedulerRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javayou are hereHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

37void runSlowWorkOffTheMainThread(JavaPlugin plugin, Runnable slowWork) {38    plugin.getServer().getScheduler().runTaskAsynchronously(plugin, slowWork);39}

Work in the background, then return. Do the slow part in the background, then hop back to the main thread to talk to players. More in Threads, performance and lag.

SchedulerRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetSchedulerRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javayou are hereHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

41void doSlowWorkThenComeBack(JavaPlugin plugin, Player player) {42    plugin.getServer().getScheduler().runTaskAsynchronously(plugin, () -> {43        int result = 6 * 7;44        plugin.getServer().getScheduler().runTask(plugin, () -> player.sendRichMessage("<gold>Answer: " + result));45    });46}
  1. Runs the inner code back on the main thread.

Cancel all of your tasks. Good to call in onDisable. More in Timing and tasks: the scheduler.

SchedulerRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetSchedulerRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javayou are hereHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

48void stopEverythingThisPluginScheduled(JavaPlugin plugin) {49    plugin.getServer().getScheduler().cancelTasks(plugin);50}

Use a BukkitRunnable. A runnable class can cancel itself by calling cancel from inside run. More in Timing and tasks: the scheduler.

SchedulerRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetSchedulerRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javayou are hereHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

52BukkitTask startRunnableClass(JavaPlugin plugin, Player player) {53    return new BukkitRunnable() {54        @Override55        public void run() {56            player.sendRichMessage("<aqua>Still here!");57        }58    }.runTaskTimer(plugin, 0L, 100L);59}

Run code for one entity. This is the Folia-safe way. The last value is code to run if the entity is gone before the task starts, and null means nothing. More in Folia and regionized scheduling.

SchedulerRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetSchedulerRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javayou are hereHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

61void runOnEntityThread(JavaPlugin plugin, Player player) {62    player.getScheduler().run(plugin, task -> player.sendRichMessage("<green>Hello from the player's region."), null);63}

Run code on the global region. For work that is not tied to a place. More in Folia and regionized scheduling.

SchedulerRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetSchedulerRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javayou are hereHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

65void runOnGlobalRegion(JavaPlugin plugin) {66    plugin.getServer().getGlobalRegionScheduler().runDelayed(plugin, task -> plugin.getLogger().info("Ran later."), 20L);67}

Run delayed work in the background. Paper's async scheduler takes a normal time unit instead of ticks. More in Folia and regionized scheduling.

SchedulerRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetSchedulerRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javayou are hereHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

69void runOnAsyncScheduler(JavaPlugin plugin) {70    plugin.getServer().getAsyncScheduler().runDelayed(plugin, task -> plugin.getLogger().info("Ran in the background."), 5, TimeUnit.SECONDS);71}

Config files

Reading and writing config.yml and your own YAML files.

Copy the default config. Copies config.yml out of your jar into the plugin folder, but only if the file does not exist yet. More in Configuration files.

ConfigRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetConfigRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javayou are hereHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

14void copyDefaultConfigOnFirstRun(JavaPlugin plugin) {15    plugin.saveDefaultConfig();16}

Read text. The second value is used when the key is missing. More in Configuration files.

ConfigRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetConfigRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javayou are hereHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

18String readText(JavaPlugin plugin) {19    return plugin.getConfig().getString("welcome-message", "Welcome!");20}

Read a whole number. Missing or invalid values give the default. More in Configuration files.

ConfigRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetConfigRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javayou are hereHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

22int readWholeNumber(JavaPlugin plugin) {23    return plugin.getConfig().getInt("max-homes", 3);24}

Read a decimal number. Use double for numbers with a decimal point. More in Configuration files.

ConfigRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetConfigRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javayou are hereHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

26double readDecimalNumber(JavaPlugin plugin) {27    return plugin.getConfig().getDouble("price", 9.99);28}

Read true or false. YAML understands true and false. More in Configuration files.

ConfigRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetConfigRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javayou are hereHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

30boolean readTrueOrFalse(JavaPlugin plugin) {31    return plugin.getConfig().getBoolean("announce-joins", true);32}

Read a list. Each dash line in the YAML becomes one String. More in Configuration files.

ConfigRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetConfigRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javayou are hereHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

34List<String> readListOfText(JavaPlugin plugin) {35    return plugin.getConfig().getStringList("blocked-words");36}

Change a value and save. Without saveConfig the change is lost when the server stops. More in Configuration files.

ConfigRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetConfigRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javayou are hereHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

38void changeAndSave(JavaPlugin plugin) {39    plugin.getConfig().set("max-homes", 5);40    plugin.saveConfig();41}

Reload the config. Re-reads the file from disk, which is good for a command of your own such as /myplugin reload. More in Configuration files.

ConfigRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetConfigRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javayou are hereHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

43void reloadFromDisk(JavaPlugin plugin) {44    plugin.reloadConfig();45}

List the keys in a section. false means only the direct children, not deeper levels. More in Configuration files.

ConfigRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetConfigRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javayou are hereHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

47Set<String> listKitNames(JavaPlugin plugin) {48    ConfigurationSection kits = plugin.getConfig().getConfigurationSection("kits");49    return kits == null ? Set.of() : kits.getKeys(false);50}

Check if a key exists. Dots go deeper into sections. More in Configuration files.

ConfigRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetConfigRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javayou are hereHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

52boolean hasSetting(JavaPlugin plugin) {53    return plugin.getConfig().contains("spawn.world");54}

Load your own YAML file. A missing file gives an empty configuration instead of an error. More in Saving player data: files and databases.

ConfigRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetConfigRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javayou are hereHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

56YamlConfiguration loadOwnYamlFile(JavaPlugin plugin) {57    File file = new File(plugin.getDataFolder(), "data.yml");58    return YamlConfiguration.loadConfiguration(file);59}

Save your own YAML file. Saving can fail with an IOException, so the method declares it. More in Saving player data: files and databases.

ConfigRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetConfigRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javayou are hereHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

61void saveOwnYamlFile(JavaPlugin plugin, FileConfiguration data) throws IOException {62    File file = new File(plugin.getDataFolder(), "data.yml");63    data.save(file);64}

Create the plugin folder. Safe to call when the folder already exists. More in Saving player data: files and databases.

ConfigRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetConfigRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javayou are hereHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

66void makeSureDataFolderExists(JavaPlugin plugin) {67    plugin.getDataFolder().mkdirs();68}

Saving data on things

PersistentDataContainer, the sticky notes you attach to players, items, entities and chunks.

Make a key. A key names one saved value. Make it once and reuse it. More in Saving data on things: PersistentDataContainer.

DataRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetDataRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javayou are hereHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

15NamespacedKey makeKey(JavaPlugin plugin) {16    return new NamespacedKey(plugin, "coins");17}

Save a number on a player. Stored in the player's data file, so it survives restarts. More in Saving data on things: PersistentDataContainer.

DataRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetDataRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javayou are hereHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

19void saveNumberOnPlayer(Player player, NamespacedKey key) {20    player.getPersistentDataContainer().set(key, PersistentDataType.INTEGER, 25);21}

Read a saved number. getOrDefault returns 0 when nothing is saved yet. More in Saving data on things: PersistentDataContainer.

DataRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetDataRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javayou are hereHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

23int readNumberFromPlayer(Player player, NamespacedKey key) {24    return player.getPersistentDataContainer().getOrDefault(key, PersistentDataType.INTEGER, 0);25}

Add one to a saved number. Read, change, write back. More in Saving data on things: PersistentDataContainer.

DataRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetDataRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javayou are hereHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

27void addOneToSavedNumber(Player player, NamespacedKey key) {28    PersistentDataContainer data = player.getPersistentDataContainer();29    int current = data.getOrDefault(key, PersistentDataType.INTEGER, 0);30    data.set(key, PersistentDataType.INTEGER, current + 1);31}

Check if something is saved. Checks only that the key exists. More in Saving data on things: PersistentDataContainer.

DataRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetDataRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javayou are hereHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

33boolean hasSavedValue(Entity entity, NamespacedKey key) {34    return entity.getPersistentDataContainer().has(key);35}

Delete a saved value. Removes the key completely. More in Saving data on things: PersistentDataContainer.

DataRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetDataRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javayou are hereHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

37void deleteSavedValue(Entity entity, NamespacedKey key) {38    entity.getPersistentDataContainer().remove(key);39}

Save text on an entity. Works on mobs, armor stands and other entities. More in Saving data on things: PersistentDataContainer.

DataRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetDataRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javayou are hereHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

41void saveTextOnEntity(Entity entity, NamespacedKey key) {42    entity.getPersistentDataContainer().set(key, PersistentDataType.STRING, "guard");43}

Save true or false. PersistentDataType.BOOLEAN stores a boolean value. More in Saving data on things: PersistentDataContainer.

DataRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetDataRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javayou are hereHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

45void saveTrueOrFalse(Player player, NamespacedKey key) {46    player.getPersistentDataContainer().set(key, PersistentDataType.BOOLEAN, true);47}

Save a list. LIST.strings makes the type for a list of text. More in Saving data on things: PersistentDataContainer.

DataRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetDataRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javayou are hereHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

49void saveListOfText(Player player, NamespacedKey key) {50    player.getPersistentDataContainer().set(key, PersistentDataType.LIST.strings(), List.of("home", "mine", "farm"));51}

Tag an item. Marks an item as special so you can recognize it later, even if renamed. More in Saving data on things: PersistentDataContainer.

DataRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetDataRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javayou are hereHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

53void tagAnItem(ItemStack item, NamespacedKey key) {54    item.editMeta(meta -> meta.getPersistentDataContainer().set(key, PersistentDataType.STRING, "magic-wand"));55}

Check an item's tag. Pass the type as well, so a value of the wrong type is not mistaken for yours. More in Saving data on things: PersistentDataContainer.

DataRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetDataRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javayou are hereHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

57boolean isTaggedItem(ItemStack item, NamespacedKey key) {58    return item.getPersistentDataContainer().has(key, PersistentDataType.STRING);59}

Save a number on a chunk. Chunks carry saved values too. More in Saving data on things: PersistentDataContainer.

DataRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetDataRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javayou are hereHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

61void saveNumberOnChunk(Chunk chunk, NamespacedKey key) {62    chunk.getPersistentDataContainer().set(key, PersistentDataType.LONG, System.currentTimeMillis());63}

Permissions

Checking and granting rights.

Check a permission. True when the sender has the permission. The console has them all. More in Permissions.

PermissionRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetPermissionRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javayou are hereHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

12boolean mayUseFeature(CommandSender sender) {13    return sender.hasPermission("myplugin.heal");14}

Stop when not allowed. Return early with a message, so the rest of the code only runs for allowed senders. More in Permissions.

PermissionRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetPermissionRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javayou are hereHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

16boolean stopIfNotAllowed(CommandSender sender) {17    if (!sender.hasPermission("myplugin.admin")) {18        sender.sendRichMessage("<red>You may not do that.");19        return true;20    }21    return false;22}

Check for operator. Operators are the people listed in ops.json. More in Permissions.

PermissionRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetPermissionRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javayou are hereHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

24boolean isOperator(CommandSender sender) {25    return sender.isOp();26}

Check the sender is a player. The console and command blocks are senders too, and they are not players. More in Commands, part 1: simple commands.

PermissionRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetPermissionRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javayou are hereHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

28boolean isPlayerNotConsole(CommandSender sender) {29    return sender instanceof Player;30}

Declare a permission. Gives it a description and a default for who gets it. More in Permissions.

PermissionRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetPermissionRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javayou are hereHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

32void declarePermissionInCode(JavaPlugin plugin) {33    Permission heal = new Permission("myplugin.heal", "Lets a player heal themselves", PermissionDefault.OP);34    plugin.getServer().getPluginManager().addPermission(heal);35}

Give a permission for now. Lasts until the player disconnects or you remove the attachment. More in Permissions.

PermissionRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetPermissionRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javayou are hereHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

37PermissionAttachment givePermissionTemporarily(JavaPlugin plugin, Player player) {38    PermissionAttachment attachment = player.addAttachment(plugin);39    attachment.setPermission("myplugin.vip", true);40    return attachment;41}

Take it back. Removes everything the attachment granted. More in Permissions.

PermissionRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetPermissionRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javayou are hereHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

43void takeTemporaryPermissionBack(PermissionAttachment attachment) {44    attachment.remove();45}

Commands

The modern way to make commands with Brigadier (Mojang's command library, which Paper uses for every command), and the classic way with plugin.yml.

The simplest command. A BasicCommand is one method that receives the sender and the words typed after the command. More in Commands, part 1: simple commands.

CommandRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetCommandRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javayou are hereCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

20BasicCommand simpleCommand() {21    return (source, args) -> source.getSender().sendRichMessage("<green>Hello from a command!");22}
  1. The player or console that ran the command.

Read what was typed. args holds the words after the command name. Check its length before reading. More in Commands, part 1: simple commands.

CommandRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetCommandRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javayou are hereCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

24BasicCommand commandWithArguments() {25    return (source, args) -> {26        if (args.length == 0) {27            source.getSender().sendRichMessage("<red>Usage: /greet <name>");28            return;29        }30        source.getSender().sendRichMessage("<green>Hello, " + args[0] + "!");31    };32}

Permission and tab completion. permission names the permission needed. suggest gives the tab list. More in Commands, part 1: simple commands.

CommandRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetCommandRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javayou are hereCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

34BasicCommand commandWithPermissionAndTabCompletion() {35    return new BasicCommand() {36        @Override37        public void execute(CommandSourceStack source, String[] args) {38            source.getSender().sendRichMessage("<green>You are allowed!");39        }40 41        @Override42        public Collection<String> suggest(CommandSourceStack source, String[] args) {43            return List.of("red", "green", "blue");44        }45 46        @Override47        public String permission() {48            return "myplugin.color";49        }50    };51}

Register a BasicCommand. Commands are registered at the COMMANDS lifecycle moment, not directly in onEnable. More in Commands, part 1: simple commands.

CommandRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetCommandRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javayou are hereCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

53void registerSimpleCommand(JavaPlugin plugin) {54    plugin.getLifecycleManager().registerEventHandler(LifecycleEvents.COMMANDS, event ->55            event.registrar().register("hello", simpleCommand()));56}
  1. The moment Paper is ready to accept commands.

Register with aliases. Players can also type the extra names. More in Commands, part 1: simple commands.

CommandRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetCommandRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javayou are hereCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

58void registerWithAliases(JavaPlugin plugin) {59    plugin.getLifecycleManager().registerEventHandler(LifecycleEvents.COMMANDS, event ->60            event.registrar().register("hello", List.of("hi", "hey"), simpleCommand()));61}

A Brigadier command. A tree: the word ping, and the code to run. Returning 1 means success. More in Commands, part 2: Brigadier command trees.

CommandRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetCommandRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javayou are hereCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

63LiteralCommandNode<CommandSourceStack> brigadierCommand() {64    return Commands.literal("ping")65            .executes(context -> {66                context.getSource().getSender().sendRichMessage("<green>Pong!");67                return Command.SINGLE_SUCCESS;68            })69            .build();70}

Register a Brigadier command. Hand the built tree to the registrar. More in Commands, part 2: Brigadier command trees.

CommandRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetCommandRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javayou are hereCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

72void registerBrigadierCommand(JavaPlugin plugin) {73    plugin.getLifecycleManager().registerEventHandler(LifecycleEvents.COMMANDS, event ->74            event.registrar().register(brigadierCommand()));75}

A number argument. The numbers 1 and 64 are the allowed range. Brigadier rejects other values for you. More in Commands, part 2: Brigadier command trees.

CommandRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetCommandRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javayou are hereCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

77LiteralCommandNode<CommandSourceStack> numberArgument() {78    return Commands.literal("give")79            .then(Commands.argument("amount", IntegerArgumentType.integer(1, 64))80                    .executes(context -> {81                        int amount = IntegerArgumentType.getInteger(context, "amount");82                        context.getSource().getSender().sendRichMessage("<gold>Giving " + amount);83                        return Command.SINGLE_SUCCESS;84                    }))85            .build();86}

A word and then the rest of the line. greedyString takes everything left, so it must be the last argument. More in Commands, part 2: Brigadier command trees.

CommandRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetCommandRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javayou are hereCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

88LiteralCommandNode<CommandSourceStack> wordAndTextArguments() {89    return Commands.literal("say")90            .then(Commands.argument("topic", StringArgumentType.word())91                    .then(Commands.argument("message", StringArgumentType.greedyString())92                            .executes(context -> {93                                String topic = StringArgumentType.getString(context, "topic");94                                String message = StringArgumentType.getString(context, "message");95                                context.getSource().getSender().sendRichMessage("<gray>[" + topic + "] " + message);96                                return Command.SINGLE_SUCCESS;97                            })))98            .build();99}

A player argument. The argument gives a selector that you resolve into real players. More in Commands, part 2: Brigadier command trees.

CommandRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetCommandRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javayou are hereCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

101LiteralCommandNode<CommandSourceStack> playerArgument() {102    return Commands.literal("poke")103            .then(Commands.argument("target", ArgumentTypes.player())104                    .executes(context -> {105                        PlayerSelectorArgumentResolver selector = context.getArgument("target", PlayerSelectorArgumentResolver.class);106                        Player target = selector.resolve(context.getSource()).getFirst();107                        target.sendRichMessage("<yellow>You were poked!");108                        return Command.SINGLE_SUCCESS;109                    }))110            .build();111}

Hide a command from people without a permission. Players without it do not even see the command in tab completion. More in Commands, part 2: Brigadier command trees.

CommandRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetCommandRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javayou are hereCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

113LiteralCommandNode<CommandSourceStack> onlyForPermissionHolders() {114    return Commands.literal("secret")115            .requires(source -> source.getSender().hasPermission("myplugin.secret"))116            .executes(context -> Command.SINGLE_SUCCESS)117            .build();118}

Check who runs the command. getExecutor is the entity running the command. It is null when there is no entity, such as the console. More in Commands, part 2: Brigadier command trees.

CommandRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetCommandRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javayou are hereCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

120LiteralCommandNode<CommandSourceStack> onlyForPlayers() {121    return Commands.literal("whereami")122            .executes(context -> {123                if (context.getSource().getExecutor() instanceof Player player) {124                    player.sendRichMessage("<green>You are at " + player.getLocation().getBlockX());125                }126                return Command.SINGLE_SUCCESS;127            })128            .build();129}

Suggest choices. The suggestions appear in the tab list while the player types. More in Commands, part 2: Brigadier command trees.

CommandRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetCommandRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javayou are hereCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

131LiteralCommandNode<CommandSourceStack> suggestedChoices() {132    return Commands.literal("team")133            .then(Commands.argument("color", StringArgumentType.word())134                    .suggests((context, builder) -> {135                        builder.suggest("red");136                        builder.suggest("blue");137                        return builder.buildFuture();138                    })139                    .executes(context -> Command.SINGLE_SUCCESS))140            .build();141}

Attach a plugin.yml command. The command must also be listed in plugin.yml. Return true when you handled it. More in Commands, part 3: the classic plugin.yml way.

CommandRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetCommandRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javayou are hereCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

143void attachClassicCommand(JavaPlugin plugin) {144    plugin.getCommand("heal").setExecutor((sender, command, label, args) -> {145        sender.sendRichMessage("<green>Healed!");146        return true;147    });148}

Attach classic tab completion. Return the list of suggestions. More in Commands, part 3: the classic plugin.yml way.

CommandRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetCommandRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javayou are hereCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javaListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

150void attachClassicTabCompletion(JavaPlugin plugin) {151    plugin.getCommand("heal").setTabCompleter((sender, command, alias, args) -> List.of("self", "all"));152}

Events

Reacting to things that happen. Methods marked with an annotation must live in a class that implements Listener and is registered.

Register a listener. Without this call none of the handlers work. More in Events and listeners.

EventRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetEventRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javayou are hereListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

28void startListening(JavaPlugin plugin, Listener listener) {29    plugin.getServer().getPluginManager().registerEvents(listener, plugin);30}

Unregister a listener. Stops all its handlers. More in Events and listeners.

EventRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetEventRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javayou are hereListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

32void stopListening(Listener listener) {33    HandlerList.unregisterAll(listener);34}

Fire an event yourself. Fires an event so other listeners can react to it. More in Making your own events.

EventRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetEventRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javayou are hereListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

36void fireAnEvent(JavaPlugin plugin, org.bukkit.event.Event event) {37    plugin.getServer().getPluginManager().callEvent(event);38}

Change the join message. Players see this instead of the default yellow line. More in Events and listeners.

EventRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetEventRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javayou are hereListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

40@EventHandler41public void changeJoinMessage(PlayerJoinEvent event) {42    event.joinMessage(Component.text(event.getPlayer().getName() + " arrived!", NamedTextColor.YELLOW));43}

Hide the quit message. Setting the message to null hides it. More in Events and listeners.

EventRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetEventRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javayou are hereListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

45@EventHandler46public void hideQuitMessage(PlayerQuitEvent event) {47    event.quitMessage(null);48}

Stop a block from breaking. Canceling the event leaves the block in place. More in Event priorities and canceling.

EventRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetEventRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javayou are hereListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

50@EventHandler51public void protectDiamondOre(BlockBreakEvent event) {52    if (event.getBlock().getType() == Material.DIAMOND_ORE) {53        event.setCancelled(true);54        event.getPlayer().sendRichMessage("<red>This ore is protected.");55    }56}

Remove drops. The block breaks but nothing drops. More in Events and listeners.

EventRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetEventRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javayou are hereListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

58@EventHandler59public void noDropsFromStone(BlockBreakEvent event) {60    if (event.getBlock().getType() == Material.STONE) {61        event.setDropItems(false);62    }63}

Stop a block from being placed. Cancel the place event to refuse it. More in Events and listeners.

EventRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetEventRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javayou are hereListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

65@EventHandler66public void blockTntPlacing(BlockPlaceEvent event) {67    if (event.getBlockPlaced().getType() == Material.TNT) {68        event.setCancelled(true);69    }70}

React to a right click with an item. getItem is null when the hand is empty, so check it first. More in Events and listeners.

EventRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetEventRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javayou are hereListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

72@EventHandler73public void rightClickWithStick(PlayerInteractEvent event) {74    if (event.getAction().isRightClick() && event.getItem() != null && event.getItem().getType() == Material.STICK) {75        event.getPlayer().sendRichMessage("<aqua>Whoosh!");76    }77}

Ignore tiny movements. The move event fires many times a second. This skips head turns and small steps. More in Events and listeners.

EventRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetEventRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javayou are hereListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

79@EventHandler80public void onlyWhenMovingToANewBlock(PlayerMoveEvent event) {81    if (!event.hasChangedBlock()) {82        return;83    }84    event.getPlayer().sendActionBar(Component.text("New block"));85}

Cancel one kind of damage. getCause says why the damage happens. More in Events and listeners.

EventRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetEventRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javayou are hereListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

87@EventHandler88public void stopFallDamageForPlayers(EntityDamageEvent event) {89    if (event.getEntity() instanceof Player && event.getCause() == EntityDamageEvent.DamageCause.FALL) {90        event.setCancelled(true);91    }92}

Change a number in an event. setDamage changes how much damage is dealt. More in Events and listeners.

EventRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetEventRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javayou are hereListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

94@EventHandler95public void doubleDamageFromPlayers(EntityDamageByEntityEvent event) {96    if (event.getDamager() instanceof Player) {97        event.setDamage(event.getDamage() * 2);98    }99}

Change the death message. Everyone sees this text instead of the default. More in Events and listeners.

EventRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetEventRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javayou are hereListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

101@EventHandler102public void changeDeathMessage(PlayerDeathEvent event) {103    event.deathMessage(Component.text(event.getEntity().getName() + " fell in battle.", NamedTextColor.DARK_RED));104}

Keep items when a player dies. Clear the drops too, or the player would have them twice. More in Events and listeners.

EventRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetEventRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javayou are hereListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

106@EventHandler107public void keepItemsOnDeath(PlayerDeathEvent event) {108    event.setKeepInventory(true);109    event.getDrops().clear();110}

Choose the respawn location. Overrides where the player appears. More in Events and listeners.

EventRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetEventRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javayou are hereListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

112@EventHandler113public void respawnAtSpawn(PlayerRespawnEvent event) {114    event.setRespawnLocation(event.getPlayer().getWorld().getSpawnLocation());115}

Read a chat message. Convert the message to plain text to compare it. Chat events run off the main thread. More in Project: Chat formatter and filter.

EventRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetEventRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javayou are hereListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

117@EventHandler118public void readChatMessage(AsyncChatEvent event) {119    String text = PlainTextComponentSerializer.plainText().serialize(event.message());120    if (text.equalsIgnoreCase("hello")) {121        event.getPlayer().sendRichMessage("<green>Hello to you too!");122    }123}

Change how chat looks. The renderer builds the line each viewer sees. More in Project: Chat formatter and filter.

EventRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetEventRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javayou are hereListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

125@EventHandler126public void restyleChat(AsyncChatEvent event) {127    event.renderer(ChatRenderer.viewerUnaware((source, sourceDisplayName, message) ->128            Component.text("[Chat] ", NamedTextColor.GRAY).append(sourceDisplayName).append(Component.text(": ")).append(message)));129}

Handler priority and canceled events. HIGH runs later than NORMAL, and ignoreCancelled skips events that another plugin already canceled. More in Event priorities and canceling.

EventRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetEventRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javayou are hereListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

131@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)132public void runLateAndSkipCanceledEvents(BlockBreakEvent event) {133    event.getPlayer().sendRichMessage("<gray>You broke a block.");134}

Watch without changing. MONITOR runs last and should only observe, never change the event. More in Event priorities and canceling.

EventRecipes.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheetsrcmainjavacomexamplerefpapercheatsheetEventRecipes.java

The package com.example.refpapercheatsheet is the folder path com/example/refpapercheatsheet inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet/
    • src/main/java/com/example/refpapercheatsheet/Package com.example.refpapercheatsheet
      • CommandRecipes.javaCommand (Brigadier tree)
      • ConfigRecipes.javaHelper class
      • DataRecipes.javaHelper class
      • EffectRecipes.javaHelper class
      • EntityRecipes.javaHelper class
      • EventRecipes.javayou are hereListener: reacts to events
      • InventoryRecipes.javaListener: reacts to events
      • ItemRecipes.javaHelper class
      • MessageRecipes.javaHelper class
      • PermissionRecipes.javaHelper class
      • PlayerRecipes.javaHelper class
      • SchedulerRecipes.javaHelper class
      • WorldRecipes.javaHelper class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

136@EventHandler(priority = EventPriority.MONITOR)137public void justWatchTheFinalResult(BlockBreakEvent event) {138    if (event.isCancelled()) {139        event.getPlayer().sendRichMessage("<gray>Another plugin canceled that.");140    }141}

Combining recipes

Real features are rarely a single recipe. They are a few recipes in one method. Here is the idea: when a player joins, show a title, play a sound, and give new players a gift. Three jobs, three recipes from this page.

Try it

Build a welcome kit from recipes

Write a listener that does these things when a player joins:

  1. Shows the title "Welcome!" with the player's name as the subtitle.
  2. Plays the level-up sound to that player.
  3. Gives a compass named "Guide Compass" to players who have never joined before, and only to them.

Use only recipes from this page, plus the event handler you know from Events and listeners.

Hint 1
Search the Messages group for a title recipe and the Effects group for the sound recipe. Both take a player.
Hint 2
The Players group has a recipe that checks whether someone has joined before. It is a method of Player itself.
Hint 3
To name the compass, use the "Name an item" recipe from the Items group. Put the item making in its own small method so the join handler stays easy to read.
Show the solution

The join handler calls the title and sound recipes, then uses hasPlayedBefore to decide about the gift. The item recipe lives in its own helper method.

WelcomeKitListener.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheet-exercisesrcmainjavacomexamplerefpapercheatsheetexerciseWelcomeKitListener.java

The package com.example.refpapercheatsheetexercise is the folder path com/example/refpapercheatsheetexercise inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet-exercise/
    • src/main/
      • java/com/example/refpapercheatsheetexercise/Package com.example.refpapercheatsheetexercise
        • WelcomeKitListener.javayou are hereListener: reacts to events
        • WelcomeKitPlugin.javaMain class: Paper starts here (named as main in plugin.yml)
      • resources/Files copied into the jar as they are
        • plugin.ymlTells Paper the plugin's name, version and main class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

1package com.example.refpapercheatsheetexercise;2 3import net.kyori.adventure.text.Component;4import net.kyori.adventure.text.format.NamedTextColor;5import net.kyori.adventure.text.format.TextDecoration;6import net.kyori.adventure.title.Title;7import org.bukkit.Material;8import org.bukkit.Sound;9import org.bukkit.entity.Player;10import org.bukkit.event.EventHandler;11import org.bukkit.event.Listener;12import org.bukkit.event.player.PlayerJoinEvent;13import org.bukkit.inventory.ItemStack;14 15public final class WelcomeKitListener implements Listener {16 17    @EventHandler18    public void onJoin(PlayerJoinEvent event) {19        Player player = event.getPlayer();20 21        player.showTitle(Title.title(22                Component.text("Welcome!", NamedTextColor.GOLD),23                Component.text(player.getName(), NamedTextColor.YELLOW)));24        player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1.0f, 1.0f);25 26        if (!player.hasPlayedBefore()) {27            player.getInventory().addItem(makeGuideCompass());28        }29    }30 31    private ItemStack makeGuideCompass() {32        ItemStack compass = ItemStack.of(Material.COMPASS);33        compass.editMeta(meta -> meta.displayName(Component.text("Guide Compass", NamedTextColor.AQUA)34                .decoration(TextDecoration.ITALIC, false)));35        return compass;36    }37}
  1. The title recipe: the first component is the big text, the second is the subtitle.
  2. The sound recipe, played only to this player.
  3. True for returning players. The exclamation mark flips it, so the gift is only for first-time players.
  4. A helper method keeps the handler short. Its body is the "Name an item" recipe.

The main class only has to register the listener, like in every plugin:

WelcomeKitPlugin.javaCompiles on Paper 26.3Compile Lab
Where this file livesref-paper-cheatsheet-exercisesrcmainjavacomexamplerefpapercheatsheetexerciseWelcomeKitPlugin.java

The package com.example.refpapercheatsheetexercise is the folder path com/example/refpapercheatsheetexercise inside src/main/java: every dot in the package name is one folder. IntelliJ creates these folders for you when you make a new package.

  • ref-paper-cheatsheet-exercise/
    • src/main/
      • java/com/example/refpapercheatsheetexercise/Package com.example.refpapercheatsheetexercise
        • WelcomeKitListener.javaListener: reacts to events
        • WelcomeKitPlugin.javayou are hereMain class: Paper starts here (named as main in plugin.yml)
      • resources/Files copied into the jar as they are
        • plugin.ymlTells Paper the plugin's name, version and main class
    • build.gradle.ktsThe build recipe: Paper 26.3 API, Java 25, how the jar is made
    • gradle.propertiesVersion numbers used by the build
    • gradlew.batRuns Gradle on Windows without installing it
    • settings.gradle.ktsThe project's name

Gray files come with the project template; you rarely edit them. Open the whole project in the Compile Lab, or download it from the project page.

1package com.example.refpapercheatsheetexercise;2 3import org.bukkit.plugin.java.JavaPlugin;4 5public final class WelcomeKitPlugin extends JavaPlugin {6 7    @Override8    public void onEnable() {9        getServer().getPluginManager().registerEvents(new WelcomeKitListener(), this);10    }11}

Recap

  • Each recipe is a method: the name is the job, the parentheses are what you must bring, and the lines inside are what you copy.
  • Common variable names are player, sender, plugin, location, item and entity.
  • 20 ticks are one second. Delays and durations in Paper use ticks.
  • Methods that find things can return null. Check before you use the result.
  • Combine small recipes in one handler to build a feature, and move each job into a helper method when it grows.

Quick quiz

  1. You want a message to appear after three seconds. How many ticks do you pass as the delay?

  2. Why does the recipe for moving a location call clone() before add()?

  3. Where do you register a Brigadier or BasicCommand in the modern way?

  4. Why do the item recipes switch off the italic decoration for names and lore?

  5. What does Placeholder.unparsed protect you from?

Next steps