[FEAT] Paper Support
This commit is contained in:
83
patches/1.19.2/Paper/build.gradle.patch
Normal file
83
patches/1.19.2/Paper/build.gradle.patch
Normal file
@@ -0,0 +1,83 @@
|
||||
--- a/Paper/build.gradle
|
||||
+++ /dev/null
|
||||
@@ -1,80 +1,0 @@
|
||||
-plugins {
|
||||
- id "io.papermc.paperweight.userdev" version "1.7.3"
|
||||
- id "xyz.jpenilla.run-paper" version "2.3.0"
|
||||
-}
|
||||
-
|
||||
-archivesBaseName = "${mod_name.replace(" ", "")}-Paper-${minecraft_version}"
|
||||
-
|
||||
-origami {
|
||||
- excludedPackages = ["com.hypherionmc.craterlib.client", "com.hypherionmc.craterlib.mixin", "com.hypherionmc.craterlib.nojang.client", "com.hypherionmc.craterlib.core.rpcsdk", "com.hypherionmc.craterlib.nojang.realmsclient"]
|
||||
- excludedResources = ["pack.mcmeta", "craterlib.mixins.json"]
|
||||
-}
|
||||
-
|
||||
-dependencies {
|
||||
- paperweight.paperDevBundle("${minecraft_version}-R0.1-SNAPSHOT")
|
||||
-
|
||||
- // Do not edit or remove
|
||||
- implementation project(":Common")
|
||||
-}
|
||||
-
|
||||
-shadowJar {
|
||||
- from sourceSets.main.output
|
||||
- configurations = [project.configurations.shade]
|
||||
-
|
||||
- dependencies {
|
||||
- exclude(dependency('com.google.code.gson:.*'))
|
||||
- exclude(dependency('net.kyori:.*'))
|
||||
-
|
||||
- relocate 'me.hypherionmc.moonconfig', 'shadow.hypherionmc.moonconfig'
|
||||
- relocate 'me.hypherionmc.mcdiscordformatter', 'shadow.hypherionmc.mcdiscordformatter'
|
||||
-
|
||||
- exclude("linux-x86-64/**", "win32-x86/**", "win32-x86-64/**", "darwin/**")
|
||||
- }
|
||||
-
|
||||
- setArchiveClassifier(null)
|
||||
- mergeServiceFiles()
|
||||
-}
|
||||
-
|
||||
-jar {
|
||||
- archiveClassifier.set "slim"
|
||||
-}
|
||||
-
|
||||
-tasks {
|
||||
- runServer {
|
||||
- minecraftVersion(project.minecraft_version)
|
||||
- }
|
||||
-}
|
||||
-
|
||||
-processResources {
|
||||
- def buildProps = project.properties.clone()
|
||||
-
|
||||
- filesMatching(['paper-plugin.yml']) {
|
||||
- expand buildProps
|
||||
- }
|
||||
-}
|
||||
-
|
||||
-compileTestJava.enabled = false
|
||||
-
|
||||
-tasks.assemble {
|
||||
- dependsOn(tasks.reobfJar)
|
||||
-}
|
||||
-
|
||||
-publisher {
|
||||
- apiKeys {
|
||||
- modrinth(System.getenv("MODRINTH_TOKEN"))
|
||||
- nightbloom(System.getenv("PLATFORM_KEY"))
|
||||
- }
|
||||
-
|
||||
- setModrinthID(modrinth_id)
|
||||
- setNightbloomID("craterlib")
|
||||
- setVersionType("alpha")
|
||||
- setChangelog(rootProject.file("changelog.md"))
|
||||
- setProjectVersion("${minecraft_version}-${project.version}")
|
||||
- setDisplayName("[Paper 1.21.3] CraterLib - ${project.version}")
|
||||
- setGameVersions("1.21.3")
|
||||
- setLoaders("paper")
|
||||
- setArtifact(reobfJar.outputJar)
|
||||
-}
|
||||
-
|
||||
-publishModrinth.dependsOn(reobfJar)
|
||||
-publishNightbloom.dependsOn(reobfJar)
|
@@ -0,0 +1,22 @@
|
||||
--- a/Paper/src/main/java/com/hypherionmc/craterlib/common/PaperCommonHelper.java
|
||||
+++ /dev/null
|
||||
@@ -1,19 +1,0 @@
|
||||
-package com.hypherionmc.craterlib.common;
|
||||
-
|
||||
-import com.hypherionmc.craterlib.core.platform.CommonPlatform;
|
||||
-import com.hypherionmc.craterlib.nojang.server.BridgedMinecraftServer;
|
||||
-import net.minecraft.server.MinecraftServer;
|
||||
-
|
||||
-/**
|
||||
- * @author HypherionSA
|
||||
- */
|
||||
-public class PaperCommonHelper implements CommonPlatform {
|
||||
-
|
||||
- public PaperCommonHelper() {
|
||||
- }
|
||||
-
|
||||
- @Override
|
||||
- public BridgedMinecraftServer getMCServer() {
|
||||
- return BridgedMinecraftServer.of(MinecraftServer.getServer());
|
||||
- }
|
||||
-}
|
@@ -0,0 +1,81 @@
|
||||
--- a/Paper/src/main/java/com/hypherionmc/craterlib/common/PaperCompatHelper.java
|
||||
+++ /dev/null
|
||||
@@ -1,78 +1,0 @@
|
||||
-package com.hypherionmc.craterlib.common;
|
||||
-
|
||||
-import com.hypherionmc.craterlib.core.platform.CompatUtils;
|
||||
-import com.hypherionmc.craterlib.core.platform.ModloaderEnvironment;
|
||||
-import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
||||
-import com.hypherionmc.craterlib.utils.ChatUtils;
|
||||
-import org.bukkit.Bukkit;
|
||||
-import org.bukkit.entity.Player;
|
||||
-import org.bukkit.metadata.MetadataValue;
|
||||
-import org.bukkit.plugin.Plugin;
|
||||
-
|
||||
-import java.lang.reflect.Method;
|
||||
-
|
||||
-public class PaperCompatHelper implements CompatUtils {
|
||||
-
|
||||
- @Override
|
||||
- public boolean isPlayerActive(BridgedPlayer player) {
|
||||
- // Essentials Vanish
|
||||
- if (ModloaderEnvironment.INSTANCE.isModLoaded("Essentials")) {
|
||||
- return !isEssentialsVanished(player);
|
||||
- }
|
||||
-
|
||||
- // PhantomAdmin Vanish
|
||||
- if (ModloaderEnvironment.INSTANCE.isModLoaded("PhantomAdmin"))
|
||||
- return !isPhantomVanished(player);
|
||||
-
|
||||
- // Other vanish mods
|
||||
- try {
|
||||
- Player p = (Player) player.toMojangServerPlayer();
|
||||
- for (MetadataValue meta : p.getMetadata("vanished")) {
|
||||
- if (meta.asBoolean()) return true;
|
||||
- }
|
||||
- } catch (Exception ignored) {}
|
||||
-
|
||||
- return true;
|
||||
- }
|
||||
-
|
||||
- @Override
|
||||
- public String getSkinUUID(BridgedPlayer player) {
|
||||
- return player.getStringUUID();
|
||||
- }
|
||||
-
|
||||
- private boolean isEssentialsVanished(BridgedPlayer player) {
|
||||
- try {
|
||||
- Plugin p = Bukkit.getPluginManager().getPlugin("Essentials");
|
||||
- if (p == null)
|
||||
- return false;
|
||||
-
|
||||
- Method getUser = p.getClass().getMethod("getUser", String.class);
|
||||
- Object essentialsPlayer = getUser.invoke(p, ChatUtils.resolve(player.getName(), false));
|
||||
-
|
||||
- if (essentialsPlayer != null) {
|
||||
- Method isVanished = essentialsPlayer.getClass().getMethod("isVanished");
|
||||
- return (boolean) isVanished.invoke(essentialsPlayer);
|
||||
- }
|
||||
- } catch (Exception ignored) {}
|
||||
-
|
||||
- return false;
|
||||
- }
|
||||
-
|
||||
- private boolean isPhantomVanished(BridgedPlayer player) {
|
||||
- try {
|
||||
- Plugin p = Bukkit.getPluginManager().getPlugin("PhantomAdmin");
|
||||
- if (p == null)
|
||||
- return false;
|
||||
-
|
||||
- Method isInvisible = p.getClass().getDeclaredMethod("isInvisible", Player.class);
|
||||
- isInvisible.setAccessible(true);
|
||||
-
|
||||
- return (boolean) isInvisible.invoke(p, (Player) player.toMojangServerPlayer());
|
||||
- } catch (Exception ignored) {
|
||||
- ignored.printStackTrace();
|
||||
- }
|
||||
-
|
||||
- return false;
|
||||
- }
|
||||
-
|
||||
-}
|
@@ -0,0 +1,73 @@
|
||||
--- a/Paper/src/main/java/com/hypherionmc/craterlib/common/PaperLoaderHelper.java
|
||||
+++ /dev/null
|
||||
@@ -1,70 +1,0 @@
|
||||
-package com.hypherionmc.craterlib.common;
|
||||
-
|
||||
-import com.hypherionmc.craterlib.core.platform.Environment;
|
||||
-import com.hypherionmc.craterlib.core.platform.LoaderType;
|
||||
-import com.hypherionmc.craterlib.core.platform.ModloaderEnvironment;
|
||||
-import net.minecraft.SharedConstants;
|
||||
-import org.bukkit.Bukkit;
|
||||
-import org.bukkit.plugin.Plugin;
|
||||
-
|
||||
-import java.io.File;
|
||||
-import java.util.Arrays;
|
||||
-
|
||||
-/**
|
||||
- * @author HypherionSA
|
||||
- */
|
||||
-public class PaperLoaderHelper implements ModloaderEnvironment {
|
||||
-
|
||||
- public PaperLoaderHelper() {
|
||||
- }
|
||||
-
|
||||
- @Override
|
||||
- public boolean isFabric() {
|
||||
- return false;
|
||||
- }
|
||||
-
|
||||
- @Override
|
||||
- public LoaderType getLoaderType() {
|
||||
- return LoaderType.PAPER;
|
||||
- }
|
||||
-
|
||||
- @Override
|
||||
- public String getGameVersion() {
|
||||
- return SharedConstants.getCurrentVersion().getName();
|
||||
- }
|
||||
-
|
||||
- @Override
|
||||
- public File getGameFolder() {
|
||||
- return new File(".");
|
||||
- }
|
||||
-
|
||||
- @Override
|
||||
- public File getConfigFolder() {
|
||||
- return new File("config");
|
||||
- }
|
||||
-
|
||||
- @Override
|
||||
- public File getModsFolder() {
|
||||
- return Bukkit.getPluginsFolder();
|
||||
- }
|
||||
-
|
||||
- @Override
|
||||
- public Environment getEnvironment() {
|
||||
- return Environment.SERVER;
|
||||
- }
|
||||
-
|
||||
- @Override
|
||||
- public boolean isModLoaded(String modid) {
|
||||
- return Bukkit.getPluginManager().isPluginEnabled(modid);
|
||||
- }
|
||||
-
|
||||
- @Override
|
||||
- public boolean isDevEnv() {
|
||||
- return false;
|
||||
- }
|
||||
-
|
||||
- @Override
|
||||
- public int getModCount() {
|
||||
- return (int) Arrays.stream(Bukkit.getPluginManager().getPlugins()).filter(Plugin::isEnabled).count();
|
||||
- }
|
||||
-}
|
@@ -0,0 +1,16 @@
|
||||
--- a/Paper/src/main/java/com/hypherionmc/craterlib/paper/CraterLibBootstrap.java
|
||||
+++ /dev/null
|
||||
@@ -1,13 +1,0 @@
|
||||
-package com.hypherionmc.craterlib.paper;
|
||||
-
|
||||
-import com.hypherionmc.craterlib.CraterConstants;
|
||||
-import io.papermc.paper.plugin.bootstrap.BootstrapContext;
|
||||
-import io.papermc.paper.plugin.bootstrap.PluginBootstrap;
|
||||
-
|
||||
-public class CraterLibBootstrap implements PluginBootstrap {
|
||||
-
|
||||
- @Override
|
||||
- public void bootstrap(BootstrapContext bootstrapContext) {
|
||||
- CraterConstants.LOG.info("Hello from CraterLib");
|
||||
- }
|
||||
-}
|
@@ -0,0 +1,34 @@
|
||||
--- a/Paper/src/main/java/com/hypherionmc/craterlib/paper/CraterLibPlugin.java
|
||||
+++ /dev/null
|
||||
@@ -1,31 +1,0 @@
|
||||
-package com.hypherionmc.craterlib.paper;
|
||||
-
|
||||
-import com.hypherionmc.craterlib.api.events.server.CraterRegisterCommandEvent;
|
||||
-import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
||||
-import com.hypherionmc.craterlib.core.platform.CommonPlatform;
|
||||
-import com.hypherionmc.craterlib.utils.InternalServiceUtil;
|
||||
-import net.minecraft.server.MinecraftServer;
|
||||
-import org.bukkit.plugin.java.JavaPlugin;
|
||||
-
|
||||
-public class CraterLibPlugin extends JavaPlugin {
|
||||
-
|
||||
- private final PaperEventListener listener = new PaperEventListener();
|
||||
-
|
||||
- public CraterLibPlugin() {
|
||||
- super();
|
||||
- InternalServiceUtil.loader = getClassLoader();
|
||||
- }
|
||||
-
|
||||
- @Override
|
||||
- public void onLoad() {
|
||||
- listener.onServerStarting(MinecraftServer.getServer());
|
||||
- }
|
||||
-
|
||||
- @Override
|
||||
- public void onEnable() {
|
||||
- CraterEventBus.INSTANCE.postEvent(new CraterRegisterCommandEvent(MinecraftServer.getServer().createCommandSourceStack().dispatcher()));
|
||||
- getServer().getPluginManager().registerEvents(listener, this);
|
||||
- getServer().getScheduler().scheduleSyncDelayedTask(this, listener::onServerStarted);
|
||||
- }
|
||||
-
|
||||
-}
|
@@ -0,0 +1,116 @@
|
||||
--- a/Paper/src/main/java/com/hypherionmc/craterlib/paper/PaperEventListener.java
|
||||
+++ /dev/null
|
||||
@@ -1,113 +1,0 @@
|
||||
-package com.hypherionmc.craterlib.paper;
|
||||
-
|
||||
-import com.hypherionmc.craterlib.api.events.common.CraterPlayerDeathEvent;
|
||||
-import com.hypherionmc.craterlib.api.events.server.PlayerPreLoginEvent;
|
||||
-import com.hypherionmc.craterlib.api.events.server.*;
|
||||
-import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
||||
-import com.hypherionmc.craterlib.nojang.advancements.BridgedAdvancement;
|
||||
-import com.hypherionmc.craterlib.nojang.authlib.BridgedGameProfile;
|
||||
-import com.hypherionmc.craterlib.nojang.server.BridgedMinecraftServer;
|
||||
-import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
||||
-import com.mojang.authlib.GameProfile;
|
||||
-import com.mojang.brigadier.CommandDispatcher;
|
||||
-import com.mojang.brigadier.ParseResults;
|
||||
-import io.papermc.paper.event.player.AsyncChatEvent;
|
||||
-import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
-import net.minecraft.commands.CommandSourceStack;
|
||||
-import net.minecraft.server.MinecraftServer;
|
||||
-import org.bukkit.command.ConsoleCommandSender;
|
||||
-import org.bukkit.craftbukkit.advancement.CraftAdvancement;
|
||||
-import org.bukkit.craftbukkit.damage.CraftDamageSource;
|
||||
-import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||
-import org.bukkit.event.EventHandler;
|
||||
-import org.bukkit.event.EventPriority;
|
||||
-import org.bukkit.event.Listener;
|
||||
-import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
-import org.bukkit.event.player.*;
|
||||
-import org.bukkit.event.server.ServerCommandEvent;
|
||||
-
|
||||
-public class PaperEventListener implements Listener {
|
||||
-
|
||||
- @EventHandler(priority = EventPriority.HIGHEST)
|
||||
- public void onPlayerDeath(PlayerDeathEvent event) {
|
||||
- CraterEventBus.INSTANCE.postEvent(
|
||||
- new CraterPlayerDeathEvent(BridgedPlayer.of(((CraftPlayer) event.getPlayer()).getHandle()), ((CraftDamageSource) event.getDamageSource()).getHandle())
|
||||
- );
|
||||
- }
|
||||
-
|
||||
- @EventHandler(priority = EventPriority.HIGHEST)
|
||||
- public void onAdvancement(PlayerAdvancementDoneEvent event) {
|
||||
- if (((CraftAdvancement) event.getAdvancement()).getHandle().value().display().isEmpty() || !((CraftAdvancement) event.getAdvancement()).getHandle().value().display().get().shouldAnnounceChat())
|
||||
- return;
|
||||
-
|
||||
- CraterEventBus.INSTANCE.postEvent(
|
||||
- new CraterAdvancementEvent(BridgedPlayer.of(((CraftPlayer) event.getPlayer()).getHandle()), BridgedAdvancement.of(((CraftAdvancement) event.getAdvancement()).getHandle().value()))
|
||||
- );
|
||||
- }
|
||||
-
|
||||
- @EventHandler(priority = EventPriority.HIGHEST)
|
||||
- public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
- CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedIn(BridgedPlayer.of(((CraftPlayer) event.getPlayer()).getHandle())));
|
||||
- }
|
||||
-
|
||||
- @EventHandler(priority = EventPriority.HIGHEST)
|
||||
- public void onPlayerLeave(PlayerQuitEvent event) {
|
||||
- CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedOut(BridgedPlayer.of(((CraftPlayer) event.getPlayer()).getHandle())));
|
||||
- }
|
||||
-
|
||||
- @EventHandler(priority = EventPriority.HIGHEST)
|
||||
- public void onServerChat(AsyncChatEvent event) {
|
||||
- CraterEventBus.INSTANCE.postEvent(
|
||||
- new CraterServerChatEvent(BridgedPlayer.of(((CraftPlayer) event.getPlayer()).getHandle()), PlainTextComponentSerializer.plainText().serialize(event.message()), event.message())
|
||||
- );
|
||||
- }
|
||||
-
|
||||
- public void onServerStarting(MinecraftServer server) {
|
||||
- CraterEventBus.INSTANCE.postEvent(new CraterServerLifecycleEvent.Starting(BridgedMinecraftServer.of(server)));
|
||||
- }
|
||||
-
|
||||
- public void onServerStarted() {
|
||||
- CraterEventBus.INSTANCE.postEvent(new CraterServerLifecycleEvent.Started(BridgedMinecraftServer.of(MinecraftServer.getServer())));
|
||||
- }
|
||||
-
|
||||
- @EventHandler(priority = EventPriority.HIGHEST)
|
||||
- public void onCommandEvent(PlayerCommandPreprocessEvent event) {
|
||||
- CommandSourceStack stack = null;
|
||||
-
|
||||
- if (event.getPlayer() instanceof CraftPlayer craftPlayer) {
|
||||
- stack = craftPlayer.getHandle().createCommandSourceStack();
|
||||
- } else if (event.getPlayer() instanceof ConsoleCommandSender) {
|
||||
- stack = MinecraftServer.getServer().createCommandSourceStack();
|
||||
- }
|
||||
-
|
||||
- if (stack == null)
|
||||
- return;
|
||||
-
|
||||
- String cmd = event.getMessage().substring(1);
|
||||
-
|
||||
- CommandDispatcher<CommandSourceStack> dispatcher = MinecraftServer.getServer().getCommands().getDispatcher();
|
||||
- ParseResults<CommandSourceStack> parseResults = dispatcher.parse(cmd, stack);
|
||||
- CraterEventBus.INSTANCE.postEvent(CraterCommandEvent.of(parseResults, cmd));
|
||||
- }
|
||||
-
|
||||
- @EventHandler(priority = EventPriority.HIGHEST)
|
||||
- public void onServerCommandEvent(ServerCommandEvent event) {
|
||||
- CommandSourceStack stack = MinecraftServer.getServer().createCommandSourceStack();
|
||||
-
|
||||
- String cmd = event.getCommand();
|
||||
-
|
||||
- CommandDispatcher<CommandSourceStack> dispatcher = MinecraftServer.getServer().getCommands().getDispatcher();
|
||||
- ParseResults<CommandSourceStack> parseResults = dispatcher.parse(cmd, stack);
|
||||
- CraterEventBus.INSTANCE.postEvent(CraterCommandEvent.of(parseResults, cmd));
|
||||
- }
|
||||
-
|
||||
- @EventHandler(priority = EventPriority.HIGHEST)
|
||||
- public void onPreLogin(AsyncPlayerPreLoginEvent event) {
|
||||
- PlayerPreLoginEvent playerPreLoginEvent = new PlayerPreLoginEvent(null, BridgedGameProfile.of(new GameProfile(event.getUniqueId(), event.getName())));
|
||||
- CraterEventBus.INSTANCE.postEvent(playerPreLoginEvent);
|
||||
-
|
||||
- if (playerPreLoginEvent.wasCancelled() || playerPreLoginEvent.getMessage() != null) {
|
||||
- event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, playerPreLoginEvent.getMessage());
|
||||
- }
|
||||
- }
|
||||
-}
|
@@ -0,0 +1,4 @@
|
||||
--- a/Paper/src/main/resources/META-INF/services/com.hypherionmc.craterlib.core.platform.CommonPlatform
|
||||
+++ /dev/null
|
||||
@@ -1,1 +1,0 @@
|
||||
-com.hypherionmc.craterlib.common.PaperCommonHelper
|
@@ -0,0 +1,4 @@
|
||||
--- a/Paper/src/main/resources/META-INF/services/com.hypherionmc.craterlib.core.platform.CompatUtils
|
||||
+++ /dev/null
|
||||
@@ -1,1 +1,0 @@
|
||||
-com.hypherionmc.craterlib.common.PaperCompatHelper
|
@@ -0,0 +1,4 @@
|
||||
--- a/Paper/src/main/resources/META-INF/services/com.hypherionmc.craterlib.core.platform.ModloaderEnvironment
|
||||
+++ /dev/null
|
||||
@@ -1,1 +1,0 @@
|
||||
-com.hypherionmc.craterlib.common.PaperLoaderHelper
|
@@ -0,0 +1,11 @@
|
||||
--- a/Paper/src/main/resources/paper-plugin.yml
|
||||
+++ /dev/null
|
||||
@@ -1,8 +1,0 @@
|
||||
-name: CraterLib
|
||||
-version: ${version}
|
||||
-description: "A Modding API used to create 'universal' mods"
|
||||
-main: com.hypherionmc.craterlib.paper.CraterLibPlugin
|
||||
-author: HypherionSA
|
||||
-api-version: '1.21.3'
|
||||
-bootstrapper: com.hypherionmc.craterlib.paper.CraterLibBootstrap
|
||||
-load: STARTUP
|
Reference in New Issue
Block a user