diff --git a/src/main/java/net/silentclient/client/Client.java b/src/main/java/net/silentclient/client/Client.java index 516d5d7..726576c 100644 --- a/src/main/java/net/silentclient/client/Client.java +++ b/src/main/java/net/silentclient/client/Client.java @@ -12,6 +12,8 @@ import net.silentclient.client.event.EventManager; import net.silentclient.client.event.EventTarget; import net.silentclient.client.event.impl.ClientTickEvent; 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.clickgui.ClickGUI; import net.silentclient.client.gui.font.SilentFontRenderer; @@ -404,7 +406,25 @@ public class Client { playersCount = 0; nextPing = 10; this.updateUserInformation(); - silentSocket.getSocket().emit("update_information", (Minecraft.getMinecraft().getCurrentServerData() != null ? Minecraft.getMinecraft().getCurrentServerData().serverIP : "")); + silentSocket.getSocket().emit("update_information", event.getIp()); + } + + @EventTarget + public void onServerDisconnect(ServerLeaveEvent event) { + ping = 0; + playersCount = 0; + nextPing = 10; + this.updateUserInformation(); + silentSocket.getSocket().emit("update_information", ""); + } + + @EventTarget + public void onServerDisconnect(SingleplayerJoinEvent event) { + ping = 0; + playersCount = 0; + nextPing = 10; + this.updateUserInformation(); + silentSocket.getSocket().emit("update_information", ""); } // Instances diff --git a/src/main/java/net/silentclient/client/config/ConfigManager.java b/src/main/java/net/silentclient/client/config/ConfigManager.java index e4c1683..dcc35b9 100644 --- a/src/main/java/net/silentclient/client/config/ConfigManager.java +++ b/src/main/java/net/silentclient/client/config/ConfigManager.java @@ -82,6 +82,7 @@ public final class ConfigManager { } public void updateConfigs() { + Client.logger.info("Updating Config List"); this.configs = Stream.of(Client.getInstance().dir.listFiles()) .filter(file -> !file.isDirectory()) .map(File::getName) @@ -98,6 +99,7 @@ public final class ConfigManager { } public void loadConfig(String name) { + Client.logger.info("Loading Config: " + name); try(PrintWriter writer = new PrintWriter(this.settingsFile)) { writer.println("config:" + name); } catch (Exception err) { @@ -123,21 +125,23 @@ public final class ConfigManager { } public String newConfig(String name, boolean clone) { + Client.logger.info("Creating Config: " + name); File testConfig = new File(Client.getInstance().dir, name); if(testConfig.exists()) { + Client.logger.info("Creating Config Error: Config already exists."); return "Config already exists."; } else { try { testConfig.createNewFile(); } catch (IOException e) { - e.printStackTrace(); + Client.logger.catching(e); return "Error: " + e.getMessage(); } } try(PrintWriter writer = new PrintWriter(this.settingsFile)) { writer.println("config:" + name); } catch (Exception err) { - err.printStackTrace(); + Client.logger.catching(err); return "Error: " + err.getMessage(); } configFile = testConfig; @@ -269,6 +273,7 @@ public final class ConfigManager { } public void save() { + Client.logger.info("Saving Config: " + this.configFile.getName()); try(PrintWriter writer = new PrintWriter(this.configFile)) { for(Mod m : Client.getInstance().getModInstances().getMods()) { writer.println("MOD:" + m.getName() + ":" + m.isToggled()); diff --git a/src/main/java/net/silentclient/client/event/impl/ConnectToServerEvent.java b/src/main/java/net/silentclient/client/event/impl/ConnectToServerEvent.java index a267fb4..3e0020d 100644 --- a/src/main/java/net/silentclient/client/event/impl/ConnectToServerEvent.java +++ b/src/main/java/net/silentclient/client/event/impl/ConnectToServerEvent.java @@ -3,5 +3,14 @@ package net.silentclient.client.event.impl; import net.silentclient.client.event.Event; public class ConnectToServerEvent extends Event { + private final String ip; + + public ConnectToServerEvent(String ip) { + this.ip = ip; + } + + public String getIp() { + return ip; + } } diff --git a/src/main/java/net/silentclient/client/event/impl/ServerLeaveEvent.java b/src/main/java/net/silentclient/client/event/impl/ServerLeaveEvent.java new file mode 100644 index 0000000..b832be6 --- /dev/null +++ b/src/main/java/net/silentclient/client/event/impl/ServerLeaveEvent.java @@ -0,0 +1,6 @@ +package net.silentclient.client.event.impl; + +import net.silentclient.client.event.Event; + +public class ServerLeaveEvent extends Event { +} diff --git a/src/main/java/net/silentclient/client/event/impl/SingleplayerJoinEvent.java b/src/main/java/net/silentclient/client/event/impl/SingleplayerJoinEvent.java new file mode 100644 index 0000000..b4a5076 --- /dev/null +++ b/src/main/java/net/silentclient/client/event/impl/SingleplayerJoinEvent.java @@ -0,0 +1,6 @@ +package net.silentclient.client.event.impl; + +import net.silentclient.client.event.Event; + +public class SingleplayerJoinEvent extends Event { +} diff --git a/src/main/java/net/silentclient/client/gui/minecraft/GuiConnecting.java b/src/main/java/net/silentclient/client/gui/minecraft/GuiConnecting.java index fa6348b..ff34c7f 100644 --- a/src/main/java/net/silentclient/client/gui/minecraft/GuiConnecting.java +++ b/src/main/java/net/silentclient/client/gui/minecraft/GuiConnecting.java @@ -59,6 +59,7 @@ public class GuiConnecting extends GuiScreen private void connectServerData(final ServerData serverData) { + logger.info("Connecting to " + serverData.serverIP); (new Thread("Server Connector #" + CONNECTION_ID.incrementAndGet()) { public void run() @@ -89,7 +90,7 @@ public class GuiConnecting extends GuiScreen GuiConnecting.this.networkManager.setNetHandler(new NetHandlerLoginClient(GuiConnecting.this.networkManager, GuiConnecting.this.mc, GuiConnecting.this.previousGuiScreen)); GuiConnecting.this.networkManager.sendPacket(new C00Handshake(47, ip, port, EnumConnectionState.LOGIN)); GuiConnecting.this.networkManager.sendPacket(new C00PacketLoginStart(GuiConnecting.this.mc.getSession().getProfile())); - new ConnectToServerEvent().call(); + new ConnectToServerEvent(serverData.serverIP).call(); } catch (UnknownHostException unknownhostexception) { @@ -153,7 +154,7 @@ public class GuiConnecting extends GuiScreen GuiConnecting.this.networkManager.setNetHandler(new NetHandlerLoginClient(GuiConnecting.this.networkManager, GuiConnecting.this.mc, GuiConnecting.this.previousGuiScreen)); GuiConnecting.this.networkManager.sendPacket(new C00Handshake(47, ip, port, EnumConnectionState.LOGIN)); GuiConnecting.this.networkManager.sendPacket(new C00PacketLoginStart(GuiConnecting.this.mc.getSession().getProfile())); - new ConnectToServerEvent().call(); + new ConnectToServerEvent(ip).call(); } catch (UnknownHostException unknownhostexception) { diff --git a/src/main/java/net/silentclient/client/gui/minecraft/GuiIngameMenu.java b/src/main/java/net/silentclient/client/gui/minecraft/GuiIngameMenu.java index fe801e8..700dc7e 100644 --- a/src/main/java/net/silentclient/client/gui/minecraft/GuiIngameMenu.java +++ b/src/main/java/net/silentclient/client/gui/minecraft/GuiIngameMenu.java @@ -14,6 +14,7 @@ import net.silentclient.client.Client; import net.silentclient.client.admin.AdminRender; import net.silentclient.client.cosmetics.Cosmetics; import net.silentclient.client.cosmetics.gui.CosmeticsGui; +import net.silentclient.client.event.impl.ServerLeaveEvent; import net.silentclient.client.gui.elements.IconButton; import net.silentclient.client.gui.elements.Button; import net.silentclient.client.gui.GuiMultiplayerInGame; @@ -97,6 +98,7 @@ public class GuiIngameMenu extends GuiScreen { this.mc.displayGuiScreen(new GuiMultiplayer(new GuiMainMenu())); } + new ServerLeaveEvent().call(); case 2: case 3: diff --git a/src/main/java/net/silentclient/client/mixin/mixins/GuiDisconnectedMixin.java b/src/main/java/net/silentclient/client/mixin/mixins/GuiDisconnectedMixin.java new file mode 100644 index 0000000..491f38b --- /dev/null +++ b/src/main/java/net/silentclient/client/mixin/mixins/GuiDisconnectedMixin.java @@ -0,0 +1,21 @@ +package net.silentclient.client.mixin.mixins; + +import net.minecraft.client.gui.GuiDisconnected; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.util.IChatComponent; +import net.silentclient.client.event.impl.ServerLeaveEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(GuiDisconnected.class) +public class GuiDisconnectedMixin { + @Inject(method = "", at = @At("RETURN")) + private void init(GuiScreen screen, + String reasonLocalizationKey, + IChatComponent chatComp, + CallbackInfo ci) { + new ServerLeaveEvent().call(); + } +} diff --git a/src/main/java/net/silentclient/client/mixin/mixins/MinecraftMixin.java b/src/main/java/net/silentclient/client/mixin/mixins/MinecraftMixin.java index 1059b45..ae9cb94 100644 --- a/src/main/java/net/silentclient/client/mixin/mixins/MinecraftMixin.java +++ b/src/main/java/net/silentclient/client/mixin/mixins/MinecraftMixin.java @@ -14,7 +14,7 @@ import net.minecraft.item.EnumAction; import net.minecraft.item.ItemBlock; import net.minecraft.util.IChatComponent; import net.minecraft.util.ResourceLocation; -import net.minecraft.util.ScreenShotHelper; +import net.minecraft.world.WorldSettings; import net.silentclient.client.Client; import net.silentclient.client.event.impl.*; import net.silentclient.client.gui.GuiNews; @@ -113,6 +113,9 @@ public abstract class MinecraftMixin { @Inject(method = "displayGuiScreen", at = @At("RETURN"), cancellable = true) public void displayGuiScreenInject(GuiScreen guiScreenIn, CallbackInfo ci) { + if(guiScreenIn != null) { + Client.logger.info("Opening menu: " + guiScreenIn.getClass().toString()); + } if(Client.backgroundPanorama == null) { Client.backgroundPanorama = new BackgroundPanorama(Minecraft.getMinecraft()); } @@ -260,4 +263,9 @@ public abstract class MinecraftMixin { public void cancelChatMessage(GuiNewChat instance, IChatComponent chatComponent) { } + + @Inject(method = "launchIntegratedServer", at = @At("HEAD")) + public void event(String folderName, String worldName, WorldSettings worldSettingsIn, CallbackInfo ci) { + new SingleplayerJoinEvent().call(); + } } diff --git a/src/main/java/net/silentclient/client/mods/hypixel/AutoTipMod.java b/src/main/java/net/silentclient/client/mods/hypixel/AutoTipMod.java index f21c522..4b06b42 100644 --- a/src/main/java/net/silentclient/client/mods/hypixel/AutoTipMod.java +++ b/src/main/java/net/silentclient/client/mods/hypixel/AutoTipMod.java @@ -1,5 +1,6 @@ package net.silentclient.client.mods.hypixel; +import net.silentclient.client.Client; import net.silentclient.client.event.EventTarget; import net.silentclient.client.event.impl.ClientTickEvent; import net.silentclient.client.mods.Mod; @@ -36,6 +37,7 @@ public class AutoTipMod extends Mod { public void onTick(ClientTickEvent event) { if(Server.isHypixel()) { if(timer.delay(1200000)) { + Client.logger.info("Attempting to tip: all"); mc.thePlayer.sendChatMessage("/tip all"); timer.reset(); } diff --git a/src/main/java/net/silentclient/client/utils/Players.java b/src/main/java/net/silentclient/client/utils/Players.java index f89aa92..d3d0029 100644 --- a/src/main/java/net/silentclient/client/utils/Players.java +++ b/src/main/java/net/silentclient/client/utils/Players.java @@ -11,12 +11,12 @@ import net.silentclient.client.mixin.ducks.AbstractClientPlayerExt; import net.silentclient.client.mods.settings.CosmeticsMod; import net.silentclient.client.utils.types.PlayerResponse; -import java.util.HashMap; import java.util.Map; import java.util.UUID; +import java.util.WeakHashMap; public class Players { - public static final Map playersCache = new HashMap<>(); + public static final Map playersCache = new WeakHashMap<>(); public static void reload() { // playersCache.clear(); diff --git a/src/main/resources/mixins.SilentClient.json b/src/main/resources/mixins.SilentClient.json index f743694..45d7c83 100644 --- a/src/main/resources/mixins.SilentClient.json +++ b/src/main/resources/mixins.SilentClient.json @@ -109,6 +109,7 @@ "mixins.ServerListMixin", "mixins.EntityPacketsMixin", "mixins.ScreenShotHelperMixin", - "mixins.RenderTNTPrimedMixin" + "mixins.RenderTNTPrimedMixin", + "mixins.GuiDisconnectedMixin" ] } \ No newline at end of file