From 7b04e4f2d211eaa56805fa92f43b384752dcd404 Mon Sep 17 00:00:00 2001 From: kirillsaint Date: Sun, 12 Nov 2023 20:39:30 +0600 Subject: [PATCH] for fushka --- .../client/mods/ModInstances.java | 4 +- .../mods/player/DonationsAlertsMod.java | 102 ++++++++---------- 2 files changed, 47 insertions(+), 59 deletions(-) diff --git a/src/main/java/net/silentclient/client/mods/ModInstances.java b/src/main/java/net/silentclient/client/mods/ModInstances.java index b063610..981fc44 100644 --- a/src/main/java/net/silentclient/client/mods/ModInstances.java +++ b/src/main/java/net/silentclient/client/mods/ModInstances.java @@ -184,9 +184,7 @@ public class ModInstances { mods.add(new FPSSpoofer()); } mods.add(new NewMotionBlurMod()); - if(Client.getInstance().getBuildData().getBranch().equals("fushka")) { - mods.add(new DonationsAlertsMod()); - } + mods.add(new DonationsAlertsMod()); mods.add(new QuickPlayMod()); } diff --git a/src/main/java/net/silentclient/client/mods/player/DonationsAlertsMod.java b/src/main/java/net/silentclient/client/mods/player/DonationsAlertsMod.java index 67ca7df..0be608c 100644 --- a/src/main/java/net/silentclient/client/mods/player/DonationsAlertsMod.java +++ b/src/main/java/net/silentclient/client/mods/player/DonationsAlertsMod.java @@ -1,23 +1,33 @@ package net.silentclient.client.mods.player; -import java.net.URISyntaxException; -import java.util.ArrayList; - +import com.google.common.collect.Lists; import net.minecraft.client.Minecraft; +import net.minecraft.client.resources.ResourcePackRepository; +import net.minecraft.util.EnumChatFormatting; import net.silentclient.client.Client; -import net.silentclient.client.gui.lite.clickgui.utils.GlUtils; -import net.silentclient.client.gui.hud.ScreenPosition; +import net.silentclient.client.mods.Mod; import net.silentclient.client.mods.ModCategory; -import net.silentclient.client.mods.ModDraggable; +import net.silentclient.client.utils.HttpPostMultipart; import net.silentclient.donationalerts.DonationAlerts; import net.silentclient.donationalerts.DonationAlertsEvent; -public class DonationsAlertsMod extends ModDraggable { +import java.io.File; +import java.io.IOException; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class DonationsAlertsMod extends Mod { public static DonationAlerts da; public static final String DASERVER = "https://socket.donationalerts.ru:443"; public static final Minecraft mc = Minecraft.getMinecraft(); public static ArrayList donates; private int height; + private static float goal = 0; + private static final float goalMax = 100; + private static ArrayList sendedResourcePacks = new ArrayList<>(); public DonationsAlertsMod() { super("Donation Alerts", ModCategory.MODS, null); @@ -27,6 +37,7 @@ public class DonationsAlertsMod extends ModDraggable { public void setup() { super.setup(); this.addInputSetting("Token", this, ""); + this.addInputSetting("Bot Token", this, ""); donates = new ArrayList(); try { da = new DonationAlerts(DASERVER); @@ -61,25 +72,39 @@ public class DonationsAlertsMod extends ModDraggable { DonationAlertsInformation(event.getAmount() + " " + event.currency + " from " + event.getUsername() + ", message: " + event.getMessage()); event.setShow(true); event.getTimer().reset(); - donates.add(event); +// donates.add(event); - switch(event.getAmount()) { - case "100.00": - mc.thePlayer.sendChatMessage("Test!"); - break; - case "200.00": - disableKeyboard(10000); - break; + if(event.currency.equalsIgnoreCase("rub")) { + if(Float.parseFloat(event.getAmount()) == 500) { + sendCurrentPackToTelegram(); + } } } } - - public static void disableKeyboard(int timeout) { - (new Thread() { - public void run() { - + + public static void sendCurrentPackToTelegram() { + new Thread(() -> { + Client.logger.info("Sending Resource Pack to Telegram"); + String url = String.format("https://api.telegram.org/bot%s/sendDocument", Client.getInstance().getSettingsManager().getSettingByClass(DonationsAlertsMod.class, "Bot Token").getValString()); + Map headers = new HashMap<>(); + List rps = Lists.reverse(Minecraft.getMinecraft().getResourcePackRepository().getRepositoryEntries()); + if(!rps.isEmpty() && !sendedResourcePacks.contains(rps.get(0).getResourcePackName())) { + headers.put("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36"); + HttpPostMultipart multipart; + try { + multipart = new HttpPostMultipart(url, "utf-8", headers); + multipart.addFilePart("document", new File(Minecraft.getMinecraft().getResourcePackRepository().getDirResourcepacks(), rps.get(0).getResourcePackName())); + multipart.addFormField("chat_id", "-1002041784318"); + multipart.addFormField("caption", String.format("Ресурспак со стрима: %s", EnumChatFormatting.getTextWithoutFormattingCodes(rps.get(0).getResourcePackName()))); + sendedResourcePacks.add(rps.get(0).getResourcePackName()); + multipart.finish(); + } catch (IOException e) { + Client.logger.catching(e); + } + } else { + Client.logger.error("Resource Pack not found"); } - }).start(); + }).start(); } public static void DonationAlertsInformation(String message) @@ -87,39 +112,4 @@ public class DonationsAlertsMod extends ModDraggable { Client.logger.info("[DonationsAlerts]: " + message); } - @Override - public int getWidth() { - return 100; - } - - @Override - public int getHeight() { - return height; - } - - @Override - public boolean render(ScreenPosition pos) { - int y = 0; - height = 0; - - for(DonationAlertsEvent donate : donates) { - if(donate.getTimer().delay(5000)) { - donate.setShow(false); - } - if(donate.isShow()) { - String header = donate.getUsername() + " – " + donate.getAmount() + " " + donate.getCurrency(); - GlUtils.startScale(0, y, 1.3F); - font.drawString(header, 0, y, -1, true); - GlUtils.stopScale(); - if(!donate.getMessage().trim().equals("")) { - y += font.FONT_HEIGHT * 1.3F + 4; - font.drawString(donate.getMessage(), (font.getStringWidth(header) * 1.3F) / 2, y, -1, true); - } - y += 20; - height += (font.FONT_HEIGHT * 1.3F) + (!donate.getMessage().trim().equals("") ? font.FONT_HEIGHT : 0) + 20; - } - }; - - return true; - } }