From 68aa0e31046292fd95921598dd6c26b4d654bb60 Mon Sep 17 00:00:00 2001 From: kirillsaint Date: Tue, 4 Jul 2023 16:14:24 +0600 Subject: [PATCH] Fix --- .../java/net/silentclient/client/Client.java | 14 ++++++++++++++ .../cosmetics/StaticResourceLocation.java | 4 ++++ .../net/silentclient/client/gui/GuiNews.java | 12 +++++++----- .../client/gui/minecraft/GuiMainMenu.java | 11 ++++++----- .../client/gui/util/RenderUtil.java | 2 +- .../client/utils/SCTextureManager.java | 14 ++++++++++---- .../client/utils/types/NewsResponse.java | 19 +++++++++++++++++++ 7 files changed, 61 insertions(+), 15 deletions(-) create mode 100644 src/main/java/net/silentclient/client/utils/types/NewsResponse.java diff --git a/src/main/java/net/silentclient/client/Client.java b/src/main/java/net/silentclient/client/Client.java index 3103ed5..13a6a40 100644 --- a/src/main/java/net/silentclient/client/Client.java +++ b/src/main/java/net/silentclient/client/Client.java @@ -15,6 +15,7 @@ import net.silentclient.client.event.impl.ConnectToServerEvent; import net.silentclient.client.event.impl.ServerLeaveEvent; import net.silentclient.client.event.impl.SingleplayerJoinEvent; import net.silentclient.client.gui.GuiError; +import net.silentclient.client.gui.GuiNews; import net.silentclient.client.gui.clickgui.ClickGUI; import net.silentclient.client.gui.font.SilentFontRenderer; import net.silentclient.client.gui.util.BackgroundPanorama; @@ -250,6 +251,19 @@ public class Client { Client.logger.info("STARTING > launching-detector"); Requests.post("https://api.silentclient.net/_next/launch_v2", new JSONObject().put("branch", getBuildData().getBranch()).toString()); + + logger.info("STARTING > news"); + String content = Requests.get("https://api.silentclient.net/_next/news/latest"); + + if(content != null) { + try { + NewsResponse newsResponse = getGson().fromJson(content, NewsResponse.class); + + GuiNews.news = newsResponse; + } catch (Exception err) { + logger.catching(err); + } + } } catch(Exception err) { logger.info("STARTING > ERROR: " + err.getMessage()); throw err; diff --git a/src/main/java/net/silentclient/client/cosmetics/StaticResourceLocation.java b/src/main/java/net/silentclient/client/cosmetics/StaticResourceLocation.java index 90024a8..d291ff8 100644 --- a/src/main/java/net/silentclient/client/cosmetics/StaticResourceLocation.java +++ b/src/main/java/net/silentclient/client/cosmetics/StaticResourceLocation.java @@ -6,6 +6,10 @@ import net.minecraft.util.ResourceLocation; public class StaticResourceLocation { private ResourceLocation location; + public StaticResourceLocation(ResourceLocation location) { + this.location = location; + } + public StaticResourceLocation(String path) { this.location = new ResourceLocation(path); } diff --git a/src/main/java/net/silentclient/client/gui/GuiNews.java b/src/main/java/net/silentclient/client/gui/GuiNews.java index 6bc7414..424c743 100644 --- a/src/main/java/net/silentclient/client/gui/GuiNews.java +++ b/src/main/java/net/silentclient/client/gui/GuiNews.java @@ -15,6 +15,7 @@ import net.silentclient.client.gui.minecraft.GuiMainMenu; import net.silentclient.client.gui.util.RenderUtil; import net.silentclient.client.utils.SCTextureManager; import net.silentclient.client.utils.TimerUtils; +import net.silentclient.client.utils.types.NewsResponse; import java.awt.image.BufferedImage; import java.io.IOException; @@ -29,6 +30,7 @@ public class GuiNews extends GuiScreen { private TimerUtils logoTimer = new TimerUtils(); private int logoY = 0; private final boolean firstTime; + public static NewsResponse news; public GuiNews() { this.firstTime = false; @@ -40,11 +42,11 @@ public class GuiNews extends GuiScreen { @Override public void drawScreen(int mouseX, int mouseY, float partialTicks) { - if(image == null && !loading) { + if(image == null && !loading && news != null) { loading = true; (new Thread("NewsThread") { public void run() { - GuiNews.image = SCTextureManager.getImage("https://i.imgur.com/jdEAKN6.png"); + GuiNews.image = SCTextureManager.getImage(news.getItem().getCover()); GuiNews.loading = false; } }).start(); @@ -60,7 +62,7 @@ public class GuiNews extends GuiScreen { GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); if(imageLocation != null) { - RenderUtil.drawImage(imageLocation, (this.width / 2) - (300 / 2), (this.height / 2) - (168 / 2) - 10, 300, 168); + RenderUtil.drawImage(imageLocation, (this.width / 2) - (300 / 2), (this.height / 2) - (168 / 2) - 10, 300, 168, false); } super.drawScreen(mouseX, mouseY, partialTicks); @@ -94,11 +96,11 @@ public class GuiNews extends GuiScreen { @Override protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { super.mouseClicked(mouseX, mouseY, mouseButton); - if(MouseUtils.isInside(mouseX, mouseY, (this.width / 2) - (300 / 2), (this.height / 2) - (168 / 2) - 10, 300, 168)) { + if(MouseUtils.isInside(mouseX, mouseY, (this.width / 2) - (300 / 2), (this.height / 2) - (168 / 2) - 10, 300, 168) && news != null) { try { Class oclass = Class.forName("java.awt.Desktop"); Object object = oclass.getMethod("getDesktop", new Class[0]).invoke((Object)null, new Object[0]); - oclass.getMethod("browse", new Class[] {URI.class}).invoke(object, new Object[] {new URI("https://silentclient.net/news/latest")}); + oclass.getMethod("browse", new Class[] {URI.class}).invoke(object, new Object[] {new URI("https://silentclient.net/news/" + GuiNews.news.getItem().id)}); } catch (Throwable err) { err.printStackTrace(); } diff --git a/src/main/java/net/silentclient/client/gui/minecraft/GuiMainMenu.java b/src/main/java/net/silentclient/client/gui/minecraft/GuiMainMenu.java index 2e1cc51..49cb6a0 100644 --- a/src/main/java/net/silentclient/client/gui/minecraft/GuiMainMenu.java +++ b/src/main/java/net/silentclient/client/gui/minecraft/GuiMainMenu.java @@ -321,7 +321,6 @@ public class GuiMainMenu extends GuiScreen implements GuiYesNoCallback float f = 1.8F - MathHelper.abs(MathHelper.sin((float)(Minecraft.getSystemTime() % 1000L) / 1000.0F * (float)Math.PI * 2.0F) * 0.1F); f = f * 100.0F / (float)(this.fontRendererObj.getStringWidth(this.splashText) + 32); GlStateManager.scale(f, f, f); -// this.drawCenteredString(this.fontRendererObj, this.splashText, 0, -8, -256); GlStateManager.popMatrix(); String s = "Silent Client 1.8.9"; @@ -332,8 +331,10 @@ public class GuiMainMenu extends GuiScreen implements GuiYesNoCallback Client.getInstance().getSilentFontRenderer().drawString(s, 2, this.height - 14, 14, SilentFontRenderer.FontType.TITLE); - RenderUtil.drawImage(new ResourceLocation(Client.getInstance().getAccount().discord_id != null ? "silentclient/promo/latest.png" : "silentclient/images/discord.png"), this.width - 73, this.height - 42, 71, 40); - + if(GuiNews.imageLocation != null) { + RenderUtil.drawImage(new ResourceLocation(Client.getInstance().getAccount().discord_id != null ? GuiNews.imageLocation.getResourcePath() : "silentclient/images/discord.png"), this.width - 73, this.height - 42, 71, 40, false); + } + if (this.openGLWarning1 != null && this.openGLWarning1.length() > 0) { drawRect(this.field_92022_t - 2, this.field_92021_u - 2, this.field_92020_v + 2, this.field_92019_w - 1, 1428160512); @@ -351,11 +352,11 @@ public class GuiMainMenu extends GuiScreen implements GuiYesNoCallback { super.mouseClicked(mouseX, mouseY, mouseButton); - if(MouseUtils.isInside(mouseX, mouseY, this.width - 73, this.height - 42, 71, 40)) { + if(MouseUtils.isInside(mouseX, mouseY, this.width - 73, this.height - 42, 71, 40) && GuiNews.news != null) { try { Class oclass = Class.forName("java.awt.Desktop"); Object object = oclass.getMethod("getDesktop", new Class[0]).invoke((Object)null, new Object[0]); - oclass.getMethod("browse", new Class[] {URI.class}).invoke(object, new Object[] {new URI(Client.getInstance().getAccount().discord_id != null ? "https://silentclient.net/news/latest" : "https://silentclient.net/news/4")}); + oclass.getMethod("browse", new Class[] {URI.class}).invoke(object, new Object[] {new URI(Client.getInstance().getAccount().discord_id != null ? "https://silentclient.net/news/" + + GuiNews.news.getItem().id : "https://silentclient.net/news/4")}); } catch (Throwable err) { err.printStackTrace(); } diff --git a/src/main/java/net/silentclient/client/gui/util/RenderUtil.java b/src/main/java/net/silentclient/client/gui/util/RenderUtil.java index 5d119c6..eb7c60a 100644 --- a/src/main/java/net/silentclient/client/gui/util/RenderUtil.java +++ b/src/main/java/net/silentclient/client/gui/util/RenderUtil.java @@ -572,7 +572,7 @@ public class RenderUtil { if(mip) { Client.getInstance().getTextureManager().bindTextureMipmapped(image); } else { - ((TextureManagerExt) Minecraft.getMinecraft().getTextureManager()).waitBindTexture(new StaticResourceLocation(image.getResourcePath()), new StaticResourceLocation("silentclient/transparent.png")); + ((TextureManagerExt) Minecraft.getMinecraft().getTextureManager()).waitBindTexture(new StaticResourceLocation(image), new StaticResourceLocation("silentclient/transparent.png")); } Gui.drawModalRectWithCustomSizedTexture((int) x, (int) y, (float) 0.0f, (float) 0.0f, (int) width, (int) height, (float) width, (float) height); GL11.glDepthMask((boolean) true); diff --git a/src/main/java/net/silentclient/client/utils/SCTextureManager.java b/src/main/java/net/silentclient/client/utils/SCTextureManager.java index 4ee220c..d765b27 100644 --- a/src/main/java/net/silentclient/client/utils/SCTextureManager.java +++ b/src/main/java/net/silentclient/client/utils/SCTextureManager.java @@ -8,7 +8,9 @@ import java.util.Map; import java.util.concurrent.Callable; import javax.imageio.ImageIO; +import javax.net.ssl.HttpsURLConnection; +import net.silentclient.client.Client; import net.silentclient.client.mixin.accessors.TextureManagerAccessor; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -181,10 +183,14 @@ public class SCTextureManager public static BufferedImage getImage(String paramString) { try { - URL uRL = new URL(paramString); - return ImageIO.read(uRL); - } catch (IOException iOException) { - iOException.printStackTrace(); + final URL url = new URL(paramString); + final HttpsURLConnection connection = (HttpsURLConnection) url + .openConnection(); + connection.setRequestProperty("User-Agent", "SilentClient"); + connection.disconnect(); + return ImageIO.read(connection.getInputStream()); + } catch (Exception exception) { + Client.logger.catching(exception); return null; } } diff --git a/src/main/java/net/silentclient/client/utils/types/NewsResponse.java b/src/main/java/net/silentclient/client/utils/types/NewsResponse.java new file mode 100644 index 0000000..5144003 --- /dev/null +++ b/src/main/java/net/silentclient/client/utils/types/NewsResponse.java @@ -0,0 +1,19 @@ +package net.silentclient.client.utils.types; + +public class NewsResponse { + public NewsItem news; + + public NewsItem getItem() { + return news; + } + + public class NewsItem { + public int id; + public String cover; + + public String getCover() { + return "https://cdn.silentclient.net/assets" + cover; + } + } + +}