2022-06-10 02:53:23 +02:00
|
|
|
package com.falsepattern.lib.internal.proxy;
|
|
|
|
|
|
|
|
|
|
import com.falsepattern.lib.internal.FalsePatternLib;
|
2022-06-10 12:43:03 +02:00
|
|
|
import com.falsepattern.lib.internal.Tags;
|
|
|
|
|
import com.falsepattern.lib.updates.UpdateChecker;
|
2022-06-19 22:42:52 +02:00
|
|
|
import cpw.mods.fml.client.IModGuiFactory;
|
2022-06-10 02:53:23 +02:00
|
|
|
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
|
|
|
|
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
|
|
|
|
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
|
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
|
|
|
|
import lombok.val;
|
|
|
|
|
import net.minecraft.client.entity.EntityPlayerSP;
|
|
|
|
|
import net.minecraft.util.IChatComponent;
|
|
|
|
|
import net.minecraftforge.common.MinecraftForge;
|
|
|
|
|
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
|
|
|
|
|
|
2022-06-19 22:42:52 +02:00
|
|
|
import java.util.Collections;
|
2022-06-10 02:53:23 +02:00
|
|
|
import java.util.List;
|
2022-06-19 22:42:52 +02:00
|
|
|
import java.util.concurrent.CompletableFuture;
|
2022-06-10 02:53:23 +02:00
|
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
|
public class ClientProxy extends CommonProxy {
|
2022-06-19 22:42:52 +02:00
|
|
|
private CompletableFuture<List<IChatComponent>> chatFuture;
|
2022-06-10 02:53:23 +02:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void preInit(FMLPreInitializationEvent e) {
|
|
|
|
|
super.preInit(e);
|
|
|
|
|
MinecraftForge.EVENT_BUS.register(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void postInit(FMLPostInitializationEvent e) {
|
|
|
|
|
super.postInit(e);
|
2022-06-19 22:42:52 +02:00
|
|
|
chatFuture = updatesFuture.handleAsync((updates, exception) -> {
|
|
|
|
|
if (exception != null || updates.isEmpty()) {
|
|
|
|
|
return Collections.emptyList();
|
2022-06-10 02:53:23 +02:00
|
|
|
}
|
2022-06-19 22:42:52 +02:00
|
|
|
return UpdateChecker.updateListToChatMessages(Tags.MODNAME, updates);
|
2022-06-10 02:53:23 +02:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
|
public void onSinglePlayer(EntityJoinWorldEvent e) {
|
|
|
|
|
if (chatFuture == null ||
|
|
|
|
|
!(e.entity instanceof EntityPlayerSP)) return;
|
|
|
|
|
val player = (EntityPlayerSP) e.entity;
|
|
|
|
|
try {
|
2022-06-19 22:42:52 +02:00
|
|
|
for (val line: chatFuture.get()) {
|
2022-06-10 02:53:23 +02:00
|
|
|
player.addChatMessage(line);
|
|
|
|
|
}
|
|
|
|
|
chatFuture = null;
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
FalsePatternLib.getLog().warn(ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|