[FEAT] Paper Support

This commit is contained in:
2024-10-22 20:13:32 +02:00
parent 86149ace11
commit e0e37685e2
352 changed files with 5772 additions and 1588 deletions

View File

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

View File

@@ -9,7 +9,6 @@ import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import net.kyori.adventure.text.serializer.json.JSONOptions; 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.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.Style; import net.minecraft.network.chat.Style;
import net.minecraft.network.chat.TextComponent; import net.minecraft.network.chat.TextComponent;
@@ -100,7 +99,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) {

View File

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

View File

@@ -111,7 +111,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-fabric.md") setChangelog(rootProject.file("changelog.md"))
setProjectVersion("${minecraft_version}-${project.version}") setProjectVersion("${minecraft_version}-${project.version}")
setDisplayName("[FABRIC/QUILT 1.18.2] CraterLib - ${project.version}") setDisplayName("[FABRIC/QUILT 1.18.2] CraterLib - ${project.version}")
setGameVersions("1.18.2") setGameVersions("1.18.2")

View File

@@ -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

View File

@@ -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.18.2] CraterLib - ${project.version}") setDisplayName("[Forge 1.18.2] CraterLib - ${project.version}")
setGameVersions("1.18.2") setGameVersions("1.18.2")

View File

@@ -12,7 +12,7 @@ public class ForgeCompatHelper 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

View File

@@ -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'
} }
@@ -29,6 +30,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_17 sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_17
@@ -95,17 +100,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
1.18.2/changelog.md Normal file
View 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

View File

@@ -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

View File

@@ -2,7 +2,7 @@ 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 = "17"; def JDK = "17";
def majorMc = "1.19.2"; def majorMc = "1.19.2";
def modLoaders = "forge|fabric|quilt"; def modLoaders = "forge|fabric|quilt|paper";
def supportedMc = "1.19.2"; def supportedMc = "1.19.2";
def reltype = "snapshot"; def reltype = "snapshot";

View File

@@ -14,8 +14,14 @@ public class CraterPlayerDeathEvent extends CraterEvent {
private final BridgedPlayer player; private final BridgedPlayer player;
private final DamageSource damageSource; private final DamageSource damageSource;
private Component deathMessage;
public CraterPlayerDeathEvent(BridgedPlayer player, DamageSource source, Component deathMessage) {
this(player, source);
this.deathMessage = deathMessage;
}
public Component getDeathMessage() { public Component getDeathMessage() {
return ChatUtils.mojangToAdventure(damageSource.getLocalizedDeathMessage(player.toMojang())); return deathMessage != null ? deathMessage : ChatUtils.mojangToAdventure(damageSource.getLocalizedDeathMessage(player.toMojang()));
} }
} }

View File

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

View File

@@ -12,6 +12,7 @@ import net.minecraft.SharedConstants;
import net.minecraft.Util; import net.minecraft.Util;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.Style; import net.minecraft.network.chat.Style;
public class ChatUtils { public class ChatUtils {
private static final GsonComponentSerializer adventureSerializer = GsonComponentSerializer.builder().options( private static final GsonComponentSerializer adventureSerializer = GsonComponentSerializer.builder().options(
@@ -97,7 +98,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) {

View File

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

View File

@@ -112,7 +112,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-fabric.md") setChangelog(rootProject.file("changelog.md"))
setProjectVersion("${minecraft_version}-${project.version}") setProjectVersion("${minecraft_version}-${project.version}")
setDisplayName("[FABRIC/QUILT 1.19.2] CraterLib - ${project.version}") setDisplayName("[FABRIC/QUILT 1.19.2] CraterLib - ${project.version}")
setGameVersions("1.19.2") setGameVersions("1.19.2")

View File

@@ -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

View File

@@ -106,7 +106,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.19.2] CraterLib - ${project.version}") setDisplayName("[Forge 1.19.2] CraterLib - ${project.version}")
setGameVersions("1.19.2") setGameVersions("1.19.2")

View File

@@ -12,7 +12,7 @@ public class ForgeCompatHelper 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

View File

@@ -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'
} }
@@ -29,6 +30,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_17 sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_17
@@ -93,17 +98,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
1.19.2/changelog.md Normal file
View 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

View File

@@ -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

View File

@@ -2,7 +2,7 @@ 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 = "17"; def JDK = "17";
def majorMc = "1.19.3"; def majorMc = "1.19.3";
def modLoaders = "forge|fabric|quilt"; def modLoaders = "forge|fabric|quilt|paper";
def supportedMc = "1.19.4"; def supportedMc = "1.19.4";
def reltype = "snapshot"; def reltype = "snapshot";

View File

@@ -14,8 +14,14 @@ public class CraterPlayerDeathEvent extends CraterEvent {
private final BridgedPlayer player; private final BridgedPlayer player;
private final DamageSource damageSource; private final DamageSource damageSource;
private Component deathMessage;
public CraterPlayerDeathEvent(BridgedPlayer player, DamageSource damageSource, Component deathMessage) {
this(player, null);
this.deathMessage = deathMessage;
}
public Component getDeathMessage() { public Component getDeathMessage() {
return ChatUtils.mojangToAdventure(damageSource.getLocalizedDeathMessage(player.toMojang())); return deathMessage != null ? deathMessage : ChatUtils.mojangToAdventure(damageSource.getLocalizedDeathMessage(player.toMojang()));
} }
} }

View File

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

View File

@@ -6,17 +6,14 @@ import me.hypherionmc.mcdiscordformatter.minecraft.MinecraftSerializer;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import net.kyori.adventure.text.serializer.json.JSONOptions;
import net.minecraft.ChatFormatting; import net.minecraft.ChatFormatting;
import net.minecraft.SharedConstants;
import net.minecraft.Util; import net.minecraft.Util;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.Style; import net.minecraft.network.chat.Style;
public class ChatUtils { public class ChatUtils {
private static final GsonComponentSerializer adventureSerializer = GsonComponentSerializer.builder().options( private static final GsonComponentSerializer adventureSerializer = GsonComponentSerializer.builder().build();
JSONOptions.byDataVersion().at(SharedConstants.getCurrentVersion().getDataVersion().getVersion())
).build();
private static final MiniMessage miniMessage = MiniMessage.miniMessage(); private static final MiniMessage miniMessage = MiniMessage.miniMessage();
@@ -97,7 +94,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) {

View File

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

View File

@@ -112,7 +112,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-fabric.md") setChangelog(rootProject.file("changelog.md"))
setProjectVersion("${minecraft_version}-${project.version}") setProjectVersion("${minecraft_version}-${project.version}")
setDisplayName("[FABRIC/QUILT 1.19.4] CraterLib - ${project.version}") setDisplayName("[FABRIC/QUILT 1.19.4] CraterLib - ${project.version}")
setGameVersions("1.19.4") setGameVersions("1.19.4")

View File

@@ -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

View File

@@ -107,7 +107,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.19.4] CraterLib - ${project.version}") setDisplayName("[Forge 1.19.4] CraterLib - ${project.version}")
setGameVersions("1.19.4") setGameVersions("1.19.4")

View File

@@ -12,7 +12,7 @@ public class ForgeCompatHelper 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
1.19.3/Paper/build.gradle Normal file
View 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.19.4] CraterLib - ${project.version}")
setGameVersions("1.19.4")
setLoaders("paper")
setArtifact(reobfJar.outputJar)
}
publishModrinth.dependsOn(reobfJar)
publishNightbloom.dependsOn(reobfJar)

View File

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

View File

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

View File

@@ -4,19 +4,18 @@ import com.hypherionmc.craterlib.core.platform.Environment;
import com.hypherionmc.craterlib.core.platform.LoaderType; import com.hypherionmc.craterlib.core.platform.LoaderType;
import com.hypherionmc.craterlib.core.platform.ModloaderEnvironment; import com.hypherionmc.craterlib.core.platform.ModloaderEnvironment;
import net.minecraft.SharedConstants; import net.minecraft.SharedConstants;
import net.minecraft.client.Minecraft; import org.bukkit.Bukkit;
import net.minecraftforge.fml.ModList; import org.bukkit.plugin.Plugin;
import net.minecraftforge.fml.loading.FMLLoader;
import net.minecraftforge.fml.loading.FMLPaths;
import java.io.File; import java.io.File;
import java.util.Arrays;
/** /**
* @author HypherionSA * @author HypherionSA
*/ */
public class ForgeLoaderHelper implements ModloaderEnvironment { public class PaperLoaderHelper implements ModloaderEnvironment {
public ForgeLoaderHelper() { public PaperLoaderHelper() {
} }
@Override @Override
@@ -26,54 +25,46 @@ public class ForgeLoaderHelper implements ModloaderEnvironment {
@Override @Override
public LoaderType getLoaderType() { public LoaderType getLoaderType() {
return LoaderType.FORGE; return LoaderType.PAPER;
} }
@Override @Override
public String getGameVersion() { public String getGameVersion() {
return SharedConstants.VERSION_STRING; return SharedConstants.getCurrentVersion().getName();
} }
@Override @Override
public File getGameFolder() { public File getGameFolder() {
return Minecraft.getInstance().gameDirectory; return new File(".");
} }
@Override @Override
public File getConfigFolder() { public File getConfigFolder() {
return FMLPaths.CONFIGDIR.get().toFile(); return new File("config");
} }
@Override @Override
public File getModsFolder() { public File getModsFolder() {
return FMLPaths.MODSDIR.get().toFile(); return Bukkit.getPluginsFolder();
} }
@Override @Override
public Environment getEnvironment() { public Environment getEnvironment() {
switch (FMLLoader.getDist()) { return Environment.SERVER;
case CLIENT -> {
return Environment.CLIENT;
}
case DEDICATED_SERVER -> {
return Environment.SERVER;
}
}
return Environment.UNKNOWN;
} }
@Override @Override
public boolean isModLoaded(String modid) { public boolean isModLoaded(String modid) {
return ModList.get().isLoaded(modid); return Bukkit.getPluginManager().isPluginEnabled(modid);
} }
@Override @Override
public boolean isDevEnv() { public boolean isDevEnv() {
return !FMLLoader.isProduction(); return false;
} }
@Override @Override
public int getModCount() { public int getModCount() {
return ModList.get().size(); return (int) Arrays.stream(Bukkit.getPluginManager().getPlugins()).filter(Plugin::isEnabled).count();
} }
} }

View File

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

View File

@@ -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().getCommands().getDispatcher()));
getServer().getPluginManager().registerEvents(listener, this);
getServer().getScheduler().scheduleSyncDelayedTask(this, listener::onServerStarted);
}
}

View File

@@ -0,0 +1,112 @@
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.v1_19_R3.advancement.CraftAdvancement;
import org.bukkit.craftbukkit.v1_19_R3.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()), null, event.deathMessage())
);
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onAdvancement(PlayerAdvancementDoneEvent event) {
if (((CraftAdvancement) event.getAdvancement()).getHandle().getDisplay() == null || !(((CraftAdvancement) event.getAdvancement()).getHandle().getDisplay().shouldAnnounceChat()))
return;
CraterEventBus.INSTANCE.postEvent(
new CraterAdvancementEvent(BridgedPlayer.of(((CraftPlayer) event.getPlayer()).getHandle()), BridgedAdvancement.of(((CraftAdvancement) event.getAdvancement()).getHandle()))
);
}
@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());
}
}
}

View File

@@ -0,0 +1 @@
com.hypherionmc.craterlib.common.PaperCommonHelper

View File

@@ -0,0 +1 @@
com.hypherionmc.craterlib.common.PaperCompatHelper

View File

@@ -0,0 +1 @@
com.hypherionmc.craterlib.common.PaperLoaderHelper

View 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.19'
bootstrapper: com.hypherionmc.craterlib.paper.CraterLibBootstrap
load: STARTUP

View File

@@ -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'
} }
@@ -29,6 +30,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_17 sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_17
@@ -93,17 +98,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
1.19.3/changelog.md Normal file
View 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

View File

@@ -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

View File

@@ -15,3 +15,4 @@ pluginManagement {
rootProject.name = 'CraterLib-1.19.3' rootProject.name = 'CraterLib-1.19.3'
include("Common", "Fabric", "Forge") include("Common", "Fabric", "Forge")
include 'Paper'

View File

@@ -2,7 +2,7 @@ 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 = "17"; def JDK = "17";
def majorMc = "1.20.2"; def majorMc = "1.20.2";
def modLoaders = "forge|fabric|quilt"; def modLoaders = "forge|fabric|quilt|paper";
def supportedMc = "1.20.2"; def supportedMc = "1.20.2";
def reltype = "snapshot"; def reltype = "snapshot";

View File

@@ -14,8 +14,14 @@ public class CraterPlayerDeathEvent extends CraterEvent {
private final BridgedPlayer player; private final BridgedPlayer player;
private final DamageSource damageSource; private final DamageSource damageSource;
private Component deathMessage;
public CraterPlayerDeathEvent(BridgedPlayer player, DamageSource damageSource, Component deathMessage) {
this(player, null);
this.deathMessage = deathMessage;
}
public Component getDeathMessage() { public Component getDeathMessage() {
return ChatUtils.mojangToAdventure(damageSource.getLocalizedDeathMessage(player.toMojang())); return deathMessage != null ? deathMessage : ChatUtils.mojangToAdventure(damageSource.getLocalizedDeathMessage(player.toMojang()));
} }
} }

View File

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

View File

@@ -6,17 +6,14 @@ import me.hypherionmc.mcdiscordformatter.minecraft.MinecraftSerializer;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import net.kyori.adventure.text.serializer.json.JSONOptions;
import net.minecraft.ChatFormatting; import net.minecraft.ChatFormatting;
import net.minecraft.SharedConstants;
import net.minecraft.Util; import net.minecraft.Util;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.Style; import net.minecraft.network.chat.Style;
public class ChatUtils { public class ChatUtils {
private static final GsonComponentSerializer adventureSerializer = GsonComponentSerializer.builder().options( private static final GsonComponentSerializer adventureSerializer = GsonComponentSerializer.builder().build();
JSONOptions.byDataVersion().at(SharedConstants.getCurrentVersion().getDataVersion().getVersion())
).build();
private static final MiniMessage miniMessage = MiniMessage.miniMessage(); private static final MiniMessage miniMessage = MiniMessage.miniMessage();
@@ -97,7 +94,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) {

View File

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

View File

@@ -112,7 +112,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-fabric.md") setChangelog(rootProject.file("changelog.md"))
setProjectVersion("${minecraft_version}-${project.version}") setProjectVersion("${minecraft_version}-${project.version}")
setDisplayName("[FABRIC/QUILT 1.20.2] CraterLib - ${project.version}") setDisplayName("[FABRIC/QUILT 1.20.2] CraterLib - ${project.version}")
setGameVersions("1.20.2") setGameVersions("1.20.2")

View File

@@ -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

View File

@@ -107,7 +107,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.2] CraterLib - ${project.version}") setDisplayName("[Forge 1.20.2] CraterLib - ${project.version}")
setGameVersions("1.20.2") setGameVersions("1.20.2")

View File

@@ -12,7 +12,7 @@ public class ForgeCompatHelper 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
1.20.2/Paper/build.gradle Normal file
View 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.20.2] CraterLib - ${project.version}")
setGameVersions("1.20.2")
setLoaders("paper")
setArtifact(reobfJar.outputJar)
}
publishModrinth.dependsOn(reobfJar)
publishNightbloom.dependsOn(reobfJar)

View File

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

View File

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

View File

@@ -4,19 +4,18 @@ import com.hypherionmc.craterlib.core.platform.Environment;
import com.hypherionmc.craterlib.core.platform.LoaderType; import com.hypherionmc.craterlib.core.platform.LoaderType;
import com.hypherionmc.craterlib.core.platform.ModloaderEnvironment; import com.hypherionmc.craterlib.core.platform.ModloaderEnvironment;
import net.minecraft.SharedConstants; import net.minecraft.SharedConstants;
import net.minecraft.client.Minecraft; import org.bukkit.Bukkit;
import net.minecraftforge.fml.ModList; import org.bukkit.plugin.Plugin;
import net.minecraftforge.fml.loading.FMLLoader;
import net.minecraftforge.fml.loading.FMLPaths;
import java.io.File; import java.io.File;
import java.util.Arrays;
/** /**
* @author HypherionSA * @author HypherionSA
*/ */
public class ForgeLoaderHelper implements ModloaderEnvironment { public class PaperLoaderHelper implements ModloaderEnvironment {
public ForgeLoaderHelper() { public PaperLoaderHelper() {
} }
@Override @Override
@@ -26,54 +25,46 @@ public class ForgeLoaderHelper implements ModloaderEnvironment {
@Override @Override
public LoaderType getLoaderType() { public LoaderType getLoaderType() {
return LoaderType.FORGE; return LoaderType.PAPER;
} }
@Override @Override
public String getGameVersion() { public String getGameVersion() {
return SharedConstants.VERSION_STRING; return SharedConstants.getCurrentVersion().getName();
} }
@Override @Override
public File getGameFolder() { public File getGameFolder() {
return Minecraft.getInstance().gameDirectory; return new File(".");
} }
@Override @Override
public File getConfigFolder() { public File getConfigFolder() {
return FMLPaths.CONFIGDIR.get().toFile(); return new File("config");
} }
@Override @Override
public File getModsFolder() { public File getModsFolder() {
return FMLPaths.MODSDIR.get().toFile(); return Bukkit.getPluginsFolder();
} }
@Override @Override
public Environment getEnvironment() { public Environment getEnvironment() {
switch (FMLLoader.getDist()) { return Environment.SERVER;
case CLIENT -> {
return Environment.CLIENT;
}
case DEDICATED_SERVER -> {
return Environment.SERVER;
}
}
return Environment.UNKNOWN;
} }
@Override @Override
public boolean isModLoaded(String modid) { public boolean isModLoaded(String modid) {
return ModList.get().isLoaded(modid); return Bukkit.getPluginManager().isPluginEnabled(modid);
} }
@Override @Override
public boolean isDevEnv() { public boolean isDevEnv() {
return !FMLLoader.isProduction(); return false;
} }
@Override @Override
public int getModCount() { public int getModCount() {
return ModList.get().size(); return (int) Arrays.stream(Bukkit.getPluginManager().getPlugins()).filter(Plugin::isEnabled).count();
} }
} }

View File

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

View File

@@ -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().getCommands().getDispatcher()));
getServer().getPluginManager().registerEvents(listener, this);
getServer().getScheduler().scheduleSyncDelayedTask(this, listener::onServerStarted);
}
}

View File

@@ -0,0 +1,116 @@
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.advancements.Advancement;
import net.minecraft.advancements.AdvancementHolder;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.server.MinecraftServer;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.craftbukkit.v1_20_R2.advancement.CraftAdvancement;
import org.bukkit.craftbukkit.v1_20_R2.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()), null, event.deathMessage())
);
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onAdvancement(PlayerAdvancementDoneEvent event) {
AdvancementHolder advancement = ((CraftAdvancement) event.getAdvancement()).getHandle();
if (advancement.value().display().isEmpty() || !advancement.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());
}
}
}

View File

@@ -0,0 +1 @@
com.hypherionmc.craterlib.common.PaperCommonHelper

View File

@@ -0,0 +1 @@
com.hypherionmc.craterlib.common.PaperCompatHelper

View File

@@ -0,0 +1 @@
com.hypherionmc.craterlib.common.PaperLoaderHelper

View 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.20'
bootstrapper: com.hypherionmc.craterlib.paper.CraterLibBootstrap
load: STARTUP

View File

@@ -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'
} }
@@ -29,6 +30,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_17 sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_17
@@ -93,17 +98,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
1.20.2/changelog.md Normal file
View 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

View File

@@ -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

View File

@@ -15,3 +15,4 @@ pluginManagement {
rootProject.name = 'CraterLib-1.20.2' rootProject.name = 'CraterLib-1.20.2'
include("Common", "Fabric", "Forge") include("Common", "Fabric", "Forge")
include 'Paper'

View File

@@ -2,7 +2,7 @@ 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 = "17"; def JDK = "17";
def majorMc = "1.20.4"; def majorMc = "1.20.4";
def modLoaders = "neoforge|forge|fabric|quilt"; def modLoaders = "neoforge|forge|fabric|quilt|paper";
def supportedMc = "1.20.4"; def supportedMc = "1.20.4";
def reltype = "snapshot"; def reltype = "snapshot";

View File

@@ -14,8 +14,14 @@ public class CraterPlayerDeathEvent extends CraterEvent {
private final BridgedPlayer player; private final BridgedPlayer player;
private final DamageSource damageSource; private final DamageSource damageSource;
private Component deathMessage;
public CraterPlayerDeathEvent(BridgedPlayer player, DamageSource damageSource, Component deathMessage) {
this(player, null);
this.deathMessage = deathMessage;
}
public Component getDeathMessage() { public Component getDeathMessage() {
return ChatUtils.mojangToAdventure(damageSource.getLocalizedDeathMessage(player.toMojang())); return deathMessage != null ? deathMessage : ChatUtils.mojangToAdventure(damageSource.getLocalizedDeathMessage(player.toMojang()));
} }
} }

View File

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

View File

@@ -12,6 +12,7 @@ import net.minecraft.SharedConstants;
import net.minecraft.Util; import net.minecraft.Util;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.Style; import net.minecraft.network.chat.Style;
public class ChatUtils { public class ChatUtils {
private static final GsonComponentSerializer adventureSerializer = GsonComponentSerializer.builder().options( private static final GsonComponentSerializer adventureSerializer = GsonComponentSerializer.builder().options(
@@ -97,7 +98,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) {

View File

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

View File

@@ -113,7 +113,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-fabric.md") setChangelog(rootProject.file("changelog.md"))
setProjectVersion("${minecraft_version}-${project.version}") setProjectVersion("${minecraft_version}-${project.version}")
setDisplayName("[FABRIC/QUILT 1.20.4] CraterLib - ${project.version}") setDisplayName("[FABRIC/QUILT 1.20.4] CraterLib - ${project.version}")
setGameVersions("1.20.4") setGameVersions("1.20.4")

View File

@@ -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

View File

@@ -107,7 +107,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.4] CraterLib - ${project.version}") setDisplayName("[Forge 1.20.4] CraterLib - ${project.version}")
setGameVersions("1.20.4") setGameVersions("1.20.4")

View File

@@ -12,7 +12,7 @@ public class ForgeCompatHelper 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

View File

@@ -106,7 +106,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("[NeoForge 1.20.4] CraterLib - ${project.version}") setDisplayName("[NeoForge 1.20.4] CraterLib - ${project.version}")
setGameVersions("1.20.4") setGameVersions("1.20.4")

View File

@@ -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
1.20.4/Paper/build.gradle Normal file
View 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.20.4] CraterLib - ${project.version}")
setGameVersions("1.20.4")
setLoaders("paper")
setArtifact(reobfJar.outputJar)
}
publishModrinth.dependsOn(reobfJar)
publishNightbloom.dependsOn(reobfJar)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -0,0 +1,112 @@
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.v1_20_R3.advancement.CraftAdvancement;
import org.bukkit.craftbukkit.v1_20_R3.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()), null, event.deathMessage())
);
}
@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());
}
}
}

View File

@@ -0,0 +1 @@
com.hypherionmc.craterlib.common.PaperCommonHelper

View File

@@ -0,0 +1 @@
com.hypherionmc.craterlib.common.PaperCompatHelper

View File

@@ -0,0 +1 @@
com.hypherionmc.craterlib.common.PaperLoaderHelper

View 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.20'
bootstrapper: com.hypherionmc.craterlib.paper.CraterLibBootstrap
load: STARTUP

View File

@@ -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'
} }
@@ -29,6 +30,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_17 sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_17
@@ -93,17 +98,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
1.20.4/changelog.md Normal file
View 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

View File

@@ -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

View File

@@ -15,3 +15,4 @@ pluginManagement {
rootProject.name = 'CraterLib-1.20.4' rootProject.name = 'CraterLib-1.20.4'
include("Common", "Fabric", "Forge", "NeoForge") include("Common", "Fabric", "Forge", "NeoForge")
include 'Paper'

View File

@@ -2,7 +2,7 @@ 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 = "17"; def JDK = "17";
def majorMc = "1.20"; def majorMc = "1.20";
def modLoaders = "forge|fabric|quilt"; def modLoaders = "forge|fabric|quilt|paper";
def supportedMc = "1.20|1.20.1"; def supportedMc = "1.20|1.20.1";
def reltype = "snapshot"; def reltype = "snapshot";

View File

@@ -14,8 +14,14 @@ public class CraterPlayerDeathEvent extends CraterEvent {
private final BridgedPlayer player; private final BridgedPlayer player;
private final DamageSource damageSource; private final DamageSource damageSource;
private Component deathMessage;
public CraterPlayerDeathEvent(BridgedPlayer player, DamageSource damageSource, Component deathMessage) {
this(player, null);
this.deathMessage = deathMessage;
}
public Component getDeathMessage() { public Component getDeathMessage() {
return ChatUtils.mojangToAdventure(damageSource.getLocalizedDeathMessage(player.toMojang())); return deathMessage != null ? deathMessage : ChatUtils.mojangToAdventure(damageSource.getLocalizedDeathMessage(player.toMojang()));
} }
} }

View File

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

View File

@@ -6,17 +6,14 @@ import me.hypherionmc.mcdiscordformatter.minecraft.MinecraftSerializer;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import net.kyori.adventure.text.serializer.json.JSONOptions;
import net.minecraft.ChatFormatting; import net.minecraft.ChatFormatting;
import net.minecraft.SharedConstants;
import net.minecraft.Util; import net.minecraft.Util;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.Style; import net.minecraft.network.chat.Style;
public class ChatUtils { public class ChatUtils {
private static final GsonComponentSerializer adventureSerializer = GsonComponentSerializer.builder().options( private static final GsonComponentSerializer adventureSerializer = GsonComponentSerializer.builder().build();
JSONOptions.byDataVersion().at(SharedConstants.getCurrentVersion().getDataVersion().getVersion())
).build();
private static final MiniMessage miniMessage = MiniMessage.miniMessage(); private static final MiniMessage miniMessage = MiniMessage.miniMessage();
@@ -97,7 +94,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) {

Some files were not shown because too many files have changed in this diff Show More