@Override
 public IMessage onMessage(AddTrustedPlayerMessage message, MessageContext ctx) {
   World world = ctx.getServerHandler().playerEntity.worldObj;
   TurretBase turret =
       (TurretBase) world.getTileEntity(message.getX(), message.getY(), message.getZ());
   turret.addTrustedPlayer(message.getPlayer());
   world.markBlockForUpdate(message.getX(), message.getY(), message.getZ());
   return null;
 }
  @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")));
      }
    }
  }