Skip to content

Commit

Permalink
Fixed disconnect notification not showing
Browse files Browse the repository at this point in the history
  • Loading branch information
MrCrayfish committed Feb 23, 2021
1 parent c3f36cb commit a38a452
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/main/java/com/mrcrayfish/controllable/Controllable.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.client.FMLFileResourcePack;
import net.minecraftforge.fml.client.FMLFolderResourcePack;
import net.minecraftforge.fml.common.*;
import net.minecraftforge.fml.common.DummyModContainer;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.LoadController;
import net.minecraftforge.fml.common.ModMetadata;
import net.minecraftforge.fml.common.event.FMLLoadCompleteEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import org.apache.logging.log4j.LogManager;
Expand All @@ -21,6 +24,8 @@
import javax.annotation.Nullable;
import java.io.File;
import java.util.Collections;
import java.util.Comparator;
import java.util.Optional;

import static org.libsdl.SDL.*;

Expand Down Expand Up @@ -170,7 +175,30 @@ public void connected(int jid)
@Override
public void disconnected(int jid)
{
Minecraft.getMinecraft().addScheduledTask(() ->
{
if(Controllable.controller != null)
{
if(Controllable.controller.getJid() == jid)
{
Controller oldController = Controllable.controller;

setController(null);

if(Controllable.getOptions().isAutoSelect() && manager.getControllerCount() > 0)
{
Optional<Integer> optional = manager.getControllers().keySet().stream().min(Comparator.comparing(i -> i));
optional.ifPresent(minJid -> setController(new Controller(minJid)));
}

Minecraft mc = Minecraft.getMinecraft();
if(mc.player != null)
{
Minecraft.getMinecraft().getToastGui().add(new ControllerToast(false, oldController.getName()));
}
}
}
});
}

public static void setController(@Nullable Controller controller)
Expand Down

0 comments on commit a38a452

Please sign in to comment.