Fix error when no player in server

This commit is contained in:
mlus 2025-06-06 12:59:52 +08:00
parent a774688d45
commit d766febb11
3 changed files with 33 additions and 3 deletions

View File

@ -34,7 +34,7 @@ mod_name=PlayerSync
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=GPL-3.0 license
# The mod version. See https://semver.org/
mod_version=2.1.2
mod_version=2.1.3
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
# This should match the base package used for the mod sources.
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html

View File

@ -0,0 +1,28 @@
package vip.fubuki.playersync;
import com.mojang.brigadier.CommandDispatcher;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraftforge.event.RegisterCommandsEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import vip.fubuki.playersync.sync.chat.ChatSyncClient;
@Mod.EventBusSubscriber()
public class CommandInit {
@SubscribeEvent
public static void registerCommand(RegisterCommandsEvent event){
CommandDispatcher<CommandSourceStack> dispatcher=event.getDispatcher();
dispatcher.register(Commands.literal("playersync")
.requires(cs->cs.hasPermission(2))
.then(Commands.literal("reconnect")
.executes(context -> {
new ChatSyncClient().run();
// context.getSource().sendSuccess(()->MutableComponent.create(new TranslatableContents("playersync.command.reconnect")),true);
return 0;
}
))
);
}
}

View File

@ -32,7 +32,9 @@ public class ChatSyncClient {
while ((serverMessage = in.readLine()) != null) {
PlayerSync.LOGGER.info("Received message from chat server: " + serverMessage);
Component textComponents = Component.nullToEmpty(serverMessage);
playerList.broadcastSystemMessage(textComponents,false);
if(playerList!=null){
playerList.broadcastSystemMessage(textComponents,false);
}
}
} catch (IOException e) {
e.printStackTrace();
@ -40,7 +42,7 @@ public class ChatSyncClient {
}
}
private static void reconnectClient() {
private void reconnectClient() {
ChatSync.LOGGER.warn("TODO: implement reconnectClient()");
//TODO
}