mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-02 06:28:54 +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
@@ -13,6 +13,7 @@ dependencies {
|
||||
implementation(libs.indraCommon)
|
||||
implementation(libs.indraLicenseHeader)
|
||||
implementation(libs.licenser)
|
||||
implementation(libs.pluginYml)
|
||||
implementation("org.spongepowered:configurate-yaml:4.0.0")
|
||||
|
||||
// https://github.com/gradle/gradle/issues/15383#issuecomment-779893192
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2017 Minecrell <https://github.com/Minecrell>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
import net.minecrell.pluginyml.InvalidPluginDescriptionException
|
||||
import net.minecrell.pluginyml.PlatformPlugin
|
||||
import net.minecrell.pluginyml.bukkit.BukkitPluginDescription
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.artifacts.result.ResolvedComponentResult
|
||||
import org.gradle.api.artifacts.result.ResolvedDependencyResult
|
||||
|
||||
class PaperPlugin : PlatformPlugin<BukkitPluginDescription>("Paper", "paper-plugin.yml") {
|
||||
|
||||
companion object {
|
||||
@JvmStatic private val VALID_NAME = Regex("^[A-Za-z0-9 _.-]+$")
|
||||
}
|
||||
|
||||
override fun createExtension(project: Project) = BukkitPluginDescription(project)
|
||||
|
||||
override fun setDefaults(project: Project, description: BukkitPluginDescription) {
|
||||
description.name = description.name ?: project.name
|
||||
description.version = description.version ?: project.version.toString()
|
||||
description.description = description.description ?: project.description
|
||||
description.website = description.website ?: project.findProperty("url")?.toString()
|
||||
description.author = description.author ?: project.findProperty("author")?.toString()
|
||||
}
|
||||
|
||||
override fun setLibraries(libraries: ResolvedComponentResult?, description: BukkitPluginDescription) {
|
||||
val resolved = libraries?.let {
|
||||
it.dependencies.map { d -> (d as? ResolvedDependencyResult)?.selected?.moduleVersion?.toString() ?: error("No moduleVersion for $d") }
|
||||
}
|
||||
description.libraries = ((description.libraries ?: listOf()) + (resolved ?: listOf())).distinct()
|
||||
}
|
||||
|
||||
override fun validate(description: BukkitPluginDescription) {
|
||||
val name = description.name ?: throw InvalidPluginDescriptionException("Plugin name is not set")
|
||||
if (!VALID_NAME.matches(name)) throw InvalidPluginDescriptionException("Invalid plugin name: should match $VALID_NAME")
|
||||
|
||||
if (description.version.isNullOrEmpty()) throw InvalidPluginDescriptionException("Plugin version is not set")
|
||||
|
||||
val main = description.main ?: throw InvalidPluginDescriptionException("Main class is not defined")
|
||||
if (main.isEmpty()) throw InvalidPluginDescriptionException("Main class cannot be empty")
|
||||
if (main.startsWith("org.bukkit.")) throw InvalidPluginDescriptionException("Main may not be within the org.bukkit namespace")
|
||||
|
||||
for (command in description.commands) {
|
||||
if (command.name.contains(':')) throw InvalidPluginDescriptionException("Command '${command.name}' cannot contain ':'")
|
||||
command.aliases?.forEach { alias ->
|
||||
if (alias.contains(':')) throw InvalidPluginDescriptionException("Alias '$alias' of '${command.name}' cannot contain ':'")
|
||||
}
|
||||
}
|
||||
|
||||
if (description.provides?.all(VALID_NAME::matches) == false) {
|
||||
throw InvalidPluginDescriptionException("Invalid plugin provides name: all should match $VALID_NAME")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,7 +5,6 @@ metadata:
|
||||
|
||||
plugins:
|
||||
net.kyori.blossom: 1.3.0
|
||||
net.minecrell.plugin-yml.bukkit: 0.5.1
|
||||
org.spongepowered.gradle.plugin: 2.1.1
|
||||
xyz.jpenilla.run-paper: 2.0.1
|
||||
|
||||
@@ -24,7 +23,7 @@ versions:
|
||||
guava: 30.1-jre
|
||||
bstats: 3.0.0
|
||||
paperApi: 1.19.4-R0.1-SNAPSHOT
|
||||
paperLib: 1.0.8-SNAPSHOT
|
||||
paperTrail: 0.0.1-SNAPSHOT
|
||||
kyoriEventApi: 5.0.0-SNAPSHOT
|
||||
kyoriRegistry: 1.0.0-SNAPSHOT
|
||||
kyoriMoonshine: 2.0.4
|
||||
@@ -51,6 +50,7 @@ versions:
|
||||
postgresql: 42.3.1
|
||||
rabbitmq: 5.13.1
|
||||
nats: 2.12.0
|
||||
pluginYml: 0.5.3
|
||||
|
||||
dependencies:
|
||||
adventureBom:
|
||||
@@ -272,10 +272,10 @@ dependencies:
|
||||
group: io.papermc.paper
|
||||
name: paper-api
|
||||
version: { ref: paperApi }
|
||||
paperLib:
|
||||
paperTrail:
|
||||
group: io.papermc
|
||||
name: paperlib
|
||||
version: { ref: paperLib }
|
||||
name: paper-trail
|
||||
version: { ref: paperTrail }
|
||||
|
||||
velocityApi:
|
||||
group: com.velocitypowered
|
||||
@@ -308,6 +308,10 @@ dependencies:
|
||||
group: org.cadixdev.licenser
|
||||
name: org.cadixdev.licenser.gradle.plugin
|
||||
version: { ref: licenser }
|
||||
pluginYml:
|
||||
group: net.minecrell
|
||||
name: plugin-yml
|
||||
version: { ref: pluginYml }
|
||||
|
||||
luckPermsApi:
|
||||
group: net.luckperms
|
||||
|
||||
+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