@SuppressWarnings("unchecked")
  @Override
  public void initGui() {
    super.initGui();
    this.buttonList.clear();

    FontRenderer fontRenderer = Minecraft.getMinecraft().fontRenderer;

    String mobsButton = "Attack Mobs: " + (base.isAttacksMobs() ? "\u00A72Yes" : "\u00A7cNo");
    String neutralsButton =
        "Attack Neutrals: " + (base.isAttacksNeutrals() ? "\u00A72Yes" : "\u00A7cNo");
    String playersButton =
        "Attack Players: " + (base.isAttacksPlayers() ? "\u00A72Yes" : "\u00A7cNo");

    int x = (width - xSize) / 2;
    int y = (height - ySize) / 2;

    textFieldAddTrustedPlayer = new GuiTextField(fontRenderer, 11, 99, 100, 18);
    textFieldAddTrustedPlayer.setMaxStringLength(50);
    textFieldAddTrustedPlayer.setFocused(true);

    this.buttonList.add(new GuiButton(1, x + 10, y + 20, 155, 20, mobsButton));
    this.buttonList.add(new GuiButton(2, x + 10, y + 40, 155, 20, neutralsButton));
    this.buttonList.add(new GuiButton(3, x + 10, y + 60, 155, 20, playersButton));
    this.buttonList.add(new GuiButton(4, x + 114, y + 98, 51, 20, "+"));
    this.buttonList.add(new GuiButton(5, x + 35, y + 135, 30, 20, "-"));
    this.buttonList.add(new GuiButton(6, x + 10, y + 135, 20, 20, "<<"));
    this.buttonList.add(new GuiButton(7, x + 145, y + 135, 20, 20, ">>"));

    if (this.base.getTrustedPlayers().size() > 0) {
      this.buttonList.add(
          new GuiButton(
              8,
              x + 70,
              y + 135,
              23,
              20,
              this.base.getTrustedPlayers().get(base.trustedPlayerIndex).canOpenGUI
                  ? "\u00A72Y"
                  : "\u00A7cN"));
      this.buttonList.add(
          new GuiButton(
              9,
              x + 93,
              y + 135,
              23,
              20,
              this.base.getTrustedPlayers().get(base.trustedPlayerIndex).canChangeTargeting
                  ? "\u00A72Y"
                  : "\u00A7cN"));
      this.buttonList.add(
          new GuiButton(
              10,
              x + 116,
              y + 135,
              23,
              20,
              this.base.getTrustedPlayers().get(base.trustedPlayerIndex).admin
                  ? "\u00A72Y"
                  : "\u00A7cN"));
    } else {
      this.buttonList.add(new GuiButton(999, x + 70, y + 135, 23, 20, "?"));
      this.buttonList.add(new GuiButton(999, x + 93, y + 135, 23, 20, "?"));
      this.buttonList.add(new GuiButton(999, x + 116, y + 135, 23, 20, "?"));
    }
  }
  @Override
  protected void actionPerformed(GuiButton guibutton) {
    if (guibutton.id == 1) { // change Attack Mobs
      if (player.getUniqueID().toString().equals(base.getOwner())) {
        sendChangeToServerMobs(!base.isAttacksMobs());
        guibutton.displayString =
            "Attack Mobs: " + (!base.isAttacksMobs() ? "\u00A72Yes" : "\u00A7cNo");
      } else if (base.getTrustedPlayer(player.getUniqueID()).canChangeTargeting) {
        sendChangeToServerMobs(!base.isAttacksMobs());
        guibutton.displayString =
            "Attack Mobs: " + (!base.isAttacksMobs() ? "\u00A72Yes" : "\u00A7cNo");
      } else {
        player.addChatMessage(
            new ChatComponentText(StatCollector.translateToLocal("status.ownership")));
      }
    }

    if (guibutton.id == 2) { // change Attack Neutrals
      if (player.getUniqueID().toString().equals(base.getOwner())) {
        sendChangeToServerNeutrals(!base.isAttacksNeutrals());
        guibutton.displayString =
            "Attack Neutrals: " + (!base.isAttacksNeutrals() ? "\u00A72Yes" : "\u00A7cNo");
      } else if (base.getTrustedPlayer(player.getUniqueID()).canChangeTargeting) {
        sendChangeToServerNeutrals(!base.isAttacksNeutrals());
        guibutton.displayString =
            "Attack Neutrals: " + (!base.isAttacksNeutrals() ? "\u00A72Yes" : "\u00A7cNo");
      } else {
        player.addChatMessage(
            new ChatComponentText(StatCollector.translateToLocal("status.ownership")));
      }
    }

    if (guibutton.id == 3) { // change Attack Players
      if (player.getUniqueID().toString().equals(base.getOwner())) {
        sendChangeToServerPlayers(!base.isAttacksPlayers());
        guibutton.displayString =
            "Attack Players: " + (!base.isAttacksPlayers() ? "\u00A72Yes" : "\u00A7cNo");
      } else if (base.getTrustedPlayer(player.getUniqueID()).canChangeTargeting) {
        sendChangeToServerPlayers(!base.isAttacksPlayers());
        guibutton.displayString =
            "Attack Players: " + (!base.isAttacksPlayers() ? "\u00A72Yes" : "\u00A7cNo");
      } else {
        player.addChatMessage(
            new ChatComponentText(StatCollector.translateToLocal("status.ownership")));
      }
    }

    if (guibutton.id == 4) { // add trusted player
      if (player.getUniqueID().toString().equals(base.getOwner())) {
        if (!textFieldAddTrustedPlayer.getText().equals("")
            || !textFieldAddTrustedPlayer.getText().isEmpty()) {
          base.addTrustedPlayer(textFieldAddTrustedPlayer.getText());
          sendChangeToServerAddTrusted();
          textFieldAddTrustedPlayer.setText("");
          this.base.trustedPlayerIndex = 0;
          player.openGui(
              ModularTurrets.instance, 6, player.worldObj, base.xCoord, base.yCoord, base.zCoord);
        }
      } else if (base.getTrustedPlayer(player.getUniqueID()).admin) {
        if (!textFieldAddTrustedPlayer.getText().equals("")
            || !textFieldAddTrustedPlayer.getText().isEmpty()) {
          base.addTrustedPlayer(textFieldAddTrustedPlayer.getText());
          sendChangeToServerAddTrusted();
          textFieldAddTrustedPlayer.setText("");
          this.base.trustedPlayerIndex = 0;
          player.openGui(
              ModularTurrets.instance, 6, player.worldObj, base.xCoord, base.yCoord, base.zCoord);
        }
      } else {
        player.addChatMessage(
            new ChatComponentText(StatCollector.translateToLocal("status.ownership")));
      }
    }

    if (guibutton.id == 5) { // remove trusted player
      if (base.getTrustedPlayers().size() > 0) {
        if (this.base.getTrustedPlayers().get(base.trustedPlayerIndex) != null
            && player.getUniqueID().toString().equals(base.getOwner())) {
          sendChangeToServerRemoveTrusted();
          base.removeTrustedPlayer(base.getTrustedPlayers().get(base.trustedPlayerIndex).getName());
          textFieldAddTrustedPlayer.setText("");
          this.base.trustedPlayerIndex = 0;
          player.openGui(
              ModularTurrets.instance, 6, player.worldObj, base.xCoord, base.yCoord, base.zCoord);
        } else if (base.getTrustedPlayer(player.getUniqueID()).admin) {
          if (this.base.getTrustedPlayers().get(base.trustedPlayerIndex) != null
              && this.base.getTrustedPlayers().size() > 0) {
            sendChangeToServerRemoveTrusted();
            base.removeTrustedPlayer(
                base.getTrustedPlayers().get(base.trustedPlayerIndex).getName());
            textFieldAddTrustedPlayer.setText("");
            this.base.trustedPlayerIndex = 0;
            if (this.base
                    .getTrustedPlayers()
                    .get(base.trustedPlayerIndex)
                    .uuid
                    .equals(player.getUniqueID())
                && !player.getUniqueID().toString().equals(base.getOwner())) {
              mc.displayGuiScreen(null);
              return;
            }
            player.openGui(
                ModularTurrets.instance, 6, player.worldObj, base.xCoord, base.yCoord, base.zCoord);
          }
        } else {
          player.addChatMessage(
              new ChatComponentText(StatCollector.translateToLocal("status.ownership")));
        }
      }
    }

    if (guibutton.id == 6) { // decrease index of trusted player list
      if ((this.base.trustedPlayerIndex - 1 >= 0)) {
        this.base.trustedPlayerIndex--;
        player.openGui(
            ModularTurrets.instance, 6, player.worldObj, base.xCoord, base.yCoord, base.zCoord);
      }
    }

    if (guibutton.id == 7) { // increase index of trusted player list
      if (!((this.base.trustedPlayerIndex + 1) > (base.getTrustedPlayers().size() - 1))) {
        this.base.trustedPlayerIndex++;
        player.openGui(
            ModularTurrets.instance, 6, player.worldObj, base.xCoord, base.yCoord, base.zCoord);
      }
    }

    if (guibutton.id == 8) { // change trusted player permission for GUI opening
      if (player.getUniqueID().toString().equals(base.getOwner())
          && this.base.getTrustedPlayers().get(base.trustedPlayerIndex) != null) {
        sendChangeToServerModifyPermissions(
            this.base.getTrustedPlayers().get(base.trustedPlayerIndex).getName(),
            "gui",
            !base.getTrustedPlayers().get(base.trustedPlayerIndex).canOpenGUI);
        guibutton.displayString =
            !base.getTrustedPlayers().get(base.trustedPlayerIndex).canOpenGUI
                ? "\u00A72Y"
                : "\u00A7cN";
      } else if (this.base.getTrustedPlayers().get(base.trustedPlayerIndex) != null
          && base.getTrustedPlayer(player.getUniqueID()).admin) {
        sendChangeToServerModifyPermissions(
            this.base.getTrustedPlayers().get(base.trustedPlayerIndex).getName(),
            "gui",
            !base.getTrustedPlayers().get(base.trustedPlayerIndex).canOpenGUI);
        guibutton.displayString =
            !base.getTrustedPlayers().get(base.trustedPlayerIndex).canOpenGUI
                ? "\u00A72Y"
                : "\u00A7cN";
      } else {
        player.addChatMessage(
            new ChatComponentText(StatCollector.translateToLocal("status.ownership")));
      }
    }

    if (guibutton.id == 9) { // change trusted player permission for targeting
      if (player.getUniqueID().toString().equals(base.getOwner())
          && this.base.getTrustedPlayers().get(base.trustedPlayerIndex) != null) {
        sendChangeToServerModifyPermissions(
            this.base.getTrustedPlayers().get(base.trustedPlayerIndex).getName(),
            "targeting",
            !base.getTrustedPlayers().get(base.trustedPlayerIndex).canChangeTargeting);
        guibutton.displayString =
            !base.getTrustedPlayers().get(base.trustedPlayerIndex).canChangeTargeting
                ? "\u00A72Y"
                : "\u00A7cN";
      } else if (this.base.getTrustedPlayers().get(base.trustedPlayerIndex) != null
          && base.getTrustedPlayer(player.getUniqueID()).admin) {
        sendChangeToServerModifyPermissions(
            this.base.getTrustedPlayers().get(base.trustedPlayerIndex).getName(),
            "targeting",
            !base.getTrustedPlayers().get(base.trustedPlayerIndex).canChangeTargeting);
        guibutton.displayString =
            !base.getTrustedPlayers().get(base.trustedPlayerIndex).canChangeTargeting
                ? "\u00A72Y"
                : "\u00A7cN";
      } else {
        player.addChatMessage(
            new ChatComponentText(StatCollector.translateToLocal("status.ownership")));
      }
    }

    if (guibutton.id == 10) { // change trusted player permission for administering
      if (player.getUniqueID().toString().equals(base.getOwner())
          && this.base.getTrustedPlayers().get(base.trustedPlayerIndex) != null) {
        sendChangeToServerModifyPermissions(
            this.base.getTrustedPlayers().get(base.trustedPlayerIndex).getName(),
            "isAdmin",
            !base.getTrustedPlayers().get(base.trustedPlayerIndex).admin);
        guibutton.displayString =
            !base.getTrustedPlayers().get(base.trustedPlayerIndex).admin ? "\u00A72Y" : "\u00A7cN";
      } else if (this.base.getTrustedPlayers().get(base.trustedPlayerIndex) != null
          && base.getTrustedPlayer(player.getUniqueID()).admin) {
        sendChangeToServerModifyPermissions(
            this.base.getTrustedPlayers().get(base.trustedPlayerIndex).getName(),
            "isAdmin",
            !base.getTrustedPlayers().get(base.trustedPlayerIndex).admin);
        guibutton.displayString =
            !base.getTrustedPlayers().get(base.trustedPlayerIndex).admin ? "\u00A72Y" : "\u00A7cN";
      } else {
        player.addChatMessage(
            new ChatComponentText(StatCollector.translateToLocal("status.ownership")));
      }
    }
  }