Compare commits
2 Commits
41b68d45c5
...
77a44be34b
| Author | SHA1 | Date | |
|---|---|---|---|
| 77a44be34b | |||
| 153d85602c |
@@ -1,5 +1,5 @@
|
||||
plugins {
|
||||
id 'net.fabricmc.fabric-loom' version '1.17-SNAPSHOT'
|
||||
id 'net.fabricmc.fabric-loom' version "${project.loom_version}"
|
||||
id 'maven-publish'
|
||||
}
|
||||
|
||||
@@ -30,8 +30,9 @@ repositories {
|
||||
|
||||
dependencies {
|
||||
minecraft "com.mojang:minecraft:${project.minecraft_version}"
|
||||
implementation "net.fabricmc:fabric-loader:${project.loader_version}"
|
||||
implementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
||||
mappings loom.officialMojangMappings()
|
||||
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
|
||||
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
||||
}
|
||||
|
||||
processResources {
|
||||
|
||||
@@ -11,12 +11,21 @@ import net.minecraft.network.chat.Component;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
public final class ClientIrcMod implements ClientModInitializer {
|
||||
public static final String MOD_ID = "clientirc";
|
||||
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
|
||||
|
||||
private static final String COMMAND_PREFIX = ".irc";
|
||||
|
||||
private static final ExecutorService IO_EXECUTOR = Executors.newSingleThreadExecutor(runnable -> {
|
||||
Thread thread = new Thread(runnable, "clientirc-io");
|
||||
thread.setDaemon(true);
|
||||
return thread;
|
||||
});
|
||||
|
||||
private static IrcConfig config;
|
||||
private static IrcService service;
|
||||
|
||||
@@ -27,10 +36,16 @@ public final class ClientIrcMod implements ClientModInitializer {
|
||||
|
||||
ClientLifecycleEvents.CLIENT_STARTED.register(client -> {
|
||||
if (config.autoConnect) {
|
||||
service.connect(resolvePlayerName(client));
|
||||
String playerName = resolvePlayerName(client);
|
||||
IO_EXECUTOR.execute(() -> service.connect(playerName));
|
||||
}
|
||||
});
|
||||
|
||||
ClientLifecycleEvents.CLIENT_STOPPING.register(client -> {
|
||||
service.disconnect();
|
||||
IO_EXECUTOR.shutdownNow();
|
||||
});
|
||||
|
||||
ClientTickEvents.END_CLIENT_TICK.register(client -> {
|
||||
IrcService.DisplayLine line;
|
||||
while ((line = service.pollLine()) != null) {
|
||||
@@ -63,9 +78,12 @@ public final class ClientIrcMod implements ClientModInitializer {
|
||||
}
|
||||
|
||||
if ("reconnect".equalsIgnoreCase(argument)) {
|
||||
boolean connected = service.reconnect(resolvePlayerName(client));
|
||||
String playerName = resolvePlayerName(client);
|
||||
IO_EXECUTOR.execute(() -> {
|
||||
boolean connected = service.reconnect(playerName);
|
||||
ChatFormatting color = connected ? ChatFormatting.GREEN : ChatFormatting.RED;
|
||||
pushClientChat(client, Component.literal("[IRC] reconnect " + (connected ? "ok" : "failed")).withStyle(color));
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -76,15 +94,16 @@ public final class ClientIrcMod implements ClientModInitializer {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!service.ensureConnected(resolvePlayerName(client))) {
|
||||
String playerName = resolvePlayerName(client);
|
||||
IO_EXECUTOR.execute(() -> {
|
||||
if (!service.ensureConnected(playerName)) {
|
||||
pushClientChat(client, Component.literal("[IRC] server is offline or config is wrong").withStyle(ChatFormatting.RED));
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
boolean sent = service.sendChat(resolvePlayerName(client), argument);
|
||||
if (!sent) {
|
||||
if (!service.sendChat(playerName, argument)) {
|
||||
pushClientChat(client, Component.literal("[IRC] send failed").withStyle(ChatFormatting.RED));
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user