package com.github.lunatrius.ingameinfo.handler;

import com.github.lunatrius.ingameinfo.InGameInfoCore;
import com.github.lunatrius.ingameinfo.tag.Tag;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiChat;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import net.minecraftforge.fml.relauncher.Side;

public class Ticker {
    public static final Ticker INSTANCE = new Ticker();

    public static boolean enabled = true;

    private final Minecraft client = Minecraft.getMinecraft();
    private final InGameInfoCore core = InGameInfoCore.INSTANCE;

    private Ticker() {}

    @SubscribeEvent(priority = EventPriority.HIGHEST)
    public void onRenderGameOverlayEventPre(final RenderGameOverlayEvent.Pre event) {
        if (isRunning()) {
            if (ConfigurationHandler.replaceDebug && event.getType() == RenderGameOverlayEvent.ElementType.DEBUG) {
                event.setCanceled(true);
            }

            if (event.getType() == RenderGameOverlayEvent.ElementType.TEXT) {
                event.setCanceled(true);
            }
        }

        if (!ConfigurationHandler.showOverlayPotions && event.getType() == RenderGameOverlayEvent.ElementType.POTION_ICONS) {
            event.setCanceled(true);
        }
    }

    @SubscribeEvent
    public void onClientTick(final TickEvent.ClientTickEvent event) {
        onTick(event);
    }

    @SubscribeEvent
    public void onRenderTick(final TickEvent.RenderTickEvent event) {
        onTick(event);
    }

    private boolean isRunning() {
        if (enabled) {
            if (this.client.mcProfiler.profilingEnabled) {
                return true;
            }

            // a && b || !a && !b  -->  a == b
            if (this.client.gameSettings != null && ConfigurationHandler.replaceDebug == this.client.gameSettings.showDebugInfo) {
                if (!ConfigurationHandler.showOnPlayerList && this.client.gameSettings.keyBindPlayerList.isKeyDown()) {
                    return false;
                }

                if (this.client.gameSettings.hideGUI) {
                    return false;
                }

                if (this.client.currentScreen == null) {
                    return true;
                }

                if (ConfigurationHandler.showInChat && this.client.currentScreen instanceof GuiChat) {
                    return true;
                }
            }
        }

        return false;
    }

    private void onTick(final TickEvent event) {
        if (event.side == Side.CLIENT && event.phase == TickEvent.Phase.END) {
            this.client.mcProfiler.startSection("ingameinfo");
            if (isRunning()) {
                if (event.type == TickEvent.Type.CLIENT) {
                    this.core.onTickClient();
                } else if (event.type == TickEvent.Type.RENDER) {
                    this.core.onTickRender();
                }
            }

            if ((!enabled || this.client.gameSettings == null) && event.type == TickEvent.Type.CLIENT) {
                Tag.setServer(null);
                Tag.releaseResources();
            }
            this.client.mcProfiler.endSection();
        }
    }
}

@@ -950,33 +950,30 @@
         if (
-isRunning
+canRun
 ()) %7B%0A      
@@ -1694,32 +1694,126 @@
 (event);%0A    %7D%0A%0A
+    // TODO: this requires a bit of optimization... it's just boolean checks mostly but still%0A
     private bool
@@ -1816,25 +1816,22 @@
 boolean 
-isRunning
+canRun
 () %7B%0A   
@@ -1839,16 +1839,17 @@
     if (
+!
 enabled)
@@ -1847,32 +1847,65 @@
 !enabled) %7B%0A    
+        return false;%0A        %7D%0A%0A
         if (this
@@ -1959,44 +1959,412 @@
     
-    return true;%0A            %7D%0A%0A    
+return true;%0A        %7D%0A%0A        if (ConfigurationHandler.replaceDebug %7C%7C ConfigurationHandler.replaceDebug == this.client.gameSettings.showDebugInfo) %7B%0A            return true;%0A        %7D%0A%0A        return false;%0A    %7D%0A%0A    private boolean isRunning() %7B%0A        if (!canRun()) %7B%0A            return false;%0A        %7D%0A%0A        if (this.client.mcProfiler.profilingEnabled) %7B%0A            return true;%0A        %7D%0A%0A
     
@@ -2402,20 +2402,16 @@
  a == b%0A
-    
         
@@ -2537,28 +2537,24 @@
             
-    
 if (!Configu
@@ -2653,36 +2653,32 @@
                 
-    
 return false;%0A  
@@ -2683,35 +2683,27 @@
             
- 
-   %7D%0A%0A    
+%7D%0A%0A
             
@@ -2750,36 +2750,32 @@
                 
-    
 return false;%0A  
@@ -2780,34 +2780,27 @@
             
-    %7D%0A%0A   
+%7D%0A%0A
             
@@ -2791,33 +2791,32 @@
  %7D%0A%0A            
- 
 if (this.client.
@@ -2848,36 +2848,32 @@
                 
-    
 return true;%0A   
@@ -2877,35 +2877,27 @@
             
-    %7D%0A%0A    
+%7D%0A%0A
             
@@ -2991,36 +2991,32 @@
                 
-    
 return true;%0A   
@@ -3012,34 +3012,16 @@
 n true;%0A
-                %7D%0A
         

Split the isRunning method into two separate canRun and isRunning methods.