Make Carbon a Paper plugin and use paper-trail instead of PaperLib

This commit is contained in:
Jason Penilla committed 2023-03-26 12:24:48 -07:00
1 parent 29d4744254
commit ca04c4dc78
5 files changed
+108 -63

No files matched your search

@@ -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);
}
}
}