<commit_before>/*
 * Aeronica's mxTune MOD
 * Copyright {2016} <NAME> a.k.a. Aeronica
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.aeronica.mods.mxtune.gui;

import net.aeronica.mods.mxtune.Reference;
import net.aeronica.mods.mxtune.groups.GROUPS;
import net.aeronica.mods.mxtune.network.PacketDispatcher;
import net.aeronica.mods.mxtune.network.server.ManageGroupMessage;
import net.aeronica.mods.mxtune.options.MusicOptionsUtil;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.GL11;

import java.util.Set;

public class GuiGroupJoin extends GuiScreen
{
    public static final int GUI_ID = 5;

    private Minecraft mc;
    private FontRenderer fontRenderer = null;

    private static final ResourceLocation guiTexture = new ResourceLocation(Reference.MOD_ID, "textures/gui/manage_group.png");

    /** The X size of the group window in pixels. */
    private int xSize = 239;

    /** The Y size of the group window in pixels. */
    private int ySize = 164;

    /** Starting X position for the Gui. Inconsistent use for Gui backgrounds. */
    private int guiLeft;

    /** Starting Y position for the Gui. Inconsistent use for Gui backgrounds. */
    private int guiTop;

    private EntityPlayer player;
    private Integer groupID;

    @Override
    public void initGui()
    {
        Keyboard.enableRepeatEvents(false);

        this.mc = Minecraft.getMinecraft();
        this.fontRenderer = mc.fontRenderer;
        this.player = mc.player;

        this.guiLeft = (this.width - this.xSize) / 2;
        this.guiTop = (this.height - this.ySize) / 2;

        buttonList.clear();

        int posX = guiLeft + 169;
        int posY = guiTop + 92;
        GuiButton btn_yes = new GuiButton(0, posX, posY, 60, 20, I18n.format("gui.yes"));

        posX = guiLeft + 169;
        posY = guiTop + 112;
        GuiButton btn_no = new GuiButton(1, posX, posY, 60, 20, I18n.format("gui.no"));
        
        buttonList.add(btn_yes);
        buttonList.add(btn_no);

        // This is a back door way to pass parameters to the GUI.
        this.groupID = Integer.valueOf(MusicOptionsUtil.getSParam1(player));
    }

    @Override
    public boolean doesGuiPauseGame()
    {
        return false;
    }

    @Override
    public void drawScreen(int i, int j, float f)
    {
        drawDefaultBackground();
        drawGuiBackground();

        /* draw "TITLE" at the top right */
        String title = I18n.format("mxtune.gui.GuiGroupJoin.title");
        int posX = guiLeft + xSize - fontRenderer.getStringWidth(title) - 12;
        int posY = guiTop + 12;
        fontRenderer.getStringWidth(title);
        fontRenderer.drawString(title, posX, posY, 0x000000);

        drawMembers();
        super.drawScreen(i, j, f);
    }

    private void drawMembers()
    {
        int posX = guiLeft + 12;
        int posY = guiTop + 12;
        Integer memberID;
        String memberName;
        String leaderName;

        if (GROUPS.getClientGroups() != null || GROUPS.getClientMembers() != null)
        {
            if (groupID != null)
            {
                // Always put the leader at the TOP of the list
                leaderName = player.getEntityWorld().getEntityByID(GROUPS.getLeaderOfGroup(groupID)).getDisplayName().getUnformattedText();
                fontRenderer.drawStringWithShadow(leaderName, posX, posY, 16777215);
                posY += 10;
                // display the remaining members taking care to not print the leader a 2nd time.
                Set<Integer> set = GROUPS.getClientMembers().keySet();
                for (Integer aSet : set)
                {
                    memberID = aSet;
                    if (groupID.equals(GROUPS.getMembersGroupID(memberID)) && !memberID.equals(GROUPS.getLeaderOfGroup(groupID)))
                    {
                        memberName = player.getEntityWorld().getEntityByID(memberID).getDisplayName().getUnformattedText();
                        fontRenderer.drawStringWithShadow(memberName, posX, posY, 16777215);

                        // Only Leaders get to remove and promote other members!
                        if (player.getEntityId() == (GROUPS.getLeaderOfGroup(groupID)))
                        {
                            // GuiGroup enable/disable and visibility setup for buttons here
                        }
                        posY += 10;
                    }
                }
            }
        }
    }

    @Override
    protected void actionPerformed(GuiButton guibutton)
    {

        /* id 0 = yes; 1 = no; */
        switch (guibutton.id)
        {
        case 2:
            /* No */
            cleanup();
            break;
        case 0:
            /* Yes */
            sendRequest(groupID, player.getEntityId());
            cleanup();
            break;
            
        default:
        }
        cleanup();
    }

    protected void cleanup()
    {
        mc.displayGuiScreen(null);
        mc.setIngameFocus();
    }
    
    private void drawGuiBackground()
    {
        GL11.glColor4f(1F, 1F, 1F, 1F);
        mc.renderEngine.bindTexture(guiTexture);
        drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
    }

    private void sendRequest(Integer groupID, Integer memberID)
    {
        PacketDispatcher.sendToServer(new ManageGroupMessage(GROUPS.MEMBER_ADD, groupID, memberID));
    }
}<commit_msg>Cleanup code smells per http://sonarcloud.io<commit_after>/*
 * Aeronica's mxTune MOD
 * Copyright 2018, <NAME> a.k.a. Aeronica
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 */
package net.aeronica.mods.mxtune.gui;

import net.aeronica.mods.mxtune.Reference;
import net.aeronica.mods.mxtune.groups.GROUPS;
import net.aeronica.mods.mxtune.network.PacketDispatcher;
import net.aeronica.mods.mxtune.network.server.ManageGroupMessage;
import net.aeronica.mods.mxtune.options.MusicOptionsUtil;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.TextFormatting;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.GL11;

import java.util.Objects;
import java.util.Set;

import static net.aeronica.mods.mxtune.groups.GROUPS.MEMBER_ADD;
import static net.aeronica.mods.mxtune.groups.GROUPS.getLeaderOfGroup;

public class GuiGroupJoin extends GuiScreen
{
    public static final int GUI_ID = 5;

    private static final ResourceLocation guiTexture = new ResourceLocation(Reference.MOD_ID, "textures/gui/manage_group.png");

    /** The X size of the group window in pixels. */
    private int xSize = 239;

    /** The Y size of the group window in pixels. */
    private int ySize = 164;

    /** Starting X position for the Gui. Inconsistent use for Gui backgrounds. */
    private int guiLeft;

    /** Starting Y position for the Gui. Inconsistent use for Gui backgrounds. */
    private int guiTop;

    private EntityPlayer player;
    private Integer groupID;

    @Override
    public void initGui()
    {
        Keyboard.enableRepeatEvents(false);

        this.player = mc.player;

        this.guiLeft = (this.width - this.xSize) / 2;
        this.guiTop = (this.height - this.ySize) / 2;

        buttonList.clear();

        int posX = guiLeft + 169;
        int posY = guiTop + 92;
        GuiButton buttonYes = new GuiButton(0, posX, posY, 60, 20, I18n.format("gui.yes"));

        posX = guiLeft + 169;
        posY = guiTop + 112;
        GuiButton buttonNo = new GuiButton(1, posX, posY, 60, 20, I18n.format("gui.no"));
        
        buttonList.add(buttonYes);
        buttonList.add(buttonNo);

        // This is a back door way to pass parameters to the GUI.
        this.groupID = Integer.valueOf(MusicOptionsUtil.getSParam1(player));
    }

    @Override
    public boolean doesGuiPauseGame()
    {
        return false;
    }

    @Override
    public void drawScreen(int i, int j, float f)
    {
        drawDefaultBackground();
        drawGuiBackground();

        /* draw "TITLE" at the top right */
        String title = I18n.format("mxtune.gui.GuiGroupJoin.title");
        int posX = guiLeft + xSize - fontRenderer.getStringWidth(title) - 12;
        int posY = guiTop + 12;
        fontRenderer.getStringWidth(title);
        fontRenderer.drawString(title, posX, posY, 0x000000);

        drawGroupMembers();
        super.drawScreen(i, j, f);
    }

    private void drawGroupMembers()
    {
        int posX = guiLeft + 12;
        int posY = guiTop + 12;

        if ((GROUPS.getClientGroups() != null) || ((GROUPS.getClientMembers() != null) && (groupID != null)))
        {
                // Always put the leader at the TOP of the list
                drawLeader(posX, posY);
                posY += 10;
                // Display the remaining members taking care to not print the leader a 2nd time
                drawMembers(posX, posY);
        }
    }

    @SuppressWarnings("ConstantConditions")
    private void drawLeader(int posX, int posY)
    {
        String leaderName = Objects.requireNonNull(player.getEntityWorld().getEntityByID(getLeaderOfGroup(groupID))).getName();
        this.fontRenderer.drawStringWithShadow(TextFormatting.YELLOW + leaderName, posX, posY, 16777215);
    }

    private void drawMembers(int posX, int posYIn)
    {
        int posY = posYIn;
        Set<Integer> members = GROUPS.getClientMembers().keySet();
        for (Integer memberID : members)
        {
            if (groupID.equals(GROUPS.getMembersGroupID(memberID)) && !memberID.equals(GROUPS.getLeaderOfGroup(groupID)))
            {
                String memberName = Objects.requireNonNull(this.mc.world.getEntityByID(memberID)).getName();
                this.fontRenderer.drawStringWithShadow(memberName, posX, posY, 16777215);
                posY += 10;
            }
        }
    }

    @Override
    protected void actionPerformed(GuiButton guibutton)
    {

        /* id 0 = yes; 1 = no; */
        switch (guibutton.id)
        {
        case 2:
            /* No */
            cleanup();
            break;
        case 0:
            /* Yes */
            sendRequest(groupID, player.getEntityId());
            cleanup();
            break;
            
        default:
        }
        cleanup();
    }

    protected void cleanup()
    {
        mc.displayGuiScreen(null);
        mc.setIngameFocus();
    }
    
    private void drawGuiBackground()
    {
        GL11.glColor4f(1F, 1F, 1F, 1F);
        mc.renderEngine.bindTexture(guiTexture);
        drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
    }

    private void sendRequest(Integer groupID, Integer memberID)
    {
        PacketDispatcher.sendToServer(new ManageGroupMessage(MEMBER_ADD, groupID, memberID));
    }
}
{'fraction_non_alphanumeric': 0.0992135015566115, 'fraction_numerical': 0.016057676552515155, 'mean_word_length': 2.3316048034934496, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '13551', 'n_tokens_mistral': 3827, 'n_tokens_neox': 3587, 'n_words': 933}