Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5aaa3c2ace | ||
|
|
41fcc82953 | ||
|
|
8057fa1112 | ||
|
|
8f989ee135 | ||
|
|
a67ec47f89 | ||
|
|
d1c6504973 | ||
|
|
939505c861 |
14
build.gradle
14
build.gradle
@@ -63,11 +63,17 @@ tasks.register('containerJar', Jar) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. Fabric nested jars (Fabric Loader 가 META-INF/jars/ 를 스캔해서
|
// 3. Fabric nested jars. Fabric Loader 는 META-INF/jars/ 를 자동 스캔하지
|
||||||
// depends.minecraft 매칭되는 jar 만 활성화).
|
// 않고 outer fabric.mod.json 의 "jars" 배열에 명시된 파일만 처리하므로,
|
||||||
|
// container-resources/fabric.mod.json 의 jars 항목과 일치하는 고정 파일명
|
||||||
|
// (버전 suffix 제거) 으로 넣는다.
|
||||||
into('META-INF/jars') {
|
into('META-INF/jars') {
|
||||||
from project(':fabric-1216').tasks.named('remapJar').flatMap { it.archiveFile }
|
from(project(':fabric-1216').tasks.named('remapJar').flatMap { it.archiveFile }) {
|
||||||
from project(':fabric-2612').tasks.named('remapJar').flatMap { it.archiveFile }
|
rename '.+\\.jar', 'chat_answer-fabric-1216.jar'
|
||||||
|
}
|
||||||
|
from(project(':fabric-2612').tasks.named('remapJar').flatMap { it.archiveFile }) {
|
||||||
|
rename '.+\\.jar', 'chat_answer-fabric-2612.jar'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
package kr.tkrmagid.chatanswer.core;
|
package kr.tkrmagid.chatanswer.core;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
@@ -29,25 +33,78 @@ public final class ChatAnswerCore {
|
|||||||
private static final String SCOREBOARD_HOLDER = "init";
|
private static final String SCOREBOARD_HOLDER = "init";
|
||||||
private static final int ACCEPTING_ANSWER_STATE = 5;
|
private static final int ACCEPTING_ANSWER_STATE = 5;
|
||||||
|
|
||||||
|
/** 음악퀴즈 데이터팩이 선언한 "모드 존재 확인" 점수 이름.
|
||||||
|
* 본 모드는 서버 측에서 채팅을 가로채는 server-only 모드 — 클라이언트는
|
||||||
|
* 설치할 필요가 없고 server 한 곳에 있으면 모든 플레이어에게 적용된다.
|
||||||
|
* 따라서 per-player 검증은 무의미하고, fake player {@link #PRESENCE_HOLDER}
|
||||||
|
* 점수만 매 server tick 마다 1 로 set 한다. 데이터팩의 start 가드는
|
||||||
|
* `score <PRESENCE_HOLDER> <OBJECTIVE> matches 1` 로 검사. */
|
||||||
|
private static final String MOD_PRESENCE_OBJECTIVE = "mq_chat_mod";
|
||||||
|
private static final String PRESENCE_HOLDER = "#server";
|
||||||
|
|
||||||
|
/** JOIN 이벤트 시점엔 클라이언트가 chat HUD 를 받을 준비가 안 됐을 수 있어
|
||||||
|
* tellraw 패킷이 사라지는 경우가 있다. 그래서 N 틱 늦춰서 호출한다. */
|
||||||
|
private static final int NOTICE_DELAY_TICKS = 20;
|
||||||
|
private static final Map<UUID, Integer> PENDING_NOTICES = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
private ChatAnswerCore() {}
|
private ChatAnswerCore() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 플레이어 로그인 직후 호출. 데이터팩이 "모드 살아있음" 신호로 쓸 수 있게
|
* 플레이어 로그인 시점에 호출. 음악퀴즈 데이터팩의
|
||||||
* storage chat_answer:status 에 active=1b 를 세팅한다. 데이터팩의 mq:load 가
|
* mq:players/mod_active_notice
|
||||||
* 매 /reload 와 서버 시작 시 이 값을 0b 로 clear 하므로, 모드가 없으면 이
|
* 함수를 해당 플레이어 컨텍스트로 호출한다. 단, JOIN 이벤트가 너무 일러서
|
||||||
* 호출이 일어나지 않아 0b 로 유지되고, 모드가 있으면 첫 로그인 직후 1b 로 갱신.
|
* 즉시 호출 시 tellraw 가 클라이언트에 도달하지 못하는 race 가 있어
|
||||||
|
* {@link #NOTICE_DELAY_TICKS} 만큼 늦춘다 ({@link #onServerTick} 가 처리).
|
||||||
*/
|
*/
|
||||||
public static void onPlayerJoin(ServerPlayer player) {
|
public static void onPlayerJoin(ServerPlayer player) {
|
||||||
MinecraftServer server = player.level().getServer();
|
String name = player.getName().getString();
|
||||||
if (server == null) return;
|
LOG.info("[{}] onPlayerJoin fired for {}, scheduling notice in {} ticks",
|
||||||
CommandSourceStack source = server.createCommandSourceStack().withSuppressedOutput();
|
MOD_ID, name, NOTICE_DELAY_TICKS);
|
||||||
|
PENDING_NOTICES.put(player.getUUID(), NOTICE_DELAY_TICKS);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 각 로더 entrypoint 가 매 server tick 마다 호출해야 한다. */
|
||||||
|
public static void onServerTick(MinecraftServer server) {
|
||||||
|
markModPresence(server);
|
||||||
|
if (PENDING_NOTICES.isEmpty()) return;
|
||||||
|
Iterator<Map.Entry<UUID, Integer>> it = PENDING_NOTICES.entrySet().iterator();
|
||||||
|
while (it.hasNext()) {
|
||||||
|
Map.Entry<UUID, Integer> e = it.next();
|
||||||
|
int remaining = e.getValue() - 1;
|
||||||
|
if (remaining > 0) {
|
||||||
|
e.setValue(remaining);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
UUID uuid = e.getKey();
|
||||||
|
it.remove();
|
||||||
|
ServerPlayer player = server.getPlayerList().getPlayer(uuid);
|
||||||
|
if (player == null) continue;
|
||||||
|
deliverNotice(server, player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 데이터팩의 mq_chat_mod 점수(fake player #server 키) 를 1 로 set.
|
||||||
|
* 데이터팩이 아직 load 되지 않아 objective 가 없으면 조용히 skip.
|
||||||
|
* 점수 값이 이미 1 이면 Minecraft 가 packet 전송을 생략하므로
|
||||||
|
* 매 tick 호출해도 트래픽은 늘지 않는다.
|
||||||
|
*/
|
||||||
|
private static void markModPresence(MinecraftServer server) {
|
||||||
|
Scoreboard scoreboard = server.getScoreboard();
|
||||||
|
Objective objective = scoreboard.getObjective(MOD_PRESENCE_OBJECTIVE);
|
||||||
|
if (objective == null) return;
|
||||||
|
scoreboard.getOrCreatePlayerScore(ScoreHolder.forNameOnly(PRESENCE_HOLDER), objective).set(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void deliverNotice(MinecraftServer server, ServerPlayer player) {
|
||||||
|
String name = player.getName().getString();
|
||||||
|
// 플레이어 자체를 source 로 써서 함수 안의 @s 가 그대로 player.
|
||||||
|
CommandSourceStack source = player.createCommandSourceStack().withSuppressedOutput();
|
||||||
try {
|
try {
|
||||||
server.getCommands().performPrefixedCommand(
|
server.getCommands().performPrefixedCommand(source, "function mq:players/mod_active_notice");
|
||||||
source,
|
LOG.info("[{}] mod_active_notice delivered for {}", MOD_ID, name);
|
||||||
"data modify storage chat_answer:status active set value 1b"
|
|
||||||
);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOG.debug("[{}] failed to set active flag: {}", MOD_ID, e.toString());
|
LOG.warn("[{}] failed to deliver mod_active_notice for {}: {}", MOD_ID, name, e.toString(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,10 @@
|
|||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"icon": "assets/chat_answer/icon.png",
|
"icon": "assets/chat_answer/icon.png",
|
||||||
"environment": "*",
|
"environment": "*",
|
||||||
|
"jars": [
|
||||||
|
{ "file": "META-INF/jars/chat_answer-fabric-1216.jar" },
|
||||||
|
{ "file": "META-INF/jars/chat_answer-fabric-2612.jar" }
|
||||||
|
],
|
||||||
"depends": {
|
"depends": {
|
||||||
"fabricloader": ">=0.16.0",
|
"fabricloader": ">=0.16.0",
|
||||||
"java": ">=21"
|
"java": ">=21"
|
||||||
|
|||||||
@@ -2,17 +2,30 @@ package kr.tkrmagid.chatanswer.fabric;
|
|||||||
|
|
||||||
import kr.tkrmagid.chatanswer.core.ChatAnswerCore;
|
import kr.tkrmagid.chatanswer.core.ChatAnswerCore;
|
||||||
import net.fabricmc.api.ModInitializer;
|
import net.fabricmc.api.ModInitializer;
|
||||||
|
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
|
||||||
import net.fabricmc.fabric.api.message.v1.ServerMessageEvents;
|
import net.fabricmc.fabric.api.message.v1.ServerMessageEvents;
|
||||||
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
|
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
public final class ChatAnswerFabric implements ModInitializer {
|
public final class ChatAnswerFabric implements ModInitializer {
|
||||||
|
private static final Logger LOG = LoggerFactory.getLogger(ChatAnswerCore.MOD_ID);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInitialize() {
|
public void onInitialize() {
|
||||||
ServerMessageEvents.ALLOW_CHAT_MESSAGE.register((message, sender, params) ->
|
LOG.info("[{}] Fabric entrypoint onInitialize starting", ChatAnswerCore.MOD_ID);
|
||||||
ChatAnswerCore.handleChat(sender, message.signedContent())
|
try {
|
||||||
);
|
ServerMessageEvents.ALLOW_CHAT_MESSAGE.register((message, sender, params) ->
|
||||||
ServerPlayConnectionEvents.JOIN.register((handler, sender, server) ->
|
ChatAnswerCore.handleChat(sender, message.signedContent())
|
||||||
ChatAnswerCore.onPlayerJoin(handler.player)
|
);
|
||||||
);
|
ServerPlayConnectionEvents.JOIN.register((handler, sender, server) ->
|
||||||
|
ChatAnswerCore.onPlayerJoin(handler.player)
|
||||||
|
);
|
||||||
|
ServerTickEvents.END_SERVER_TICK.register(ChatAnswerCore::onServerTick);
|
||||||
|
LOG.info("[{}] Fabric entrypoint registered: ALLOW_CHAT_MESSAGE + JOIN + TICK", ChatAnswerCore.MOD_ID);
|
||||||
|
} catch (Throwable t) {
|
||||||
|
LOG.error("[{}] Fabric entrypoint event registration failed", ChatAnswerCore.MOD_ID, t);
|
||||||
|
throw t;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,17 +2,30 @@ package kr.tkrmagid.chatanswer.fabric;
|
|||||||
|
|
||||||
import kr.tkrmagid.chatanswer.core.ChatAnswerCore;
|
import kr.tkrmagid.chatanswer.core.ChatAnswerCore;
|
||||||
import net.fabricmc.api.ModInitializer;
|
import net.fabricmc.api.ModInitializer;
|
||||||
|
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
|
||||||
import net.fabricmc.fabric.api.message.v1.ServerMessageEvents;
|
import net.fabricmc.fabric.api.message.v1.ServerMessageEvents;
|
||||||
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
|
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
public final class ChatAnswerFabric implements ModInitializer {
|
public final class ChatAnswerFabric implements ModInitializer {
|
||||||
|
private static final Logger LOG = LoggerFactory.getLogger(ChatAnswerCore.MOD_ID);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInitialize() {
|
public void onInitialize() {
|
||||||
ServerMessageEvents.ALLOW_CHAT_MESSAGE.register((message, sender, params) ->
|
LOG.info("[{}] Fabric entrypoint onInitialize starting", ChatAnswerCore.MOD_ID);
|
||||||
ChatAnswerCore.handleChat(sender, message.signedContent())
|
try {
|
||||||
);
|
ServerMessageEvents.ALLOW_CHAT_MESSAGE.register((message, sender, params) ->
|
||||||
ServerPlayConnectionEvents.JOIN.register((handler, sender, server) ->
|
ChatAnswerCore.handleChat(sender, message.signedContent())
|
||||||
ChatAnswerCore.onPlayerJoin(handler.player)
|
);
|
||||||
);
|
ServerPlayConnectionEvents.JOIN.register((handler, sender, server) ->
|
||||||
|
ChatAnswerCore.onPlayerJoin(handler.player)
|
||||||
|
);
|
||||||
|
ServerTickEvents.END_SERVER_TICK.register(ChatAnswerCore::onServerTick);
|
||||||
|
LOG.info("[{}] Fabric entrypoint registered: ALLOW_CHAT_MESSAGE + JOIN + TICK", ChatAnswerCore.MOD_ID);
|
||||||
|
} catch (Throwable t) {
|
||||||
|
LOG.error("[{}] Fabric entrypoint event registration failed", ChatAnswerCore.MOD_ID, t);
|
||||||
|
throw t;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ org.gradle.parallel=true
|
|||||||
|
|
||||||
# ───── mod metadata ─────────────────────────────────────────────────────────
|
# ───── mod metadata ─────────────────────────────────────────────────────────
|
||||||
mod_id=chat_answer
|
mod_id=chat_answer
|
||||||
mod_version=1.3.0
|
mod_version=1.3.5
|
||||||
mod_group=kr.tkrmagid.chatanswer
|
mod_group=kr.tkrmagid.chatanswer
|
||||||
mod_name=채팅정답
|
mod_name=채팅정답
|
||||||
|
|
||||||
|
|||||||
@@ -8,12 +8,14 @@ import net.neoforged.fml.common.Mod;
|
|||||||
import net.neoforged.neoforge.common.NeoForge;
|
import net.neoforged.neoforge.common.NeoForge;
|
||||||
import net.neoforged.neoforge.event.ServerChatEvent;
|
import net.neoforged.neoforge.event.ServerChatEvent;
|
||||||
import net.neoforged.neoforge.event.entity.player.PlayerEvent;
|
import net.neoforged.neoforge.event.entity.player.PlayerEvent;
|
||||||
|
import net.neoforged.neoforge.event.tick.ServerTickEvent;
|
||||||
|
|
||||||
@Mod(ChatAnswerCore.MOD_ID)
|
@Mod(ChatAnswerCore.MOD_ID)
|
||||||
public final class ChatAnswerNeoForge {
|
public final class ChatAnswerNeoForge {
|
||||||
public ChatAnswerNeoForge(IEventBus modBus) {
|
public ChatAnswerNeoForge(IEventBus modBus) {
|
||||||
NeoForge.EVENT_BUS.addListener(ChatAnswerNeoForge::onServerChat);
|
NeoForge.EVENT_BUS.addListener(ChatAnswerNeoForge::onServerChat);
|
||||||
NeoForge.EVENT_BUS.addListener(ChatAnswerNeoForge::onPlayerLogin);
|
NeoForge.EVENT_BUS.addListener(ChatAnswerNeoForge::onPlayerLogin);
|
||||||
|
NeoForge.EVENT_BUS.addListener(ChatAnswerNeoForge::onServerTick);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
@@ -30,4 +32,9 @@ public final class ChatAnswerNeoForge {
|
|||||||
ChatAnswerCore.onPlayerJoin(player);
|
ChatAnswerCore.onPlayerJoin(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void onServerTick(ServerTickEvent.Post event) {
|
||||||
|
ChatAnswerCore.onServerTick(event.getServer());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user