mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-03 22:15:45 +00:00
Make Carbon a Paper plugin and use paper-trail instead of PaperLib
This commit is contained in:
5 files changed
+108
-63
No files matched your search
+22
-7
@@ -1,3 +1,5 @@
|
||||
import net.minecrell.pluginyml.bukkit.BukkitPluginDescription
|
||||
|
||||
plugins {
|
||||
id("carbon.shadow-platform")
|
||||
id("net.minecrell.plugin-yml.bukkit")
|
||||
@@ -10,7 +12,7 @@ dependencies {
|
||||
|
||||
// Server
|
||||
compileOnly(libs.paperApi)
|
||||
implementation(libs.paperLib)
|
||||
implementation(libs.paperTrail)
|
||||
|
||||
// Commands
|
||||
implementation(libs.cloudPaper)
|
||||
@@ -30,7 +32,7 @@ carbonShadowPlatform {
|
||||
|
||||
tasks {
|
||||
shadowJar {
|
||||
relocateDependency("io.papermc.lib")
|
||||
relocateDependency("io.papermc.papertrail")
|
||||
relocateDependency("io.leangen.geantyref")
|
||||
}
|
||||
runServer {
|
||||
@@ -38,8 +40,10 @@ tasks {
|
||||
}
|
||||
}
|
||||
|
||||
// Generates plugin.yml automatically
|
||||
bukkit {
|
||||
plugins.apply(PaperPlugin::class)
|
||||
|
||||
val paper = extensions["paper"] as BukkitPluginDescription
|
||||
paper.apply {
|
||||
name = rootProject.name
|
||||
version = project.version as String
|
||||
main = "net.draycia.carbon.paper.CarbonPaperBootstrap"
|
||||
@@ -50,9 +54,20 @@ bukkit {
|
||||
website = GITHUB_REPO_URL
|
||||
}
|
||||
|
||||
bukkit {
|
||||
name = rootProject.name
|
||||
version = project.version as String
|
||||
main = "net.draycia.carbon.libs.io.papermc.papertrail.RequiresPaperPlugins"
|
||||
apiVersion = "1.19"
|
||||
author = "Draycia"
|
||||
website = GITHUB_REPO_URL
|
||||
}
|
||||
|
||||
carbonPermission.permissions.get().forEach {
|
||||
bukkit.permissions.register(it.string) {
|
||||
description = it.description
|
||||
childrenMap = it.children
|
||||
setOf(bukkit, paper).forEach { ext ->
|
||||
ext.permissions.register(it.string) {
|
||||
description = it.description
|
||||
childrenMap = it.children
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,71 +20,26 @@
|
||||
package net.draycia.carbon.paper;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import java.util.logging.Level;
|
||||
import net.draycia.carbon.api.CarbonChatProvider;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public final class CarbonPaperBootstrap extends JavaPlugin {
|
||||
|
||||
private @MonotonicNonNull CarbonChatPaper carbonChat;
|
||||
private @MonotonicNonNull UnsupportedPlatformException unsupportedPlatform;
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
this.unsupportedPlatform = this.checkPlatform();
|
||||
if (this.unsupportedPlatform != null) {
|
||||
this.getLogger().log(Level.SEVERE, this.unsupportedPlatform.getMessage(), this.unsupportedPlatform);
|
||||
return;
|
||||
}
|
||||
|
||||
this.carbonChat = Guice.createInjector(new CarbonChatPaperModule(this))
|
||||
.getInstance(CarbonChatPaper.class);
|
||||
CarbonChatProvider.register(this.carbonChat);
|
||||
}
|
||||
|
||||
// null = success
|
||||
private @Nullable UnsupportedPlatformException checkPlatform() {
|
||||
if (PaperLib.isPaper()) {
|
||||
return this.checkPaperVersion();
|
||||
}
|
||||
this.severe("*");
|
||||
this.severe("* CarbonChat makes extensive use of APIs added by Paper.");
|
||||
this.severe("* For this reason, CarbonChat requires Paper and is not");
|
||||
this.severe("* compatible with Spigot or CraftBukkit servers.");
|
||||
this.severe("* Upgrade your server to Paper in order to use CarbonChat.");
|
||||
this.severe("*");
|
||||
PaperLib.suggestPaper(this, Level.SEVERE);
|
||||
return new UnsupportedPlatformException("Not Paper or a Paper-based server runtime");
|
||||
}
|
||||
|
||||
private @Nullable UnsupportedPlatformException checkPaperVersion() {
|
||||
// assume major version 1
|
||||
final int minor = PaperLib.getMinecraftVersion();
|
||||
final int patch = PaperLib.getMinecraftPatchVersion();
|
||||
if (minor != 19 || patch < 3) {
|
||||
return new UnsupportedPlatformException("Wrong Minecraft version (" + Bukkit.getMinecraftVersion() + "), this build of Carbon is for 1.19.3 and newer");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void severe(final String message) {
|
||||
this.getLogger().log(Level.SEVERE, message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
if (this.unsupportedPlatform != null) {
|
||||
this.getLogger().log(Level.SEVERE, this.unsupportedPlatform.getMessage(), this.unsupportedPlatform);
|
||||
this.getServer().getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
if (this.carbonChat != null) {
|
||||
this.carbonChat.onEnable();
|
||||
}
|
||||
@@ -97,10 +52,4 @@ public final class CarbonPaperBootstrap extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
private static final class UnsupportedPlatformException extends RuntimeException {
|
||||
UnsupportedPlatformException(final String reason) {
|
||||
super("Your server does not support this build of Carbon: " + reason);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user