[FEAT] Paper Support
This commit is contained in:
@@ -2,8 +2,8 @@ def projectName = "CraterLib";
|
|||||||
def projectIcon = "https://cdn.modrinth.com/data/Nn8Wasaq/a172c634683a11a2e9ae593e56eba7885743bb44.png";
|
def projectIcon = "https://cdn.modrinth.com/data/Nn8Wasaq/a172c634683a11a2e9ae593e56eba7885743bb44.png";
|
||||||
def JDK = "21";
|
def JDK = "21";
|
||||||
def majorMc = "1.21.2";
|
def majorMc = "1.21.2";
|
||||||
def modLoaders = "neoforge|fabric|quilt";
|
def modLoaders = "neoforge|fabric|quilt|paper";
|
||||||
def supportedMc = "1.21.2";
|
def supportedMc = "1.21.3";
|
||||||
def reltype = "port";
|
def reltype = "port";
|
||||||
|
|
||||||
pipeline {
|
pipeline {
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
|
// @excludeplugin
|
||||||
package com.hypherionmc.craterlib.compat;
|
package com.hypherionmc.craterlib.compat;
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
||||||
@@ -13,4 +14,4 @@ public class FTBEssentials {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -12,7 +12,9 @@ import net.kyori.adventure.text.serializer.json.JSONOptions;
|
|||||||
import net.minecraft.ChatFormatting;
|
import net.minecraft.ChatFormatting;
|
||||||
import net.minecraft.SharedConstants;
|
import net.minecraft.SharedConstants;
|
||||||
import net.minecraft.Util;
|
import net.minecraft.Util;
|
||||||
|
// @noplugin
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
|
// #noplugin
|
||||||
import net.minecraft.core.HolderLookup;
|
import net.minecraft.core.HolderLookup;
|
||||||
import net.minecraft.core.RegistryAccess;
|
import net.minecraft.core.RegistryAccess;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
@@ -37,8 +39,10 @@ public class ChatUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static HolderLookup.Provider getRegistryLookup() {
|
private static HolderLookup.Provider getRegistryLookup() {
|
||||||
|
// @noplugin
|
||||||
if (ModloaderEnvironment.INSTANCE.getEnvironment().isClient() && Minecraft.getInstance().level != null)
|
if (ModloaderEnvironment.INSTANCE.getEnvironment().isClient() && Minecraft.getInstance().level != null)
|
||||||
return Minecraft.getInstance().level.registryAccess();
|
return Minecraft.getInstance().level.registryAccess();
|
||||||
|
// #noplugin
|
||||||
|
|
||||||
if (ModloaderEnvironment.INSTANCE.getEnvironment().isServer() && CommonPlatform.INSTANCE.getMCServer() != null)
|
if (ModloaderEnvironment.INSTANCE.getEnvironment().isServer() && CommonPlatform.INSTANCE.getMCServer() != null)
|
||||||
return CommonPlatform.INSTANCE.getMCServer().toMojang().registryAccess();
|
return CommonPlatform.INSTANCE.getMCServer().toMojang().registryAccess();
|
||||||
@@ -113,7 +117,15 @@ public class ChatUtils {
|
|||||||
|
|
||||||
public static net.kyori.adventure.text.Component format(String value) {
|
public static net.kyori.adventure.text.Component format(String value) {
|
||||||
value = convertFormattingCodes(value);
|
value = convertFormattingCodes(value);
|
||||||
return miniMessage.deserializeOr(value, net.kyori.adventure.text.Component.translatable(value));
|
|
||||||
|
try {
|
||||||
|
return miniMessage.deserializeOr(value, net.kyori.adventure.text.Component.translatable(value));
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
// Mini message fails to format text that contain legacy formatting. Since we support both, that's bad.
|
||||||
|
// We just ignore the exception here so that the whole format doesn't fail
|
||||||
|
}
|
||||||
|
|
||||||
|
return net.kyori.adventure.text.Component.translatable(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String convertFormattingCodes(String input) {
|
private static String convertFormattingCodes(String input) {
|
||||||
|
@@ -10,6 +10,8 @@ import java.util.ServiceLoader;
|
|||||||
*/
|
*/
|
||||||
public class InternalServiceUtil {
|
public class InternalServiceUtil {
|
||||||
|
|
||||||
|
public static ClassLoader loader = Thread.currentThread().getContextClassLoader();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Try to load a service
|
* Try to load a service
|
||||||
*
|
*
|
||||||
@@ -17,7 +19,7 @@ public class InternalServiceUtil {
|
|||||||
* @return The loaded class
|
* @return The loaded class
|
||||||
*/
|
*/
|
||||||
public static <T> T load(Class<T> clazz) {
|
public static <T> T load(Class<T> clazz) {
|
||||||
final T loadedService = ServiceLoader.load(clazz)
|
final T loadedService = ServiceLoader.load(clazz, loader)
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.orElseThrow(() -> new NullPointerException("Failed to load service for " + clazz.getName()));
|
.orElseThrow(() -> new NullPointerException("Failed to load service for " + clazz.getName()));
|
||||||
CraterConstants.LOG.debug("Loaded {} for service {}", loadedService, clazz);
|
CraterConstants.LOG.debug("Loaded {} for service {}", loadedService, clazz);
|
||||||
|
@@ -113,10 +113,10 @@ publisher {
|
|||||||
setModrinthID(modrinth_id)
|
setModrinthID(modrinth_id)
|
||||||
setNightbloomID("craterlib")
|
setNightbloomID("craterlib")
|
||||||
setVersionType("release")
|
setVersionType("release")
|
||||||
setChangelog("https://raw.githubusercontent.com/hypherionmc/changelogs/main/craterlib/changelog-fabric.md")
|
setChangelog(rootProject.file("changelog.md"))
|
||||||
setProjectVersion("${minecraft_version}-${project.version}")
|
setProjectVersion("${minecraft_version}-${project.version}")
|
||||||
setDisplayName("[FABRIC/QUILT 1.21.2] CraterLib - ${project.version}")
|
setDisplayName("[FABRIC/QUILT 1.21.3] CraterLib - ${project.version}")
|
||||||
setGameVersions("1.21.2")
|
setGameVersions("1.21.3")
|
||||||
setLoaders("fabric", "quilt")
|
setLoaders("fabric", "quilt")
|
||||||
setArtifact(remapJar)
|
setArtifact(remapJar)
|
||||||
setCurseEnvironment("both")
|
setCurseEnvironment("both")
|
||||||
|
@@ -13,7 +13,7 @@ public class FabricCompatHelper implements CompatUtils {
|
|||||||
if (!ModloaderEnvironment.INSTANCE.isModLoaded("melius-vanish"))
|
if (!ModloaderEnvironment.INSTANCE.isModLoaded("melius-vanish"))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return Vanish.isPlayerVanished(player.toMojangServerPlayer());
|
return !Vanish.isPlayerVanished(player.toMojangServerPlayer());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -105,7 +105,7 @@ publisher {
|
|||||||
setModrinthID(modrinth_id)
|
setModrinthID(modrinth_id)
|
||||||
setNightbloomID("craterlib")
|
setNightbloomID("craterlib")
|
||||||
setVersionType("release")
|
setVersionType("release")
|
||||||
setChangelog("https://raw.githubusercontent.com/hypherionmc/changelogs/main/craterlib/changelog-forge.md")
|
setChangelog(rootProject.file("changelog.md"))
|
||||||
setProjectVersion("${minecraft_version}-${project.version}")
|
setProjectVersion("${minecraft_version}-${project.version}")
|
||||||
setDisplayName("[Forge 1.20.6] CraterLib - ${project.version}")
|
setDisplayName("[Forge 1.20.6] CraterLib - ${project.version}")
|
||||||
setGameVersions("1.20.6")
|
setGameVersions("1.20.6")
|
||||||
|
@@ -111,10 +111,10 @@ publisher {
|
|||||||
setModrinthID(modrinth_id)
|
setModrinthID(modrinth_id)
|
||||||
setNightbloomID("craterlib")
|
setNightbloomID("craterlib")
|
||||||
setVersionType("release")
|
setVersionType("release")
|
||||||
setChangelog("https://raw.githubusercontent.com/hypherionmc/changelogs/main/craterlib/changelog-forge.md")
|
setChangelog(rootProject.file("changelog.md"))
|
||||||
setProjectVersion("${minecraft_version}-${project.version}")
|
setProjectVersion("${minecraft_version}-${project.version}")
|
||||||
setDisplayName("[NeoForge 1.21.2] CraterLib - ${project.version}")
|
setDisplayName("[NeoForge 1.21.3] CraterLib - ${project.version}")
|
||||||
setGameVersions("1.21.2")
|
setGameVersions("1.21.3")
|
||||||
setLoaders("neoforge")
|
setLoaders("neoforge")
|
||||||
setArtifact(remapJar)
|
setArtifact(remapJar)
|
||||||
setCurseEnvironment("both")
|
setCurseEnvironment("both")
|
||||||
|
@@ -12,7 +12,7 @@ public class NeoForgeCompatHelper implements CompatUtils {
|
|||||||
if (!ModloaderEnvironment.INSTANCE.isModLoaded("vmod"))
|
if (!ModloaderEnvironment.INSTANCE.isModLoaded("vmod"))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return VanishUtil.isVanished(player.toMojangServerPlayer());
|
return !VanishUtil.isVanished(player.toMojangServerPlayer());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
80
Paper/build.gradle
Normal file
80
Paper/build.gradle
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
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,19 @@
|
|||||||
|
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,78 @@
|
|||||||
|
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,70 @@
|
|||||||
|
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,13 @@
|
|||||||
|
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,31 @@
|
|||||||
|
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,113 @@
|
|||||||
|
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 @@
|
|||||||
|
com.hypherionmc.craterlib.common.PaperCommonHelper
|
@@ -0,0 +1 @@
|
|||||||
|
com.hypherionmc.craterlib.common.PaperCompatHelper
|
@@ -0,0 +1 @@
|
|||||||
|
com.hypherionmc.craterlib.common.PaperLoaderHelper
|
8
Paper/src/main/resources/paper-plugin.yml
Normal file
8
Paper/src/main/resources/paper-plugin.yml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
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
|
27
build.gradle
27
build.gradle
@@ -3,7 +3,8 @@ plugins {
|
|||||||
id 'com.github.johnrengelman.shadow' version '8.1.1' apply false
|
id 'com.github.johnrengelman.shadow' version '8.1.1' apply false
|
||||||
id "xyz.wagyourtail.unimined" version "1.3.9" apply false
|
id "xyz.wagyourtail.unimined" version "1.3.9" apply false
|
||||||
id "com.hypherionmc.modutils.modpublisher" version "2.1.6"
|
id "com.hypherionmc.modutils.modpublisher" version "2.1.6"
|
||||||
id "com.hypherionmc.modutils.orion" version "1.0.+"
|
id "com.hypherionmc.modutils.orion" version "1.0.24"
|
||||||
|
id "com.hypherionmc.modutils.orion.origami" version "1.0.24" apply false
|
||||||
id 'maven-publish'
|
id 'maven-publish'
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,6 +36,10 @@ subprojects {
|
|||||||
apply plugin: 'com.github.johnrengelman.shadow'
|
apply plugin: 'com.github.johnrengelman.shadow'
|
||||||
apply plugin: 'com.hypherionmc.modutils.modpublisher'
|
apply plugin: 'com.hypherionmc.modutils.modpublisher'
|
||||||
|
|
||||||
|
if (project.name === "Paper") {
|
||||||
|
apply plugin: 'com.hypherionmc.modutils.orion.origami'
|
||||||
|
}
|
||||||
|
|
||||||
sourceCompatibility = JavaVersion.VERSION_21
|
sourceCompatibility = JavaVersion.VERSION_21
|
||||||
targetCompatibility = JavaVersion.VERSION_21
|
targetCompatibility = JavaVersion.VERSION_21
|
||||||
|
|
||||||
@@ -100,17 +105,19 @@ subprojects {
|
|||||||
* = DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING =
|
* = DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING =
|
||||||
* ===============================================================================
|
* ===============================================================================
|
||||||
*/
|
*/
|
||||||
unimined.minecraft(sourceSets.main, true) {
|
if (project.name !== "Paper") {
|
||||||
version minecraft_version
|
unimined.minecraft(sourceSets.main, true) {
|
||||||
|
version minecraft_version
|
||||||
|
|
||||||
mappings {
|
mappings {
|
||||||
mojmap()
|
mojmap()
|
||||||
devNamespace "mojmap"
|
devNamespace "mojmap"
|
||||||
}
|
}
|
||||||
|
|
||||||
mods {
|
mods {
|
||||||
remap(configurations.stupidRemapArch) {
|
remap(configurations.stupidRemapArch) {
|
||||||
catchAWNamespaceAssertion()
|
catchAWNamespaceAssertion()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
11
changelog.md
Normal file
11
changelog.md
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
**New Features**:
|
||||||
|
|
||||||
|
- Paper Support. Currently only available on Modrinth and NightBloom
|
||||||
|
|
||||||
|
**Bug Fixes**:
|
||||||
|
|
||||||
|
- Fixed Vanish compact API being swapped
|
||||||
|
|
||||||
|
**Changes**:
|
||||||
|
|
||||||
|
- Config library now logs which line of the config the error is on
|
@@ -1,7 +1,7 @@
|
|||||||
#Project
|
#Project
|
||||||
version_major=2
|
version_major=2
|
||||||
version_minor=1
|
version_minor=1
|
||||||
version_patch=1
|
version_patch=2
|
||||||
version_build=0
|
version_build=0
|
||||||
|
|
||||||
#Mod
|
#Mod
|
||||||
@@ -10,18 +10,18 @@ mod_id=craterlib
|
|||||||
mod_name=CraterLib
|
mod_name=CraterLib
|
||||||
|
|
||||||
# Shared
|
# Shared
|
||||||
minecraft_version=1.21.2
|
minecraft_version=1.21.3
|
||||||
project_group=com.hypherionmc.craterlib
|
project_group=com.hypherionmc.craterlib
|
||||||
|
|
||||||
# Fabric
|
# Fabric
|
||||||
fabric_loader=0.16.7
|
fabric_loader=0.16.7
|
||||||
fabric_api=0.106.1+1.21.2
|
fabric_api=0.107.3+1.21.3
|
||||||
|
|
||||||
# Forge
|
# Forge
|
||||||
forge_version=50.0.6
|
forge_version=50.0.6
|
||||||
|
|
||||||
# NeoForged
|
# NeoForged
|
||||||
neoforge_version=0-beta
|
neoforge_version=16-beta
|
||||||
|
|
||||||
# Dependencies
|
# Dependencies
|
||||||
moon_config=1.0.10
|
moon_config=1.0.10
|
||||||
|
@@ -14,4 +14,6 @@ pluginManagement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
rootProject.name = 'CraterLib'
|
rootProject.name = 'CraterLib'
|
||||||
include("Common", "Fabric", "NeoForge")
|
include("Common", "Fabric", "NeoForge")
|
||||||
|
include 'Paper'
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user