Advertisement
Guest User

Untitled

a guest
Jul 15th, 2016
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.86 KB | None | 0 0
  1. package fr.ph1823.RoylityCraft.Menu;
  2.  
  3. import java.net.UnknownHostException;
  4. import java.util.concurrent.ScheduledThreadPoolExecutor;
  5. import java.util.concurrent.ThreadPoolExecutor;
  6.  
  7. import cpw.mods.fml.client.FMLClientHandler;
  8. import org.lwjgl.opengl.GL11;
  9.  
  10. import com.google.common.util.concurrent.ThreadFactoryBuilder;
  11.  
  12. import net.minecraft.client.Minecraft;
  13. import net.minecraft.client.gui.FontRenderer;
  14. import net.minecraft.client.gui.GuiButton;
  15. import net.minecraft.client.multiplayer.ServerData;
  16. import net.minecraft.client.renderer.OpenGlHelper;
  17. import net.minecraft.util.EnumChatFormatting;
  18.  
  19. public class CustomButton extends GuiButton
  20. {
  21.  
  22.    private static final ThreadPoolExecutor thread = new ScheduledThreadPoolExecutor(5, (new ThreadFactoryBuilder()).setNameFormat("Server Pinger #%d").setDaemon(true).build());
  23.    private ServerData serverData = new ServerData("RoylityCraft", "gloryofrp.glorycraft.fr");
  24.  
  25.    private CustomMainMenu menu;
  26.  
  27.    public CustomButton(int id, int x, int y, int sizeX, int sizeY, CustomMainMenu menu)
  28.    {
  29.        super(id, x, y, sizeX, sizeY, "");
  30.        this.menu = menu;
  31.    }
  32.    
  33.    public void drawButton(Minecraft mc, int mouseX, int mouseY)
  34.    {
  35.    
  36.        if (!this.serverData.field_78841_f)
  37.        {
  38.            this.serverData.field_78841_f = true;
  39.            this.serverData.pingToServer = -2L;
  40.            this.serverData.serverMOTD = "";
  41.            this.serverData.populationInfo = "";
  42.  
  43.            thread.submit(new Runnable()
  44.            {
  45.              
  46.                public void run()
  47.                {
  48.                    try
  49.                    {
  50.                    
  51.                        CustomButton.this.menu.getPinger().func_147224_a(CustomButton.this.serverData);
  52.                      
  53.                       //CustomButton.this.osp.func_147224_a(serverData);
  54.                       //System.out.print(CustomButton.this.serverData.populationInfo);
  55.                    
  56.                    }
  57.                    catch (UnknownHostException unknownhostexception)
  58.                    {
  59.                
  60.                        CustomButton.this.serverData.pingToServer = -1L;
  61.                        CustomButton.this.serverData.serverMOTD = EnumChatFormatting.DARK_RED + "Can\'t resolve hostname";
  62.                      
  63.                     //CustomButton.this.menu.getPinger().func_147224_a(CustomButton.this.serverData);
  64.                  
  65.                    }
  66.                    catch (Exception exception)
  67.                    {
  68.                        CustomButton.this.serverData.pingToServer = -1L;
  69.                        CustomButton.this.serverData.serverMOTD = EnumChatFormatting.DARK_RED + "Can\'t connect to server.";
  70.                      
  71.                    }
  72.                }
  73.            });
  74.        }
  75.        
  76.        if (this.visible)
  77.        {
  78.          
  79.            FontRenderer fontrenderer = mc.fontRenderer;
  80.            mc.getTextureManager().bindTexture(buttonTextures);
  81.            GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  82.            this.field_146123_n = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height;
  83.            int k = this.getHoverState(this.field_146123_n);
  84.            GL11.glEnable(GL11.GL_BLEND);
  85.            OpenGlHelper.glBlendFunc(770, 771, 1, 0);
  86.            GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
  87.            this.drawTexturedModalRect(this.xPosition, this.yPosition, 0, 46 + k * 20, this.width / 2, this.height);
  88.            this.drawTexturedModalRect(this.xPosition + this.width / 2, this.yPosition, 200 - this.width / 2, 46 + k * 20, this.width / 2, this.height);
  89.            this.mouseDragged(mc, mouseX, mouseY);
  90.            int l = 14737632;
  91.  
  92.            if (packedFGColour != 0)
  93.            {
  94.                l = packedFGColour;
  95.            }
  96.            else if (!this.enabled)
  97.            {
  98.                l = 10526880;
  99.            }
  100.            else if (this.field_146123_n)
  101.            {
  102.                l = 16777120;
  103.            }
  104.            
  105.           // System.out.println(serverData.populationInfo);
  106.            if(serverData.populationInfo != null && !serverData.populationInfo.isEmpty())
  107.            {
  108.                this.drawCenteredString(fontrenderer, "RoylityCraft (" + serverData.populationInfo + ")" , this.xPosition + this.width / 2, this.yPosition + (this.height - 8) / 2, l);
  109.            }
  110.            else
  111.            {
  112.               //FMLClientHandler.instance().finishServerLoading();
  113.                              
  114.               this.drawCenteredString(fontrenderer, "RoylityCraft (...)" /*CustomButton.this.serverData.serverMOTD/*+ CustomButton.this.serverData.serverMOTD + ")"  */, this.xPosition + this.width / 2, this.yPosition + (this.height - 8) / 2, l);
  115.               // this.menu.mc.currentScreen.updateScreen();
  116.              
  117.            }
  118.        }
  119.    }
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement