• Stars
    star
    248
  • Rank 163,560 (Top 4 %)
  • Language
    Java
  • License
    MIT License
  • Created about 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Plugin Library for interfacing with Paper Specific API's with graceful fallback that maintains Spigot Compatibility, such as Async Chunk Loading.

PaperLib

PaperLib is a plugin library for interfacing with Paper specific APIs (such as async chunk loading), with graceful fallbacks maintaining compatibility with both the Bukkit and Spigot API's.

API

All API calls can be found as static util methods in the PaperLib class.

getChunkAtAsync

public class PaperLib {
  public static CompletableFuture<Chunk> getChunkAtAsync(Location loc);
  public static CompletableFuture<Chunk> getChunkAtAsync(Location loc, boolean gen);
  public static CompletableFuture<Chunk> getChunkAtAsync(World world, int x, int z);
  public static CompletableFuture<Chunk> getChunkAtAsync(World world, int x, int z, boolean gen); 
}

On Paper, loads (or generates on 1.13.1+) the chunk asynchronously if it is not loaded yet, then completes the returned future. Chunk will load synchronous on Spigot.

teleportAsync

public class PaperLib {
  public static CompletableFuture<Boolean> teleportAsync(Entity entity, Location location);
  public static CompletableFuture<Boolean> teleportAsync(Entity entity, Location location, TeleportCause cause);
}

Uses the Async Chunk Load API, and if possible, loads/generates the chunk asynchronously before teleporting. Will load synchronous on Spigot.

On 1.15+, this has an added improvement of also loading neighbor chunks to avoid collision checks loading chunks too.

isChunkGenerated

public class PaperLib {
  public static boolean isChunkGenerated(Location loc);
  public static boolean isChunkGenerated(World world, int x, int z);
}

Returns whether or not the chunk is generated. Only Supported in Paper 1.12+ and Spigot 1.13.1+

getBlockState

public class PaperLib {
  public static BlockStateSnapshotResult getBlockState(Block block, boolean useSnapshot);
}

Allows you to optionally avoid taking a snapshot of a TileEntity in a BlockState. Versions prior to 1.12 will always be false for the snapshot. In versions 1.12+ on Spigot, the snapshot will always be true. In Paper 1.12+, the snapshot will be whether or not you requested one in the API call.

suggestPaper

public class PaperLib {
  public static void suggestPaper(Plugin plugin);
}

Helps inform users who run your plugin on Spigot that your plugin will behave better on Paper! Calling this method will print out an informational message in the logs that they should switch to Paper, and will help users discover our software. We would appreciate it if you call this method, but it is optional.

Example Plugin

public class MyPlugin extends JavaPlugin {
    public void onEnable() {
        PaperLib.suggestPaper(this);
    }
    
    public void doSomething(Entity entity, Location location) {
        PaperLib.teleportAsync(entity, location).thenAccept(result -> {
            if (result) {
                player.sendMessage("Teleported!");
            } else {
                player.sendMessage("Something went wrong!");
            }
        });
    }
}

Build Script Setup

Add the Paper repository and the PaperLib dependency, then shade and relocate it to your own package. Relocation helps avoid version conflicts with other plugins using PaperLib.

Gradle

Repo:

repositories {
    maven {
        name "papermc"
        url "https://papermc.io/repo/repository/maven-public/"
    }
}

Dependency:

dependencies {
    implementation "io.papermc:paperlib:1.0.7"
}

Shadow Jar and Relocate (Groovy Syntax):

plugins {
  id "com.github.johnrengelman.shadow" version "7.1.0"
  // Make sure to always use the latest version (https://plugins.gradle.org/plugin/com.github.johnrengelman.shadow)
}
shadowJar {
   relocate "io.papermc.lib", "[YOUR PLUGIN PACKAGE].paperlib"
}

Maven

Repo:

<repositories>
    <repository>
        <id>papermc</id>
        <url>https://papermc.io/repo/repository/maven-public/</url>
    </repository>
</repositories>

Dependency:

<dependencies>
    <dependency>
        <groupId>io.papermc</groupId>
        <artifactId>paperlib</artifactId>
        <version>1.0.7</version>
        <scope>compile</scope>
     </dependency>
 </dependencies>

Shade & Relocate:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>3.2.4</version> <!-- Make sure to always use the latest version (https://maven.apache.org/plugins/maven-shade-plugin/) -->
            <configuration>
                <dependencyReducedPomLocation>${project.build.directory}/dependency-reduced-pom.xml</dependencyReducedPomLocation>
                <relocations>
                    <relocation>
                        <pattern>io.papermc.lib</pattern>
                        <shadedPattern>[YOUR PLUGIN PACKAGE].paperlib</shadedPattern> <!-- Replace this -->
                    </relocation>
                </relocations>
            </configuration>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

Compiling

PaperLib is compiled using Gradle:

./gradlew build

License

PaperLib is licensed under the MIT license

More Repositories

1

Paper

The most widely used, high performance Minecraft server that aims to fix gameplay and mechanics inconsistencies
Java
7,858
star
2

Folia

Fork of Paper which adds regionised multithreading to the dedicated server.
Batchfile
3,387
star
3

Velocity

The modern, next-generation Minecraft server proxy.
Java
1,379
star
4

Starlight

Rewrites the light engine to fix lighting performance and lighting errors
Java
1,268
star
5

Waterfall

BungeeCord fork that aims to improve performance and stability.
Shell
721
star
6

paperweight

Gradle build system plugin for Paper and Paper forks
Kotlin
181
star
7

Travertine

Waterfall with 1.7 support
Shell
137
star
8

papermc.io

The PaperMC Website
SCSS
125
star
9

Paperclip

Bootstrap utility and launcher for the Paper Minecraft server
Java
113
star
10

paperweight-test-plugin

test plugin for paperweight-userdev
Java
71
star
11

DataConverter

Rewrite of the dataconverter system for performance.
Java
56
star
12

paperd

Wrapper which allows running the PaperMC Minecraft server as a proper daemon
Rust
53
star
13

website

The PaperMC website
TypeScript
48
star
14

PaperDocs

Documentation for all projects under the PaperMC umbrella
Python
47
star
15

paperweight-examples

Kotlin
45
star
16

Paper-1.7

Shell
45
star
17

mache

Compilable patches for the decompiled Minecraft server
32
star
18

docs

Documentation for all projects under the PaperMC umbrella.
TypeScript
29
star
19

bibliothek

The PaperMC downloads API.
Java
25
star
20

SectorTool

Java
22
star
21

asm-utils

Library for redirecting Java bytecode & reflection calls using ASM
Java
8
star
22

PaperTestServer

Skeleton for test server setup to test Paper
5
star
23

velocitypowered.com

The revamped Velocity website built on Gatsby
JavaScript
5
star
24

item-converter

REST API for upgrading Minecraft commands and command arguments from 1.20.4 to 1.20.6
Java
4
star
25

update-projects-action

TypeScript
4
star
26

.github

2
star
27

Parchment

PHP
2
star
28

paper-trail

Helpers for notifying users of legacy server software that a plugin requires Paper
Java
2
star
29

PaperclipMavenPlugin

Generates the patch and settings file for Paperclip
Java
2
star
30

deprecated-bungeechat

Kotlin
2
star
31

patched-spigot-fernflower

Kotlin
2
star
32

multi-version-catalog

Combines multiple toml files into a single version catalog
Kotlin
2
star
33

docs-previews

Automatically generated previews for pull requests against PaperMC/docs
HTML
1
star
34

restamp

Apply access transformers to closed/forked source files
Java
1
star