mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-04 06:28:53 +00:00
Setup base for fabric platform
This commit is contained in:
1 parent
35742909dd
commit
fb99ecf235
10 files changed
+399
-4
No files matched your search
@@ -0,0 +1,65 @@
|
|||||||
|
import org.apache.tools.ant.filters.ReplaceTokens
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
id("carbon.shadow-platform")
|
||||||
|
id("quiet-fabric-loom")
|
||||||
|
}
|
||||||
|
|
||||||
|
val carbon: Configuration by configurations.creating
|
||||||
|
|
||||||
|
configurations.implementation {
|
||||||
|
extendsFrom(carbon)
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
minecraft(libs.fabricMinecraft)
|
||||||
|
mappings(minecraft.officialMojangMappings())
|
||||||
|
modImplementation(libs.fabricLoader)
|
||||||
|
|
||||||
|
carbon(projects.carbonchatCommon) {
|
||||||
|
exclude("net.kyori", "adventure-api")
|
||||||
|
}
|
||||||
|
|
||||||
|
modImplementation(libs.cloudFabric)
|
||||||
|
include(libs.cloudFabric)
|
||||||
|
modImplementation(libs.adventurePlatformFabric)
|
||||||
|
include(libs.adventurePlatformFabric)
|
||||||
|
}
|
||||||
|
|
||||||
|
carbonPlatform {
|
||||||
|
jarTask.set(tasks.remapJar)
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks {
|
||||||
|
jar {
|
||||||
|
archiveClassifier.set("dev")
|
||||||
|
}
|
||||||
|
shadowJar {
|
||||||
|
configurations = arrayListOf(carbon) as List<FileCollection>
|
||||||
|
archiveClassifier.set("dev-all")
|
||||||
|
}
|
||||||
|
remapJar {
|
||||||
|
archiveClassifier.set(null as String?)
|
||||||
|
input.set(shadowJar.flatMap { it.archiveFile })
|
||||||
|
}
|
||||||
|
runServer {
|
||||||
|
standardInput = System.`in`
|
||||||
|
}
|
||||||
|
processResources {
|
||||||
|
val props = mapOf(
|
||||||
|
"modId" to rootProject.name.toLowerCase(),
|
||||||
|
"name" to rootProject.name,
|
||||||
|
"version" to project.version,
|
||||||
|
"description" to project.description,
|
||||||
|
"github_url" to GITHUB_REPO_URL
|
||||||
|
)
|
||||||
|
inputs.properties(props)
|
||||||
|
filesMatching("fabric.mod.json") {
|
||||||
|
filter<ReplaceTokens>(
|
||||||
|
"beginToken" to "\${",
|
||||||
|
"endToken" to "}",
|
||||||
|
"tokens" to props
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package net.draycia.carbon.fabric;
|
||||||
|
|
||||||
|
import net.draycia.carbon.fabric.callback.FabricChatCallback;
|
||||||
|
import net.fabricmc.api.ModInitializer;
|
||||||
|
import net.kyori.adventure.platform.fabric.FabricServerAudiences;
|
||||||
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||||
|
|
||||||
|
import static net.kyori.adventure.text.Component.translatable;
|
||||||
|
|
||||||
|
@DefaultQualifier(NonNull.class)
|
||||||
|
public final class CarbonFabricEntry implements ModInitializer {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onInitialize() {
|
||||||
|
FabricChatCallback.setup();
|
||||||
|
|
||||||
|
final FabricChatCallback.Chat.MessageFormatter formatter = (sender, message, viewer) -> translatable(
|
||||||
|
"chat.type.text",
|
||||||
|
FabricServerAudiences.of(sender.server).toAdventure(sender.getDisplayName()),
|
||||||
|
MiniMessage.miniMessage().deserialize(message)
|
||||||
|
);
|
||||||
|
|
||||||
|
FabricChatCallback.INSTANCE.registerListener(chat -> chat.formatter(formatter));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,187 @@
|
|||||||
|
package net.draycia.carbon.fabric.callback;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
|
||||||
|
import net.kyori.adventure.audience.Audience;
|
||||||
|
import net.kyori.adventure.audience.MessageType;
|
||||||
|
import net.kyori.adventure.platform.fabric.FabricServerAudiences;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
import net.minecraft.util.thread.NamedThreadFactory;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||||
|
|
||||||
|
import static net.kyori.adventure.identity.Identity.identity;
|
||||||
|
import static net.kyori.adventure.text.Component.text;
|
||||||
|
import static net.kyori.adventure.text.Component.translatable;
|
||||||
|
|
||||||
|
@DefaultQualifier(NonNull.class)
|
||||||
|
public enum FabricChatCallback {
|
||||||
|
|
||||||
|
INSTANCE;
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LogManager.getLogger();
|
||||||
|
|
||||||
|
private @Nullable ExecutorService chatExecutor;
|
||||||
|
private final List<Consumer<Chat>> listeners = new LinkedList<>();
|
||||||
|
|
||||||
|
public void initExecutor() {
|
||||||
|
this.chatExecutor = Executors.newSingleThreadExecutor(new NamedThreadFactory("CarbonChat-ChatThread"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void shutdownExecutor() {
|
||||||
|
final @Nullable ExecutorService executor = this.chatExecutor;
|
||||||
|
if (executor == null) {
|
||||||
|
LOGGER.warn("Tried to shutdown null executor!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.chatExecutor = null;
|
||||||
|
executor.shutdown();
|
||||||
|
try {
|
||||||
|
if (!executor.awaitTermination(25L, TimeUnit.MILLISECONDS)) {
|
||||||
|
throw new RuntimeException("Timeout elapsed before tasks completed");
|
||||||
|
}
|
||||||
|
} catch (final InterruptedException | RuntimeException ex) {
|
||||||
|
LOGGER.warn("Failed to shutdown chat executor", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void registerListener(final Consumer<Chat> listener) {
|
||||||
|
this.listeners.add(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void fireAsync(final MinecraftServer server, final ServerPlayer sender, final String chat) {
|
||||||
|
final @Nullable ExecutorService executor = this.chatExecutor;
|
||||||
|
if (executor != null) {
|
||||||
|
this.chatExecutor.execute(() -> this.fire(server, sender, chat));
|
||||||
|
} else {
|
||||||
|
LOGGER.error("Tried to fire chat callback for player '{}' with message '{}' when executor was not initialized!", sender.getGameProfile().getName(), chat);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fire(final MinecraftServer server, final ServerPlayer sender, final String chat) {
|
||||||
|
final FabricServerAudiences fabricServerAudiences = FabricServerAudiences.of(server);
|
||||||
|
|
||||||
|
// adventure-platform-fabric's PlayerListMixin makes this safe off main
|
||||||
|
final ChatImpl c = new ChatImpl(sender, chat, server.getPlayerList().getPlayers());
|
||||||
|
for (final Consumer<Chat> listener : this.listeners) {
|
||||||
|
listener.accept(c);
|
||||||
|
}
|
||||||
|
if (c.cancelled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final Chat.MessageFormatter formatter = c.formatter == null ? defaultFormatter() : c.formatter;
|
||||||
|
|
||||||
|
final Audience console = fabricServerAudiences.console();
|
||||||
|
final @Nullable Component msgForConsole = formatter.format(sender, chat, console);
|
||||||
|
if (msgForConsole != null) {
|
||||||
|
console.sendMessage(msgForConsole);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (final ServerPlayer player : c.recipients()) {
|
||||||
|
final @Nullable Component rendered = formatter.format(sender, chat, fabricServerAudiences.audience(player));
|
||||||
|
if (rendered != null) {
|
||||||
|
fabricServerAudiences.audience(player).sendMessage(identity(sender.getUUID()), rendered, MessageType.CHAT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setup() {
|
||||||
|
ServerLifecycleEvents.SERVER_STARTING.register(server -> INSTANCE.initExecutor());
|
||||||
|
ServerLifecycleEvents.SERVER_STOPPED.register(server -> INSTANCE.shutdownExecutor());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Chat.MessageFormatter defaultFormatter() {
|
||||||
|
return new Chat.MessageFormatter() {
|
||||||
|
private @MonotonicNonNull Component rendered;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Component format(final ServerPlayer sender, final String message, final Audience viewer) {
|
||||||
|
if (this.rendered != null) {
|
||||||
|
return this.rendered;
|
||||||
|
}
|
||||||
|
this.rendered = translatable(
|
||||||
|
"chat.type.text",
|
||||||
|
FabricServerAudiences.of(sender.server).toAdventure(sender.getDisplayName()),
|
||||||
|
text(message)
|
||||||
|
);
|
||||||
|
return this.rendered;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface Chat {
|
||||||
|
|
||||||
|
ServerPlayer sender();
|
||||||
|
|
||||||
|
String message();
|
||||||
|
|
||||||
|
void formatter(MessageFormatter formatter);
|
||||||
|
|
||||||
|
void cancel();
|
||||||
|
|
||||||
|
List<ServerPlayer> recipients();
|
||||||
|
|
||||||
|
interface MessageFormatter {
|
||||||
|
|
||||||
|
@Nullable Component format(ServerPlayer sender, String message, Audience viewer);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final class ChatImpl implements Chat {
|
||||||
|
|
||||||
|
private final ServerPlayer sender;
|
||||||
|
private final String message;
|
||||||
|
private boolean cancelled = false;
|
||||||
|
private @Nullable MessageFormatter formatter = null;
|
||||||
|
private final List<ServerPlayer> recipients;
|
||||||
|
|
||||||
|
private ChatImpl(final ServerPlayer sender, final String message, final List<ServerPlayer> players) {
|
||||||
|
this.sender = sender;
|
||||||
|
this.message = message;
|
||||||
|
this.recipients = new ArrayList<>(players);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ServerPlayer sender() {
|
||||||
|
return this.sender;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String message() {
|
||||||
|
return this.message;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void formatter(final MessageFormatter formatter) {
|
||||||
|
this.formatter = formatter;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void cancel() {
|
||||||
|
this.cancelled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ServerPlayer> recipients() {
|
||||||
|
return this.recipients;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+43
@@ -0,0 +1,43 @@
|
|||||||
|
package net.draycia.carbon.fabric.mixin;
|
||||||
|
|
||||||
|
import net.draycia.carbon.fabric.callback.FabricChatCallback;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||||
|
import org.spongepowered.asm.mixin.Final;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||||
|
|
||||||
|
@Mixin(ServerGamePacketListenerImpl.class)
|
||||||
|
abstract class ServerGamePacketListenerImplMixin {
|
||||||
|
|
||||||
|
@Shadow
|
||||||
|
protected abstract void handleCommand(String string);
|
||||||
|
|
||||||
|
@Shadow @Final private MinecraftServer server;
|
||||||
|
|
||||||
|
@Shadow public ServerPlayer player;
|
||||||
|
|
||||||
|
@Redirect(
|
||||||
|
method = "handleChat(Lnet/minecraft/server/network/TextFilter$FilteredText;)V",
|
||||||
|
at = @At(value = "INVOKE", target = "Ljava/lang/String;startsWith(Ljava/lang/String;)Z")
|
||||||
|
)
|
||||||
|
public boolean redirectStartsWith(final String string, final String prefix) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Redirect(
|
||||||
|
method = "handleChat(Lnet/minecraft/server/network/TextFilter$FilteredText;)V",
|
||||||
|
at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerGamePacketListenerImpl;handleCommand(Ljava/lang/String;)V")
|
||||||
|
)
|
||||||
|
public void redirectHandleCommand(final ServerGamePacketListenerImpl serverGamePacketListener, final String string) {
|
||||||
|
if (string.startsWith("/")) {
|
||||||
|
this.handleCommand(string);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
FabricChatCallback.INSTANCE.fireAsync(this.server, this.player, string);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"required": true,
|
||||||
|
"minVersion": "0.8.4",
|
||||||
|
"package": "net.draycia.carbon.fabric.mixin",
|
||||||
|
"compatibilityLevel": "JAVA_16",
|
||||||
|
"mixins": [
|
||||||
|
"ServerGamePacketListenerImplMixin"
|
||||||
|
],
|
||||||
|
"client": [
|
||||||
|
],
|
||||||
|
"injectors": {
|
||||||
|
"defaultRequire": 1
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
{
|
||||||
|
"schemaVersion": 1,
|
||||||
|
"id": "${modId}",
|
||||||
|
"version": "${version}",
|
||||||
|
"name": "${name}",
|
||||||
|
"description": "${description}",
|
||||||
|
"authors": [
|
||||||
|
"Draycia"
|
||||||
|
],
|
||||||
|
"contact": {
|
||||||
|
"homepage": "${github_url}",
|
||||||
|
"sources": "${github_url}",
|
||||||
|
"issues": "${github_url}/issues"
|
||||||
|
},
|
||||||
|
"license": "GPLv3",
|
||||||
|
"environment": "server",
|
||||||
|
"entrypoints": {
|
||||||
|
"main": [
|
||||||
|
"net.draycia.carbon.fabric.CarbonFabricEntry"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"mixins": [
|
||||||
|
"carbonchat.mixins.json"
|
||||||
|
],
|
||||||
|
"depends": {
|
||||||
|
"fabricloader": ">=0.12.5",
|
||||||
|
"fabric": ">=0.31.0",
|
||||||
|
"minecraft": ">=1.17"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,3 +5,4 @@ projectVersion=2.0.0-SNAPSHOT
|
|||||||
org.gradle.configureondemand=true
|
org.gradle.configureondemand=true
|
||||||
org.gradle.caching=true
|
org.gradle.caching=true
|
||||||
org.gradle.parallel=true
|
org.gradle.parallel=true
|
||||||
|
org.gradle.jvmargs=-Xmx2G
|
||||||
@@ -12,12 +12,12 @@ plugins:
|
|||||||
versions:
|
versions:
|
||||||
indra: 2.0.5
|
indra: 2.0.5
|
||||||
shadow: 7.1.0
|
shadow: 7.1.0
|
||||||
adventure: 4.9.2
|
adventure: 4.9.3
|
||||||
minimessage: 4.2.0-SNAPSHOT
|
minimessage: 4.2.0-SNAPSHOT
|
||||||
cloud: 1.6.0-SNAPSHOT
|
cloud: 1.6.0-SNAPSHOT
|
||||||
configurate: 4.1.2
|
configurate: 4.1.2
|
||||||
typesafeConfig: 1.4.1
|
typesafeConfig: 1.4.1
|
||||||
checkerQual: 3.18.1
|
checkerQual: 3.19.0
|
||||||
stylecheck: 0.1
|
stylecheck: 0.1
|
||||||
gson: 2.8.0
|
gson: 2.8.0
|
||||||
guava: 30.1-jre
|
guava: 30.1-jre
|
||||||
@@ -27,10 +27,13 @@ versions:
|
|||||||
kyoriEventApi: 5.0.0-SNAPSHOT
|
kyoriEventApi: 5.0.0-SNAPSHOT
|
||||||
kyoriRegistry: 1.0.0-SNAPSHOT
|
kyoriRegistry: 1.0.0-SNAPSHOT
|
||||||
kyoriMoonshine: 2.0.0-SNAPSHOT
|
kyoriMoonshine: 2.0.0-SNAPSHOT
|
||||||
log4j: 2.11.2
|
log4j: 2.14.1
|
||||||
guice: 5.0.1
|
guice: 5.0.1
|
||||||
velocityApi: 3.0.1
|
velocityApi: 3.0.1
|
||||||
geantyref: 1.3.11
|
geantyref: 1.3.11
|
||||||
|
fabricMinecraft: 1.17.1
|
||||||
|
fabricLoader: 0.12.5
|
||||||
|
adventurePlatformFabric: 4.1.0-SNAPSHOT
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
adventureBom:
|
adventureBom:
|
||||||
@@ -57,6 +60,10 @@ dependencies:
|
|||||||
group: net.kyori
|
group: net.kyori
|
||||||
name: adventure-text-minimessage
|
name: adventure-text-minimessage
|
||||||
version: { ref: minimessage }
|
version: { ref: minimessage }
|
||||||
|
adventurePlatformFabric:
|
||||||
|
group: net.kyori
|
||||||
|
name: adventure-platform-fabric
|
||||||
|
version: { ref: adventurePlatformFabric }
|
||||||
|
|
||||||
geantyref:
|
geantyref:
|
||||||
group: io.leangen.geantyref
|
group: io.leangen.geantyref
|
||||||
@@ -111,6 +118,10 @@ dependencies:
|
|||||||
cloudVelocity:
|
cloudVelocity:
|
||||||
group: cloud.commandframework
|
group: cloud.commandframework
|
||||||
name: cloud-velocity
|
name: cloud-velocity
|
||||||
|
cloudFabric:
|
||||||
|
group: cloud.commandframework
|
||||||
|
name: cloud-fabric
|
||||||
|
version: { ref: cloud }
|
||||||
|
|
||||||
configurateCore:
|
configurateCore:
|
||||||
group: org.spongepowered
|
group: org.spongepowered
|
||||||
@@ -171,6 +182,15 @@ dependencies:
|
|||||||
name: velocity-api
|
name: velocity-api
|
||||||
version: { ref: velocityApi }
|
version: { ref: velocityApi }
|
||||||
|
|
||||||
|
fabricMinecraft:
|
||||||
|
group: com.mojang
|
||||||
|
name: minecraft
|
||||||
|
version: { ref: fabricMinecraft }
|
||||||
|
fabricLoader:
|
||||||
|
group: net.fabricmc
|
||||||
|
name: fabric-loader
|
||||||
|
version: { ref: fabricLoader }
|
||||||
|
|
||||||
# for build-logic
|
# for build-logic
|
||||||
indraCommon:
|
indraCommon:
|
||||||
group: net.kyori
|
group: net.kyori
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
@@ -38,11 +38,17 @@ dependencyResolutionManagement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pluginManagement {
|
pluginManagement {
|
||||||
|
repositories {
|
||||||
|
gradlePluginPortal()
|
||||||
|
maven("https://maven.fabricmc.net/")
|
||||||
|
maven("https://repo.jpenilla.xyz/snapshots/")
|
||||||
|
}
|
||||||
includeBuild("build-logic")
|
includeBuild("build-logic")
|
||||||
}
|
}
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id("ca.stellardrift.polyglot-version-catalogs") version "5.0.0"
|
id("ca.stellardrift.polyglot-version-catalogs") version "5.0.0"
|
||||||
|
id("quiet-fabric-loom") version "0.8-SNAPSHOT"
|
||||||
}
|
}
|
||||||
|
|
||||||
rootProject.name = "CarbonChat"
|
rootProject.name = "CarbonChat"
|
||||||
@@ -52,6 +58,7 @@ sequenceOf(
|
|||||||
"common",
|
"common",
|
||||||
"bukkit",
|
"bukkit",
|
||||||
"sponge",
|
"sponge",
|
||||||
|
"fabric",
|
||||||
"velocity"
|
"velocity"
|
||||||
).forEach {
|
).forEach {
|
||||||
include("carbonchat-$it")
|
include("carbonchat-$it")
|
||||||
|
|||||||
Reference in new issue
Block a user